Java Code Examples for com.jme3.scene.Geometry#setMesh()

The following examples show how to use com.jme3.scene.Geometry#setMesh() . 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: MapView.java    From OpenRTS with MIT License 6 votes vote down vote up
private void createSky() {
	vp.setBackgroundColor(new ColorRGBA(135f / 255f, 206f / 255f, 250f / 255f, 1));
	Geometry xAxe = new Geometry();
	xAxe.setMesh(new Box(5, 0.1f, 0.1f));
	xAxe.setMaterial(MaterialManager.getColor(ColorRGBA.Brown));
	xAxe.setLocalTranslation(5, 0, 0);
	getRootNode().attachChild(xAxe);

	Geometry zAxe = new Geometry();
	zAxe.setMesh(new Box(0.1f, 0.1f, 5));
	zAxe.setMaterial(MaterialManager.greenMaterial);
	zAxe.setLocalTranslation(0, 0, 5);
	rootNode.attachChild(zAxe);

	Geometry yAxe = new Geometry();
	yAxe.setMesh(new Box(0.1f, 5, 0.1f));
	yAxe.setMaterial(MaterialManager.redMaterial);
	yAxe.setLocalTranslation(0, 5, 0);
	rootNode.attachChild(yAxe);
}
 
Example 2
Source File: TerrainTestModifyHeight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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);
}
 
Example 3
Source File: DebugShapeFactory.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
private static Geometry createDebugShape(CollisionShape shape) {
    Geometry geom = new Geometry();
    geom.setMesh(DebugShapeFactory.getDebugMesh(shape));
    //        geom.setLocalScale(shape.getScale());
    geom.updateModelBound();
    return geom;
}
 
Example 4
Source File: DebugShapeFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static Geometry createDebugShape(CollisionShape shape) {
        Geometry geom = new Geometry();
        geom.setMesh(DebugShapeFactory.getDebugMesh(shape));
//        geom.setLocalScale(shape.getScale());
        geom.updateModelBound();
        return geom;
    }
 
Example 5
Source File: EditorRenderer.java    From OpenRTS with MIT License 5 votes vote down vote up
private void BuildAtlasPencil() {
	for (int i = 0; i < Pencil.MAX_SIZE * 8; i++) {
		Geometry g = new Geometry();
		g.setMesh(new Line(new Vector3f(-1000, -1000, 0), new Vector3f(-1000, -1000, 1)));
		g.setMaterial(MaterialManager.getColor(ColorRGBA.Orange));
		AtlasPencilNode.attachChild(g);
	}
}
 
Example 6
Source File: EditorRenderer.java    From OpenRTS with MIT License 5 votes vote down vote up
public EditorRenderer(EditorView view) {
	this.view = view;
	EventManager.register(this);

	if(ModelManager.getBattlefield() != null)
		for (Parcel parcel : ModelManager.getBattlefield().getMap().getParcelling().getAll()) {
			GridMesh grid = new GridMesh(parcel);
			gridMeshes.put(parcel, grid);

			Geometry g = new Geometry();
			g.setMesh(TranslateUtil.toJMEMesh(grid));
			Material mat = MaterialManager.getColor(ColorRGBA.Black);
			mat.getAdditionalRenderState().setWireframe(true);
			g.setMaterial(mat);
			gridNode.attachChild(g);
			gridGeoms.put(parcel, g);
		}

	mainNode.attachChild(gridNode);

	mainNode.attachChild(CliffPencilNode);
	mainNode.attachChild(HeightPencilNode);
	mainNode.attachChild(AtlasPencilNode);

	BuildCliffPencil();
	BuildHeightPencil();
	BuildAtlasPencil();

	EventManager.register(this);
}
 
Example 7
Source File: TerrainQuad.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * used by attachBoundChildren()
 */
private void attachBoundingBox(BoundingBox bb, Node parent) {
    WireBox wb = new WireBox(bb.getXExtent(), bb.getYExtent(), bb.getZExtent());
    Geometry g = new Geometry();
    g.setMesh(wb);
    g.setLocalTranslation(bb.getCenter());
    parent.attachChild(g);
}
 
