Java Code Examples for com.jme3.scene.Mesh#getVertexCount()
The following examples show how to use
com.jme3.scene.Mesh#getVertexCount() .
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: BIHTree.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public BIHTree(Mesh mesh, int maxTrisPerNode) { this.mesh = mesh; this.maxTrisPerNode = maxTrisPerNode; if (maxTrisPerNode < 1 || mesh == null) { throw new IllegalArgumentException(); } bihSwapTmp = new float[9]; FloatBuffer vb = (FloatBuffer) mesh.getBuffer(Type.Position).getData(); IndexBuffer ib = mesh.getIndexBuffer(); if (ib == null) { ib = new VirtualIndexBuffer(mesh.getVertexCount(), mesh.getMode()); } else if (mesh.getMode() != Mode.Triangles) { ib = new WrappedIndexBuffer(mesh); } numTris = ib.size() / 3; initTriList(vb, ib); }
Example 2
Source File: TextureAtlas.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static void applyAtlasCoords(List<Geometry> geometries, Mesh outMesh, TextureAtlas atlas) { int globalVertIndex = 0; for (Geometry geom : geometries) { Mesh inMesh = geom.getMesh(); geom.computeWorldMatrix(); int geomVertCount = inMesh.getVertexCount(); VertexBuffer inBuf = inMesh.getBuffer(Type.TexCoord); VertexBuffer outBuf = outMesh.getBuffer(Type.TexCoord); if (inBuf == null || outBuf == null) { continue; } atlas.applyCoords(geom, globalVertIndex, outMesh); globalVertIndex += geomVertCount; } }
Example 3
Source File: RagdollUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Test whether the indexed bone has at least one vertex in the specified * meshes with a weight greater than the specified threshold. * * @param boneIndex the index of the bone (≥0) * @param targets the meshes to search (not null, no null elements) * @param weightThreshold the threshold (≥0, ≤1) * @return true if at least 1 vertex found, otherwise false */ public static boolean hasVertices(int boneIndex, Mesh[] targets, float weightThreshold) { for (Mesh mesh : targets) { VertexBuffer biBuf = mesh.getBuffer(VertexBuffer.Type.BoneIndex); Buffer boneIndices = biBuf.getDataReadOnly(); FloatBuffer boneWeight = (FloatBuffer) mesh.getBuffer(Type.BoneWeight).getData(); boneIndices.rewind(); boneWeight.rewind(); int vertexComponents = mesh.getVertexCount() * 3; for (int i = 0; i < vertexComponents; i += 3) { int start = i / 3 * 4; for (int k = start; k < start + 4; k++) { if (readIndex(boneIndices, k) == boneIndex && boneWeight.get(k) >= weightThreshold) { return true; } } } } return false; }
Example 4
Source File: WrappedIndexBuffer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public WrappedIndexBuffer(Mesh mesh){ super(mesh.getVertexCount(), mesh.getMode()); this.ib = mesh.getIndexBuffer(); switch (meshMode){ case Points: numIndices = mesh.getTriangleCount(); break; case Lines: case LineLoop: case LineStrip: numIndices = mesh.getTriangleCount() * 2; break; case Triangles: case TriangleStrip: case TriangleFan: numIndices = mesh.getTriangleCount() * 3; break; default: throw new UnsupportedOperationException(); } }
Example 5
Source File: GLRenderer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void renderMesh(Mesh mesh, int lod, int count, VertexBuffer[] instanceData) { if (mesh.getVertexCount() == 0 || mesh.getTriangleCount() == 0 || count == 0) { return; } if (count > 1 && !caps.contains(Caps.MeshInstancing)) { throw new RendererException("Mesh instancing is not supported by the video hardware"); } if (mesh.getLineWidth() != 1f && context.lineWidth != mesh.getLineWidth()) { gl.glLineWidth(mesh.getLineWidth()); context.lineWidth = mesh.getLineWidth(); } if (gl4 != null && mesh.getMode().equals(Mode.Patch)) { gl4.glPatchParameter(mesh.getPatchVertexCount()); } statistics.onMeshDrawn(mesh, lod, count); // if (ctxCaps.GL_ARB_vertex_array_object){ // renderMeshVertexArray(mesh, lod, count); // }else{ renderMeshDefault(mesh, lod, count, instanceData); // } }
Example 6
Source File: HullCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
protected float[] getPoints(Mesh mesh) { FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); vertices.rewind(); int components = mesh.getVertexCount() * 3; float[] pointsArray = new float[components]; for (int i = 0; i < components; i += 3) { pointsArray[i] = vertices.get(); pointsArray[i + 1] = vertices.get(); pointsArray[i + 2] = vertices.get(); } return pointsArray; }
Example 7
Source File: RagdollUtils.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private static Map<Integer, List<Float>> buildPointMapForMesh(Mesh mesh, Map<Integer, List<Float>> map) { FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); ByteBuffer boneIndices = (ByteBuffer) mesh.getBuffer(Type.BoneIndex).getData(); FloatBuffer boneWeight = (FloatBuffer) mesh.getBuffer(Type.BoneWeight).getData(); vertices.rewind(); boneIndices.rewind(); boneWeight.rewind(); int vertexComponents = mesh.getVertexCount() * 3; int k, start, index; float maxWeight = 0; for (int i = 0; i < vertexComponents; i += 3) { start = i / 3 * 4; index = 0; maxWeight = -1; for (k = start; k < start + 4; k++) { float weight = boneWeight.get(k); if (weight > maxWeight) { maxWeight = weight; index = boneIndices.get(k); } } List<Float> points = map.get(index); if (points == null) { points = new ArrayList<Float>(); map.put(index, points); } points.add(vertices.get(i)); points.add(vertices.get(i + 1)); points.add(vertices.get(i + 2)); } return map; }
Example 8
Source File: JoglRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void renderMesh(Mesh mesh, int lod, int count) { if (mesh.getVertexCount() == 0) return; if (context.pointSize != mesh.getPointSize()) { gl.glPointSize(mesh.getPointSize()); context.pointSize = mesh.getPointSize(); } if (context.lineWidth != mesh.getLineWidth()) { gl.glLineWidth(mesh.getLineWidth()); context.lineWidth = mesh.getLineWidth(); } checkTexturingUsed(); if (vbo) { renderMeshVBO(mesh, lod, count); } else { boolean dynamic = false; if (mesh.getNumLodLevels() == 0) { IntMap<VertexBuffer> bufs = mesh.getBuffers(); for (Entry<VertexBuffer> entry : bufs) { if (entry.getValue().getUsage() != VertexBuffer.Usage.Static) { dynamic = true; break; } } } else { dynamic = true; } if (!dynamic) { // dealing with a static object, generate display list renderMeshDisplayList(mesh); } else { renderMeshDefault(mesh, lod, count); } } }
Example 9
Source File: HullCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
protected float[] getPoints(Mesh mesh) { FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); vertices.rewind(); int components = mesh.getVertexCount() * 3; float[] pointsArray = new float[components]; for (int i = 0; i < components; i += 3) { pointsArray[i] = vertices.get(); pointsArray[i + 1] = vertices.get(); pointsArray[i + 2] = vertices.get(); } return pointsArray; }
Example 10
Source File: FloatToFixed.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public static void compressIndexBuffer(Mesh mesh){ int vertCount = mesh.getVertexCount(); VertexBuffer vb = mesh.getBuffer(Type.Index); Format targetFmt; if (vb.getFormat() == Format.UnsignedInt && vertCount <= 0xffff){ if (vertCount <= 256) targetFmt = Format.UnsignedByte; else targetFmt = Format.UnsignedShort; }else if (vb.getFormat() == Format.UnsignedShort && vertCount <= 0xff){ targetFmt = Format.UnsignedByte; }else{ return; } IndexBuffer src = mesh.getIndexBuffer(); Buffer newBuf = VertexBuffer.createBuffer(targetFmt, vb.getNumComponents(), src.size()); VertexBuffer newVb = new VertexBuffer(Type.Index); newVb.setupData(vb.getUsage(), vb.getNumComponents(), targetFmt, newBuf); mesh.clearBuffer(Type.Index); mesh.setBuffer(newVb); IndexBuffer dst = mesh.getIndexBuffer(); for (int i = 0; i < src.size(); i++){ dst.put(i, src.get(i)); } }
Example 11
Source File: Statistics.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Called by the Renderer when a mesh has been drawn. */ public void onMeshDrawn(Mesh mesh, int lod, int count){ if( !enabled ) return; numObjects += 1; numTriangles += mesh.getTriangleCount(lod) * count; numVertices += mesh.getVertexCount() * count; }
Example 12
Source File: Converter.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static synchronized IndexedMesh convert(Mesh mesh) { IndexedMesh jBulletIndexedMesh = new IndexedMesh(); jBulletIndexedMesh.triangleIndexBase = ByteBuffer.allocate(mesh.getTriangleCount() * 3 * 4); jBulletIndexedMesh.vertexBase = ByteBuffer.allocate(mesh.getVertexCount() * 3 * 4); IndexBuffer indices = mesh.getIndicesAsList(); FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); vertices.rewind(); int verticesLength = mesh.getVertexCount() * 3; jBulletIndexedMesh.numVertices = mesh.getVertexCount(); jBulletIndexedMesh.vertexStride = 12; //3 verts * 4 bytes per. for (int i = 0; i < verticesLength; i++) { float tempFloat = vertices.get(); jBulletIndexedMesh.vertexBase.putFloat(tempFloat); } int indicesLength = mesh.getTriangleCount() * 3; jBulletIndexedMesh.numTriangles = mesh.getTriangleCount(); jBulletIndexedMesh.triangleIndexStride = 12; //3 index entries * 4 bytes each. for (int i = 0; i < indicesLength; i++) { jBulletIndexedMesh.triangleIndexBase.putInt(indices.get(i)); } vertices.rewind(); vertices.clear(); return jBulletIndexedMesh; }
Example 13
Source File: HullCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected float[] getPoints(Mesh mesh) { FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); vertices.rewind(); int components = mesh.getVertexCount() * 3; float[] pointsArray = new float[components]; for (int i = 0; i < components; i += 3) { pointsArray[i] = vertices.get(); pointsArray[i + 1] = vertices.get(); pointsArray[i + 2] = vertices.get(); } return pointsArray; }
Example 14
Source File: RagdollUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Map<Integer, List<Float>> buildPointMapForMesh(Mesh mesh, Map<Integer, List<Float>> map) { FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); ByteBuffer boneIndices = (ByteBuffer) mesh.getBuffer(Type.BoneIndex).getData(); FloatBuffer boneWeight = (FloatBuffer) mesh.getBuffer(Type.BoneWeight).getData(); vertices.rewind(); boneIndices.rewind(); boneWeight.rewind(); int vertexComponents = mesh.getVertexCount() * 3; int k, start, index; float maxWeight = 0; for (int i = 0; i < vertexComponents; i += 3) { start = i / 3 * 4; index = 0; maxWeight = -1; for (k = start; k < start + 4; k++) { float weight = boneWeight.get(k); if (weight > maxWeight) { maxWeight = weight; index = boneIndices.get(k); } } List<Float> points = map.get(index); if (points == null) { points = new ArrayList<Float>(); map.put(index, points); } points.add(vertices.get(i)); points.add(vertices.get(i + 1)); points.add(vertices.get(i + 2)); } return map; }
Example 15
Source File: NativeMeshUtil.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Pass a mesh to Native Bullet. * * @param mesh the JME mesh to pass (not null) * @return the unique identifier of the resulting btTriangleIndexVertexArray * (not 0) */ public static long getTriangleIndexVertexArray(Mesh mesh){ ByteBuffer triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4); ByteBuffer vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4); int numVertices = mesh.getVertexCount(); int vertexStride = 12; //3 verts * 4 bytes each int numTriangles = mesh.getTriangleCount(); int triangleIndexStride = 12; //3 index entries * 4 bytes each IndexBuffer indices = mesh.getIndicesAsList(); FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); vertices.rewind(); int verticesLength = mesh.getVertexCount() * 3; for (int i = 0; i < verticesLength; i++) { float tempFloat = vertices.get(); vertexBase.putFloat(tempFloat); } int indicesLength = mesh.getTriangleCount() * 3; for (int i = 0; i < indicesLength; i++) { triangleIndexBase.putInt(indices.get(i)); } vertices.rewind(); vertices.clear(); return createTriangleIndexVertexArray(triangleIndexBase, vertexBase, numTriangles, numVertices, vertexStride, triangleIndexStride); }
Example 16
Source File: MeshCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void createCollisionMesh(Mesh mesh) { this.triangleIndexBase = BufferUtils.createByteBuffer(mesh.getTriangleCount() * 3 * 4); this.vertexBase = BufferUtils.createByteBuffer(mesh.getVertexCount() * 3 * 4); this.numVertices = mesh.getVertexCount(); this.vertexStride = 12; // 3 verts * 4 bytes per. this.numTriangles = mesh.getTriangleCount(); this.triangleIndexStride = 12; // 3 index entries * 4 bytes each. IndexBuffer indices = mesh.getIndicesAsList(); FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); vertices.rewind(); int verticesLength = mesh.getVertexCount() * 3; for (int i = 0; i < verticesLength; i++) { float tempFloat = vertices.get(); vertexBase.putFloat(tempFloat); } int indicesLength = mesh.getTriangleCount() * 3; for (int i = 0; i < indicesLength; i++) { triangleIndexBase.putInt(indices.get(i)); } vertices.rewind(); vertices.clear(); this.createShape(null); }
Example 17
Source File: HullCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Copy the vertex positions from a JME mesh. * * @param mesh the mesh to read (not null) * @return a new array (not null, length a multiple of 3) */ protected float[] getPoints(Mesh mesh) { FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); vertices.rewind(); int components = mesh.getVertexCount() * 3; float[] pointsArray = new float[components]; for (int i = 0; i < components; i += 3) { pointsArray[i] = vertices.get(); pointsArray[i + 1] = vertices.get(); pointsArray[i + 2] = vertices.get(); } return pointsArray; }
Example 18
Source File: MeshPropertyBuilder.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
@Override @FxThread protected void buildForImpl(@NotNull final Object object, @Nullable final Object parent, @NotNull final VBox container, @NotNull final ModelChangeConsumer changeConsumer) { if (!(object instanceof Mesh)) return; final Mesh mesh = (Mesh) object; final Mesh.Mode mode = mesh.getMode(); final int id = mesh.getId(); final int instanceCount = mesh.getInstanceCount(); final int vertexCount = mesh.getVertexCount(); final int numLodLevels = mesh.getNumLodLevels(); final int triangleCount = mesh.getTriangleCount(); final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> idControl = new DefaultSinglePropertyControl<>(id, Messages.MODEL_PROPERTY_ID, changeConsumer); idControl.setSyncHandler(Mesh::getId); idControl.setToStringFunction(value -> Integer.toString(value)); idControl.setEditObject(mesh); final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> instanceCountControl = new DefaultSinglePropertyControl<>(instanceCount, Messages.MODEL_PROPERTY_INSTANCE_COUNT, changeConsumer); instanceCountControl.setSyncHandler(Mesh::getInstanceCount); instanceCountControl.setToStringFunction(value -> Integer.toString(value)); instanceCountControl.setEditObject(mesh); final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> vertexCountControl = new DefaultSinglePropertyControl<>(vertexCount, Messages.MODEL_PROPERTY_VERTEX_COUNT, changeConsumer); vertexCountControl.setSyncHandler(Mesh::getVertexCount); vertexCountControl.setToStringFunction(value -> Integer.toString(value)); vertexCountControl.setEditObject(mesh); final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> triangleCountControl = new DefaultSinglePropertyControl<>(triangleCount, Messages.MODEL_PROPERTY_TRIANGLE_COUNT, changeConsumer); triangleCountControl.setSyncHandler(Mesh::getTriangleCount); triangleCountControl.setToStringFunction(value -> Integer.toString(value)); triangleCountControl.setEditObject(mesh); final DefaultSinglePropertyControl<ModelChangeConsumer, Mesh, Integer> numLodLevelsControl = new DefaultSinglePropertyControl<>(numLodLevels, Messages.MODEL_PROPERTY_NUM_LOD_LEVELS, changeConsumer); numLodLevelsControl.setSyncHandler(Mesh::getNumLodLevels); numLodLevelsControl.setToStringFunction(value -> Integer.toString(value)); numLodLevelsControl.setEditObject(mesh); final EnumPropertyControl<ModelChangeConsumer, Mesh, Mesh.Mode> modeControl = new EnumPropertyControl<>(mode, Messages.MODEL_PROPERTY_MODE, changeConsumer, MODES); modeControl.setApplyHandler(Mesh::setMode); modeControl.setSyncHandler(Mesh::getMode); modeControl.setEditObject(mesh); FXUtils.addToPane(idControl, container); FXUtils.addToPane(instanceCountControl, container); FXUtils.addToPane(vertexCountControl, container); FXUtils.addToPane(triangleCountControl, container); FXUtils.addToPane(numLodLevelsControl, container); FXUtils.addToPane(modeControl, container); }
Example 19
Source File: Statistics.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * Called by the Renderer when a mesh has been drawn. * */ public void onMeshDrawn(Mesh mesh, int lod){ numObjects ++; numTriangles += mesh.getTriangleCount(lod); numVertices += mesh.getVertexCount(); }
Example 20
Source File: RagdollUtils.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
/** * returns a list of points for the given bone * @param mesh * @param boneIndex * @param offset * @param link * @return */ private static List<Float> getPoints(Mesh mesh, int boneIndex, Vector3f initialScale, Vector3f offset, float weightThreshold) { if (mesh == null) { throw new RuntimeException("mesh is null "); } if (initialScale == null) { throw new RuntimeException("initialScale is null "); } if (offset == null) { throw new RuntimeException("offset is null "); } if (mesh.getFloatBuffer(Type.Position) == null) { throw new RuntimeException("verticies is null "); } if (mesh.getBuffer(Type.BoneIndex) == null) { throw new RuntimeException("boneIndices is null "); } if (mesh.getBuffer(Type.BoneWeight) == null) { throw new RuntimeException("boneWeight is null "); } FloatBuffer vertices = mesh.getFloatBuffer(Type.Position); Buffer boneIndices = (Buffer) mesh.getBuffer(Type.BoneIndex).getData(); FloatBuffer boneWeight = (FloatBuffer) mesh.getBuffer(Type.BoneWeight).getData(); vertices.rewind(); boneIndices.rewind(); boneWeight.rewind(); ArrayList<Float> results = new ArrayList<Float>(); int vertexComponents = mesh.getVertexCount() * 3; for (int i = 0; i < vertexComponents; i += 3) { int k; boolean add = false; int start = i / 3 * 4; for (k = start; k < start + 4; k++) { if (getBoneIndex(boneIndices, k) == boneIndex && boneWeight.get(k) >= weightThreshold) { add = true; break; } } if (add) { Vector3f pos = new Vector3f(); pos.x = vertices.get(i); pos.y = vertices.get(i + 1); pos.z = vertices.get(i + 2); pos.subtractLocal(offset).multLocal(initialScale); results.add(pos.x); results.add(pos.y); results.add(pos.z); } } return results; }