diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2014-03-29 16:03:46 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2014-03-29 16:03:46 +0400 |
commit | 8f33538fabe9b2485478b7ce0167c15396bdb355 (patch) | |
tree | 2ad971354ba58047cfbab6d9c23749a475d42df1 /intern/cycles/blender | |
parent | 99f59930885ed69890967f8864a3aa0626249d86 (diff) |
Cycles code refactor: add motion sampled normals attribute.
Diffstat (limited to 'intern/cycles/blender')
-rw-r--r-- | intern/cycles/blender/blender_mesh.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index 9e11cc1ae0b..ed19fb2672b 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -601,37 +601,50 @@ void BlenderSync::sync_mesh_motion(BL::Object b_ob, Object *object, float motion if(numverts) { /* find attributes */ Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); + Attribute *attr_mN = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL); + Attribute *attr_N = mesh->attributes.find(ATTR_STD_VERTEX_NORMAL); bool new_attribute = false; /* add new attributes if they don't exist already */ if(!attr_mP) { attr_mP = mesh->attributes.add(ATTR_STD_MOTION_VERTEX_POSITION); + if(attr_N) + attr_mN = mesh->attributes.add(ATTR_STD_MOTION_VERTEX_NORMAL); new_attribute = true; } /* load vertex data from mesh */ float3 *mP = attr_mP->data_float3() + time_index*numverts; + float3 *mN = (attr_mN)? attr_mN->data_float3() + time_index*numverts: NULL; BL::Mesh::vertices_iterator v; int i = 0; - for(b_mesh.vertices.begin(v); v != b_mesh.vertices.end() && i < numverts; ++v, ++i) + for(b_mesh.vertices.begin(v); v != b_mesh.vertices.end() && i < numverts; ++v, ++i) { mP[i] = get_float3(v->co()); + if(mN) + mN[i] = get_float3(v->normal()); + } /* in case of new attribute, we verify if there really was any motion */ if(new_attribute) { if(i != numverts || memcmp(mP, &mesh->verts[0], sizeof(float3)*numverts) == 0) { /* no motion, remove attributes again */ mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_POSITION); + if(attr_mN) + mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_NORMAL); } else if(time_index > 0) { /* motion, fill up previous steps that we might have skipped because * they had no motion, but we need them anyway now */ float3 *P = &mesh->verts[0]; + float3 *N = (attr_N)? attr_N->data_float3(): NULL; - for(int step = 0; step < time_index; step++) + for(int step = 0; step < time_index; step++) { memcpy(attr_mP->data_float3() + step*numverts, P, sizeof(float3)*numverts); + memcpy(attr_mN->data_float3() + step*numverts, N, sizeof(float3)*numverts); + } } } } |