Commit: eb8376bcbe7ba00e68c142235421c57e4e3304f0
Author: Mai Lavelle
Date:   Wed Jun 22 11:27:15 2016 -0400
Branches: temp-cycles-microdisplacement
https://developer.blender.org/rBeb8376bcbe7ba00e68c142235421c57e4e3304f0

Sync ngons and attributes from Blender to Cycles

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

M       intern/cycles/blender/blender_mesh.cpp
M       intern/cycles/blender/blender_util.h
M       intern/cycles/render/mesh.cpp

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

diff --git a/intern/cycles/blender/blender_mesh.cpp 
b/intern/cycles/blender/blender_mesh.cpp
index 3f22355..455668a 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -191,8 +191,7 @@ static void mikk_compute_tangents(BL::Mesh& b_mesh,
                                   const vector<int>& nverts,
                                   const vector<int>& face_flags,
                                   bool need_sign,
-                                  bool active_render,
-                                  bool subdivision)
+                                  bool active_render)
 {
        /* setup userdata */
        MikkUserData userdata(b_mesh, b_layer, nverts.size());
@@ -218,7 +217,6 @@ static void mikk_compute_tangents(BL::Mesh& b_mesh,
 
        /* create tangent attributes */
        Attribute *attr;
-       AttributeSet& mesh_attributes = subdivision? mesh->subd_attributes: 
mesh->attributes;
        ustring name;
        if(b_layer != NULL)
                name = ustring((string(b_layer->name().c_str()) + 
".tangent").c_str());
@@ -226,9 +224,9 @@ static void mikk_compute_tangents(BL::Mesh& b_mesh,
                name = ustring("orco.tangent");
 
        if(active_render)
-               attr = mesh_attributes.add(ATTR_STD_UV_TANGENT, name);
+               attr = mesh->attributes.add(ATTR_STD_UV_TANGENT, name);
        else
-               attr = mesh_attributes.add(name, TypeDesc::TypeVector, 
ATTR_ELEMENT_CORNER);
+               attr = mesh->attributes.add(name, TypeDesc::TypeVector, 
ATTR_ELEMENT_CORNER);
 
        float3 *tangent = attr->data_float3();
 
@@ -244,59 +242,40 @@ static void mikk_compute_tangents(BL::Mesh& b_mesh,
                        name_sign = ustring("orco.tangent_sign");
 
                if(active_render)
-                       attr_sign = 
mesh_attributes.add(ATTR_STD_UV_TANGENT_SIGN, name_sign);
+                       attr_sign = 
mesh->attributes.add(ATTR_STD_UV_TANGENT_SIGN, name_sign);
                else
-                       attr_sign = mesh_attributes.add(name_sign, 
TypeDesc::TypeFloat, ATTR_ELEMENT_CORNER);
+                       attr_sign = mesh->attributes.add(name_sign, 
TypeDesc::TypeFloat, ATTR_ELEMENT_CORNER);
 
                tangent_sign = attr_sign->data_float();
        }
 
-       if(!subdivision) {
-               for(int i = 0; i < nverts.size(); i++) {
-                       int tri_a[3], tri_b[3];
-                       face_split_tri_indices(nverts[i], face_flags[i], tri_a, 
tri_b);
+       for(int i = 0; i < nverts.size(); i++) {
+               int tri_a[3], tri_b[3];
+               face_split_tri_indices(nverts[i], face_flags[i], tri_a, tri_b);
 
-                       tangent[0] = float4_to_float3(userdata.tangent[i*4 + 
tri_a[0]]);
-                       tangent[1] = float4_to_float3(userdata.tangent[i*4 + 
tri_a[1]]);
-                       tangent[2] = float4_to_float3(userdata.tangent[i*4 + 
tri_a[2]]);
-                       tangent += 3;
+               tangent[0] = float4_to_float3(userdata.tangent[i*4 + tri_a[0]]);
+               tangent[1] = float4_to_float3(userdata.tangent[i*4 + tri_a[1]]);
+               tangent[2] = float4_to_float3(userdata.tangent[i*4 + tri_a[2]]);
+               tangent += 3;
 
-                       if(tangent_sign) {
-                               tangent_sign[0] = userdata.tangent[i*4 + 
tri_a[0]].w;
-                               tangent_sign[1] = userdata.tangent[i*4 + 
tri_a[1]].w;
-                               tangent_sign[2] = userdata.tangent[i*4 + 
tri_a[2]].w;
-                               tangent_sign += 3;
-                       }
-
-                       if(nverts[i] == 4) {
-                               tangent[0] = 
float4_to_float3(userdata.tangent[i*4 + tri_b[0]]);
-                               tangent[1] = 
float4_to_float3(userdata.tangent[i*4 + tri_b[1]]);
-                               tangent[2] = 
float4_to_float3(userdata.tangent[i*4 + tri_b[2]]);
-                               tangent += 3;
-
-                               if(tangent_sign) {
-                                       tangent_sign[0] = userdata.tangent[i*4 
+ tri_b[0]].w;
-                                       tangent_sign[1] = userdata.tangent[i*4 
+ tri_b[1]].w;
-                                       tangent_sign[2] = userdata.tangent[i*4 
+ tri_b[2]].w;
-                                       tangent_sign += 3;
-                               }
-                       }
+               if(tangent_sign) {
+                       tangent_sign[0] = userdata.tangent[i*4 + tri_a[0]].w;
+                       tangent_sign[1] = userdata.tangent[i*4 + tri_a[1]].w;
+                       tangent_sign[2] = userdata.tangent[i*4 + tri_a[2]].w;
+                       tangent_sign += 3;
                }
-       }
-       else {
-               for(int i = 0; i < nverts.size(); i++) {
-                       tangent[0] = float4_to_float3(userdata.tangent[i*4 + 
0]);
-                       tangent[1] = float4_to_float3(userdata.tangent[i*4 + 
1]);
-                       tangent[2] = float4_to_float3(userdata.tangent[i*4 + 
2]);
-                       tangent[3] = float4_to_float3(userdata.tangent[i*4 + 
3]);
-                       tangent += 4;
+
+               if(nverts[i] == 4) {
+                       tangent[0] = float4_to_float3(userdata.tangent[i*4 + 
tri_b[0]]);
+                       tangent[1] = float4_to_float3(userdata.tangent[i*4 + 
tri_b[1]]);
+                       tangent[2] = float4_to_float3(userdata.tangent[i*4 + 
tri_b[2]]);
+                       tangent += 3;
 
                        if(tangent_sign) {
-                               tangent_sign[0] = userdata.tangent[i*4 + 0].w;
-                               tangent_sign[1] = userdata.tangent[i*4 + 1].w;
-                               tangent_sign[2] = userdata.tangent[i*4 + 2].w;
-                               tangent_sign[3] = userdata.tangent[i*4 + 3].w;
-                               tangent_sign += 4;
+                               tangent_sign[0] = userdata.tangent[i*4 + 
tri_b[0]].w;
+                               tangent_sign[1] = userdata.tangent[i*4 + 
tri_b[1]].w;
+                               tangent_sign[2] = userdata.tangent[i*4 + 
tri_b[2]].w;
+                               tangent_sign += 3;
                        }
                }
        }
@@ -359,31 +338,55 @@ static void attr_create_vertex_color(Scene *scene,
                                      const vector<int>& face_flags,
                                      bool subdivision)
 {
-       BL::Mesh::tessface_vertex_colors_iterator l;
-       for(b_mesh.tessface_vertex_colors.begin(l); l != 
b_mesh.tessface_vertex_colors.end(); ++l) {
-               if(!mesh->need_attribute(scene, ustring(l->name().c_str())))
-                       continue;
+       if(subdivision) {
+               BL::Mesh::vertex_colors_iterator l;
 
-               Attribute *attr = (subdivision? mesh->subd_attributes: 
mesh->attributes).add(
-                       ustring(l->name().c_str()), TypeDesc::TypeColor, 
ATTR_ELEMENT_CORNER_BYTE);
+               for(b_mesh.vertex_colors.begin(l); l != 
b_mesh.vertex_colors.end(); ++l) {
+                       if(!mesh->need_attribute(scene, 
ustring(l->name().c_str())))
+                               continue;
 
-               BL::MeshColorLayer::data_iterator c;
-               uchar4 *cdata = attr->data_uchar4();
-               size_t i = 0;
+                       Attribute *attr = 
mesh->subd_attributes.add(ustring(l->name().c_str()),
+                                                                   
TypeDesc::TypeColor,
+                                                                   
ATTR_ELEMENT_CORNER_BYTE);
 
-               for(l->data.begin(c); c != l->data.end(); ++c, ++i) {
-                       int tri_a[3], tri_b[3];
-                       face_split_tri_indices(nverts[i], face_flags[i], tri_a, 
tri_b);
+                       BL::Mesh::polygons_iterator p;
+                       uchar4 *cdata = attr->data_uchar4();
 
-                       uchar4 colors[4];
-                       colors[0] = 
color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color1())));
-                       colors[1] = 
color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color2())));
-                       colors[2] = 
color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color3())));
-                       if(nverts[i] == 4) {
-                               colors[3] = 
color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color4())));
+                       for(b_mesh.polygons.begin(p); p != 
b_mesh.polygons.end(); ++p) {
+                               int n = p->loop_total();
+                               for(int i = 0; i < n; i++) {
+                                       float3 color = 
get_float3(l->data[p->loop_start() + i].color());
+                                       *(cdata++) = 
color_float_to_byte(color_srgb_to_scene_linear(color));
+                               }
                        }
