本文整理汇总了Java中javafx.scene.shape.TriangleMesh类的典型用法代码示例。如果您正苦于以下问题:Java TriangleMesh类的具体用法?Java TriangleMesh怎么用?Java TriangleMesh使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TriangleMesh类属于javafx.scene.shape包,在下文中一共展示了TriangleMesh类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkConstruct
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
@Override
public boolean checkConstruct() {
try {
triMesh = new TriangleMesh();
triMesh.getFaces().addAll(faces);
triMesh.getPoints().addAll(points);
triMesh.getTexCoords().addAll(texCoords);
if (!checkPoints(triMesh.getPoints())
|| !checkFaces(triMesh.getFaces())
|| !checkTexCoords(triMesh.getTexCoords())) {
return false;
}
} catch (Throwable t) {
t.printStackTrace();
return false;
}
meshView.setMesh(triMesh);
return true;
}
示例2: calcSmoothGroups
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
/**
* Calculates smoothing groups for data formatted in TriangleMesh style
* @param flatFaces An array of faces, where each triangle face is represented by 6 (vertex and uv) indices
* @param flatFaceNormals An array of face normals, where each triangle face is represented by 3 normal indices
* @param normals The array of normals
* @return An array of smooth groups, where the length of the array is the number of faces
*/
public static int[] calcSmoothGroups(TriangleMesh mesh, int[] flatFaces, int[] flatFaceNormals, float[] normals) {
int faceElementSize = mesh.getFaceElementSize();
int[][] faces = new int[flatFaces.length/faceElementSize][faceElementSize];
for (int f = 0; f < faces.length; f++) {
for (int e = 0; e < faceElementSize; e++) {
faces[f][e] = flatFaces[f * faceElementSize + e];
}
}
int pointElementSize = mesh.getPointElementSize();
int[][] faceNormals = new int[flatFaceNormals.length/pointElementSize][pointElementSize];
for (int f = 0; f < faceNormals.length; f++) {
for (int e = 0; e < pointElementSize; e++) {
faceNormals[f][e] = flatFaceNormals[f * pointElementSize + e];
}
}
SmoothingGroups smoothGroups = new SmoothingGroups(faces, faceNormals, normals);
return smoothGroups.calcSmoothGroups();
}
示例3: createMesh
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
protected TriangleMesh createMesh(MeshHelper mh) {
float[] points0=mh.getPoints();
float[] f = mh.getF();
listVertices.clear();
listVertices.addAll(IntStream.range(0, points0.length/3)
.mapToObj(i -> new Point3D(points0[3*i], points0[3*i+1], points0[3*i+2],f[i]))
.collect(Collectors.toList()));
textureCoords=mh.getTexCoords();
int[] faces0 = mh.getFaces();
listFaces.clear();
listFaces.addAll(IntStream.range(0, faces0.length/6)
.mapToObj(i -> new Face3(faces0[6*i+0], faces0[6*i+2], faces0[6*i+4]))
.collect(Collectors.toList()));
listTextures.clear();
// listTextures.addAll(listFaces);
listTextures.addAll(IntStream.range(0, faces0.length/6)
.mapToObj(i -> new Face3(faces0[6*i+1], faces0[6*i+3], faces0[6*i+5]))
.collect(Collectors.toList()));
smoothingGroups=mh.getFaceSmoothingGroups();
return createMesh();
}
示例4: createMesh
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
protected TriangleMesh createMesh(MeshHelper mh) {
float[] points0=mh.getPoints();
float[] f = mh.getF();
listVertices.clear();
listVertices.addAll(IntStreams.range(0, points0.length/3)
.mapToObj(i -> new Point3D(points0[3*i], points0[3*i+1], points0[3*i+2],f[i]))
.collect(Collectors.toList()));
textureCoords=mh.getTexCoords();
int[] faces0 = mh.getFaces();
listFaces.clear();
listFaces.addAll(IntStreams.range(0, faces0.length/6)
.mapToObj(i -> new Face3(faces0[6*i+0], faces0[6*i+2], faces0[6*i+4]))
.collect(Collectors.toList()));
listTextures.clear();
// listTextures.addAll(listFaces);
listTextures.addAll(IntStreams.range(0, faces0.length/6)
.mapToObj(i -> new Face3(faces0[6*i+1], faces0[6*i+3], faces0[6*i+5]))
.collect(Collectors.toList()));
smoothingGroups=mh.getFaceSmoothingGroups();
return createMesh();
}
示例5: load
import javafx.scene.shape.TriangleMesh; //导入依赖的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: buildTriMesh
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
private TriangleMesh buildTriMesh() {
points = buildPoints();
texCoords = buildTexCoords();
faces = buildFaces();
smoothingGroups = null;
TriangleMesh tmesh = new TriangleMesh();
tmesh.getFaces().addAll(faces);
tmesh.getPoints().addAll(points);
tmesh.getTexCoords().addAll(texCoords);
return tmesh;
}
示例7: buildTriangleMesh
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
private TriangleMesh buildTriangleMesh(int subDivX, int subDivY,
float scale, int smooth) {
TriangleMesh triangleMesh = new TriangleMesh();
triangleMesh.getPoints().addAll(getPoints(subDivX, subDivY, scale));
triangleMesh.getTexCoords().addAll(getTexCoords(subDivX, subDivY));
triangleMesh.getFaces().addAll(getFaces(subDivX, subDivY));
return triangleMesh;
}
示例8: getMeshNormal
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
private static Point3D getMeshNormal(MeshView mesh){
TriangleMesh tm = (TriangleMesh) mesh.getMesh();
float[] fPoints = new float[tm.getPoints().size()];
tm.getPoints().toArray(fPoints);
Point3D BA = new Point3D(fPoints[3] - fPoints[0], fPoints[4] - fPoints[1], fPoints[5] - fPoints[2]);
Point3D CA = new Point3D(fPoints[6] - fPoints[0], fPoints[7] - fPoints[1], fPoints[8] - fPoints[2]);
Point3D normal = BA.crossProduct(CA);
Affine a = new Affine(mesh.getTransforms().get(0));
return a.transform(normal.normalize());
}
示例9: getMesh
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
@Override
public TriangleMesh getMesh(String type) {
// Save the retrieved mesh
last = super.getMesh(type);
return last;
}
示例10: Plane
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
/**
*
* @param width
* @param height
* @param depth
*/
public Plane(double width, double height, double depth, int segments) {
TriangleMesh mesh = new TriangleMesh();
mesh.setVertexFormat(VertexFormat.POINT_TEXCOORD);
generatePlane(mesh, width, height, depth, segments);
}
示例11: createTrapezoid
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
private TriangleMesh createTrapezoid (double smallSize , double bigSize , double high ,double depth){
TriangleMesh m = new TriangleMesh();
float s = ((float)smallSize) ;
float b = ((float)bigSize);
float h = ((float)high);
float d = ((float)depth);
//create Points
m.getPoints().addAll(
-s/2 , -h/2 , d/2, // A = 0
s/2 , -h/2 , d/2, // B = 1
-b/2 , h/2 , d/2, // C = 2
b/2 , h/2 , d/2, // D = 3
-s/2 , -h/2 , -d/2, // E = 4
s/2 , -h/2 , -d/2, // F = 5
-b/2 , h/2 , -d/2, // G = 6
b/2 , h/2 , -d/2 // H = 7
);
m.getTexCoords().addAll(0,0);
m.getFaces().addAll(
0 , 0 , 1 , 0 , 3 , 0 , // A-B-D
0 , 0 , 3 , 0 , 2 , 0 , // A-D-C
0 , 0 , 2 , 0 , 6 , 0 , // A-C-G
0 , 0 , 6 , 0 , 4 , 0 , // A-G-E
0 , 0 , 4 , 0 , 1 , 0 , // A-E-B
1 , 0 , 4 , 0 , 5 , 0 , // B-E-F
1 , 0 , 5 , 0 , 7 , 0 , // B-F-H
1 , 0 , 7 , 0 , 3 , 0 , // B-H-D
3 , 0 , 7 , 0 , 6 , 0 , // D-H-G
3 , 0 , 6 , 0 , 2 , 0 , // D-G-C
6 , 0 , 7 , 0 , 5 , 0 , // G-H-F
6 , 0 , 5 , 0 , 4 , 0 // G-F-E
);
return m ;
}
示例12: MeshHelper
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
public MeshHelper(TriangleMesh tm) {
this.points = tm.getPoints().toArray(points);
this.texCoords = tm.getTexCoords().toArray(texCoords);
this.faces = tm.getFaces().toArray(faces);
this.faceSmoothingGroups = tm.getFaceSmoothingGroups().toArray(faceSmoothingGroups);
this.f=new float[points.length/3];
}
示例13: createCone
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
private TriangleMesh createCone(int divisions, float radius, float height) {
TriangleMesh mesh = new TriangleMesh();
//Start with the top of the cone, later we will build our faces from these
mesh.getPoints().addAll(0,0,0); //Point 0: Top of the Cone
//Generate the segments of the bottom circle (Cone Base)
double segment_angle = 2.0 * Math.PI / divisions;
float x, z;
double angle;
double halfCount = (Math.PI / 2 - Math.PI / (divisions / 2));
// Reverse loop for speed!! der
for(int i=divisions+1;--i >= 0; ) {
angle = segment_angle * i;
x = (float)(radius * Math.cos(angle - halfCount));
z = (float)(radius * Math.sin(angle - halfCount));
mesh.getPoints().addAll(x,height,z);
}
mesh.getPoints().addAll(0,height,0); //Point N: Center of the Cone Base
//@TODO Birdasaur for now we'll just make an empty texCoordinate group
//@DUB HELP ME DUBi Wan Kanobi, you are my only hope!
//I'm not good at determining Texture Coordinates
mesh.getTexCoords().addAll(0,0);
//Add the faces "winding" the points generally counter clock wise
//Must loop through each face, not including first and last points
for(int i=1;i<=divisions;i++) {
mesh.getFaces().addAll( //use dummy texCoords, @TODO Upgrade face code to be real
0,0,i+1,0,i,0, // Vertical Faces "wind" counter clockwise
divisions+2,0,i,0,i+1,0 // Base Faces "wind" clockwise
);
}
return mesh;
}
示例14: createPyramid
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
private TriangleMesh createPyramid(double hypotenuse , double height){
TriangleMesh mesh = new TriangleMesh();
float hy = (float)hypotenuse;
float he = (float)height;
mesh.getPoints().addAll(
0 , 0 , 0, //point O
0 , he , -hy/2, //point A
-hy/2, he , 0, //point B
hy/2, he , 0, //point C
0 , he , hy/2 //point D
);
mesh.getTexCoords().addAll(0,0);
mesh.getFaces().addAll(
0 , 0 , 2 , 0 , 1 , 0 , // O-B-A
0 , 0 , 1 , 0 , 3 , 0 , // O-A-C
0 , 0 , 3 , 0 , 4 , 0 , // O-C-D
0 , 0 , 4 , 0 , 2 , 0 , // O-D-B
4 , 0 , 1 , 0 , 2 , 0 , // D-A-B
4 , 0 , 3 , 0 , 1 , 0 // D-C-A
);
return mesh;
}
示例15: createOctahedron
import javafx.scene.shape.TriangleMesh; //导入依赖的package包/类
private TriangleMesh createOctahedron(double hypotenuse , double height){
TriangleMesh mesh = new TriangleMesh();
float hy = (float)hypotenuse;
float he = (float)height;
mesh.getPoints().addAll(
0 , 0 , 0, //point O
0 , he , -hy/2, //point A
-hy/2, he , 0, //point B
hy/2, he , 0, //point C
0 , he , hy/2, //point D
0 , 2*he , 0 //point E
);
mesh.getTexCoords().addAll(0,0);
mesh.getFaces().addAll(
0 , 0 , 2 , 0 , 1 , 0 , // O-B-A
0 , 0 , 1 , 0 , 3 , 0 , // O-A-C
0 , 0 , 3 , 0 , 4 , 0 , // O-C-D
0 , 0 , 4 , 0 , 2 , 0 , // O-D-B
4 , 0 , 1 , 0 , 2 , 0 , // D-A-B
4 , 0 , 3 , 0 , 1 , 0 , // D-C-A
5 , 0 , 2 , 0 , 1 , 0 , // E-B-A
5 , 0 , 1 , 0 , 3 , 0 , // E-A-C
5 , 0 , 3 , 0 , 4 , 0 , // E-C-D
5 , 0 , 4 , 0 , 2 , 0 // E-D-B
);
return mesh;
}