private void startSharedGeom(String vertexcount) throws SAXException { sharedMesh = new Mesh(); vertCount = parseInt(vertexcount); usesSharedVerts = false; geom = null; mesh = sharedMesh; }
public static Mesh makeFrustum(Vector3f[] points){ Mesh m = new Mesh(); initGeom(m, points); return m; }
protected final void createMesh() { if( mesh == null ) { mesh = new Mesh(); mesh.setMode(Mesh.Mode.Lines); } mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(size * 4 * 3)); FloatBuffer cb = BufferUtils.createFloatBuffer(size * 4 * 4); for( int i = 0; i < size; i++ ) { // For each index we add 4 colors, one for each line // endpoint for two layers. cb.put(0.5f).put(0.5f).put(0).put(1); cb.put(1).put(1).put(0).put(1); cb.put(0).put(0.5f).put(0.5f).put(1); cb.put(0).put(1).put(1).put(1); } mesh.setBuffer(Type.Color, 4, cb); }
public static void main(String[] args) { Mesh mesh = new Mesh(); mesh.setBuffer(Type.Position, 3, new float[]{ 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0 }); mesh.setBuffer(Type.Index, 2, new short[]{ 0, 1, 1, 2, 2, 3, 3, 0 }); Geometry g1 = new Geometry("g1", mesh); ArrayList<Geometry> geoms = new ArrayList<Geometry>(); geoms.add(g1); Mesh outMesh = new Mesh(); mergeGeometries(geoms, outMesh); printMesh(outMesh); }
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; }
public static Mesh convert(IndexedMesh mesh) { Mesh jmeMesh = new Mesh(); jmeMesh.setBuffer(Type.Index, 3, BufferUtils.createShortBuffer(mesh.numTriangles * 3)); jmeMesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(mesh.numVertices * 3)); IndexBuffer indicess = jmeMesh.getIndexBuffer(); FloatBuffer vertices = jmeMesh.getFloatBuffer(Type.Position); for (int i = 0; i < mesh.numTriangles * 3; i++) { indicess.put(i, mesh.triangleIndexBase.getInt(i * 4)); } for (int i = 0; i < mesh.numVertices * 3; i++) { vertices.put(i, mesh.vertexBase.getFloat(i * 4)); } jmeMesh.updateCounts(); jmeMesh.updateBound(); jmeMesh.getFloatBuffer(Type.Position).clear(); return jmeMesh; }
public static Mesh getDebugMesh(CollisionShape shape) { Mesh mesh = null; if (shape.getCShape() instanceof ConvexShape) { mesh = new Mesh(); mesh.setBuffer(Type.Position, 3, getVertices((ConvexShape) shape.getCShape())); mesh.getFloatBuffer(Type.Position).clear(); } else if (shape.getCShape() instanceof ConcaveShape) { mesh = new Mesh(); mesh.setBuffer(Type.Position, 3, getVertices((ConcaveShape) shape.getCShape())); mesh.getFloatBuffer(Type.Position).clear(); } return mesh; }
/** * Create a mesh for visualizing the specified shape. * * @param shape (not null, unaffected) * @return a new mesh (not null) */ public static Mesh getDebugMesh(CollisionShape shape) { Mesh mesh = new Mesh(); DebugMeshCallback callback = new DebugMeshCallback(); long id = shape.getObjectId(); getVertices(id, callback); mesh.setBuffer(Type.Position, 3, callback.getVertices()); mesh.getFloatBuffer(Type.Position).clear(); return mesh; }
settings.putString("TestStr", "HelloWorld"); settings.putFloat("TestFloat", 123.567f); settings.put("TestObj", new Mesh()); // Objects not supported by file settings
pointBuffers.append(vertices.get(point.getIndex()), normals.get(point.getIndex())); Mesh pointsMesh = new Mesh(); pointsMesh.setMode(Mode.Points); pointsMesh.setPointSize(blenderContext.getBlenderKey().getPointsSize());
public Mesh createMesh(Vector3f scale, Vector2f tcScale, boolean center){ FloatBuffer pb = writeVertexArray(null, scale, center); FloatBuffer tb = writeTexCoordArray(null, Vector2f.ZERO, tcScale); FloatBuffer nb = writeNormalArray(null, scale); IntBuffer ib = writeIndexArray(null); Mesh m = new Mesh(); m.setBuffer(Type.Position, 3, pb); m.setBuffer(Type.Normal, 3, nb); m.setBuffer(Type.TexCoord, 2, tb); m.setBuffer(Type.Index, 3, ib); m.setStatic(); m.updateBound(); return m; }
BitmapTextPage(BitmapFont font, boolean arrayBased, int page) { super("BitmapFont", new Mesh()); setRequiresUpdates(false); setBatchHint(BatchHint.Never);
@Test public void testSimpleSort() { Geometry g = new Geometry("test", new Mesh()); LightList list = new LightList(g); list.add(new SpotLight(Vector3f.ZERO, Vector3f.UNIT_X)); list.add(new PointLight(Vector3f.UNIT_X)); list.add(new DirectionalLight(Vector3f.UNIT_X)); list.add(new AmbientLight()); list.sort(true); assert list.get(0) instanceof AmbientLight; // Ambients always first assert list.get(1) instanceof DirectionalLight; // .. then directionals assert list.get(2) instanceof SpotLight; // Spot is 0 units away from geom assert list.get(3) instanceof PointLight; // .. and point is 1 unit away. }
Mesh q = new Mesh(); q.setBuffer(Type.Position, 3, new float[]
/** * Attach a pair of parallel white lines in the z=1 plane. */ void createWhiteLines() { Mesh lineMesh = new Mesh(); lineMesh.setMode(Mesh.Mode.Lines); float[] corners = new float[]{ -1f, -1f, 0f, -1f, 1f, 0f, 1f, 1f, 0f, 1f, -1f, 0f }; lineMesh.setBuffer(VertexBuffer.Type.Position, 3, corners); short[] indices = new short[]{0, 1, 2, 3}; lineMesh.setBuffer(VertexBuffer.Type.Index, 2, indices); lineMesh.updateBound(); Geometry whiteLines = new Geometry("white lines", lineMesh); Material white = assetManager.loadMaterial("Common/Materials/WhiteColor.j3m"); whiteLines.setMaterial(white); whiteLines.move(0f, 0f, 1f); rootNode.attachChild(whiteLines); }
@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); }
/** * Tests preference based AppSettings. */ private static void testPreferenceSettings() { AppSettings settings = new AppSettings(false); settings.putBoolean("TestBool", true); settings.putInteger("TestInt", 123); settings.putString("TestStr", "HelloWorld"); settings.putFloat("TestFloat", 123.567f); settings.put("TestObj", new Mesh()); // Objects not supported by preferences try { settings.save(APPSETTINGS_KEY); } catch (BackingStoreException ex) { ex.printStackTrace(); } AppSettings loadedSettings = new AppSettings(false); try { loadedSettings.load(APPSETTINGS_KEY); } catch (BackingStoreException ex) { ex.printStackTrace(); } assertEqual(loadedSettings.getBoolean("TestBool"), true); assertEqual(loadedSettings.getInteger("TestInt"), 123); assertEqual(loadedSettings.getString("TestStr"), "HelloWorld"); assertEqual(loadedSettings.get("TestFloat"), 123.567f); }
@Override protected void initialize( Application app ) { graph = new Geometry("profiler", profiler.getMesh()); Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.setBoolean("VertexColor", true); graph.setMaterial(mat); graph.setLocalTranslation(0, 300, 0); graph.setLocalScale(1, scale, 1); Mesh mesh = new Mesh(); background = new Geometry("profiler.background", mesh); mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.setBoolean("VertexColor", true); mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); background.setMaterial(mat); background.setLocalTranslation(0, 300, -1); background.setLocalScale(1, scale, 1); refreshBackground(); InputManager inputManager = app.getInputManager(); if( inputManager != null ) { inputManager.addMapping(INPUT_MAPPING_PROFILER_TOGGLE, new KeyTrigger(KeyInput.KEY_F6)); inputManager.addListener(keyListener, INPUT_MAPPING_PROFILER_TOGGLE); } }
ColorRGBA normalColor = ColorRGBA.Blue; Mesh lineMesh = new Mesh(); lineMesh.setMode(Mesh.Mode.Lines);
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); Buffer ib; IndexBuffer idxB = writeIndexArrayLodDiff(lod, rightLod, topLod, leftLod, bottomLod, totalSize); if (idxB.getBuffer() instanceof IntBuffer) ib = (IntBuffer)idxB.getBuffer(); else ib = (ShortBuffer)idxB.getBuffer(); 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); if (ib instanceof IntBuffer) m.setBuffer(Type.Index, 3, (IntBuffer)ib); else if (ib instanceof ShortBuffer) m.setBuffer(Type.Index, 3, (ShortBuffer)ib); m.setStatic(); m.updateBound(); return m; }