FBX -> Scene, part 2. Code changes, file renames (#1704)
* First pass FBX -> Scene File conversion. This is the simple pass, minimizing code changes and focused on comments. Signed-off-by: stankowi <4838196+AMZN-stankowi@users.noreply.github.com> * Step 1 of part 2 of the FBX -> Scene rename Signed-off-by: stankowi <4838196+AMZN-stankowi@users.noreply.github.com> * Renaming FbxSceneBuilder folder to SceneBuilder Signed-off-by: stankowi <4838196+AMZN-stankowi@users.noreply.github.com> * Renamed files Signed-off-by: stankowi <4838196+AMZN-stankowi@users.noreply.github.com> * More FBX -> Scene Signed-off-by: stankowi <4838196+AMZN-stankowi@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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 <SceneAPI/SceneBuilder/Importers/AssImpImporterUtilities.h>
|
||||
|
||||
#include <AzCore/Debug/Trace.h>
|
||||
#include <AzCore/StringFunc/StringFunc.h>
|
||||
|
||||
#include <assimp/scene.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
namespace SceneAPI
|
||||
{
|
||||
namespace SceneBuilder
|
||||
{
|
||||
bool IsSkinnedMesh(const aiNode& node, const aiScene& scene)
|
||||
{
|
||||
unsigned boneCount = 0;
|
||||
|
||||
for (unsigned mesh = 0; mesh < node.mNumMeshes; ++mesh)
|
||||
{
|
||||
if (scene.mMeshes[node.mMeshes[mesh]]->HasBones())
|
||||
{
|
||||
++boneCount;
|
||||
}
|
||||
}
|
||||
|
||||
if (boneCount > 1 && boneCount != node.mNumMeshes)
|
||||
{
|
||||
AZ_Error("AssImpImporterUtilities", false, "Node has %d meshes but only %d are skinned. "
|
||||
"This is unexpected and may result in errors", node.mNumMeshes, boneCount);
|
||||
}
|
||||
|
||||
return boneCount > 0;
|
||||
}
|
||||
|
||||
bool IsPivotNode(const aiString& nodeName, size_t* pos)
|
||||
{
|
||||
AZStd::string_view name(nodeName.C_Str(), nodeName.length);
|
||||
|
||||
size_t myPos;
|
||||
|
||||
if (!pos)
|
||||
{
|
||||
pos = &myPos;
|
||||
}
|
||||
|
||||
*pos = AZ::StringFunc::Find(name, PivotNodeMarker);
|
||||
|
||||
return *pos != name.npos;
|
||||
}
|
||||
|
||||
void SplitPivotNodeName(const aiString& nodeName, size_t pivotPos, AZStd::string_view& baseNodeName, AZStd::string_view& pivotType)
|
||||
{
|
||||
AZStd::string_view nodeNameView(nodeName.data, nodeName.length);
|
||||
baseNodeName = AZStd::string_view(nodeNameView.substr(0, pivotPos));
|
||||
pivotType = AZStd::string_view(nodeNameView.substr(pivotPos + sizeof PivotNodeMarker - 1));
|
||||
}
|
||||
|
||||
aiMatrix4x4 GetConcatenatedLocalTransform(const aiNode* currentNode)
|
||||
{
|
||||
const aiNode* parent = currentNode->mParent;
|
||||
aiMatrix4x4 combinedTransform = currentNode->mTransformation;
|
||||
|
||||
while (parent)
|
||||
{
|
||||
size_t pos;
|
||||
|
||||
if (IsPivotNode(parent->mName, &pos))
|
||||
{
|
||||
combinedTransform = parent->mTransformation * combinedTransform;
|
||||
parent = parent->mParent;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return combinedTransform;
|
||||
}
|
||||
} // namespace SceneBuilder
|
||||
} // namespace SceneAPI
|
||||
} // namespace AZ
|
||||
Reference in New Issue
Block a user