+               }
+       }
+       else {
+               BL::Mesh::tessface_vertex_colors_iterator l;
+               for(b_mesh.tessface_vertex_colors.begin(l); l != 
b_mesh.tessface_vertex_colors.end(); ++l) {
+                       if(!mesh->need_attribute(scene, 
ustring(l->name().c_str())))
+                               continue;
+
+                       Attribute *attr = 
mesh->attributes.add(ustring(l->name().c_str()),
+                                                              
TypeDesc::TypeColor,
+                                                              
ATTR_ELEMENT_CORNER_BYTE);
+
+                       BL::MeshColorLayer::data_iterator c;
+                       uchar4 *cdata = attr->data_uchar4();
+                       size_t i = 0;
+
+                       for(l->data.begin(c); c != l->data.end(); ++c, ++i) {
+                               int tri_a[3], tri_b[3];
+                               face_split_tri_indices(nverts[i], 
face_flags[i], tri_a, tri_b);
+
+                               uchar4 colors[4];
+                               colors[0] = 
color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color1())));
+                               colors[1] = 
color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color2())));
+                               colors[2] = 
color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color3())));
+                               if(nverts[i] == 4) {
+                                       colors[3] = 
color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color4())));
+                               }
 
-                       if(!subdivision) {
                                cdata[0] = colors[tri_a[0]];
                                cdata[1] = colors[tri_a[1]];
                                cdata[2] = colors[tri_a[2]];
@@ -397,13 +400,6 @@ static void attr_create_vertex_color(Scene *scene,
                                else
                                        cdata += 3;
                        }
-                       else {
-                               cdata[0] = colors[0];
-                               cdata[1] = colors[1];
-                               cdata[2] = colors[2];
-                               cdata[3] = colors[3];
-                               cdata += 4;
-                       }
                }
        }
 }
