📄 materialretained.java
字号:
initSpecularColor(color); sendMessage(SPECULAR_COLOR_CHANGED, new Color3f(color)); } /** * Sets this material's specular color. * This is the specular highlight color of the material. * @param r the new specular color's red component * @param g the new specular color's green component * @param b the new specular color's blue component */ final void initSpecularColor(float r, float g, float b) { this.specularColor.set(r, g, b); } /** * Sets this material's specular color and sends a message notifying * the interested structures of the change. * This is the specular highlight color of the material. * @param r the new specular color's red component * @param g the new specular color's green component * @param b the new specular color's blue component */ final void setSpecularColor(float r, float g, float b) { initSpecularColor(r, g, b); sendMessage(SPECULAR_COLOR_CHANGED, new Color3f(r, g, b)); } /** * Retrieves this material's specular color. * @param color the vector that will receive this material's specular color */ final void getSpecularColor(Color3f color) { color.set(this.specularColor); } /** * Sets this material's shininess. * This specifies a material specular exponent, or shininess. * It takes a floating point number in the range [1.0, 128.0] * with 1.0 being not shiny and 128.0 being very shiny. * @param shininess the material's shininess */ final void initShininess(float shininess) { // Clamp shininess value if (shininess < 1.0f) this.shininess = 1.0f; else if (shininess > 128.0f) this.shininess = 128.0f; else this.shininess = shininess; } /** * Sets this material's shininess and sends a message notifying * the interested structures of the change. * This specifies a material specular exponent, or shininess. * It takes a floating point number in the range [1.0, 128.0] * with 1.0 being not shiny and 128.0 being very shiny. * @param shininess the material's shininess */ final void setShininess(float shininess) { initShininess(shininess); sendMessage(SHININESS_CHANGED, new Float(this.shininess)); } /** * Retrieves this material's shininess. * @return the material's shininess */ final float getShininess() { return this.shininess; } /** * Enables or disables lighting for this appearance component object. * @param state true or false to enable or disable lighting */ void initLightingEnable(boolean state) { lightingEnable = state; } /** * Enables or disables lighting for this appearance component object * and sends a message notifying * the interested structures of the change. * @param state true or false to enable or disable lighting */ void setLightingEnable(boolean state) { initLightingEnable(state); sendMessage(ENABLE_CHANGED, (state ? Boolean.TRUE: Boolean.FALSE)); } /** * Retrieves the state of the lighting enable flag. * @return true if lighting is enabled, false if lighting is disabled */ boolean getLightingEnable() { return lightingEnable; } void initColorTarget(int colorTarget) { this.colorTarget = colorTarget; } final void setColorTarget(int colorTarget) { initColorTarget(colorTarget); sendMessage(COLORTARGET_CHANGED, new Integer(colorTarget)); } final int getColorTarget() { return colorTarget; } synchronized void createMirrorObject() { if (mirror == null) { // Check the capability bits and let the mirror object // point to itself if is not editable if (isStatic()) { mirror = this; } else { MaterialRetained mirrorMat = new MaterialRetained(); mirrorMat.set(this); mirrorMat.source = source; mirror = mirrorMat; } } else { ((MaterialRetained) mirror).set(this); } } /** * Updates the native context. */ void updateNative(Context ctx, float red, float green, float blue, float alpha, boolean enableLighting) { Pipeline.getPipeline().updateMaterial(ctx, red, green, blue, alpha, ambientColor.x, ambientColor.y, ambientColor.z, emissiveColor.x, emissiveColor.y, emissiveColor.z, diffuseColor.x, diffuseColor.y, diffuseColor.z, specularColor.x, specularColor.y, specularColor.z, shininess, colorTarget, enableLighting); } /** * Creates a mirror object, point the mirror object to the retained * object if the object is not editable */ synchronized void initMirrorObject() { MaterialRetained mirrorMaterial = (MaterialRetained)mirror; mirrorMaterial.set(this); } /** * Update the "component" field of the mirror object with the * given "value" */ synchronized void updateMirrorObject(int component, Object value) { MaterialRetained mirrorMaterial = (MaterialRetained)mirror; if ((component & AMBIENT_COLOR_CHANGED) != 0) { mirrorMaterial.ambientColor = (Color3f)value; } else if ((component & EMISSIVE_COLOR_CHANGED) != 0) { mirrorMaterial.emissiveColor = (Color3f)value; } else if ((component & DIFFUSE_COLOR_CHANGED) != 0) { mirrorMaterial.diffuseColor = (Color3f)value; } else if ((component & SPECULAR_COLOR_CHANGED) != 0) { mirrorMaterial.specularColor = (Color3f)value; } else if ((component & SHININESS_CHANGED) != 0) { mirrorMaterial.shininess = ((Float)value).floatValue(); } else if ((component & ENABLE_CHANGED) != 0) { mirrorMaterial.lightingEnable = ((Boolean)value).booleanValue(); } else if ((component & COLORTARGET_CHANGED) != 0) { mirrorMaterial.colorTarget = ((Integer)value).intValue(); } } boolean equivalent(MaterialRetained m) { return ((m != null) && lightingEnable == m.lightingEnable && diffuseColor.equals(m.diffuseColor) && emissiveColor.equals(m.emissiveColor) && specularColor.equals(m.specularColor) && ambientColor.equals(m.ambientColor) && colorTarget == m.colorTarget && shininess == m.shininess); } // This functions clones the retained side only and is used // internally protected Object clone() { MaterialRetained mr = (MaterialRetained)super.clone(); // color can't share the same reference mr.ambientColor = new Color3f(ambientColor); mr.emissiveColor = new Color3f(emissiveColor); mr.diffuseColor = new Color3f(diffuseColor); mr.specularColor = new Color3f(specularColor); // other attributes are copy by clone() automatically return mr; } protected void set(MaterialRetained mat) { super.set(mat); // duplicate any referenced data ambientColor.set(mat.ambientColor); emissiveColor.set(mat.emissiveColor); diffuseColor.set(mat.diffuseColor); specularColor.set(mat.specularColor); shininess = mat.shininess; lightingEnable = mat.lightingEnable; colorTarget = mat.colorTarget; } final void sendMessage(int attrMask, Object attr) { ArrayList univList = new ArrayList(); ArrayList gaList = Shape3DRetained.getGeomAtomsList(mirror.users, univList); // Send to rendering attribute structure, regardless of // whether there are users or not (alternate appearance case ..) J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES; createMessage.type = J3dMessage.MATERIAL_CHANGED; createMessage.universe = null; createMessage.args[0] = this; createMessage.args[1]= new Integer(attrMask); createMessage.args[2] = attr; createMessage.args[3] = new Integer(changedFrequent); VirtualUniverse.mc.processMessage(createMessage); int size = univList.size(); for(int i=0; i<size; i++) { createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDER; createMessage.type = J3dMessage.MATERIAL_CHANGED; createMessage.universe = (VirtualUniverse) univList.get(i); createMessage.args[0] = this; createMessage.args[1]= new Integer(attrMask); createMessage.args[2] = attr; ArrayList gL = (ArrayList) gaList.get(i); GeometryAtom[] gaArr = new GeometryAtom[gL.size()]; gL.toArray(gaArr); createMessage.args[3] = gaArr; VirtualUniverse.mc.processMessage(createMessage); } } void handleFrequencyChange(int bit) { if (bit == Material.ALLOW_COMPONENT_WRITE) { setFrequencyChangeMask(Material.ALLOW_COMPONENT_WRITE, 0x1); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -