[Bf-blender-cvs] [a73dc3a] opensubdiv-modifier: OpenSubdiv: Quick implementation of DerivedMesh converter

Sergey Sharybin noreply at git.blender.org
Sat Jul 11 20:01:48 CEST 2015


Commit: a73dc3ad9f34f519cd601b992ccce14668305e2d
Author: Sergey Sharybin
Date:   Wed Jul 8 16:28:22 2015 +0200
Branches: opensubdiv-modifier
https://developer.blender.org/rBa73dc3ad9f34f519cd601b992ccce14668305e2d

OpenSubdiv: Quick implementation of DerivedMesh converter

Currently uses some bad level calls and hackish storage of original
DerivedMesh in the SubSurf structure which we'll get rid of rather
soon.

It leaks and such, but moves us towards ultimate integration.

===================================================================

M	intern/opensubdiv/CMakeLists.txt
M	intern/opensubdiv/opensubdiv_capi.cc
M	intern/opensubdiv/opensubdiv_capi.h
A	intern/opensubdiv/opensubdiv_converter.cc
A	intern/opensubdiv/opensubdiv_converter.h
M	source/blender/blenkernel/BKE_subsurf.h
M	source/blender/blenkernel/intern/CCGSubSurf.c
M	source/blender/blenkernel/intern/CCGSubSurf.h
M	source/blender/blenkernel/intern/subsurf_ccg.c

===================================================================

