/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/EditorPlugins/Assets/EditorPluginAssets/AnimatedMeshAsset/AnimatedMeshAsset.cpp
161 строка
5 KB
Yuriy Balyuk
Added "Normal Weight" parameter to "Simplify Mesh" feature; ... (#1910)
21 апр 2026, 14:59
Не верифицирован
21 апр 2026, 14:59
f54587c
Код
Авторство
О чём код?
#include <EditorPluginAssets/EditorPluginAssetsPCH.h> #include <EditorPluginAssets/AnimatedMeshAsset/AnimatedMeshAsset.h> #include <EditorPluginAssets/Util/MeshImportUtils.h> #include <Foundation/Utilities/Progress.h> #include <ModelImporter2/ModelImporter.h> #include <RendererCore/Meshes/MeshResourceDescriptor.h> // clang-format off EZ_BEGIN_DYNAMIC_REFLECTED_TYPE(ezAnimatedMeshAssetDocument, 9, ezRTTINoAllocator) EZ_END_DYNAMIC_REFLECTED_TYPE; // clang-format on ezAnimatedMeshAssetDocument::ezAnimatedMeshAssetDocument(ezStringView sDocumentPath) : ezSimpleAssetDocument<ezAnimatedMeshAssetProperties>(sDocumentPath, ezAssetDocEngineConnection::Simple, true) { } ezTransformStatus ezAnimatedMeshAssetDocument::InternalTransformAsset(ezStreamWriter& stream, ezStringView sOutputTag, const ezPlatformProfile* pAssetProfile, const ezAssetFileHeader& AssetHeader, ezBitflags<ezTransformFlags> transformFlags) { ezProgressRange range("Transforming Asset", 2, false); ezAnimatedMeshAssetProperties* pProp = GetProperties(); if (pProp->m_sDefaultSkeleton.IsEmpty()) { return ezStatus("Animated mesh doesn't have a default skeleton assigned."); } ezMeshResourceDescriptor desc; range.SetStepWeighting(0, 0.9f); range.BeginNextStep("Importing Mesh"); EZ_SUCCEED_OR_RETURN(CreateMeshFromFile(pProp, desc)); // the properties object can get invalidated by the CreateMeshFromFile() call pProp = GetProperties(); range.BeginNextStep("Writing Result"); if (!pProp->m_sDefaultSkeleton.IsEmpty()) { desc.m_hDefaultSkeleton = ezResourceManager::LoadResource<ezSkeletonResource>(pProp->m_sDefaultSkeleton); } desc.Save(stream); return ezStatus(EZ_SUCCESS); } ezStatus ezAnimatedMeshAssetDocument::CreateMeshFromFile(ezAnimatedMeshAssetProperties* pProp, ezMeshResourceDescriptor& desc) { ezProgressRange range("Mesh Import", 5, false); range.SetStepWeighting(0, 0.7f); range.BeginNextStep("Importing Mesh Data"); ezStringBuilder sAbsFilename = pProp->m_sMeshFile; if (!ezQtEditorApp::GetSingleton()->MakeDataDirectoryRelativePathAbsolute(sAbsFilename)) { return ezStatus(ezFmt("Couldn't make path absolute: '{0};", sAbsFilename)); } ezUniquePtr<ezModelImporter2::Importer> pImporter = ezModelImporter2::RequestImporterForFileType(sAbsFilename); if (pImporter == nullptr) return ezStatus("No known importer for this file type."); ezModelImporter2::ImportOptions opt; opt.m_sSourceFile = sAbsFilename; opt.m_bImportSkinningData = true; opt.m_bRecomputeNormals = pProp->m_bRecalculateNormals; opt.m_bRecomputeTangents = pProp->m_bRecalculateTangents; opt.m_bHighPrecision = pProp->m_bHighPrecision; opt.m_MeshVertexColorConversion = pProp->m_VertexColorConversion; opt.m_bNormalizeWeights = pProp->m_bNormalizeWeights; opt.m_pMeshOutput = &desc; // include tags { ezTempHybridArray<ezStringView, 8> tags; pProp->m_sMeshIncludeTags.Split(false, tags, ";"); for (ezStringView tag : tags) { tag.Trim(); opt.m_MeshIncludeTags.PushBack(tag); } } // exclude tags { ezTempHybridArray<ezStringView, 8> tags; pProp->m_sMeshExcludeTags.Split(false, tags, ";"); for (ezStringView tag : tags) { tag.Trim(); opt.m_MeshExcludeTags.PushBack(tag); } } if (pProp->m_bSimplifyMesh) { opt.m_uiMeshSimplification = pProp->m_uiMeshSimplification; opt.m_uiMaxSimplificationError = pProp->m_uiMaxSimplificationError; opt.m_fNormalWeight = pProp->m_fNormalWeight; opt.m_bAggressiveSimplification = pProp->m_bAggressiveSimplification; } if (pImporter->Import(opt).Failed()) return ezStatus("Model importer was unable to read this asset."); if (desc.GetSubMeshes().IsEmpty() || !desc.GetBounds().IsValid()) return ezStatus("Imported mesh is empty."); for (auto& sm : desc.GetSubMeshes()) { if (sm.m_uiPrimitiveCount == 0) { return ezStatus("Imported mesh is empty."); } } range.BeginNextStep("Importing Materials"); // correct the number of material slots if (pProp->m_bImportMaterials || pProp->m_Slots.GetCount() != desc.GetSubMeshes().GetCount()) { GetObjectAccessor()->StartTransaction("Update Mesh Materials"); ezMeshImportUtils::SetMeshAssetMaterialSlots(pProp->m_Slots, pImporter.Borrow()); if (pProp->m_bImportMaterials) { ezMeshImportUtils::ImportMeshAssetMaterials(pProp->m_Slots, GetDocumentPath(), pImporter.Borrow()); } ApplyNativePropertyChangesToObjectManager(); GetObjectAccessor()->FinishTransaction(); // Need to reacquire pProp pointer since it might be reallocated. pProp = GetProperties(); } ezMeshImportUtils::CopyMeshAssetMaterialSlotToResource(desc, pProp->m_Slots); return ezStatus(EZ_SUCCESS); } ezTransformStatus ezAnimatedMeshAssetDocument::InternalCreateThumbnail(const ThumbnailInfo& ThumbnailInfo) { ezStatus status = ezAssetDocument::RemoteCreateThumbnail(ThumbnailInfo); return status; } void ezAnimatedMeshAssetDocument::UpdateAssetDocumentInfo(ezAssetDocumentInfo* pInfo) const { SUPER::UpdateAssetDocumentInfo(pInfo); // For glTF files, add any referenced external buffer files as dependencies ezMeshImportUtils::AddGltfBufferDependencies(GetProperties()->m_sMeshFile, pInfo->m_TransformDependencies); }