当我尝试在javafx中混合矩形时,它仅适用于2D但不适用于3D。是否可以混合(BlendMode.ADD)矩形或Box-es(深度较小)来构建javafx8中的粒子系统3D版本?
这里是代码(使用网格但类似于矩形也不能在3D中工作):
public class PS2 extends Application {
private PerspectiveCamera ps ;
public MeshView textMesh(){
float [] points={
-100f,-100f,0f,
100f,-100f,0f,
100f,100f,0f,
-100f,100f,0f
} ;
float [] textCord={
0f,0f,
1f,0f,
1f,1f,
0f,1f
} ;
int[] faces={
0,0,3,3,1,1,
0,0,1,1,3,3,
3,3,2,2,1,1,
3,3,1,1,2,2
} ;
TriangleMesh mesh=new TriangleMesh() ;
mesh.getPoints().addAll(points);
mesh.getTexCoords().addAll(textCord);
mesh.getFaces().addAll(faces);
MeshView kv=new MeshView() ;
kv.setMesh(mesh) ;
PhongMaterial pm=new PhongMaterial() ;
pm.setDiffuseMap(new Image("file:/c:/pdfs/prs.png"));
kv.setMaterial(pm);
return kv ;
}
public void particleSystem(Group g){
//ArrayList<MeshView> particles=new ArrayList<>() ;
for(int i=0;i<20;i++){
MeshView mv=textMesh() ;
double x= (new Random()).nextDouble()*100.0 ;
double y= (new Random()).nextDouble()*100.0 ;
double z= (new Random()).nextDouble()*100.0 ;
mv.setTranslateX(x);
mv.setTranslateY(y);
mv.setTranslateZ(z);
//particles.add(mv) ;
mv.setBlendMode(BlendMode.ADD);
g.getChildren().add(mv) ;
}
}
public void initCamera(Scene scene){
ps=new PerspectiveCamera(true) ;
ps.setNearClip(0.1);
ps.setFarClip(10000);
ps.setTranslateZ(-2100);
ps.setTranslateX(100);
ps.setTranslateY(100);
scene.setCamera(ps);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Particle Systems");
Group root=new Group() ;
Scene s=new Scene(root,400,400,true) ;
s.setFill(Color.BLACK);
initCamera(s) ;
particleSystem(root);
primaryStage.setScene(s);
primaryStage.show() ;
}
public static void main(String[] args) {
launch(args) ;
}
}