Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void applyOutput(final DecalMeshGenerator.Output output, final Mesh decalMesh)
- {
- applyOutput(output, decalMesh, false);
- }
- private static void applyDynamicFloatArray(final Mesh decalMesh, final VertexBuffer.Type type, final int components, final DynamicFloatArray src)
- {
- VertexBuffer destVB = decalMesh.getBuffer(type);
- if (destVB != null)
- {
- FloatBuffer dest = (FloatBuffer)destVB.getData();
- if (dest != null && dest.capacity() >= src.getLength())
- {
- dest.clear();
- src.toFloatBuffer(dest);
- dest.position(0).limit(src.getLength());
- destVB.updateData(dest);
- return;
- }
- }
- decalMesh.setBuffer(type, components, src.toFloatBuffer());
- }
- public static void applyOutput(final DecalMeshGenerator.Output output, final Mesh decalMesh, boolean generateIndexData)
- {
- applyDynamicFloatArray(decalMesh, VertexBuffer.Type.Position, 3, output.Positions);
- applyDynamicFloatArray(decalMesh, VertexBuffer.Type.Normal, 3, output.Normals);
- applyDynamicFloatArray(decalMesh, VertexBuffer.Type.TexCoord, 2, output.TexCoords);
- if (generateIndexData)
- {
- int indexDataSize = output.Positions.getLength() / 3;
- IndexBuffer ib = decalMesh.getIndexBuffer();
- Buffer ibb;
- if (ib != null)
- {
- ibb = ib.getBuffer();
- if (ibb != null && ibb.capacity() >= indexDataSize)
- {
- ibb.limit(indexDataSize).rewind();
- }
- else
- {
- ib = IndexBuffer.createIndexBuffer(indexDataSize, indexDataSize);
- ibb = ib.getBuffer();
- }
- }
- else
- {
- ib = IndexBuffer.createIndexBuffer(indexDataSize, indexDataSize);
- ibb = ib.getBuffer();
- }
- for (int i = 0; i < indexDataSize; i++)
- {
- ib.put(i, i);
- }
- if (ibb instanceof IntBuffer)
- {
- decalMesh.setBuffer(VertexBuffer.Type.Index, 3, (IntBuffer)ibb);
- }
- else
- {
- decalMesh.setBuffer(VertexBuffer.Type.Index, 3, (ShortBuffer)ibb);
- }
- }
- else
- {
- decalMesh.clearBuffer(VertexBuffer.Type.Index);
- }
- if (output.Tangents != null)
- {
- applyDynamicFloatArray(decalMesh, VertexBuffer.Type.Tangent, 4, output.Tangents);
- output.Tangents.reset();
- }
- else
- {
- decalMesh.clearBuffer(VertexBuffer.Type.Tangent);
- }
- output.Positions.reset();
- output.Normals.reset();
- output.TexCoords.reset();
- decalMesh.updateCounts();
- decalMesh.updateBound();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement