Java Code Examples for com.jme3.util.BufferUtils#getVector3Array()

The following examples show how to use com.jme3.util.BufferUtils#getVector3Array() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmitterMeshFaceShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void setMeshes(List<Mesh> meshes) {
    this.vertices = new ArrayList<List<Vector3f>>(meshes.size());
    this.normals = new ArrayList<List<Vector3f>>(meshes.size());
    for (Mesh mesh : meshes) {
        Vector3f[] vertexTable = BufferUtils.getVector3Array(mesh.getFloatBuffer(Type.Position));
        int[] indices = new int[3];
        List<Vector3f> vertices = new ArrayList<Vector3f>(mesh.getTriangleCount() * 3);
        List<Vector3f> normals = new ArrayList<Vector3f>(mesh.getTriangleCount());
        for (int i = 0; i < mesh.getTriangleCount(); ++i) {
            mesh.getTriangle(i, indices);
            vertices.add(vertexTable[indices[0]]);
            vertices.add(vertexTable[indices[1]]);
            vertices.add(vertexTable[indices[2]]);
            normals.add(FastMath.computeNormal(vertexTable[indices[0]], vertexTable[indices[1]], vertexTable[indices[2]]));
        }
        this.vertices.add(vertices);
        this.normals.add(normals);
    }
}
 
Example 2
Source File: CurvesHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * The method generates normal buffer for the created mesh of the curve.
 * 
 * @param indexes
 *            the indexes of the mesh points
 * @param points
 *            the mesh's points
 * @param smooth
 *            the flag indicating if the result is to be smooth or solid
 * @return normals buffer for the mesh
 */
private FloatBuffer generateNormals(IndexBuffer indexes, FloatBuffer points, boolean smooth) {
    Map<Integer, Vector3f> normalMap = new TreeMap<Integer, Vector3f>();
    Vector3f[] allVerts = BufferUtils.getVector3Array(points);

    for (int i = 0; i < indexes.size(); i += 3) {
        int index1 = indexes.get(i);
        int index2 = indexes.get(i + 1);
        int index3 = indexes.get(i + 2);

        Vector3f n = FastMath.computeNormal(allVerts[index1], allVerts[index2], allVerts[index3]);
        this.addNormal(n, normalMap, smooth, index1, index2, index3);
    }

    FloatBuffer normals = BufferUtils.createFloatBuffer(normalMap.size() * 3);
    for (Entry<Integer, Vector3f> entry : normalMap.entrySet()) {
        normals.put(entry.getValue().x);
        normals.put(entry.getValue().y);
        normals.put(entry.getValue().z);
    }
    return normals;
}
 
Example 3
Source File: EmitterMeshFaceShape.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void setMeshes(List<Mesh> meshes) {
    this.vertices = new ArrayList<List<Vector3f>>(meshes.size());
    this.normals = new ArrayList<List<Vector3f>>(meshes.size());
    for (Mesh mesh : meshes) {
        Vector3f[] vertexTable = BufferUtils.getVector3Array(mesh.getFloatBuffer(Type.Position));
        int[] indices = new int[3];
        List<Vector3f> vertices = new ArrayList<Vector3f>(mesh.getTriangleCount() * 3);
        List<Vector3f> normals = new ArrayList<Vector3f>(mesh.getTriangleCount());
        for (int i = 0; i < mesh.getTriangleCount(); ++i) {
            mesh.getTriangle(i, indices);
            vertices.add(vertexTable[indices[0]]);
            vertices.add(vertexTable[indices[1]]);
            vertices.add(vertexTable[indices[2]]);
            normals.add(FastMath.computeNormal(vertexTable[indices[0]], vertexTable[indices[1]], vertexTable[indices[2]]));
        }
        this.vertices.add(vertices);
        this.normals.add(normals);
    }
}