[Bf-blender-cvs] [e8ff90b3bbf] cycles_procedural_api: add alembic procedural code
Kévin Dietrich
noreply at git.blender.org
Mon Sep 7 05:03:34 CEST 2020
Commit: e8ff90b3bbfd8bc4940ba427ae4c0b061d0e270a
Author: Kévin Dietrich
Date: Tue Sep 1 04:04:59 2020 +0200
Branches: cycles_procedural_api
https://developer.blender.org/rBe8ff90b3bbfd8bc4940ba427ae4c0b061d0e270a
add alembic procedural code
===================================================================
M intern/cycles/blender/CMakeLists.txt
M intern/cycles/blender/blender_object.cpp
M intern/cycles/blender/blender_sync.cpp
M intern/cycles/blender/blender_sync.h
M intern/cycles/render/CMakeLists.txt
A intern/cycles/render/alembic.cpp
A intern/cycles/render/alembic.h
A intern/cycles/render/procedural.cpp
A intern/cycles/render/procedural.h
M intern/cycles/render/scene.cpp
M intern/cycles/render/scene.h
===================================================================
diff --git a/intern/cycles/blender/CMakeLists.txt b/intern/cycles/blender/CMakeLists.txt
index 0d805dc8683..7d1b695434e 100644
--- a/intern/cycles/blender/CMakeLists.txt
+++ b/intern/cycles/blender/CMakeLists.txt
@@ -24,6 +24,7 @@ set(INC
)
set(INC_SYS
+ ${ALEMBIC_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}
${GLEW_INCLUDE_DIR}
)
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index 3fbab9ca377..6a1524d8ef5 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -29,6 +29,8 @@
#include "blender/blender_sync.h"
#include "blender/blender_util.h"
+#include "render/alembic.h"
+
#include "util/util_foreach.h"
#include "util/util_hash.h"
#include "util/util_logging.h"
@@ -327,6 +329,84 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph,
/* Object Loop */
+static bool object_has_alembic_cache(BL::Object b_ob)
+{
+ /* Test if the object has a mesh sequence modifier. */
+ BL::Object::modifiers_iterator b_mod;
+ for (b_ob.modifiers.begin(b_mod); b_mod != b_ob.modifiers.end(); ++b_mod) {
+ if ((b_mod->type() == b_mod->type_MESH_SEQUENCE_CACHE)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void BlenderSync::sync_procedural(BL::Object b_ob, int frame_current, float motion_time)
+{
+ bool motion = motion_time != 0.0f;
+
+ // return for now
+ if (motion) {
+ return;
+ }
+
+ ObjectKey key(b_ob.parent(), NULL, b_ob, false);
+
+ AlembicProcedural *p = static_cast<AlembicProcedural *>(procedural_map.find(key));
+
+ if (!p) {
+ p = scene->create_node<AlembicProcedural>();
+ procedural_map.add(key, p);
+ }
+ else {
+ procedural_map.used(p);
+ }
+
+ p->set_current_frame(scene, static_cast<float>(frame_current));
+
+ // check if it was already created (for synchronisation during interactive rendering)
+ if (p->objects.size()) {
+ return;
+ }
+
+ Shader *default_shader = (b_ob.type() == BL::Object::type_VOLUME) ? scene->default_volume :
+ scene->default_surface;
+ /* Find shader indices. */
+ array<Shader *> 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);
+ }
+
+ BL::Object::modifiers_iterator b_mod;
+ for (b_ob.modifiers.begin(b_mod); b_mod != b_ob.modifiers.end(); ++b_mod) {
+ if ((b_mod->type() == b_mod->type_MESH_SEQUENCE_CACHE)) {
+ BL::MeshSequenceCacheModifier mcmd((const PointerRNA)b_mod->ptr);
+
+ auto absolute_path = blender_absolute_path(b_data, b_ob, mcmd.cache_file().filepath());
+
+ if (p->filepath != absolute_path) {
+ p->filepath = absolute_path;
+
+ AlembicObject *abc_object = scene->create_node<AlembicObject>();
+ abc_object->path = mcmd.object_path();
+ abc_object->shader = used_shaders[0];
+
+ p->objects.push_back_slow(abc_object);
+ }
+
+ break;
+ }
+ }
+}
+
void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
BL::SpaceView3D &b_v3d,
float motion_time)
@@ -339,6 +419,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
light_map.pre_sync();
geometry_map.pre_sync();
object_map.pre_sync();
+ procedural_map.pre_sync();
particle_system_map.pre_sync();
motion_times.clear();
}
@@ -374,14 +455,19 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
/* Object itself. */
if (b_instance.show_self()) {
- sync_object(b_depsgraph,
- b_view_layer,
- b_instance,
- motion_time,
- false,
- show_lights,
- culling,
- &use_portal);
+ if (object_has_alembic_cache(b_ob)) {
+ sync_procedural(b_ob, b_depsgraph.scene().frame_current(), motion_time);
+ }
+ else {
+ sync_object(b_depsgraph,
+ b_view_layer,
+ b_instance,
+ motion_time,
+ false,
+ show_lights,
+ culling,
+ &use_portal);
+ }
}
/* Particle hair as separate object. */
@@ -409,6 +495,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
geometry_map.post_sync(scene);
object_map.post_sync(scene);
particle_system_map.post_sync(scene);
+ procedural_map.post_sync(scene);
}
if (motion)
diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index a34ec38e85c..91fecc23263 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -24,6 +24,7 @@
#include "render/mesh.h"
#include "render/nodes.h"
#include "render/object.h"
+#include "render/procedural.h"
#include "render/scene.h"
#include "render/shader.h"
@@ -57,6 +58,7 @@ BlenderSync::BlenderSync(BL::RenderEngine &b_engine,
b_scene(b_scene),
shader_map(),
object_map(),
+ procedural_map(),
geometry_map(),
light_map(),
particle_system_map(),
diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h
index dd7a56b35ba..b493880b4a3 100644
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@ -220,6 +220,7 @@ class BlenderSync {
id_map<void *, Shader> shader_map;
id_map<ObjectKey, Object> object_map;
+ id_map<ObjectKey, Procedural> procedural_map;
id_map<GeometryKey, Geometry> geometry_map;
id_map<ObjectKey, Light> light_map;
id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
diff --git a/intern/cycles/render/CMakeLists.txt b/intern/cycles/render/CMakeLists.txt
index 43e66aa4e5b..33d486a34e2 100644
--- a/intern/cycles/render/CMakeLists.txt
+++ b/intern/cycles/render/CMakeLists.txt
@@ -19,10 +19,12 @@ set(INC
)
set(INC_SYS
+ ${ALEMBIC_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}
)
set(SRC
+ alembic.cpp
attribute.cpp
background.cpp
bake.cpp
@@ -48,6 +50,7 @@ set(SRC
mesh_displace.cpp
mesh_subdivision.cpp
nodes.cpp
+ procedural.cpp
object.cpp
osl.cpp
particles.cpp
@@ -64,6 +67,7 @@ set(SRC
)
set(SRC_HEADERS
+ alembic.h
attribute.h
bake.h
background.h
@@ -90,6 +94,7 @@ set(SRC_HEADERS
object.h
osl.h
particles.h
+ procedural.h
curves.h
scene.h
session.h
diff --git a/intern/cycles/render/alembic.cpp b/intern/cycles/render/alembic.cpp
new file mode 100644
index 00000000000..642643cdeba
--- /dev/null
+++ b/intern/cycles/render/alembic.cpp
@@ -0,0 +1,440 @@
+/*
+ * Copyright 2011-2018 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "alembic.h"
+
+#include <algorithm>
+#include <fnmatch.h>
+#include <iterator>
+#include <set>
+#include <sstream>
+#include <stack>
+#include <stdio.h>
+#include <vector>
+
+#include "render/camera.h"
+#include "render/curves.h"
+#include "render/mesh.h"
+#include "render/object.h"
+#include "render/scene.h"
+#include "render/shader.h"
+
+#include "util/util_foreach.h"
+#include "util/util_transform.h"
+#include "util/util_vector.h"
+
+CCL_NAMESPACE_BEGIN
+
+static float3 make_float3_from_yup(Imath::Vec3<float> const &v)
+{
+ return make_float3(v.x, -v.z, v.y);
+}
+
+static M44d convert_yup_zup(M44d const &mtx)
+{
+ Imath::Vec3<double> scale, shear, rot, trans;
+ extractSHRT(mtx, scale, shear, rot, trans);
+ M44d rotmat, scalemat, transmat;
+ rotmat.setEulerAngles(Imath::Vec3<double>(rot.x, -rot.z, rot.y));
+ scalemat.setScale(Imath::Vec3<double>(scale.x, scale.z, scale.y));
+ transmat.setTranslation(Imath::Vec3<double>(trans.x, -trans.z, trans.y));
+ return scalemat * rotmat * transmat;
+}
+
+static Transform make_transform(const Abc::M44d &a)
+{
+ auto m = convert_yup_zup(a);
+ Transform trans;
+ for (int j = 0; j < 3; j++) {
+ for (int i = 0; i < 4; i++) {
+ trans[j][i] = static_cast<float>(m[i][j]);
+ }
+ }
+ return trans;
+}
+
+/* TODO: any attribute lookup should probably go through the AttributeRequests
+ */
+static void read_uvs(const IV2fGeomParam &uvs, Geometry *node, const int *face_counts, const int num_faces)
+{
+ if (uvs.valid()) {
+ switch (uvs.getScope()) {
+ case kVaryingScope:
+ case kVertexScope:
+ {
+ IV2fGeomParam::Sample uvsample = uvs.getExpandedValue();
+ break;
+ }
+ case kFacevaryingScope:
+ {
+ IV2fGeomParam::Sample uvsample = uvs.getIndexedValue();
+
+ ustring name = ustring("UVMap");
+ Attribute *attr = node->attributes.add(ATTR_STD_UV, name);
+ float2 *fdata = attr->data_float2();
+
+ /* loop over the triangles */
+ int index_offset = 0;
+ const unsigned int *uvIndices = uvsample.getIndices()->get();
+ const Imath::Vec2<float> *uvValues = uvsample.getVals()->get();
+
+ for (size_t i = 0; i < num_faces; i++) {
+ for (int j = 0; j < face_counts[i] - 2; j++) {
+ int v0 = uvIndices[index_offset];
+ int v1 = uvIndices[index_offset + j + 1];
+ int v2 = uvIndices[index_offset + j + 2];
+
+ fdata[0] = make_float2(uvValues[v0][0], uvValues[v0][1]);
+ fdata[1] = make_float2(uvValues[v1][0], uvValues[v1][1]);
+ fdata[2] = make_float2(uvValues[v2][0], uvValues[v2][1]);
+ fdata += 3;
+ }
+
+ index_offset += face_cou
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list