/** * Creates the default axes, which are lines of different colors from the origin to the unit * vectors. These are attached to the Node {@link #axes}. */ protected void initAxes() { Geometry geometry; Line line; float lineWidth = 3f; // Create the x axis as a red line of unit length. line = new Line(Vector3f.ZERO, Vector3f.UNIT_X); line.setLineWidth(lineWidth); geometry = new Geometry("x", line); geometry.setMaterial(materials.get("XAxis")); axes.attachChild(geometry); // Create the y axis as a green line of unit length. line = new Line(Vector3f.ZERO, Vector3f.UNIT_Y); line.setLineWidth(lineWidth); geometry = new Geometry("y", line); geometry.setMaterial(materials.get("YAxis")); axes.attachChild(geometry); // Create the z axis as a blue line of unit length. line = new Line(Vector3f.ZERO, Vector3f.UNIT_Z); line.setLineWidth(lineWidth); geometry = new Geometry("z", line); geometry.setMaterial(materials.get("ZAxis")); axes.attachChild(geometry); return; }
@Override public void simpleInitApp() { /** create a blue box at coordinates (1,-1,1) */ Box box1 = new Box(new Vector3f(1, -1, 1), 1, 1, 1); Geometry blue = new Geometry("Box", box1); Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.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(new Vector3f(1, 3, 1), 1, 1, 1); Geometry red = new Geometry("Box", box2); Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.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); }
@Override public void simpleInitApp() { JmeCanvasContext ctx = (JmeCanvasContext) getContext(); gui = new GUI(this, ctx.getCanvas()); gui.show(); flyCam.setEnabled(false); Box b = new Box(1, 1, 1); Geometry geom = new Geometry("Box", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Blue); geom.setMaterial(mat); rootNode.attachChild(geom); cinematic = new Cinematic(rootNode, 5); MotionPath path = new MotionPath(); path.addWayPoint(Vector3f.ZERO.clone()); path.addWayPoint(new Vector3f(10, 0, 0)); MotionEvent motionEvent = new MotionEvent(geom, path, 5); cinematic.addCinematicEvent(0, motionEvent); cinematic.fitDuration(); cinematic.setLoopMode(LoopMode.Loop); stateManager.attach(cinematic); }
/** * 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; }
public void UserJoin(HostedConnection source, Message message) { boolean bfound = false; // SMObjectShare SMObjshare = (SMObjectShare)smobj; for (SMObjectPlayerController player : players) { if (source.getId() == Integer.parseInt(player.smobjshare.userid)) { SMObjectShare shareobject = (SMObjectShare) message; player.smobjshare = shareobject; // player.getSpatial().setLocalTranslation(shareobject.x, shareobject.y, shareobject.z); bfound = true; } } if (!bfound) { Box objplayer = new Box(Vector3f.ZERO, 1, 1, 1); Geometry geomplayer = new Geometry("Box", objplayer); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("m_Color", ColorRGBA.Brown); geomplayer.setMaterial(mat); Spatial spl = (Spatial) geomplayer; SMObjectPlayerController newplayer = new SMObjectPlayerController(spl); newplayer.smobjshare = new SMObjectShare(); newplayer.smobjshare.userid = Integer.toString(source.getId()); newplayer.smobjshare.userid = Integer.toString(source.getId()); source.send(newplayer.smobjshare); rootNode.attachChild(newplayer.getSpatial()); players.add(newplayer); } }
private void attachRandomGeometry(Node node, Material mat) { Box box = new Box(0.25f, 0.25f, 0.25f); Torus torus = new Torus(16, 16, 0.2f, 0.8f); Geometry[] boxes = new Geometry[] { new Geometry("box1", box), new Geometry("box2", box), new Geometry("box3", box), new Geometry("torus1", torus), new Geometry("torus2", torus), new Geometry("torus3", torus) }; for (int i = 0; i < boxes.length; i++) { Geometry geometry = boxes[i]; geometry.setLocalTranslation( (float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10); geometry.setLocalRotation( new Quaternion() .fromAngles( (float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI)); geometry.setLocalScale( (float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10); geometry.setMaterial(mat); node.attachChild(geometry); } }
@Override public void simpleInitApp() { // add a random cube Box b = new Box(1, 1, 1); Geometry geom = new Geometry("Box", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.randomColor()); geom.setMaterial(mat); geom.move( (FastMath.nextRandomFloat() * 10) - 5, (FastMath.nextRandomFloat() * 10) - 5, (FastMath.nextRandomFloat() * -10)); rootNode.attachChild(geom); // add saved cubes String userHome = System.getProperty("user.home"); BinaryImporter importer = BinaryImporter.getInstance(); importer.setAssetManager(assetManager); try { File file = new File(userHome + "/mycoolgame/savedgame.j3o"); Node sceneNode = (Node) importer.load(file); sceneNode.setName("My restored node"); rootNode.attachChild(sceneNode); Logger.getLogger(SaveAndLoad.class.getName()).log(Level.INFO, "Success: Loaded saved node."); } catch (IOException ex) { Logger.getLogger(SaveAndLoad.class.getName()) .log(Level.INFO, "Warning: Could not load saved node.", ex); } }
/** * Returns a player base geometry. * * @param basevec - Local translation for base. * @param basescale - Local scale for base. * @return */ public Geometry getBase(Vector3f basevec, Vector3f basescale) { Geometry base_geom = new Geometry("Base", new Box(1, 1, 1)); base_geom.setMaterial(bs.getMaterial("Base")); base_geom.setLocalScale(basescale); base_geom.setLocalTranslation(basevec); return base_geom; }
@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); }
// debug function that create a displayable frustrum protected Geometry createFrustum(Vector3f[] pts, int i) { WireFrustum frustum = new WireFrustum(pts); Geometry frustumMdl = new Geometry("f", frustum); frustumMdl.setCullHint(Spatial.CullHint.Never); frustumMdl.setShadowMode(ShadowMode.Off); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.getAdditionalRenderState().setWireframe(true); frustumMdl.setMaterial(mat); switch (i) { case 0: frustumMdl.getMaterial().setColor("Color", ColorRGBA.Pink); break; case 1: frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red); break; case 2: frustumMdl.getMaterial().setColor("Color", ColorRGBA.Green); break; case 3: frustumMdl.getMaterial().setColor("Color", ColorRGBA.Blue); break; default: frustumMdl.getMaterial().setColor("Color", ColorRGBA.White); break; } frustumMdl.updateGeometricState(); return frustumMdl; }
Node createDebugGeometry() { Line l = new Line(from.getPlanet().getPosition(), to.getPlanet().getPosition()); line = new Geometry("Line #" + from.getPlanet().getID() + " to #" + to.getPlanet().getID(), l); Material material = new Material( SolarWarsApplication.getInstance().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); Player p = from.getPlanet().getOwner(); ColorRGBA c; if (p == null) { c = ColorRGBA.White.clone(); c.a = 0.5f; material.setColor("Color", c); } else { c = p.getColor(); c.a = 0.5f; material.setColor("Color", c); } material.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha); line.setMaterial(material); createLabel(); Node lineNode = new Node(line.getName() + "_Node"); lineNode.attachChild(line); lineNode.attachChild(label); // Vector3f pos = to.getPlanet().getPosition(). // subtract(from.getPlanet().getPosition()); // lineNode.setLocalTranslation(pos.mult(0.5f)); return lineNode; }
/** A red ball that marks the last spot that was "hit" by the "shot". */ protected void initMark() { Sphere sphere = new Sphere(30, 30, 0.2f); mark = new Geometry("BOOM!", sphere); Material mark_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mark_mat.setColor("Color", ColorRGBA.Red); mark.setMaterial(mark_mat); }
private void displayPlayersPositions() { Map<Vector3f, Integer> playerPositions = gm.getMapManager().getBoard().getPlayerPositions(); Iterator it = playerPositions.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); Vector3f pos = (Vector3f) pairs.getKey(); Integer number = (Integer) pairs.getValue(); Box b = new Box(Vector3f.ZERO, 2.0f, 1.0f, 2.0f); Geometry geom = new Geometry("Box", b); Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.randomColor()); geom.setMaterial(mat); geom.setLocalTranslation(pos.x, 0, pos.z); String geomName = "PLAYERMARKER"; geom.setName(geomName); geom.setUserData(geomName, pos); playerNodes.attachChild(geom); displayLocationName(number.toString(), new Vector3f(pos.x, 1, pos.z)); } }
/** * Main constructor; builds a SphericalSprite from a {@link SpriteData} object * * @param sprite The sprite information to build from */ public SphericalSprite(final SpriteData sprite) { aSpriteInfo = sprite; try { aMaterial = new SphericalMapped(aSpriteInfo.sprite); // Calling two times getHeight() because it's a sphere so it doesn't matter. // Width of texture is twice as long so it's faster to get the height than to get the width // and divide by 2 final Quad q = new Quad(aMaterial.getHeight(), aMaterial.getHeight()); final Geometry g = new Geometry("SphericalSprite-" + aSpriteInfo.sprite + " @ " + hashCode(), q); g.setMaterial(aMaterial); final EverNode image = new EverNode(g); addNode(image); // Offset image so that the origin is around the center of the image aSpriteTransform = image.getNewTransform(); aSpriteTransform .translate( -aMaterial.getHeight() * aSpriteInfo.scale / 2 + aSpriteInfo.x, -aMaterial.getHeight() * aSpriteInfo.scale / 2 + aSpriteInfo.y) .commit(); aSpriteTransform.setScale(aSpriteInfo.scale); } catch (final TextureException e) { // Do nothing; just a blank node aValidSprite = false; System.err.println("Warning: Could not load SphericalSprite! Info = " + aSpriteInfo); } }
/** A cube object for target practice */ protected Geometry makeCube(String name, float x, float y, float z) { Box box = new Box(new Vector3f(x, y, z), 1, 1, 1); Geometry cube = new Geometry(name, box); Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat1.setColor("Color", ColorRGBA.randomColor()); cube.setMaterial(mat1); return cube; }
/** A floor to show that the "shot" can go through several objects. */ protected Geometry makeFloor() { Box box = new Box(new Vector3f(0, -4, -5), 15, .2f, 15); Geometry floor = new Geometry("the Floor", box); Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat1.setColor("Color", ColorRGBA.Gray); floor.setMaterial(mat1); return floor; }
private Geometry putShape(SimpleApplication game, Mesh shape, ColorRGBA color) { Geometry g = new Geometry("coordinate axis", shape); Material mat = new Material(game.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.getAdditionalRenderState().setWireframe(true); mat.setColor("Color", color); g.setMaterial(mat); game.getRootNode().attachChild(g); return g; }
private void setupEnvironments() { // カメラ設定 cam.setFrustumPerspective(80f, 1f, 1f, 1000f); cam.setLocation(new Vector3f(0, 1.5f, 10)); // cam.lookAt(new Vector3f(0, 1.6f, 0), Vector3f.UNIT_Y); flyCam.setDragToRotate(true); // ライティング DirectionalLight dl = new DirectionalLight(); dl.setColor(ColorRGBA.White.mult(3.0f)); dl.setDirection(Vector3f.UNIT_XYZ.negate()); rootNode.addLight(dl); // マテリアル設定 Material textureMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); textureMat.setTexture("ColorMap", assetManager.loadTexture("myAssets/Textures/woodFloor.jpg")); Material whitemat = assetManager.loadMaterial("Common/Materials/WhiteColor.j3m"); // 床面 Box floor = new Box(Vector3f.ZERO, 20.0f, 0.01f, 20.0f); Geometry floorGeom = new Geometry("Floor", floor); floorGeom.setMaterial(textureMat); floorGeom.setLocalTranslation(0, 0, 0); rootNode.attachChild(floorGeom); // 壁面 wallGeom[0] = new Geometry("Wall1", new Box(Vector3f.ZERO, 20f, 4f, 0.1f)); wallGeom[1] = new Geometry("Wall2", new Box(Vector3f.ZERO, 20f, 4f, 0.1f)); wallGeom[2] = new Geometry("Wall3", new Box(Vector3f.ZERO, 20f, 4f, 0.1f)); wallGeom[0].setMaterial(whitemat); wallGeom[1].setMaterial(whitemat); wallGeom[2].setMaterial(whitemat); wallGeom[0].setLocalTranslation(0, 4, -2); wallGeom[1].setLocalTranslation(-20, 4, 0); wallGeom[2].setLocalTranslation(20, 4, 0); wallGeom[1].rotate(0, (float) (Math.PI / 2f), 0); wallGeom[2].rotate(0, (float) (Math.PI / 2f), 0); rootNode.attachChild(wallGeom[0]); rootNode.attachChild(wallGeom[1]); rootNode.attachChild(wallGeom[2]); // 女性をランダムに追加 for (int i = 0; i < girl.length; i++) { girl[i] = assetManager.loadModel("myAssets/Models/WalkingGirl/WalkingGirl.obj"); girlPos[i] = new Vector3f((float) (Math.random() * 16.0f - 8f), 0, (float) (Math.random() * 8f)); // 移動スピードをランダムに girlSpeed[i] = (float) (Math.random() * -0.02f) + 0.01f; if (girlSpeed[i] < 0) { girl[i].rotate(0, (float) (-Math.PI / 2.0f), 0); } else { girl[i].rotate(0, (float) (Math.PI / 2.0f), 0); } girl[i].setLocalTranslation(girlPos[i]); this.rootNode.attachChild(girl[i]); } }
private void setupBox() { Box boxshape1 = new Box(new Vector3f(-3f, 1.1f, 0f), 1f, 1f, 1f); Geometry cube = new Geometry("My Textured Box", boxshape1); Material mat_stl = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); Texture tex_ml = app.getAssetManager().loadTexture("Textures/test.png"); mat_stl.setTexture("ColorMap", tex_ml); cube.setMaterial(mat_stl); app.getRootNode().attachChild(cube); }
private void initBox() { Box b = new Box(1, 1, 1); Geometry blue = new Geometry("Box", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Blue); blue.setMaterial(mat); /** Attach the two boxes to the *pivot* node. (And transitively to the root node.) */ rootNode.attachChild(blue); }
@Override public void simpleInitApp() { Sphere sphereMesh = new Sphere(32, 32, 1f); Geometry spherePlainGeo = new Geometry("rough sphere", sphereMesh); Material spherePlainMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); spherePlainMat.setFloat("Shininess", 0f); // [1,128] spherePlainMat.setBoolean("UseMaterialColors", true); spherePlainMat.setColor("Ambient", ColorRGBA.Black); spherePlainMat.setColor("Diffuse", ColorRGBA.Cyan); spherePlainMat.setColor("Specular", ColorRGBA.White); spherePlainGeo.setMaterial(spherePlainMat); spherePlainGeo.move(-2.5f, 0, 0); rootNode.attachChild(spherePlainGeo); Geometry sphereShinyGeo = new Geometry("normal sphere", sphereMesh); Material sphereShinyMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); sphereShinyMat.setBoolean("UseMaterialColors", true); sphereShinyMat.setColor("Ambient", ColorRGBA.Black); sphereShinyMat.setColor("Diffuse", ColorRGBA.Cyan); sphereShinyMat.setColor("Specular", ColorRGBA.White); sphereShinyMat.setFloat("Shininess", 4f); // [1,128] sphereShinyGeo.setMaterial(sphereShinyMat); rootNode.attachChild(sphereShinyGeo); Geometry sphereVeryShinyGeo = new Geometry("Smooth sphere", sphereMesh); Material sphereVeryShinyMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); sphereVeryShinyMat.setBoolean("UseMaterialColors", true); sphereVeryShinyMat.setColor("Ambient", ColorRGBA.Black); sphereVeryShinyMat.setColor("Diffuse", ColorRGBA.Cyan); sphereVeryShinyMat.setColor("Specular", ColorRGBA.White); sphereVeryShinyMat.setFloat("Shininess", 100f); // [1,128] sphereVeryShinyGeo.setMaterial(sphereVeryShinyMat); sphereVeryShinyGeo.move(2.5f, 0, 0); rootNode.attachChild(sphereVeryShinyGeo); /** Must add a light to make the lit object visible! */ DirectionalLight sun = new DirectionalLight(); sun.setDirection(new Vector3f(1, 0, -2)); sun.setColor(ColorRGBA.White); rootNode.addLight(sun); }
public void addBrick(Vector3f ori) { Geometry reBoxg = new Geometry("brick", brick); reBoxg.setMaterial(mat); reBoxg.setLocalTranslation(ori); reBoxg.rotate(0f, (float) Math.toRadians(angle), 0f); reBoxg.addControl(new RigidBodyControl(1.5f)); reBoxg.setShadowMode(ShadowMode.CastAndReceive); reBoxg.getControl(RigidBodyControl.class).setFriction(1.6f); this.rootNode.attachChild(reBoxg); this.getPhysicsSpace().add(reBoxg); }
/** Make a solid floor and add it to the scene. */ public void initFloor() { Geometry floor_geo = new Geometry("Floor", floor); floor_geo.setMaterial(floor_mat); floor_geo.setShadowMode(ShadowMode.Receive); floor_geo.setLocalTranslation(0, -0.1f, 0); this.rootNode.attachChild(floor_geo); /* Make the floor physical with mass 0.0f! */ floor_phy = new RigidBodyControl(0.0f); floor_geo.addControl(floor_phy); bulletAppState.getPhysicsSpace().add(floor_phy); }
private void createMarker() { // collision marker Sphere sphere = new Sphere(8, 8, 0.5f); marker = new Geometry("Marker"); marker.setMesh(sphere); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", new ColorRGBA(251f / 255f, 130f / 255f, 0f, 0.6f)); mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); marker.setMaterial(mat); rootNode.attachChild(marker); // surface normal marker Arrow arrow = new Arrow(new Vector3f(0, 1, 0)); markerNormal = new Geometry("MarkerNormal"); markerNormal.setMesh(arrow); markerNormal.setMaterial(mat); rootNode.attachChild(markerNormal); }
private void doShowMaterial(Material m) { // geom.setLocalTranslation(-2.5f, -2.5f, 0); // geom.lookAt(new Vector3f(5, 5, 5), Vector3f.UNIT_Y); currentGeom.setMaterial(m); if (currentGeom.getMaterial() != null) { PreviewRequest request = new PreviewRequest(this, currentGeom); request.getCameraRequest().setLocation(new Vector3f(0, 0, 7)); request.getCameraRequest().setLookAt(new Vector3f(0, 0, 0), Vector3f.UNIT_Y); SceneApplication.getApplication().createPreview(request); } }
public void initFloor() { Box floorBox = new Box(Vector3f.ZERO, 10f, 0.1f, 5f); floorBox.scaleTextureCoordinates(new Vector2f(3, 6)); Geometry floor = new Geometry("floor", floorBox); floor.setMaterial(mat3); floor.setShadowMode(ShadowMode.Receive); floor.setLocalTranslation(0, 0, 0); floor.addControl(new RigidBodyControl(0)); this.rootNode.attachChild(floor); this.getPhysicsSpace().add(floor); }
@Override public void simpleInitApp() { // put the camera in a bad position cam.setLocation(new Vector3f(0.7804813f, 1.7502685f, -2.1556435f)); cam.setRotation(new Quaternion(0.1961598f, -0.7213164f, 0.2266092f, 0.6243975f)); cam.setFrustumFar(10); Material mat = assetManager.loadMaterial("Common/Materials/WhiteColor.j3m"); rootNode.setShadowMode(ShadowMode.Off); Box floor = new Box(Vector3f.ZERO, 3, 0.1f, 3); Geometry floorGeom = new Geometry("Floor", floor); floorGeom.setMaterial(mat); floorGeom.setLocalTranslation(0, -0.2f, 0); floorGeom.setShadowMode(ShadowMode.Receive); rootNode.attachChild(floorGeom); teapot = assetManager.loadModel("Models/Teapot/Teapot.obj"); teapot.setLocalScale(2f); teapot.setMaterial(mat); teapot.setShadowMode(ShadowMode.CastAndReceive); rootNode.attachChild(teapot); // lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f)); // lightMdl.setMaterial(mat); // // disable shadowing for light representation // lightMdl.setShadowMode(ShadowMode.Off); // rootNode.attachChild(lightMdl); bsr = new BasicShadowRenderer(assetManager, 512); bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal()); viewPort.addProcessor(bsr); frustum = new WireFrustum(bsr.getPoints()); frustumMdl = new Geometry("f", frustum); frustumMdl.setCullHint(Spatial.CullHint.Never); frustumMdl.setShadowMode(ShadowMode.Off); frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md")); frustumMdl.getMaterial().getAdditionalRenderState().setWireframe(true); frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red); rootNode.attachChild(frustumMdl); }
@Override public void simpleInitApp() { // sun DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal()); dl.setColor(ColorRGBA.Orange); rootNode.addLight(dl); // ambient light AmbientLight al = new AmbientLight(); al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f)); rootNode.addLight(al); // floor Material textureMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); textureMat.setTexture("ColorMap", assetManager.loadTexture("myAssets/Textures/woodFloor.jpg")); Box floor = new Box(Vector3f.ZERO, 20.0f, 0.01f, 20.0f); Geometry floorGeom = new Geometry("Floor", floor); floorGeom.setMaterial(textureMat); rootNode.attachChild(floorGeom); // object Spatial tree = assetManager.loadModel("Models/Tree/Tree.mesh.j3o"); tree.setQueueBucket(Bucket.Transparent); rootNode.attachChild(tree); // projector PApplet applet = new ColorBarsPApplet(); PAppletProjectorNode projectorNode = new PAppletProjectorNode("projector0", assetManager, applet, 200, 200, true); rootNode.attachChild(projectorNode); rootNode.attachChild( projectorNode .getFrustmMdel()); // if you don't want to see frustum, please don't attach it to // rootNode. // projector should be added to TextureProjectorRenderer, and TextureProjectorRenderer should be // added to ViewPort. TextureProjectorRenderer ptr = new TextureProjectorRenderer(assetManager); ptr.getTextureProjectors().add(projectorNode.getProjector()); viewPort.addProcessor(ptr); // projector is a kind of Shadow, and following processes are necessary for Shadow Rendering. floorGeom.setShadowMode(ShadowMode.Receive); tree.setShadowMode(ShadowMode.CastAndReceive); // tree makes and receives shadow projectorNode.setLocalTranslation(new Vector3f(0, 10, 0)); // move the projector, projectorNode.lookAt( new Vector3f(0, 0, 0), Vector3f.UNIT_X); // and make it to look at where you want. // cam cam.setLocation(Vector3f.UNIT_XYZ.mult(10.0f)); // camera moves to 10, 10, 10 cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y); // and looks at 0,0,0. }
public void simpleInitApp() { renderManager.setAlphaToCoverage(true); cam.setLocation(new Vector3f(0.14914267f, 0.58147097f, 4.7686534f)); cam.setRotation(new Quaternion(-0.0044764364f, 0.9767943f, 0.21314798f, 0.020512417f)); // cam.setLocation(new Vector3f(2.0606942f, 3.20342f, 6.7860126f)); // cam.setRotation(new Quaternion(-0.017481906f, 0.98241085f, -0.12393151f, // -0.13857932f)); viewPort.setBackgroundColor(ColorRGBA.DarkGray); Quad q = new Quad(20, 20); q.scaleTextureCoordinates(Vector2f.UNIT_XY.mult(5)); Geometry geom = new Geometry("floor", q); Material mat = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m"); geom.setMaterial(mat); geom.rotate(-FastMath.HALF_PI, 0, 0); geom.center(); geom.setShadowMode(ShadowMode.Receive); rootNode.attachChild(geom); // create the geometry and attach it Spatial teaGeom = assetManager.loadModel("Models/Tree/Tree.mesh.j3o"); teaGeom.setQueueBucket(Bucket.Transparent); teaGeom.setShadowMode(ShadowMode.Cast); makeToonish(teaGeom); AmbientLight al = new AmbientLight(); al.setColor(ColorRGBA.White.mult(2)); rootNode.addLight(al); DirectionalLight dl1 = new DirectionalLight(); dl1.setDirection(new Vector3f(1, -1, 1).normalizeLocal()); dl1.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f)); rootNode.addLight(dl1); DirectionalLight dl = new DirectionalLight(); dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal()); dl.setColor(new ColorRGBA(0.965f, 0.949f, 0.772f, 1f).mult(0.7f)); rootNode.addLight(dl); rootNode.attachChild(teaGeom); FilterPostProcessor fpp = new FilterPostProcessor(assetManager); CartoonEdgeFilter toon = new CartoonEdgeFilter(); toon.setEdgeWidth(0.5f); toon.setEdgeIntensity(1.0f); toon.setNormalThreshold(0.8f); fpp.addFilter(toon); viewPort.addProcessor(fpp); }
/** * Initialize the axes displayed in the scene. This method should be overridden if custom axes are * desired. You can toggle the axes by using {@link #setDisplayAxes(boolean)}. * * <p>If this method is overridden, you should also override {@link #clearAxes()} to dispose of * them properly when the <code>ViewAppState</code> is cleaned. */ protected void initAxes() { // If necessary, add spatials to the axes. Geometry geometry; Line line; float lineWidth = 3f; // Create the materials for the axis. In a sub-class, this would be done // in initMaterials(). However, adding the materials here is easier for // sub-classes because there would be a dependency between initAxes() // and initMaterials(). setMaterial("XAxis", createBasicMaterial(ColorRGBA.Red)); setMaterial("YAxis", createBasicMaterial(ColorRGBA.Green)); setMaterial("ZAxis", createBasicMaterial(ColorRGBA.Blue)); // Create the x axis as a red line of unit length. line = new Line(Vector3f.ZERO, Vector3f.UNIT_X); line.setLineWidth(lineWidth); geometry = new Geometry("x", line); geometry.setMaterial(getMaterial("XAxis")); axes.attachChild(geometry); // Create the y axis as a green line of unit length. line = new Line(Vector3f.ZERO, Vector3f.UNIT_Y); line.setLineWidth(lineWidth); geometry = new Geometry("y", line); geometry.setMaterial(getMaterial("YAxis")); axes.attachChild(geometry); // Create the z axis as a blue line of unit length. line = new Line(Vector3f.ZERO, Vector3f.UNIT_Z); line.setLineWidth(lineWidth); geometry = new Geometry("z", line); geometry.setMaterial(getMaterial("ZAxis")); axes.attachChild(geometry); return; }