I'm trying to understand the JCSG library by using the following test code, where I take the difference between a FXyz mesh/cloth and a sphere to create a hole in the mesh so as to display the underlying mesh image. Is it possible to do this, if so how? All my attempts produce a red circle.
import org.fxyz.shapes.primitives.SpheroidMesh
import org.fxyz.utils.MeshUtils
import org.fxyz.shapes.complex.cloth.ClothMesh
import scalafx.Includes._
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.image.Image
import scalafx.scene.paint.PhongMaterial
import scalafx.scene.shape._
import scalafx.scene.{Group, PerspectiveCamera, Scene, SceneAntialiasing}
import scalafx.scene.paint.Color
import scala.collection.JavaConversions._
object ClothTest1 extends JFXApp {
stage = new PrimaryStage {
scene = new Scene(600, 600, true, SceneAntialiasing.Balanced) {
fill = Color.LightGray
val rose = "https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Redoute_-_Rosa_gallica_purpuro-violacea_magna.jpg/800px-Redoute_-_Rosa_gallica_purpuro-violacea_magna.jpg"
val img = new Image(rose, 400, 400, false, true)
val meshView = new ClothMesh(4, 4, 400, 400)
meshView.setDrawMode(DrawMode.Fill)
meshView.setCullFace(CullFace.None)
meshView.setStyle("-fx-background-color: #00000000") // transparent
meshView.setWidth(img.width.value)
meshView.setHeight(img.height.value)
meshView.setMaterial(new PhongMaterial(Color.White, img, null, null, null))
val fxyzSphere = new SpheroidMesh(120.0) {
setDrawMode(DrawMode.Fill)
setStyle("-fx-background-color: #00000000") // transparent
}
val csgHole = MeshUtils.mesh2CSG(fxyzSphere.getMesh())
val csgMesh = MeshUtils.mesh2CSG(meshView.getMesh())
val fxMesh = csgMesh.difference(csgHole).toJavaFXMesh.getAsMeshViews.head
root = new Group() {
children += fxMesh
translateX = 250
translateY = 250
}
camera = new PerspectiveCamera(false)
}
}
}