Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r2183 - trunk/scenes


Chronological Thread 
  • From: "Solomon Boulos" <boulos@cs.utah.edu>
  • To: manta@sci.utah.edu
  • Subject: [Manta] r2183 - trunk/scenes
  • Date: Sat, 12 Apr 2008 16:57:04 -0600 (MDT)

Author: boulos
Date: Sat Apr 12 16:57:03 2008
New Revision: 2183

Modified:
   trunk/scenes/triangleSceneViewer.cc
Log:
scenes/triangleSceneViewer.cc

 Adding support for both -defaultMatl and -overrideMatl. overrideMatl
 now does what it claims (overrides the materials in the file) as
 Thiago suggested.

 stringToMaterial has been refactored.

 Adding support for AmbientOcclusion as a material (currently the
 cutoff distance and number of rays are hard coded of course). This
 again is a stop gap until real scene description is possible.

 Adding support for setting the lightPosition as well (instead of
 being forced to use the bbox computation). If a lightPosition is not
 set, the bbox computation is used.


Modified: trunk/scenes/triangleSceneViewer.cc
==============================================================================
--- trunk/scenes/triangleSceneViewer.cc (original)
+++ trunk/scenes/triangleSceneViewer.cc Sat Apr 12 16:57:03 2008
@@ -14,6 +14,7 @@
 #include <Model/Groups/KDTree.h>
 #include <Model/Groups/ObjGroup.h>
 #include <Model/Groups/RecursiveGrid.h>
+#include <Model/Materials/AmbientOcclusion.h>
 #include <Model/Materials/Flat.h>
 #include <Model/Materials/Lambertian.h>
 #include <Model/Materials/Phong.h>
@@ -62,17 +63,24 @@
   throw IllegalArgument("scene primtest", i, args);
 }
 
