Commit: 004ab8859ef17abad0bc0dc5636dbf01276bdc7c
Author: Mai Lavelle
Date:   Sat Jun 25 07:57:22 2016 -0400
Branches: temp-cycles-microdisplacement
https://developer.blender.org/rB004ab8859ef17abad0bc0dc5636dbf01276bdc7c

Move Mesh::tessellate to mesh_subdivision.cpp

Adding OpenSubdiv support will require a lot of code, to keep things organized
subdivision related things are being moved to their own file.

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

M       intern/cycles/render/CMakeLists.txt
M       intern/cycles/render/mesh.cpp
A       intern/cycles/render/mesh_subdivision.cpp

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

diff --git a/intern/cycles/render/CMakeLists.txt 
b/intern/cycles/render/CMakeLists.txt
index b14da3e..2317026 100644
--- a/intern/cycles/render/CMakeLists.txt
+++ b/intern/cycles/render/CMakeLists.txt
@@ -29,6 +29,7 @@ set(SRC
        light.cpp
        mesh.cpp
        mesh_displace.cpp
+       mesh_subdivision.cpp
        nodes.cpp
        object.cpp
        osl.cpp
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 699b466..074e887 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -35,9 +35,6 @@
 #include "util_progress.h"
 #include "util_set.h"
 
-#include "subd_split.h"
-#include "subd_patch.h"
-
 CCL_NAMESPACE_BEGIN
 
 /* Triangle */
@@ -1700,175 +1697,5 @@ bool Mesh::need_attribute(Scene * /*scene*/, ustring 
name)
        return false;
 }
 
