1
我有以下测试代码,我尝试用圆圈剪切MeshView。 我也尝试将meshView放入一个组中,然后剪裁,但这导致了一个黑色的圆圈。剪切MeshView scalafx/javafx
有没有办法剪切一个MeshView,最好不要把它放到一个组中?
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 a while to 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
)
我来看看CSG的运营情况。如果我理解你的答案是正确的,那么你说这是无法完成的。 – workingdog
三维裁剪将是一个CSG布尔操作,所以可以完成...我没有说它不能。在我提到的问题中,您有使用[JCSG](https://github.com/miho/JCSG)和[FXyz](https://github.com/Birdasaur/FXyz)的3D形状之间的布尔操作示例。库。 –
我仍在看CSG布尔运算,我已经在使用FXyz,并且不知道CSG。 这两个图书馆都很棒。由于网格上的clip()在不破坏材质的情况下不起作用,我想出了一个解决方法来使用Shape.subtract进行剪切。 它几乎工作,但有一个问题。如何依次获取网格的外边界点。 我不明白像Cloth这样的复杂网格中的点的通用排序,因此无法制定公式来挑选我需要创建多边形的点。 https://gist.github.com/anonymous/49977e526a501905d1fb – workingdog