Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/alembic/exporter/abc_writer_mesh.cc
| Show All 19 Lines | |||||
| #include "abc_writer_mesh.h" | #include "abc_writer_mesh.h" | ||||
| #include "abc_hierarchy_iterator.h" | #include "abc_hierarchy_iterator.h" | ||||
| #include "intern/abc_axis_conversion.h" | #include "intern/abc_axis_conversion.h" | ||||
| #include "BLI_assert.h" | #include "BLI_assert.h" | ||||
| #include "BLI_math_vector.h" | #include "BLI_math_vector.h" | ||||
| #include "BKE_attribute.h" | |||||
| #include "BKE_customdata.h" | #include "BKE_customdata.h" | ||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_modifier.h" | #include "BKE_modifier.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "bmesh.h" | #include "bmesh.h" | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | else { | ||||
| CLOG_INFO(&LOG, 2, "exporting OPolyMesh %s", args_.abc_path.c_str()); | CLOG_INFO(&LOG, 2, "exporting OPolyMesh %s", args_.abc_path.c_str()); | ||||
| abc_poly_mesh_ = OPolyMesh(args_.abc_parent, args_.abc_name, timesample_index_); | abc_poly_mesh_ = OPolyMesh(args_.abc_parent, args_.abc_name, timesample_index_); | ||||
| abc_poly_mesh_schema_ = abc_poly_mesh_.getSchema(); | abc_poly_mesh_schema_ = abc_poly_mesh_.getSchema(); | ||||
| OCompoundProperty typeContainer = abc_poly_mesh_.getSchema().getUserProperties(); | OCompoundProperty typeContainer = abc_poly_mesh_.getSchema().getUserProperties(); | ||||
| OBoolProperty type(typeContainer, "meshtype"); | OBoolProperty type(typeContainer, "meshtype"); | ||||
| type.set(subsurf_modifier_ == nullptr); | type.set(subsurf_modifier_ == nullptr); | ||||
| } | } | ||||
| Scene *scene_eval = DEG_get_evaluated_scene(args_.depsgraph); | |||||
| liquid_sim_modifier_ = get_liquid_sim_modifier(scene_eval, context->object); | |||||
| } | } | ||||
| Alembic::Abc::OObject ABCGenericMeshWriter::get_alembic_object() const | Alembic::Abc::OObject ABCGenericMeshWriter::get_alembic_object() const | ||||
| { | { | ||||
| if (is_subd_) { | if (is_subd_) { | ||||
| return abc_subdiv_; | return abc_subdiv_; | ||||
| } | } | ||||
| return abc_poly_mesh_; | return abc_poly_mesh_; | ||||
| Show All 17 Lines | for (; md; md = md->prev) { | ||||
| if (md->type == eModifierType_Subsurf && (md->mode & eModifierMode_DisableTemporary)) { | if (md->type == eModifierType_Subsurf && (md->mode & eModifierMode_DisableTemporary)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| ModifierData *ABCGenericMeshWriter::get_liquid_sim_modifier(Scene *scene, Object *ob) | |||||
| { | |||||
| ModifierData *md = BKE_modifiers_findby_type(ob, eModifierType_Fluidsim); | |||||
| if (md && (BKE_modifier_is_enabled(scene, md, eModifierMode_Render))) { | |||||
| FluidsimModifierData *fsmd = reinterpret_cast<FluidsimModifierData *>(md); | |||||
| if (fsmd->fss && fsmd->fss->type == OB_FLUIDSIM_DOMAIN) { | |||||
| return md; | |||||
| } | |||||
| } | |||||
| return nullptr; | |||||
| } | |||||
| bool ABCGenericMeshWriter::is_supported(const HierarchyContext *context) const | bool ABCGenericMeshWriter::is_supported(const HierarchyContext *context) const | ||||
| { | { | ||||
| if (args_.export_params->visible_objects_only) { | if (args_.export_params->visible_objects_only) { | ||||
| return context->is_object_visible(args_.export_params->evaluation_mode); | return context->is_object_visible(args_.export_params->evaluation_mode); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | if (args_.export_params->normals) { | ||||
| mesh_sample.setNormals(normals_sample); | mesh_sample.setNormals(normals_sample); | ||||
| } | } | ||||
| if (args_.export_params->orcos) { | if (args_.export_params->orcos) { | ||||
| write_generated_coordinates(abc_poly_mesh_schema_.getArbGeomParams(), m_custom_data_config); | write_generated_coordinates(abc_poly_mesh_schema_.getArbGeomParams(), m_custom_data_config); | ||||
| } | } | ||||
| if (liquid_sim_modifier_ != nullptr) { | if (get_velocities(mesh, velocities)) { | ||||
| get_velocities(mesh, velocities); | |||||
| mesh_sample.setVelocities(V3fArraySample(velocities)); | mesh_sample.setVelocities(V3fArraySample(velocities)); | ||||
| } | } | ||||
| update_bounding_box(context.object); | update_bounding_box(context.object); | ||||
| mesh_sample.setSelfBounds(bounding_box_); | mesh_sample.setSelfBounds(bounding_box_); | ||||
| abc_poly_mesh_schema_.set(mesh_sample); | abc_poly_mesh_schema_.set(mesh_sample); | ||||
| ▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | for (it = geo_groups.begin(); it != geo_groups.end(); ++it) { | ||||
| OFaceSetSchema::Sample samp; | OFaceSetSchema::Sample samp; | ||||
| samp.setFaces(Int32ArraySample(it->second)); | samp.setFaces(Int32ArraySample(it->second)); | ||||
| face_set.getSchema().set(samp); | face_set.getSchema().set(samp); | ||||
| } | } | ||||
| } | } | ||||
| void ABCGenericMeshWriter::write_arb_geo_params(struct Mesh *me) | void ABCGenericMeshWriter::write_arb_geo_params(struct Mesh *me) | ||||
| { | { | ||||
| if (liquid_sim_modifier_ != nullptr) { | |||||
| /* We don't need anything more for liquid meshes. */ | |||||
| return; | |||||
| } | |||||
| if (frame_has_been_written_ || !args_.export_params->vcolors) { | if (frame_has_been_written_ || !args_.export_params->vcolors) { | ||||
| return; | return; | ||||
| } | } | ||||
| OCompoundProperty arb_geom_params; | OCompoundProperty arb_geom_params; | ||||
| if (is_subd_) { | if (is_subd_) { | ||||
| arb_geom_params = abc_subdiv_.getSchema().getArbGeomParams(); | arb_geom_params = abc_subdiv_.getSchema().getArbGeomParams(); | ||||
| } | } | ||||
| else { | else { | ||||
| arb_geom_params = abc_poly_mesh_.getSchema().getArbGeomParams(); | arb_geom_params = abc_poly_mesh_.getSchema().getArbGeomParams(); | ||||
| } | } | ||||
| write_custom_data(arb_geom_params, m_custom_data_config, &me->ldata, CD_MLOOPCOL); | write_custom_data(arb_geom_params, m_custom_data_config, &me->ldata, CD_MLOOPCOL); | ||||
| } | } | ||||
| void ABCGenericMeshWriter::get_velocities(struct Mesh *mesh, std::vector<Imath::V3f> &vels) | bool ABCGenericMeshWriter::get_velocities(struct Mesh *mesh, std::vector<Imath::V3f> &vels) | ||||
| { | { | ||||
| /* Export velocity attribute output by fluid sim, sequence cache modifier | |||||
| * and geometry nodes. */ | |||||
| CustomDataLayer *velocity_layer = BKE_id_attribute_find( | |||||
| &mesh->id, "velocity", CD_PROP_FLOAT3, ATTR_DOMAIN_POINT); | |||||
| if (velocity_layer == nullptr) { | |||||
| return false; | |||||
| } | |||||
| const int totverts = mesh->totvert; | const int totverts = mesh->totvert; | ||||
| const float(*mesh_velocities)[3] = reinterpret_cast<float(*)[3]>(velocity_layer->data); | |||||
| vels.clear(); | vels.clear(); | ||||
| vels.resize(totverts); | vels.resize(totverts); | ||||
| FluidsimModifierData *fmd = reinterpret_cast<FluidsimModifierData *>(liquid_sim_modifier_); | |||||
| FluidsimSettings *fss = fmd->fss; | |||||
| if (fss->meshVelocities) { | |||||
| float *mesh_vels = reinterpret_cast<float *>(fss->meshVelocities); | |||||
| for (int i = 0; i < totverts; i++) { | for (int i = 0; i < totverts; i++) { | ||||
| copy_yup_from_zup(vels[i].getValue(), mesh_vels); | copy_yup_from_zup(vels[i].getValue(), mesh_velocities[i]); | ||||
| mesh_vels += 3; | |||||
| } | |||||
| } | |||||
| else { | |||||
| std::fill(vels.begin(), vels.end(), Imath::V3f(0.0f)); | |||||
| } | } | ||||
| return true; | |||||
| } | } | ||||
| void ABCGenericMeshWriter::get_geo_groups(Object *object, | void ABCGenericMeshWriter::get_geo_groups(Object *object, | ||||
| struct Mesh *mesh, | struct Mesh *mesh, | ||||
| std::map<std::string, std::vector<int32_t>> &geo_groups) | std::map<std::string, std::vector<int32_t>> &geo_groups) | ||||
| { | { | ||||
| const int num_poly = mesh->totpoly; | const int num_poly = mesh->totpoly; | ||||
| MPoly *polygons = mesh->mpoly; | MPoly *polygons = mesh->mpoly; | ||||
| ▲ Show 20 Lines • Show All 147 Lines • Show Last 20 Lines | |||||