[Bf-blender-cvs] [47402dcb916] master: Cleanup: split Cycles export into smaller files

Brecht Van Lommel noreply at git.blender.org
Fri Feb 7 12:22:01 CET 2020


Commit: 47402dcb9160793fcfd87ea3c6e6685ea6954b3f
Author: Brecht Van Lommel
Date:   Sun Feb 2 13:09:18 2020 +0100
Branches: master
https://developer.blender.org/rB47402dcb9160793fcfd87ea3c6e6685ea6954b3f

Cleanup: split Cycles export into smaller files

===================================================================

M	intern/cycles/blender/CMakeLists.txt
M	intern/cycles/blender/blender_curves.cpp
A	intern/cycles/blender/blender_geometry.cpp
A	intern/cycles/blender/blender_id_map.h
A	intern/cycles/blender/blender_image.cpp
A	intern/cycles/blender/blender_light.cpp
M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/blender/blender_object.cpp
M	intern/cycles/blender/blender_object_cull.cpp
M	intern/cycles/blender/blender_python.cpp
M	intern/cycles/blender/blender_session.cpp
M	intern/cycles/blender/blender_sync.h
M	intern/cycles/blender/blender_util.h
A	intern/cycles/blender/blender_volume.cpp

===================================================================

diff --git a/intern/cycles/blender/CMakeLists.txt b/intern/cycles/blender/CMakeLists.txt
index 0888eeb78bb..d9a2ebf8571 100644
--- a/intern/cycles/blender/CMakeLists.txt
+++ b/intern/cycles/blender/CMakeLists.txt
@@ -18,6 +18,9 @@ set(INC_SYS
 set(SRC
   blender_camera.cpp
   blender_device.cpp
+  blender_image.cpp
+  blender_geometry.cpp
+  blender_light.cpp
   blender_mesh.cpp
   blender_object.cpp
   blender_object_cull.cpp
@@ -30,9 +33,11 @@ set(SRC
   blender_sync.cpp
   blender_texture.cpp
   blender_viewport.cpp
+  blender_volume.cpp
 
   CCL_api.h
   blender_device.h
+  blender_id_map.h
   blender_object_cull.h
   blender_sync.h
   blender_session.h
diff --git a/intern/cycles/blender/blender_curves.cpp b/intern/cycles/blender/blender_curves.cpp
index 755214f422c..64efaab70e0 100644
--- a/intern/cycles/blender/blender_curves.cpp
+++ b/intern/cycles/blender/blender_curves.cpp
@@ -1160,6 +1160,63 @@ void BlenderSync::sync_particle_hair(
   }
 
   mesh->compute_bounds();
+  mesh->geometry_flags |= Mesh::GEOMETRY_CURVES;
+}
+
+void BlenderSync::sync_hair(BL::Depsgraph b_depsgraph, BL::Object b_ob, Mesh *mesh)
+{
+  /* compares curve_keys rather than strands in order to handle quick hair
+   * adjustments in dynamic BVH - other methods could probably do this better*/
+  array<float3> oldcurve_keys;
+  array<float> oldcurve_radius;
+  oldcurve_keys.steal_data(mesh->curve_keys);
+  oldcurve_radius.steal_data(mesh->curve_radius);
+
+  if (view_layer.use_hair) {
+    /* Particle hair. */
+    bool need_undeformed = mesh->need_attribute(scene, ATTR_STD_GENERATED);
+    BL::Mesh b_mesh = object_to_mesh(
+        b_data, b_ob, b_depsgraph, need_undeformed, Mesh::SUBDIVISION_NONE);
+
+    if (b_mesh) {
+      sync_particle_hair(mesh, b_mesh, b_ob, false);
+      free_object_to_mesh(b_data, b_ob, b_mesh);
+    }
+  }
+
+  /* tag update */
+  bool rebuild = (oldcurve_keys != mesh->curve_keys) || (oldcurve_radius != mesh->curve_radius);
+  mesh->tag_update(scene, rebuild);
+}
+
+void BlenderSync::sync_hair_motion(BL::Depsgraph b_depsgraph,
+                                   BL::Object b_ob,
+                                   Mesh *mesh,
+                                   int motion_step)
+{
+  /* Skip if no curves were exported. */
+  size_t numkeys = mesh->curve_keys.size();
+  if (numkeys == 0) {
+    return;
+  }
+
+  /* Export deformed coordinates. */
+  if (ccl::BKE_object_is_deform_modified(b_ob, b_scene, preview)) {
+    /* Particle hair. */
+    BL::Mesh b_mesh = object_to_mesh(b_data, b_ob, b_depsgraph, false, Mesh::SUBDIVISION_NONE);
+    if (b_mesh) {
+      sync_particle_hair(mesh, b_mesh, b_ob, true, motion_step);
+      free_object_to_mesh(b_data, b_ob, b_mesh);
+      return;
+    }
+  }
+
+  /* No deformation on this frame, copy coordinates if other frames did have it. */
+  Attribute *attr_mP = mesh->curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
+  if (attr_mP) {
+    float3 *keys = &mesh->curve_keys[0];
+    memcpy(attr_mP->data_float3() + motion_step * numkeys, keys, sizeof(float3) * numkeys);
+  }
 }
 
 CCL_NAMESPACE_END
diff --git a/intern/cycles/blender/blender_geometry.cpp b/intern/cycles/blender/blender_geometry.cpp
new file mode 100644
index 00000000000..151b741b003
--- /dev/null
+++ b/intern/cycles/blender/blender_geometry.cpp
@@ -0,0 +1,146 @@
+
+/*
+ * Copyright 2011-2013 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 "render/mesh.h"
+#include "render/object.h"
+
+#include "blender/blender_sync.h"
+#include "blender/blender_util.h"
+
+CCL_NAMESPACE_BEGIN
+
+Mesh *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph,
+                                 BL::Object &b_ob,
+                                 BL::Object &b_ob_instance,
+                                 bool object_updated,
+                                 bool use_particle_hair)
+{
+  /* 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;
+  MeshKey key(b_key_id.ptr.data, use_particle_hair);
+  BL::Material material_override = view_layer.material_override;
+  Shader *default_shader = scene->default_surface;
+
+  /* Find shader indices. */
+  vector<Shader *> used_shaders;
+
+  BL::Object::material_slots_iterator slot;
+  for (b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) {
+    if (material_override) {
+      find_shader(material_override, used_shaders, default_shader);
+    }
+    else {
+      BL::ID b_material(slot->material());
+      find_shader(b_material, used_shaders, default_shader);
+    }
+  }
+
+  if (used_shaders.size() == 0) {
+    if (material_override)
+      find_shader(material_override, used_shaders, default_shader);
+    else
+      used_shaders.push_back(default_shader);
+  }
+
+  /* Test if we need to sync. */
+  Mesh *mesh;
+
+  if (!mesh_map.sync(&mesh, b_key_id, key)) {
+    /* If transform was applied to mesh, need full update. */
+    if (object_updated && mesh->transform_applied)
+      ;
+    /* Test if shaders changed, these can be object level so mesh
+     * does not get tagged for recalc. */
+    else if (mesh->used_shaders != used_shaders)
+      ;
+    else {
+      /* Even if not tagged for recalc, we may need to sync anyway
+       * because the shader needs different mesh attributes. */
+      bool attribute_recalc = false;
+
+      foreach (Shader *shader, mesh->used_shaders)
+        if (shader->need_update_mesh)
+          attribute_recalc = true;
+
+      if (!attribute_recalc)
+        return mesh;
+    }
+  }
+
+  /* Ensure we only sync instanced meshes once. */
+  if (mesh_synced.find(mesh) != mesh_synced.end())
+    return mesh;
+
+  progress.set_sync_status("Synchronizing object", b_ob.name());
+
+  mesh_synced.insert(mesh);
+
+  mesh->clear();
+  mesh->used_shaders = used_shaders;
+  mesh->name = ustring(b_ob_data.name().c_str());
+
+  if (use_particle_hair) {
+    sync_hair(b_depsgraph, b_ob, mesh);
+  }
+  else if (object_fluid_gas_domain_find(b_ob)) {
+    sync_volume(b_ob, mesh);
+  }
+  else {
+    sync_mesh(b_depsgraph, b_ob, mesh);
+  }
+
+  return mesh;
+}
+
+void BlenderSync::sync_geometry_motion(BL::Depsgraph &b_depsgraph,
+                                       BL::Object &b_ob,
+                                       Object *object,
+                                       float motion_time,
+                                       bool use_particle_hair)
+{
+  /* Ensure we only sync instanced meshes once. */
+  Mesh *mesh = object->mesh;
+
+  if (mesh_motion_synced.find(mesh) != mesh_motion_synced.end())
+    return;
+
+  mesh_motion_synced.insert(mesh);
+
+  /* Ensure we only motion sync meshes that also had mesh synced, to avoid
+   * unnecessary work and to ensure that its attributes were clear. */
+  if (mesh_synced.find(mesh) == mesh_synced.end())
+    return;
+
+  /* Find time matching motion step required by mesh. */
+  int motion_step = mesh->motion_step(motion_time);
+  if (motion_step < 0) {
+    return;
+  }
+
+  if (use_particle_hair) {
+    sync_hair_motion(b_depsgraph, b_ob, mesh, motion_step);
+  }
+  else if (object_fluid_gas_domain_find(b_ob)) {
+    /* No volume motion blur support yet. */
+  }
+  else {
+    sync_mesh_motion(b_depsgraph, b_ob, mesh, motion_step);
+  }
+}
+
+CCL_NAMESPACE_END
diff --git a/intern/cycles/blender/blender_id_map.h b/intern/cycles/blender/blender_id_map.h
new file mode 100644
index 00000000000..52031cd9f34
--- /dev/null
+++ b/intern/cycles/blender/blender_id_map.h
@@ -0,0 +1,279 @@
+/*
+ * Copyright 2011-2013 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.
+ */
+
+#ifndef __BLENDER_ID_MAP_H__
+#define __BLENDER_ID_MAP_H__
+
+#include <string.h>
+
+#include "util/util_map.h"
+#include "util/util_set.h"
+#include "util/util_vector.h"
+
+CCL_NAMESPACE_BEGIN
+
+/* ID Map
+ *
+ * Utility class to map between Blender datablocks and Cycles data structures,
+ * and keep track of recalc tags from the dependency graph. */
+
+template<typename K, typename T> class id_map {
+ public:
+  id_map(vector<T *> *scene_data_)
+  {
+    scene_data = scene_data_;
+  }
+
+  T *find(const BL::ID &id)
+  {
+    return find(id.ptr.owner_id);
+  }
+
+  T *find(const K &key)
+  {
+    if (b_map.find(key) != b_map.end()) {
+      T *data = b_map[key];
+      return data;
+    }
+
+    return NULL;
+  }
+
+  void set_recalc(const BL::ID &id)
+  {
+    b_recalc.insert(id.ptr.data);
+  }
+
+  void set_recalc(void *id_ptr)
+  {
+    b_recalc.insert(id_ptr);
+  }
+
+  bool has_recalc()
+  {
+    return !(b_recalc.empty());
+  }
+
+  void pre_sync()
+  {
+    used_set.clear();
+  }
+
+  bool sync(T **r_data, const BL::ID &id)
+  {
+    return sync(r_data, id, id, id.ptr.owner_id);
+  }
+
+  bool sync(T **r_data, const BL::ID &id, const K &key)
+  {
+    return sync(r_data, id, id, key);
+  }
+
+  bool sync(T **r_data, const BL::ID &id, const BL::ID &parent, const K &key)
+  {
+    T *data = find(key);
+    bool recalc;
+
+    if (!data) {
+      /* add data if it didn't exist yet */
+      data = new T();
+      scene_data->push_back(data);
+      b_map[key] = dat

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list