[Bf-blender-cvs] [04b5b4a914d] new-object-types: Merge branch 'master' into new-object-types
Brecht Van Lommel
noreply at git.blender.org
Fri Feb 7 12:32:50 CET 2020
Commit: 04b5b4a914da5c6f213b1005a9281ffde74e7f4f
Author: Brecht Van Lommel
Date: Fri Feb 7 12:26:24 2020 +0100
Branches: new-object-types
https://developer.blender.org/rB04b5b4a914da5c6f213b1005a9281ffde74e7f4f
Merge branch 'master' into new-object-types
===================================================================
===================================================================
diff --cc intern/cycles/blender/blender_curves.cpp
index 4da5c8f7101,affd5685337..641f267e2f4
--- a/intern/cycles/blender/blender_curves.cpp
+++ b/intern/cycles/blender/blender_curves.cpp
@@@ -594,7 -595,41 +595,7 @@@ static void ExportCurveTriangleGeometry
/* texture coords still needed */
}
- static void ExportCurveSegments(Scene *scene, Mesh *mesh, ParticleCurveData *CData)
-static void export_hair_motion_validate_attribute(Hair *hair,
- int motion_step,
- int num_motion_keys,
- bool have_motion)
-{
- Attribute *attr_mP = hair->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
- const int num_keys = hair->curve_keys.size();
-
- if (num_motion_keys != num_keys || !have_motion) {
- /* No motion or hair "topology" changed, remove attributes again. */
- if (num_motion_keys != num_keys) {
- VLOG(1) << "Hair topology changed, removing attribute.";
- }
- else {
- VLOG(1) << "No motion, removing attribute.";
- }
- hair->attributes.remove(ATTR_STD_MOTION_VERTEX_POSITION);
- }
- else if (motion_step > 0) {
- VLOG(1) << "Filling in new motion vertex position for motion_step " << motion_step;
-
- /* Motion, fill up previous steps that we might have skipped because
- * they had no motion, but we need them anyway now. */
- for (int step = 0; step < motion_step; step++) {
- float4 *mP = attr_mP->data_float4() + step * num_keys;
-
- for (int key = 0; key < num_keys; key++) {
- mP[key] = float3_to_float4(hair->curve_keys[key]);
- mP[key].w = hair->curve_radius[key];
- }
- }
- }
-}
-
+ static void ExportCurveSegments(Scene *scene, Hair *hair, ParticleCurveData *CData)
{
int num_keys = 0;
int num_curves = 0;
@@@ -713,43 -748,9 +714,43 @@@ static float4 LerpCurveSegmentMotionCV(
return lerp(mP, mP2, remainder);
}
- static void export_hair_motion_validate_attribute(Mesh *mesh,
++static void export_hair_motion_validate_attribute(Hair *hair,
+ int motion_step,
+ int num_motion_keys,
+ bool have_motion)
+{
- Attribute *attr_mP = mesh->curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
- const int num_keys = mesh->curve_keys.size();
++ Attribute *attr_mP = hair->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
++ const int num_keys = hair->curve_keys.size();
+
+ if (num_motion_keys != num_keys || !have_motion) {
+ /* No motion or hair "topology" changed, remove attributes again. */
+ if (num_motion_keys != num_keys) {
+ VLOG(1) << "Hair topology changed, removing attribute.";
+ }
+ else {
+ VLOG(1) << "No motion, removing attribute.";
+ }
- mesh->curve_attributes.remove(ATTR_STD_MOTION_VERTEX_POSITION);
++ hair->attributes.remove(ATTR_STD_MOTION_VERTEX_POSITION);
+ }
+ else if (motion_step > 0) {
+ VLOG(1) << "Filling in new motion vertex position for motion_step " << motion_step;
+
+ /* Motion, fill up previous steps that we might have skipped because
+ * they had no motion, but we need them anyway now. */
+ for (int step = 0; step < motion_step; step++) {
+ float4 *mP = attr_mP->data_float4() + step * num_keys;
+
+ for (int key = 0; key < num_keys; key++) {
- mP[key] = float3_to_float4(mesh->curve_keys[key]);
- mP[key].w = mesh->curve_radius[key];
++ mP[key] = float3_to_float4(hair->curve_keys[key]);
++ mP[key].w = hair->curve_radius[key];
+ }
+ }
+ }
+}
+
- static void ExportCurveSegmentsMotion(Mesh *mesh, ParticleCurveData *CData, int motion_step)
+ static void ExportCurveSegmentsMotion(Hair *hair, ParticleCurveData *CData, int motion_step)
{
- VLOG(1) << "Exporting curve motion segments for mesh " << mesh->name << ", motion step "
+ VLOG(1) << "Exporting curve motion segments for hair " << hair->name << ", motion step "
<< motion_step;
/* find attribute */
@@@ -816,9 -817,9 +817,9 @@@
}
}
- /* in case of new attribute, we verify if there really was any motion */
+ /* In case of new attribute, we verify if there really was any motion. */
if (new_attribute) {
- export_hair_motion_validate_attribute(mesh, motion_step, i, have_motion);
+ export_hair_motion_validate_attribute(hair, motion_step, i, have_motion);
}
}
@@@ -1149,207 -1152,77 +1152,271 @@@ void BlenderSync::sync_particle_hair
}
}
}
-
- mesh->compute_bounds();
}
+static float4 hair_point_as_float4(BL::HairPoint b_point)
+{
+ float4 mP = float3_to_float4(get_float3(b_point.co()));
+ mP.w = b_point.radius();
+ return mP;
+}
+
+static float4 interpolate_hair_points(BL::Hair b_hair,
+ const int first_point_index,
+ const int num_points,
+ const float step)
+{
+ const float curve_t = step * (num_points - 1);
+ const int point_a = clamp((int)curve_t, 0, num_points - 1);
+ const int point_b = min(point_a + 1, num_points - 1);
+ const float t = curve_t - (float)point_a;
+ return lerp(hair_point_as_float4(b_hair.points[first_point_index + point_a]),
+ hair_point_as_float4(b_hair.points[first_point_index + point_b]),
+ t);
+}
+
- static void export_hair_curves(Scene *scene, Mesh *mesh, BL::Hair b_hair)
++static void export_hair_curves(Scene *scene, Hair *hair, BL::Hair b_hair)
+{
+ /* TODO: optimize so we can straight memcpy arrays from Blender? */
+
+ /* Add requested attributes. */
+ Attribute *attr_intercept = NULL;
+ Attribute *attr_random = NULL;
+
- if (mesh->need_attribute(scene, ATTR_STD_CURVE_INTERCEPT)) {
- attr_intercept = mesh->curve_attributes.add(ATTR_STD_CURVE_INTERCEPT);
++ if (hair->need_attribute(scene, ATTR_STD_CURVE_INTERCEPT)) {
++ attr_intercept = hair->attributes.add(ATTR_STD_CURVE_INTERCEPT);
+ }
- if (mesh->need_attribute(scene, ATTR_STD_CURVE_RANDOM)) {
- attr_random = mesh->curve_attributes.add(ATTR_STD_CURVE_RANDOM);
++ if (hair->need_attribute(scene, ATTR_STD_CURVE_RANDOM)) {
++ attr_random = hair->attributes.add(ATTR_STD_CURVE_RANDOM);
+ }
+
+ /* Reserve memory. */
+ const int num_keys = b_hair.points.length();
+ const int num_curves = b_hair.curves.length();
+
+ if (num_curves > 0) {
- VLOG(1) << "Exporting curve segments for mesh " << mesh->name;
++ VLOG(1) << "Exporting curve segments for hair " << hair->name;
+ }
+
- mesh->reserve_curves(num_curves, num_keys);
++ hair->reserve_curves(num_curves, num_keys);
+
+ /* Export curves and points. */
+ vector<float> points_length;
+
+ BL::Hair::curves_iterator b_curve_iter;
+ for (b_hair.curves.begin(b_curve_iter); b_curve_iter != b_hair.curves.end(); ++b_curve_iter) {
+ BL::HairCurve b_curve = *b_curve_iter;
+ const int first_point_index = b_curve.first_point_index();
+ const int num_points = b_curve.num_points();
+
+ float3 prev_co = make_float3(0.0f, 0.0f, 0.0f);
+ float length = 0.0f;
+ if (attr_intercept) {
+ points_length.clear();
+ points_length.reserve(num_points);
+ }
+
+ /* Position and radius. */
+ for (int i = 0; i < num_points; i++) {
+ BL::HairPoint b_point = b_hair.points[first_point_index + i];
+
+ const float3 co = get_float3(b_point.co());
+ const float radius = b_point.radius();
- mesh->add_curve_key(co, radius);
++ hair->add_curve_key(co, radius);
+
+ if (attr_intercept) {
+ if (i > 0) {
+ length += len(co - prev_co);
+ points_length.push_back(length);
+ }
+ prev_co = co;
+ }
+ }
+
+ /* Normalized 0..1 attribute along curve. */
+ if (attr_intercept) {
+ for (int i = 0; i < num_points; i++) {
+ attr_intercept->add((length == 0.0f) ? 0.0f : points_length[i] / length);
+ }
+ }
+
+ /* Random number per curve. */
+ if (attr_random != NULL) {
+ attr_random->add(hash_uint2_to_float(b_curve.index(), 0));
+ }
+
+ /* Curve. */
+ const int shader_index = 0;
- mesh->add_curve(first_point_index, shader_index);
++ hair->add_curve(first_point_index, shader_index);
+ }
+}
+
- static void export_hair_curves_motion(Mesh *mesh, BL::Hair b_hair, int motion_step)
++static void export_hair_curves_motion(Hair *hair, BL::Hair b_hair, int motion_step)
+{
- VLOG(1) << "Exporting curve motion segments for mesh " << mesh->name << ", motion step "
++ VLOG(1) << "Exporting curve motion segments for hair " << hair->name << ", motion step "
+ << motion_step;
+
+ /* Find or add attribute. */
- Attribute *attr_mP = mesh->curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
++ Attribute *attr_mP = hair->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
+ bool new_attribute = false;
+
+ if (!attr_mP) {
+ VLOG(1) << "Creating new motion vertex position attribute";
- attr_mP = mesh->curve_attributes.add(ATTR_STD_MOTION_VERTEX_POSITION);
++ attr_mP = hair->attributes.add(ATTR_STD_MOTION_VERTEX_POSITION);
+ new_attribute = true;
+ }
+
+ /* Export motion keys. */
- const int num_keys = mesh->curve_keys.size();
++ const int num_keys = hair->curve_keys.size();
+ float4 *mP = attr_mP->data_float4() + motion_step * num_keys;
+ bool have_motion = false;
+ int num_motion_keys = 0;
+ int curve_index = 0;
+
+ BL::Hair::curves_iterator b_curve_iter;
+ for (b_hair.curves.begin(b_curve_iter); b_curve_iter != b_hair.curves.end(); ++b_curve_iter) {
+ BL::HairCurve b_curve = *b_curve_iter;
+ const int first_point_index = b_curve.first_point_index();
+ const int num_points = b_curve.num_points();
+
- Mesh::Curve curve = mesh->get_curve(curve_index);
++ Hair::Curve curve = hair->get_curve(curve_index);
+ curve_index++;
+
+ if (num_points == curve.num_keys) {
+ /* Number of keys matches. */
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list