Search in sources :

Example 41 with VertexBuffer

use of com.jme3.scene.VertexBuffer 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 42 with VertexBuffer

use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.

the class TangentBinormalGenerator method genNormalLines.

public static Mesh genNormalLines(Mesh mesh, float scale) {
    FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
    FloatBuffer normalBuffer = (FloatBuffer) mesh.getBuffer(Type.Normal).getData();
    ColorRGBA originColor = ColorRGBA.White;
    ColorRGBA normalColor = ColorRGBA.Blue;
    Mesh lineMesh = new Mesh();
    lineMesh.setMode(Mesh.Mode.Lines);
    Vector3f origin = new Vector3f();
    Vector3f point = new Vector3f();
    FloatBuffer lineVertex = BufferUtils.createFloatBuffer(vertexBuffer.limit() * 2);
    FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.limit() / 3 * 4 * 2);
    for (int i = 0; i < vertexBuffer.limit() / 3; i++) {
        populateFromBuffer(origin, vertexBuffer, i);
        populateFromBuffer(point, normalBuffer, i);
        int index = i * 2;
        setInBuffer(origin, lineVertex, index);
        setInBuffer(originColor, lineColor, index);
        point.multLocal(scale);
        point.addLocal(origin);
        setInBuffer(point, lineVertex, index + 1);
        setInBuffer(normalColor, lineColor, index + 1);
    }
    lineMesh.setBuffer(Type.Position, 3, lineVertex);
    lineMesh.setBuffer(Type.Color, 4, lineColor);
    lineMesh.setStatic();
    //lineMesh.setInterleaved();
    return lineMesh;
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) Vector3f(com.jme3.math.Vector3f) FloatBuffer(java.nio.FloatBuffer)

Example 43 with VertexBuffer

use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.

the class MikkTSpaceImpl method getTexCoord.

@Override
public void getTexCoord(float[] texOut, int face, int vert) {
    int vertIndex = getIndex(face, vert);
    VertexBuffer texCoord = mesh.getBuffer(VertexBuffer.Type.TexCoord);
    FloatBuffer tex = (FloatBuffer) texCoord.getData();
    tex.position(vertIndex * 2);
    texOut[0] = tex.get();
    texOut[1] = tex.get();
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer)

Example 44 with VertexBuffer

use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.

the class TestVertexBufferSharing method initOpenCL2.

private void initOpenCL2() {
    //bind vertex buffer to OpenCL
    VertexBuffer vb = geom.getMesh().getBuffer(VertexBuffer.Type.Position);
    buffer = clContext.bindVertexBuffer(vb, MemoryAccess.READ_WRITE).register();
    ws = new com.jme3.opencl.Kernel.WorkSize(geom.getMesh().getVertexCount());
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer)

Example 45 with VertexBuffer

use of com.jme3.scene.VertexBuffer in project jmonkeyengine by jMonkeyEngine.

the class TestLodGeneration method makeLod.

private void makeLod(final LodGenerator.TriangleReductionMethod method, final float value, final int ll) {
    exec.execute(new Runnable() {

        public void run() {
            for (final Geometry geometry : listGeoms) {
                LodGenerator lODGenerator = new LodGenerator(geometry);
                final VertexBuffer[] lods = lODGenerator.computeLods(method, value);
                enqueue(new Callable<Void>() {

                    public Void call() throws Exception {
                        geometry.getMesh().setLodLevels(lods);
                        lodLevel = 0;
                        if (geometry.getMesh().getNumLodLevels() > ll) {
                            lodLevel = ll;
                        }
                        geometry.setLodLevel(lodLevel);
                        hudText.setText(computeNbTri() + " tris");
                        return null;
                    }
                });
            }
        }
    });
}
Also used : Geometry(com.jme3.scene.Geometry) LodGenerator(jme3tools.optimize.LodGenerator) Callable(java.util.concurrent.Callable)

Aggregations

FloatBuffer (java.nio.FloatBuffer)42 VertexBuffer (com.jme3.scene.VertexBuffer)40 Vector3f (com.jme3.math.Vector3f)17 ByteBuffer (java.nio.ByteBuffer)12 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)9 ShortBuffer (java.nio.ShortBuffer)9 IntBuffer (java.nio.IntBuffer)8 Buffer (java.nio.Buffer)6 Geometry (com.jme3.scene.Geometry)5 Mesh (com.jme3.scene.Mesh)5 Bone (com.jme3.animation.Bone)4 Matrix4f (com.jme3.math.Matrix4f)4 Vector2f (com.jme3.math.Vector2f)4 ArrayList (java.util.ArrayList)4 Material (com.jme3.material.Material)3 ColorRGBA (com.jme3.math.ColorRGBA)3 Type (com.jme3.scene.VertexBuffer.Type)3 TempVars (com.jme3.util.TempVars)3 HashMap (java.util.HashMap)3 BoundingBox (com.jme3.bounding.BoundingBox)2