Search in sources :

Example 6 with StandardMeshData

use of org.terasology.engine.rendering.assets.mesh.StandardMeshData in project Terasology by MovingBlocks.

the class BlockMeshShapeGenerator method getStandaloneMesh.

@Override
public Mesh getStandaloneMesh() {
    if (mesh == null || mesh.isDisposed()) {
        Block block = getBlock();
        StandardMeshData meshData = new StandardMeshData();
        int nextIndex = 0;
        Vector3f light0 = new Vector3f(1, 1, 1);
        for (BlockPart dir : BlockPart.allParts()) {
            BlockMeshPart part = block.getPrimaryAppearance().getPart(dir);
            if (part != null) {
                for (int i = 0; i < part.size(); i++) {
                    meshData.position.put(part.getVertex(i));
                    meshData.color0.put(Color.white);
                    meshData.normal.put(part.getNormal(i));
                    meshData.uv0.put(part.getTexCoord(i));
                    meshData.light0.put(light0);
                }
                for (int i = 0; i < part.indicesSize(); ++i) {
                    meshData.indices.put(nextIndex + part.getIndex(i));
                }
                if (block.isDoubleSided()) {
                    for (int i = 0; i < part.indicesSize(); i += 3) {
                        meshData.indices.put(nextIndex + part.getIndex(i + 1));
                        meshData.indices.put(nextIndex + part.getIndex(i));
                        meshData.indices.put(nextIndex + part.getIndex(i + 2));
                    }
                }
                nextIndex += part.size();
            }
        }
        mesh = Assets.generateAsset(new ResourceUrn(getBaseUrn(), block.getURI().toString()), meshData, Mesh.class);
    }
    return mesh;
}
Also used : BlockPart(org.terasology.engine.world.block.BlockPart) StandardMeshData(org.terasology.engine.rendering.assets.mesh.StandardMeshData) Vector3f(org.joml.Vector3f) Block(org.terasology.engine.world.block.Block) Mesh(org.terasology.engine.rendering.assets.mesh.Mesh) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BlockMeshPart(org.terasology.engine.world.block.shapes.BlockMeshPart)

Aggregations

StandardMeshData (org.terasology.engine.rendering.assets.mesh.StandardMeshData)6 Mesh (org.terasology.engine.rendering.assets.mesh.Mesh)4 Vector3f (org.joml.Vector3f)2 Color (org.terasology.nui.Color)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ByteBuffer (java.nio.ByteBuffer)1 Vector2f (org.joml.Vector2f)1 GLTF (org.terasology.engine.rendering.gltf.model.GLTF)1 GLTFAccessor (org.terasology.engine.rendering.gltf.model.GLTFAccessor)1 GLTFBufferView (org.terasology.engine.rendering.gltf.model.GLTFBufferView)1 GLTFMesh (org.terasology.engine.rendering.gltf.model.GLTFMesh)1 GLTFPrimitive (org.terasology.engine.rendering.gltf.model.GLTFPrimitive)1 Block (org.terasology.engine.world.block.Block)1 BlockPart (org.terasology.engine.world.block.BlockPart)1 BlockMeshPart (org.terasology.engine.world.block.shapes.BlockMeshPart)1 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)1 Rectanglei (org.terasology.joml.geom.Rectanglei)1