clipping of MeshView scalafx/javafx -


i have following test code, try clip meshview circle. tried putting meshview group clipping that, result in black circle.

is there way clip meshview, preferably without putting group?

import scalafx.application.jfxapp import scalafx.application.jfxapp.primarystage import scalafx.scene.image.image import scalafx.scene.paint.{color, phongmaterial} import scalafx.scene.shape.{trianglemesh, circle, meshview} import scalafx.scene.{group, perspectivecamera, scene, sceneantialiasing}  object test4 extends jfxapp {   stage = new primarystage {     scene = new scene(500, 500, true, sceneantialiasing.balanced) {       fill = color.lightgray       val clipcircle = circle(150.0)       val meshview = new meshview(new rectanglemesh(500,500)) {         // takes while load         material = new phongmaterial(color.white, new image("https://peach.blender.org/wp-content/uploads/bbb-splash.png"), null, null, null)       }     //  val meshgroup = new group(meshview)       meshview.setclip(clipcircle)       root = new group {children = meshview; translatex = 250.0; translatey = 250.0; translatez = 560.0}       camera = new perspectivecamera(false)     }   } }  class rectanglemesh(width: float, height: float) extends trianglemesh {   points = array(     -width / 2, height / 2, 0,     -width / 2, -height / 2, 0,     width / 2, height / 2, 0,     width / 2, -height / 2, 0   )   texcoords = array(     1, 1,     1, 0,     0, 1,     0, 0   )   faces = array(     2, 2, 1, 1, 0, 0,     2, 2, 3, 3, 1, 1   ) 

the clippling works fine on meshview wrapped around group.

if check javadoc setclip():

there known limitation of mixing clip 3d transform. clipping 2d image operation. result of clip set on group node 3d transformed children cause children rendered in order without z-buffering applied between children.

as result of this:

group meshgroup = new group(meshview); meshgroup.setclip(clipcircle); 

you have 2d image, , seems material not applied. can check there's mesh, seting this:

meshview.setdrawmode(drawmode.line); 

so in case, adjusting dimensions:

@override public void start(stage primarystage) {     circle clipcircle = new circle(220.0);     meshview meshview = new meshview(new rectanglemesh(400,400));     meshview.setdrawmode(drawmode.line);     group meshgroup = new group(meshview);     meshgroup.setclip(clipcircle);     perspectivecamera camera = new perspectivecamera(false);      stackpane root = new stackpane();     final circle circle = new circle(220.0);     circle.setfill(color.transparent);     circle.setstroke(color.red);     root.getchildren().addall(meshgroup, circle);      scene scene = new scene(root, 500, 500, true, sceneantialiasing.balanced);     scene.setcamera(camera);      primarystage.settitle("hello world!");     primarystage.setscene(scene);     primarystage.show(); } 

will give this:

clip

in end, clipping doesn't make sense 3d shapes. can use 2d shape result want.

if want 3d clipping have @ csg operations. check question javafx based solution.


Comments