Package com.jme3.scene

Examples of com.jme3.scene.VertexBuffer


        }
    }

    public void clearVertexAttribs() {
        for (int i = 0; i < 16; i++) {
            VertexBuffer vb = context.boundAttribs[i];
            if (vb != null) {
                int arrayType = convertArrayType(vb.getBufferType());
                glDisableClientState(arrayType);
                context.boundAttribs[vb.getBufferType().ordinal()] = null;
            }
        }
    }
View Full Code Here


            }
        }
    }

    private void renderMeshDefault(Mesh mesh, int lod, int count) {
        VertexBuffer indices;

        VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
        if (interleavedData != null && interleavedData.isUpdateNeeded()) {
            updateBufferData(interleavedData);
        }

        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
View Full Code Here

   
    private void gatherVertexData(Mesh mesh, List<Vertex> vertexLookup) {

        //in case the model is currently animating with software animation
        //attempting to retrieve the bind position instead of the position.
        VertexBuffer position = mesh.getBuffer(VertexBuffer.Type.BindPosePosition);
        if (position == null) {
            position = mesh.getBuffer(VertexBuffer.Type.Position);
        }
        FloatBuffer pos = (FloatBuffer) position.getDataReadOnly();
        pos.rewind();
       
        while (pos.remaining() != 0) {
            Vertex v = new Vertex();
            v.position.setX(pos.get());
View Full Code Here

        }
        return null;
    }
   
    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;
View Full Code Here

    public void bakeLods(TriangleReductionMethod reductionMethod, float... reductionValues) {
        mesh.setLodLevels(computeLods(reductionMethod, reductionValues));
    }
   
    private VertexBuffer makeLod(Mesh mesh) {
        VertexBuffer indexBuffer = mesh.getBuffer(VertexBuffer.Type.Index);
       
        boolean isShortBuffer = indexBuffer.getFormat() == VertexBuffer.Format.UnsignedShort;
        // Create buffers. 
        VertexBuffer lodBuffer = new VertexBuffer(VertexBuffer.Type.Index);
        int bufsize = indexCount == 0 ? 3 : indexCount;
       
        if (isShortBuffer) {
            lodBuffer.setupData(VertexBuffer.Usage.Static, 3, VertexBuffer.Format.UnsignedShort, BufferUtils.createShortBuffer(bufsize));
        } else {
            lodBuffer.setupData(VertexBuffer.Usage.Static, 3, VertexBuffer.Format.UnsignedInt, BufferUtils.createIntBuffer(bufsize));
        }
       
       
       
        lodBuffer.getData().rewind();
        //Check if we should fill it with a "dummy" triangle.
        if (indexCount == 0) {
            if (isShortBuffer) {
                for (int m = 0; m < 3; m++) {
                    ((ShortBuffer) lodBuffer.getData()).put((short) 0);
                }
            } else {
                for (int m = 0; m < 3; m++) {
                    ((IntBuffer) lodBuffer.getData()).put(0);
                }
            }
        }

        // Fill buffers.      
        Buffer buf = lodBuffer.getData();
        buf.rewind();
        for (Triangle triangle : triangleList) {
            if (!triangle.isRemoved) {
            //    assert (indexCount != 0);
                if (isShortBuffer) {
                    for (int m = 0; m < 3; m++) {
                        ((ShortBuffer) buf).put((short) triangle.vertexId[m]);
                       
                    }
                } else {
                    for (int m = 0; m < 3; m++) {
                        ((IntBuffer) buf).put(triangle.vertexId[m]);
                    }
                   
                }
            }
        }
        buf.clear();
        lodBuffer.updateData(buf);
        return lodBuffer;
    }
View Full Code Here

                        mesh.getBuffer(Type.Position).setUsage(Usage.Stream);
                        mesh.getBuffer(Type.Normal).setUsage(Usage.Stream);

                        // creating empty buffers for HW skinning
                        // the buffers will be setup if ever used.
                        VertexBuffer verticesWeightsHW = new VertexBuffer(Type.HWBoneWeight);
                        VertexBuffer verticesWeightsIndicesHW = new VertexBuffer(Type.HWBoneIndex);
                        mesh.setBuffer(verticesWeightsHW);
                        mesh.setBuffer(verticesWeightsIndicesHW);
                    }
                } catch (BlenderFileException e) {
                    LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
View Full Code Here

        }

        bonesGroups[0] = Math.max(bonesGroups[0], 1);

        this.endBoneAssigns(vertexListSize, weightsFloatData);
        VertexBuffer verticesWeights = new VertexBuffer(Type.BoneWeight);
        verticesWeights.setupData(Usage.CpuOnly, bonesGroups[0], Format.Float, weightsFloatData);

        VertexBuffer verticesWeightsIndices = new VertexBuffer(Type.BoneIndex);
        verticesWeightsIndices.setupData(Usage.CpuOnly, bonesGroups[0], Format.UnsignedByte, indicesData);
        return new VertexBuffer[] { verticesWeights, verticesWeightsIndices };
    }
