Files
o3de/Code/Tools/SceneAPI/SDKWrapper/AssImpNodeWrapper.cpp
T
amzn-victor eb1593a19c Changes to SDK wrappers and functions to allow more flexible scene file processing (#3112)
These changes allow for usage of different asset import SDKs to process scene files.

    Move AssImp specific code out of node, scene & material wrapper parent classes and into child wrapper classes (AssImpNodeWrapper, etc.), allowing child classes to expose import SDK code. Allows for more convenient implementation of other import SDK's elsewhere (such as in a gem).
    Add a loadingComponentUuid parameter to LoadSceneFromVerifiedPath to allow for usage of different loading components. Changed tests and all calls to this function accordingly.


* Move AssImp specific code out of wrapper parent classes and into child classes for gem usage

Signed-off-by: Victor Huang <huavicto@amazon.com>

* Add loadingComponentUuid parameter to LoadSceneFromVerifiedPath function

Signed-off-by: Victor Huang <huavicto@amazon.com>

* Make wrapper members protected, change pointer cast

Signed-off-by: Victor Huang <huavicto@amazon.com>

* Adding spaces to fix style

Signed-off-by: Victor Huang <huavicto@amazon.com>

* Fix for pointer cast causing test failures

Signed-off-by: Victor Huang <huavicto@amazon.com>
2021-08-17 06:52:20 -07:00

86 lines
2.8 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AzCore/Debug/Trace.h>
#include <AzCore/Math/Sha1.h>
#include <AzCore/std/string/string.h>
#include <SceneAPI/SDKWrapper/AssImpNodeWrapper.h>
#include <assimp/scene.h>
namespace AZ
{
namespace AssImpSDKWrapper
{
AssImpNodeWrapper::AssImpNodeWrapper(aiNode* sourceNode)
: m_assImpNode(sourceNode)
{
AZ_Assert(m_assImpNode, "Asset Importer Node cannot be null");
}
aiNode* AssImpNodeWrapper::GetAssImpNode() const
{
return m_assImpNode;
}
const char* AssImpNodeWrapper::GetName() const
{
return m_assImpNode->mName.C_Str();
}
AZ::u64 AssImpNodeWrapper::GetUniqueId() const
{
AZStd::string fingerprintString;
fingerprintString.append(GetName());
fingerprintString.append(m_assImpNode->mParent ? m_assImpNode->mParent->mName.C_Str() : "");
AZStd::string extraInformation = AZStd::string::format("%i%i", m_assImpNode->mNumChildren, m_assImpNode->mNumMeshes);
fingerprintString.append(extraInformation);
AZ::Sha1 sha;
sha.ProcessBytes(fingerprintString.data(), fingerprintString.size());
AZ::u32 digest[5]; //sha1 populate a 5 element array of AZ:u32
sha.GetDigest(digest);
return (static_cast<AZ::u64>(digest[0]) << 32) | digest[1];
}
int AssImpNodeWrapper::GetChildCount() const
{
return m_assImpNode->mNumChildren;
}
const std::shared_ptr<SDKNode::NodeWrapper> AssImpNodeWrapper::GetChild(int childIndex) const
{
aiNode* child = m_assImpNode->mChildren[childIndex];
AZ_Error("SDKWrapper", child, "Cannot get child assImpNode at index %d", childIndex);
return child ? std::shared_ptr<SDKNode::NodeWrapper>(new AssImpNodeWrapper(child)) : nullptr;
}
const bool AssImpNodeWrapper::ContainsMesh()
{
return m_assImpNode->mNumMeshes != 0;
}
bool AssImpNodeWrapper::ContainsBones(const aiScene& scene) const
{
for (unsigned meshIndex = 0; meshIndex < m_assImpNode->mNumMeshes; ++meshIndex)
{
if (scene.mMeshes[m_assImpNode->mMeshes[meshIndex]]->HasBones())
{
return true;
}
}
return false;
}
int AssImpNodeWrapper::GetMaterialCount() const
{
// one mesh uses only a single material
return m_assImpNode->mNumMeshes;
}
} // namespace AssImpSDKWrapper
} // namespace AZ