Created
July 24, 2015 02:49
-
-
Save anonymous/49977e526a501905d1fb to your computer and use it in GitHub Desktop.
MeshView Shape.subtract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 scalafx.scene.shape.Polygon | |
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)) | |
// not correct, should be the outer boundary polygon of the mesh, but how to get that | |
val poly = new Polygon { meshView.getPoints.foreach(c => points += c.toDouble) } | |
val clipCircle = new Circle() { | |
radius = meshView.getWidth * 0.4 | |
fill = Color.Transparent | |
} | |
val stencil = Shape.subtract(poly, clipCircle) | |
root = new Group(meshView, stencil) { | |
translateX = 250 | |
translateY = 250 | |
} | |
camera = new PerspectiveCamera(false) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment