Search in sources :

Example 71 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class TangentBinormalGenerator method processTriangles.

private static List<VertexData> processTriangles(Mesh mesh, int[] index, Vector3f[] v, Vector2f[] t, boolean splitMirrored) {
    IndexBuffer indexBuffer = mesh.getIndexBuffer();
    FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
    if (mesh.getBuffer(Type.TexCoord) == null) {
        throw new IllegalArgumentException("Can only generate tangents for " + "meshes with texture coordinates");
    }
    FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();
    List<VertexData> vertices = initVertexData(vertexBuffer.limit() / 3);
    for (int i = 0; i < indexBuffer.size() / 3; i++) {
        for (int j = 0; j < 3; j++) {
            index[j] = indexBuffer.get(i * 3 + j);
            populateFromBuffer(v[j], vertexBuffer, index[j]);
            populateFromBuffer(t[j], textureBuffer, index[j]);
        }
        TriangleData triData = processTriangle(index, v, t);
        if (splitMirrored) {
            triData.setIndex(index);
            triData.triangleOffset = i * 3;
        }
        vertices.get(index[0]).triangles.add(triData);
        vertices.get(index[1]).triangles.add(triData);
        vertices.get(index[2]).triangles.add(triData);
    }
    return vertices;
}
Also used : IndexBuffer(com.jme3.scene.mesh.IndexBuffer) FloatBuffer(java.nio.FloatBuffer)

Example 72 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class TangentBinormalGenerator method generate.

public static void generate(Mesh mesh, boolean approxTangents, boolean splitMirrored) {
    int[] index = new int[3];
    Vector3f[] v = new Vector3f[3];
    Vector2f[] t = new Vector2f[3];
    for (int i = 0; i < 3; i++) {
        v[i] = new Vector3f();
        t[i] = new Vector2f();
    }
    if (mesh.getBuffer(Type.Normal) == null) {
        throw new IllegalArgumentException("The given mesh has no normal data!");
    }
    List<VertexData> vertices;
    switch(mesh.getMode()) {
        case Triangles:
            vertices = processTriangles(mesh, index, v, t, splitMirrored);
            if (splitMirrored) {
                splitVertices(mesh, vertices, splitMirrored);
            }
            break;
        case TriangleStrip:
            vertices = processTriangleStrip(mesh, index, v, t);
            break;
        case TriangleFan:
            vertices = processTriangleFan(mesh, index, v, t);
            break;
        default:
            throw new UnsupportedOperationException(mesh.getMode() + " is not supported.");
    }
    processTriangleData(mesh, vertices, approxTangents, splitMirrored);
    //if the mesh has a bind pose, we need to generate the bind pose for the tangent buffer
    TangentUtils.generateBindPoseTangentsIfNecessary(mesh);
}
Also used : Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f)

Example 73 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class TangentBinormalGenerator method processTriangleStrip.

private static List<VertexData> processTriangleStrip(Mesh mesh, int[] index, Vector3f[] v, Vector2f[] t) {
    IndexBuffer indexBuffer = mesh.getIndexBuffer();
    FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
    FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();
    List<VertexData> vertices = initVertexData(vertexBuffer.limit() / 3);
    index[0] = indexBuffer.get(0);
    index[1] = indexBuffer.get(1);
    populateFromBuffer(v[0], vertexBuffer, index[0]);
    populateFromBuffer(v[1], vertexBuffer, index[1]);
    populateFromBuffer(t[0], textureBuffer, index[0]);
    populateFromBuffer(t[1], textureBuffer, index[1]);
    for (int i = 2; i < indexBuffer.size(); i++) {
        index[2] = indexBuffer.get(i);
        BufferUtils.populateFromBuffer(v[2], vertexBuffer, index[2]);
        BufferUtils.populateFromBuffer(t[2], textureBuffer, index[2]);
        boolean isDegenerate = isDegenerateTriangle(v[0], v[1], v[2]);
        TriangleData triData = processTriangle(index, v, t);
        if (!isDegenerate) {
            vertices.get(index[0]).triangles.add(triData);
            vertices.get(index[1]).triangles.add(triData);
            vertices.get(index[2]).triangles.add(triData);
        }
        Vector3f vTemp = v[0];
        v[0] = v[1];
        v[1] = v[2];
        v[2] = vTemp;
        Vector2f tTemp = t[0];
        t[0] = t[1];
        t[1] = t[2];
        t[2] = tTemp;
        index[0] = index[1];
        index[1] = index[2];
    }
    return vertices;
}
Also used : IndexBuffer(com.jme3.scene.mesh.IndexBuffer) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) FloatBuffer(java.nio.FloatBuffer)

Example 74 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class BufferUtils method multInBuffer.

/**
     * Multiply and store a Vector2f in-buffer.
     * 
     * @param toMult
     *            the vector to multiply against
     * @param buf
     *            the buffer to find the Vector2f within
     * @param index
     *            the position (in terms of vectors, not floats) of the vector
     *            to multiply
     */
public static void multInBuffer(Vector2f toMult, FloatBuffer buf, int index) {
    TempVars vars = TempVars.get();
    Vector2f tempVec2 = vars.vect2d;
    populateFromBuffer(tempVec2, buf, index);
    tempVec2.multLocal(toMult);
    setInBuffer(tempVec2, buf, index);
    vars.release();
}
Also used : Vector2f(com.jme3.math.Vector2f)

Example 75 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class BufferUtils method addInBuffer.

/**
     * Add to a Vector2f in-buffer.
     * 
     * @param toAdd
     *            the vector to add from
     * @param buf
     *            the buffer to find the Vector2f within
     * @param index
     *            the position (in terms of vectors, not floats) of the vector
     *            to add to
     */
public static void addInBuffer(Vector2f toAdd, FloatBuffer buf, int index) {
    TempVars vars = TempVars.get();
    Vector2f tempVec2 = vars.vect2d;
    populateFromBuffer(tempVec2, buf, index);
    tempVec2.addLocal(toAdd);
    setInBuffer(tempVec2, buf, index);
    vars.release();
}
Also used : Vector2f(com.jme3.math.Vector2f)

Aggregations

Vector2f (com.jme3.math.Vector2f)80 Vector3f (com.jme3.math.Vector3f)38 Geometry (com.jme3.scene.Geometry)22 Material (com.jme3.material.Material)20 Box (com.jme3.scene.shape.Box)17 ArrayList (java.util.ArrayList)14 Texture (com.jme3.texture.Texture)9 List (java.util.List)9 Node (com.jme3.scene.Node)8 Sphere (com.jme3.scene.shape.Sphere)8 FloatBuffer (java.nio.FloatBuffer)8 InputCapsule (com.jme3.export.InputCapsule)7 Spatial (com.jme3.scene.Spatial)7 DirectionalLight (com.jme3.light.DirectionalLight)6 Mesh (com.jme3.scene.Mesh)6 AmbientLight (com.jme3.light.AmbientLight)5 Quad (com.jme3.scene.shape.Quad)5 BoundingBox (com.jme3.bounding.BoundingBox)4 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)4 CollisionResult (com.jme3.collision.CollisionResult)4