[Bf-blender-cvs] [ce86599fab1] cycles_procedural_api: make sure data is updated when editing shaders
Kévin Dietrich
noreply at git.blender.org
Sun Dec 6 06:26:30 CET 2020
Commit: ce86599fab10a40d4be986f078e7f3d19c6b7775
Author: Kévin Dietrich
Date: Fri Dec 4 18:45:54 2020 +0100
Branches: cycles_procedural_api
https://developer.blender.org/rBce86599fab10a40d4be986f078e7f3d19c6b7775
make sure data is updated when editing shaders
===================================================================
M intern/cycles/blender/blender_geometry.cpp
M intern/cycles/blender/blender_object.cpp
M intern/cycles/blender/blender_sync.h
M intern/cycles/render/alembic.cpp
M intern/cycles/render/alembic.h
M intern/cycles/render/scene.cpp
M intern/cycles/render/shader.cpp
===================================================================
diff --git a/intern/cycles/blender/blender_geometry.cpp b/intern/cycles/blender/blender_geometry.cpp
index 99df8b7b1c9..f4728db06ee 100644
--- a/intern/cycles/blender/blender_geometry.cpp
+++ b/intern/cycles/blender/blender_geometry.cpp
@@ -42,23 +42,13 @@ static Geometry::Type determine_geom_type(BL::Object &b_ob, bool use_particle_ha
return Geometry::MESH;
}
-Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
- BL::Object &b_ob,
- BL::Object &b_ob_instance,
- bool object_updated,
- bool use_particle_hair,
- TaskPool *task_pool)
+array<Node *> BlenderSync::find_used_shaders(BL::Object &b_ob)
{
- /* Test if we can instance or if the object is modified. */
- BL::ID b_ob_data = b_ob.data();
- BL::ID b_key_id = (BKE_object_is_modified(b_ob)) ? b_ob_instance : b_ob_data;
BL::Material material_override = view_layer.material_override;
+
Shader *default_shader = (b_ob.type() == BL::Object::type_VOLUME) ? scene->default_volume :
scene->default_surface;
- Geometry::Type geom_type = determine_geom_type(b_ob, use_particle_hair);
- GeometryKey key(b_key_id.ptr.data, geom_type);
- /* Find shader indices. */
array<Node *> used_shaders;
BL::Object::material_slots_iterator slot;
@@ -79,6 +69,25 @@ Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
used_shaders.push_back_slow(default_shader);
}
+ return used_shaders;
+}
+
+Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
+ BL::Object &b_ob,
+ BL::Object &b_ob_instance,
+ bool object_updated,
+ bool use_particle_hair,
+ TaskPool *task_pool)
+{
+ /* Test if we can instance or if the object is modified. */
+ BL::ID b_ob_data = b_ob.data();
+ BL::ID b_key_id = (BKE_object_is_modified(b_ob)) ? b_ob_instance : b_ob_data;
+ Geometry::Type geom_type = determine_geom_type(b_ob, use_particle_hair);
+ GeometryKey key(b_key_id.ptr.data, geom_type);
+
+ /* Find shader indices. */
+ array<Node *> used_shaders = find_used_shaders(b_ob);
+
/* Ensure we only sync instanced geometry once. */
Geometry *geom = geometry_map.find(key);
if (geom) {
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index abda51c6fdc..95deb12480b 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -514,36 +514,22 @@ void BlenderSync::sync_procedural(BL::Object &b_ob,
string absolute_path = blender_absolute_path(b_data, b_ob, b_mesh_cache.cache_file().filepath());
procedural->set_filepath(ustring(absolute_path));
+ /* create or update existing AlembicObjects */
ustring object_path = ustring(b_mesh_cache.object_path());
- if (!procedural->has_object(object_path)) {
- Shader *default_shader = (b_ob.type() == BL::Object::type_VOLUME) ? scene->default_volume :
- scene->default_surface;
- array<Node *> used_shaders;
+ AlembicObject *abc_object = procedural->get_or_create_object(object_path);
- 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 = procedural->create_node<AlembicObject>();
- abc_object->set_path(object_path);
- abc_object->set_used_shaders(used_shaders);
+ array<Node *> used_shaders = find_used_shaders(b_ob);
+ abc_object->set_used_shaders(used_shaders);
- PointerRNA cobj = RNA_pointer_get(&b_ob.ptr, "cycles");
- const float subd_dicing_rate = max(0.1f, RNA_float_get(&cobj, "dicing_rate") * dicing_rate);
- abc_object->set_subd_dicing_rate(subd_dicing_rate);
- abc_object->set_subd_max_level(max_subdivisions);
+ PointerRNA cobj = RNA_pointer_get(&b_ob.ptr, "cycles");
+ const float subd_dicing_rate = max(0.1f, RNA_float_get(&cobj, "dicing_rate") * dicing_rate);
+ abc_object->set_subd_dicing_rate(subd_dicing_rate);
+ abc_object->set_subd_max_level(max_subdivisions);
- procedural->add_object(abc_object);
+ if (abc_object->is_modified() || procedural->is_modified()) {
+ procedural->tag_update(scene);
}
-
- procedural->tag_update(scene);
#else
(void)b_ob;
(void)b_mesh_cache;
diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h
index 7fc2d05ad9b..fb71fab7f56 100644
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@ -134,6 +134,7 @@ class BlenderSync {
void sync_view();
/* Shader */
+ array<Node *> find_used_shaders(BL::Object &b_ob);
void sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all);
void sync_shaders(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d);
void sync_nodes(Shader *shader, BL::ShaderNodeTree &b_ntree);
diff --git a/intern/cycles/render/alembic.cpp b/intern/cycles/render/alembic.cpp
index 3244a767372..44ae71af44c 100644
--- a/intern/cycles/render/alembic.cpp
+++ b/intern/cycles/render/alembic.cpp
@@ -453,6 +453,35 @@ bool AlembicObject::has_data_loaded() const
return data_loaded;
}
+void AlembicObject::update_shader_attributes(const ICompoundProperty &arb_geom_params,
+ Progress &progress)
+{
+ AttributeRequestSet requested_attributes = get_requested_attributes();
+
+ foreach (const AttributeRequest &attr, requested_attributes.requests) {
+ if (progress.get_cancel()) {
+ return;
+ }
+
+ bool attr_exists = false;
+ foreach (CachedData::CachedAttribute &cached_attr, cached_data.attributes) {
+ if (cached_attr.name == attr.name) {
+ attr_exists = true;
+ break;
+ }
+ }
+
+ if (attr_exists) {
+ continue;
+ }
+
+ read_attribute(arb_geom_params, attr.name, progress);
+ }
+
+ cached_data.invalidate_last_loaded_time(true);
+ need_shader_update = false;
+}
+
template<typename SchemaType>
void AlembicObject::read_face_sets(SchemaType &schema, array<int> &polygon_to_shader)
{
@@ -516,8 +545,6 @@ void AlembicObject::load_all_data(IPolyMeshSchema &schema, Progress &progress)
{
cached_data.clear();
- AttributeRequestSet requested_attributes = get_requested_attributes();
-
const TimeSamplingPtr time_sampling = schema.getTimeSampling();
cached_data.vertices.set_time_sampling(*time_sampling);
cached_data.triangles.set_time_sampling(*time_sampling);
@@ -553,16 +580,14 @@ void AlembicObject::load_all_data(IPolyMeshSchema &schema, Progress &progress)
if (normals.valid()) {
add_normals(sample.getFaceIndices(), normals, time, cached_data);
}
+ }
- foreach (const AttributeRequest &attr, requested_attributes.requests) {
- if (progress.get_cancel()) {
- return;
- }
-
- read_attribute(schema.getArbGeomParams(), iss, attr.name);
- }
+ if (progress.get_cancel()) {
+ return;
}
+ update_shader_attributes(schema.getArbGeomParams(), progress);
+
if (progress.get_cancel()) {
return;
}
@@ -713,10 +738,10 @@ void AlembicObject::load_all_data(ISubDSchema &schema, Progress &progress)
cached_data.subd_creases_edge.add_data(creases_edge, time);
cached_data.subd_creases_weight.add_data(creases_weight, time);
}
-
- /* TODO(@kevindietrich) : attributes, need test files */
}
+ /* TODO(@kevindietrich) : attributes, need test files */
+
if (progress.get_cancel()) {
return;
}
@@ -799,7 +824,7 @@ void AlembicObject::load_all_data(const ICurvesSchema &schema,
cached_data.curve_shader.add_data(curve_shader, time);
}
- // TODO(@kevindietrich): attributes, but I need example files
+ // TODO(@kevindietrich): attributes, need example files
setup_transform_cache();
@@ -849,7 +874,6 @@ AttributeRequestSet AlembicObject::get_requested_attributes()
Geometry *geometry = object->get_geometry();
assert(geometry);
- // TODO(@kevindietrich) : check for attribute changes in the shaders
foreach (Node *node, geometry->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(node);
@@ -864,11 +888,9 @@ AttributeRequestSet AlembicObject::get_requested_attributes()
}
void AlembicObject::read_attribute(const ICompoundProperty &arb_geom_params,
- const ISampleSelector &iss,
- const ustring &attr_name)
+ const ustring &attr_name,
+ Progress &progress)
{
- const index_t index = iss.getRequestedIndex();
-
const PropertyHeader *prop = arb_geom_params.getPropertyHeader(attr_name.c_str());
if (prop == nullptr) {
@@ -878,144 +900,168 @@ void AlembicObject::read_attribute(const ICompoundProperty &arb_geom_params,
if (IV2fProperty::matches(prop->getMetaData()) && Alembic::AbcGeom::isUV(*prop)) {
const IV2fGeomParam ¶m = IV2fGeomParam(arb_geom_params, prop->getName());
- IV2fGeomParam::Sample sample;
- param.getIndexed(sample, iss);
-
CachedData::CachedAttribute &attribute = cached_data.add_attribute(attr_name,
*param.getTimeSampling());
- const chrono_t time = param.getTimeSampling()->getSampleTime(index);
+ for (size_t i = 0; i < param.getNumSamples(); ++i) {
+ if (progress.get_cancel()) {
+ return;
+ }
+
+ ISampleSelector iss = ISampleSelector(index_t(i));
- if (param.getScope() == kFacevaryingScope) {
- V2fArraySamplePtr values = sample.getVals();
- UInt32ArraySamplePtr indices = sample.getIndices();
+ IV2fGeomParam::Sample sample;
+ param.g
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list