Examples of VertexBuffer


Examples of com.jme3.scene.VertexBuffer

    /**
     * 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 parentTail = bone.getModelSpacePosition().add(bone.getModelSpaceRotation().mult(Vector3f.UNIT_Y.mult(boneLengths.get(i))));

            for (Bone child : bone.getChildren()) {
                Vector3f childHead = child.getModelSpacePosition();
                Vector3f v = childHead.subtract(parentTail);
                float pointDelta = v.length() / POINT_AMOUNT;
                v.normalizeLocal().multLocal(pointDelta);
                Vector3f pointPosition = parentTail.clone();
                for (int j = 0; j < POINT_AMOUNT; ++j) {
                    posBuf.put(pointPosition.getX()).put(pointPosition.getY()).put(pointPosition.getZ());
                    pointPosition.addLocal(v);
                }
            }
        }
        posBuf.flip();
        vb.updateData(posBuf);

        this.updateBound();
    }
View Full Code Here

Examples of com.jme3.scene.VertexBuffer

    /**
     * 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();
    }
View Full Code Here

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

Examples of com.jme3.scene.VertexBuffer

            }
        }
    }

    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

Examples of com.jme3.scene.VertexBuffer

   
    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

Examples of com.jme3.scene.VertexBuffer

        }
        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

Examples of com.jme3.scene.VertexBuffer

    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

Examples of com.jme3.scene.VertexBuffer

                        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

Examples of com.jme3.scene.VertexBuffer

        }

        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

Examples of com.jme3.scene.VertexBuffer

    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
TOP
Copyright © 2018 www.massapi.com. 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.