com.jme3.scene.Geometry Java Examples
The following examples show how to use
com.jme3.scene.Geometry.
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: ActorDrawer.java From OpenRTS with MIT License | 6 votes |
private void applyToSubmesh(Spatial s, String subMeshName, int subMeshIndex, Object colorOrMaterial){ if(s instanceof Geometry){ Geometry g = (Geometry)s; if(g.getName().equals(subMeshName) || subMeshIndex == 0){ if(colorOrMaterial instanceof Color) g.getMaterial().setColor("Diffuse", TranslateUtil.toColorRGBA((Color)colorOrMaterial)); else if (colorOrMaterial instanceof String) g.setMaterial(MaterialManager.getMaterial((String)colorOrMaterial)); else throw new IllegalArgumentException(); return; } } else { for(Spatial child : ((Node)s).getChildren()){ applyToSubmesh(child, subMeshName, --subMeshIndex, colorOrMaterial); } return; } if(subMeshIndex > 0) { logger.warning("Sub mesh of index "+subMeshIndex+" doesn't seem to exist."); } if(subMeshName != null) { logger.warning("Sub mesh named "+subMeshName+" doesn't seem to exist."); } }
Example #2
Source File: GeomUtils.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * Get the index of the object in the model. */ @FromAnyThread private static boolean getIndex(@NotNull Object model, @NotNull Object object, @NotNull AtomicInteger counter) { counter.incrementAndGet(); if (Objects.equals(model, object)) { return true; } else if (model instanceof Geometry) { return getIndex(((Geometry) model).getMesh(), object, counter); } else if (!(model instanceof Node)) { return false; } var node = (Node) model; var children = node.getChildren(); for (var child : children) { if (getIndex(child, object, counter)) { return true; } } return false; }
Example #3
Source File: TestSpotLight.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void setupFloor(){ Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m"); mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat); mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat); // mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat); mat.setFloat("Shininess",3); // mat.setBoolean("VertexLighting", true); Box floor = new Box(50, 1f, 50); TangentBinormalGenerator.generate(floor); floor.scaleTextureCoordinates(new Vector2f(5, 5)); Geometry floorGeom = new Geometry("Floor", floor); floorGeom.setMaterial(mat); floorGeom.setShadowMode(ShadowMode.Receive); rootNode.attachChild(floorGeom); }
Example #4
Source File: TestBatchNodeCluster.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void randomGenerator() { for (int i = startAt; i < maxCubes - 1; i++) { randomize(); Geometry box = new Geometry("Box" + i, new Box(Vector3f.ZERO, 1, 1, 1)); box.setLocalTranslation(new Vector3f(xPosition.get(xPosition.size() - 1), yPosition.get(yPosition.size() - 1), zPosition.get(zPosition.size() - 1))); batchNode.attachChild(box); if (i < 500) { box.setMaterial(mat1); } else if (i < 1000) { box.setMaterial(mat2); } else if (i < 1500) { box.setMaterial(mat3); } else { box.setMaterial(mat4); } } }
Example #5
Source File: NodeUtils.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
/** * Find a first geometry in the {@link Spatial}. * * @param spatial the spatial. * @param condition the condition. * @return the geometry or null. */ @FromAnyThread public static @Nullable Geometry findGeometry(@NotNull Spatial spatial, @NotNull Predicate<Geometry> condition) { if (!(spatial instanceof Node)) { return null; } var node = (Node) spatial; for (var child : node.getChildren()) { var geometry = findGeometry(child, condition); if (geometry != null) { return geometry; } if (child instanceof Geometry && condition.test((Geometry) child)) { return (Geometry) child; } } return null; }
Example #6
Source File: TestParallelProjection.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void simpleInitApp() { Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj"); DirectionalLight dl = new DirectionalLight(); dl.setColor(ColorRGBA.White); dl.setDirection(Vector3f.UNIT_XYZ.negate()); rootNode.addLight(dl); rootNode.attachChild(teaGeom); // Setup first view cam.setParallelProjection(true); float aspect = (float) cam.getWidth() / cam.getHeight(); cam.setFrustum(-1000, 1000, -aspect * frustumSize, aspect * frustumSize, frustumSize, -frustumSize); inputManager.addListener(this, "Size+", "Size-"); inputManager.addMapping("Size+", new KeyTrigger(KeyInput.KEY_W)); inputManager.addMapping("Size-", new KeyTrigger(KeyInput.KEY_S)); }
Example #7
Source File: RenderQueue.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Adds a geometry to a shadow bucket. * Note that this operation is done automatically by the * {@link RenderManager}. {@link SceneProcessor}s that handle * shadow rendering should fetch the queue by using * {@link #getShadowQueueContent(com.jme3.renderer.queue.RenderQueue.ShadowMode) }, * by default no action is taken on the shadow queues. * * @param g The geometry to add * @param shadBucket The shadow bucket type, if it is * {@link ShadowMode#CastAndReceive}, it is added to both the cast * and the receive buckets. */ public void addToShadowQueue(Geometry g, ShadowMode shadBucket) { switch (shadBucket) { case Inherit: break; case Off: break; case Cast: shadowCast.add(g); break; case Receive: shadowRecv.add(g); break; case CastAndReceive: shadowCast.add(g); shadowRecv.add(g); break; default: throw new UnsupportedOperationException("Unrecognized shadow bucket type: " + shadBucket); } }
Example #8
Source File: TestCubeCluster.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void randomGenerator() { for (int i = startAt; i < maxCubes - 1; i++) { randomize(); Geometry box = new Geometry("Box" + i, new Box(Vector3f.ZERO, 1, 1, 1)); box.setLocalTranslation(new Vector3f(xPosition.get(xPosition.size() - 1), yPosition.get(yPosition.size() - 1), zPosition.get(zPosition.size() - 1))); if (i < 500) { blueList.add(box); } else if (i < 1000) { brownList.add(box); } else if (i < 1500) { pinkList.add(box); } else { orangeList.add(box); } } }
Example #9
Source File: TestBumpModel.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void simpleInitApp() { Spatial signpost = (Spatial) assetManager.loadAsset(new OgreMeshKey("Models/Sign Post/Sign Post.mesh.xml")); signpost.setMaterial( (Material) assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m")); TangentBinormalGenerator.generate(signpost); rootNode.attachChild(signpost); lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f)); lightMdl.setMaterial( (Material) assetManager.loadMaterial("Common/Materials/RedColor.j3m")); rootNode.attachChild(lightMdl); // flourescent main light pl = new PointLight(); pl.setColor(new ColorRGBA(0.88f, 0.92f, 0.95f, 1.0f)); rootNode.addLight(pl); AmbientLight al = new AmbientLight(); al.setColor(new ColorRGBA(0.44f, 0.40f, 0.20f, 1.0f)); rootNode.addLight(al); DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(1,-1,-1).normalizeLocal()); dl.setColor(new ColorRGBA(0.92f, 0.85f, 0.8f, 1.0f)); rootNode.addLight(dl); }
Example #10
Source File: TestTransparentCartoonEdge.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void makeToonish(Spatial spatial){ if (spatial instanceof Node){ Node n = (Node) spatial; for (Spatial child : n.getChildren()) makeToonish(child); }else if (spatial instanceof Geometry){ Geometry g = (Geometry) spatial; Material m = g.getMaterial(); if (m.getMaterialDef().getName().equals("Phong Lighting")){ Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png"); // t.setMinFilter(Texture.MinFilter.NearestNoMipMaps); // t.setMagFilter(Texture.MagFilter.Nearest); m.setTexture("ColorRamp", t); m.setBoolean("UseMaterialColors", true); m.setColor("Specular", ColorRGBA.Black); m.setColor("Diffuse", ColorRGBA.White); m.setBoolean("VertexLighting", true); } } }
Example #11
Source File: HelloPhysics.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** This method creates one individual physical cannon ball. * By defaul, the ball is accelerated and flies * from the camera position in the camera direction.*/ public void makeCannonBall() { /** Create a cannon ball geometry and attach to scene graph. */ Geometry ball_geo = new Geometry("cannon ball", sphere); ball_geo.setMaterial(stone_mat); rootNode.attachChild(ball_geo); /** Position the cannon ball */ ball_geo.setLocalTranslation(cam.getLocation()); /** Make the ball physcial with a mass > 0.0f */ ball_phy = new RigidBodyControl(1f); /** Add physical ball to physics space. */ ball_geo.addControl(ball_phy); bulletAppState.getPhysicsSpace().add(ball_phy); /** Accelerate the physcial ball to shoot it. */ ball_phy.setLinearVelocity(cam.getDirection().mult(25)); }
Example #12
Source File: GeometryBatchFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
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); }
Example #13
Source File: TestUnshadedModel.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void simpleInitApp() { Sphere sphMesh = new Sphere(32, 32, 1); sphMesh.setTextureMode(Sphere.TextureMode.Projected); sphMesh.updateGeometry(32, 32, 1, false, false); TangentBinormalGenerator.generate(sphMesh); Geometry sphere = new Geometry("Rock Ball", sphMesh); Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m"); mat.setColor("Ambient", ColorRGBA.DarkGray); mat.setColor("Diffuse", ColorRGBA.White); mat.setBoolean("UseMaterialColors", true); sphere.setMaterial(mat); rootNode.attachChild(sphere); PointLight pl = new PointLight(); pl.setColor(ColorRGBA.White); pl.setPosition(new Vector3f(4f, 0f, 0f)); rootNode.addLight(pl); AmbientLight al = new AmbientLight(); al.setColor(ColorRGBA.White); rootNode.addLight(al); }
Example #14
Source File: TestNiftyGui.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleInitApp() { Box b = new Box(1, 1, 1); Geometry geom = new Geometry("Box", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); geom.setMaterial(mat); rootNode.attachChild(geom); NiftyJmeDisplay niftyDisplay = NiftyJmeDisplay.newNiftyJmeDisplay( assetManager, inputManager, audioRenderer, guiViewPort); nifty = niftyDisplay.getNifty(); nifty.fromXml("Interface/Nifty/HelloJme.xml", "start", this); // attach the nifty display to the gui view port as a processor guiViewPort.addProcessor(niftyDisplay); // disable the fly cam // flyCam.setEnabled(false); // flyCam.setDragToRotate(true); inputManager.setCursorVisible(true); }
Example #15
Source File: GeometryTreeNode.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override public void accept(@NotNull final ChangeConsumer changeConsumer, @NotNull final Object object, final boolean isCopy) { final Geometry geometry = getElement(); if (object instanceof Material) { final Material material = (Material) object; if (isCopy) { final Material clone = material.clone(); final PropertyOperation<ChangeConsumer, Geometry, Material> operation = new PropertyOperation<>(geometry, "Material", clone, geometry.getMaterial()); operation.setApplyHandler(Geometry::setMaterial); changeConsumer.execute(operation); } } super.accept(changeConsumer, object, isCopy); }
Example #16
Source File: TestTransparentCartoonEdge.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void makeToonish(Spatial spatial){ if (spatial instanceof Node){ Node n = (Node) spatial; for (Spatial child : n.getChildren()) makeToonish(child); }else if (spatial instanceof Geometry){ Geometry g = (Geometry) spatial; Material m = g.getMaterial(); if (m.getMaterialDef().getName().equals("Phong Lighting")){ Texture t = assetManager.loadTexture("Textures/ColorRamp/toon.png"); // t.setMinFilter(Texture.MinFilter.NearestNoMipMaps); // t.setMagFilter(Texture.MagFilter.Nearest); m.setTexture("ColorRamp", t); m.setBoolean("UseMaterialColors", true); m.setColor("Specular", ColorRGBA.Black); m.setColor("Diffuse", ColorRGBA.White); m.setBoolean("VertexLighting", true); } } }
Example #17
Source File: SimpleWaterProcessor.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * Creates a quad with the water material applied to it. * @param width * @param height * @return */ public Geometry createWaterGeometry(float width, float height) { Quad quad = new Quad(width, height); Geometry geom = new Geometry("WaterGeometry", quad); geom.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); geom.setMaterial(material); return geom; }
Example #18
Source File: TestObjLoading.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { // create the geometry and attach it Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj"); // show normals as material Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md"); teaGeom.setMaterial(mat); rootNode.attachChild(teaGeom); }
Example #19
Source File: MaterialDebugAppState.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Material reloadMaterial(Material mat) { //clear the entire cache, there might be more clever things to do, like clearing only the matdef, and the associated shaders. assetManager.clearCache(); //creating a dummy mat with the mat def of the mat to reload // Force the reloading of the asset, otherwise the new shader code will not be applied. Material dummy = new Material(assetManager, mat.getMaterialDef().getAssetName()); for (MatParam matParam : mat.getParams()) { dummy.setParam(matParam.getName(), matParam.getVarType(), matParam.getValue()); } dummy.getAdditionalRenderState().set(mat.getAdditionalRenderState()); //creating a dummy geom and assigning the dummy material to it Geometry dummyGeom = new Geometry("dummyGeom", new Box(1f, 1f, 1f)); dummyGeom.setMaterial(dummy); try { //preloading the dummyGeom, this call will compile the shader again renderManager.preloadScene(dummyGeom); } catch (RendererException e) { //compilation error, the shader code will be output to the console //the following code will output the error //System.err.println(e.getMessage()); Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, e.getMessage()); return null; } Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.INFO, "Material succesfully reloaded"); //System.out.println("Material succesfully reloaded"); return dummy; }
Example #20
Source File: TestSplitScreen.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { flyCam.setEnabled(false); Geometry blueBox = new Geometry("blue box", mesh); Material blueMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); blueMat.setColor("Color", ColorRGBA.Blue); blueBox.setMaterial(blueMat); rootNode.attachChild(blueBox); rightCam = cam.clone(); rightCam.setViewPort(0.5f, 1f, 0f, 1f); rightView = renderManager.createMainView("right", rightCam); rightView.setClearFlags(true, true, true); rightView.setEnabled(false); rightView.attachScene(rootNode); Geometry redBox = new Geometry("red box", mesh); Material redMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); redMat.setColor("Color", ColorRGBA.Red); redBox.setMaterial(redMat); leftScene.attachChild(redBox); leftCam = cam.clone(); leftCam.setViewPort(0f, 0.5f, 0f, 1f); leftView = renderManager.createMainView("left", leftCam); leftView.setClearFlags(true, true, true); leftView.setEnabled(false); leftView.attachScene(leftScene); inputManager.addMapping("lmb", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); inputManager.addListener(this, "lmb"); }
Example #21
Source File: PhysicsTestHelper.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * creates the necessary inputlistener and action to shoot balls from the camera * * @param app the application that's running * @param rootNode where ball geometries should be added * @param space where collision objects should be added */ public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) { ActionListener actionListener = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { Sphere bullet = new Sphere(32, 32, 0.4f, true, false); bullet.setTextureMode(TextureMode.Projected); Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG"); key2.setGenerateMips(true); Texture tex2 = app.getAssetManager().loadTexture(key2); mat2.setTexture("ColorMap", tex2); if (name.equals("shoot") && !keyPressed) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(app.getCamera().getLocation()); RigidBodyControl bulletControl = new RigidBodyControl(10); bulletg.addControl(bulletControl); bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25)); bulletg.addControl(bulletControl); rootNode.attachChild(bulletg); space.add(bulletControl); } } }; app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); app.getInputManager().addListener(actionListener, "shoot"); }
Example #22
Source File: RagUtils.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Validate a model for use with DynamicAnimControl. * * @param model the model to validate (not null, unaffected) */ static void validate(Spatial model) { List<Geometry> geometries = listGeometries(model, null); if (geometries.isEmpty()) { throw new IllegalArgumentException("No meshes in the model."); } for (Geometry geometry : geometries) { if (geometry.isIgnoreTransform()) { throw new IllegalArgumentException( "A model geometry ignores transforms."); } } }
Example #23
Source File: HelloNode.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void simpleInitApp() { /** create a blue box at coordinates (1,-1,1) */ Box box1 = new Box(1,1,1); Geometry blue = new Geometry("Box", box1); blue.setLocalTranslation(new Vector3f(1,-1,1)); Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat1.setColor("Color", ColorRGBA.Blue); blue.setMaterial(mat1); /** create a red box straight above the blue one at (1,3,1) */ Box box2 = new Box(1,1,1); Geometry red = new Geometry("Box", box2); red.setLocalTranslation(new Vector3f(1,3,1)); Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat2.setColor("Color", ColorRGBA.Red); red.setMaterial(mat2); /** Create a pivot node at (0,0,0) and attach it to the root node */ Node pivot = new Node("pivot"); rootNode.attachChild(pivot); // put this node in the scene /** Attach the two boxes to the *pivot* node. (And transitively to the root node.) */ pivot.attachChild(blue); pivot.attachChild(red); /** Rotate the pivot node: Note that both boxes have rotated! */ pivot.rotate(.4f,.4f,0f); }
Example #24
Source File: BulletVehicleDebugControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void createVehicle() { suspensionNode.detachAllChildren(); 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(); Arrow locArrow = new Arrow(location); Arrow axleArrow = new Arrow(axle.normalizeLocal().multLocal(0.3f)); Arrow wheelArrow = new Arrow(direction.normalizeLocal().multLocal(radius)); Arrow dirArrow = new Arrow(direction.normalizeLocal().multLocal(restLength)); Geometry locGeom = new Geometry("WheelLocationDebugShape" + i, locArrow); Geometry dirGeom = new Geometry("WheelDirectionDebugShape" + i, dirArrow); Geometry axleGeom = new Geometry("WheelAxleDebugShape" + i, axleArrow); Geometry wheelGeom = new Geometry("WheelRadiusDebugShape" + i, wheelArrow); dirGeom.setLocalTranslation(location); axleGeom.setLocalTranslation(location.add(direction)); wheelGeom.setLocalTranslation(location.add(direction)); locGeom.setMaterial(debugAppState.DEBUG_MAGENTA); dirGeom.setMaterial(debugAppState.DEBUG_MAGENTA); axleGeom.setMaterial(debugAppState.DEBUG_MAGENTA); wheelGeom.setMaterial(debugAppState.DEBUG_MAGENTA); suspensionNode.attachChild(locGeom); suspensionNode.attachChild(dirGeom); suspensionNode.attachChild(axleGeom); suspensionNode.attachChild(wheelGeom); } }
Example #25
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public static CollisionShape createBoxShape(Spatial spatial) { if (spatial instanceof Geometry) { return createSingleBoxShape((Geometry) spatial, spatial); } else if (spatial instanceof Node) { return createBoxCompoundShape((Node) spatial); } else { throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!"); } }
Example #26
Source File: ParticlesModifier.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Node apply(Node node, BlenderContext blenderContext) { if (invalid) { LOGGER.log(Level.WARNING, "Particles modifier is invalid! Cannot be applied to: {0}", node.getName()); return node; } MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class); ParticleEmitter emitter = particleEmitter.clone(); // veryfying the alpha function for particles' texture Integer alphaFunction = MaterialHelper.ALPHA_MASK_HYPERBOLE; char nameSuffix = emitter.getName().charAt(emitter.getName().length() - 1); if (nameSuffix == 'B' || nameSuffix == 'N') { alphaFunction = MaterialHelper.ALPHA_MASK_NONE; } // removing the type suffix from the name emitter.setName(emitter.getName().substring(0, emitter.getName().length() - 1)); // applying emitter shape EmitterShape emitterShape = emitter.getShape(); List<Mesh> meshes = new ArrayList<Mesh>(); for (Spatial spatial : node.getChildren()) { if (spatial instanceof Geometry) { Mesh mesh = ((Geometry) spatial).getMesh(); if (mesh != null) { meshes.add(mesh); Material material = materialHelper.getParticlesMaterial(((Geometry) spatial).getMaterial(), alphaFunction, blenderContext); emitter.setMaterial(material);// TODO: divide into several pieces } } } if (meshes.size() > 0 && emitterShape instanceof EmitterMeshVertexShape) { ((EmitterMeshVertexShape) emitterShape).setMeshes(meshes); } node.attachChild(emitter); return node; }
Example #27
Source File: CollideIgnoreTransformTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Attach a red square in the XY plane with its lower left corner at (0, 0, * 0). It is composed of 2 triangles. */ void createRedSquare() { Mesh quadMesh = new Quad(1f, 1f); Geometry redSquare = new Geometry("red square", quadMesh); Material red = assetManager.loadMaterial("Common/Materials/RedColor.j3m"); redSquare.setMaterial(red); rootNode.attachChild(redSquare); redSquare.setLocalTranslation(0f, 3f, 0f); redSquare.setIgnoreTransform(true); }
Example #28
Source File: BoundingCollisionTest.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testBoxTriangleCollision() { BoundingBox box = new BoundingBox(Vector3f.ZERO, 1, 1, 1); Geometry geom = new Geometry("geom", new Quad(1, 1)); checkCollision(box, geom, 2); // Both triangles intersect // The box touches the edges of the triangles. box.setCenter(new Vector3f(-1f, 0, 0)); checkCollision(box, geom, 2); // Move it slightly farther.. box.setCenter(new Vector3f(-1f - FastMath.ZERO_TOLERANCE, 0, 0)); checkCollision(box, geom, 0); // Parallel triangle / box side, touching box.setCenter(new Vector3f(0, 0, -1f)); checkCollision(box, geom, 2); // Not touching box.setCenter(new Vector3f(0, 0, -1f - FastMath.ZERO_TOLERANCE)); checkCollision(box, geom, 0); // Test collisions only against one of the triangles box.setCenter(new Vector3f(-1f, 1.5f, 0f)); checkCollision(box, geom, 1); box.setCenter(new Vector3f(1.5f, -1f, 0f)); checkCollision(box, geom, 1); }
Example #29
Source File: TestCollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.getPhysicsSpace().enableDebug(assetManager); createMaterial(); Node node = new Node("node1"); attachRandomGeometry(node, mat1); randomizeTransform(node); Node node2 = new Node("node2"); attachRandomGeometry(node2, mat2); randomizeTransform(node2); node.attachChild(node2); rootNode.attachChild(node); RigidBodyControl control = new RigidBodyControl(0); node.addControl(control); getPhysicsSpace().add(control); //test single geometry too Geometry myGeom = new Geometry("cylinder", new Cylinder(16, 16, 0.5f, 1)); myGeom.setMaterial(mat3); randomizeTransform(myGeom); rootNode.attachChild(myGeom); RigidBodyControl control3 = new RigidBodyControl(0); myGeom.addControl(control3); getPhysicsSpace().add(control3); }
Example #30
Source File: CollisionShapeFactory.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * This method creates a hull shape for the given Spatial.<br> * If you want to have mesh-accurate dynamic shapes (CPU intense!!!) use GImpact shapes, its probably best to do so with a low-poly version of your model. * @return A HullCollisionShape or a CompoundCollisionShape with HullCollisionShapes as children if the supplied spatial is a Node. */ public static CollisionShape createDynamicMeshShape(Spatial spatial) { if (spatial instanceof Geometry) { return createSingleDynamicMeshShape((Geometry) spatial, spatial); } else if (spatial instanceof Node) { return createCompoundShape((Node) spatial, (Node) spatial, new CompoundCollisionShape(), true, true); } else { throw new IllegalArgumentException("Supplied spatial must either be Node or Geometry!"); } }