Java 类javafx.scene.shape.Mesh 实例源码

项目:FX3DAndroid    文件:MeshContainer.java   
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;
}
项目:FX3DAndroid    文件:MeshContainer.java   
MeshContainer(Vector3d min, Vector3d max, List<Mesh> meshes) {
    this.meshes = meshes;
    this.materials = new ArrayList<>();
    this.bounds = new Bounds(min, max);
    this.width = bounds.getBounds().x;
    this.height = bounds.getBounds().y;
    this.depth = bounds.getBounds().z;

    PhongMaterial material = new PhongMaterial(Color.RED);
    for (Mesh mesh : meshes) {
        materials.add(material);
    }
}
项目:FX3DAndroid    文件:MeshContainer.java   
MeshContainer(Vector3d min, Vector3d max, List<Mesh> meshes, List<Material> materials) {
    this.meshes = meshes;
    this.materials = materials;
    this.bounds = new Bounds(min, max);
    this.width = bounds.getBounds().x;
    this.height = bounds.getBounds().y;
    this.depth = bounds.getBounds().z;

    if (materials.size() != meshes.size()) {
        throw new IllegalArgumentException("Mesh list and Material list must not differ in size!");
    }

}
项目:FX3DAndroid    文件:Validator.java   
public void validate(Mesh mesh) {
        if (!(mesh instanceof TriangleMesh)) {
            throw new AssertionError("Mesh is not TriangleMesh: " + mesh.getClass() + ", mesh = " + mesh);
        }
        TriangleMesh tMesh = (TriangleMesh) mesh;
        int numPoints = tMesh.getPoints().size() / tMesh.getPointElementSize();
        int numTexCoords = tMesh.getTexCoords().size() / tMesh.getTexCoordElementSize();
        int numFaces = tMesh.getFaces().size() / tMesh.getFaceElementSize();
        if (numPoints == 0 || numPoints * tMesh.getPointElementSize() != tMesh.getPoints().size()) {
            throw new AssertionError("Points array size is not correct: " + tMesh.getPoints().size());
        }
        if (numTexCoords == 0 || numTexCoords * tMesh.getTexCoordElementSize() != tMesh.getTexCoords().size()) {
            throw new AssertionError("TexCoords array size is not correct: " + tMesh.getPoints().size());
        }
        if (numFaces == 0 || numFaces * tMesh.getFaceElementSize() != tMesh.getFaces().size()) {
            throw new AssertionError("Faces array size is not correct: " + tMesh.getPoints().size());
        }
        if (numFaces != tMesh.getFaceSmoothingGroups().size() && tMesh.getFaceSmoothingGroups().size() > 0) {
            throw new AssertionError("FaceSmoothingGroups array size is not correct: " + tMesh.getPoints().size() + ", numFaces = " + numFaces);
        }
        ObservableIntegerArray faces = tMesh.getFaces();
        for (int i = 0; i < faces.size(); i += 2) {
            int pIndex = faces.get(i);
            if (pIndex < 0 || pIndex > numPoints) {
                throw new AssertionError("Incorrect point index: " + pIndex + ", numPoints = " + numPoints);
            }
            int tcIndex = faces.get(i + 1);
            if (tcIndex < 0 || tcIndex > numTexCoords) {
                throw new AssertionError("Incorrect texCoord index: " + tcIndex + ", numTexCoords = " + numTexCoords);
            }
        }
//        System.out.println("Validation successfull of " + mesh);
    }
项目:FX3DAndroid    文件:MeshUtils.java   
public static CSG mesh2CSG(Mesh mesh) throws IOException {

        List<Polygon> polygons = new ArrayList<>();
        List<Vector3d> vertices = new ArrayList<>();
        if(mesh instanceof TriangleMesh){
            // Get faces
            ObservableFaceArray faces = ((TriangleMesh)mesh).getFaces();
            int[] f=new int[faces.size()];
            faces.toArray(f);

            // Get vertices
            ObservableFloatArray points = ((TriangleMesh)mesh).getPoints();
            float[] p = new float[points.size()];
            points.toArray(p);

            // convert faces to polygons
            for(int i=0; i<faces.size()/6; i++){
                int i0=f[6*i], i1=f[6*i+2], i2=f[6*i+4];
                vertices.add(new Vector3d(p[3*i0], p[3*i0+1], p[3*i0+2]));
                vertices.add(new Vector3d(p[3*i1], p[3*i1+1], p[3*i1+2]));
                vertices.add(new Vector3d(p[3*i2], p[3*i2+1], p[3*i2+2]));
                polygons.add(Polygon.fromPoints(vertices));
                vertices = new ArrayList<>();
            }
        }

        return CSG.fromPolygons(new PropertyStorage(),polygons);
    }
项目:minecraft-jfx-skin    文件:SkinCube.java   
public Mesh getModel() {
    return model;
}
项目:minecraft-jfx-skin    文件:SkinCube.java   
public void setModel(Mesh model) {
    this.model = model;
    setMesh(model);
}
项目:FX3DAndroid    文件:MeshContainer.java   
MeshContainer(Vector3d min, Vector3d max, Mesh... meshes) {
    this(min, max, Arrays.asList(meshes));
}
项目:FX3DAndroid    文件:MeshContainer.java   
/**
 * @return the mesh
 */
public List<Mesh> getMeshes() {
    return meshes;
}
项目:FX3DAndroid    文件:MeshUtils.java   
public static void mesh2STL(String fileName, Mesh mesh) throws IOException{

        if(!(mesh instanceof TriangleMesh)){
            return;
        }
        // Get faces
        ObservableFaceArray faces = ((TriangleMesh)mesh).getFaces();
        int[] f=new int[faces.size()];
        faces.toArray(f);

        // Get vertices
        ObservableFloatArray points = ((TriangleMesh)mesh).getPoints();
        float[] p = new float[points.size()];
        points.toArray(p);

        StringBuilder sb = new StringBuilder();
        sb.append("solid meshFX\n");

        // convert faces to polygons
        for(int i=0; i<faces.size()/6; i++){
            int i0=f[6*i], i1=f[6*i+2], i2=f[6*i+4];
            Point3D pA=new Point3D(p[3*i0], p[3*i0+1], p[3*i0+2]);
            Point3D pB=new Point3D(p[3*i1], p[3*i1+1], p[3*i1+2]);
            Point3D pC=new Point3D(p[3*i2], p[3*i2+1], p[3*i2+2]);
            Point3D pN=pB.subtract(pA).crossProduct(pC.subtract(pA)).normalize();

            sb.append("  facet normal ").append(pN.getX()).append(" ").append(pN.getY()).append(" ").append(pN.getZ()).append("\n");
            sb.append("    outer loop\n");
            sb.append("      vertex ").append(pA.getX()).append(" ").append(pA.getY()).append(" ").append(pA.getZ()).append("\n");
            sb.append("      vertex ").append(pB.getX()).append(" ").append(pB.getY()).append(" ").append(pB.getZ()).append("\n");
            sb.append("      vertex ").append(pC.getX()).append(" ").append(pC.getY()).append(" ").append(pC.getZ()).append("\n");
            sb.append("    endloop\n");
            sb.append("  endfacet\n");
        }

        sb.append("endsolid meshFX\n");

        // write file
        try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(fileName), Charset.forName("UTF-8"),
                StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
            writer.write(sb.toString());
        }
    }