-void Mesh::tessellate(DiagSplit *split)
-{
-       int num_faces = subd_faces.size();
-
-       Attribute *attr_vN = subd_attributes.find(ATTR_STD_VERTEX_NORMAL);
-       float3* vN = attr_vN->data_float3();
-
-       for(int f = 0; f < num_faces; f++) {
-               SubdFace& face = subd_faces[f];
-
-               if(face.is_quad()) {
-                       /* quad */
-                       LinearQuadPatch patch;
-                       float3 *hull = patch.hull;
-                       float3 *normals = patch.normals;
-
-                       patch.patch_index = face.ptex_offset;
-
-                       for(int i = 0; i < 4; i++) {
-                               hull[i] = 
verts[subd_face_corners[face.start_corner+i]];
-                       }
-
-                       if(face.smooth) {
-                               for(int i = 0; i < 4; i++) {
-                                       normals[i] = 
vN[subd_face_corners[face.start_corner+i]];
-                               }
-                       }
-                       else {
-                               float3 N = face.normal(this);
-                               for(int i = 0; i < 4; i++) {
-                                       normals[i] = N;
-                               }
-                       }
-
-                       swap(hull[2], hull[3]);
-                       swap(normals[2], normals[3]);
-
-                       /* Quad faces need to be split at least once to line up 
with split ngons, we do this
-                        * here in this manner because if we do it later edge 
factors may end up slightly off.
-                        */
-                       QuadDice::SubPatch subpatch;
-                       subpatch.patch = &patch;
-
-                       subpatch.P00 = make_float2(0.0f, 0.0f);
-                       subpatch.P10 = make_float2(0.5f, 0.0f);
-                       subpatch.P01 = make_float2(0.0f, 0.5f);
-                       subpatch.P11 = make_float2(0.5f, 0.5f);
-                       split->split_quad(&patch, &subpatch);
-
-                       subpatch.P00 = make_float2(0.5f, 0.0f);
-                       subpatch.P10 = make_float2(1.0f, 0.0f);
-                       subpatch.P01 = make_float2(0.5f, 0.5f);
-                       subpatch.P11 = make_float2(1.0f, 0.5f);
-                       split->split_quad(&patch, &subpatch);
-
-                       subpatch.P00 = make_float2(0.0f, 0.5f);
-                       subpatch.P10 = make_float2(0.5f, 0.5f);
-                       subpatch.P01 = make_float2(0.0f, 1.0f);
-                       subpatch.P11 = make_float2(0.5f, 1.0f);
-                       split->split_quad(&patch, &subpatch);
-
-                       subpatch.P00 = make_float2(0.5f, 0.5f);
-                       subpatch.P10 = make_float2(1.0f, 0.5f);
-                       subpatch.P01 = make_float2(0.5f, 1.0f);
-                       subpatch.P11 = make_float2(1.0f, 1.0f);
-                       split->split_quad(&patch, &subpatch);
-               }
-               else {
-                       /* ngon */
-                       float3 center_vert = make_float3(0.0f, 0.0f, 0.0f);
-                       float3 center_normal = make_float3(0.0f, 0.0f, 0.0f);
-
-                       float inv_num_corners = 1.0f/float(face.num_corners);
-                       for(int corner = 0; corner < face.num_corners; 
corner++) {
-                               center_vert += 
verts[subd_face_corners[face.start_corner + corner]] * inv_num_corners;
-                               center_normal += 
vN[subd_face_corners[face.start_corner + corner]] * inv_num_corners;
-                       }
-
-                       for(int corner = 0; corner < face.num_corners; 
corner++) {
-                               LinearQuadPatch patch;
-                               float3 *hull = patch.hull;
-                               float3 *normals = patch.normals;
-
-                               patch.patch_index = face.ptex_offset + corner;
-
-                               hull[0] = 
verts[subd_face_corners[face.start_corner + mod(corner + 0, face.num_corners)]];
-                               hull[1] = 
verts[subd_face_corners[face.start_corner + mod(corner + 1, face.num_corners)]];
-                               hull[2] = 
verts[subd_face_corners[face.start_corner + mod(corner - 1, face.num_corners)]];
-                               hull[3] = center_vert;
-
-                               hull[1] = (hull[1] + hull[0]) * 0.5;
-                               hull[2] = (hull[2] + hull[0]) * 0.5;
-
-                               if(face.smooth) {
-                                       normals[0] = 
vN[subd_face_corners[face.start_corner + mod(corner + 0, face.num_corners)]];
-                                       normals[1] = 
vN[subd_face_corners[face.start_corner + mod(corner + 1, face.num_corners)]];
-                                       normals[2] = 
vN[subd_face_corners[face.start_corner + mod(corner - 1, face.num_corners)]];
-                                       normals[3] = center_normal;
-
-                                       normals[1] = (normals[1] + normals[0]) 
* 0.5;
-                                       normals[2] = (normals[2] + normals[0]) 
* 0.5;
-                               }
-                               else {
-                                       float3 N = face.normal(this);
-                                       for(int i = 0; i < 4; i++) {
-                                               normals[i] = N;
-                                       }
-                               }
-
-                               split->split_quad(&patch);
-                       }
-               }
-       }
-
-       /* interpolate center points for attributes */
-       foreach(Attribute& attr, subd_attributes.attributes) {
-               char* data = attr.data();
-               size_t stride = attr.data_sizeof();
-               int ngons = 0;
-
-               switch(attr.element) {
-                       case ATTR_ELEMENT_VERTEX: {
-                               for(int f = 0; f < num_faces; f++) {
-                                       SubdFace& face = subd_faces[f];
-
-                                       if(!face.is_quad()) {
-                                               char* center = data + 
(verts.size() - num_subd_verts + ngons) * stride;
-                                               attr.zero_data(center);
-
-                                               float inv_num_corners = 1.0f / 
float(face.num_corners);
-
-                                               for(int corner = 0; corner < 
face.num_corners; corner++) {
-                                                       
attr.add_with_weight(center,
-                                                                            
data + subd_face_corners[face.start_corner + corner] * stride,
-                                                                            
inv_num_corners);
-                                               }
-
-                                               ngons++;
-                                       }
-                               }
-                       } break;
-                       case ATTR_ELEMENT_VERTEX_MOTION: {
-                               // TODO(mai): implement
-                       } break;
-                       case ATTR_ELEMENT_CORNER:
-                       case ATTR_ELEMENT_CORNER_BYTE: {
-                               for(int f = 0; f < num_faces; f++) {
-                                       SubdFace& face = subd_faces[f];
-
-                                       if(!face.is_quad()) {
-                                               char* center = data + 
(subd_face_corners.size() + ngons) * stride;
-                                               attr.zero_data(center);
-
-                                               float inv_num_corners = 1.0f / 
float(face.num_corners);
-
-                                               for(int corner = 0; corner < 
face.num_corners; corner++) {
-                                                       
attr.add_with_weight(center,
-                                                                            
data + (face.start_corner + corner) * stride,
-                                                                            
inv_num_corners);
-                                               }
-
-                                               ngons++;
-                                       }
-                               }
-                       } break;
-                       default: break;
-               }
-       }
-}
-
 CCL_NAMESPACE_END
 
