📄 scparser.java
字号:
p.checkNextToken("}");
}
private void parseLightserverBlock(SunflowAPI api) throws ParserException, IOException {
p.checkNextToken("{");
if (p.peekNextToken("shadows")) {
UI.printWarning(Module.API, "Deprecated: shadows setting ignored");
p.getNextBoolean();
}
if (p.peekNextToken("direct-samples")) {
UI.printWarning(Module.API, "Deprecated: use samples keyword in area light definitions");
numLightSamples = p.getNextInt();
}
if (p.peekNextToken("glossy-samples")) {
UI.printWarning(Module.API, "Deprecated: use samples keyword in glossy shader definitions");
p.getNextInt();
}
if (p.peekNextToken("max-depth")) {
UI.printWarning(Module.API, "Deprecated: max-depth setting - use trace-depths block instead");
int d = p.getNextInt();
api.parameter("depths.diffuse", 1);
api.parameter("depths.reflection", d - 1);
api.parameter("depths.refraction", 0);
api.options(SunflowAPI.DEFAULT_OPTIONS);
}
if (p.peekNextToken("global")) {
UI.printWarning(Module.API, "Deprecated: global settings ignored - use photons block instead");
p.getNextBoolean();
p.getNextInt();
p.getNextInt();
p.getNextInt();
p.getNextFloat();
}
if (p.peekNextToken("caustics")) {
UI.printWarning(Module.API, "Deprecated: caustics settings ignored - use photons block instead");
p.getNextBoolean();
p.getNextInt();
p.getNextFloat();
p.getNextInt();
p.getNextFloat();
}
if (p.peekNextToken("irr-cache")) {
UI.printWarning(Module.API, "Deprecated: irradiance cache settings ignored - use gi block instead");
p.getNextInt();
p.getNextFloat();
p.getNextFloat();
p.getNextFloat();
}
p.checkNextToken("}");
}
private void parseTraceBlock(SunflowAPI api) throws ParserException, IOException {
p.checkNextToken("{");
if (p.peekNextToken("diff"))
api.parameter("depths.diffuse", p.getNextInt());
if (p.peekNextToken("refl"))
api.parameter("depths.reflection", p.getNextInt());
if (p.peekNextToken("refr"))
api.parameter("depths.refraction", p.getNextInt());
p.checkNextToken("}");
api.options(SunflowAPI.DEFAULT_OPTIONS);
}
private void parseCamera(SunflowAPI api) throws ParserException, IOException {
p.checkNextToken("{");
p.checkNextToken("type");
String type = p.getNextToken();
UI.printInfo(Module.API, "Reading %s camera ...", type);
parseCameraTransform(api);
String name = api.getUniqueName("camera");
if (type.equals("pinhole")) {
p.checkNextToken("fov");
api.parameter("fov", p.getNextFloat());
p.checkNextToken("aspect");
api.parameter("aspect", p.getNextFloat());
api.camera(name, new PinholeLens());
} else if (type.equals("thinlens")) {
p.checkNextToken("fov");
api.parameter("fov", p.getNextFloat());
p.checkNextToken("aspect");
api.parameter("aspect", p.getNextFloat());
p.checkNextToken("fdist");
api.parameter("focus.distance", p.getNextFloat());
p.checkNextToken("lensr");
api.parameter("lens.radius", p.getNextFloat());
if (p.peekNextToken("sides"))
api.parameter("lens.sides", p.getNextInt());
if (p.peekNextToken("rotation"))
api.parameter("lens.rotation", p.getNextFloat());
api.camera(name, new ThinLens());
} else if (type.equals("spherical")) {
// no extra arguments
api.camera(name, new SphericalLens());
} else if (type.equals("fisheye")) {
// no extra arguments
api.camera(name, new FisheyeLens());
} else {
UI.printWarning(Module.API, "Unrecognized camera type: %s", p.getNextToken());
p.checkNextToken("}");
return;
}
p.checkNextToken("}");
if (name != null) {
api.parameter("camera", name);
api.options(SunflowAPI.DEFAULT_OPTIONS);
}
}
private void parseCameraTransform(SunflowAPI api) throws ParserException, IOException {
if (p.peekNextToken("steps")) {
// motion blur camera
int n = p.getNextInt();
api.parameter("transform.steps", n);
for (int i = 0; i < n; i++)
parseCameraMatrix(i, api);
} else
parseCameraMatrix(-1, api);
}
private void parseCameraMatrix(int index, SunflowAPI api) throws IOException, ParserException {
String offset = index < 0 ? "" : String.format("[%d]", index);
if (p.peekNextToken("transform")) {
// advanced camera
api.parameter(String.format("transform%s", offset), parseMatrix());
} else {
if (index >= 0)
p.checkNextToken("{");
// regular camera specification
p.checkNextToken("eye");
api.parameter(String.format("eye%s", offset), parsePoint());
p.checkNextToken("target");
api.parameter(String.format("target%s", offset), parsePoint());
p.checkNextToken("up");
api.parameter(String.format("up%s", offset), parseVector());
if (index >= 0)
p.checkNextToken("}");
}
}
private boolean parseShader(SunflowAPI api) throws ParserException, IOException {
p.checkNextToken("{");
p.checkNextToken("name");
String name = p.getNextToken();
UI.printInfo(Module.API, "Reading shader: %s ...", name);
p.checkNextToken("type");
if (p.peekNextToken("diffuse")) {
if (p.peekNextToken("diff")) {
api.parameter("diffuse", parseColor());
api.shader(name, new DiffuseShader());
} else if (p.peekNextToken("texture")) {
api.parameter("texture", p.getNextToken());
api.shader(name, new TexturedDiffuseShader());
} else
UI.printWarning(Module.API, "Unrecognized option in diffuse shader block: %s", p.getNextToken());
} else if (p.peekNextToken("phong")) {
String tex = null;
if (p.peekNextToken("texture"))
api.parameter("texture", tex = p.getNextToken());
else {
p.checkNextToken("diff");
api.parameter("diffuse", parseColor());
}
p.checkNextToken("spec");
api.parameter("specular", parseColor());
api.parameter("power", p.getNextFloat());
if (p.peekNextToken("samples"))
api.parameter("samples", p.getNextInt());
if (tex != null)
api.shader(name, new TexturedPhongShader());
else
api.shader(name, new PhongShader());
} else if (p.peekNextToken("amb-occ") || p.peekNextToken("amb-occ2")) {
String tex = null;
if (p.peekNextToken("diff") || p.peekNextToken("bright"))
api.parameter("bright", parseColor());
else if (p.peekNextToken("texture"))
api.parameter("texture", tex = p.getNextToken());
if (p.peekNextToken("dark")) {
api.parameter("dark", parseColor());
p.checkNextToken("samples");
api.parameter("samples", p.getNextInt());
p.checkNextToken("dist");
api.parameter("maxdist", p.getNextFloat());
}
if (tex == null)
api.shader(name, new AmbientOcclusionShader());
else
api.shader(name, new TexturedAmbientOcclusionShader());
} else if (p.peekNextToken("mirror")) {
p.checkNextToken("refl");
api.parameter("color", parseColor());
api.shader(name, new MirrorShader());
} else if (p.peekNextToken("glass")) {
p.checkNextToken("eta");
api.parameter("eta", p.getNextFloat());
p.checkNextToken("color");
api.parameter("color", parseColor());
if (p.peekNextToken("absorbtion.distance"))
api.parameter("absorbtion.distance", p.getNextFloat());
if (p.peekNextToken("absorbtion.color"))
api.parameter("absorbtion.color", parseColor());
api.shader(name, new GlassShader());
} else if (p.peekNextToken("shiny")) {
String tex = null;
if (p.peekNextToken("texture"))
api.parameter("texture", tex = p.getNextToken());
else {
p.checkNextToken("diff");
api.parameter("diffuse", parseColor());
}
p.checkNextToken("refl");
api.parameter("shiny", p.getNextFloat());
if (tex == null)
api.shader(name, new ShinyDiffuseShader());
else
api.shader(name, new TexturedShinyDiffuseShader());
} else if (p.peekNextToken("ward")) {
String tex = null;
if (p.peekNextToken("texture"))
api.parameter("texture", tex = p.getNextToken());
else {
p.checkNextToken("diff");
api.parameter("diffuse", parseColor());
}
p.checkNextToken("spec");
api.parameter("specular", parseColor());
p.checkNextToken("rough");
api.parameter("roughnessX", p.getNextFloat());
api.parameter("roughnessY", p.getNextFloat());
if (p.peekNextToken("samples"))
api.parameter("samples", p.getNextInt());
if (tex != null)
api.shader(name, new TexturedWardShader());
else
api.shader(name, new AnisotropicWardShader());
} else if (p.peekNextToken("view-caustics")) {
api.shader(name, new ViewCausticsShader());
} else if (p.peekNextToken("view-irradiance")) {
api.shader(name, new ViewIrradianceShader());
} else if (p.peekNextToken("view-global")) {
api.shader(name, new ViewGlobalPhotonsShader());
} else if (p.peekNextToken("constant")) {
// backwards compatibility -- peek only
p.peekNextToken("color");
api.parameter("color", parseColor());
api.shader(name, new ConstantShader());
} else if (p.peekNextToken("janino")) {
String code = p.getNextCodeBlock();
try {
Shader shader = (Shader) ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(null, new StringReader(code)), Shader.class, ClassLoader.getSystemClassLoader());
api.shader(name, shader);
} catch (CompileException e) {
UI.printDetailed(Module.API, "Compiling: %s", code);
UI.printError(Module.API, "%s", e.getMessage());
e.printStackTrace();
return false;
} catch (ParseException e) {
UI.printDetailed(Module.API, "Compiling: %s", code);
UI.printError(Module.API, "%s", e.getMessage());
e.printStackTrace();
return false;
} catch (ScanException e) {
UI.printDetailed(Module.API, "Compiling: %s", code);
UI.printError(Module.API, "%s", e.getMessage());
e.printStackTrace();
return false;
} catch (IOException e) {
UI.printDetailed(Module.API, "Compiling: %s", code);
UI.printError(Module.API, "%s", e.getMessage());
e.printStackTrace();
return false;
}
} else if (p.peekNextToken("id")) {
api.shader(name, new IDShader());
} else if (p.peekNextToken("uber")) {
if (p.peekNextToken("diff"))
api.parameter("diffuse", parseColor());
if (p.peekNextToken("diff.texture"))
api.parameter("diffuse.texture", p.getNextToken());
if (p.peekNextToken("diff.blend"))
api.parameter("diffuse.blend", p.getNextFloat());
if (p.peekNextToken("refl") || p.peekNextToken("spec"))
api.parameter("specular", parseColor());
if (p.peekNextToken("texture")) {
// deprecated
UI.printWarning(Module.API, "Deprecated uber shader parameter \"texture\" - please use \"diffuse.texture\" and \"diffuse.blend\" instead");
api.parameter("diffuse.texture", p.getNextToken());
api.parameter("diffuse.blend", p.getNextFloat());
}
if (p.peekNextToken("spec.texture"))
api.parameter("specular.texture", p.getNextToken());
if (p.peekNextToken("spec.blend"))
api.parameter("specular.blend", p.getNextFloat());
if (p.peekNextToken("glossy"))
api.parameter("glossyness", p.getNextFloat());
if (p.peekNextToken("samples"))
api.parameter("samples", p.getNextInt());
api.shader(name, new UberShader());
} else
UI.printWarning(Module.API, "Unrecognized shader type: %s", p.getNextToken());
p.checkNextToken("}");
return true;
}
private boolean parseModifier(SunflowAPI api) throws ParserException, IOException {
p.checkNextToken("{");
p.checkNextToken("name");
String name = p.getNextToken();
UI.printInfo(Module.API, "Reading shader: %s ...", name);
p.checkNextToken("type");
if (p.peekNextToken("bump")) {
p.checkNextToken("texture");
api.parameter("texture", p.getNextToken());
p.checkNextToken("scale");
api.parameter("scale", p.getNextFloat());
api.modifier(name, new BumpMappingModifier());
} else if (p.peekNextToken("normalmap")) {
p.checkNextToken("texture");
api.parameter("texture", p.getNextToken());
api.modifier(name, new NormalMapModifier());
} else {
UI.printWarning(Module.API, "Unrecognized modifier type: %s", p.getNextToken());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -