[Bf-blender-cvs] [0bf91408093] cycles_procedural_api: cleaunp, add comments, more sensible way to check for created objects, add ownership
Kévin Dietrich
noreply at git.blender.org
Sun Dec 6 06:26:29 CET 2020
Commit: 0bf91408093fa5e3403259d5b1cbcd67c57ea18d
Author: Kévin Dietrich
Date: Thu Dec 3 18:42:41 2020 +0100
Branches: cycles_procedural_api
https://developer.blender.org/rB0bf91408093fa5e3403259d5b1cbcd67c57ea18d
cleaunp, add comments, more sensible way to check for created objects, add ownership
===================================================================
M intern/cycles/blender/blender_object.cpp
M intern/cycles/render/alembic.cpp
M intern/cycles/render/alembic.h
M intern/cycles/render/procedural.cpp
M intern/cycles/render/procedural.h
===================================================================
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index 814250207b4..c00fd0eaa5c 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -496,51 +496,49 @@ void BlenderSync::sync_procedural(BL::Object &b_ob,
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));
+ AlembicProcedural *procedural = static_cast<AlembicProcedural *>(
+ procedural_map.find(cache_file_key));
- if (!p) {
- p = scene->create_node<AlembicProcedural>();
- procedural_map.add(cache_file_key, p);
+ if (procedural == nullptr) {
+ procedural = scene->create_node<AlembicProcedural>();
+ procedural_map.add(cache_file_key, procedural);
}
else {
- procedural_map.used(p);
+ procedural_map.used(procedural);
}
- p->set_frame(static_cast<float>(frame_current));
- p->set_frame_rate(b_scene.render().fps() / b_scene.render().fps_base());
- p->set_default_curves_radius(cache_file.default_curves_radius());
+ procedural->set_frame(static_cast<float>(frame_current));
+ procedural->set_frame_rate(b_scene.render().fps() / b_scene.render().fps_base());
+ procedural->set_default_curves_radius(cache_file.default_curves_radius());
- auto absolute_path = blender_absolute_path(b_data, b_ob, b_mesh_cache.cache_file().filepath());
+ string absolute_path = blender_absolute_path(b_data, b_ob, b_mesh_cache.cache_file().filepath());
+ procedural->set_filepath(ustring(absolute_path));
- p->set_filepath(ustring(absolute_path));
+ ustring object_path = ustring(b_mesh_cache.object_path());
- p->tag_update(scene);
+ 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;
- /* if the filepath was not modified, then we have already created the objects */
- if (!p->filepath_is_modified()) {
- return;
- }
+ 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);
+ }
- Shader *default_shader = (b_ob.type() == BL::Object::type_VOLUME) ? scene->default_volume :
- scene->default_surface;
- /* Find shader indices. */
- array<Node *> used_shaders;
+ if (used_shaders.size() == 0) {
+ used_shaders.push_back_slow(default_shader);
+ }
- 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);
- }
+ AlembicObject *abc_object = procedural->create_node<AlembicObject>();
+ abc_object->set_path(object_path);
+ abc_object->set_used_shaders(used_shaders);
- if (used_shaders.size() == 0) {
- used_shaders.push_back_slow(default_shader);
+ procedural->add_object(abc_object);
}
- 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->add_object(abc_object);
+ procedural->tag_update(scene);
#else
(void)b_ob;
(void)b_mesh_cache;
diff --git a/intern/cycles/render/alembic.cpp b/intern/cycles/render/alembic.cpp
index 0214054d7ea..ff1f9390272 100644
--- a/intern/cycles/render/alembic.cpp
+++ b/intern/cycles/render/alembic.cpp
@@ -41,7 +41,7 @@ CCL_NAMESPACE_BEGIN
/* TODO(@kevindietrich): arrays are emptied when passed to the sockets, so for now we copy the
* arrays to avoid reloading the data */
-static float3 make_float3_from_yup(const Imath::Vec3<float> &v)
+static float3 make_float3_from_yup(const V3f &v)
{
return make_float3(v.x, -v.z, v.y);
}
@@ -59,13 +59,10 @@ static M44d convert_yup_zup(const M44d &mtx)
return scale_mat * rot_mat * trans_mat;
}
-static void transform_decompose(const Imath::M44d &mat,
- Imath::V3d &scale,
- Imath::V3d &shear,
- Imath::Quatd &rotation,
- Imath::V3d &translation)
+static void transform_decompose(
+ const M44d &mat, V3d &scale, V3d &shear, Quatd &rotation, V3d &translation)
{
- Imath::M44d mat_remainder(mat);
+ M44d mat_remainder(mat);
/* extract scale and shear */
Imath::extractAndRemoveScalingAndShear(mat_remainder, scale, shear);
@@ -79,12 +76,12 @@ static void transform_decompose(const Imath::M44d &mat,
rotation = extractQuat(mat_remainder);
}
-static M44d transform_compose(const Imath::V3d &scale,
- const Imath::V3d &shear,
- const Imath::Quatd &rotation,
- const Imath::V3d &translation)
+static M44d transform_compose(const V3d &scale,
+ const V3d &shear,
+ const Quatd &rotation,
+ const V3d &translation)
{
- Imath::M44d scale_mat, shear_mat, rot_mat, trans_mat;
+ M44d scale_mat, shear_mat, rot_mat, trans_mat;
scale_mat.setScale(scale);
shear_mat.setShear(shear);
@@ -206,62 +203,61 @@ static Transform make_transform(const M44d &a)
return trans;
}
-static void read_default_uvs(const IV2fGeomParam &uvs, CachedData &cached_data)
+static void add_uvs(const IV2fGeomParam &uvs, CachedData &cached_data, Progress &progress)
{
- CachedData::CachedAttribute &attr = cached_data.add_attribute(ustring(uvs.getName()));
+ if (uvs.getScope() != kFacevaryingScope) {
+ return;
+ }
- for (size_t i = 0; i < uvs.getNumSamples(); ++i) {
- const ISampleSelector iss = ISampleSelector(index_t(i));
- const IV2fGeomParam::Sample sample = uvs.getExpandedValue(iss);
+ const TimeSamplingPtr time_sampling = uvs.getTimeSampling();
- const double time = uvs.getTimeSampling()->getSampleTime(index_t(i));
+ CachedData::CachedAttribute &attr = cached_data.add_attribute(ustring(uvs.getName()),
+ *time_sampling);
+ attr.std = ATTR_STD_UV;
- switch (uvs.getScope()) {
- case kFacevaryingScope: {
- const IV2fGeomParam::Sample uvsample = uvs.getIndexedValue(iss);
+ for (size_t i = 0; i < uvs.getNumSamples(); ++i) {
+ if (progress.get_cancel()) {
+ return;
+ }
- if (!uvsample.valid()) {
- continue;
- }
+ const ISampleSelector iss = ISampleSelector(index_t(i));
+ const IV2fGeomParam::Sample sample = uvs.getExpandedValue(iss);
- const array<int3> *triangles = cached_data.triangles.data_for_time_no_check(time);
- const array<int3> *triangles_loops = cached_data.triangles_loops.data_for_time_no_check(
- time);
+ const double time = time_sampling->getSampleTime(index_t(i));
- if (!triangles || !triangles_loops) {
- continue;
- }
+ const IV2fGeomParam::Sample uvsample = uvs.getIndexedValue(iss);
- attr.std = ATTR_STD_UV;
+ if (!uvsample.valid()) {
+ continue;
+ }
- array<char> data;
- data.resize(triangles->size() * 3 * sizeof(float2));
+ const array<int3> *triangles = cached_data.triangles.data_for_time_no_check(time);
+ const array<int3> *triangles_loops = cached_data.triangles_loops.data_for_time_no_check(time);
- float2 *data_float2 = reinterpret_cast<float2 *>(data.data());
+ if (!triangles || !triangles_loops) {
+ continue;
+ }
- const unsigned int *indices = uvsample.getIndices()->get();
- const V2f *values = uvsample.getVals()->get();
+ array<char> data;
+ data.resize(triangles->size() * 3 * sizeof(float2));
- for (const int3 &loop : *triangles_loops) {
- unsigned int v0 = indices[loop.x];
- unsigned int v1 = indices[loop.y];
- unsigned int v2 = indices[loop.z];
+ float2 *data_float2 = reinterpret_cast<float2 *>(data.data());
- data_float2[0] = make_float2(values[v0][0], values[v0][1]);
- data_float2[1] = make_float2(values[v1][0], values[v1][1]);
- data_float2[2] = make_float2(values[v2][0], values[v2][1]);
- data_float2 += 3;
- }
+ const unsigned int *indices = uvsample.getIndices()->get();
+ const V2f *values = uvsample.getVals()->get();
- attr.data.add_data(data, time);
+ for (const int3 &loop : *triangles_loops) {
+ unsigned int v0 = indices[loop.x];
+ unsigned int v1 = indices[loop.y];
+ unsigned int v2 = indices[loop.z];
- break;
- }
- default: {
- // not supported
- break;
- }
+ data_float2[0] = make_float2(values[v0][0], values[v0][1]);
+ data_float2[1] = make_float2(values[v1][0], values[v1][1]);
+ data_float2[2] = make_float2(values[v2][0], values[v2][1]);
+ data_float2 += 3;
}
+
+ attr.data.add_data(data, time);
}
}
@@ -270,7 +266,6 @@ static void add_normals(const Int32ArraySamplePtr face_indices,
double time,
CachedData &cached_data)
{
-
switch (normals.getScope()) {
case kFacevaryingScope: {
const ISampleSelector iss = ISampleSelector(time);
@@ -280,7 +275,8 @@ static void add_normals(const Int32ArraySamplePtr face_indices,
return;
}
- CachedData::CachedAttribute &attr = cached_data.add_attribute(ustring(normals.getName()));
+ CachedData::CachedAttribute &attr = cached_data.add_attribute(ustring(normals.getName()),
+ *normals.getTimeSampling());
attr.std = ATTR_STD_VERTEX_NORMAL;
const array<float3> *vertices = cached_data.vertices.data_for_time_no_check(time);
@@ -319,7 +315,8 @@ static void add_normals(const Int32ArraySamplePtr
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list