1

次のテスト コードがあります。ここでは、MeshView を円でクリップしようとしています。また、meshView をグループに入れてクリッピングしようとしましたが、これは黒い円になります。

できればグループに入れずに、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
  )
4

1 に答える 1

0

クリッピングは、実際には、ラップされた aに対して正常に機能しますMeshViewGroup

JavaDoc をチェックすると、次のようになりますsetClip()

Clip と 3D Transform の混合には既知の制限があります。クリッピングは基本的に 2D イメージ操作です。3D 変換された子を持つグループ ノードに設定されたクリップの結果は、それらの子の間に Z バッファリングを適用せずに、その子を順番にレンダリングします。

結果的に:

Group meshGroup = new Group(meshView);
meshGroup.setClip(clipCircle);

2D 画像が表示Materialされますが、適用されていないようです。ただし、これを設定することで、メッシュがあることを確認できます。

meshView.setDrawMode(DrawMode.LINE);

したがって、あなたの場合、寸法を調整します:

@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();
}

これを与える:

クリップ

結局、クリッピングは 3D 形状では意味がありません。そのためには、2D 形状だけを使用して、必要な結果を得ることができます。

3D クリッピングが必要な場合は、CSG 操作をご覧ください。JavaFX ベースのソリューションについては、この質問を確認してください。

于 2015-07-21T12:51:46.880 に答える