diff --git a/intern/opensubdiv/CMakeLists.txt b/intern/opensubdiv/CMakeLists.txt
index ec0dc8e..40236db 100644
--- a/intern/opensubdiv/CMakeLists.txt
+++ b/intern/opensubdiv/CMakeLists.txt
@@ -26,6 +26,9 @@
 set(INC
 	.
 	../guardedalloc
+	../../source/blender/blenlib
+	../../source/blender/blenkernel
+	../../source/blender/makesdna
 )
 
 set(INC_SYS
@@ -36,12 +39,14 @@ set(INC_SYS
 
 set(SRC
 	opensubdiv_capi.cc
+	opensubdiv_converter.cc
 	opensubdiv_device_context_cuda.cc
 	opensubdiv_device_context_opencl.cc
 	opensubdiv_gpu_capi.cc
 	opensubdiv_utils_capi.cc
 
 	opensubdiv_capi.h
+	opensubdiv_converter.h
 	opensubdiv_device_context_cuda.h
 	opensubdiv_device_context_opencl.h
 	opensubdiv_partitioned.h
diff --git a/intern/opensubdiv/opensubdiv_capi.cc b/intern/opensubdiv/opensubdiv_capi.cc
index 88b271a..c4f9d73 100644
--- a/intern/opensubdiv/opensubdiv_capi.cc
+++ b/intern/opensubdiv/opensubdiv_capi.cc
@@ -68,6 +68,7 @@
 #include <opensubdiv/osd/glPatchTable.h>
 #include <opensubdiv/far/stencilTable.h>
 
+#include "opensubdiv_converter.h"
 #include "opensubdiv_partitioned.h"
 
 #include "MEM_guardedalloc.h"
@@ -260,282 +261,9 @@ const float *openSubdiv_evaluatorGetFloatTagArgs(
 #endif
 }
 
-static int g_nverts = 5,
-           g_nedges = 8,
-           g_nfaces = 5;
-
-// vertex positions
-static float g_verts[5][3] = {{ 0.0f,  0.0f,  2.0f},
-                              { 0.0f, -2.0f,  0.0f},
-                              { 2.0f,  0.0f,  0.0f},
-                              { 0.0f,  2.0f,  0.0f},
-                              {-2.0f,  0.0f,  0.0f}};
-
-// number of vertices in each face
-static int g_facenverts[5] = { 3, 3, 3, 3, 4 };
-
-// index of face vertices
-static int g_faceverts[16] = { 0, 1, 2,
-                               0, 2, 3,
-                               0, 3, 4,
-                               0, 4, 1,
-                               4, 3, 2, 1 };
-
-// index of edge vertices (2 per edge)
-static int g_edgeverts[16] = { 0, 1,
-                               1, 2,
-                               2, 0,
-                               2, 3,
-                               3, 0,
-                               3, 4,
-                               4, 0,
-                               4, 1 };
-
-
-// index of face edges
-static int g_faceedges[16] = { 0, 1, 2,
-                               2, 3, 4,
-                               4, 5, 6,
-                               6, 7, 0,
-                               5, 3, 1, 7 };
-
-// number of faces adjacent to each edge
-static int g_edgenfaces[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
-
-// index of faces incident to a given edge
-static int g_edgefaces[16] = { 0, 3,
-                               0, 4,
-                               0, 1,
-                               1, 4,
-                               1, 2,
-                               2, 4,
-                               2, 3,
-                               3, 4 };
-
-// number of faces incident to each vertex
-static int g_vertexnfaces[5] = { 4, 3, 3, 3, 3 };
-
-// index of faces incident to each vertex
-static int g_vertexfaces[25] = { 0, 1, 2, 3,
-                                 0, 3, 4,
-                                 0, 4, 1,
-                                 1, 4, 2,
-                                 2, 4, 3 };
-
-
-// number of edges incident to each vertex
-static int g_vertexnedges[5] = { 4, 3, 3, 3, 3 };
-
-// index of edges incident to each vertex
-static int g_vertexedges[25] = { 0, 2, 4, 6,
-                                 1, 0, 7,
-                                 2, 1, 3,
-                                 4, 3, 5,
-                                 6, 5, 7 };
-
-// Edge crease sharpness
-static float g_edgeCreases[8] = { 0.0f,
-                                  2.5f,
-                                  0.0f,
-                                  2.5f,
-                                  0.0f,
-                                  2.5f,
-                                  0.0f,
-                                  2.5f };
-
-struct Converter {
-
-public:
-
-	OpenSubdiv::Sdc::SchemeType GetType() const {
-        return OpenSubdiv::Sdc::SCHEME_CATMARK;
-    }
-
-    OpenSubdiv::Sdc::Options GetOptions() const {
-        OpenSubdiv::Sdc::Options options;
-        options.SetVtxBoundaryInterpolation(OpenSubdiv::Sdc::Options::VTX_BOUNDARY_EDGE_ONLY);
-        return options;
-    }
-
-    int GetNumFaces() const { return g_nfaces; }
-
-    int GetNumEdges() const { return g_nedges; }
-
-    int GetNumVertices() const { return g_nverts; }
-
-    //
-    // Face relationships
-    //
-    int GetNumFaceVerts(int face) const { return g_facenverts[face]; }
-
-    int const * GetFaceVerts(int face) const { return g_faceverts+getCompOffset(g_facenverts, face); }
-
-    int const * GetFaceEdges(int edge) const { return g_faceedges+getCompOffset(g_facenverts, edge); }
-
-
-    //
-    // Edge relationships
-    //
-    int const * GetEdgeVertices(int edge) const { return g_edgeverts+edge*2; }
-
-    int GetNumEdgeFaces(int edge) const { return g_edgenfaces[edge]; }
-
-    int const * GetEdgeFaces(int edge) const { return g_edgefaces+getCompOffset(g_edgenfaces, edge); }
-
-    //
-    // Vertex relationships
-    //
-    int GetNumVertexEdges(int vert) const { return g_vertexnedges[vert]; }
-
-    int const * GetVertexEdges(int vert) const { return g_vertexedges+getCompOffset(g_vertexnedges, vert); }
-
-    int GetNumVertexFaces(int vert) const { return g_vertexnfaces[vert]; }
-
-    int const * GetVertexFaces(int vert) const { return g_vertexfaces+getCompOffset(g_vertexnfaces, vert); }
-
-private:
-
-    int getCompOffset(int const * comps, int comp) const {
-        int ofs=0;
-        for (int i=0; i<comp; ++i) {
-            ofs += comps[i];
-        }
-        return ofs;
-    }
-
-};
-
-namespace OpenSubdiv {
-namespace OPENSUBDIV_VERSION {
-
-namespace Far {
-
-template <>
-bool
-TopologyRefinerFactory<Converter>::resizeComponentTopology(
-    TopologyRefiner & refiner, Converter const & conv) {
-
-    // Faces and face-verts
-    int nfaces = conv.GetNumFaces();
-    setNumBaseFaces(refiner, nfaces);
-    for (int face=0; face<nfaces; ++face) {
-
-        int nv = conv.GetNumFaceVerts(face);
-        setNumBaseFaceVertices(refiner, face, nv);
-    }
-
-   // Edges and edge-faces
-    int nedges = conv.GetNumEdges();
-    setNumBaseEdges(refiner, nedges);
-    for (int edge=0; edge<nedges; ++edge) {
-
-        int nf = conv.GetNumEdgeFaces(edge);
-        setNumBaseEdgeFaces(refiner, edge, nf);
-    }
-
-    // Vertices and vert-faces and vert-edges
-    int nverts = conv.GetNumVertices();
-    setNumBaseVertices(refiner, nverts);
-    for (int vert=0; vert<nverts; ++vert) {
-
-        int ne = conv.GetNumVertexEdges(vert),
-            nf = conv.GetNumVertexFaces(vert);
-        setNumBaseVertexEdges(refiner, vert, ne);
-        setNumBaseVertexFaces(refiner, vert, nf);
-    }
-    return true;
-}
-
-template <>
-bool
-TopologyRefinerFactory<Converter>::assignComponentTopology(
-    TopologyRefiner & refiner, Converter const & conv) {
-
-    typedef Far::IndexArray      IndexArray;
-
-    { // Face relations:
-        int nfaces = conv.GetNumFaces();
-        for (int face=0; face<nfaces; ++face) {
-
-            IndexArray dstFaceVerts = getBaseFaceVertices(refiner, face);
-            IndexArray dstFaceEdges = getBaseFaceEdges(refiner, face);
-
-            int const * faceverts = conv.GetFaceVerts(face);
-            int const * faceedges = conv.GetFaceEdges(face);
-
-            for (int vert=0; vert<conv.GetNumFaceVerts(face); ++vert) {
-                dstFaceVerts[vert] = faceverts[vert];
-                dstFaceEdges[vert] = faceedges[vert];
-            }
-        }
-    }
-
-    { // Edge relations
-      //
-      // Note: if your representation is unable to provide edge relationships
-      //       (ex: half-edges), you can comment out this section and Far will
-      //       automatically generate the missing information.
-      //
-        int nedges = conv.GetNumEdges();
-        for (int edge=0; edge<nedges; ++edge) {
-
-            //  Edge-vertices:
-            IndexArray dstEdgeVerts = getBaseEdgeVertices(refiner, edge);
-            dstEdgeVerts[0] = conv.GetEdgeVertices(edge)[0];
-            dstEdgeVerts[1] = conv.GetEdgeVertices(edge)[1];
-
-            //  Edge-faces
-            IndexArray dstEdgeFaces = getBaseEdgeFaces(refiner, edge);
-            for (int face=0; face<conv.GetNumEdgeFaces(face); ++face) {
-                dstEdgeFaces[face] = conv.GetEdgeFaces(edge)[face];
-            }
-        }
-    }
-
-    { // Vertex relations
-        int nverts = conv.GetNumVertices();
-        for (int vert=0; vert<nverts; ++vert) {
-
-            //  Vert-Faces:
-            IndexArray vertFaces = getBaseVertexFaces(refiner, vert);
-            //LocalIndexArray vertInFaceIndices = getBaseVertexFaceLocalIndices(refiner, vert);
-            for (int face=0; face<conv.GetNumVertexFaces(vert); ++face) {
-                vertFaces[face] = conv.GetVertexFaces(vert)[face];
-            }
-
-            //  Vert-Edges:
-            IndexArray vertEdges = getBaseVertexEdges(refiner, vert);
-            //LocalIndexArray vertInEdgeIndices = getBaseVertexEdgeLocalIndices(refiner, vert);
-            for (int edge=0; edge<conv.GetNumVertexEdges(vert); ++edge) {
-                vertEdges[edge] = conv.GetVertexEdges(vert)[edge];
-            }
-        }
-    }
-
-    populateBaseLocalIndices(refiner);
-
-    return true;
-};
-
-template <>
-bool
-TopologyRefinerFactory<Converter>::assignComponentTags(
-    TopologyRefiner & refiner, Converter const & conv) {
-
-    // arbitrarily sharpen the 4 bottom edges of the pyramid to 2.5f
-    for (int edge=0; edge<conv.GetNumEdges(); ++edge) {
-        setBaseEdgeSharpness(refiner, edge, g_edgeCreases[edge]);
-    }
-    return true;
-}
-
-} // namespace Far
-
-} // namespace OPENSUBDIV_VERSION
-} // namespace OpenSubdiv
-
 struct OpenSubdiv_GLMesh *openSubdiv_createOsdGLMeshFromEvaluator(
-        OpenSubdiv_EvaluatorDescr * /*evaluator_descr*/,
+        //OpenSubdiv_EvaluatorDescr * /*evaluator_descr*/,
+        DerivedMesh *dm,
         int evaluator_t

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list