From: <ha...@us...> - 2006-11-26 01:19:57
|
Revision: 6344 http://svn.sourceforge.net/jmol/?rev=6344&view=rev Author: hansonr Date: 2006-11-25 17:19:55 -0800 (Sat, 25 Nov 2006) Log Message: ----------- lighting cleanup; addition of lighting to state Modified Paths: -------------- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java trunk/Jmol/src/org/jmol/g3d/Shade3D.java trunk/Jmol/src/org/jmol/viewer/ColorManager.java trunk/Jmol/src/org/jmol/viewer/Eval.java trunk/Jmol/src/org/jmol/viewer/StateManager.java trunk/Jmol/src/org/jmol/viewer/Token.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/g3d/Graphics3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2006-11-25 19:51:36 UTC (rev 6343) +++ trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2006-11-26 01:19:55 UTC (rev 6344) @@ -1593,10 +1593,6 @@ Shade3D.setSpecularPower(specularPower); } - public String getSpecularState() { - return Shade3D.getSpecularState(); - } - public void setAmbientPercent(int ambientPercent) { Shade3D.setAmbientPercent(ambientPercent); } Modified: trunk/Jmol/src/org/jmol/g3d/Shade3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Shade3D.java 2006-11-25 19:51:36 UTC (rev 6343) +++ trunk/Jmol/src/org/jmol/g3d/Shade3D.java 2006-11-26 01:19:55 UTC (rev 6344) @@ -24,7 +24,7 @@ package org.jmol.g3d; -import org.jmol.util.Logger; +//import org.jmol.util.Logger; /** *<p> @@ -63,6 +63,8 @@ // the viewer vector is always 0,0,1 + // the following six settings are actually set in StateManager + // set specular on|off static boolean specularOn = true; // set specular 0-100 @@ -253,7 +255,7 @@ static void setSpecular(boolean specular) { specularOn = specular; - dump(); + //dump(); } static boolean getSpecular() { @@ -266,7 +268,7 @@ (float)Math.sqrt(xLightsource * xLightsource + yLightsource * yLightsource + zLightsource * zLightsource); - dump(); + //dump(); } static void setSpecularPower(int specularPower) { @@ -274,17 +276,12 @@ intenseFraction = specularPower / 100f; else specularExponent = -specularPower; - dump(); + //dump(); } - static String getSpecularState() { - return "set specPower " + (-specularExponent) + "; set specPower " - + (int) (intenseFraction * 100); - } - static void setAmbientPercent(int ambientPercent) { ambientFraction = ambientPercent / 100f; - dump(); + //dump(); } static int getAmbientPercent() { @@ -294,7 +291,7 @@ static void setDiffusePercent(int diffusePercent) { intensityDiffuse = diffusePercent / 100f; - dump(); + //dump(); } static int getDiffusePercent() { @@ -303,13 +300,13 @@ static void setSpecularPercent(int specularPercent) { intensitySpecular = specularPercent / 100f; - dump(); + //dump(); } static int getSpecularPercent() { return (int) (intensitySpecular * 100); } - +/* static void dump() { Logger.debug("\n ambientPercent=" + ambientFraction + "\n diffusePercent=" + intensityDiffuse + @@ -320,4 +317,5 @@ "\n zLightsource=" + zLightsource + "\n shadeNormal=" + shadeNormal); } +*/ } Modified: trunk/Jmol/src/org/jmol/viewer/ColorManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/ColorManager.java 2006-11-25 19:51:36 UTC (rev 6343) +++ trunk/Jmol/src/org/jmol/viewer/ColorManager.java 2006-11-26 01:19:55 UTC (rev 6344) @@ -41,7 +41,6 @@ altArgbsCpk = new int[JmolConstants.altArgbsCpk.length]; for (int i = JmolConstants.altArgbsCpk.length; --i >= 0; ) altArgbsCpk[i] = JmolConstants.altArgbsCpk[i]; - resetElementColors(); } boolean isDefaultColorRasmol; @@ -339,7 +338,6 @@ private void flushCaches() { g3d.flushShadesAndImageCaches(); - viewer.refresh(0, "ColorManager:flushCaches()"); } void setSpecular(boolean specular) { @@ -356,10 +354,6 @@ flushCaches(); } - String getSpecularState() { - return g3d.getSpecularState(); - } - void setAmbientPercent(int ambientPercent) { g3d.setAmbientPercent(ambientPercent); flushCaches(); Modified: trunk/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Eval.java 2006-11-25 19:51:36 UTC (rev 6343) +++ trunk/Jmol/src/org/jmol/viewer/Eval.java 2006-11-26 01:19:55 UTC (rev 6344) @@ -4242,6 +4242,7 @@ */ void set() throws ScriptException { + int val = 0; switch (statement[1].tok) { case Token.axes: setAxes(2); @@ -4304,7 +4305,42 @@ if (!isSyntaxCheck) viewer.setFormalCharges(n); break; - + case Token.specular: + if (statementLength == 2 || statement[2].tok != Token.integer) { + setBooleanProperty("specular", booleanParameter(2)); + break; + } + //fall through + case Token.ambient: + case Token.diffuse: + case Token.specpercent: + checkLength3(); + val = intParameter(2); + if (val > 100 || val < 0) + numberOutOfRange(0, 100); + setIntProperty((String)statement[1].value, val); + break; + case Token.specpower: + checkLength3(); + val = intParameter(2); + if (val > 100) + numberOutOfRange(0, 100); + if (val >= 0) { + setIntProperty((String)statement[1].value, val); + break; + } + if (val < -10 || val > -1) + numberOutOfRange(-10, -1); + setIntProperty("specularExponent", -val); + break; + case Token.specexponent: + checkLength3(); + if (val == 0) + val = intParameter(2); + if (val > 10 || val < 1) + numberOutOfRange(1, 10); + setIntProperty("specularExponent", val); + break; // not implemented case Token.backfade: case Token.cartoon: @@ -4319,10 +4355,8 @@ case Token.write: // fall through to identifier - case Token.ambient: case Token.bonds: case Token.debugscript: - case Token.diffuse: case Token.frank: case Token.help: case Token.hetero: @@ -4330,8 +4364,7 @@ case Token.identifier: case Token.radius: case Token.solvent: - case Token.specular: - case Token.specpower: + String str = (String) statement[1].value; if (str.toLowerCase().indexOf("label") == 0) { setLabel(str.substring(5)); @@ -5082,19 +5115,10 @@ str = ""; break; case Token.ambient: - value = "set ambient " + viewer.getAmbientPercent(); - str = ""; - break; case Token.diffuse: - value = "set diffuse " + viewer.getDiffusePercent(); - str = ""; - break; case Token.specular: - value = "set specular " + viewer.getSpecular(); - str = ""; - break; case Token.specpower: - // strange! two values! + case Token.specexponent: value = viewer.getSpecularState(); str = ""; break; Modified: trunk/Jmol/src/org/jmol/viewer/StateManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/StateManager.java 2006-11-25 19:51:36 UTC (rev 6343) +++ trunk/Jmol/src/org/jmol/viewer/StateManager.java 2006-11-26 01:19:55 UTC (rev 6344) @@ -315,6 +315,15 @@ // } + //lighting (see Graphics3D.Shade3D + + boolean specular = true; + int specularPercent = 22; + int specularExponent = 6; + int specularPower = 40; + int diffusePercent = 84; + int ambientPercent = 45; + //file loading char inlineNewlineChar = '|'; //pseudo static @@ -459,11 +468,23 @@ appendCmd(str, "initialize"); appendCmd(str, "set refreshing false"); appendCmd(str, "background " + escapeColor(argbBackground)); + str.append(getSpecularState()); if (stereoState != null) appendCmd(str, "stereo " + stereoState); return str + "\n"; } + String getSpecularState() { + StringBuffer str = new StringBuffer(""); + appendCmd(str, "set ambientPercent " + ambientPercent); + appendCmd(str, "set diffusePercent " + diffusePercent); + appendCmd(str, "set specular " + specular); + appendCmd(str, "set specularPercent " + specularPercent); + appendCmd(str, "set specularPower " + specularPower); + appendCmd(str, "set specularExponent " + specularExponent); + return str.toString(); + } + int axesMode = JmolConstants.AXES_MODE_BOUNDBOX; int pickingSpinRate = 10; @@ -515,6 +536,7 @@ //settings won't be reflected in the load state, which is determined //earlier, when the file loads. ";refreshing;defaults;backgroundmodel;backgroundcolor;stereo;" + + ";ambientpercent;diffusepercent;specular;specularexponent;specularpower;specularpercent;" + ";debugscript;frank;showaxes;showunitcell;showboundbox;" + ";slabEnabled;zoomEnabled;axeswindow;axesunitcell;axesmolecular;windowcentered;" + ";vibrationscale;vibrationperiod;"; Modified: trunk/Jmol/src/org/jmol/viewer/Token.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Token.java 2006-11-25 19:51:36 UTC (rev 6343) +++ trunk/Jmol/src/org/jmol/viewer/Token.java 2006-11-26 01:19:55 UTC (rev 6344) @@ -208,44 +208,46 @@ final static int boundbox = setparam | 5 | command; // cartoon final static int cisangle = setparam | 6; - final static int fontsize = setparam | 8; - final static int fontstroke = setparam | 9; + final static int fontsize = setparam | 7; + final static int fontstroke = setparam | 8; // hbonds // hetero - final static int hourglass = setparam | 10; + final static int hourglass = setparam | 9; // hydrogen - final static int kinemage = setparam | 11; - final static int menus = setparam | 12; + final static int kinemage = setparam | 10; + final static int menus = setparam | 11; // monitor - final static int mouse = setparam | 13; - final static int picking = setparam | 14; - final static int shadow = setparam | 15; - final static int slabmode = setparam | 16; + final static int mouse = setparam | 12; + final static int picking = setparam | 13; + final static int shadow = setparam | 14; + final static int slabmode = setparam | 15; // solvent - final static int specular = setparam | 17; + final static int specular = setparam | 16; + final static int specpercent = setparam | 17; final static int specpower = setparam | 18; + final static int specexponent = setparam | 19; // ssbonds // stereo // strands - final static int transparent = setparam | 19; - final static int unitcell = setparam | 20 | expression | predefinedset | command; - final static int vectps = setparam | 21; + final static int transparent = setparam | 20; + final static int unitcell = setparam | 21 | expression | predefinedset | command; + final static int vectps = setparam | 22; // write // chime set parameters - final static int clear = setparam | 22; - final static int gaussian = setparam | 23; + final static int clear = setparam | 23; + final static int gaussian = setparam | 24; // load - final static int mep = setparam | 24; - final static int mlp = setparam | 25; - final static int molsurface = setparam | 26; - final static int debugscript = setparam | 27; - final static int scale3d = setparam | 28; + final static int mep = setparam | 25; + final static int mlp = setparam | 26; + final static int molsurface = setparam | 27; + final static int debugscript = setparam | 28; + final static int scale3d = setparam | 29; // jmol extensions - final static int property = setparam | 29; - final static int diffuse = setparam | 30; - final static int frank = setparam | 31 | command; + final static int property = setparam | 30; + final static int diffuse = setparam | 31; + final static int frank = setparam | 32 | command; final static int pickingStyle = setparam | 33; final static int spacegroup = setparam | 34; @@ -595,9 +597,20 @@ "history", new Token(history, varArgCount, "history"), "subset", new Token(subset, varArgCount, "subset"), + // lighting + + "ambient", new Token(ambient, "ambientPercent"), + "ambientpercent", null, + "diffuse", new Token(diffuse, "diffusePercent"), + "diffusepercent", null, + "specular", new Token(specular, "specular"), + "specularpercent", new Token(specpercent, "specularPercent"), + "specularpower", new Token(specpower, "specularPower"), + "specpower", null, + "specularExponent", new Token(specexponent, "specularExponent"), + // setparams - "ambient", new Token(ambient, "ambient"), "axes", new Token(axes, varArgCount, "axes"), "backfade", new Token(backfade, "backfade"), "bondmode", new Token(bondmode, "bondmode"), @@ -619,8 +632,6 @@ "shadow", new Token(shadow, "shadow"), "slabmode", new Token(slabmode, "slabmode"), // solvent - "specular", new Token(specular, "specular"), - "specpower", new Token(specpower, "specpower"), "transparent", new Token(transparent, "transparent"), "unitcell", new Token(unitcell, onDefault1, "unitcell"), "cell", new Token(cell, "cell"), @@ -637,7 +648,6 @@ // jmol extensions "property", new Token(property, "property"), - "diffuse", new Token(diffuse, "diffuse"), "frank", new Token(frank, onDefault1, "frank"), // must be lower case - see comment above "formalcharge", new Token(formalCharge, "formalcharge"), Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2006-11-25 19:51:36 UTC (rev 6343) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2006-11-26 01:19:55 UTC (rev 6344) @@ -130,10 +130,9 @@ jvm12orGreater = (strJavaVersion.compareTo("1.2") >= 0); jvm14orGreater = (strJavaVersion.compareTo("1.4") >= 0); stateManager = new StateManager(this); - global = stateManager.getGlobalSettings(); g3d = new Graphics3D(display); colorManager = new ColorManager(this, g3d); - setStringProperty("backgroundColor", "black"); + initialize(); statusManager = new StatusManager(this); scriptManager = new ScriptManager(this); transformManager = new TransformManager(this); @@ -303,6 +302,13 @@ void resetAllParameters() { global = stateManager.getGlobalSettings(); colorManager.resetElementColors(); + setStringProperty("backgroundColor", "black"); + setAmbientPercent(global.ambientPercent); + setDiffusePercent(global.diffusePercent); + setSpecular(global.specular); + setSpecularPercent(global.specularPercent); + setSpecularExponent(global.specularExponent); + setSpecularPower(global.specularPower); } String listSavedStates() { @@ -841,6 +847,7 @@ private void setSpecular(boolean specular) { //Eval colorManager.setSpecular(specular); + global.specular = specular; } boolean getSpecular() { @@ -849,16 +856,24 @@ private void setSpecularPower(int specularPower) { //Eval - colorManager.setSpecularPower(specularPower); + colorManager.setSpecularPower(Math.abs(specularPower)); + global.specularPower = specularPower; } + private void setSpecularExponent(int specularExponent) { + //Eval + colorManager.setSpecularPower(-Math.abs(specularExponent)); + global.specularExponent = specularExponent; + } + String getSpecularState() { - return colorManager.getSpecularState(); + return global.getSpecularState(); } private void setAmbientPercent(int ambientPercent) { //Eval colorManager.setAmbientPercent(ambientPercent); + global.ambientPercent = ambientPercent; } int getAmbientPercent() { @@ -868,6 +883,7 @@ private void setDiffusePercent(int diffusePercent) { //Eval colorManager.setDiffusePercent(diffusePercent); + global.diffusePercent = diffusePercent; } int getDiffusePercent() { @@ -877,6 +893,7 @@ private void setSpecularPercent(int specularPercent) { //Eval colorManager.setSpecularPercent(specularPercent); + global.specularPercent = specularPercent; } int getSpecularPercent() { @@ -3182,22 +3199,39 @@ setBackgroundModel(value); break; } - if (key.equalsIgnoreCase("specPower")) { + if (key.equalsIgnoreCase("specularPower")) { setSpecularPower(value); break; } + if (key.equalsIgnoreCase("specularExponent")) { + setSpecularExponent(value); + break; + } if (key.equalsIgnoreCase("specular")) { + setIntProperty("specularPercent", value); + return; + } + if (key.equalsIgnoreCase("diffuse")) { + setIntProperty("diffusePercent", value); + break; + } + if (key.equalsIgnoreCase("ambient")) { + setIntProperty("ambientPercent", value); + break; + } + if (key.equalsIgnoreCase("specularPercent")) { setSpecularPercent(value); break; } - if (key.equalsIgnoreCase("diffuse")) { + if (key.equalsIgnoreCase("diffusePercent")) { setDiffusePercent(value); break; } - if (key.equalsIgnoreCase("ambient")) { + if (key.equalsIgnoreCase("ambientPercent")) { setAmbientPercent(value); break; } + if (key.equalsIgnoreCase("ribbonAspectRatio")) { setRibbonAspectRatio(value); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |