Java Code Examples for com.jme3.scene.Geometry#getMesh()
The following examples show how to use
com.jme3.scene.Geometry#getMesh() .
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: GeometryTreeNode.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override public @NotNull Array<TreeNode<?>> getChildren(@NotNull final NodeTree<?> nodeTree) { if (!(nodeTree instanceof ModelNodeTree)) return TreeNode.EMPTY_ARRAY; final Array<TreeNode<?>> result = ArrayFactory.newArray(TreeNode.class); final Geometry geometry = getElement(); final Mesh mesh = geometry.getMesh(); final Material material = geometry.getMaterial(); if (mesh != null) result.add(FACTORY_REGISTRY.createFor(mesh)); result.add(FACTORY_REGISTRY.createFor(material)); result.addAll(super.getChildren(nodeTree)); return result; }
Example 2
Source File: SilentTangentBinormalGenerator.java From OpenRTS with MIT License | 6 votes |
public static void generate(Spatial scene, boolean splitMirrored) { if (scene instanceof Node) { Node node = (Node) scene; for (Spatial child : node.getChildren()) { generate(child, splitMirrored); } } else { Geometry geom = (Geometry) scene; Mesh mesh = geom.getMesh(); // Check to ensure mesh has texcoords and normals before generating if (mesh.getBuffer(Type.TexCoord) != null && mesh.getBuffer(Type.Normal) != null) { generate(geom.getMesh(), true, splitMirrored); } } }
Example 3
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 4
Source File: TestGimpactShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private RigidBodyControl drop(Vector3f offset, String model, float scale, float mass) { scale *= scaleMod; Node n = (Node) assetManager.loadModel(model); n.setLocalTranslation(offset); n.rotate(0, 0, -FastMath.HALF_PI); Geometry tp = ((Geometry) n.getChild(0)); tp.scale(scale); Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); tp.setMaterial(mat); Mesh mesh = tp.getMesh(); GImpactCollisionShape shape = new GImpactCollisionShape(mesh); shape.setScale(new Vector3f(scale, scale, scale)); RigidBodyControl control = new RigidBodyControl(shape, mass); n.addControl(control); addObject(n); return control; }
Example 5
Source File: TestTriangleStrip.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void simpleInitApp() { Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj"); Mesh teaMesh = teaGeom.getMesh(); ModelConverter.generateStrips(teaMesh, true, false, 24, 0); // show normals as material Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md"); for (int y = -10; y < 10; y++){ for (int x = -10; x < 10; x++){ Geometry teaClone = new Geometry("teapot", teaMesh); teaClone.setMaterial(mat); teaClone.setLocalTranslation(x * .5f, 0, y * .5f); teaClone.setLocalScale(.5f); rootNode.attachChild(teaClone); } } cam.setLocation(new Vector3f(8.378951f, 5.4324f, 8.795956f)); cam.setRotation(new Quaternion(-0.083419204f, 0.90370524f, -0.20599906f, -0.36595422f)); }
Example 6
Source File: LodControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void setSpatial(Spatial spatial) { if (spatial != null && !(spatial instanceof Geometry)) { throw new IllegalArgumentException("LodControl can only be attached to Geometry!"); } super.setSpatial(spatial); if(spatial != null) { Geometry geom = (Geometry) spatial; Mesh mesh = geom.getMesh(); numLevels = mesh.getNumLodLevels(); numTris = new int[numLevels]; for (int i = numLevels - 1; i >= 0; i--) { numTris[i] = mesh.getTriangleCount(i); } } else { numLevels = 0; numTris = null; } }
Example 7
Source File: LodControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void setSpatial(Spatial spatial){ if (!(spatial instanceof Geometry)) throw new IllegalArgumentException("LodControl can only be attached to Geometry!"); super.setSpatial(spatial); Geometry geom = (Geometry) spatial; Mesh mesh = geom.getMesh(); numLevels = mesh.getNumLodLevels(); numTris = new int[numLevels]; for (int i = numLevels - 1; i >= 0; i--) numTris[i] = mesh.getTriangleCount(i); }
Example 8
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * This method creates a hull collision shape for the given mesh.<br> */ private static HullCollisionShape createSingleDynamicMeshShape(Geometry geom, Spatial parent) { Mesh mesh = geom.getMesh(); Transform trans = getTransform(geom, parent); if (mesh != null) { HullCollisionShape dynamicShape = new HullCollisionShape(mesh); dynamicShape.setScale(trans.getScale()); return dynamicShape; } else { return null; } }
Example 9
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * This type of collision shape is mesh-accurate and meant for immovable "world objects". * Examples include terrain, houses or whole shooter levels.<br> * Objects with "mesh" type collision shape will not collide with each other. */ private static MeshCollisionShape createSingleMeshShape(Geometry geom, Spatial parent) { Mesh mesh = geom.getMesh(); Transform trans = getTransform(geom, parent); if (mesh != null) { MeshCollisionShape mColl = new MeshCollisionShape(mesh); mColl.setScale(trans.getScale()); return mColl; } else { return null; } }
Example 10
Source File: TextureAtlas.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Applies the texture coordinates to the given output mesh * if the DiffuseMap or ColorMap of the input geometry exist in the atlas. * @param geom The geometry to change the texture coordinate buffer on. * @param offset Target buffer offset. * @param outMesh The mesh to set the coords in (can be same as input). * @return true if texture has been found and coords have been changed, false otherwise. */ public boolean applyCoords(Geometry geom, int offset, Mesh outMesh) { Mesh inMesh = geom.getMesh(); geom.computeWorldMatrix(); VertexBuffer inBuf = inMesh.getBuffer(Type.TexCoord); VertexBuffer outBuf = outMesh.getBuffer(Type.TexCoord); if (inBuf == null || outBuf == null) { throw new IllegalStateException("Geometry mesh has no texture coordinate buffer."); } Texture tex = getMaterialTexture(geom, "DiffuseMap"); if (tex == null) { tex = getMaterialTexture(geom, "ColorMap"); } if (tex != null) { TextureAtlasTile tile = getAtlasTile(tex); if (tile != null) { FloatBuffer inPos = (FloatBuffer) inBuf.getData(); FloatBuffer outPos = (FloatBuffer) outBuf.getData(); tile.transformTextureCoords(inPos, offset, outPos); return true; } else { return false; } } else { throw new IllegalStateException("Geometry has no proper texture."); } }
Example 11
Source File: DefaultTechniqueDefLogic.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void renderMeshFromGeometry(Renderer renderer, Geometry geom) { Mesh mesh = geom.getMesh(); int lodLevel = geom.getLodLevel(); if (geom instanceof InstancedGeometry) { InstancedGeometry instGeom = (InstancedGeometry) geom; renderer.renderMesh(mesh, lodLevel, instGeom.getActualNumInstances(), instGeom.getAllInstanceData()); } else { renderer.renderMesh(mesh, lodLevel, 1, null); } }
Example 12
Source File: BulletVehicleDebugControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Update this control. Invoked once per frame during the logical-state * update, provided the control is enabled and added to a scene. Should be * invoked only by a subclass or by AbstractControl. * * @param tpf the time interval between frames (in seconds, ≥0) */ @Override protected void controlUpdate(float tpf) { for (int i = 0; i < body.getNumWheels(); i++) { VehicleWheel physicsVehicleWheel = body.getWheel(i); Vector3f location = physicsVehicleWheel.getLocation().clone(); Vector3f direction = physicsVehicleWheel.getDirection().clone(); Vector3f axle = physicsVehicleWheel.getAxle().clone(); float restLength = physicsVehicleWheel.getRestLength(); float radius = physicsVehicleWheel.getRadius(); Geometry locGeom = (Geometry) suspensionNode.getChild("WheelLocationDebugShape" + i); Geometry dirGeom = (Geometry) suspensionNode.getChild("WheelDirectionDebugShape" + i); Geometry axleGeom = (Geometry) suspensionNode.getChild("WheelAxleDebugShape" + i); Geometry wheelGeom = (Geometry) suspensionNode.getChild("WheelRadiusDebugShape" + i); Arrow locArrow = (Arrow) locGeom.getMesh(); locArrow.setArrowExtent(location); Arrow axleArrow = (Arrow) axleGeom.getMesh(); axleArrow.setArrowExtent(axle.normalizeLocal().multLocal(0.3f)); Arrow wheelArrow = (Arrow) wheelGeom.getMesh(); wheelArrow.setArrowExtent(direction.normalizeLocal().multLocal(radius)); Arrow dirArrow = (Arrow) dirGeom.getMesh(); dirArrow.setArrowExtent(direction.normalizeLocal().multLocal(restLength)); dirGeom.setLocalTranslation(location); axleGeom.setLocalTranslation(location.addLocal(direction)); wheelGeom.setLocalTranslation(location); i++; } applyPhysicsTransform(body.getPhysicsLocation(location), body.getPhysicsRotation(rotation)); }
Example 13
Source File: RenderManager.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Preloads a scene for rendering. * <p> * After invocation of this method, the underlying * renderer would have uploaded any textures, shaders and meshes * used by the given scene to the video driver. * Using this method is useful when wishing to avoid the initial pause * when rendering a scene for the first time. Note that it is not * guaranteed that the underlying renderer will actually choose to upload * the data to the GPU so some pause is still to be expected. * * @param scene The scene to preload */ public void preloadScene(Spatial scene) { if (scene instanceof Node) { // recurse for all children Node n = (Node) scene; List<Spatial> children = n.getChildren(); for (int i = 0; i < children.size(); i++) { preloadScene(children.get(i)); } } else if (scene instanceof Geometry) { // add to the render queue Geometry gm = (Geometry) scene; if (gm.getMaterial() == null) { throw new IllegalStateException("No material is set for Geometry: " + gm.getName()); } gm.getMaterial().preload(this); Mesh mesh = gm.getMesh(); if (mesh != null) { for (Entry<VertexBuffer> entry : mesh.getBuffers()) { VertexBuffer buf = entry.getValue(); if (buf.getData() != null) { renderer.updateBufferData(buf); } } } } }
Example 14
Source File: TestIssue1004.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { BulletAppState bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); String sinbadPath = "Models/Sinbad/SinbadOldAnim.j3o"; Node sinbad = (Node) assetManager.loadModel(sinbadPath); Geometry geometry = (Geometry) sinbad.getChild(0); Mesh mesh = geometry.getMesh(); VertexBuffer.Type bufferType = VertexBuffer.Type.BoneIndex; VertexBuffer vertexBuffer = mesh.getBuffer(bufferType); // Remove the existing bone-index buffer. mesh.getBufferList().remove(vertexBuffer); mesh.getBuffers().remove(bufferType.ordinal()); // Copy the 8-bit bone indices to 16-bit indices. ByteBuffer oldBuffer = (ByteBuffer) vertexBuffer.getDataReadOnly(); int numComponents = oldBuffer.limit(); oldBuffer.rewind(); short[] shortArray = new short[numComponents]; for (int index = 0; oldBuffer.hasRemaining(); ++index) { shortArray[index] = oldBuffer.get(); } // Add the 16-bit bone indices to the mesh. mesh.setBuffer(bufferType, 4, shortArray); KinematicRagdollControl ragdoll = new KinematicRagdollControl(0.5f); sinbad.addControl(ragdoll); stop(); }
Example 15
Source File: PaintingUtils.java From jmonkeybuilder with Apache License 2.0 | 5 votes |
/** * Check that the point is contains in the geometry. * * @param geometry the geometry. * @param x the X component. * @param y the Y component. * @return true if the geometry contains the point. */ @FromAnyThread public static boolean isContains(@NotNull Geometry geometry, float x, float y) { var mesh = geometry.getMesh(); var localScale = geometry.getLocalScale(); if (mesh instanceof Sphere) { var radius = ((Sphere) mesh).getRadius() * localScale.getX(); // return true if the distance is less than equal to the radius return Math.abs(CoordsUtils.length(x, y)) <= radius; } return false; }
Example 16
Source File: GeometryOptimizer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void add(Geometry geom) { Mesh mesh = geom.getMesh(); if (mesh != null) { meshSet.add(mesh); } }
Example 17
Source File: VehicleControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void render(RenderManager rm, ViewPort vp) { if (enabled && space != null && space.getDebugManager() != null) { if (debugShape == null) { attachDebugShape(space.getDebugManager()); } Node debugNode = (Node) debugShape; debugShape.setLocalTranslation(spatial.getWorldTranslation()); debugShape.setLocalRotation(spatial.getWorldRotation()); int i = 0; for (Iterator<VehicleWheel> it = wheels.iterator(); it.hasNext();) { VehicleWheel physicsVehicleWheel = it.next(); Vector3f location = physicsVehicleWheel.getLocation().clone(); Vector3f direction = physicsVehicleWheel.getDirection().clone(); Vector3f axle = physicsVehicleWheel.getAxle().clone(); float restLength = physicsVehicleWheel.getRestLength(); float radius = physicsVehicleWheel.getRadius(); Geometry locGeom = (Geometry) debugNode.getChild("WheelLocationDebugShape" + i); Geometry dirGeom = (Geometry) debugNode.getChild("WheelDirectionDebugShape" + i); Geometry axleGeom = (Geometry) debugNode.getChild("WheelAxleDebugShape" + i); Geometry wheelGeom = (Geometry) debugNode.getChild("WheelRadiusDebugShape" + i); Arrow locArrow = (Arrow) locGeom.getMesh(); locArrow.setArrowExtent(location); Arrow axleArrow = (Arrow) axleGeom.getMesh(); axleArrow.setArrowExtent(axle.normalizeLocal().multLocal(0.3f)); Arrow wheelArrow = (Arrow) wheelGeom.getMesh(); wheelArrow.setArrowExtent(direction.normalizeLocal().multLocal(radius)); Arrow dirArrow = (Arrow) dirGeom.getMesh(); dirArrow.setArrowExtent(direction.normalizeLocal().multLocal(restLength)); dirGeom.setLocalTranslation(location); axleGeom.setLocalTranslation(location.addLocal(direction)); wheelGeom.setLocalTranslation(location); i++; } debugShape.updateLogicalState(0); debugShape.updateGeometricState(); rm.renderScene(debugShape, vp); } }
Example 18
Source File: GenerateLodLevelsDialog.java From jmonkeybuilder with Apache License 2.0 | 4 votes |
public GenerateLodLevelsDialog(@NotNull final NodeTree<?> nodeTree, final @NotNull Geometry geometry) { this.nodeTree = nodeTree; this.geometry = geometry; this.mesh = geometry.getMesh(); updateButtonOk(); }
Example 19
Source File: PhysicsTestHelper.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Creates a curved "floor" with a MeshCollisionShape provided as the RigidBodyControl's collision shape. * Surface has four slightly concave corners to allow for multiple tests and minimize falling off the edge * of the floor. * * @param assetManager for loading assets * @param floorDimensions width/depth of the "floor" (X/Z) * @param position sets the floor's local translation * @return */ public static Geometry createMeshTestFloor(AssetManager assetManager, float floorDimensions, Vector3f position) { Geometry floor = createTestFloor(assetManager, floorDimensions, position, new ColorRGBA(0.5f, 0.5f, 0.9f, 1)); RigidBodyControl floorControl = new RigidBodyControl(new MeshCollisionShape(floor.getMesh()), 0); floor.addControl(floorControl); return floor; }
Example 20
Source File: LodGenerator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Construct a LodGenerator for the given geometry * * @param geom the geometry to consider to generate de Lods. */ public LodGenerator(Geometry geom) { mesh = geom.getMesh(); build(); }