Search in sources :

Example 56 with VertexBuffer

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

the class SkeletonWire method updateGeometry.

/**
     * The method updates the geometry according to the poitions of the bones.
     */
public void updateGeometry() {
    VertexBuffer vb = this.getBuffer(Type.Position);
    FloatBuffer posBuf = this.getFloatBuffer(Type.Position);
    posBuf.clear();
    for (int i = 0; i < skeleton.getBoneCount(); ++i) {
        Bone bone = skeleton.getBone(i);
        Vector3f head = bone.getModelSpacePosition();
        posBuf.put(head.getX()).put(head.getY()).put(head.getZ());
        if (boneLengths != null) {
            Vector3f tail = head.add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i))));
            posBuf.put(tail.getX()).put(tail.getY()).put(tail.getZ());
        }
    }
    posBuf.flip();
    vb.updateData(posBuf);
    this.updateBound();
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) Vector3f(com.jme3.math.Vector3f) FloatBuffer(java.nio.FloatBuffer) Bone(com.jme3.animation.Bone)

Example 57 with VertexBuffer

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

the class WireBox method updatePositions.

public void updatePositions(float xExt, float yExt, float zExt) {
    VertexBuffer pvb = getBuffer(Type.Position);
    FloatBuffer pb;
    if (pvb == null) {
        pvb = new VertexBuffer(Type.Position);
        pb = BufferUtils.createVector3Buffer(8);
        pvb.setupData(Usage.Dynamic, 3, Format.Float, pb);
        setBuffer(pvb);
    } else {
        pb = (FloatBuffer) pvb.getData();
        pvb.updateData(pb);
    }
    pb.rewind();
    pb.put(new float[] { -xExt, -yExt, zExt, xExt, -yExt, zExt, xExt, yExt, zExt, -xExt, yExt, zExt, -xExt, -yExt, -zExt, xExt, -yExt, -zExt, xExt, yExt, -zExt, -xExt, yExt, -zExt });
    updateBound();
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer)

Example 58 with VertexBuffer

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

the class Line method updatePoints.

/**
     * Update the start and end points of the line.
     */
public void updatePoints(Vector3f start, Vector3f end) {
    VertexBuffer posBuf = getBuffer(Type.Position);
    FloatBuffer fb = (FloatBuffer) posBuf.getData();
    fb.rewind();
    fb.put(start.x).put(start.y).put(start.z);
    fb.put(end.x).put(end.y).put(end.z);
    posBuf.updateData(fb);
    updateBound();
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer)

Example 59 with VertexBuffer

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

the class LodGenerator method gatherIndexData.

