Esempio n. 1
0
 private void parseLightserverBlock(SunflowAPI api)
 {
     p.checkNextToken("{");
     if (p.peekNextToken("shadows"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: shadows setting ignored");
         p.getNextbool();
     }
     if (p.peekNextToken("direct-samples"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: use samples keyword in area light definitions");
         numLightSamples = p.getNextInt();
     }
     if (p.peekNextToken("glossy-samples"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: use samples keyword in glossy shader definitions");
         p.getNextInt();
     }
     if (p.peekNextToken("max-depth"))
     {
         UI.printWarning(UI.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(UI.Module.API, "Deprecated: global settings ignored - use photons block instead");
         p.getNextbool();
         p.getNextInt();
         p.getNextInt();
         p.getNextInt();
         p.getNextFloat();
     }
     if (p.peekNextToken("caustics"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: caustics settings ignored - use photons block instead");
         p.getNextbool();
         p.getNextInt();
         p.getNextFloat();
         p.getNextInt();
         p.getNextFloat();
     }
     if (p.peekNextToken("irr-cache"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: irradiance cache settings ignored - use gi block instead");
         p.getNextInt();
         p.getNextFloat();
         p.getNextFloat();
         p.getNextFloat();
     }
     p.checkNextToken("}");
 }
Esempio n. 2
0
 private void parseImageBlock(SunflowAPI api)
 {
     p.checkNextToken("{");
     if (p.peekNextToken("resolution"))
     {
         api.parameter("resolutionX", p.getNextInt());
         api.parameter("resolutionY", p.getNextInt());
     }
       if (p.peekNextToken("sampler"))
     api.parameter("sampler", p.getNextToken());
     if (p.peekNextToken("aa"))
     {
         api.parameter("aa.min", p.getNextInt());
         api.parameter("aa.max", p.getNextInt());
     }
     if (p.peekNextToken("samples"))
         api.parameter("aa.samples", p.getNextInt());
     if (p.peekNextToken("contrast"))
         api.parameter("aa.contrast", p.getNextFloat());
     if (p.peekNextToken("filter"))
         api.parameter("filter", p.getNextToken());
     if (p.peekNextToken("jitter"))
         api.parameter("aa.jitter", p.getNextbool());
     if (p.peekNextToken("show-aa"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: show-aa ignored");
         p.getNextbool();
     }
       if (p.peekNextToken("cache"))
     api.parameter("aa.cache", p.getNextbool());
     if (p.peekNextToken("output"))
     {
         UI.printWarning(UI.Module.API, "Deprecated: output statement ignored");
         p.getNextToken();
     }
     api.options(SunflowAPI.DEFAULT_OPTIONS);
     p.checkNextToken("}");
 }
Esempio n. 3
0
 public override bool parse(Stream stream, SunflowAPI api)
 {
     //string localDir = Path.GetFullPath(filename);
     numLightSamples = 1;
     Timer timer = new Timer();
     timer.start();
     UI.printInfo(UI.Module.API, "Parsing stream ...");
     try
     {
         p = new Systems.Parser(stream);
         while (true)
         {
             string token = p.getNextToken();
             if (token == null)
                 break;
             if (token == "image")
             {
                 UI.printInfo(UI.Module.API, "Reading image settings ...");
                 parseImageBlock(api);
             }
             else if (token == "background")
             {
                 UI.printInfo(UI.Module.API, "Reading background ...");
                 parseBackgroundBlock(api);
             }
             else if (token == "accel")
             {
                 UI.printInfo(UI.Module.API, "Reading accelerator type ...");
                 p.getNextToken();
                 UI.printWarning(UI.Module.API, "Setting accelerator type is not recommended - ignoring");
             }
             else if (token == "filter")
             {
                 UI.printInfo(UI.Module.API, "Reading image filter type ...");
                 parseFilter(api);
             }
             else if (token == "bucket")
             {
                 UI.printInfo(UI.Module.API, "Reading bucket settings ...");
                 api.parameter("bucket.size", p.getNextInt());
                 api.parameter("bucket.order", p.getNextToken());
                 api.options(SunflowAPI.DEFAULT_OPTIONS);
             }
             else if (token == "photons")
             {
                 UI.printInfo(UI.Module.API, "Reading photon settings ...");
                 parsePhotonBlock(api);
             }
             else if (token == "gi")
             {
                 UI.printInfo(UI.Module.API, "Reading global illumination settings ...");
                 parseGIBlock(api);
             }
             else if (token == "lightserver")
             {
                 UI.printInfo(UI.Module.API, "Reading light server settings ...");
                 parseLightserverBlock(api);
             }
             else if (token == "trace-depths")
             {
                 UI.printInfo(UI.Module.API, "Reading trace depths ...");
                 parseTraceBlock(api);
             }
             else if (token == "camera")
             {
                 parseCamera(api);
             }
             else if (token == "shader")
             {
                 if (!parseShader(api))
                     return false;
             }
             else if (token == "modifier")
             {
                 if (!parseModifier(api))
                     return false;
             }
             else if (token == "override")
             {
     api.parameter("override.shader", p.getNextToken());
     api.parameter("override.photons", p.getNextbool());
     api.options(SunflowAPI.DEFAULT_OPTIONS);
             }
             else if (token == "object")
             {
                 parseObjectBlock(api);
             }
             else if (token == "instance")
             {
                 parseInstanceBlock(api);
             }
             else if (token == "light")
             {
                 parseLightBlock(api);
             }
             else if (token == "texturepath")
             {
                 string path = p.getNextToken();
                 //if (!new File(path).isAbsolute())
                 //    path = localDir + File.separator + path;
     api.searchpath("texture", Path.GetFullPath(path));
             }
             else if (token == "includepath")
             {
                 string path = p.getNextToken();
                 //if (!new File(path).isAbsolute())
                 //    path = localDir + File.separator + path;
                 api.searchpath("include", Path.GetFullPath(path));
             }
             else if (token == "include")
             {
                 string file = p.getNextToken();
                 UI.printInfo(UI.Module.API, "Including: \"{0}\" ...", file);
                 api.include(file);
             }
             else
                 UI.printWarning(UI.Module.API, "Unrecognized token {0}", token);
         }
         p.close();
     }
     catch (Exception e)
     {
         UI.printError(UI.Module.API, "{0}", e);
         return false;
     }
     timer.end();
     UI.printInfo(UI.Module.API, "Done parsing.");
     UI.printInfo(UI.Module.API, "Parsing time: {0}", timer.ToString());
     return true;
 }
Esempio n. 4
0
 private void parseGIBlock(SunflowAPI api)
 {
     p.checkNextToken("{");
     p.checkNextToken("type");
     if (p.peekNextToken("irr-cache"))
     {
         api.parameter("gi.engine", "irr-cache");
         p.checkNextToken("samples");
         api.parameter("gi.irr-cache.samples", p.getNextInt());
         p.checkNextToken("tolerance");
         api.parameter("gi.irr-cache.tolerance", p.getNextFloat());
         p.checkNextToken("spacing");
         api.parameter("gi.irr-cache.min_spacing", p.getNextFloat());
         api.parameter("gi.irr-cache.max_spacing", p.getNextFloat());
         // parse global photon map info
         if (p.peekNextToken("global"))
         {
             api.parameter("gi.irr-cache.gmap.emit", p.getNextInt());
             api.parameter("gi.irr-cache.gmap", p.getNextToken());
             api.parameter("gi.irr-cache.gmap.gather", p.getNextInt());
             api.parameter("gi.irr-cache.gmap.radius", p.getNextFloat());
         }
     }
     else if (p.peekNextToken("path"))
     {
         api.parameter("gi.engine", "path");
         p.checkNextToken("samples");
         api.parameter("gi.path.samples", p.getNextInt());
         if (p.peekNextToken("bounces"))
         {
             UI.printWarning(UI.Module.API, "Deprecated setting: bounces - use diffuse trace depth instead");
             p.getNextInt();
         }
     }
     else if (p.peekNextToken("fake"))
     {
         api.parameter("gi.engine", "fake");
         p.checkNextToken("up");
         api.parameter("gi.fake.up", parseVector());
         p.checkNextToken("sky");
         api.parameter("gi.fake.sky", null, parseColor().getRGB());
         p.checkNextToken("ground");
     api.parameter("gi.fake.ground", null, parseColor().getRGB());
     }
     else if (p.peekNextToken("igi"))
     {
         api.parameter("gi.engine", "igi");
         p.checkNextToken("samples");
         api.parameter("gi.igi.samples", p.getNextInt());
         p.checkNextToken("sets");
         api.parameter("gi.igi.sets", p.getNextInt());
         if (!p.peekNextToken("b"))
             p.checkNextToken("c");
         api.parameter("gi.igi.c", p.getNextFloat());
         p.checkNextToken("bias-samples");
         api.parameter("gi.igi.bias_samples", p.getNextInt());
     }
     else if (p.peekNextToken("ambocc"))
     {
         api.parameter("gi.engine", "ambocc");
         p.checkNextToken("bright");
     api.parameter("gi.ambocc.bright", null, parseColor().getRGB());
         p.checkNextToken("dark");
     api.parameter("gi.ambocc.dark", null, parseColor().getRGB());
         p.checkNextToken("samples");
         api.parameter("gi.ambocc.samples", p.getNextInt());
         if (p.peekNextToken("maxdist"))
             api.parameter("gi.ambocc.maxdist", p.getNextFloat());
     }
     else if (p.peekNextToken("none") || p.peekNextToken("null"))
     {
         // disable GI
         api.parameter("gi.engine", "none");
     }
     else
         UI.printWarning(UI.Module.API, "Unrecognized gi engine type \"{0}\" - ignoring", p.getNextToken());
     api.options(SunflowAPI.DEFAULT_OPTIONS);
     p.checkNextToken("}");
 }
Esempio n. 5
0
 private void parseFilter(SunflowAPI api)
 {
     UI.printWarning(UI.Module.API, "Deprecated keyword \"filter\" - set this option in the image block");
     string name = p.getNextToken();
     api.parameter("filter", name);
     api.options(SunflowAPI.DEFAULT_OPTIONS);
     bool hasSizeParams = name == "box" || name == "gaussian" || name == "blackman-harris" || name == "sinc" || name == "triangle";
     if (hasSizeParams)
     {
         p.getNextFloat();
         p.getNextFloat();
     }
 }
Esempio n. 6
0
 private void parseCamera(SunflowAPI api)
 {
     p.checkNextToken("{");
     p.checkNextToken("type");
     string type = p.getNextToken();
       UI.printInfo(UI.Module.API, "Reading {0} camera ...", type);
       if (p.peekNextToken("shutter")) {
     api.parameter("shutter.open", p.getNextFloat());
     api.parameter("shutter.close", p.getNextFloat());
       }
     parseCameraTransform(api);
       string name = generateUniqueName("camera");
     if (type == "pinhole")
     {
         p.checkNextToken("fov");
         api.parameter("fov", p.getNextFloat());
         p.checkNextToken("aspect");
         api.parameter("aspect", p.getNextFloat());
     if (p.peekNextToken("shift"))
     {
       api.parameter("shift.x", p.getNextFloat());
       api.parameter("shift.y", p.getNextFloat());
       }
         api.camera(name, "pinhole");
     }
     else if (type == "thinlens")
     {
         p.checkNextToken("fov");
         api.parameter("fov", p.getNextFloat());
         p.checkNextToken("aspect");
         api.parameter("aspect", p.getNextFloat());
     if (p.peekNextToken("shift"))
     {
       api.parameter("shift.x", p.getNextFloat());
       api.parameter("shift.y", 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, "thinlens");
     }
     else if (type == "spherical")
     {
         // no extra arguments
         api.camera(name, "spherical");
     }
     else if (type == "fisheye")
     {
         // no extra arguments
         api.camera(name, "fisheye");
     }
     else
     {
         UI.printWarning(UI.Module.API, "Unrecognized camera type: {0}", p.getNextToken());
         p.checkNextToken("}");
         return;
     }
     p.checkNextToken("}");
     if (name != null)
     {
         api.parameter("camera", name);
         api.options(SunflowAPI.DEFAULT_OPTIONS);
     }
 }
Esempio n. 7
0
 private void parseTraceBlock(SunflowAPI api)
 {
     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);
 }
Esempio n. 8
0
 private void parsePhotonBlock(SunflowAPI api)
 {
     int numEmit = 0;
     bool globalEmit = false;
     p.checkNextToken("{");
     if (p.peekNextToken("emit"))
     {
         UI.printWarning(UI.Module.API, "Shared photon emit values are deprectated - specify number of photons to emit per map");
         numEmit = p.getNextInt();
         globalEmit = true;
     }
     if (p.peekNextToken("global"))
     {
         UI.printWarning(UI.Module.API, "Global photon map setting belonds inside the gi block - ignoring");
         if (!globalEmit)
             p.getNextInt();
         p.getNextToken();
         p.getNextInt();
         p.getNextFloat();
     }
     p.checkNextToken("caustics");
     if (!globalEmit)
         numEmit = p.getNextInt();
     api.parameter("caustics.emit", numEmit);
     api.parameter("caustics", p.getNextToken());
     api.parameter("caustics.gather", p.getNextInt());
     api.parameter("caustics.radius", p.getNextFloat());
     api.options(SunflowAPI.DEFAULT_OPTIONS);
     p.checkNextToken("}");
 }