public static void setTranslucent(Spatial spatial) { MaterialState rs = (MaterialState) doRemoveRenderState(spatial, StateType.Material); if (rs != null) { materials.put(spatial.getName(), rs); MaterialState newState = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState(); ColorRGBA ambient = rs.getAmbient(); ambient.a = .5f; ColorRGBA diffuse = rs.getDiffuse(); diffuse.a = .5f; ColorRGBA emissive = rs.getEmissive(); emissive.a = .5f; ColorRGBA specular = rs.getSpecular(); specular.a = .5f; newState.setAmbient(ambient); newState.setColorMaterial(rs.getColorMaterial()); newState.setDiffuse(diffuse); newState.setEmissive(emissive); newState.setMaterialFace(rs.getMaterialFace()); newState.setShininess(rs.getShininess()); newState.setSpecular(specular); } spatial.updateRenderState(); if (spatial instanceof Node && ((Node) spatial).getChildren() != null) { for (int i = 0; i < ((Node) spatial).getChildren().size(); i++) { colorStripper(((Node) spatial).getChildren().get(i)); } } }
/** * Applies color to a Spatial in the form of a <code>MaterialState</code>. * * @param spatial * @param diffuseColor * @param ambientColor * @see MaterialState */ public static MaterialState applyColor( Spatial spatial, ColorRGBA diffuseColor, ColorRGBA ambientColor) { colorStripper(spatial); MaterialState targetMaterial = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState(); targetMaterial.setDiffuse(diffuseColor); targetMaterial.setAmbient(ambientColor); spatial.setRenderState(targetMaterial); spatial.updateRenderState(); if (workingState != null) { MaterialState ms = (MaterialState) workingState; workingState = null; return ms; } else return null; }