-Mesh* LoadModel(std::string modelName, Material *matl,
+Mesh* LoadModel(std::string modelName, Material* defaultMatl, Material 
*overrideMatl,
                 MeshTriangle::TriangleType triangleType, bool useFaceNormals,
                 bool interpolateNormals ) {
   Mesh* frame = NULL;
   if (!strncmp(modelName.c_str()+modelName.length()-4, ".ply", 4)) {
     frame = new Mesh;
-    if (!readPlyFile(modelName, AffineTransform::createIdentity(), frame, 
matl, triangleType))
+    if (!readPlyFile(modelName, AffineTransform::createIdentity(), frame, 
defaultMatl, triangleType))
       printf("error loading or reading ply file: %s\n", modelName.c_str());
   }
   else if  (!strncmp(modelName.c_str()+modelName.length()-4, ".obj", 4)) {
-    frame = new ObjGroup(modelName.c_str(), matl, triangleType);
+    frame = new ObjGroup(modelName.c_str(), defaultMatl, triangleType);
+  }
+
+  if (overrideMatl) {
+    frame->materials[0] = overrideMatl;
+    for (size_t i = 0; i < frame->face_material.size(); i++) {
+      frame->face_material[i] = 0;
+    }
   }
 
   // NOTE(boulos): This code seems a bit strange, but what it's doing
@@ -91,6 +99,27 @@
   return frame;
 }
 
+Material* stringToMaterial(string matlName) {
+  Material* result = 0;
+  if (matlName == "flat" ||
+      matlName == "eyelight") {
+    result = new Flat(Color::white() * 0.8);
+  } else if (matlName == "lambert" ||
+             matlName == "lambertian" ||
+             matlName == "diffuse") {
+    result = new Lambertian(Color::white() * 0.8);
+  } else if (matlName == "phong") {
+    result = new Phong(Color::white() * 0.8,
+                       Color::white(),
+                       32, 1.f);
+  } else if (matlName == "ambientocclusion") {
+    result = new AmbientOcclusion(Color::white() * 0.8,
+                                  1.f,
+                                  RayPacket::MaxSize);
+  }
+  return result;
+}
+
 MANTA_PLUGINEXPORT
 Scene* make_scene(const ReadContext&, const vector<string>& args)
 {
@@ -103,8 +132,10 @@
   bool smoothAnimation = false;
   float animationLength = 5; //in seconds
   Material* overrideMatl = 0;
+  Material* defaultMatl  = 0;
   bool setModel = false;
-
+  bool setLight = false;
+  Vector lightPosition;
   MeshTriangle::TriangleType triangleType = 
MeshTriangle::KENSLER_SHIRLEY_TRI;
 
   for(size_t i=0;i<args.size();i++){
@@ -155,21 +186,22 @@
         throw IllegalArgument("scene triangleSceneViewer -overrideMatl", i, 
args);
 
       std::transform(matlName.begin(), matlName.end(), matlName.begin(), 
::tolower);
-
-      if (matlName == "flat" ||
-          matlName == "eyelight") {
-        overrideMatl = new Flat(Color::white() * 0.8);
-      } else if (matlName == "lambert" ||
-                 matlName == "lambertian" ||
-                 matlName == "diffuse") {
-        overrideMatl = new Lambertian(Color::white() * 0.8);
-      } else if (matlName == "phong") {
-        overrideMatl = new Phong(Color::white() * 0.8,
-                                 Color::white(),
-                                 32, 1.f);
-      } else {
+      overrideMatl = stringToMaterial(matlName);
+      if (0 == overrideMatl)
         throw IllegalArgument("scene triangleSceneViewer -overrideMatl 
unknown material", i, args);
-      }
+    } else if (arg == "-defaultMatl") {
+      string matlName;
+      if (!getStringArg(i, args, matlName))
+        throw IllegalArgument("scene triangleSceneViewer -defaultMatl", i, 
args);
+
+      std::transform(matlName.begin(), matlName.end(), matlName.begin(), 
::tolower);
+      defaultMatl = stringToMaterial(matlName);
+      if (0 == defaultMatl)
+        throw IllegalArgument("scene triangleSceneViewer -defaultMatl 
unknown material", i, args);
+    } else if (arg == "-lightPosition") {
+      if (!getVectorArg(i, args, lightPosition))
+        throw IllegalArgument("scene triangleSceneViewer -lightPosition", i, 
args);
+      setLight = true;
     } else {
         argumentError(i, args);
     }
@@ -202,7 +234,7 @@
     for (size_t i=0; i < fileNames.size(); ++i) {
       modelName = fileNames[i];
       cout << "loading " << modelName <<endl;
-      Mesh* frame = LoadModel(modelName, overrideMatl, triangleType,
+      Mesh* frame = LoadModel(modelName, defaultMatl, overrideMatl, 
triangleType,
                               useFaceNormals, interpolateNormals);
       animation->push_back(frame);
     }
@@ -212,7 +244,7 @@
   } else {
     // If we're just a single mesh, load it directly instead of using
     // the animation class.
-    Mesh* singleFrame = LoadModel(fileNames[0], overrideMatl, triangleType,
+    Mesh* singleFrame = LoadModel(fileNames[0], defaultMatl, overrideMatl, 
triangleType,
                                   useFaceNormals, interpolateNormals);
     as->setGroup(singleFrame);
     as->rebuild();
@@ -228,10 +260,6 @@
   scene->setObject(group);
 
   LightSet* lights = new LightSet();
-  BBox bbox;
-  PreprocessContext dummyContext;
-  group->computeBounds(dummyContext, bbox);
-  Vector lightOrigin = bbox[1] + bbox.diagonal()*.3;
 #if 0
   Color area_light_color = Color(RGB(1,1,1))*20;
   Real areaLightDim = bbox.diagonal().length()*.30;
@@ -244,7 +272,13 @@
 
   lights->add(new AreaLight(area_light_geometry, area_light_color));
 #else
-  lights->add(new PointLight(lightOrigin, Color(RGB(1,1,1))*1));
+  if (!setLight) {
+    BBox bbox;
+    PreprocessContext dummyContext;
+    group->computeBounds(dummyContext, bbox);
+    lightPosition = bbox[1] + bbox.diagonal()*.3;
+  }
+  lights->add(new PointLight(lightPosition, Color::white()));
 #endif
 
   Color cup(RGB(0.2, 0.2, 0.2));




  • [Manta] r2183 - trunk/scenes, Solomon Boulos, 04/12/2008

Archive powered by MHonArc 2.6.16.

Top of page