Java Code Examples for com.jme3.scene.Mesh#getBuffer()

The following examples show how to use com.jme3.scene.Mesh#getBuffer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void renderMeshVertexArray(Mesh mesh, int lod, int count, VertexBuffer instanceData) {
        if (mesh.getId() == -1) {
            updateVertexArray(mesh, instanceData);
        } else {
            // TODO: Check if it was updated
        }

        if (context.boundVertexArray != mesh.getId()) {
            gl3.glBindVertexArray(mesh.getId());
            context.boundVertexArray = mesh.getId();
        }

//        IntMap<VertexBuffer> buffers = mesh.getBuffers();
        VertexBuffer indices;
        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
        } else {
            indices = mesh.getBuffer(Type.Index);
        }
        if (indices != null) {
            drawTriangleList(indices, mesh, count);
        } else {
            drawTriangleArray(mesh.getMode(), count, mesh.getVertexCount());
        }
        clearVertexAttribs();
    }
 
Example 2
Source File: SilentTangentBinormalGenerator.java    From OpenRTS with MIT License 5 votes vote down vote up
public static Mesh genTbnLines(Mesh mesh, float scale) {
	if (mesh.getBuffer(Type.Tangent) == null) {
		return genNormalLines(mesh, scale);
	} else {
		return genTangentLines(mesh, scale);
	}
}
 
Example 3
Source File: TangentBinormalGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static VertexData[] processTriangles(Mesh mesh,
        int[] index, Vector3f[] v, Vector2f[] t)
{
    IndexBuffer indexBuffer =  mesh.getIndexBuffer();
    FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
    if (mesh.getBuffer(Type.TexCoord) == null)
        throw new IllegalArgumentException("Can only generate tangents for "
                                         + "meshes with texture coordinates");
    
    FloatBuffer textureBuffer = (FloatBuffer) mesh.getBuffer(Type.TexCoord).getData();

    VertexData[] vertices = initVertexData(vertexBuffer.capacity() / 3);

    for (int i = 0; i < indexBuffer.size() / 3; i++) {
        for (int j = 0; j < 3; j++) {
            index[j] = indexBuffer.get(i*3 + j);
            populateFromBuffer(v[j], vertexBuffer, index[j]);
            populateFromBuffer(t[j], textureBuffer, index[j]);
        }

        TriangleData triData = processTriangle(index, v, t);
        if (triData != null) {
            vertices[index[0]].triangles.add(triData);
            vertices[index[1]].triangles.add(triData);
            vertices[index[2]].triangles.add(triData);
        }
    }
    
    return vertices;
}
 
Example 4
Source File: PoseTrack.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void applyFrame(Mesh target, int frameIndex, float weight){
    PoseFrame frame = frames[frameIndex];
    VertexBuffer pb = target.getBuffer(Type.Position);
    for (int i = 0; i < frame.poses.length; i++){
        Pose pose = frame.poses[i];
        float poseWeight = frame.weights[i] * weight;

        pose.apply(poseWeight, (FloatBuffer) pb.getData());
    }

    // force to re-upload data to gpu
    pb.updateData(pb.getData());
}
 
Example 5
Source File: TextureAtlas.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Applies the texture coordinates to the given output mesh
 * if the DiffuseMap or ColorMap of the input geometry exist in the atlas.
 * @param geom The geometry to change the texture coordinate buffer on.
 * @param offset Target buffer offset.
 * @param outMesh The mesh to set the coords in (can be same as input).
 * @return true if texture has been found and coords have been changed, false otherwise.
 */
public boolean applyCoords(Geometry geom, int offset, Mesh outMesh) {
    Mesh inMesh = geom.getMesh();
    geom.computeWorldMatrix();

    VertexBuffer inBuf = inMesh.getBuffer(Type.TexCoord);
    VertexBuffer outBuf = outMesh.getBuffer(Type.TexCoord);

    if (inBuf == null || outBuf == null) {
        throw new IllegalStateException("Geometry mesh has no texture coordinate buffer.");
    }

    Texture tex = getMaterialTexture(geom, "DiffuseMap");
    if (tex == null) {
        tex = getMaterialTexture(geom, "ColorMap");

    }
    if (tex != null) {
        TextureAtlasTile tile = getAtlasTile(tex);
        if (tile != null) {
            FloatBuffer inPos = (FloatBuffer) inBuf.getData();
            FloatBuffer outPos = (FloatBuffer) outBuf.getData();
            tile.transformTextureCoords(inPos, offset, outPos);
            return true;
        } else {
            return false;
        }
    } else {
        throw new IllegalStateException("Geometry has no proper texture.");
    }
}
 
