diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-02-13 16:20:47 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-02-13 16:20:47 +0300 |
commit | 37f65e9dc4bcfa5225a114feabac753e342bb201 (patch) | |
tree | 0d5f08e60de8c40c940dcb806e20a97bafdff667 /intern/cycles/blender | |
parent | d640ce40aa9e472613cac22ecbc7655db9c27201 (diff) |
Cycles: Implement index output for hair node
This is like the only way to add variety to hair which is created
using simple children. Used here for the hair.
Maybe not ideal, but the time will show.
Diffstat (limited to 'intern/cycles/blender')
-rw-r--r-- | intern/cycles/blender/blender_curves.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/intern/cycles/blender/blender_curves.cpp b/intern/cycles/blender/blender_curves.cpp index 42b985305ea..c8eb879e5cb 100644 --- a/intern/cycles/blender/blender_curves.cpp +++ b/intern/cycles/blender/blender_curves.cpp @@ -565,9 +565,12 @@ static void ExportCurveSegments(Scene *scene, Mesh *mesh, ParticleCurveData *CDa return; Attribute *attr_intercept = NULL; + Attribute *attr_index = NULL; if(mesh->need_attribute(scene, ATTR_STD_CURVE_INTERCEPT)) attr_intercept = mesh->curve_attributes.add(ATTR_STD_CURVE_INTERCEPT); + if(mesh->need_attribute(scene, ATTR_STD_CURVE_INDEX)) + attr_index = mesh->curve_attributes.add(ATTR_STD_CURVE_INDEX); /* compute and reserve size of arrays */ for(int sys = 0; sys < CData->psys_firstcurve.size(); sys++) { @@ -612,12 +615,25 @@ static void ExportCurveSegments(Scene *scene, Mesh *mesh, ParticleCurveData *CDa num_curve_keys++; } + if(attr_index != NULL) { + attr_index->add(num_curves); + } + mesh->add_curve(num_keys, CData->psys_shader[sys]); num_keys += num_curve_keys; num_curves++; } } + if(attr_index != NULL) { + /* Normalize index to 0..1 range. */ + float *curve_index = attr_index->data_float(); + const float norm_factor = 1.0f / (float)num_curves; + for(int i = 0; i < num_curves; ++i) { + curve_index[i] *= norm_factor; + } + } + /* check allocation */ if((mesh->curve_keys.size() != num_keys) || (mesh->num_curves() != num_curves)) { VLOG(1) << "Allocation failed, clearing data"; |