Esempio n. 1
0
        /**
         * Create an API object from the specified file. Java files are read by
         * Janino and are expected to implement a build method (they implement a
         * derived class of SunflowAPI. The build method is called if the code
         * compiles succesfully. Other files types are handled by the parse method.
         *
         * @param filename filename to load
         * @return a valid SunflowAPI object or <code>null</code> on failure
         */
        public static SunflowAPI create(string filename, int frameNumber)
        {
            if (filename == null)
            {
                return(new SunflowAPI());
            }
            SunflowAPI api = null;

            if (filename.EndsWith(".java"))
            {
                Timer t = new Timer();
                UI.printInfo(UI.Module.API, "Compiling \"" + filename + "\" ...");
                t.start();
                try
                {
                    //FileInputStream stream = new FileInputStream(filename);
                    api = null;//(SunflowAPI) ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(filename, stream), SunflowAPI.class, ClassLoader.getSystemClassLoader());
                    //fixme: the dynamic loading
                    //stream.close();
                }
                catch (Exception e)
                {
                    UI.printError(UI.Module.API, "Could not compile: \"{0}\"", filename);
                    UI.printError(UI.Module.API, "{0}", e);
                    return(null);
                }
                t.end();
                UI.printInfo(UI.Module.API, "Compile time: " + t.ToString());
                if (api != null)
                {
                    string currentFolder = Path.GetDirectoryName(filename);//new File(filename).getAbsoluteFile().getParentFile().getAbsolutePath();
                    api.includeSearchPath.addSearchPath(currentFolder);
                    api.textureSearchPath.addSearchPath(currentFolder);
                }
                UI.printInfo(UI.Module.API, "Build script running ...");
                t.start();
                api.currentFrame = frameNumber;
                api.build();
                t.end();
                UI.printInfo(UI.Module.API, "Build script time: {0}", t.ToString());
            }
            else
            {
                api = new SunflowAPI();
                api = api.include(filename) ? api : null;
            }
            return(api);
        }
Esempio n. 2
0
 /**
  * Create an API object from the specified file. Java files are read by
  * Janino and are expected to implement a build method (they implement a
  * derived class of SunflowAPI. The build method is called if the code
  * compiles succesfully. Other files types are handled by the parse method.
  *
  * @param filename filename to load
  * @return a valid SunflowAPI object or <code>null</code> on failure
  */
 public static SunflowAPI create(string filename, int frameNumber)
 {
     if (filename == null)
         return new SunflowAPI();
     SunflowAPI api = null;
     if (filename.EndsWith(".java"))
     {
         Timer t = new Timer();
         UI.printInfo(UI.Module.API, "Compiling \"" + filename + "\" ...");
         t.start();
         try
         {
             //FileInputStream stream = new FileInputStream(filename);
             api = null;//(SunflowAPI) ClassBodyEvaluator.createFastClassBodyEvaluator(new Scanner(filename, stream), SunflowAPI.class, ClassLoader.getSystemClassLoader());
             //fixme: the dynamic loading
             //stream.close();
         }
         catch (Exception e)
         {
             UI.printError(UI.Module.API, "Could not compile: \"{0}\"", filename);
             UI.printError(UI.Module.API, "{0}", e);
             return null;
         }
         t.end();
         UI.printInfo(UI.Module.API, "Compile time: " + t.ToString());
         if (api != null)
         {
             string currentFolder = Path.GetDirectoryName(filename);//new File(filename).getAbsoluteFile().getParentFile().getAbsolutePath();
             api.includeSearchPath.addSearchPath(currentFolder);
             api.textureSearchPath.addSearchPath(currentFolder);
         }
         UI.printInfo(UI.Module.API, "Build script running ...");
         t.start();
         api.currentFrame = frameNumber;
         api.build();
         t.end();
         UI.printInfo(UI.Module.API, "Build script time: {0}", t.ToString());
     }
     else
     {
         api = new SunflowAPI();
         api = api.include(filename) ? api : null;
     }
     return api;
 }
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;
 }