Package java.nio

Examples of java.nio.Buffer


        for (int i = 0; i < compsForBuf.length; i++) {
            if (compsForBuf[i] == 0) {
                continue;
            }

            Buffer data;
            if (i == VertexBuffer.Type.Index.ordinal()) {
                data = VertexBuffer.createBuffer(formatForBuf[i], compsForBuf[i], totalTris);
            } else {
                data = VertexBuffer.createBuffer(formatForBuf[i], compsForBuf[i], totalVerts);
            }
View Full Code Here


                context.normalizeEnabled = false;
            }
        }

        // NOTE: Use data from interleaved buffer if specified
        Buffer data = idb != null ? idb.getData() : vb.getData();
        int comps = vb.getNumComponents();
        int type = convertVertexFormat(vb.getFormat());

        data.rewind();

        switch (vb.getBufferType()) {
            case Position:
                if (!(data instanceof FloatBuffer)) {
                    throw new UnsupportedOperationException();
View Full Code Here

    }

    public void drawTriangleList(VertexBuffer indexBuf, Mesh mesh, int count) {
        Mesh.Mode mode = mesh.getMode();

        Buffer indexData = indexBuf.getData();
        indexData.rewind();

        if (mesh.getMode() == Mode.Hybrid) {
            throw new UnsupportedOperationException();
            /*
            int[] modeStart = mesh.getModeStart();
View Full Code Here

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

                }
            }
        }

        // 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

                            FloatBuffer clonePosition = clone.getFloatBuffer(Type.Position);
                            FloatBuffer cloneBindPosePosition = clone.getFloatBuffer(Type.BindPosePosition);
                            FloatBuffer cloneNormals = clone.getFloatBuffer(Type.Normal);
                            FloatBuffer cloneBindPoseNormals = clone.getFloatBuffer(Type.BindPoseNormal);
                            Buffer cloneIndexes = clone.getBuffer(Type.Index).getData();

                            for (int i = 0; i < cloneIndexes.limit(); ++i) {
                                int index = cloneIndexes instanceof ShortBuffer ? ((ShortBuffer) cloneIndexes).get(i) : ((IntBuffer) cloneIndexes).get(i);
                                if (!modifiedIndexes.contains(index)) {
                                    modifiedIndexes.add(index);

                                    this.get(clonePosition, index, point);
                                    if (mirrorAtPoint0) {
                                        d = Math.abs(point.get(mirrorIndex));
                                        shiftVector.set(0, 0, 0).set(mirrorIndex, -point.get(mirrorIndex));
                                    } else {
                                        d = this.computeDistanceFromPlane(point, mirrorPlaneCenter, mirrorPlaneNormal);
                                        mirrorPlaneNormal.mult(d, shiftVector);
                                    }

                                    if (merge && d <= tolerance) {
                                        point.addLocal(shiftVector);

                                        this.set(index, point, clonePosition, cloneBindPosePosition, position, bindPosePosition);
                                        if (cloneNormals != null) {
                                            this.get(cloneNormals, index, normal);
                                            normal.set(mirrorIndex, 0);
                                            this.set(index, normal, cloneNormals, cloneBindPoseNormals);
                                        }
                                    } else {
                                        point.addLocal(shiftVector.multLocal(2));

                                        this.set(index, point, clonePosition, cloneBindPosePosition);
                                        if (cloneNormals != null) {
                                            this.get(cloneNormals, index, normal);
                                            normal.set(mirrorIndex, -normal.get(mirrorIndex));
                                            this.set(index, normal, cloneNormals, cloneBindPoseNormals);
                                        }
                                    }
                                }
                            }
                            modifiedIndexes.clear();

                            LOGGER.finer("Flipping index order.");
                            switch (mesh.getMode()) {
                                case Points:
                                    cloneIndexes.flip();
                                    break;
                                case Lines:
                                    for (int i = 0; i < cloneIndexes.limit(); i += 2) {
                                        if (cloneIndexes instanceof ShortBuffer) {
                                            short index = ((ShortBuffer) cloneIndexes).get(i + 1);
                                            ((ShortBuffer) cloneIndexes).put(i + 1, ((ShortBuffer) cloneIndexes).get(i));
                                            ((ShortBuffer) cloneIndexes).put(i, index);
                                        } else {
                                            int index = ((IntBuffer) cloneIndexes).get(i + 1);
                                            ((IntBuffer) cloneIndexes).put(i + 1, ((IntBuffer) cloneIndexes).get(i));
                                            ((IntBuffer) cloneIndexes).put(i, index);
                                        }
                                    }
                                    break;
                                case Triangles:
                                    for (int i = 0; i < cloneIndexes.limit(); i += 3) {
                                        if (cloneIndexes instanceof ShortBuffer) {
                                            short index = ((ShortBuffer) cloneIndexes).get(i + 2);
                                            ((ShortBuffer) cloneIndexes).put(i + 2, ((ShortBuffer) cloneIndexes).get(i + 1));
                                            ((ShortBuffer) cloneIndexes).put(i + 1, index);
                                        } else {
View Full Code Here

        int numElements = 0;
        for (PrimitiveGroup group : groups)
            numElements += group.numIndices;

        VertexBuffer original = mesh.getBuffer(Type.Index);
        Buffer buf = VertexBuffer.createBuffer(original.getFormat(),
                                               original.getNumComponents(),
                                               numElements);
        original.updateData(buf);
        ib = mesh.getIndexBuffer();
View Full Code Here

    //only do this for software updates
    void resetToBind() {
        for (Mesh mesh : targets) {
            if (mesh.isAnimated()) {
                Buffer bwBuff = mesh.getBuffer(Type.BoneWeight).getData();
                Buffer biBuff = mesh.getBuffer(Type.BoneIndex).getData();
                if (!biBuff.hasArray() || !bwBuff.hasArray()) {
                    mesh.prepareForAnim(true); // prepare for software animation
                }
                VertexBuffer bindPos = mesh.getBuffer(Type.BindPosePosition);
                VertexBuffer bindNorm = mesh.getBuffer(Type.BindPoseNormal);
                VertexBuffer pos = mesh.getBuffer(Type.Position);
View Full Code Here

                //Some buffer (hardware skinning ones) can be there but not
                //initialized, they must be skipped.
                //They'll be initialized when Hardware Skinning is engaged
                if(vb==null || vb.getNumComponents() == 0) continue;
               
                Buffer buffer = vb.getData();  
                //IndexBuffer has special treatement, only swapping the vertex indices is needed               
                if(type == Type.Index){
                    boolean isShortBuffer = vb.getFormat() == VertexBuffer.Format.UnsignedShort;                    
                    for (VertexData vertex : newVertices) {
                        for (TriangleData tri : vertex.triangles) {
                            for (int i = 0; i < tri.index.length; i++) {
                                if (isShortBuffer) {
                                    ((ShortBuffer) buffer).put(tri.triangleOffset + i, (short) tri.index[i]);
                                } else {
                                    ((IntBuffer) buffer).put(tri.triangleOffset + i, tri.index[i]);
                                }
                            }
                        }
                    }
                    vb.setUpdateNeeded();
                }else{
                    //copy the buffer in a bigger one and append nex vertices to the end
                    Buffer newVerts = VertexBuffer.createBuffer(vb.getFormat(), vb.getNumComponents(), nbVertices);                  
                    if (buffer != null) {
                        buffer.rewind();
                        bulkPut(vb.getFormat(), newVerts,buffer)
                       
                        int index = vertexData.size();                     
                        newVerts.position(vertexData.size() * vb.getNumComponents());
                        for (int j = 0; j < newVertices.size(); j++) {
                            int oldInd = indiceMap.get(index) ;
                            for (int i = 0; i < vb.getNumComponents(); i++) {                               
                                    putValue(vb.getFormat(), newVerts, buffer, oldInd* vb.getNumComponents() + i);
                            }                           
View Full Code Here

                    continue;

                // NOTE: we are not actually sure
                // how many elements will be in this buffer.
                // It will be compacted later.
                Buffer b = VertexBuffer.createBuffer(vb.getFormat(),
                                                     vb.getNumComponents(),
                                                     outElementCount);

                VertexBuffer outVb = new VertexBuffer(vb.getBufferType());
                outVb.setNormalized(vb.isNormalized());
View Full Code Here

TOP

Related Classes of java.nio.Buffer

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.