java - JavaFX 8 Z-buffer issue -


my problem z-buffer in javafx 3d, not seem work intended on machine.

i'am aware of questions: overlapping shapes , ...z order...

however have z-buffer enabled, , nodes still being rendered in order added scenegraph.

maybe i'm missing dependencies or whatsoever?

i'm posting code, hope can me. i'm creating transition moves node around on elliptic path.

thank in advance!

public class orbitexp extends application { group root = new group(); scene scene = new scene(root, 800, 600, true, sceneantialiasing.balanced); perspectivecamera camera = new perspectivecamera(); @override public void start(stage primarystage) {     root.setdepthtest(depthtest.enable);  //tried set depthtest explicitly. assumed maybe did not inherit:s     system.out.println(         "3d supported? " +         platform.issupported(conditionalfeature.scene3d)     );    // returns true      system.out.println("root z-buffer: " + root.getdepthtest());     initcamera();     box              box1 = new box(50,50,50),             box2 = new box(10,10,10);     root.settranslatex(scene.getwidth()/2);     root.settranslatey(scene.getheight()/2);     phongmaterial              pmat = new phongmaterial(color.blue),             pmat2 = new phongmaterial(color.red);     box1.setmaterial(pmat);     box2.setmaterial(pmat2);     scene.setfill(color.lightgreen);     root.getchildren().addall(box1,box2);     sequentialtransition sqt = orbit(box1, box2, 40, 40, duration.seconds(3), 360);     sqt.play();     scene.setonmouseclicked(click->{         node node = (node)(click.getpickresult().getintersectednode());         system.out.println("tx: "+node.gettranslatex());         system.out.println("ty: "+node.gettranslatey());         system.out.println("tz: "+node.gettranslatez());     });  // debugging, coords seem alright     primarystage.setscene(scene);     primarystage.show(); } public static void main(string[] args) {     launch(args); } private void initcamera() {     camera.settranslatez(-50);     camera.settranslatey(20);     camera.setfarclip(5000);     camera.setnearclip(0);     scene.setcamera(camera); } sequentialtransition orbit(node node1, node node2,double a, double b, duration totalduration, int n) {     sequentialtransition sqt = new sequentialtransition();     duration dur = new duration(totalduration.tomillis()*(1.0d/n));     node2.settranslatex(a+node1.gettranslatex());     node2.settranslatez(node1.gettranslatez());     (int = 1; < n; i++) {         translatetransition tt = new translatetransition(dur, node2);         double                  angle = i*(360.0d/n),                 tox = (math.cos(math.toradians(angle))*a)+node1.gettranslatex(),                 toz = (math.sin(math.toradians(angle))*b)+node1.gettranslatez();         tt.settox(tox);         tt.settoz(toz);         tt.setinterpolator(interpolator.linear);         sqt.getchildren().add(tt);         system.out.println("angle = " + angle + "\nangle in rads: " + math.toradians(angle) + "\ntox = " + tox + "\ntoz = " + toz);     }     sqt.setcyclecount(timeline.indefinite);     return sqt; } 

}

this first post way:)

if check code on link provided using rectangles, depth buffer works fine.

changing rectangles use 3d boxes works well.

the issue how define rotation of 1 of boxes related other, instead of using rotatetransition or sequentialtransition of translatetransition do, i've applied rotate transform red box setting pivot in center of blue one, , used animationtimer modify angle of rotation create 'orbit' effect.

you can use transparency on big box (since 8u60) see small 1 beneath it.

private final group shapes = new group(); private long lasttimercall; private animationtimer timeline;  @override public void start(stage stage) throws exception {     scene scene = new scene(createrotatingshapes(), 400, 300,             true, sceneantialiasing.balanced);     scene.setfill(color.lightgreen);     final perspectivecamera camera = new perspectivecamera();     camera.setrotationaxis(rotate.x_axis);     camera.setrotate(10);     camera.settranslatez(200);     scene.setcamera(camera);      stage.setscene(scene);     stage.show(); }  private group createrotatingshapes() {     final box box1 = new box(50, 50, 50);     // transparency in box1: last node of group     box1.setmaterial(new phongmaterial(color.web("#0000ff80")));      box1.settranslatez(50);      final box box2 = new box(10, 10, 10);     box2.setmaterial(new phongmaterial(color.red));      box2.settranslatez(-50);      shapes.getchildren().addall(box2, box1);      shapes.settranslatex(200);     shapes.settranslatey(150);      rotatearoundyaxis(box2);      return shapes; }  private int count = 0; private void rotatearoundyaxis(node node) {     rotate r = new rotate(0, 0, 0, 100, rotate.y_axis);     node.gettransforms().add(r);     lasttimercall = system.nanotime();     timeline = new animationtimer() {         @override public void handle(long now) {             if (now > lasttimercall + 100_000_000l) {                 r.setangle((count++)%360);             }         }     };     timeline.start(); }   @override public void stop() {     timeline.stop(); } 

in front of box:

in front of

behind blue box:

behind

edit

if have camera javadoc nearclip:

specifies distance eye of near clipping plane of camera in eye coordinate space. objects closer eye nearclip not drawn. nearclip specified value greater zero. value less or equal 0 treated small positive number.

(bold mine).

so problem code line:

camera.setnearclip(0); 

just change to:

camera.setnearclip(0.01); 

and work expected.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -