本文整理汇总了Java中javafx.scene.shape.MeshView.setMaterial方法的典型用法代码示例。如果您正苦于以下问题:Java MeshView.setMaterial方法的具体用法?Java MeshView.setMaterial怎么用?Java MeshView.setMaterial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.shape.MeshView
的用法示例。
在下文中一共展示了MeshView.setMaterial方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildGroup
import javafx.scene.shape.MeshView; //导入方法依赖的package包/类
@Override
protected Group buildGroup() {
mb = new MeshBuilder();
triangleMesh = mb.getTriangleMesh();
meshView = new MeshView(triangleMesh);
material = new PhongMaterial();
material.setDiffuseColor(Color.LIGHTGRAY);
material.setSpecularColor(Color.rgb(30, 30, 30));
meshView.setMaterial(material);
//Set Wireframe mode
meshView.setDrawMode(DrawMode.FILL);
meshView.setCullFace(CullFace.BACK);
meshView.setScaleX(SCALE);
meshView.setScaleY(SCALE);
meshView.setScaleZ(SCALE);
grp = new Group(meshView);
return grp;
}
示例2: updateArrow
import javafx.scene.shape.MeshView; //导入方法依赖的package包/类
public void updateArrow(String face, boolean hover){
boolean bFaceArrow = !(face.startsWith("X") || face.startsWith("Y") || face.startsWith("Z"));
MeshView arrow = bFaceArrow ? faceArrow : axisArrow;
if (hover && onRotation.get()) {
return;
}
arrow.getTransforms().clear();
if (hover) {
double d0 = arrow.getBoundsInParent().getHeight() / 2d;
Affine aff = Utils.getAffine(dimCube, d0, bFaceArrow, face);
arrow.getTransforms().setAll(aff);
arrow.setMaterial(Utils.getMaterial(face));
if (previewFace.get().isEmpty()) {
previewFace.set(face);
onPreview.set(true);
rotateFace(face, true, false);
}
} else if (previewFace.get().equals(face)) {
rotateFace(Utils.reverseRotation(face), true, true);
} else if (previewFace.get().equals("V")) {
previewFace.set("");
onPreview.set(false);
}
}
示例3: getAsMeshViews
import javafx.scene.shape.MeshView; //导入方法依赖的package包/类
public List<MeshView> getAsMeshViews() {
List<MeshView> result = new ArrayList<>(meshes.size());
for (int i = 0; i < meshes.size(); i++) {
Mesh mesh = meshes.get(i);
Material mat = materials.get(i);
MeshView view = new MeshView(mesh);
view.setMaterial(mat);
view.setCullFace(CullFace.NONE);
result.add(view);
}
return result;
}
示例4: updateArrow
import javafx.scene.shape.MeshView; //导入方法依赖的package包/类
public void updateArrow(String face, boolean hover){
boolean bFaceArrow=!(face.startsWith("X")||face.startsWith("Y")||face.startsWith("Z"));
MeshView arrow=bFaceArrow?faceArrow:axisArrow;
if(hover && onRotation.get()){
return;
}
arrow.getTransforms().clear();
if(hover){
double d0=arrow.getBoundsInParent().getHeight()/2d;
Affine aff=Utils.getAffine(dimCube, d0, bFaceArrow, face);
arrow.getTransforms().setAll(aff);
arrow.setMaterial(Utils.getMaterial(face));
if(previewFace.get().isEmpty()) {
previewFace.set(face);
onPreview.set(true);
rotateFace(face,true,false);
}
} else if(previewFace.get().equals(face)){
rotateFace(Utils.reverseRotation(face),true,true);
} else if(previewFace.get().equals("V")){
previewFace.set("");
onPreview.set(false);
}
}
示例5: load
import javafx.scene.shape.MeshView; //导入方法依赖的package包/类
/**
* Load a 3D file, always loaded as TriangleMesh.
*
* @param fileUrl the url of the 3D file to load
* @return the loaded Node which could be a MeshView or a Group
* @throws IOException if there is a problem loading the file
*/
public static Group load(final String fileUrl) throws IOException {
final int dot = fileUrl.lastIndexOf('.');
if (dot <= 0) {
throw new IOException("Unknown 3D file format, url missing extension [" + fileUrl + "]");
}
final String extension = fileUrl.substring(dot + 1, fileUrl.length()).toLowerCase();
switch (extension) {
case "3ds":
ModelImporter tdsImporter = new TdsModelImporter();
tdsImporter.read(fileUrl);
final Node[] tdsMesh = (Node[]) tdsImporter.getImport();
tdsImporter.close();
return new Group(tdsMesh);
case "stl":
StlMeshImporter stlImporter = new StlMeshImporter();
stlImporter.read(fileUrl);
// STL includes only geometry data
TriangleMesh cylinderHeadMesh = stlImporter.getImport();
stlImporter.close();
// Create Shape3D
MeshView cylinderHeadMeshView = new MeshView();
cylinderHeadMeshView.setMaterial(new PhongMaterial(Color.GRAY));
cylinderHeadMeshView.setMesh(cylinderHeadMesh);
stlImporter.close();
return new Group(cylinderHeadMeshView);
default:
throw new IOException("Unsupported 3D file format [" + extension + "]");
}
}
示例6: buildMeshView
import javafx.scene.shape.MeshView; //导入方法依赖的package包/类
public MeshView buildMeshView(String key) {
MeshView meshView = new MeshView();
meshView.setId(key);
meshView.setMaterial(materials.get(key));
meshView.setMesh(meshes.get(key));
meshView.setCullFace(CullFace.NONE);
return meshView;
}
示例7: addTiles
import javafx.scene.shape.MeshView; //导入方法依赖的package包/类
public void addTiles() {
for (Tile tile : Board.getTiles()) {
MeshView mesh = tile.getMesh();
PhongMaterial material = new PhongMaterial(Color.WHITE);
material.setDiffuseMap(new Image(GameGroup.class.getResourceAsStream(tile.getResourceString())));
mesh.setMaterial(material);
mesh.getTransforms().add(new Translate(tile.getCenter().getX(), tile.getCenter().getY(), tile.getCenter().getZ()));
getChildren().add(mesh);
}
}
示例8: setHeightData
import javafx.scene.shape.MeshView; //导入方法依赖的package包/类
public void setHeightData(float[][] arrayY, int spacing, Color color, boolean ambient, boolean fill) {
material = new PhongMaterial();
material.setSpecularColor(color);
material.setDiffuseColor(color);
mesh = new TriangleMesh();
// Fill Points
for (int x = 0; x < arrayY.length; x++) {
for (int z = 0; z < arrayY[0].length; z++) {
mesh.getPoints().addAll(x * spacing, arrayY[x][z], z * spacing);
}
}
//for now we'll just make an empty texCoordinate group
mesh.getTexCoords().addAll(0, 0);
int total = arrayY.length * arrayY.length;
int nextRow = arrayY.length;
//Add the faces "winding" the points generally counter clock wise
for (int i = 0; i < total - nextRow -1; i++) {
//Top upper left triangle
mesh.getFaces().addAll(i,0,i+nextRow,0,i+1,0);
//Top lower right triangle
mesh.getFaces().addAll(i+nextRow,0,i+nextRow + 1,0,i+1,0);
//Bottom
}
//Create a viewable MeshView to be added to the scene
//To add a TriangleMesh to a 3D scene you need a MeshView container object
meshView = new MeshView(mesh);
//The MeshView allows you to control how the TriangleMesh is rendered
if(fill) {
meshView.setDrawMode(DrawMode.FILL);
} else {
meshView.setDrawMode(DrawMode.LINE); //show lines only by default
}
meshView.setCullFace(CullFace.BACK); //Removing culling to show back lines
getChildren().add(meshView);
meshView.setMaterial(material);
if (ambient) {
selfLight.getScope().add(meshView);
if(!getChildren().contains(selfLight))
getChildren().add(selfLight);
}
else if(getChildren().contains(selfLight))
getChildren().remove(selfLight);
setDepthTest(DepthTest.ENABLE);
}
示例9: PolyLine3D
import javafx.scene.shape.MeshView; //导入方法依赖的package包/类
public PolyLine3D(List<Point3D> points, int width, Color color) {
this.points = points;
this.width = width;
this.color = color;
setDepthTest(DepthTest.ENABLE);
mesh = new TriangleMesh();
//add each point. For each point add another point shifted on Z axis by width
//This extra point allows us to build triangles later
for(Point3D point: points) {
mesh.getPoints().addAll(point.x,point.y,point.z);
mesh.getPoints().addAll(point.x,point.y,point.z+width);
}
//add dummy Texture Coordinate
mesh.getTexCoords().addAll(0,0);
//Now generate trianglestrips for each line segment
for(int i=2;i<points.size()*2;i+=2) { //add each segment
//Vertices wound counter-clockwise which is the default front face of any Triange
//These triangles live on the frontside of the line facing the camera
mesh.getFaces().addAll(i,0,i-2,0,i+1,0); //add primary face
mesh.getFaces().addAll(i+1,0,i-2,0,i-1,0); //add secondary Width face
//Add the same faces but wind them clockwise so that the color looks correct when camera is rotated
//These triangles live on the backside of the line facing away from initial the camera
mesh.getFaces().addAll(i+1,0,i-2,0,i,0); //add primary face
mesh.getFaces().addAll(i-1,0,i-2,0,i+1,0); //add secondary Width face
}
//Need to add the mesh to a MeshView before adding to our 3D scene
meshView = new MeshView(mesh);
meshView.setDrawMode(DrawMode.FILL); //Fill so that the line shows width
material = new PhongMaterial(color);
material.setDiffuseColor(color);
material.setSpecularColor(color);
meshView.setMaterial(material);
//Make sure you Cull the Back so that no black shows through
meshView.setCullFace(CullFace.BACK);
//Add some ambient light so folks can see it
AmbientLight light = new AmbientLight(Color.WHITE);
light.getScope().add(meshView);
getChildren().add(light);
getChildren().add(meshView);
}
示例10: draw
import javafx.scene.shape.MeshView; //导入方法依赖的package包/类
public static Group draw(float[] footprint, float zLevel, float HEIGHT) {
Group box = new Group();
int y = 0;
// for each footprint coordinate make a rectangle
int n = footprint.length - 2;
// one side of the box
for (int k = 0; k < n; k = k + 2) {
float[] points = { footprint[k], y + zLevel, footprint[k + 1], footprint[k + 2], y + zLevel,
footprint[k + 3], footprint[k + 2], y + zLevel + HEIGHT, footprint[k + 3], footprint[k],
y + zLevel + HEIGHT, footprint[k + 1] };
float[] texCoords = { 1, 1, 1, 0, 0, 1, 0, 0 };
int[] faces = { 0, 0, 2, 2, 1, 1, 0, 0, 3, 3, 2, 2 };
int[] faces2 = { 0, 0, 1, 1, 2, 2, 0, 0, 2, 2, 3, 3 };
TriangleMesh mesh1 = new TriangleMesh();
mesh1.getPoints().setAll(points);
mesh1.getTexCoords().setAll(texCoords);
mesh1.getFaces().setAll(faces);
TriangleMesh mesh2 = new TriangleMesh();
mesh2.getPoints().setAll(points);
mesh2.getTexCoords().setAll(texCoords);
mesh2.getFaces().setAll(faces2);
final MeshView rectangle1 = new MeshView(mesh1);
rectangle1.setMaterial(new PhongMaterial(Color.web("#FF0000", 0.25)));
rectangle1.setCullFace(CullFace.BACK);
final MeshView rectangle2 = new MeshView(mesh2);
rectangle2.setMaterial(new PhongMaterial(Color.web("#FF0000", 0.25)));
rectangle2.setCullFace(CullFace.BACK);
final MeshView wire1 = new MeshView(mesh1);
wire1.setMaterial(new PhongMaterial(Color.web("#000000", 0.5)));
wire1.setCullFace(CullFace.BACK);
wire1.setDrawMode(DrawMode.LINE);
final MeshView wire2 = new MeshView(mesh2);
wire2.setMaterial(new PhongMaterial(Color.web("#000000", 0.5)));
wire2.setCullFace(CullFace.BACK);
wire2.setDrawMode(DrawMode.LINE);
// add to group
box.getChildren().addAll(rectangle1, wire1, rectangle2, wire2);
}
return box;
}
示例11: buildSTL
import javafx.scene.shape.MeshView; //导入方法依赖的package包/类
/**Creates a visualization of a .stl file.
*
* @param filePath the absolute file path of the .stl file
* @param color the color the visualized file should have
* @param ambient enables ambient light on the geometry
* @param fill renders the faces or just shows the lines
* @return the visualized STL file as a group node
*/
private Group buildSTL (String filePath,Color color, boolean ambient, boolean fill){
STLReader reader = new STLReader(filePath);
reader.start();
reader.getFacetPoints(0);
reader.getNormal(0);
// reader.readFromAscii();
float[] vertices = reader.getVerticesFloatArray();
float[] normals = reader.getNormalsFloatArray();
TriangleMesh mesh = new TriangleMesh();
mesh.getPoints().addAll(vertices);
mesh.getTexCoords().addAll(0,0);
for (int i = 0; i < vertices.length/3 ; i+=3) {
mesh.getFaces().addAll(i,0, i+1,0,i+2,0);
}
MeshView meshView = new MeshView(mesh);
Group customGroup2 = new Group();
customGroup2.getChildren().add(meshView);
if (null != color) {
PhongMaterial material = new PhongMaterial(color);
meshView.setMaterial(material);
}
if (ambient) {
AmbientLight light = new AmbientLight(Color.WHITE);
light.getScope().add(meshView);
customGroup2.getChildren().add(light);
}
if(fill) {
meshView.setDrawMode(DrawMode.FILL);
} else {
meshView.setDrawMode(DrawMode.LINE); //show lines only by default
}
meshView.setCullFace(CullFace.BACK); //Removing culling to show back lines
return customGroup2;
}
示例12: compile
import javafx.scene.shape.MeshView; //导入方法依赖的package包/类
private void compile(String code) {
csgObject = null;
clearLog();
viewGroup.getChildren().clear();
try {
CompilerConfiguration cc = new CompilerConfiguration();
cc.addCompilationCustomizers(
new ImportCustomizer().
addStarImports("eu.mihosoft.vrl.v3d",
"eu.mihosoft.vrl.v3d.samples").
addStaticStars("eu.mihosoft.vrl.v3d.Transform"));
GroovyShell shell = new GroovyShell(getClass().getClassLoader(),
new Binding(), cc);
Script script = shell.parse(code);
Object obj = script.run();
if (obj instanceof CSG) {
CSG csg = (CSG) obj;
csgObject = csg;
MeshContainer meshContainer = csg.toJavaFXMesh();
final MeshView meshView = meshContainer.getAsMeshViews().get(0);
setMeshScale(meshContainer,
viewContainer.getBoundsInLocal(), meshView);
PhongMaterial m = new PhongMaterial(Color.RED);
meshView.setCullFace(CullFace.NONE);
meshView.setMaterial(m);
viewGroup.layoutXProperty().bind(
viewContainer.widthProperty().divide(2));
viewGroup.layoutYProperty().bind(
viewContainer.heightProperty().divide(2));
viewContainer.boundsInLocalProperty().addListener(
(ov, oldV, newV) -> {
setMeshScale(meshContainer, newV, meshView);
});
VFX3DUtil.addMouseBehavior(meshView,
viewContainer, MouseButton.PRIMARY);
viewGroup.getChildren().add(meshView);
} else {
System.out.println(">> no CSG object returned :(");
}
} catch (Throwable ex) {
ex.printStackTrace(System.err);
}
}