Search in sources :

Example 11 with VertexBuffer

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

the class Arrow method setArrowExtent.

/**
     * Sets the arrow's extent.
     * This will modify the buffers on the mesh.
     * 
     * @param extent the arrow's extent.
     */
public void setArrowExtent(Vector3f extent) {
    float len = extent.length();
    //        Vector3f dir = extent.normalize();
    tempQuat.lookAt(extent, Vector3f.UNIT_Y);
    tempQuat.normalizeLocal();
    VertexBuffer pvb = getBuffer(Type.Position);
    FloatBuffer buffer = (FloatBuffer) pvb.getData();
    buffer.rewind();
    for (int i = 0; i < positions.length; i += 3) {
        Vector3f vec = tempVec.set(positions[i], positions[i + 1], positions[i + 2]);
        vec.multLocal(len);
        tempQuat.mult(vec, vec);
        buffer.put(vec.x);
        buffer.put(vec.y);
        buffer.put(vec.z);
    }
    pvb.updateData(buffer);
    updateBound();
    updateCounts();
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) Vector3f(com.jme3.math.Vector3f) FloatBuffer(java.nio.FloatBuffer)

Example 12 with VertexBuffer

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

the class WireFrustum method update.

public void update(Vector3f[] points) {
    VertexBuffer vb = getBuffer(Type.Position);
    if (vb == null) {
        setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(points));
        return;
    }
    FloatBuffer b = BufferUtils.createFloatBuffer(points);
    FloatBuffer a = (FloatBuffer) vb.getData();
    b.rewind();
    a.rewind();
    a.put(b);
    a.rewind();
    vb.updateData(a);
    updateBound();
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer)

Example 13 with VertexBuffer

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

the class WireSphere method updatePositions.

public void updatePositions(float radius) {
    VertexBuffer pvb = getBuffer(Type.Position);
    FloatBuffer pb;
    if (pvb == null) {
        pvb = new VertexBuffer(Type.Position);
        pb = BufferUtils.createVector3Buffer(samples * 2 + samples * zSamples);
        pvb.setupData(Usage.Dynamic, 3, Format.Float, pb);
        setBuffer(pvb);
    } else {
        pb = (FloatBuffer) pvb.getData();
    }
    pb.rewind();
    // X axis
    //        pb.put(radius).put(0).put(0);
    //        pb.put(-radius).put(0).put(0);
    //
    //        // Y axis
    //        pb.put(0).put(radius).put(0);
    //        pb.put(0).put(-radius).put(0);
    //
    //        // Z axis
    //        pb.put(0).put(0).put(radius);
    //        pb.put(0).put(0).put(-radius);
    float rate = FastMath.TWO_PI / (float) samples;
    float angle = 0;
    for (int i = 0; i < samples; i++) {
        float x = radius * FastMath.cos(angle);
        float y = radius * FastMath.sin(angle);
        pb.put(x).put(y).put(0);
        angle += rate;
    }
    angle = 0;
    for (int i = 0; i < samples; i++) {
        float x = radius * FastMath.cos(angle);
        float y = radius * FastMath.sin(angle);
        pb.put(0).put(x).put(y);
        angle += rate;
    }
    float zRate = (radius * 2) / (float) (zSamples);
    float zHeight = -radius + (zRate / 2f);
    float rb = 1f / zSamples;
    float b = rb / 2f;
    for (int k = 0; k < zSamples; k++) {
        angle = 0;
        float scale = FastMath.sin(b * FastMath.PI);
        for (int i = 0; i < samples; i++) {
            float x = radius * FastMath.cos(angle);
            float y = radius * FastMath.sin(angle);
            pb.put(x * scale).put(zHeight).put(y * scale);
            angle += rate;
        }
        zHeight += zRate;
        b += rb;
    }
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer)

Example 14 with VertexBuffer

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

the class TerrainPatch method setHeight.

protected void setHeight(List<LocationHeight> locationHeights, boolean overrideHeight) {
    final float[] heightArray = geomap.getHeightArray();
    final VertexBuffer vertexBuffer = mesh.getBuffer(Type.Position);
    final FloatBuffer floatBuffer = mesh.getFloatBuffer(Type.Position);
    for (LocationHeight lh : locationHeights) {
        if (lh.x < 0 || lh.z < 0 || lh.x >= size || lh.z >= size) {
            continue;
        }
        int idx = lh.z * size + lh.x;
        if (overrideHeight) {
            heightArray[idx] = lh.h;
        } else {
            float currentHeight = floatBuffer.get(idx * 3 + 1);
            heightArray[idx] = currentHeight + lh.h;
        }
    }
    floatBuffer.clear();
    geomap.writeVertexArray(floatBuffer, stepScale, false);
    vertexBuffer.setUpdateNeeded();
}
Also used : LocationHeight(com.jme3.terrain.geomipmap.TerrainQuad.LocationHeight) VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer)

Example 15 with VertexBuffer

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

the class TerrainPatch method setInBuffer.

private void setInBuffer(Mesh mesh, int index, Vector3f normal, Vector3f tangent, Vector3f binormal) {
    VertexBuffer NB = mesh.getBuffer(Type.Normal);
    VertexBuffer TB = mesh.getBuffer(Type.Tangent);
    VertexBuffer BB = mesh.getBuffer(Type.Binormal);
    BufferUtils.setInBuffer(normal, (FloatBuffer) NB.getData(), index);
    BufferUtils.setInBuffer(tangent, (FloatBuffer) TB.getData(), index);
    BufferUtils.setInBuffer(binormal, (FloatBuffer) BB.getData(), index);
    NB.setUpdateNeeded();
    TB.setUpdateNeeded();
    BB.setUpdateNeeded();
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer)

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