Example 8
Source File: MapDrawer.java    From OpenRTS with MIT License 5 votes vote down vote up
private void attachBuggedCliff(Cliff c) {
	Geometry g = new Geometry();
	g.setMesh(new Box(0.5f, 0.5f, 1));
	g.setMaterial(MaterialManager.redMaterial);
	g.setLocalTranslation((float)c.getTile().getCoord().x + 0.5f, (float)c.getTile().getCoord().y + 0.5f, (float) (c.level * Tile.STAGE_HEIGHT) + 1);

	Node n = new Node();
	n.attachChild(g);
	tilesSpatial.get(c.getTile()).add(n);
	castAndReceiveNode.attachChild(n);
}
 
Example 9
Source File: TextureAtlas.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates one geometry out of the given root spatial and merges all single
 * textures into one texture of the given size.
 * @param spat The root spatial of the scene to batch
 * @param mgr An assetmanager that can be used to create the material.
 * @param atlasSize A size for the atlas texture, it has to be large enough to hold all single textures.
 * @return A new geometry that uses the generated texture atlas and merges all meshes of the root spatial, null if the atlas cannot be created because not all textures fit.
 */
public static Geometry makeAtlasBatch(Spatial spat, AssetManager mgr, int atlasSize) {
    List<Geometry> geometries = new ArrayList<Geometry>();
    GeometryBatchFactory.gatherGeoms(spat, geometries);
    TextureAtlas atlas = createAtlas(spat, atlasSize);
    if (atlas == null) {
        return null;
    }
    Geometry geom = new Geometry();
    Mesh mesh = new Mesh();
    GeometryBatchFactory.mergeGeometries(geometries, mesh);
    applyAtlasCoords(geometries, mesh, atlas);
    mesh.updateCounts();
    mesh.updateBound();
    geom.setMesh(mesh);

    Material mat = new Material(mgr, "Common/MatDefs/Light/Lighting.j3md");
    Texture diffuseMap = atlas.getAtlasTexture("DiffuseMap");
    Texture normalMap = atlas.getAtlasTexture("NormalMap");
    Texture specularMap = atlas.getAtlasTexture("SpecularMap");
    if (diffuseMap != null) {
        mat.setTexture("DiffuseMap", diffuseMap);
    }
    if (normalMap != null) {
        mat.setTexture("NormalMap", normalMap);
    }
    if (specularMap != null) {
        mat.setTexture("SpecularMap", specularMap);
    }
    mat.setFloat("Shininess", 16.0f);

    geom.setMaterial(mat);
    return geom;
}
 
Example 10
Source File: DebugShapeFactory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Geometry createDebugShape(CollisionShape shape) {
        Geometry geom = new Geometry();
        geom.setMesh(DebugShapeFactory.getDebugMesh(shape));
//        geom.setLocalScale(shape.getScale());
        geom.updateModelBound();
        return geom;
    }
 
Example 11
Source File: DebugShapeFactory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
     * Create a geometry for visualizing the specified shape.
     *
     * @param shape (not null, unaffected)
     * @return a new geometry (not null)
     */
    private static Geometry createDebugShape(CollisionShape shape) {
        Geometry geom = new Geometry();
        geom.setMesh(DebugShapeFactory.getDebugMesh(shape));
//        geom.setLocalScale(shape.getScale());
        geom.updateModelBound();
        return geom;
    }
 
Example 12
Source File: DebugShapeFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static Geometry createDebugShape(CollisionShape shape) {
        Geometry geom = new Geometry();
        geom.setMesh(DebugShapeFactory.getDebugMesh(shape));
//        geom.setLocalScale(shape.getScale());
        geom.updateModelBound();
        return geom;
    }
 
Example 13
Source File: TerrainTestCollision.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createCollisionMarkers(int num) {
    for (int i = 0; i < num; i++) {
        Sphere s = new Sphere(6, 6, 1);
        Geometry collisionMarker = new Geometry("collisionMarker");
        collisionMarker.setMesh(s);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", i == 0 ? ColorRGBA.Orange : ColorRGBA.Blue);
        collisionMarker.setMaterial(mat);
        rootNode.attachChild(collisionMarker);
        collisionMarkers.add(collisionMarker);
    }
}
 
Example 14
Source File: TerrainQuad.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * used by attachBoundChildren()
 */
