/** * 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; }
/* * (non-Javadoc) * * @see org.rifidi.designer.entities.Entity#loaded() */ @Override public void loaded() { if (msStopped == null) { msStopped = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState(); msStopped.setDiffuse(new ColorRGBA(1, 0, 0, .5f)); msStopped.setEmissive(new ColorRGBA(1, 0, 0, .3f)); msStopped.setShininess(1); msStopped.setSpecular(new ColorRGBA(1, 0, 0, .3f)); } if (as == null) { as = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState(); as.setBlendEnabled(true); as.setSrcFunction(AlphaState.SB_SRC_ALPHA); as.setDstFunction(AlphaState.DB_ONE); as.setEnabled(true); } getNode().clearRenderState(RenderState.RS_ALPHA); getNode().clearRenderState(RenderState.RS_MATERIAL); getNode().setRenderState(as); getNode().updateRenderState(); ((PhysicsNode) getNode()).setMaterial(Material.GHOST); if (msStarted == null) { msStarted = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState(); msStarted.setDiffuse(new ColorRGBA(0, 1, 0, .5f)); msStarted.setEmissive(new ColorRGBA(0, 1, 0, .3f)); msStarted.setShininess(1); msStarted.setSpecular(new ColorRGBA(0, 1, 0, .3f)); } if (running) { turnOn(); } else { turnOff(); } fieldService.registerField(this); }
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)); } } }