Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/blender/blender_geometry.cpp
| Show All 13 Lines | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include "render/curves.h" | #include "render/curves.h" | ||||
| #include "render/hair.h" | #include "render/hair.h" | ||||
| #include "render/mesh.h" | #include "render/mesh.h" | ||||
| #include "render/object.h" | #include "render/object.h" | ||||
| #include "render/volume.h" | |||||
| #include "blender/blender_sync.h" | #include "blender/blender_sync.h" | ||||
| #include "blender/blender_util.h" | #include "blender/blender_util.h" | ||||
| #include "util/util_foreach.h" | #include "util/util_foreach.h" | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| static Geometry::Type determine_geom_type(BL::Object &b_ob, bool use_particle_hair) | |||||
| { | |||||
| if (b_ob.type() == BL::Object::type_HAIR || use_particle_hair) { | |||||
| return Geometry::HAIR; | |||||
| } | |||||
| if (b_ob.type() == BL::Object::type_VOLUME || object_fluid_gas_domain_find(b_ob)) { | |||||
| return Geometry::VOLUME; | |||||
| } | |||||
| return Geometry::MESH; | |||||
| } | |||||
| Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph, | Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph, | ||||
| BL::Object &b_ob, | BL::Object &b_ob, | ||||
| BL::Object &b_ob_instance, | BL::Object &b_ob_instance, | ||||
| bool object_updated, | bool object_updated, | ||||
| bool use_particle_hair) | bool use_particle_hair) | ||||
| { | { | ||||
| /* Test if we can instance or if the object is modified. */ | /* Test if we can instance or if the object is modified. */ | ||||
| BL::ID b_ob_data = b_ob.data(); | 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::ID b_key_id = (BKE_object_is_modified(b_ob)) ? b_ob_instance : b_ob_data; | ||||
| GeometryKey key(b_key_id.ptr.data, use_particle_hair); | GeometryKey key(b_key_id.ptr.data, use_particle_hair); | ||||
| BL::Material material_override = view_layer.material_override; | BL::Material material_override = view_layer.material_override; | ||||
| Shader *default_shader = (b_ob.type() == BL::Object::type_VOLUME) ? scene->default_volume : | Shader *default_shader = (b_ob.type() == BL::Object::type_VOLUME) ? scene->default_volume : | ||||
| scene->default_surface; | scene->default_surface; | ||||
| Geometry::Type geom_type = (b_ob.type() == BL::Object::type_HAIR || use_particle_hair) ? | Geometry::Type geom_type = determine_geom_type(b_ob, use_particle_hair); | ||||
| Geometry::HAIR : | |||||
| Geometry::MESH; | |||||
| /* Find shader indices. */ | /* Find shader indices. */ | ||||
| vector<Shader *> used_shaders; | vector<Shader *> used_shaders; | ||||
| BL::Object::material_slots_iterator slot; | BL::Object::material_slots_iterator slot; | ||||
| for (b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) { | for (b_ob.material_slots.begin(slot); slot != b_ob.material_slots.end(); ++slot) { | ||||
| if (material_override) { | if (material_override) { | ||||
| find_shader(material_override, used_shaders, default_shader); | find_shader(material_override, used_shaders, default_shader); | ||||
| Show All 14 Lines | Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph, | ||||
| /* Test if we need to sync. */ | /* Test if we need to sync. */ | ||||
| Geometry *geom = geometry_map.find(key); | Geometry *geom = geometry_map.find(key); | ||||
| bool sync = true; | bool sync = true; | ||||
| if (geom == NULL) { | if (geom == NULL) { | ||||
| /* Add new geometry if it did not exist yet. */ | /* Add new geometry if it did not exist yet. */ | ||||
| if (geom_type == Geometry::HAIR) { | if (geom_type == Geometry::HAIR) { | ||||
| geom = new Hair(); | geom = new Hair(); | ||||
| } | } | ||||
| else if (geom_type == Geometry::VOLUME) { | |||||
| geom = new Volume(); | |||||
| } | |||||
| else { | else { | ||||
| geom = new Mesh(); | geom = new Mesh(); | ||||
| } | } | ||||
| geometry_map.add(key, geom); | geometry_map.add(key, geom); | ||||
| } | } | ||||
| else { | else { | ||||
| /* Test if we need to update existing geometry. */ | /* Test if we need to update existing geometry. */ | ||||
| sync = geometry_map.update(geom, b_key_id); | sync = geometry_map.update(geom, b_key_id); | ||||
| Show All 32 Lines | Geometry *BlenderSync::sync_geometry(BL::Depsgraph &b_depsgraph, | ||||
| } | } | ||||
| progress.set_sync_status("Synchronizing object", b_ob.name()); | progress.set_sync_status("Synchronizing object", b_ob.name()); | ||||
| geometry_synced.insert(geom); | geometry_synced.insert(geom); | ||||
| geom->name = ustring(b_ob_data.name().c_str()); | geom->name = ustring(b_ob_data.name().c_str()); | ||||
| if (b_ob.type() == BL::Object::type_HAIR || use_particle_hair) { | if (geom_type == Geometry::HAIR) { | ||||
| Hair *hair = static_cast<Hair *>(geom); | Hair *hair = static_cast<Hair *>(geom); | ||||
| sync_hair(b_depsgraph, b_ob, hair, used_shaders); | sync_hair(b_depsgraph, b_ob, hair, used_shaders); | ||||
| } | } | ||||
| else if (b_ob.type() == BL::Object::type_VOLUME || object_fluid_gas_domain_find(b_ob)) { | else if (geom_type == Geometry::VOLUME) { | ||||
| Mesh *mesh = static_cast<Mesh *>(geom); | Volume *volume = static_cast<Volume *>(geom); | ||||
| sync_volume(b_ob, mesh, used_shaders); | sync_volume(b_ob, volume, used_shaders); | ||||
| } | } | ||||
| else { | else { | ||||
| Mesh *mesh = static_cast<Mesh *>(geom); | Mesh *mesh = static_cast<Mesh *>(geom); | ||||
| sync_mesh(b_depsgraph, b_ob, mesh, used_shaders); | sync_mesh(b_depsgraph, b_ob, mesh, used_shaders); | ||||
| } | } | ||||
| return geom; | return geom; | ||||
| } | } | ||||
| Show All 40 Lines | |||||