Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r1550 - in trunk/Model: Groups Primitives


Chronological Thread 
  • From: boulos@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1550 - in trunk/Model: Groups Primitives
  • Date: Tue, 24 Jul 2007 20:27:16 -0600 (MDT)

Author: boulos
Date: Tue Jul 24 20:27:16 2007
New Revision: 1550

Modified:
   trunk/Model/Groups/Mesh.cc
   trunk/Model/Groups/Mesh.h
   trunk/Model/Primitives/WaldTriangle.cc
Log:
Model/Groups/Mesh.cc
Model/Groups/Mesh.h
Model/Primitives/WaldTriangle.cc

  Adding a sentinel to represent missing texcoords and using it in the
  WaldTriangle class.

  Removing loop invariant Vector& code from inner loop in
  WaldTriangle::computeTexCoords2


Modified: trunk/Model/Groups/Mesh.cc
==============================================================================
--- trunk/Model/Groups/Mesh.cc  (original)
+++ trunk/Model/Groups/Mesh.cc  Tue Jul 24 20:27:16 2007
@@ -4,6 +4,8 @@
 
 using namespace Manta;
 
+const unsigned int Mesh::kNoTextureIndex = static_cast<unsigned int>(-1);
+
 Mesh::Mesh()
 {
 }
@@ -39,18 +41,18 @@
   return copy;
 }
 
-Interpolable::InterpErr 
+Interpolable::InterpErr
 Mesh::serialInterpolate(const std::vector<keyframe_t> &keyframes)
 {
   return parallelInterpolate(keyframes, 0, 1);
 }
 
