From 87ef03745971e1c860894ddc18172a183f42ed26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Tue, 23 Feb 2021 05:45:55 +0100 Subject: Alembic procedural: cleanup, demultiply Object and Geometry Node creation --- intern/cycles/render/alembic.cpp | 103 +++++++++++++-------------------------- 1 file changed, 34 insertions(+), 69 deletions(-) (limited to 'intern') diff --git a/intern/cycles/render/alembic.cpp b/intern/cycles/render/alembic.cpp index 2f69cc99638..13144f46314 100644 --- a/intern/cycles/render/alembic.cpp +++ b/intern/cycles/render/alembic.cpp @@ -1466,38 +1466,47 @@ void AlembicProcedural::load_objects(Progress &progress) for (size_t i = 0; i < root.getNumChildren(); ++i) { walk_hierarchy(root, root.getChildHeader(i), nullptr, object_map, progress); } -} -void AlembicProcedural::read_mesh(Scene *scene, - AlembicObject *abc_object, - Abc::chrono_t frame_time, - Progress &progress) -{ - IPolyMesh polymesh(abc_object->iobject, Alembic::Abc::kWrapExisting); + /* Create nodes in the scene. */ + for (std::pair pair : object_map) { + AlembicObject *abc_object = pair.second; - Mesh *mesh = nullptr; + Geometry *geometry = nullptr; - /* create a mesh node in the scene if not already done */ - if (!abc_object->get_object()) { - mesh = scene->create_node(); - mesh->set_owner(this); - mesh->name = abc_object->iobject.getName(); + if (abc_object->schema_type == AlembicObject::CURVES) { + geometry = scene_->create_node(); + } + else if (abc_object->schema_type == AlembicObject::POLY_MESH || + abc_object->schema_type == AlembicObject::SUBD) { + geometry = scene_->create_node(); + } + else { + continue; + } + + geometry->set_owner(this); + geometry->name = abc_object->iobject.getName(); array used_shaders = abc_object->get_used_shaders(); - mesh->set_used_shaders(used_shaders); + geometry->set_used_shaders(used_shaders); - /* create object*/ - Object *object = scene->create_node(); + Object *object = scene_->create_node(); object->set_owner(this); - object->set_geometry(mesh); - object->set_tfm(abc_object->xform); + object->set_geometry(geometry); object->name = abc_object->iobject.getName(); abc_object->set_object(object); } - else { - mesh = static_cast(abc_object->get_object()->get_geometry()); - } +} + +void AlembicProcedural::read_mesh(Scene *scene, + AlembicObject *abc_object, + Abc::chrono_t frame_time, + Progress &progress) +{ + IPolyMesh polymesh(abc_object->iobject, Alembic::Abc::kWrapExisting); + + Mesh *mesh = static_cast(abc_object->get_object()->get_geometry()); CachedData &cached_data = abc_object->get_cached_data(); IPolyMeshSchema schema = polymesh.getSchema(); @@ -1570,32 +1579,10 @@ void AlembicProcedural::read_subd(Scene *scene, ISubD subd_mesh(abc_object->iobject, Alembic::Abc::kWrapExisting); ISubDSchema schema = subd_mesh.getSchema(); - Mesh *mesh = nullptr; - - /* create a mesh node in the scene if not already done */ - if (!abc_object->get_object()) { - mesh = scene->create_node(); - mesh->set_owner(this); - mesh->name = abc_object->iobject.getName(); - - array used_shaders = abc_object->get_used_shaders(); - mesh->set_used_shaders(used_shaders); - - /* Alembic is OpenSubDiv compliant, there is no option to set another subdivision type. */ - mesh->set_subdivision_type(Mesh::SubdivisionType::SUBDIVISION_CATMULL_CLARK); - - /* create object*/ - Object *object = scene->create_node(); - object->set_owner(this); - object->set_geometry(mesh); - object->set_tfm(abc_object->xform); - object->name = abc_object->iobject.getName(); + Mesh *mesh = static_cast(abc_object->get_object()->get_geometry()); - abc_object->set_object(object); - } - else { - mesh = static_cast(abc_object->get_object()->get_geometry()); - } + /* Alembic is OpenSubDiv compliant, there is no option to set another subdivision type. */ + mesh->set_subdivision_type(Mesh::SubdivisionType::SUBDIVISION_CATMULL_CLARK); if (!abc_object->has_data_loaded()) { abc_object->load_all_data(this, schema, scale, progress); @@ -1696,29 +1683,7 @@ void AlembicProcedural::read_curves(Scene *scene, Progress &progress) { ICurves curves(abc_object->iobject, Alembic::Abc::kWrapExisting); - Hair *hair; - - /* create a hair node in the scene if not already done */ - if (!abc_object->get_object()) { - hair = scene->create_node(); - hair->set_owner(this); - hair->name = abc_object->iobject.getName(); - - array used_shaders = abc_object->get_used_shaders(); - hair->set_used_shaders(used_shaders); - - /* create object*/ - Object *object = scene->create_node(); - object->set_owner(this); - object->set_geometry(hair); - object->set_tfm(abc_object->xform); - object->name = abc_object->iobject.getName(); - - abc_object->set_object(object); - } - else { - hair = static_cast(abc_object->get_object()->get_geometry()); - } + Hair *hair = static_cast(abc_object->get_object()->get_geometry()); ICurvesSchema schema = curves.getSchema(); -- cgit v1.2.3