javafx - Ambient and PointLight on SubScene influences all other SubScenes -
problem
in javafx default light on every 3d scene. it's pointlight shining top of scene.
i've tried show in program different possibilities of light, ran in trouble. if add subscene default, pointlight , ambientlight, works aspected. if add 1 more subscene combined light of ambient , point, i'll result showing in screenshot 2. seems other subscene lost light , fall it's default light. maybe hit bug?
systems tested
- os: windows 8.1 x64, windows 7 x64
- graphics: amd 4200 hd, intel hd 3000
- java: 1.8.0_45 jdk/jre x86 (32-bit), 1.8.0_60ea x64
stage 3 subscenes - default, point, ambient
stage 4 subscenes - default, point, ambient, (point,ambient)
example
here minimal, complete, , verifiable example
import javafx.application.application; import javafx.scene.*; import javafx.scene.control.label; import javafx.scene.layout.hbox; import javafx.scene.paint.color; import javafx.scene.paint.phongmaterial; import javafx.scene.shape.*; import javafx.stage.stage; public class shapes3dviewer extends application { phongmaterial material; @override public void start(stage stage) { material = new phongmaterial(); material.setdiffusecolor(color.firebrick); material.setspecularcolor(color.yellow); pointlight pointlight = new pointlight(color.white); pointlight.settranslatex(100); pointlight.settranslatey(100); pointlight.settranslatez(-300); pointlight.setrotate(90); ambientlight ambient = new ambientlight(); group g1 = createspheregroup(100, "default light"); group g2 = createspheregroup(100, "point light"); group g3 = createspheregroup(100, "ambient light"); group g4 = createspheregroup(100, "ambient & point light"); g2.getchildren().add(pointlight); g3.getchildren().add(ambient); g4.getchildren().addall(pointlight, ambient); subscene s1 = createsubscene(g1, 400, 400); subscene s2 = createsubscene(g2, 400, 400); subscene s3 = createsubscene(g3, 400, 400); subscene s4 = createsubscene(g4, 400, 400); hbox root = new hbox(); root.getchildren().addall(s1, s2, s3, s4); scene scene = new scene(root); stage.setscene(scene); stage.show(); } public static void main(string[] args) { launch(args); } private group createspheregroup(double radius, string text) { sphere c = new sphere(radius); c.setmaterial(material); c.setdrawmode(drawmode.fill); c.settranslatex(radius * 1.33); c.settranslatey(radius * 2); label lbl = new label(text); lbl.setstyle("-fx-text-fill: red;-fx-font-size: 18pt;"); return new group(c, lbl); } private subscene createsubscene(group group, double width, double height) { subscene s = new subscene(group, width, height); s.setcamera(new perspectivecamera()); s.setfill(color.color(.1, .1, .1)); return s; } }
output of mcve on:
javafx.runtime.version=8.0.45-b11 os x 10.9.5 2014 macbook pro
question
am doing wrong, or bug? can confirm same behaviour?
update
i've made new test added 2 new lights: pointlight2 , ambient2. both i've added fourth sphere. solution works.
pointlight pointlight2 = new pointlight(color.white); pointlight.settranslatex(100); pointlight.settranslatey(100); pointlight.settranslatez(-300); pointlight.setrotate(90); ambientlight ambient2 = new ambientlight(); g4.getchildren().addall(pointlight2, ambient2);
it seems lights merged , added 1 scene , removed other scenes.
conclusion
as jewselsea explained in answer, not bug! point of view should repeat statement in light classes again or make hint, because it's little bit confusing.
subscene needs parent root in constructor, don't have choice.
this not bug. pointlight node. node javadoc states: "if program adds child node parent (including group, region, etc) , node child of different parent or root of scene, node automatically (and silently) removed former parent." application appears behaving expected.
Comments
Post a Comment