/** * Returns the material that is used for the first batch of this BatchNode * <p> * use getMaterial(Material material,int batchIndex) to get a material from a specific batch * * @return the material that is used for the first batch of this BatchNode * @see #setMaterial(com.jme3.material.Material) */ public Material getMaterial() { if (!batches.isEmpty()) { Batch b = batches.iterator().next(); return b.geometry.getMaterial(); } return null; }
public void reload() { Material reloadedMat = reloadMaterial(geom.getMaterial()); //if the reload is successful, we re setup the material with its params and reassign it to the box if (reloadedMat != null) { // setupMaterial(reloadedMat); geom.setMaterial(reloadedMat); } }
private Batch findBatchByMaterial(Material m) { for (Batch batch : batches.getArray()) { if (batch.geometry.getMaterial().contentEquals(m)) { return batch; } } return null; }
@Override protected void controlUpdate(float tpf) { Material mat = sphere.getMaterial(); mat.getAdditionalRenderState().setStencil(enableStencil, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.TestFunction.Never, RenderState.TestFunction.Never //TestFunction.Always, TestFunction.Always ); }
private void buildMatCache(GeometryList l) { matCache.clear(); for (int i = 0; i < l.size(); i++) { Material mat = l.get(i).getMaterial(); //checking if the material has the post technique and adding it to the material cache if (mat.getMaterialDef().getTechniqueDefs(postTechniqueName) != null) { if (!matCache.contains(mat)) { matCache.add(mat); } } else { needsfallBackMaterial = true; } } }
private void buildMatCache(GeometryList l) { matCache.clear(); for (int i = 0; i < l.size(); i++) { Material mat = l.get(i).getMaterial(); //checking if the material has the post technique and adding it to the material cache if (mat.getMaterialDef().getTechniqueDefs(postTechniqueName) != null) { if (!matCache.contains(mat)) { matCache.add(mat); } } else { needsfallBackMaterial = true; } } }
protected void reloadScene(Geometry g, Geometry boxGeo, Node cubeNodes) { MaterialDebugAppState debug = stateManager.getState(MaterialDebugAppState.class); Material m = debug.reloadMaterial(g.getMaterial()); if (m != null) { g.setMaterial(m); } m = debug.reloadMaterial(boxGeo.getMaterial()); if (m != null) { cubeNodes.setMaterial(m); } }
private void addToInstancedGeometry(Geometry geom) { Material material = geom.getMaterial(); MatParam param = material.getParam("UseInstancing"); if (param == null || !((Boolean)param.getValue()).booleanValue()) { throw new IllegalStateException("You must set the 'UseInstancing' " + "parameter to true on the material prior " + "to adding it to InstancedNode"); } InstancedGeometry ig = lookUpByGeometry(geom); igByGeom.put(geom, ig); geom.associateWithGroupNode(this, 0); ig.addInstance(geom); }
@Override public void simpleUpdate(float tpf) { CollisionResults results = new CollisionResults(); BoundingVolume bv = geom1.getWorldBound(); golem.collideWith(bv, results); if (results.size() > 0) { geom1.getMaterial().setColor("Color", ColorRGBA.Red); }else{ geom1.getMaterial().setColor("Color", ColorRGBA.Blue); } } }
@Override public void simpleUpdate(float tpf) { area.setCenter(ln.getLocalTranslation()); area.setRotation(ln.getLocalRotation()); TempVars vars = TempVars.get(); boolean intersectBox = area.intersectsBox(aabb, vars); boolean intersectFrustum = area.intersectsFrustum(frustumCam, vars); boolean intersectSphere = area.intersectsSphere(sphere, vars); vars.release(); boolean intersect = intersectBox || intersectFrustum || intersectSphere; areaGeom.getMaterial().setColor("Color", intersect ? ColorRGBA.Green : ColorRGBA.White); sphereGeom.getMaterial().setColor("Color", intersectSphere ? ColorRGBA.Cyan : ColorRGBA.White); frustumGeom.getMaterial().setColor("Color", intersectFrustum ? ColorRGBA.Cyan : ColorRGBA.White); aabbGeom.getMaterial().setColor("Color", intersectBox ? ColorRGBA.Cyan : ColorRGBA.White); } }
private static Texture getMaterialTexture(Geometry geometry, String mapName) { Material mat = geometry.getMaterial(); if (mat == null || mat.getParam(mapName) == null || !(mat.getParam(mapName) instanceof MatParamTexture)) { return null; } MatParamTexture param = (MatParamTexture) mat.getParam(mapName); Texture texture = param.getTextureValue(); if (texture == null) { return null; } return texture; }
private void evaluateTechniqueDef() { Assert.assertFalse(evaluated); Material mat = geometry.getMaterial(); mat.render(geometry, lightList, renderManager); Assert.assertTrue(evaluated); }
private void inputMp(MatParam... params) { if (evaluated) { throw new IllegalStateException(); } Material mat = geometry.getMaterial(); for (MatParam param : params) { mat.setParam(param.getName(), param.getVarType(), param.getValue()); } }
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); } } } }
private void outDefines(Define... expectedDefinesArray) { StringBuilder expectedDefineSource = new StringBuilder(); for (Define define : expectedDefinesArray) { expectedDefineSource.append(define.toString()); } if (!evaluated) { evaluateTechniqueDef(); } Material mat = geometry.getMaterial(); Technique tech = mat.getActiveTechnique(); TechniqueDef def = tech.getDef(); DefineList actualDefines = tech.getDynamicDefines(); String[] defineNames = def.getDefineNames(); VarType[] defineTypes = def.getDefineTypes(); String actualDefineSource = actualDefines.generateSource(Arrays.asList(defineNames), Arrays.asList(defineTypes)); assertEquals(expectedDefineSource.toString(), actualDefineSource); }
public void makeSphereWire(BoundingSphere sphere) { sphereGeom = new Geometry("box", new Sphere(16, 16, 10)); sphereGeom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md")); sphereGeom.getMaterial().getAdditionalRenderState().setWireframe(true); sphereGeom.setLocalTranslation(sphere.getCenter()); rootNode.attachChild(sphereGeom); }
@Override public void visit(Geometry geom) { MatParam p = geom.getMaterial().getMaterialDef().getMaterialParam("MorphWeights"); if (p == null) { return; } Mesh mesh = geom.getMesh(); if (mesh != null && mesh.hasMorphTargets()) { targets.add(geom); // If the mesh is in a subgraph of a node with a SkinningControl it might have hardware skinning activated through mat param override even if it's not skinned. // this code makes sure that if the mesh has no hardware skinning buffers hardware skinning won't be activated. // this is important, because if HW skinning is activated the shader will declare 2 additional useless attributes, // and we desperately need all the attributes we can find for Morph animation. if (mesh.getBuffer(VertexBuffer.Type.HWBoneIndex) == null && !geom.getLocalMatParamOverrides().contains(nullNumberOfBones)) { geom.addMatParamOverride(nullNumberOfBones); } } } }
@Override public void visit(Geometry g){ Mesh m = g.getMesh(); Material mat = g.getMaterial(); // if (mat.getParam("DiffuseMap") != null){ // mat.setTexture("DiffuseMap", null); // } TangentBinormalGenerator.generate(m); Geometry debug = new Geometry( "debug tangents geom", TangentBinormalGenerator.genTbnLines(g.getMesh(), 0.2f) ); debug.setMaterial(debugMat); debug.setCullHint(Spatial.CullHint.Never); debug.setLocalTransform(g.getWorldTransform()); debugTangents.attachChild(debug); } });
public void makeAreaGeom() { Vector3f[] points = new Vector3f[8]; for (int i = 0; i < points.length; i++) { points[i] = new Vector3f(); } points[0].set(-1, -1, 1); points[1].set(-1, 1, 1); points[2].set(1, 1, 1); points[3].set(1, -1, 1); points[4].set(-1, -1, -1); points[5].set(-1, 1, -1); points[6].set(1, 1, -1); points[7].set(1, -1, -1); Mesh box = WireFrustum.makeFrustum(points); areaGeom = new Geometry("light", (Mesh)box); areaGeom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md")); areaGeom.getMaterial().setColor("Color", ColorRGBA.White); }
public void makeBoxWire(BoundingBox box) { Vector3f[] points = new Vector3f[8]; for (int i = 0; i < 8; i++) { points[i] = new Vector3f(); } points[0].set(-1, -1, 1); points[1].set(-1, 1, 1); points[2].set(1, 1, 1); points[3].set(1, -1, 1); points[4].set(-1, -1, -1); points[5].set(-1, 1, -1); points[6].set(1, 1, -1); points[7].set(1, -1, -1); WireFrustum frustumShape = new WireFrustum(points); aabbGeom = new Geometry("box", frustumShape); aabbGeom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md")); aabbGeom.getMaterial().getAdditionalRenderState().setWireframe(true); aabbGeom.setLocalTranslation(box.getCenter()); aabbGeom.setLocalScale(box.getXExtent(), box.getYExtent(), box.getZExtent()); rootNode.attachChild(aabbGeom); }