Java Code Examples for com.jme3.scene.Mesh#setMode()
The following examples show how to use
com.jme3.scene.Mesh#setMode() .
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: TestGeometryShader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleInitApp() { Mesh mesh = new Mesh(); mesh.setBuffer(VertexBuffer.Type.Index, 1, BufferUtils.createIntBuffer(new int[]{1})); mesh.setBuffer(VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer(new float[]{0, 0, 0})); mesh.setMode(Mesh.Mode.Points); mesh.setBound(new BoundingBox(new Vector3f(0, 0, 0), 10, 10, 10)); mesh.updateCounts(); Geometry geometry = new Geometry("Test", mesh); geometry.updateGeometricState(); geometry.setMaterial(new Material(assetManager, "Materials/Geom/SimpleGeom.j3md")); //geometry.getMaterial().getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off); //geometry.setMaterial(assetManager.loadMaterial("Materials/Geom/SimpleTess.j3md")); rootNode.attachChild(geometry); Geometry geometry1 = new Geometry("T1", new Sphere(10, 10, 1)); geometry1.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md")); rootNode.attachChild(geometry1); }
Example 2
Source File: WireFrustum.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static void initGeom(Mesh m, Vector3f[] points) { if (points != null) m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(points)); m.setBuffer(Type.Index, 2, new short[]{ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7, } ); m.getBuffer(Type.Index).setUsage(Usage.Static); m.setMode(Mode.Lines); }
Example 3
Source File: WrappedIndexBuffer.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static void convertToList(Mesh mesh){ IndexBuffer inBuf = mesh.getIndicesAsList(); IndexBuffer outBuf = IndexBuffer.createIndexBuffer(mesh.getVertexCount(), inBuf.size()); for (int i = 0; i < inBuf.size(); i++){ outBuf.put(i, inBuf.get(i)); } mesh.clearBuffer(Type.Index); switch (mesh.getMode()){ case LineLoop: case LineStrip: mesh.setMode(Mode.Lines); break; case TriangleStrip: case TriangleFan: mesh.setMode(Mode.Triangles); break; default: break; } mesh.setBuffer(Type.Index, 3, outBuf.getFormat(), outBuf.getBuffer()); }
Example 4
Source File: LODGeomap.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Mesh createMesh(Vector3f scale, Vector2f tcScale, Vector2f tcOffset, float offsetAmount, int totalSize, boolean center, int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod) { FloatBuffer pb = writeVertexArray(null, scale, center); FloatBuffer texb = writeTexCoordArray(null, tcOffset, tcScale, offsetAmount, totalSize); FloatBuffer nb = writeNormalArray(null, scale); IndexBuffer ib = writeIndexArrayLodDiff(lod, rightLod, topLod, leftLod, bottomLod, totalSize); FloatBuffer bb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3); FloatBuffer tanb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3); writeTangentArray(nb, tanb, bb, texb, scale); Mesh m = new Mesh(); m.setMode(Mode.TriangleStrip); m.setBuffer(Type.Position, 3, pb); m.setBuffer(Type.Normal, 3, nb); m.setBuffer(Type.Tangent, 3, tanb); m.setBuffer(Type.Binormal, 3, bb); m.setBuffer(Type.TexCoord, 2, texb); switch (ib.getFormat()) { case UnsignedInt: m.setBuffer(Type.Index, 3, (IntBuffer) ib.getBuffer()); break; case UnsignedShort: m.setBuffer(Type.Index, 3, (ShortBuffer) ib.getBuffer()); break; case UnsignedByte: m.setBuffer(Type.Index, 3, (ByteBuffer) ib.getBuffer()); break; } m.setStatic(); m.updateBound(); return m; }
Example 5
Source File: TestTangentGen.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private Mesh createTriangleStripMesh() { Mesh strip = new Mesh(); strip.setMode(Mode.TriangleStrip); FloatBuffer vb = BufferUtils.createFloatBuffer(3*3*3); // 3 rows * 3 columns * 3 floats vb.rewind(); vb.put(new float[]{0,2,0}); vb.put(new float[]{1,2,0}); vb.put(new float[]{2,2,0}); vb.put(new float[]{0,1,0}); vb.put(new float[]{1,1,0}); vb.put(new float[]{2,1,0}); vb.put(new float[]{0,0,0}); vb.put(new float[]{1,0,0}); vb.put(new float[]{2,0,0}); FloatBuffer nb = BufferUtils.createFloatBuffer(3*3*3); nb.rewind(); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); FloatBuffer tb = BufferUtils.createFloatBuffer(3*3*2); tb.rewind(); tb.put(new float[]{0,0}); tb.put(new float[]{0.5f,0}); tb.put(new float[]{1,0}); tb.put(new float[]{0,0.5f}); tb.put(new float[]{0.5f,0.5f}); tb.put(new float[]{1,0.5f}); tb.put(new float[]{0,1}); tb.put(new float[]{0.5f,1}); tb.put(new float[]{1,1}); int[] indexes = new int[]{0,3,1,4,2,5, 5,3, 3,6,4,7,5,8}; IntBuffer ib = BufferUtils.createIntBuffer(indexes.length); ib.put(indexes); strip.setBuffer(Type.Position, 3, vb); strip.setBuffer(Type.Normal, 3, nb); strip.setBuffer(Type.TexCoord, 2, tb); strip.setBuffer(Type.Index, 3, ib); strip.updateBound(); return strip; }
Example 6
Source File: SilentTangentBinormalGenerator.java From OpenRTS with MIT License | 5 votes |
public static Mesh genNormalLines(Mesh mesh, float scale) { FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData(); FloatBuffer normalBuffer = (FloatBuffer) mesh.getBuffer(Type.Normal).getData(); ColorRGBA originColor = ColorRGBA.White; ColorRGBA normalColor = ColorRGBA.Blue; Mesh lineMesh = new Mesh(); lineMesh.setMode(Mesh.Mode.Lines); Vector3f origin = new Vector3f(); Vector3f point = new Vector3f(); FloatBuffer lineVertex = BufferUtils.createFloatBuffer(vertexBuffer.limit() * 2); FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.limit() / 3 * 4 * 2); for (int i = 0; i < vertexBuffer.limit() / 3; i++) { populateFromBuffer(origin, vertexBuffer, i); populateFromBuffer(point, normalBuffer, i); int index = i * 2; setInBuffer(origin, lineVertex, index); setInBuffer(originColor, lineColor, index); point.multLocal(scale); point.addLocal(origin); setInBuffer(point, lineVertex, index + 1); setInBuffer(normalColor, lineColor, index + 1); } lineMesh.setBuffer(Type.Position, 3, lineVertex); lineMesh.setBuffer(Type.Color, 4, lineColor); lineMesh.setStatic(); // lineMesh.setInterleaved(); return lineMesh; }
Example 7
Source File: TestTangentGen.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private Mesh createTriangleStripMesh() { Mesh strip = new Mesh(); strip.setMode(Mode.TriangleStrip); FloatBuffer vb = BufferUtils.createFloatBuffer(3*3*3); // 3 rows * 3 columns * 3 floats vb.rewind(); vb.put(new float[]{0,2,0}); vb.put(new float[]{1,2,0}); vb.put(new float[]{2,2,0}); vb.put(new float[]{0,1,0}); vb.put(new float[]{1,1,0}); vb.put(new float[]{2,1,0}); vb.put(new float[]{0,0,0}); vb.put(new float[]{1,0,0}); vb.put(new float[]{2,0,0}); FloatBuffer nb = BufferUtils.createFloatBuffer(3*3*3); nb.rewind(); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); nb.put(new float[]{0,0,1}); FloatBuffer tb = BufferUtils.createFloatBuffer(3*3*2); tb.rewind(); tb.put(new float[]{0,0}); tb.put(new float[]{0.5f,0}); tb.put(new float[]{1,0}); tb.put(new float[]{0,0.5f}); tb.put(new float[]{0.5f,0.5f}); tb.put(new float[]{1,0.5f}); tb.put(new float[]{0,1}); tb.put(new float[]{0.5f,1}); tb.put(new float[]{1,1}); int[] indexes = new int[]{0,3,1,4,2,5, 5,3, 3,6,4,7,5,8}; IntBuffer ib = BufferUtils.createIntBuffer(indexes.length); ib.put(indexes); strip.setBuffer(Type.Position, 3, vb); strip.setBuffer(Type.Normal, 3, nb); strip.setBuffer(Type.TexCoord, 2, tb); strip.setBuffer(Type.Index, 3, ib); strip.updateBound(); return strip; }
Example 8
Source File: WrappedIndexBuffer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public static void convertToList(Mesh mesh){ IndexBuffer inBuf = mesh.getIndicesAsList(); IndexBuffer outBuf = IndexBuffer.createIndexBuffer(mesh.getVertexCount(), inBuf.size()); for (int i = 0; i < inBuf.size(); i++){ outBuf.put(i, inBuf.get(i)); } mesh.clearBuffer(Type.Index); switch (mesh.getMode()){ case LineLoop: case LineStrip: mesh.setMode(Mode.Lines); break; case TriangleStrip: case TriangleFan: mesh.setMode(Mode.Triangles); break; default: break; } if (outBuf instanceof IndexIntBuffer){ mesh.setBuffer(Type.Index, 3, (IntBuffer)outBuf.getBuffer()); }else{ mesh.setBuffer(Type.Index, 3, (ShortBuffer)outBuf.getBuffer()); } }
Example 9
Source File: TangentBinormalGenerator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public static Mesh genNormalLines(Mesh mesh, float scale) { FloatBuffer vertexBuffer = (FloatBuffer) mesh.getBuffer(Type.Position).getData(); FloatBuffer normalBuffer = (FloatBuffer) mesh.getBuffer(Type.Normal).getData(); ColorRGBA originColor = ColorRGBA.White; ColorRGBA normalColor = ColorRGBA.Blue; Mesh lineMesh = new Mesh(); lineMesh.setMode(Mesh.Mode.Lines); Vector3f origin = new Vector3f(); Vector3f point = new Vector3f(); FloatBuffer lineVertex = BufferUtils.createFloatBuffer(vertexBuffer.capacity() * 2); FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.capacity() / 3 * 4 * 2); for (int i = 0; i < vertexBuffer.capacity() / 3; i++) { populateFromBuffer(origin, vertexBuffer, i); populateFromBuffer(point, normalBuffer, i); int index = i * 2; setInBuffer(origin, lineVertex, index); setInBuffer(originColor, lineColor, index); point.multLocal(scale); point.addLocal(origin); setInBuffer(point, lineVertex, index + 1); setInBuffer(normalColor, lineColor, index + 1); } lineMesh.setBuffer(Type.Position, 3, lineVertex); lineMesh.setBuffer(Type.Color, 4, lineColor); lineMesh.setStatic(); lineMesh.setInterleaved(); return lineMesh; }