View Full Code Here

    public static void convertToFixed(Geometry geom, Format posFmt, Format nmFmt, Format tcFmt){
        geom.updateModelBound();
        BoundingBox bbox = (BoundingBox) geom.getModelBound();
        Mesh mesh = geom.getMesh();

        VertexBuffer positions = mesh.getBuffer(Type.Position);
        VertexBuffer normals   = mesh.getBuffer(Type.Normal);
        VertexBuffer texcoords = mesh.getBuffer(Type.TexCoord);
        VertexBuffer indices   = mesh.getBuffer(Type.Index);

        // positions
        FloatBuffer fb = (FloatBuffer) positions.getData();
        if (posFmt != Format.Float){
            Buffer newBuf = VertexBuffer.createBuffer(posFmt, positions.getNumComponents(),
                                                      mesh.getVertexCount());
            Transform t = convertPositions(fb, bbox, newBuf);
            t.combineWithParent(geom.getLocalTransform());
            geom.setLocalTransform(t);

            VertexBuffer newPosVb = new VertexBuffer(Type.Position);
            newPosVb.setupData(positions.getUsage(),
                               positions.getNumComponents(),
                               posFmt,
                               newBuf);
            mesh.clearBuffer(Type.Position);
            mesh.setBuffer(newPosVb);
        }

        // normals, automatically convert to signed byte
        fb = (FloatBuffer) normals.getData();

        ByteBuffer bb = BufferUtils.createByteBuffer(fb.capacity());
        convertNormals(fb, bb);

        normals = new VertexBuffer(Type.Normal);
        normals.setupData(Usage.Static, 3, Format.Byte, bb);
        normals.setNormalized(true);
        mesh.clearBuffer(Type.Normal);
        mesh.setBuffer(normals);

        // texcoords
        fb = (FloatBuffer) texcoords.getData();
        if (tcFmt != Format.Float){
            Buffer newBuf = VertexBuffer.createBuffer(tcFmt,
                                                      texcoords.getNumComponents(),
                                                      mesh.getVertexCount());
            convertTexCoords2D(fb, newBuf);

            VertexBuffer newTcVb = new VertexBuffer(Type.TexCoord);
            newTcVb.setupData(texcoords.getUsage(),
                              texcoords.getNumComponents(),
                              tcFmt,
                              newBuf);
            mesh.clearBuffer(Type.TexCoord);
            mesh.setBuffer(newTcVb);
View Full Code Here

        }
    }

    public static void compressIndexBuffer(Mesh mesh){
        int vertCount = mesh.getVertexCount();
        VertexBuffer vb = mesh.getBuffer(Type.Index);
        Format targetFmt;
        if (vb.getFormat() == Format.UnsignedInt && vertCount <= 0xffff){
            if (vertCount <= 256)
                targetFmt = Format.UnsignedByte;
            else
                targetFmt = Format.UnsignedShort;
        }else if (vb.getFormat() == Format.UnsignedShort && vertCount <= 0xff){
            targetFmt = Format.UnsignedByte;
        }else{
            return;
        }

        IndexBuffer src = mesh.getIndexBuffer();
        Buffer newBuf = VertexBuffer.createBuffer(targetFmt, vb.getNumComponents(), src.size());

        VertexBuffer newVb = new VertexBuffer(Type.Index);
        newVb.setupData(vb.getUsage(), vb.getNumComponents(), targetFmt, newBuf);
        mesh.clearBuffer(Type.Index);
        mesh.setBuffer(newVb);

        IndexBuffer dst = mesh.getIndexBuffer();
        for (int i = 0; i < src.size(); i++){
View Full Code Here

    public static VertexBuffer convertToUByte(VertexBuffer vb){
        FloatBuffer fb = (FloatBuffer) vb.getData();
        ByteBuffer bb = BufferUtils.createByteBuffer(fb.capacity());
        convertToUByte(fb, bb);

        VertexBuffer newVb = new VertexBuffer(vb.getBufferType());
        newVb.setupData(vb.getUsage(),
                        vb.getNumComponents(),
                        Format.UnsignedByte,
                        bb);
        newVb.setNormalized(true);
        return newVb;
    }
View Full Code Here

TOP

Related Classes of com.jme3.scene.VertexBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.