-Interpolable::InterpErr 
+Interpolable::InterpErr
 Mesh::parallelInterpolate(const std::vector<keyframe_t> &keyframes,
                            int proc, int numProcs)
 {
   InterpErr worstError = success;
-  
+
   Mesh *meshes[keyframes.size()];
   for (unsigned int frame=0; frame < keyframes.size(); ++frame) {
     Mesh *mesh = dynamic_cast<Mesh*>(keyframes[frame].keyframe);
@@ -148,10 +150,10 @@
   WaldTriangle *waldtri = static_cast<WaldTriangle*>(tri);
   waldtri->attachMesh(this, objs.size());
   objs.push_back(waldtri);
-  
+
 }
 
-void Mesh::computeBounds(const PreprocessContext& context, 
+void Mesh::computeBounds(const PreprocessContext& context,
                          int proc, int numProcs) const
 {
   if (proc == 0) {
@@ -171,7 +173,7 @@
   //this barrier enforces that bbox has been initialized before
   //threads start writing to it.
   barrier.wait(numProcs);
-  
+
   mutex.lock();
   this->bbox.extendByBox(myBBox);
   mutex.unlock();
@@ -239,7 +241,7 @@
 
   for (size_t i = 0; i < vertexNormals.size(); ++i) {
     vertexNormals[i] = vertexNormals[i].normal();
-  }    
+  }
 }
 
 

Modified: trunk/Model/Groups/Mesh.h
==============================================================================
--- trunk/Model/Groups/Mesh.h   (original)
+++ trunk/Model/Groups/Mesh.h   Tue Jul 24 20:27:16 2007
@@ -18,6 +18,10 @@
   class Mesh : public Group {
   public:
 
+    // If a triangle has a vertex without texture coordinates, this
+    // will be its index into the texture_indices array.
+    static const unsigned int kNoTextureIndex;
+
     vector<Vector> vertices;
     vector<Vector> vertexNormals;
     vector<Vector> texCoords;
@@ -30,7 +34,7 @@
     //meshes total, so the space savings is minimal and we can just
     //avoid template ugliness.
 
-    // Per vertex data.  size() == 3*numTriangles; 
+    // Per vertex data.  size() == 3*numTriangles;
     vector<unsigned int> vertex_indices;
     vector<unsigned int> normal_indices;
     vector<unsigned int> texture_indices;
@@ -51,7 +55,7 @@
     virtual bool isParallel() const { return true; }
 
     bool hasVertexNormals() const { return !normal_indices.empty(); }
-    void discardVertexNormals() { 
+    void discardVertexNormals() {
       normal_indices.clear();
       vertexNormals.clear();
     }
@@ -70,7 +74,7 @@
     // You can't get access to the actual primitive, because it may not
     // actually exist.  You can get the bounds of it, though.
     BBox getBBox(unsigned int which);

+
     virtual void preprocess(const PreprocessContext& context);
 
     //removes degenerate triangles from mesh.

Modified: trunk/Model/Primitives/WaldTriangle.cc
==============================================================================
--- trunk/Model/Primitives/WaldTriangle.cc      (original)
+++ trunk/Model/Primitives/WaldTriangle.cc      Tue Jul 24 20:27:16 2007
@@ -12,7 +12,7 @@
 {
 }
 
-WaldTriangle::WaldTriangle(Mesh *mesh, unsigned int id) : 
+WaldTriangle::WaldTriangle(Mesh *mesh, unsigned int id) :
   myID(id), mesh(mesh)
 {
   update();
@@ -90,7 +90,7 @@
 }
 
 void WaldTriangle::setPoints(const Vector& _p1, const Vector& _p2, const 
Vector& _p3)
-{ 
+{
     Vector normal = Cross(_p2-_p1, _p3-_p1);
     normal.normalize();
 
@@ -142,7 +142,7 @@
               << "n_v: " << n_v << std::endl
               << "n_d: " << n_d << std::endl
               << "k:   " << k << std::endl
-      
+
               << "b_nu: " << b_nu << std::endl
               << "b_nv: " << b_nv << std::endl
               << "b_d:  " << b_d << std::endl
@@ -151,22 +151,44 @@
               << "c_nu: " << c_nu << std::endl
               << "c_nv: " << c_nv << std::endl
               << "c_d:  " << c_d  << std::endl;
-#endif      
+#endif
 }
 
 
 
 void WaldTriangle::computeTexCoords2(const RenderContext&, RayPacket& rays) 
const
 {
+  const int which = myID*3;
+
+  const unsigned int index0 = mesh->texture_indices[which];
+
+  if (index0 == Mesh::kNoTextureIndex) {
+    // NOTE(boulos): Assume that if the first index is invalid, they
+    // all are.  In this case, set the texture coordinates to be the
+    // barycentric coordinates of the triangle.
+    for(int ray=rays.begin(); ray<rays.end(); ray++) {
+      float a = rays.getScratchpad<float>(SCRATCH_U)[ray];
+      float b = rays.getScratchpad<float>(SCRATCH_V)[ray];
+      float c = (1.0 - a - b);
+
+      rays.setTexCoords(ray, Vector(a, b, c));
+    }
+    rays.setFlag( RayPacket::HaveTexture2|RayPacket::HaveTexture3 );
+    return;
+  }
+
+  const unsigned int index1 = mesh->texture_indices[which+1];
+  const unsigned int index2 = mesh->texture_indices[which+2];
+
+
+  const Vector &tex0 = mesh->texCoords[index0];
+  const Vector &tex1 = mesh->texCoords[index1];
+  const Vector &tex2 = mesh->texCoords[index2];
+
   for(int ray=rays.begin(); ray<rays.end(); ray++) {
     float a = rays.getScratchpad<float>(SCRATCH_U)[ray];
     float b = rays.getScratchpad<float>(SCRATCH_V)[ray];
     float c = (1.0 - a - b);
-
-    const int which = myID*3;
-    const Vector &tex0 = mesh->texCoords[mesh->texture_indices[which]];
-    const Vector &tex1 = mesh->texCoords[mesh->texture_indices[which+1]];
-    const Vector &tex2 = mesh->texCoords[mesh->texture_indices[which+2]];
 
     rays.setTexCoords(ray, (tex1 * a) + (tex2 * b) + (tex0 * c));
   }




  • [MANTA] r1550 - in trunk/Model: Groups Primitives, boulos, 07/24/2007

Archive powered by MHonArc 2.6.16.

Top of page