diff --git a/data/test_assets/urdf/skinned_prism.ao_config.json b/data/test_assets/urdf/skinned_prism.ao_config.json index 6d59e26827..44fae167e1 100644 --- a/data/test_assets/urdf/skinned_prism.ao_config.json +++ b/data/test_assets/urdf/skinned_prism.ao_config.json @@ -1,3 +1,4 @@ { - "render_asset": "data/test_assets/objects/skinned_prism.glb" + "render_asset": "../objects/skinned_prism.glb", + "debug_render_primitives": false } diff --git a/src/esp/assets/ResourceManager.cpp b/src/esp/assets/ResourceManager.cpp index b4198c6560..1a327d5898 100644 --- a/src/esp/assets/ResourceManager.cpp +++ b/src/esp/assets/ResourceManager.cpp @@ -1798,8 +1798,7 @@ bool ResourceManager::loadRenderAssetGeneral(const AssetInfo& info) { scene->parentsAsArray()) { nodes[parent.first()].emplace(); nodes[parent.first()]->componentID = parent.first(); - nodes[parent.first()]->name = - fileImporter_->objectName(nodes[parent.first()]->componentID); + nodes[parent.first()]->name = fileImporter_->objectName(parent.first()); } // Set transformations. Objects that are not part of the hierarchy are @@ -1888,24 +1887,24 @@ scene::SceneNode* ResourceManager::createRenderAssetInstanceGeneralPrimitive( // If the object has a skin and a rig (articulated object), link them together // such as the model bones are driven by the articulated object links. std::shared_ptr instanceSkinData = nullptr; - if (creation.rig && - loadedAssetData.meshMetaData.skinIndex.first != ID_UNDEFINED) { + const auto& meshMetaData = loadedAssetData.meshMetaData; + if (creation.rig && meshMetaData.skinIndex.first != ID_UNDEFINED) { ESP_CHECK( !skins_.empty(), "Cannot instantiate skinned model because no skin data is imported."); - const auto& skinData = skins_[loadedAssetData.meshMetaData.skinIndex.first]; + const auto& skinData = skins_[meshMetaData.skinIndex.first]; instanceSkinData = std::make_shared(skinData); - mapSkinnedModelToArticulatedObject(loadedAssetData.meshMetaData.root, - creation.rig, instanceSkinData); + mapSkinnedModelToArticulatedObject(meshMetaData.root, creation.rig, + instanceSkinData); ESP_CHECK(instanceSkinData->rootJointId != ID_UNDEFINED, "Could not map skinned model to articulated object."); } - addComponent(loadedAssetData.meshMetaData, // mesh metadata - newNode, // parent scene node - creation.lightSetupKey, // lightSetup key - drawables, // drawable group - loadedAssetData.meshMetaData.root, // mesh transform node + addComponent(meshMetaData, // mesh metadata + newNode, // parent scene node + creation.lightSetupKey, // lightSetup key + drawables, // drawable group + meshMetaData.root, // mesh transform node visNodeCache, // a vector of scene nodes, the visNodeCache computeAbsoluteAABBs, // compute absolute AABBs staticDrawableInfo, // a vector of static drawable info @@ -2472,8 +2471,8 @@ void ResourceManager::loadSkins(Importer& importer, if (importer.skin3DCount() == 0) return; - int skinStart = nextSkinID_; - int skinEnd = skinStart + importer.skin3DCount() - 1; + const int skinStart = nextSkinID_; + const int skinEnd = skinStart + importer.skin3DCount() - 1; nextSkinID_ = skinEnd + 1; loadedAssetData.meshMetaData.setSkinIndices(skinStart, skinEnd); @@ -2914,15 +2913,15 @@ void ResourceManager::mapSkinnedModelToArticulatedObject( // Find skin joint ID that matches the node const auto& gfxBoneName = meshTransformNode.name; const auto& boneNameJointIdMap = skinData->skinData->boneNameJointIdMap; - auto jointIt = boneNameJointIdMap.find(gfxBoneName); + const auto jointIt = boneNameJointIdMap.find(gfxBoneName); if (jointIt != boneNameJointIdMap.end()) { int jointId = jointIt->second; // Find articulated object link ID that matches the node const auto& linkIds = rig->getLinkIdsWithBase(); - auto linkId = std::find_if(linkIds.begin(), linkIds.end(), [&](int i) { - return gfxBoneName == rig->getLinkName(i); - }); + const auto linkId = + std::find_if(linkIds.begin(), linkIds.end(), + [&](int i) { return gfxBoneName == rig->getLinkName(i); }); // Map the articulated object link associated with the skin joint if (linkId != linkIds.end()) { diff --git a/src/esp/assets/ResourceManager.h b/src/esp/assets/ResourceManager.h index 94f7044ce5..52b64c3fbb 100644 --- a/src/esp/assets/ResourceManager.h +++ b/src/esp/assets/ResourceManager.h @@ -856,7 +856,7 @@ class ResourceManager { const std::shared_ptr& skinData = nullptr); /** - * @brief Recursive construction of instance skin and rig data. + * @brief Recursive construction of instance skinning data. * * Fills the fields of a @ref InstanceSkinData to enable skinned mesh rendering * by associating each bone to a corresponding articulated object link. @@ -865,7 +865,7 @@ class ResourceManager { * @param creationInfo Creation information for the instance which contains * the rig. * @param skinData Structure holding the skin and rig configuration for the - * instance + * instance. */ void mapSkinnedModelToArticulatedObject( const MeshTransformNode& meshTransformNode, diff --git a/src/esp/gfx/GenericDrawable.cpp b/src/esp/gfx/GenericDrawable.cpp index f1ce59c42f..a10d359815 100644 --- a/src/esp/gfx/GenericDrawable.cpp +++ b/src/esp/gfx/GenericDrawable.cpp @@ -191,24 +191,24 @@ void GenericDrawable::draw(const Mn::Matrix4& transformationMatrix, if (skinData_) { // Gather joint transformations - auto& skin = skinData_->skinData->skin; + const auto& skin = skinData_->skinData->skin; + const auto& transformNodes = skinData_->jointIdToTransformNode; auto& jointIdToArticulatedObjectNodes = skinData_->jointIdToArticulatedObjectNode; - auto& transformNodes = skinData_->jointIdToTransformNode; ESP_CHECK(jointTransformations_.size() == skin->joints().size(), "Joint transformation count doesn't match bone count."); // Undo root node transform so that the model origin matches the root // articulated object link. - auto invRootTransform = + const auto invRootTransform = jointIdToArticulatedObjectNodes[skinData_->rootJointId] ->absoluteTransformationMatrix() .inverted(); - Mn::Matrix4 lastTransform = Mn::Matrix4{Magnum::Math::IdentityInit}; + auto lastTransform = Mn::Matrix4{Magnum::Math::IdentityInit}; for (std::size_t i = 0; i != jointTransformations_.size(); ++i) { - auto jointNodeIt = transformNodes.find(skin->joints()[i]); + const auto jointNodeIt = transformNodes.find(skin->joints()[i]); if (jointNodeIt != transformNodes.end()) { jointTransformations_[i] = invRootTransform * @@ -233,10 +233,10 @@ void GenericDrawable::draw(const Mn::Matrix4& transformationMatrix, } void GenericDrawable::updateShader() { - Mn::UnsignedInt lightCount = lightSetup_->size(); - Mn::UnsignedInt jointCount = + const Mn::UnsignedInt lightCount = lightSetup_->size(); + const Mn::UnsignedInt jointCount = skinData_ ? skinData_->skinData->skin->joints().size() : 0; - Mn::UnsignedInt perVertexJointCount = + const Mn::UnsignedInt perVertexJointCount = skinData_ ? skinData_->skinData->perVertexJointCount : 0; if (skinData_) { diff --git a/src/esp/physics/bullet/BulletPhysicsManager.cpp b/src/esp/physics/bullet/BulletPhysicsManager.cpp index 905dc48219..763faf1eba 100644 --- a/src/esp/physics/bullet/BulletPhysicsManager.cpp +++ b/src/esp/physics/bullet/BulletPhysicsManager.cpp @@ -188,6 +188,8 @@ int BulletPhysicsManager::addArticulatedObjectFromURDF( articulatedObject->btMultiBody_->getLinkCollider(linkIx), linkObjectId); } + // render visual shapes if either no skinned mesh is present or if the debug + // flag is enabled bool renderVisualShapes = !renderAssetPath || model->getDebugRenderPrimitives(); if (renderVisualShapes) { diff --git a/src/tests/SimTest.cpp b/src/tests/SimTest.cpp index f67e2832d7..0b2522cb0f 100644 --- a/src/tests/SimTest.cpp +++ b/src/tests/SimTest.cpp @@ -1078,7 +1078,8 @@ void SimTest::getRuntimePerfStats() { void SimTest::testArticulatedObjectSkinned() { ESP_DEBUG() << "Starting Test : testArticulatedObjectSkinned"; - const std::string urdfFile = "data/test_assets/urdf/skinned_prism.urdf"; + const std::string urdfFile = + Cr::Utility::Path::join(TEST_ASSETS, "urdf/skinned_prism.urdf"); // create a simulator SimulatorConfiguration simConfig{};