@@ -416,7 +412,37 @@ static void attr_create_uv_map(Scene *scene,
                                const vector<int>& face_flags,
                                bool subdivision)
 {
-       if(b_mesh.tessface_uv_textures.length() != 0) {
+       if(subdivision) {
+               BL::Mesh::uv_layers_iterator l;
+               int i = 0;
+
+               for(b_mesh.uv_layers.begin(l); l != b_mesh.uv_layers.end(); 
++l, ++i) {
+                       bool active_render = 
b_mesh.uv_textures[i].active_render();
+                       AttributeStandard std = (active_render)? ATTR_STD_UV: 
ATTR_STD_NONE;
+                       ustring name = ustring(l->name().c_str());
+
+                       /* UV map */
+                       if(mesh->need_attribute(scene, name) || 
mesh->need_attribute(scene, std)) {
+                               Attribute *attr;
+
+                               if(active_render)
+                                       attr = mesh->subd_attributes.add(std, 
name);
+                               else
+                                       attr = mesh->subd_attributes.add(name, 
TypeDesc::TypePoint, ATTR_ELEMENT_CORNER);
+
+                               BL::Mesh::polygons_iterator p;
+                               float3 *fdata = attr->data_float3();
+
+                               for(b_mesh.polygons.begin(p); p != 
b_mesh.polygons.end(); ++p) {
+                                       int n = p->loop_total();
+                                       for(int j = 0; j < n; j++) {
+                                               *(fdata++) = 
get_float3(l->data[p->loop_start() + j].uv());
+                                       }
+                               }
+                       }
+               }
+       }
+       else if(b_mesh.tessface_uv_textures.length() != 0) {
                BL::Mesh::tessface_uv_textures_iterator l;
 
                for(b_mesh.tessface_uv_textures.begin(l); l != 
b_mesh.tessface_uv_textures.end(); ++l) {
@@ -429,9 +455,9 @@ static void attr_create_uv_map(Scene *scene,
                                Attribute *attr;
 
                                if(active_render)
-                                       attr = (subdivision? 
mesh->subd_attributes: mesh->attributes).add(std, name);
+                                       attr = mesh->attributes.add(std, name);
                                else
-                                       attr = (subdivision? 
mesh->subd_attributes: mesh->attributes).add(name, TypeDesc::TypePoint, 
ATTR_ELEMENT_CORNER);
+                                       attr = mesh->attributes.add(name, 
TypeDesc::TypePoint, ATTR_ELEMENT_CORNER);
 
                                BL::MeshTextureFaceLayer::data_iterator t;
                                float3 *fdat

@@ 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