[Bf-blender-cvs] [a013bb98193] cycles_procedural_api: Merge branch 'cycles_socket_api' into cycles_procedural_api
Kévin Dietrich
noreply at git.blender.org
Thu Nov 5 18:57:53 CET 2020
Commit: a013bb9819398bf9f446f11333b5f6dea256975e
Author: Kévin Dietrich
Date: Thu Nov 5 09:47:33 2020 +0100
Branches: cycles_procedural_api
https://developer.blender.org/rBa013bb9819398bf9f446f11333b5f6dea256975e
Merge branch 'cycles_socket_api' into cycles_procedural_api
===================================================================
===================================================================
diff --cc intern/cycles/blender/blender_mesh.cpp
index d6d37ad2849,e87d87419d0..66347a59752
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@@ -1017,15 -1017,12 +1017,16 @@@ static void sync_mesh_fluid_motion(BL::
}
}
- void BlenderSync::sync_mesh(BL::Depsgraph b_depsgraph,
- BL::Object b_ob,
- Mesh *mesh,
- array<Node *> &used_shaders)
+ void BlenderSync::sync_mesh(BL::Depsgraph b_depsgraph, BL::Object b_ob, Mesh *mesh)
{
+ if (mesh->get_time_stamp() == b_depsgraph.scene().frame_current()) {
+ return;
+ }
+
+ /* make a copy of the shaders as the caller in the main thread still need them for syncing the
+ * attributes */
+ array<Node *> used_shaders = mesh->get_used_shaders();
+
Mesh new_mesh;
new_mesh.set_used_shaders(used_shaders);
diff --cc intern/cycles/blender/blender_object.cpp
index d0ff7aa67f2,4a70cbbf41f..0315097ae47
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@@ -339,81 -341,134 +343,207 @@@ Object *BlenderSync::sync_object(BL::De
return object;
}
+ /* This function mirrors drw_uniform_property_lookup in draw_instance_data.cpp */
+ static bool lookup_property(BL::ID b_id, const string &name, float4 *r_value)
+ {
+ PointerRNA ptr;
+ PropertyRNA *prop;
+
+ if (!RNA_path_resolve(&b_id.ptr, name.c_str(), &ptr, &prop)) {
+ return false;
+ }
+
+ PropertyType type = RNA_property_type(prop);
+ int arraylen = RNA_property_array_length(&ptr, prop);
+
+ if (arraylen == 0) {
+ float value;
+
+ if (type == PROP_FLOAT)
+ value = RNA_property_float_get(&ptr, prop);
+ else if (type == PROP_INT)
+ value = RNA_property_int_get(&ptr, prop);
+ else
+ return false;
+
+ *r_value = make_float4(value, value, value, 1.0f);
+ return true;
+ }
+ else if (type == PROP_FLOAT && arraylen <= 4) {
+ *r_value = make_float4(0.0f, 0.0f, 0.0f, 1.0f);
+ RNA_property_float_get_array(&ptr, prop, &r_value->x);
+ return true;
+ }
+
+ return false;
+ }
+
+ /* This function mirrors drw_uniform_attribute_lookup in draw_instance_data.cpp */
+ static float4 lookup_instance_property(BL::DepsgraphObjectInstance &b_instance,
+ const string &name,
+ bool use_instancer)
+ {
+ string idprop_name = string_printf("[\"%s\"]", name.c_str());
+ float4 value;
+
+ /* If requesting instance data, check the parent particle system and object. */
+ if (use_instancer && b_instance.is_instance()) {
+ BL::ParticleSystem b_psys = b_instance.particle_system();
+
+ if (b_psys) {
+ if (lookup_property(b_psys.settings(), idprop_name, &value) ||
+ lookup_property(b_psys.settings(), name, &value)) {
+ return value;
+ }
+ }
+ if (lookup_property(b_instance.parent(), idprop_name, &value) ||
+ lookup_property(b_instance.parent(), name, &value)) {
+ return value;
+ }
+ }
+
+ /* Check the object and mesh. */
+ BL::Object b_ob = b_instance.object();
+ BL::ID b_data = b_ob.data();
+
+ if (lookup_property(b_ob, idprop_name, &value) || lookup_property(b_ob, name, &value) ||
+ lookup_property(b_data, idprop_name, &value) || lookup_property(b_data, name, &value)) {
+ return value;
+ }
+
+ return make_float4(0.0f);
+ }
+
+ bool BlenderSync::sync_object_attributes(BL::DepsgraphObjectInstance &b_instance, Object *object)
+ {
+ /* Find which attributes are needed. */
+ AttributeRequestSet requests = object->get_geometry()->needed_attributes();
+
+ /* Delete attributes that became unnecessary. */
+ vector<ParamValue> &attributes = object->attributes;
+ bool changed = false;
+
+ for (int i = attributes.size() - 1; i >= 0; i--) {
+ if (!requests.find(attributes[i].name())) {
+ attributes.erase(attributes.begin() + i);
+ changed = true;
+ }
+ }
+
+ /* Update attribute values. */
+ foreach (AttributeRequest &req, requests.requests) {
+ ustring name = req.name;
+
+ std::string real_name;
+ BlenderAttributeType type = blender_attribute_name_split_type(name, &real_name);
+
+ if (type != BL::ShaderNodeAttribute::attribute_type_GEOMETRY) {
+ bool use_instancer = (type == BL::ShaderNodeAttribute::attribute_type_INSTANCER);
+ float4 value = lookup_instance_property(b_instance, real_name, use_instancer);
+
+ /* Try finding the existing attribute value. */
+ ParamValue *param = NULL;
+
+ for (size_t i = 0; i < attributes.size(); i++) {
+ if (attributes[i].name() == name) {
+ param = &attributes[i];
+ break;
+ }
+ }
+
+ /* Replace or add the value. */
+ ParamValue new_param(name, TypeDesc::TypeFloat4, 1, &value);
+ assert(new_param.datasize() == sizeof(value));
+
+ if (!param) {
+ changed = true;
+ attributes.push_back(new_param);
+ }
+ else if (memcmp(param->data(), &value, sizeof(value)) != 0) {
+ changed = true;
+ *param = new_param;
+ }
+ }
+ }
+
+ return changed;
+ }
+
/* Object Loop */
+static BL::MeshSequenceCacheModifier object_alembic_cache_find(BL::Object b_ob)
+{
+ if (b_ob.modifiers.length() > 0) {
+ BL::Modifier b_mod = b_ob.modifiers[b_ob.modifiers.length() - 1];
+
+ if (b_mod.type() == BL::Modifier::type_MESH_SEQUENCE_CACHE) {
+ return BL::MeshSequenceCacheModifier(b_mod);
+ }
+ }
+
+ return BL::MeshSequenceCacheModifier(PointerRNA_NULL);
+}
+
+void BlenderSync::sync_procedural(BL::Object &b_ob,
+ BL::MeshSequenceCacheModifier &b_mesh_cache,
+ int frame_current,
+ float motion_time)
+{
+ bool motion = motion_time != 0.0f;
+
+ if (motion) {
+ return;
+ }
+
+ BL::CacheFile cache_file = b_mesh_cache.cache_file();
+ void *cache_file_key = cache_file.ptr.data;
+
+ AlembicProcedural *p = static_cast<AlembicProcedural *>(procedural_map.find(cache_file_key));
+
+ if (!p) {
+ p = scene->create_node<AlembicProcedural>();
+ procedural_map.add(cache_file_key, p);
+ }
+ else {
+ procedural_map.used(p);
+ }
+
+ p->set_frame(static_cast<float>(frame_current));
+ if (p->frame_is_modified()) {
+ scene->procedural_manager->need_update = true;
+ }
+
+ auto absolute_path = blender_absolute_path(b_data, b_ob, b_mesh_cache.cache_file().filepath());
+
+ p->set_filepath(ustring(absolute_path));
+
+ /* if the filepath was not modified, then we have already created the objects */
+ if (!p->filepath_is_modified()) {
+ return;
+ }
+
+ Shader *default_shader = (b_ob.type() == BL::Object::type_VOLUME) ? scene->default_volume :
+ scene->default_surface;
+ /* Find shader indices. */
+ array<Node *> used_shaders;
+
+ BL::Object::material_slots_iterator slot;
+ for (b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) {
+ BL::ID b_material(slot->material());
+ find_shader(b_material, used_shaders, default_shader);
+ }
+
+ if (used_shaders.size() == 0) {
+ used_shaders.push_back_slow(default_shader);
+ }
+
+ AlembicObject *abc_object = scene->create_node<AlembicObject>();
+ abc_object->set_path(ustring(b_mesh_cache.object_path()));
+ abc_object->set_used_shaders(used_shaders);
+
+ p->objects.push_back_slow(abc_object);
+}
+
void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
BL::SpaceView3D &b_v3d,
float motion_time)
diff --cc intern/cycles/blender/blender_sync.h
index f6588ca8ad8,ccf059d7704..7fc2d05ad9b
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@@ -149,19 -149,13 +149,18 @@@ class BlenderSync
bool *use_portal,
TaskPool *geom_task_pool);
+ void sync_procedural(BL::Object &b_ob,
+ BL::MeshSequenceCacheModifier &b_mesh_cache,
+ int frame_current,
+ float motion_time);
+
+ bool sync_object_attributes(BL::DepsgraphObjectInstance &b_instance, Object *object);
+
/* Volume */
- void sync_volume(BL::Object &b_ob, Volume *volume, array<Node *> &used_shaders);
+ void sync_volume(BL::Object &b_ob, Volume *volume);
/* Mesh */
- void sync_mesh(BL::Depsgraph b_depsgraph,
- BL::Object b_ob,
- Mesh *mesh,
- array<Node *> &used_shaders);
+ void sync_mesh(BL::Depsgraph b_depsgraph, BL::Object b_ob, Mesh *mesh);
void sync_mesh_motion(BL::Depsgraph b_depsgraph, BL::Object b_ob, Mesh *mesh, int motion_step);
/* Hair */
More information about the Bf-blender-cvs
mailing list