Example 6
Source File: TerrainPatch.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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();
}
 
Example 7
Source File: LodGenerator.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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();
}
 
Example 8
Source File: LodGenerator.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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());
            v.position.setY(pos.get());
            v.position.setZ(pos.get());
            v.isSeam = false;
            Vertex existingV = findSimilar(v);
            if (existingV != null) {
                //vertex position already exists
                existingV.isSeam = true;
                v.isSeam = true;
            } else {
                vertexList.add(v);
            }
            vertexLookup.add(v);
        }
        pos.rewind();
    }
 
Example 9
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void updateVertexArray(Mesh mesh, VertexBuffer instanceData) {
    int id = mesh.getId();
    if (id == -1) {
        IntBuffer temp = intBuf1;
        gl3.glGenVertexArrays(temp);
        id = temp.get(0);
        mesh.setId(id);
    }

    if (context.boundVertexArray != id) {
        gl3.glBindVertexArray(id);
        context.boundVertexArray = id;
    }

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

    if (instanceData != null) {
        setVertexAttrib(instanceData, null);
    }

    for (VertexBuffer vb : mesh.getBufferList().getArray()) {
        if (vb.getBufferType() == Type.InterleavedData
                || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
                || vb.getBufferType() == Type.Index) {
            continue;
        }

        if (vb.getStride() == 0) {
            // not interleaved
            setVertexAttrib(vb);
        } else {
            // interleaved
            setVertexAttrib(vb, interleavedData);
        }
    }
}
 
Example 10
Source File: RagUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Enumerate all animated meshes in the specified subtree of a scene graph.
 * Note: recursive!
 *
 * @param subtree which subtree (aliases created)
 * @param storeResult (added to if not null)
 * @return an expanded list (either storeResult or a new instance)
 */
static List<Mesh> listAnimatedMeshes(Spatial subtree,
        List<Mesh> storeResult) {
    if (storeResult == null) {
        storeResult = new ArrayList<>(10);
    }

    if (subtree instanceof Geometry) {
        Geometry geometry = (Geometry) subtree;
        Mesh mesh = geometry.getMesh();
        VertexBuffer indices = mesh.getBuffer(VertexBuffer.Type.BoneIndex);
        boolean hasIndices = indices != null;
        VertexBuffer weights = mesh.getBuffer(VertexBuffer.Type.BoneWeight);
        boolean hasWeights = weights != null;
        if (hasIndices && hasWeights && !storeResult.contains(mesh)) {
            storeResult.add(mesh);
        }

    } else if (subtree instanceof Node) {
        Node node = (Node) subtree;
        List<Spatial> children = node.getChildren();
        for (Spatial child : children) {
            listAnimatedMeshes(child, storeResult);
        }
    }

    return storeResult;
}
 
Example 11
Source File: TangentBinormalGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void generate(Mesh mesh, boolean approxTangents) {
    int[] index = new int[3];
    Vector3f[] v = new Vector3f[3];
    Vector2f[] t = new Vector2f[3];
    for (int i = 0; i < 3; i++) {
        v[i] = new Vector3f();
        t[i] = new Vector2f();
    }
    
    if (mesh.getBuffer(Type.Normal) == null){
        throw new IllegalArgumentException("The given mesh has no normal data!");
    }

    VertexData[] vertices;
    switch (mesh.getMode()) {
        case Triangles:
            vertices = processTriangles(mesh, index, v, t); break;
        case TriangleStrip:
            vertices = processTriangleStrip(mesh, index, v, t); break;
        case TriangleFan:
            vertices = processTriangleFan(mesh, index, v, t); break;
        default: throw new UnsupportedOperationException(
                mesh.getMode() + " is not supported.");
    }

    processTriangleData(mesh, vertices, approxTangents);
}
 
