Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/usd/intern/usd_writer_mesh.cc
| Show All 20 Lines | |||||
| #include <pxr/usd/usdGeom/mesh.h> | #include <pxr/usd/usdGeom/mesh.h> | ||||
| #include <pxr/usd/usdShade/material.h> | #include <pxr/usd/usdShade/material.h> | ||||
| #include <pxr/usd/usdShade/materialBindingAPI.h> | #include <pxr/usd/usdShade/materialBindingAPI.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 "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| ▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | void USDGenericMeshWriter::write_mesh(HierarchyContext &context, Mesh *mesh) | ||||
| } | } | ||||
| if (usd_export_context_.export_params.export_uvmaps) { | if (usd_export_context_.export_params.export_uvmaps) { | ||||
| write_uv_maps(mesh, usd_mesh); | write_uv_maps(mesh, usd_mesh); | ||||
| } | } | ||||
| if (usd_export_context_.export_params.export_normals) { | if (usd_export_context_.export_params.export_normals) { | ||||
| write_normals(mesh, usd_mesh); | write_normals(mesh, usd_mesh); | ||||
| } | } | ||||
| write_surface_velocity(context.object, mesh, usd_mesh); | write_surface_velocity(mesh, usd_mesh); | ||||
| /* TODO(Sybren): figure out what happens when the face groups change. */ | /* TODO(Sybren): figure out what happens when the face groups change. */ | ||||
| if (frame_has_been_written_) { | if (frame_has_been_written_) { | ||||
| return; | return; | ||||
| } | } | ||||
| usd_mesh.CreateSubdivisionSchemeAttr().Set(pxr::UsdGeomTokens->none); | usd_mesh.CreateSubdivisionSchemeAttr().Set(pxr::UsdGeomTokens->none); | ||||
| ▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | void USDGenericMeshWriter::write_normals(const Mesh *mesh, pxr::UsdGeomMesh usd_mesh) | ||||
| pxr::UsdAttribute attr_normals = usd_mesh.CreateNormalsAttr(pxr::VtValue(), true); | pxr::UsdAttribute attr_normals = usd_mesh.CreateNormalsAttr(pxr::VtValue(), true); | ||||
| if (!attr_normals.HasValue()) { | if (!attr_normals.HasValue()) { | ||||
| attr_normals.Set(loop_normals, pxr::UsdTimeCode::Default()); | attr_normals.Set(loop_normals, pxr::UsdTimeCode::Default()); | ||||
| } | } | ||||
| usd_value_writer_.SetAttribute(attr_normals, pxr::VtValue(loop_normals), timecode); | usd_value_writer_.SetAttribute(attr_normals, pxr::VtValue(loop_normals), timecode); | ||||
| usd_mesh.SetNormalsInterpolation(pxr::UsdGeomTokens->faceVarying); | usd_mesh.SetNormalsInterpolation(pxr::UsdGeomTokens->faceVarying); | ||||
| } | } | ||||
| void USDGenericMeshWriter::write_surface_velocity(Object *object, | void USDGenericMeshWriter::write_surface_velocity(const Mesh *mesh, pxr::UsdGeomMesh usd_mesh) | ||||
kevindietrich: `object` is not used anymore, which also gives a compile warning. | |||||
| const Mesh *mesh, | { | ||||
| pxr::UsdGeomMesh usd_mesh) | /* Export velocity attribute output by fluid sim, sequence cache modifier | ||||
| { | * and geometry nodes. */ | ||||
| /* Only velocities from the fluid simulation are exported. This is the most important case, | CustomDataLayer *velocity_layer = BKE_id_attribute_find( | ||||
| * though, as the baked mesh changes topology all the time, and thus computing the velocities | &mesh->id, "velocity", CD_PROP_FLOAT3, ATTR_DOMAIN_POINT); | ||||
| * at import time in a post-processing step is hard. */ | |||||
| ModifierData *md = BKE_modifiers_findby_type(object, eModifierType_Fluidsim); | |||||
| if (md == nullptr) { | |||||
| return; | |||||
| } | |||||
| /* Check that the fluid sim modifier is enabled and has useful data. */ | if (velocity_layer == nullptr) { | ||||
| const bool use_render = (DEG_get_mode(usd_export_context_.depsgraph) == DAG_EVAL_RENDER); | |||||
| const ModifierMode required_mode = use_render ? eModifierMode_Render : eModifierMode_Realtime; | |||||
| const Scene *scene = DEG_get_evaluated_scene(usd_export_context_.depsgraph); | |||||
| if (!BKE_modifier_is_enabled(scene, md, required_mode)) { | |||||
| return; | |||||
| } | |||||
| FluidsimModifierData *fsmd = reinterpret_cast<FluidsimModifierData *>(md); | |||||
| if (!fsmd->fss || fsmd->fss->type != OB_FLUIDSIM_DOMAIN) { | |||||
| return; | |||||
| } | |||||
| FluidsimSettings *fss = fsmd->fss; | |||||
| if (!fss->meshVelocities) { | |||||
| return; | return; | ||||
| } | } | ||||
| const float(*velocities)[3] = reinterpret_cast<float(*)[3]>(velocity_layer->data); | |||||
| /* Export per-vertex velocity vectors. */ | /* Export per-vertex velocity vectors. */ | ||||
| pxr::VtVec3fArray usd_velocities; | pxr::VtVec3fArray usd_velocities; | ||||
| usd_velocities.reserve(mesh->totvert); | usd_velocities.reserve(mesh->totvert); | ||||
| FluidVertexVelocity *mesh_velocities = fss->meshVelocities; | for (int vertex_idx = 0, totvert = mesh->totvert; vertex_idx < totvert; ++vertex_idx) { | ||||
| for (int vertex_idx = 0, totvert = mesh->totvert; vertex_idx < totvert; | usd_velocities.push_back(pxr::GfVec3f(velocities[vertex_idx])); | ||||
| ++vertex_idx, ++mesh_velocities) { | |||||
| usd_velocities.push_back(pxr::GfVec3f(mesh_velocities->vel)); | |||||
| } | } | ||||
| pxr::UsdTimeCode timecode = get_export_time_code(); | pxr::UsdTimeCode timecode = get_export_time_code(); | ||||
| usd_mesh.CreateVelocitiesAttr().Set(usd_velocities, timecode); | usd_mesh.CreateVelocitiesAttr().Set(usd_velocities, timecode); | ||||
| } | } | ||||
| USDMeshWriter::USDMeshWriter(const USDExporterContext &ctx) : USDGenericMeshWriter(ctx) | USDMeshWriter::USDMeshWriter(const USDExporterContext &ctx) : USDGenericMeshWriter(ctx) | ||||
| { | { | ||||
| } | } | ||||
| Mesh *USDMeshWriter::get_export_mesh(Object *object_eval, bool & /*r_needsfree*/) | Mesh *USDMeshWriter::get_export_mesh(Object *object_eval, bool & /*r_needsfree*/) | ||||
| { | { | ||||
| return BKE_object_get_evaluated_mesh(object_eval); | return BKE_object_get_evaluated_mesh(object_eval); | ||||
| } | } | ||||
| } // namespace blender::io::usd | } // namespace blender::io::usd | ||||
object is not used anymore, which also gives a compile warning.