Commits

Daniel K. O.  committed e2a1e72

build fix for trimesh with double precision

  • Participants
  • Parent commits 67ea101

Comments (0)

Files changed (3)

File include/kode/collision/Trimesh.hpp

             Data();
             Data(const float* verts, unsigned nVerts,
                  const TriIndex* indices, unsigned triCount);
+            Data(const double* verts, unsigned nVerts,
+                 const TriIndex* indices, unsigned triCount);
             ~Data() noexcept;
 
             Data(Data&&) noexcept = default;
             void build(const float* verts, unsigned nVerts,
                        const TriIndex* indices, unsigned triCount);
 
+            void build(const double* verts, unsigned nVerts,
+                       const TriIndex* indices, unsigned triCount);
+
 
             void preprocess();
 

File src/collision/Trimesh.cpp

     {
         vertices.resize(vertexCount);
         for (size_t i=0; i<vertexCount; ++i)
-            vertices[i] = Vector3(pvertices + i*3);
+            vertices[i] = Vector3(pvertices[i*3+0],
+                                  pvertices[i*3+1],
+                                  pvertices[i*3+2]);
+
+        indices.resize(triCount*3);
+        for (size_t i=0; i<triCount*3; ++i)
+            indices[i] = pindices[i];
+
+        Mesh.SetNbTriangles(triCount);
+        Mesh.SetNbVertices(vertexCount);
+        Mesh.SetPointers(reinterpret_cast<const IndexedTriangle*>(&indices[0]),
+                         reinterpret_cast<const Point*>(&vertices[0]));
+        //Mesh.SetStrides(triStride, vertexStride);
+        Mesh.SetStrides(3*sizeof(indices[0]), sizeof(vertices[0]));
+        Mesh.SetSingle(sizeof(Real) == sizeof(float));
+
+        // Build tree
+        opc::BuildSettings Settings;
+        // recommended in Opcode User Manual
+        //Settings.mRules = SPLIT_COMPLETE | SPLIT_SPLATTERPOINTS | SPLIT_GEOMCENTER;
+        // used in ODE, why?
+        //Settings.mRules = SPLIT_BEST_AXIS;
+
+        // best compromise?
+        Settings.mRules = opc::SPLIT_BEST_AXIS | opc::SPLIT_SPLATTER_POINTS | opc::SPLIT_GEOM_CENTER;
+
+
+        opc::OPCODECREATE TreeBuilder;
+        TreeBuilder.mIMesh = &Mesh;
+
+        TreeBuilder.mSettings = Settings;
+        TreeBuilder.mNoLeaf = true;
+        TreeBuilder.mQuantized = false;
+
+        TreeBuilder.mKeepOriginal = false;
+        TreeBuilder.mCanRemap = false;
+
+
+
+        BVTree.Build(TreeBuilder);
+
+        // compute model space AABB
+        aabb.clear();
+        for(const Vector3& v : vertices)
+            aabb.merge(v);
+    }
+
+
+    /// hack: overload for double precision source
+    void
+    Trimesh::Data::Impl::build(const double* pvertices, unsigned vertexCount,
+                               const kode::TriIndex* pindices, unsigned triCount)
+    {
+        vertices.resize(vertexCount);
+        for (size_t i=0; i<vertexCount; ++i)
+            vertices[i] = Vector3(pvertices[i*3+0],
+                                  pvertices[i*3+1],
+                                  pvertices[i*3+2]);
 
         indices.resize(triCount*3);
         for (size_t i=0; i<triCount*3; ++i)
         build(verts, nVerts, indices, triCount);
     }
 
+    Trimesh::Data::Data(const double* verts, unsigned nVerts,
+                        const TriIndex* indices, unsigned triCount) :
+        Data()
+    {
+        build(verts, nVerts, indices, triCount);
+    }
 
     Trimesh::Data::~Data()
     {}
         pimpl->build(verts, nVerts, indices, triCount);
     }
 
+    void
+    Trimesh::Data::build(const double* verts, unsigned nVerts,
+                         const TriIndex* indices, unsigned triCount)
+    {
+        pimpl->build(verts, nVerts, indices, triCount);
+    }
 
     void
     Trimesh::Data::preprocess()

File src/collision/TrimeshInternal.hpp

         void build(const float* vertices, unsigned vertexCount,
                    const TriIndex* indices, unsigned triCount);
 
+        void build(const double* vertices, unsigned vertexCount,
+                   const TriIndex* indices, unsigned triCount);
+
         void preprocess();