private void gatherIndexData(Mesh mesh, List<Vertex> vertexLookup) {
    VertexBuffer indexBuffer = mesh.getBuffer(VertexBuffer.Type.Index);
    indexCount = indexBuffer.getNumElements() * 3;
    Buffer b = indexBuffer.getDataReadOnly();
    b.rewind();
    while (b.remaining() != 0) {
        Triangle tri = new Triangle();
        tri.isRemoved = false;
        triangleList.add(tri);
        for (int i = 0; i < 3; i++) {
            if (b instanceof IntBuffer) {
                tri.vertexId[i] = ((IntBuffer) b).get();
            } else {
                //bit shift to avoid negative values due to conversion form short to int.
                //we need an unsigned int here.
                tri.vertexId[i] = ((ShortBuffer) b).get() & 0xffff;
            }
            // assert (tri.vertexId[i] < vertexLookup.size());
            tri.vertex[i] = vertexLookup.get(tri.vertexId[i]);
            //debug only;
            tri.vertex[i].index = tri.vertexId[i];
        }
        if (tri.isMalformed()) {
            if (!tri.isRemoved) {
                logger.log(Level.FINE, "malformed triangle found with ID:{0}\n{1} It will be excluded from Lod level calculations.", new Object[] { triangleList.indexOf(tri), tri.toString() });
                tri.isRemoved = true;
                indexCount -= 3;
            }
        } else {
            tri.computeNormal();
            addTriangleToEdges(tri);
        }
    }
    b.rewind();
}
Also used : VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer) ShortBuffer(java.nio.ShortBuffer) IntBuffer(java.nio.IntBuffer) Buffer(java.nio.Buffer) VertexBuffer(com.jme3.scene.VertexBuffer) IntBuffer(java.nio.IntBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 60 with VertexBuffer

use of com.jme3.scene.VertexBuffer in project chordatlas by twak.

the class TexGen method setTexture.

protected void setTexture(Geometry g, Material mat, int[] texSize, BufferedImage srcPano, File writeTo) {
    if (!autoProject)
        return;
    if (cancel != null)
        cancel.cancel();
    cancel = new Cancellable();
    new Thread() {

        public void run() {
            VertexBuffer vb = g.getMesh().getBuffer(VertexBuffer.Type.TexCoord);
            VertexBuffer ib = g.getMesh().getBuffer(VertexBuffer.Type.Index);
            VertexBuffer pb = g.getMesh().getBuffer(VertexBuffer.Type.Position);
            float[][] pts = new float[3][3], uvs = new float[3][2];
            BufferedImage target = new BufferedImage(texSize[0], texSize[1], BufferedImage.TYPE_3BYTE_BGR);
            // if (false) {
            for (int i = 0; i < ib.getNumElements(); i++) {
                assert ib.getNumComponents() == 3;
                for (int c = 0; c < ib.getNumComponents(); c++) {
                    int ind = ((Number) ib.getElementComponent(i, c)).intValue();
                    for (int x = 0; x < 3; x++) pts[c][x] = ((Number) pb.getElementComponent(ind, x)).floatValue();
                    for (int u = 0; u < 2; u++) uvs[c][u] = ((Number) vb.getElementComponent(ind, u)).floatValue() * texSize[u];
                }
                cast(pts, uvs, srcPano, target, cancel, texSize);
                if (cancel.cancelled)
                    return;
            }
            try {
                System.out.println("writing " + writeTo);
                ImageIO.write(target, "png", writeTo);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (mat != null)
                tweed.enqueue(new Callable<Spatial>() {

                    public Spatial call() throws Exception {
                        System.out.println("calculations complete");
                        TextureKey key = new TextureKey("Desktop/foo.png", false);
                        tweed.getAssetManager().deleteFromCache(key);
                        Texture texture = tweed.getAssetManager().loadTexture(key);
                        mat.setTexture("DiffuseMap", texture);
                        return null;
                    }
                });
        }
    }.start();
}
Also used : TextureKey(com.jme3.asset.TextureKey) VertexBuffer(com.jme3.scene.VertexBuffer) Spatial(com.jme3.scene.Spatial) Cancellable(org.twak.utils.ui.Cancellable) IOException(java.io.IOException) Texture(com.jme3.texture.Texture) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException)

Aggregations

VertexBuffer (com.jme3.scene.VertexBuffer)45 FloatBuffer (java.nio.FloatBuffer)43 Vector3f (com.jme3.math.Vector3f)20 ByteBuffer (java.nio.ByteBuffer)12 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)10 ShortBuffer (java.nio.ShortBuffer)9 IntBuffer (java.nio.IntBuffer)8 Mesh (com.jme3.scene.Mesh)7 Geometry (com.jme3.scene.Geometry)6 Buffer (java.nio.Buffer)6 ColorRGBA (com.jme3.math.ColorRGBA)5 Vector2f (com.jme3.math.Vector2f)5 ArrayList (java.util.ArrayList)5 Bone (com.jme3.animation.Bone)4 Material (com.jme3.material.Material)4 Matrix4f (com.jme3.math.Matrix4f)4 Type (com.jme3.scene.VertexBuffer.Type)3 Texture (com.jme3.texture.Texture)3 TempVars (com.jme3.util.TempVars)3 HashMap (java.util.HashMap)3