Example 12
Source File: TestIssue1004.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    BulletAppState bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    String sinbadPath = "Models/Sinbad/SinbadOldAnim.j3o";
    Node sinbad = (Node) assetManager.loadModel(sinbadPath);

    Geometry geometry = (Geometry) sinbad.getChild(0);
    Mesh mesh = geometry.getMesh();
    VertexBuffer.Type bufferType = VertexBuffer.Type.BoneIndex;
    VertexBuffer vertexBuffer = mesh.getBuffer(bufferType);

    // Remove the existing bone-index buffer.
    mesh.getBufferList().remove(vertexBuffer);
    mesh.getBuffers().remove(bufferType.ordinal());

    // Copy the 8-bit bone indices to 16-bit indices.
    ByteBuffer oldBuffer = (ByteBuffer) vertexBuffer.getDataReadOnly();
    int numComponents = oldBuffer.limit();
    oldBuffer.rewind();
    short[] shortArray = new short[numComponents];
    for (int index = 0; oldBuffer.hasRemaining(); ++index) {
        shortArray[index] = oldBuffer.get();
    }

    // Add the 16-bit bone indices to the mesh.
    mesh.setBuffer(bufferType, 4, shortArray);

    KinematicRagdollControl ragdoll = new KinematicRagdollControl(0.5f);
    sinbad.addControl(ragdoll);

    stop();
}
 
Example 13
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void renderMeshDefault(Mesh mesh, int lod, int count) {
    VertexBuffer indices = null;
    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    IntMap<VertexBuffer> buffers = mesh.getBuffers();
    if (mesh.getNumLodLevels() > 0) {
        indices = mesh.getLodLevel(lod);
    } else {
        indices = buffers.get(Type.Index.ordinal());
    }
    for (Entry<VertexBuffer> entry : buffers) {
        VertexBuffer vb = entry.getValue();

        if (vb.getBufferType() == Type.InterleavedData
                || vb.getUsage() == Usage.CpuOnly) // ignore cpu-only buffers
        {
            continue;
        }

        if (vb.getBufferType() == Type.Index) {
            indices = vb;
        } else {
            if (vb.getStride() == 0) {
                // not interleaved
                setVertexAttrib(vb);
            } else {
                // interleaved
                setVertexAttrib(vb, interleavedData);
            }
        }
    }

    if (indices != null) {
        drawTriangleList(indices, mesh, count);
    } else {
        gl.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
    }
    clearVertexAttribs();
    clearTextureUnits();
}
 
Example 14
Source File: GdxRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
     * renderMeshVertexArray renders a mesh using vertex arrays
     * @param mesh
     * @param lod
     * @param count
     */
    private void renderMeshVertexArray(Mesh mesh, int lod, int count) {
        if (verboseLogging) {
            logger.info("renderMeshVertexArray");
        }

        //  IntMap<VertexBuffer> buffers = mesh.getBuffers();
        IntMap<VertexBuffer> buffers = mesh.getBuffers();
        IntMap.Entry<VertexBuffer> table[] = buffers.getTable();
        for (IntMap.Entry<VertexBuffer> entry : table) {
            if (entry == null) {
                continue;
            }
            VertexBuffer vb = entry.getValue();

            if (vb.getBufferType() == Type.InterleavedData
                    || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
                    || vb.getBufferType() == Type.Index) {
                continue;
            }

            if (vb.getStride() == 0) {
                // not interleaved
                setVertexAttrib_Array(vb);
            } else {
                // interleaved
                VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
                setVertexAttrib_Array(vb, interleavedData);
            }
        }

        VertexBuffer indices = null;
        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
        } else {
            indices = mesh.getBuffer(Type.Index);//buffers.get(Type.Index.ordinal());
        }
        clearVertexAttribs();
//        clearTextureUnits();
        if (indices != null) {
            drawTriangleList_Array(indices, mesh, count);
        } else {
            if (verboseLogging) {
                logger.log(Level.INFO, "GLES20.glDrawArrays({0}, {1}, {2})",
                        new Object[]{mesh.getMode(), 0, mesh.getVertexCount()});
            }

            Gdx.gl20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
        }
    }
 
