Manta Interactive Ray Tracer Development Mailing List

Text archives Help


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


Chronological Thread 
  • From: bigler@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r1433 - in trunk/Model: Groups Primitives
  • Date: Wed, 27 Jun 2007 21:37:33 -0600 (MDT)

Author: bigler
Date: Wed Jun 27 21:37:33 2007
New Revision: 1433

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

Groups/Mesh.h

  Start of a mesh class.

Primitives/BumpPrimitive.cc

  Fix GCC warnings by reordering contructor's initializations.


Added: trunk/Model/Groups/Mesh.h
==============================================================================
--- (empty file)
+++ trunk/Model/Groups/Mesh.h   Wed Jun 27 21:37:33 2007
@@ -0,0 +1,128 @@
+
+
+// IndexT is a template type, because you may not need the precision
+// of a whole int to store the geometry.
+//
+// MatIndexT is a template type, because you often don't have more
+// than 256 materials per mesh.
+template<class IndexT, class MatIndexT>
+class Mesh: public Primitive {
+  // This will allow you to get access to the index type.
+  typedef IndexT IndexType;
+
+  // All the elements with index >= numeric_limits<IndexT>::max() will
+  // be unable to be index.
+  vector<Vector> vertices;
+  vector<Vector> vertexNormals;
+  vector<Vector> texCoords;
+  vector<Vector> faceNormals;
+  vector<Material*> materials;
+
+  // I was tempted to make numTriangles of type IndexT, but then I
+  // realized that you may have many more triangles than vertices, by
+  // use of clever combinations of the existing vertex set.
+  size_t numTriangles;
+
+  // Per vertex data.  size() == 3*numTriangles;
+  vector<IndexT> vertex_indices;
+  vector<IndexT> normal_indices;
+  vector<IndexT> texture_indices;
+
+  // Per face data.  size() == numTriangles;
+  vector<IndexT> face_normals;
+  vector<MatIndexT> face_material;
+
+  // Should we support having both face_normals and vertex_normals?
+
+  //////////////////////////////
+  // This is what would be stuffed into the scratchpad if there was a
+  // hit.
+
+  struct ScratchPadInfo {
+    Real u, v;
+    IndexT which;
+  };
+
+  //////////////////////////////////////////////////////////////
+  // Here's the primitive interface
+
+  // 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(IndexT which);
+
+  // Computes the hit location.  It doesn't register the hit.  Call
+  // registerHit later.
+  Real intersect(const RenderContext& context, const RayPacket& rays,
+                 int which_ray, IndexT which_tri, ScratchPadInfo& info);
+#ifdef MANTA_SSE
+  // SSE version
+  __m128 intersectSSE(const RenderContext& context, const RayPacket& rays,
+                      IndexT which);
+#endif
+
+  void registerHit(RayPacket& rays, int which_ray, ScratchPadInfo& info);
+#ifdef MANTA_SSE
+  void registerHitSSE(RayPacket& rays, int which, __m128i hitMask);
+#endif
+  
+
+  // These functions shouldn't be called, as it doesn't make sense to
+  // perform these operations on the whole mesh.
+  virtual void intersect(const RenderContext& context,
+                         RayPacket& rays) const;
+
+  
+  virtual void preprocess(const PreprocessContext& context);
+  virtual void setTexCoordMapper(const TexCoordMapper* new_tex);
+  virtual void computeBounds(const PreprocessContext& context, BBox& bbox) 
const = 0;
+
+  // This is after intersection, and we need to be able to act the
+  // part of a general primitive.  The primitive index must be stored
+  // in the scratchpad.
+  virtual void computeNormal(const RenderContext& context,
+                             RayPacket& rays) const;
+  
+};
+
+template<class IndexT, class MatIndexT>
+BBox Mesh::getBBox(IndexT which)
+{
+  IndexT index = which*3;
+  Vertex p1 = vertex_indices[index];
+  BBox bbox(p1, p1);
+  bbox.extendByPoint(vertex_indices[index+1]);
+  bbox.extendByPoint(vertex_indices[index+2]);
+}
+
+// Computes the hit location.  It doesn't register the hit.  Call
+// registerHit later.
+template<class IndexT, class MatIndexT>
+Real Mesh::intersect(const RenderContext& context, const RayPacket& rays,
+                     int which_ray, IndexT which_tri, ScratchPadInfo& info)
+{
+  IndexT index = which*3;
+
+  Real t = numeric_limits<Real>::max();
+
+  Vector edge1 = vertices[index+1] - vertices[index];
+  Vector edge2 = vertices[index+2] - vertices[index];
+  if (Intersection::intersectTriangleEdge( t, info.u, info.v,
+                                           rays.getRay(which_ray),
+                                           edge1, edge2, vertices[index] ))
+    {
+      info.which = which;
+    }
+  return t;
+}
+
+
+template<class IndexT, class MatIndexT>
+void Mesh::registerHit(RayPacket& rays, int which_ray,
+                       Real t, ScratchPadInfo& info)
+{
+  if (rays.hit(which_ray, t, material, prim, tex)) {
+    rays.scratchpad<ScratchPadInfo>(which_ray) = info;
+  }
+}
+
+

Modified: trunk/Model/Primitives/BumpPrimitive.cc
==============================================================================
--- trunk/Model/Primitives/BumpPrimitive.cc     (original)
+++ trunk/Model/Primitives/BumpPrimitive.cc     Wed Jun 27 21:37:33 2007
@@ -16,7 +16,13 @@
 }
 
 BumpPrimitive::BumpPrimitive(PrimitiveCommon* obj_, Material* mat, Real 
const k1_, Real const k2_, int const octaves_, Real const lacunarity_, Real 
const gain_ )
-  : bumpobject(obj_), PrimitiveCommon(mat), k1(k1_), k2(k2_), octaves( 
octaves_ ), lacunarity( lacunarity_ ), gain( gain_ )
+  : PrimitiveCommon(mat),
+    bumpobject(obj_),
+    k1(k1_),
+    k2(k2_),
+    octaves( octaves_ ),
+    lacunarity( lacunarity_ ),
+    gain( gain_ )
 {
   
 }




  • [MANTA] r1433 - in trunk/Model: Groups Primitives, bigler, 06/27/2007

Archive powered by MHonArc 2.6.16.

Top of page