private void attachBoundingBox(BoundingBox bb, Node parent) {
    WireBox wb = new WireBox(bb.getXExtent(), bb.getYExtent(), bb.getZExtent());
    Geometry g = new Geometry();
    g.setMesh(wb);
    g.setLocalTranslation(bb.getCenter());
    parent.attachChild(g);
}
 
Example 15
Source File: TerrainTestCollision.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void createCollisionMarker() {
    Sphere s = new Sphere(6, 6, 1);
    collisionMarker = new Geometry("collisionMarker");
    collisionMarker.setMesh(s);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Orange);
    collisionMarker.setMaterial(mat);
    rootNode.attachChild(collisionMarker);
}
 
Example 16
Source File: GeometryTreeNode.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
public void add(@NotNull final TreeNode<?> child) {
    super.add(child);

    final Geometry geometry = getElement();

    if (child instanceof MeshTreeNode) {
        final Mesh element = (Mesh) child.getElement();
        geometry.setMesh(element);
    }
}
 
Example 17
Source File: TestInstanceNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {
    time += tpf;

    if (time > 1f) {
        time = 0f;
        
        for (Spatial instance : instancedNode.getChildren()) {
            if (!(instance instanceof InstancedGeometry)) {
                Geometry geom = (Geometry) instance;
                geom.setMaterial(materials[FastMath.nextRandomInt(0, materials.length - 1)]);

                Mesh mesh; 
                if (FastMath.nextRandomInt(0, 1) == 1) mesh = mesh2;
                else mesh = mesh1;
                geom.setMesh(mesh);
            }
        }
    }
    
    for (Spatial child : instancedNode.getChildren()) {
        if (!(child instanceof InstancedGeometry)) {
            float val = ((Float)child.getUserData("height")).floatValue();
            float dir = ((Float)child.getUserData("dir")).floatValue();

            val += (dir + ((FastMath.nextRandomFloat() * 0.5f) - 0.25f)) * tpf;

            if (val > 1f) {
                val = 1f;
                dir = -dir;
            } else if (val < 0f) {
                val = 0f;
                dir = -dir;
            }

            Vector3f translation = child.getLocalTranslation();
            translation.y = (smoothstep(0, 1, val) * 2.5f) - 1.25f;

            child.setUserData("height", val);
            child.setUserData("dir", dir);

            child.setLocalTranslation(translation);
        }
    }
}
 
Example 18
Source File: TerrainTestTile.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    loadHintText();
    setupKeys();

    // WIREFRAME material
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    
    terrain = new TiledTerrain();
    rootNode.attachChild(terrain);
    
    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
    rootNode.addLight(light);

    AmbientLight ambLight = new AmbientLight();
    ambLight.setColor(new ColorRGBA(1f, 1f, 0.8f, 0.2f));
    rootNode.addLight(ambLight);

    cam.setLocation(new Vector3f(0, 256, 0));
    cam.lookAtDirection(new Vector3f(0, -1, -1).normalizeLocal(), Vector3f.UNIT_Y);
    
    
    Sphere s = new Sphere(12, 12, 3);
    Geometry g = new Geometry("marker");
    g.setMesh(s);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Red);
    g.setMaterial(mat);
    g.setLocalTranslation(0, -100, 0);
    rootNode.attachChild(g);
    
    Geometry g2 = new Geometry("marker");
    g2.setMesh(s);
    mat.setColor("Color", ColorRGBA.Red);
    g2.setMaterial(mat);
    g2.setLocalTranslation(10, -100, 0);
    rootNode.attachChild(g2);
    
    Geometry g3 = new Geometry("marker");
    g3.setMesh(s);
    mat.setColor("Color", ColorRGBA.Red);
    g3.setMaterial(mat);
    g3.setLocalTranslation(0, -100, 10);
    rootNode.attachChild(g3);
}
 