Example 15
Source File: TangentBinormalGenerator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static Mesh genTbnLines(Mesh mesh, float scale) {
    if (mesh.getBuffer(Type.Tangent) == null)
        return genNormalLines(mesh, scale);
    else
        return genTangentLines(mesh, scale);
}
 
Example 16
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void updateVertexArray(Mesh mesh) {
    logger.log(Level.INFO, "updateVertexArray({0})", mesh);
    int id = mesh.getId();
    /*
    if (id == -1){
    IntBuffer temp = intBuf1;
    //      ARBVertexArrayObject.glGenVertexArrays(temp);
    GLES20.glGenVertexArrays(temp);
    id = temp.get(0);
    mesh.setId(id);
    }
    
    if (context.boundVertexArray != id){
    //     ARBVertexArrayObject.glBindVertexArray(id);
    GLES20.glBindVertexArray(id);
    context.boundVertexArray = id;
    }
     */
    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }

    SafeArrayList<VertexBuffer> buffersList = mesh.getBufferList();
    for (int i = 0; i < buffersList.size(); i++) {
        VertexBuffer vb = buffersList.get(i);

        if (vb.getBufferType() == Type.InterleavedData
                || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
                || vb.getBufferType() == Type.Index) {
            continue;
        }

        if (vb.getStride() == 0) {
            // not interleaved
            setVertexAttrib(vb);
        } else {
            // interleaved
            setVertexAttrib(vb, interleavedData);
        }
    }
}
 
Example 17
Source File: OGLESShaderRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
     * renderMeshVertexArray renders a mesh using vertex arrays
     * @param mesh
     * @param lod
     * @param count
     */
    private void renderMeshVertexArray(Mesh mesh, int lod, int count) {
        if (verboseLogging) {
            logger.info("renderMeshVertexArray");
        }

        //  IntMap<VertexBuffer> buffers = mesh.getBuffers();
        IntMap<VertexBuffer> buffers = mesh.getBuffers();
        IntMap.Entry<VertexBuffer> table[] = buffers.getTable();
        for (IntMap.Entry<VertexBuffer> entry : table) {
            if (entry == null) {
                continue;
            }
            VertexBuffer vb = entry.getValue();

            if (vb.getBufferType() == Type.InterleavedData
                    || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
                    || vb.getBufferType() == Type.Index) {
                continue;
            }

            if (vb.getStride() == 0) {
                // not interleaved
                setVertexAttrib_Array(vb);
            } else {
                // interleaved
                VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
                setVertexAttrib_Array(vb, interleavedData);
            }
        }

        VertexBuffer indices = null;
        if (mesh.getNumLodLevels() > 0) {
            indices = mesh.getLodLevel(lod);
        } else {
            indices = mesh.getBuffer(Type.Index);//buffers.get(Type.Index.ordinal());
        }
        clearVertexAttribs();
//        clearTextureUnits();
        if (indices != null) {
            drawTriangleList_Array(indices, mesh, count);
        } else {
            if (verboseLogging) {
                logger.log(Level.INFO, "GLES20.glDrawArrays({0}, {1}, {2})",
                        new Object[]{mesh.getMode(), 0, mesh.getVertexCount()});
            }

            GLES20.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
        }
    }
 
Example 18
Source File: EntropyComputeUtil.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static float computeLodEntropy(Mesh terrainBlock, Buffer lodIndices){
    // Bounding box for the terrain block
    BoundingBox bbox = (BoundingBox) terrainBlock.getBound();

    // Vertex positions for the block
    FloatBuffer positions = terrainBlock.getFloatBuffer(Type.Position);

    // Prepare to cast rays
    Vector3f pos = new Vector3f();
    Vector3f dir = new Vector3f(0, -1, 0);
    Ray ray = new Ray(pos, dir);

    // Prepare collision results
    CollisionResults results = new CollisionResults();

    // Set the LOD indices on the block
    VertexBuffer originalIndices = terrainBlock.getBuffer(Type.Index);

    terrainBlock.clearBuffer(Type.Index);
    if (lodIndices instanceof IntBuffer)
        terrainBlock.setBuffer(Type.Index, 3, (IntBuffer)lodIndices);
    else if (lodIndices instanceof ShortBuffer) {
        terrainBlock.setBuffer(Type.Index, 3, (ShortBuffer) lodIndices);
    }

    // Recalculate collision mesh
    terrainBlock.createCollisionData();

    float entropy = 0;
    for (int i = 0; i < positions.limit() / 3; i++){
        BufferUtils.populateFromBuffer(pos, positions, i);

        float realHeight = pos.y;

        pos.addLocal(0, bbox.getYExtent(), 0);
        ray.setOrigin(pos);

        results.clear();
        terrainBlock.collideWith(ray, Matrix4f.IDENTITY, bbox, results);

        if (results.size() > 0){
            Vector3f contactPoint = results.getClosestCollision().getContactPoint();
            float delta = Math.abs(realHeight - contactPoint.y);
            entropy = Math.max(delta, entropy);
        }
    }

    // Restore original indices
    terrainBlock.clearBuffer(Type.Index);
    terrainBlock.setBuffer(originalIndices);

    return entropy;
}
 