diff --git a/intern/cycles/render/mesh_subdivision.cpp 
b/intern/cycles/render/mesh_subdivision.cpp
new file mode 100644
index 0000000..43c36c7
--- /dev/null
+++ b/intern/cycles/render/mesh_subdivision.cpp
@@ -0,0 +1,198 @@
+/*
+ * Copyright 2011-2016 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "mesh.h"
+#include "attribute.h"
+
+#include "subd_split.h"
+#include "subd_patch.h"
+
+#include "util_foreach.h"
+
+CCL_NAMESPACE_BEGIN
+
+void Mesh::tessellate(DiagSplit *split)
+{
+       int num_faces = subd_faces.size();
+
+       Attribute *attr_vN = subd_attributes.find(ATTR_STD_VERTEX_NORMAL);
+       float3* vN = attr_vN->data_float3();
+
+       for(int f = 0; f < num_faces; f++) {
+               SubdFace& face = subd_faces[f];
+
+               if(face.is_quad()) {
+                       /* quad */
+                       LinearQuadPatch patch;
+                       float3 *hull = patch.hull;
+                       float3 *normals = patch.normals;
+
+                       patch.patch_index = face.ptex_offset;
+
+                       for(int i = 0; i < 4; i++) {
+                               hull[i] = 
verts[subd_face_corners[face.start_corner+i]];
+                       }
+
+                       if(face.smooth) {
+                               for(int i = 0; i < 4; i++) {
+                                       normals[i] = 
vN[subd_face_corners[face.start_corner+i]];
+                               }
+                       }
+                       else {
+                               float3 N = face.normal(this);
+                               for(int i = 0; i < 4; i++) {
+                                       normals[i] = N;
+                               }
+                       }
+
+                       swap(hull[2], hull[3]);
+                       swap(normals[2], normals[3]);
+
+                       /* Quad faces need to be split at least once to line up 
with split ngons, we do this
+                        * here in this manner because if we do it later edge 
factors may end up slightly off.
+                        */
+                       QuadDice::SubPatch subpatch;
+                       subpatch.patch = &patch;
+
+                       subpatch.P00 = make_float2(0.0f, 0.0f);
+                       subpatch.P10 = make_float2(0.5f, 0.0f);
+                       subpatch.P01 = make_float2(0.0f, 0.5f);
+                       subpatch.P11 = make_float2(0.5f, 0.5f);
+                       split->split_quad(&patch, &subpatch);
+
+                       subpatch.P00 = make_float2(0.5f, 0.0f);
+                       subpatch.P10 = make_float2(1.0f, 0.0f);
+                       subpatch.P01 = make_float2(0.5f, 0.5f);
+                       subpatch.P11 = make_float2(1.0f, 0.5f);
+                       split->split_quad(&patch, &subpatch);
+
+                       subpatch.P00 = make_float2(0.0f, 0.5f);
+                       subpatch.P10 = make_float2(0.5f, 0.5f);
+                       subpatch.P01 = make_float2(0.0f, 1.0f);
+                       subpatch.P11 = make_float2(0.5f, 1.0f);
+                       split->split_quad(&patch, &subpatch);
+
+                       subpatch.P00 = make_float2(0.5f, 0.5f);
+                       subpatch.P10 = make_float2(1.0f, 0.5f);
+                       subpatch.P01 = make_float2(0.5f, 1.0f);
+                       subpatch.P11 = make_float2(1.0f, 1.0f);
+                       split->split_quad(&patch, &subpatch);
+               }
+               else {
+                       /* ngon */
+                       float3 center_vert = make_float3(0.0f, 0.0f, 0.0f);
+                       float3 center_normal = make_float3(0.0f, 0.0f, 0.0f);
+
+                       float inv_num_corners = 1.0f/float(face.num_corners);
+                       for(int corner = 0; corner < face.num_corners; 
corner++) {
+                               center_vert += 
verts[subd_face_corners[face.start_corner + corner]] * inv_num_corners;
+                               center_normal += 
vN[subd_face_corners[face.start_corner + corner]] * inv_num_corners;
+                       }
+
+                       for(int corner = 0; corner < face.num_corners; 
corner++) {
+                               LinearQuadPatch patch;
+                               float3 *hull = patch.hull;
+                               float3 *normals = patch.normals;
+
+                               patch.patch_index = face.ptex_offset + corner;
+
+                               hull[0] = 
verts[subd_face_corners[face.start_corner + mod(corner + 0, face.num_corners)]];
+                               hull[1] = 
verts[subd_face_corners[face.start_corner + mod(corner + 1, face.num_corners)]];
+                               hull[2] = 
verts[subd_face_corners[face.start_corner + mod(corner - 1, face.num_corners)]];
+                               hull[3] = center_vert;
+
+                               hull[1] = (hull[1] + hull[0]) * 0.5;
+                               hull[2] = (hull[2] + hull[0]) * 0.5;
+
+                               if(face.smooth) {
+                                       normals[0] = 
vN[subd_face_corners[face.start_corner + mod(corner +

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to