Example #1
0
 final void remove(String name) {
   RenderObjectHandle obj = renderObjects.get(name);
   if (obj == null) {
     UI.printWarning(Module.API, "Unable to remove \"%s\" - object was not defined yet");
     return;
   }
   UI.printDetailed(Module.API, "Removing object \"%s\"", name);
   renderObjects.remove(name);
   // scan through all objects to make sure we don't have any
   // references to the old object still around
   switch (obj.type) {
     case SHADER:
       Shader s = obj.getShader();
       for (Map.Entry<String, RenderObjectHandle> e : renderObjects.entrySet()) {
         Instance i = e.getValue().getInstance();
         if (i != null) {
           UI.printWarning(
               Module.API, "Removing shader \"%s\" from instance \"%s\"", name, e.getKey());
           i.removeShader(s);
         }
       }
       break;
     case MODIFIER:
       Modifier m = obj.getModifier();
       for (Map.Entry<String, RenderObjectHandle> e : renderObjects.entrySet()) {
         Instance i = e.getValue().getInstance();
         if (i != null) {
           UI.printWarning(
               Module.API, "Removing modifier \"%s\" from instance \"%s\"", name, e.getKey());
           i.removeModifier(m);
         }
       }
       break;
     case GEOMETRY:
       {
         Geometry g = obj.getGeometry();
         for (Map.Entry<String, RenderObjectHandle> e : renderObjects.entrySet()) {
           Instance i = e.getValue().getInstance();
           if (i != null && i.hasGeometry(g)) {
             UI.printWarning(
                 Module.API,
                 "Removing instance \"%s\" because it referenced geometry \"%s\"",
                 e.getKey(),
                 name);
             remove(e.getKey());
           }
         }
         break;
       }
     case INSTANCE:
       rebuildInstanceList = true;
       break;
     case LIGHT:
       rebuildLightList = true;
       break;
     default:
       // no dependencies
       break;
   }
 }
Example #2
0
 final boolean update(String name, ParameterList pl, SunflowAPI api) {
   RenderObjectHandle obj = renderObjects.get(name);
   boolean success;
   if (obj == null) {
     UI.printError(Module.API, "Unable to update \"%s\" - object was not defined yet", name);
     success = false;
   } else {
     UI.printDetailed(Module.API, "Updating %s object \"%s\"", obj.typeName(), name);
     success = obj.update(pl, api);
     if (!success) {
       UI.printError(Module.API, "Unable to update \"%s\" - removing", name);
       remove(name);
     } else {
       switch (obj.type) {
         case GEOMETRY:
         case INSTANCE:
           rebuildInstanceList = true;
           break;
         case LIGHT:
           rebuildLightList = true;
           break;
         default:
           break;
       }
     }
   }
   return success;
 }
 private boolean isValidParameter(
     String name, ParameterType type, InterpolationType interp, int requestedSize, Parameter p) {
   if (p == null) return false;
   if (p.type != type) {
     UI.printWarning(
         Module.API,
         "Parameter %s requested as a %s - declared as %s",
         name,
         type.name().toLowerCase(),
         p.type.name().toLowerCase());
     return false;
   }
   if (p.interp != interp) {
     UI.printWarning(
         Module.API,
         "Parameter %s requested as a %s - declared as %s",
         name,
         interp.name().toLowerCase(),
         p.interp.name().toLowerCase());
     return false;
   }
   if (requestedSize > 0 && p.size() != requestedSize) {
     UI.printWarning(
         Module.API,
         "Parameter %s requires %d %s - declared with %d",
         name,
         requestedSize,
         requestedSize == 1 ? "value" : "values",
         p.size());
     return false;
   }
   p.checked = true;
   return true;
 }