Example 19
Source File: SilentTangentBinormalGenerator.java    From OpenRTS with MIT License 4 votes vote down vote up
public static void generate(Mesh mesh, boolean approxTangents, boolean splitMirrored) {
	int[] index = new int[3];
	Vector3f[] v = new Vector3f[3];
	Vector2f[] t = new Vector2f[3];
	for (int i = 0; i < 3; i++) {
		v[i] = new Vector3f();
		t[i] = new Vector2f();
	}

	if (mesh.getBuffer(Type.Normal) == null) {
		throw new IllegalArgumentException("The given mesh has no normal data!");
	}

	List<VertexData> vertices;
	switch (mesh.getMode()) {
		case Triangles:
			vertices = processTriangles(mesh, index, v, t, splitMirrored);
			if (splitMirrored) {
				splitVertices(mesh, vertices, splitMirrored);
			}
			break;
		case TriangleStrip:
			vertices = processTriangleStrip(mesh, index, v, t);
			break;
		case TriangleFan:
			vertices = processTriangleFan(mesh, index, v, t);
			break;
		default:
			throw new UnsupportedOperationException(mesh.getMode() + " is not supported.");
	}

	processTriangleData(mesh, vertices, approxTangents, splitMirrored);

	// if the mesh has a bind pose, we need to generate the bind pose for the tangent buffer
	if (mesh.getBuffer(Type.BindPosePosition) != null) {

		VertexBuffer tangents = mesh.getBuffer(Type.Tangent);
		if (tangents != null) {
			VertexBuffer bindTangents = new VertexBuffer(Type.BindPoseTangent);
			bindTangents.setupData(Usage.CpuOnly, 4, Format.Float, BufferUtils.clone(tangents.getData()));

			if (mesh.getBuffer(Type.BindPoseTangent) != null) {
				mesh.clearBuffer(Type.BindPoseTangent);
			}
			mesh.setBuffer(bindTangents);
			tangents.setUsage(Usage.Stream);
		}
	}
}
 
Example 20
Source File: AbstractRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void renderMeshDefault(Mesh mesh, int lod, int count) {
    VertexBuffer indices = null;
    VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
    if (interleavedData != null && interleavedData.isUpdateNeeded()) {
        updateBufferData(interleavedData);
    }
    IntMap<VertexBuffer> buffers = mesh.getBuffers();
    if (mesh.getNumLodLevels() > 0) {
        indices = mesh.getLodLevel(lod);
    }
    else {
        indices = buffers.get(Type.Index.ordinal());
    }
    for (Entry<VertexBuffer> entry : buffers) {
        VertexBuffer vb = entry.getValue();

        if (vb.getBufferType() == Type.InterleavedData || vb.getUsage() == Usage.CpuOnly
                || vb.getBufferType() == Type.Index) {
            continue;
        }

        /*if (vb.getBufferType() == Type.Index) {
            indices = vb;
        }
        else {*/
        if (vb.getStride() == 0) {
            // not interleaved
            setVertexAttrib(vb);
        }
        else {
            // interleaved
            setVertexAttrib(vb, interleavedData);
        }
        /*}*/
    }

    if (indices != null) {
        drawTriangleList(indices, mesh, count);
    }
    else {
        drawArrays(mesh);
    }
    clearVertexAttribs();
    clearTextureUnits();
}