Example 19
Source File: TerrainTestTile.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    loadHintText();
    setupKeys();

    // WIREFRAME material
    matWire = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWire.getAdditionalRenderState().setWireframe(true);
    matWire.setColor("Color", ColorRGBA.Green);
    
    terrain = new TiledTerrain();
    rootNode.attachChild(terrain);
    
    DirectionalLight light = new DirectionalLight();
    light.setDirection((new Vector3f(-0.5f, -1f, -0.5f)).normalize());
    rootNode.addLight(light);

    AmbientLight ambLight = new AmbientLight();
    ambLight.setColor(new ColorRGBA(1f, 1f, 0.8f, 0.2f));
    rootNode.addLight(ambLight);

    cam.setLocation(new Vector3f(0, 256, 0));
    cam.lookAtDirection(new Vector3f(0, -1, -1).normalizeLocal(), Vector3f.UNIT_Y);
    
    
    Sphere s = new Sphere(12, 12, 3);
    Geometry g = new Geometry("marker");
    g.setMesh(s);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Red);
    g.setMaterial(mat);
    g.setLocalTranslation(0, -100, 0);
    rootNode.attachChild(g);
    
    Geometry g2 = new Geometry("marker");
    g2.setMesh(s);
    mat.setColor("Color", ColorRGBA.Red);
    g2.setMaterial(mat);
    g2.setLocalTranslation(10, -100, 0);
    rootNode.attachChild(g2);
    
    Geometry g3 = new Geometry("marker");
    g3.setMesh(s);
    mat.setColor("Color", ColorRGBA.Red);
    g3.setMaterial(mat);
    g3.setLocalTranslation(0, -100, 10);
    rootNode.attachChild(g3);
}
 
Example 20
Source File: CollisionTester.java    From OpenRTS with MIT License 4 votes vote down vote up
public static boolean areColliding(Asset asset1, Asset asset2, boolean debug){
		Spatial s1 = getSpatialFromAsset(asset1); 
		Spatial s2 = getSpatialFromAsset(asset2);

		PhysicsSpace space = new PhysicsSpace();
		
		RigidBodyControl ghost1 = new RigidBodyControl(getCollisionShape(asset1));
		s1.addControl(ghost1);
		space.add(ghost1);

		RigidBodyControl ghost2 = new RigidBodyControl(getCollisionShape(asset2));
		s2.addControl(ghost2);
//		ghost2.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
//		space.add(ghost2);

		space.update(1);
		
//		int numCollision = ghost1.getOverlappingCount();
//		boolean collision = numCollision > 0;
		Transform t = new Transform();
		t.setRotation(s2.getLocalRotation());
		t.setTranslation(s2.getLocalTranslation());
		boolean collision = false;
		for(ChildCollisionShape hull : getCollisionShape(asset2).getChildren())
			if(!space.sweepTest(hull.shape, Transform.IDENTITY, t).isEmpty()){
				collision = true;
				break;
			}
				
		
		space.remove(ghost1);
//		space.remove(ghost2);

//		if(!collision){
//			Spatial debugS2 = DebugShapeFactory.getDebugShape(ghost2.getCollisionShape());
//			debugS2.setLocalRotation(ghost2.getPhysicsRotation());
////			Spatial debugS2 = s2;
//			Material m = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
//			m.getAdditionalRenderState().setWireframe(true);
//			m.setColor("Color", ColorRGBA.Red);
//			debugS2.setMaterial(m);
//			debugS2.setLocalTranslation(ghost2.getPhysicsLocation());
//			asset2.s = debugS2;
//			//EventManager.post(new GenericEvent(debugS2));
//		}
			
		if(!collision){// && debug){
			Material m = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
			m.getAdditionalRenderState().setWireframe(true);
			m.setColor("Color", ColorRGBA.Red);
			Spatial debugS2 = DebugShapeFactory.getDebugShape(getCollisionShape(asset2));
			debugS2.setLocalTransform(t);
//			debugS2.setLocalRotation(ghost2.getPhysicsRotation());
//			debugS2.setLocalTranslation(ghost2.getPhysicsLocation());
			debugS2.setMaterial(m);

			Material m2 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
			m2.getAdditionalRenderState().setWireframe(true);
			m2.setColor("Color", ColorRGBA.Blue);
			Geometry linegeom = new Geometry();
			Line l = new Line(debugS2.getLocalTranslation().add(0,  0, 1), ghost1.getPhysicsLocation().add(0,  0, 1));
			linegeom.setMesh(l);
			linegeom.setMaterial(m2);
	
			asset2.s = debugS2;
			if(l.getStart().distance(l.getEnd())<2)
				asset2.links.add(linegeom);
//			EventManager.post(new GenericEvent(debugS2));
//			EventManager.post(new GenericEvent(linegeom));
			
			
		}

		return collision; 
	}