[Bf-blender-cvs] [30adc1a] alembic_basic_io: Cycles: sync motion vectors when syncing the mesh, not as an extra step.
Kévin Dietrich
noreply at git.blender.org
Mon Jul 18 08:51:16 CEST 2016
Commit: 30adc1a615cda6e0463569f929e49251b4c1219b
Author: Kévin Dietrich
Date: Mon Jul 18 08:46:03 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB30adc1a615cda6e0463569f929e49251b4c1219b
Cycles: sync motion vectors when syncing the mesh, not as an extra step.
===================================================================
M intern/cycles/blender/blender_mesh.cpp
M intern/cycles/blender/blender_object.cpp
M intern/cycles/blender/blender_sync.h
M intern/cycles/render/scene.cpp
M intern/cycles/render/scene.h
===================================================================
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 0511244..d5fd139 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -680,6 +680,65 @@ static void create_subd_mesh(Scene *scene,
/* Sync */
+static inline BL::MeshSequenceCacheModifier object_mesh_cache_find(BL::Object &b_ob)
+{
+ BL::Object::modifiers_iterator b_mod;
+
+ for(b_ob.modifiers.begin(b_mod); b_mod != b_ob.modifiers.end(); ++b_mod) {
+ if (!b_mod->is_a(&RNA_MeshSequenceCacheModifier)) {
+ continue;
+ }
+
+ BL::MeshSequenceCacheModifier mesh_cache = BL::MeshSequenceCacheModifier(*b_mod);
+
+ if (MeshSequenceCacheModifier_has_velocity_get(&mesh_cache.ptr)) {
+ return mesh_cache;
+ }
+ }
+
+ return BL::MeshSequenceCacheModifier(PointerRNA_NULL);
+}
+
+static void sync_mesh_cached_velocities(BL::Object& b_ob, Scene *scene, Mesh *mesh)
+{
+ if(scene->need_motion() == Scene::MOTION_NONE)
+ return;
+
+ BL::MeshSequenceCacheModifier mesh_cache = object_mesh_cache_find(b_ob);
+
+ if(!mesh_cache)
+ return;
+
+ /* TODO: check that the number of vertices still matches. */
+
+ /* Find or add attribute */
+ float3 *P = &mesh->verts[0];
+ Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
+
+ if(!attr_mP) {
+ attr_mP = mesh->attributes.add(ATTR_STD_MOTION_VERTEX_POSITION);
+ }
+
+ const size_t numverts = mesh->verts.size();
+
+ float3 *buffer = new float3[numverts];
+
+ MeshSequenceCacheModifier_velocity_cache_get(&mesh_cache.ptr, &buffer[0].x);
+
+ /* Only export previous and next frame, we don't have any in between data. */
+ float motion_times[2] = {-1.0f, 1.0f};
+ for (int step = 0; step < 2; step++) {
+ const float relative_time = motion_times[step] * scene->motion_shutter_time() * 0.5f;
+ float3 *mP = attr_mP->data_float3() + step*numverts;
+
+ for (int i = 0; i < numverts; ++i) {
+ mP[i] = P[i] + buffer[i]*relative_time;
+ }
+ }
+
+ delete [] buffer;
+}
+
Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
bool object_updated,
bool hide_tris)
@@ -821,6 +880,9 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
mesh->displacement_method = Mesh::DISPLACE_BOTH;
}
+ /* cached velocities (e.g. from alembic archive) */
+ sync_mesh_cached_velocities(b_ob, scene, mesh);
+
/* tag update */
bool rebuild = false;
@@ -850,29 +912,9 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
return mesh;
}
-static inline BL::MeshSequenceCacheModifier object_mesh_cache_find(BL::Object &b_ob)
-{
- BL::Object::modifiers_iterator b_mod;
-
- for(b_ob.modifiers.begin(b_mod); b_mod != b_ob.modifiers.end(); ++b_mod) {
- if (!b_mod->is_a(&RNA_MeshSequenceCacheModifier)) {
- continue;
- }
-
- BL::MeshSequenceCacheModifier mesh_cache = BL::MeshSequenceCacheModifier(*b_mod);
-
- if (MeshSequenceCacheModifier_has_velocity_get(&mesh_cache.ptr)) {
- return mesh_cache;
- }
- }
-
- return BL::MeshSequenceCacheModifier(PointerRNA_NULL);
-}
-
void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
Object *object,
- float motion_time,
- float shuttertime)
+ float motion_time)
{
/* ensure we only sync instanced meshes once */
Mesh *mesh = object->mesh;
@@ -930,10 +972,12 @@ void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
* would need a more extensive check to see which objects are animated */
BL::Mesh b_mesh(PointerRNA_NULL);
- /* First try to determine if this is a fluid domain. */
+ /* cached motion is exported immediate with mesh, skip here */
BL::MeshSequenceCacheModifier mesh_cache = object_mesh_cache_find(b_ob);
+ if (mesh_cache)
+ return;
- if(mesh_cache || ccl::BKE_object_is_deform_modified(b_ob, b_scene, preview)) {
+ if(ccl::BKE_object_is_deform_modified(b_ob, b_scene, preview)) {
/* get derived mesh */
b_mesh = object_to_mesh(b_data, b_ob, b_scene, true, !preview, false);
}
@@ -971,14 +1015,6 @@ void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
/* TODO(sergey): Perform preliminary check for number of verticies. */
if(numverts) {
- /* For fluid meshes since we have change in geometry, we use velocities,
- * not delta-positions, and all the work is done on the last frame when
- * time_index is != 0, such that we use the velocities from the right
- * frame. */
- if(mesh_cache && time_index == 0) {
- return;
- }
-
/* find attributes */
Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
Attribute *attr_mN = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL);
@@ -994,78 +1030,46 @@ void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
new_attribute = true;
}
- if (mesh_cache) {
- /* load vertex data from mesh */
- float3 *P = &mesh->verts[0];
- float3 *N = (attr_mN) ? attr_N->data_float3() : NULL;
-
- int step = 0;
-
- float3 *buffer = new float3[numverts];
-
- MeshSequenceCacheModifier_velocity_cache_get(&mesh_cache.ptr, &buffer[0].x);
-
- /* Generate motion data for all motion times in one go, so that
- * vertices and velocities coincide. */
- foreach(float relative_time, this->motion_times) {
- float3 *mP = attr_mP->data_float3() + step*numverts;
- float3 *mN = (attr_mN) ? attr_mN->data_float3() + step*numverts : NULL;
+ /* 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;
- for (int i = 0; i < numverts; ++i) {
- mP[i] = P[i] + buffer[i]*relative_time*shuttertime*0.5f;
-
- if(mN) {
- mN[i] = N[i];
- }
- }
-
- ++step;
- }
+ BL::Mesh::vertices_iterator v;
+ int i = 0;
- delete [] buffer;
+ 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());
}
- else {
- /* 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) {
- 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(b_mesh.vertices.length() != numverts ||
- memcmp(mP, &mesh->verts[0], sizeof(float3)*numverts) == 0)
- {
- /* no motion, remove attributes again */
- if(b_mesh.vertices.length() != numverts) {
- VLOG(1) << "Topology differs, disabling motion blur.";
- }
- else {
- VLOG(1) << "No actual deformation motion for object " << b_ob.name();
- }
- mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_POSITION);
- if(attr_mN)
- mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_NORMAL);
+ /* in case of new attribute, we verify if there really was any motion */
+ if(new_attribute) {
+ if(b_mesh.vertices.length() != numverts ||
+ memcmp(mP, &mesh->verts[0], sizeof(float3)*numverts) == 0)
+ {
+ /* no motion, remove attributes again */
+ if(b_mesh.vertices.length() != numverts) {
+ VLOG(1) << "Topology differs, disabling motion blur.";
+ }
+ else {
+ VLOG(1) << "No actual deformation motion for object " << b_ob.name();
}
- else if(time_index > 0) {
- VLOG(1) << "Filling deformation motion for object " << b_ob.name();
- /* motion, fill up previous steps that we might have skipped because
+ mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_POSITION);
+ if(attr_mN)
+ mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_NORMAL);
+ }
+ else if(time_index > 0) {
+ VLOG(1) << "Filling deformation motion for object " << b_ob.name();
+ /* 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;
+ float3 *P = &mesh->verts[0];
+ float3 *N = (attr_N)? attr_N->data_float3(): NULL;
- for(int step = 0; step < time_index; step++) {
- memcpy(attr_mP->data_float3() + step*numverts, P, sizeof(float3)*numverts);
- if(attr_mN)
- memcpy(attr_mN->data_float3() + step*numverts, N, sizeof(float3)*numverts);
- }
+ for(int step = 0; step < time_index; step++) {
+ memcpy(attr_mP->data_float3() + step*numverts, P, sizeof(float3)*numverts);
+ if(attr_mN)
+ memcpy(attr_mN->data_float3() + step*numverts, N, sizeof(float3)*numverts);
}
}
}
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index 7782620e..4f51933 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -280,7 +280,6 @@ Object *BlenderSync::sync_object(BL::Object& b_parent,
Transform& tfm,
uint layer_flag,
float motion_time,
- float shutter_time,
bool hide_tris,
bool use_camera_cull,
float camera_cull_margin,
@@ -333,7 +332,7 @@ Object *BlenderSync::sync_object(BL::Object& b_parent,
/* mesh deformation */
if(object->mesh)
- sync_mesh_motion(b_ob, object, motion_time, shutter_time);
+ sync_mesh_motion(b_ob, object, motion_time);
}
return object;
@@ -519,7 +518,7 @@ static bool object_render_hide_duplis(BL::Object& b_ob)
/* Object Loop */
-void BlenderSync::sync_objects(BL::SpaceView3D& b_v3d, float motion_time, float shutter_time)
+void BlenderSync::sync_objects(BL::SpaceView3D& b_v3d, float motion_time)
{
/* layer data */
uint scene_layer = render_layer.scene_layer;
@@ -610,7 +609,6 @@ void BlenderSync::sync_objects(BL::SpaceView3D& b_v3d, float motion_time, float
tfm,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list