diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-01-16 21:56:40 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-01-20 14:46:15 +0300 |
commit | 461214508c26110de615e0797cb63bf0df02bdca (patch) | |
tree | ec0aa55d516de9650a7ad65e9d1077141884d7c3 /intern | |
parent | 811e6c2d32c5cd84112c6ee64af6ecb482186d91 (diff) |
Cycles: Add utility function to fetch motion triangle when on CPU side
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/render/mesh.cpp | 48 | ||||
-rw-r--r-- | intern/cycles/render/mesh.h | 19 |
2 files changed, 66 insertions, 1 deletions
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp index 5f0b2ef50bc..25d220562ea 100644 --- a/intern/cycles/render/mesh.cpp +++ b/intern/cycles/render/mesh.cpp @@ -49,6 +49,54 @@ void Mesh::Triangle::bounds_grow(const float3 *verts, BoundBox& bounds) const bounds.grow(verts[v[2]]); } +void Mesh::Triangle::motion_verts(const float3 *verts, + const float3 *vert_steps, + size_t num_verts, + size_t num_steps, + float time, + float3 r_verts[3]) const +{ + /* Figure out which steps we need to fetch and their interpolation factor. */ + const size_t max_step = num_steps - 1; + const size_t step = min((int)(time * max_step), max_step - 1); + const float t = time*max_step - step; + /* Fetch vertex coordinates. */ + float3 curr_verts[3]; + float3 next_verts[3]; + verts_for_step(verts, vert_steps, num_verts, num_steps, step, curr_verts); + verts_for_step(verts, vert_steps, num_verts, num_steps, step + 1, next_verts); + /* Interpolate between steps. */ + r_verts[0] = (1.0f - t)*curr_verts[0] + t*next_verts[0]; + r_verts[1] = (1.0f - t)*curr_verts[1] + t*next_verts[1]; + r_verts[2] = (1.0f - t)*curr_verts[2] + t*next_verts[2]; +} + +void Mesh::Triangle::verts_for_step(const float3 *verts, + const float3 *vert_steps, + size_t num_verts, + size_t num_steps, + size_t step, + float3 r_verts[3]) const +{ + const size_t center_step = ((num_steps - 1) / 2); + if(step == center_step) { + /* Center step: regular vertex location. */ + r_verts[0] = verts[v[0]]; + r_verts[1] = verts[v[1]]; + r_verts[2] = verts[v[2]]; + } + else { + /* Center step not stored in the attribute array array. */ + if(step > center_step) { + step--; + } + size_t offset = step * num_verts; + r_verts[0] = vert_steps[offset + v[0]]; + r_verts[1] = vert_steps[offset + v[1]]; + r_verts[2] = vert_steps[offset + v[2]]; + } +} + /* Curve */ void Mesh::Curve::bounds_grow(const int k, const float3 *curve_keys, const float *curve_radius, BoundBox& bounds) const diff --git a/intern/cycles/render/mesh.h b/intern/cycles/render/mesh.h index c0310f45840..33d8acc9c8b 100644 --- a/intern/cycles/render/mesh.h +++ b/intern/cycles/render/mesh.h @@ -31,6 +31,7 @@ CCL_NAMESPACE_BEGIN +class Attribute; class BVH; class Device; class DeviceScene; @@ -54,11 +55,27 @@ public: int v[3]; void bounds_grow(const float3 *verts, BoundBox& bounds) const; + + void motion_verts(const float3 *verts, + const float3 *vert_steps, + size_t num_verts, + size_t num_steps, + float time, + float3 r_verts[3]) const; + + void verts_for_step(const float3 *verts, + const float3 *vert_steps, + size_t num_verts, + size_t num_steps, + size_t step, + float3 r_verts[3]) const; }; Triangle get_triangle(size_t i) const { - Triangle tri = {{triangles[i*3 + 0], triangles[i*3 + 1], triangles[i*3 + 2]}}; + Triangle tri = {{triangles[i*3 + 0], + triangles[i*3 + 1], + triangles[i*3 + 2]}}; return tri; } |