Example #4
0
 public boolean update(ParameterList pl, SunflowAPI api) {
   {
     int[] quads = pl.getIntArray("quads");
     if (quads != null) {
       this.quads = quads;
     }
   }
   if (quads == null) {
     UI.printError(Module.GEOM, "Unable to update mesh - quad indices are missing");
     return false;
   }
   if (quads.length % 4 != 0)
     UI.printWarning(
         Module.GEOM, "Quad index data is not a multiple of 4 - some quads may be missing");
   pl.setFaceCount(quads.length / 4);
   {
     FloatParameter pointsP = pl.getPointArray("points");
     if (pointsP != null)
       if (pointsP.interp != InterpolationType.VERTEX)
         UI.printError(
             Module.GEOM,
             "Point interpolation type must be set to \"vertex\" - was \"%s\"",
             pointsP.interp.name().toLowerCase(Locale.ENGLISH));
       else {
         points = pointsP.data;
       }
   }
   if (points == null) {
     UI.printError(Module.GEOM, "Unabled to update mesh - vertices are missing");
     return false;
   }
   pl.setVertexCount(points.length / 3);
   pl.setFaceVertexCount(4 * (quads.length / 4));
   FloatParameter normals = pl.getVectorArray("normals");
   if (normals != null) this.normals = normals;
   FloatParameter uvs = pl.getTexCoordArray("uvs");
   if (uvs != null) this.uvs = uvs;
   int[] faceShaders = pl.getIntArray("faceshaders");
   if (faceShaders != null && faceShaders.length == quads.length / 4) {
     this.faceShaders = new byte[faceShaders.length];
     for (int i = 0; i < faceShaders.length; i++) {
       int v = faceShaders[i];
       if (v > 255) UI.printWarning(Module.GEOM, "Shader index too large on quad %d", i);
       this.faceShaders[i] = (byte) (v & 0xFF);
     }
   }
   return true;
 }
 /**
  * Add the specified matrices as a parameter. <code>null</code> values are not permitted.
  *
  * @param name parameter name
  * @param interp interpolation type
  * @param data parameter value
  */
 public void addMatrices(String name, InterpolationType interp, float[] data) {
   if (data == null || data.length % 16 != 0) {
     UI.printError(Module.API, "Cannot create matrix parameter %s -- invalid data length", name);
     return;
   }
   add(name, new Parameter(ParameterType.MATRIX, interp, data));
 }
 /**
  * Add the specified texture coordinates as a parameter. <code>null</code> values are not
  * permitted.
  *
  * @param name parameter name
  * @param interp interpolation type
  * @param data parameter value
  */
 public void addTexCoords(String name, InterpolationType interp, float[] data) {
   if (data == null || data.length % 2 != 0) {
     UI.printError(Module.API, "Cannot create texcoord parameter %s -- invalid data length", name);
     return;
   }
   add(name, new Parameter(ParameterType.TEXCOORD, interp, data));
 }
 /**
  * Add the specified vectors as a parameter. <code>null</code> values are not permitted.
  *
  * @param name parameter name
  * @param interp interpolation type
  * @param data parameter value
  */
 public void addVectors(String name, InterpolationType interp, float[] data) {
   if (data == null || data.length % 3 != 0) {
     UI.printError(Module.API, "Cannot create vector parameter %s -- invalid data length", name);
     return;
   }
   add(name, new Parameter(ParameterType.VECTOR, interp, data));
 }
 /**
  * Add the specified floats as a parameter. <code>null</code> values are not permitted.
  *
  * @param name parameter name
  * @param interp interpolation type
  * @param data parameter value
  */
 public void addFloats(String name, InterpolationType interp, float[] data) {
   if (data == null) {
     UI.printError(Module.API, "Cannot create float parameter %s -- invalid data length", name);
     return;
   }
   add(name, new Parameter(ParameterType.FLOAT, interp, data));
 }
 /**
  * Clears the list of all its members. If some members were never used, a warning will be printed
  * to remind the user something may be wrong.
  */
 public void clear(boolean showUnused) {
   if (showUnused) {
     for (FastHashMap.Entry<String, Parameter> e : list) {
       if (!e.getValue().checked)
         UI.printWarning(Module.API, "Unused parameter: %s - %s", e.getKey(), e.getValue());
     }
   }
   list.clear();
   numVerts = numFaces = numFaceVerts = 0;
 }
