Java Code Examples for com.badlogic.gdx.graphics.Mesh#getNumIndices()
The following examples show how to use
com.badlogic.gdx.graphics.Mesh#getNumIndices() .
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: GLTFExporter.java From gdx-gltf with Apache License 2.0 | 6 votes |
/** convenient method to export a single mesh * primitiveType can be any of OpenGL primitive: * {@link com.badlogic.gdx.graphics.GL20#GL_POINTS}, * {@link com.badlogic.gdx.graphics.GL20#GL_LINES}, * {@link com.badlogic.gdx.graphics.GL20#GL_LINE_STRIP}, * {@link com.badlogic.gdx.graphics.GL20#GL_TRIANGLES}, * {@link com.badlogic.gdx.graphics.GL20#GL_TRIANGLE_STRIP}, * {@link com.badlogic.gdx.graphics.GL20#GL_TRIANGLE_FAN}, * etc.. * */ public void export(Mesh mesh, int primitiveType, FileHandle file){ GLTFScene scene = beginSingleScene(file); GLTFNode glNode = obtainNode(); scene.nodes = new Array<Integer>(); scene.nodes.add(root.nodes.size-1); GLTFMesh gltfMesh = obtainMesh(); glNode.mesh = root.meshes.size-1; MeshPart meshPart = new MeshPart(); meshPart.mesh = mesh; meshPart.offset = 0; meshPart.primitiveType = primitiveType; meshPart.size = mesh.getNumIndices(); if(meshPart.size == 0) meshPart.size = mesh.getNumVertices(); gltfMesh.primitives = new Array<GLTFPrimitive>(); GLTFPrimitive primitive = meshExporter.exportMeshPart(meshPart); gltfMesh.primitives.add(primitive); end(file); }
Example 2
Source File: NavMeshGraph.java From GdxDemo3D with Apache License 2.0 | 6 votes |
/** * Creates Vector3 objects from the vertices of the mesh. The resulting array follows the ordering of the provided * index array. * * @param mesh * @param indices * @return */ private static Vector3[] createVertexVectors(Mesh mesh, short[] indices) { FloatBuffer verticesBuffer = mesh.getVerticesBuffer(); int positionOffset = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position).offset / 4; int vertexSize = mesh.getVertexSize() / 4; Vector3[] vertexVectors = new Vector3[mesh.getNumIndices()]; for (int i = 0; i < indices.length; i++) { short index = indices[i]; int a = index * vertexSize + positionOffset; float x = verticesBuffer.get(a++); float y = verticesBuffer.get(a++); float z = verticesBuffer.get(a); vertexVectors[index] = new Vector3(x, y, z); } return vertexVectors; }
Example 3
Source File: GLTFMeshExporter.java From gdx-gltf with Apache License 2.0 | 5 votes |
GLTFPrimitive exportMeshPart(MeshPart meshPart) { Mesh mesh = meshPart.mesh; GLTFPrimitive primitive = new GLTFPrimitive(); primitive.attributes = new ObjectMap<String, Integer>(); primitive.mode = mapPrimitiveMode(meshPart.primitiveType); GLTFPrimitive layout = layouts.get(mesh); if(layout != null){ copyLayout(primitive, layout); }else{ layouts.put(mesh, primitive); exportMesh(primitive, mesh); } // mesh may not have indices if(mesh.getNumIndices() > 0) { ShortBuffer outBuffer = base.binManager.beginShorts(meshPart.size); ShortBuffer inBuffer = mesh.getIndicesBuffer(); if(meshPart.offset == 0 && meshPart.size == mesh.getNumIndices()){ outBuffer.put(mesh.getIndicesBuffer()); }else{ short[] localIndices = new short[meshPart.size]; inBuffer.position(meshPart.offset); inBuffer.get(localIndices); outBuffer.put(localIndices); } inBuffer.rewind(); GLTFAccessor accessor = base.obtainAccessor(); accessor.type = GLTFTypes.TYPE_SCALAR; accessor.componentType = GLTFTypes.C_SHORT; accessor.count = meshPart.size; accessor.bufferView = base.binManager.end(); primitive.indices = base.root.accessors.size-1; } return primitive; }
Example 4
Source File: NavMeshGraph.java From GdxDemo3D with Apache License 2.0 | 5 votes |
/** * Get an array of the vertex indices from the mesh. Any vertices which share the same position will be counted * as a single vertex and share the same index. That is, position duplicates will be filtered out. * * @param mesh * @return */ private static short[] getUniquePositionVertexIndices(Mesh mesh) { FloatBuffer verticesBuffer = mesh.getVerticesBuffer(); int positionOffset = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position).offset / 4; // Number of array elements which make up a vertex int vertexSize = mesh.getVertexSize() / 4; // The indices tell us which vertices are part of a triangle. short[] indices = new short[mesh.getNumIndices()]; mesh.getIndices(indices); // Marks true if an index has already been compared to avoid unnecessary comparisons Bits handledIndices = new Bits(mesh.getNumIndices()); for (int i = 0; i < indices.length; i++) { short indexI = indices[i]; if (handledIndices.get(indexI)) { // Index handled in an earlier iteration continue; } int vBufIndexI = indexI * vertexSize + positionOffset; float xi = verticesBuffer.get(vBufIndexI++); float yi = verticesBuffer.get(vBufIndexI++); float zi = verticesBuffer.get(vBufIndexI++); for (int j = i + 1; j < indices.length; j++) { short indexJ = indices[j]; int vBufIndexJ = indexJ * vertexSize + positionOffset; float xj = verticesBuffer.get(vBufIndexJ++); float yj = verticesBuffer.get(vBufIndexJ++); float zj = verticesBuffer.get(vBufIndexJ++); if (xi == xj && yi == yj && zi == zj) { indices[j] = indexI; } } handledIndices.set(indexI); } return indices; }
Example 5
Source File: GLTFInspector.java From gdx-gltf with Apache License 2.0 | 4 votes |
private void logScenes(SceneAsset asset) { int nBones = 0; int nNodes = 0; int meshNodes = 0; int nMeshParts = 0; int nMesh = 0; int nVert = 0; int nTri = 0; int nRealTri = 0; ObjectSet<Material> mapSet = new ObjectSet<Material>(); for(SceneModel scene : asset.scenes){ nMesh += scene.model.meshes.size; allCameras.addAll(scene.cameras.values().toArray()); allLights.addAll(scene.lights.values().toArray()); for(Mesh mesh : scene.model.meshes ){ nVert += mesh.getNumVertices(); nTri += mesh.getNumIndices() / 3; } Array<Node> nodes = NodeUtil.getAllNodes(new Array<Node>(), scene.model); nNodes += nodes.size; for(Node node : nodes){ if(node.parts.size > 0){ nMeshParts += node.parts.size; for(NodePart np : node.parts){ nRealTri += np.meshPart.size / 3; mapSet.add(np.material); nBones += np.bones != null ? np.bones.length : 0; } meshNodes++; } } } int nMaterials = mapSet.size; log("Scene Graph", "scenes", asset.scenes.size, "nodes", nNodes, "empty", nNodes - meshNodes); if(nMesh > 0) log("Mesh", "count", nMesh, "parts", nMeshParts, "Vertices", nVert, "Tris", nTri, "Rendered", nRealTri); if(nMaterials > 0) log("Materials", "count", nMaterials); if(asset.maxBones > 0) log("Bones", "max", asset.maxBones, "count", nBones); }