Example #10
0
 final void updateScene(Scene scene) {
   if (rebuildInstanceList) {
     UI.printInfo(Module.API, "Building scene instance list for rendering ...");
     int numInfinite = 0, numInstance = 0;
     for (Map.Entry<String, RenderObjectHandle> e : renderObjects.entrySet()) {
       Instance i = e.getValue().getInstance();
       if (i != null) {
         i.updateBounds();
         if (i.getBounds() == null) numInfinite++;
         else numInstance++;
       }
     }
     Instance[] infinite = new Instance[numInfinite];
     Instance[] instance = new Instance[numInstance];
     numInfinite = numInstance = 0;
     for (Map.Entry<String, RenderObjectHandle> e : renderObjects.entrySet()) {
       Instance i = e.getValue().getInstance();
       if (i != null) {
         if (i.getBounds() == null) {
           infinite[numInfinite] = i;
           numInfinite++;
         } else {
           instance[numInstance] = i;
           numInstance++;
         }
       }
     }
     scene.setInstanceLists(instance, infinite);
     rebuildInstanceList = false;
   }
   if (rebuildLightList) {
     UI.printInfo(Module.API, "Building scene light list for rendering ...");
     ArrayList<LightSource> lightList = new ArrayList<LightSource>();
     for (Map.Entry<String, RenderObjectHandle> e : renderObjects.entrySet()) {
       LightSource light = e.getValue().getLight();
       if (light != null) lightList.add(light);
     }
     scene.setLightList(lightList.toArray(new LightSource[lightList.size()]));
     rebuildLightList = false;
   }
 }
Example #11
0
 static {
   UI.printInfo(Module.QMC, "Initializing Faure scrambling tables ...");
   // build table of first primes
   PRIMES[0] = 2;
   for (int i = 1; i < PRIMES.length; i++) PRIMES[i] = nextPrime(PRIMES[i - 1]);
   int[][] table = new int[PRIMES[PRIMES.length - 1] + 1][];
   table[2] = new int[2];
   table[2][0] = 0;
   table[2][1] = 1;
   for (int i = 3; i <= PRIMES[PRIMES.length - 1]; i++) {
     table[i] = new int[i];
     if ((i & 1) == 0) {
       int[] prev = table[i >> 1];
       for (int j = 0; j < prev.length; j++) table[i][j] = 2 * prev[j];
       for (int j = 0; j < prev.length; j++) table[i][prev.length + j] = 2 * prev[j] + 1;
     } else {
       int[] prev = table[i - 1];
       int med = (i - 1) >> 1;
       for (int j = 0; j < med; j++) table[i][j] = prev[j] + ((prev[j] >= med) ? 1 : 0);
       table[i][med] = med;
       for (int j = 0; j < med; j++)
         table[i][med + j + 1] = prev[j + med] + ((prev[j + med] >= med) ? 1 : 0);
     }
   }
   for (int i = 0; i < PRIMES.length; i++) {
     int p = PRIMES[i];
     SIGMA[i] = new int[p];
     System.arraycopy(table[p], 0, SIGMA[i], 0, p);
   }
   UI.printInfo(Module.QMC, "Initializing lattice tables ...");
   FIBONACCI[0] = 0;
   FIBONACCI[1] = 1;
   for (int i = 2; i < FIBONACCI.length; i++) {
     FIBONACCI[i] = FIBONACCI[i - 1] + FIBONACCI[i - 2];
     FIBONACCI_INV[i] = 1.0 / FIBONACCI[i];
   }
   KOROBOV[0] = 1;
   for (int i = 1; i < KOROBOV.length; i++) KOROBOV[i] = 203 * KOROBOV[i - 1];
 }
Example #12
0
 public static final GIEngine create(Options options) {
   String type = options.getString("gi.engine", null);
   if (type == null || type.equals("null") || type.equals("none")) return null;
   else if (type.equals("ambocc")) return new AmbientOcclusionGIEngine(options);
   else if (type.equals("fake")) return new FakeGIEngine(options);
   else if (type.equals("igi")) return new InstantGI(options);
   else if (type.equals("irr-cache")) return new IrradianceCacheGIEngine(options);
   else if (type.equals("path")) return new PathTracingGIEngine(options);
   else {
     UI.printWarning(Module.LIGHT, "Unrecognized GI engine type \"%s\" - ignoring", type);
     return null;
   }
 }
 private void add(String name, Parameter param) {
   if (name == null) UI.printError(Module.API, "Cannot declare parameter with null name");
   else if (list.put(name, param) != null)
     UI.printWarning(Module.API, "Parameter %s was already defined -- overwriting", name);
 }