diff options
| author | Anton Novoselov <[email protected]> | 2017-08-01 12:53:38 +0300 |
|---|---|---|
| committer | Anton Novoselov <[email protected]> | 2017-08-01 12:53:38 +0300 |
| commit | 236f03c0b9a4982328ed1201978f7f69d192d9b2 (patch) | |
| tree | e486f2fa39dba203563895541e92c60ed3e25759 /tools/ArtistTools/source/CoreLib/Anim | |
| parent | Added screens to welcome page (diff) | |
| download | blast-236f03c0b9a4982328ed1201978f7f69d192d9b2.tar.xz blast-236f03c0b9a4982328ed1201978f7f69d192d9b2.zip | |
Blast 1.1 release (windows / linux)
see docs/release_notes.txt for details
Diffstat (limited to 'tools/ArtistTools/source/CoreLib/Anim')
| -rw-r--r-- | tools/ArtistTools/source/CoreLib/Anim/AnimUtil.cpp | 8 | ||||
| -rw-r--r-- | tools/ArtistTools/source/CoreLib/Anim/AnimUtil.h | 16 | ||||
| -rw-r--r-- | tools/ArtistTools/source/CoreLib/Anim/FbxUtil.cpp | 60 | ||||
| -rw-r--r-- | tools/ArtistTools/source/CoreLib/Anim/FbxUtil.h | 5 |
4 files changed, 47 insertions, 42 deletions
diff --git a/tools/ArtistTools/source/CoreLib/Anim/AnimUtil.cpp b/tools/ArtistTools/source/CoreLib/Anim/AnimUtil.cpp index 5ab1563..f070f42 100644 --- a/tools/ArtistTools/source/CoreLib/Anim/AnimUtil.cpp +++ b/tools/ArtistTools/source/CoreLib/Anim/AnimUtil.cpp @@ -58,7 +58,7 @@ void AnimationCache::Initialize(int numBones, NvInt32 frameStart, NvInt32 frameE void AnimationCache::Allocate() { m_pBoneMatrices = new atcore_float4x4[m_numFrames * m_numBones]; -// m_pBoneNames = new char[NV_HAIR_MAX_STRING * m_numBones]; + m_pBoneNames = new char[NV_HAIR_MAX_STRING * m_numBones]; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -104,14 +104,12 @@ int AnimationCache::FindBone(const char *toFind) const { if (!toFind) return -1; - /* for (int i = 0; i < m_numBones; i++) { const char* boneName = GetBoneName(i); if (!strcmp(boneName, toFind)) return i; } - */ return -1; } @@ -122,7 +120,7 @@ bool AnimationCache::FindBoneMapping( int numBones, const NvChar* boneNames, int for (int i = 0; i < numBones; i++) { - //mappedBoneId[i] = FindBone(boneNames + i * NV_HAIR_MAX_STRING); + mappedBoneId[i] = FindBone(boneNames + i * NV_HAIR_MAX_STRING); } return true; @@ -140,7 +138,7 @@ void BoneData::Allocate(NvUInt32 numBones) m_pBoneMatrices = new atcore_float4x4[numBones]; m_pSkinDQs = new atcore_dualquaternion[numBones]; - //m_pBoneNames = new char[NV_HAIR_MAX_STRING * m_numBones]; + m_pBoneNames = new char[NV_HAIR_MAX_STRING * m_numBones]; m_pMappedBoneId = new int[numBones]; for (int i = 0; i < numBones; i++) diff --git a/tools/ArtistTools/source/CoreLib/Anim/AnimUtil.h b/tools/ArtistTools/source/CoreLib/Anim/AnimUtil.h index 8de718c..5fd239b 100644 --- a/tools/ArtistTools/source/CoreLib/Anim/AnimUtil.h +++ b/tools/ArtistTools/source/CoreLib/Anim/AnimUtil.h @@ -29,8 +29,7 @@ #include "MathUtil.h" #include <string.h> - -//#include <Nv/Blast/NvHairSdk.h> +#define NV_HAIR_MAX_STRING 128 //////////////////////////////////////////////////////////////////////////////////////// // cache for animated bone data @@ -67,7 +66,7 @@ struct CORELIB_EXPORT AnimationCache const atcore_float4x4* GetNodeMatrices(int index) const { return m_pBoneMatrices + index * m_numBones; } atcore_float4x4* GetNodeMatrices(int index) { return m_pBoneMatrices + index * m_numBones; } - /* + const char* GetBoneName(int index) const { return m_pBoneNames + index * NV_HAIR_MAX_STRING; @@ -78,7 +77,7 @@ struct CORELIB_EXPORT AnimationCache char* str = m_pBoneNames + index * NV_HAIR_MAX_STRING; strcpy_s(str, NV_HAIR_MAX_STRING, boneName); } - */ + int FindBone(const char *boneName) const; bool FindBoneMapping( int numBones, const NvChar* boneNames, int* mappedBoneId) const; @@ -117,7 +116,7 @@ public: void Allocate(NvUInt32 numBones); void Release(); - /* + const char* getBoneName(int index) { return m_pBoneNames + index * NV_HAIR_MAX_STRING; @@ -128,7 +127,7 @@ public: char* str = m_pBoneNames + index * NV_HAIR_MAX_STRING; strcpy_s(str, NV_HAIR_MAX_STRING, boneName); } - */ + void InitializeAnimationCache(AnimationCache* pGlobalCache, const char* nodeName); bool Update(float frameTime, const char* rootBoneName, bool bindPose, bool zup); @@ -164,6 +163,7 @@ struct CORELIB_EXPORT MeshDesc atcore_float3* m_pVertexNormals; atcore_float3* m_pFaceNormals; atcore_float3* m_pTangents; + atcore_float3 m_ColorRGB; NvUInt32* m_pIndices; atcore_float2* m_pTexCoords; @@ -180,7 +180,9 @@ public: m_pIndices(nullptr), m_pTexCoords(nullptr) - {} + { + m_ColorRGB = gfsdk_makeFloat3(0, 0, 0); + } void Allocate(NvUInt32 numVertices, NvUInt32 numTriangles); void Release(); diff --git a/tools/ArtistTools/source/CoreLib/Anim/FbxUtil.cpp b/tools/ArtistTools/source/CoreLib/Anim/FbxUtil.cpp index 97ba7d8..1d78d5c 100644 --- a/tools/ArtistTools/source/CoreLib/Anim/FbxUtil.cpp +++ b/tools/ArtistTools/source/CoreLib/Anim/FbxUtil.cpp @@ -35,8 +35,7 @@ #include "FbxUtil.h" #include "MathUtil.h" - -//#include <Nv/Blast/NvHairSdk.h> +#include "GlobalSettings.h" // local functions used only in this file namespace { @@ -138,7 +137,8 @@ FbxUtil::Release(void) } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -bool FbxUtil::Initialize(const char* fbxFileName, float sceneUnit) +//// if fbx uses one unit which is not supported, we will also convert its unit. +bool FbxUtil::Initialize(const char* fbxFileName, nvidia::Float& fbxSceneUnit, nvidia::Float toScneUnit, bool bConvertUnit) { if (fbxFileName) { @@ -162,12 +162,15 @@ bool FbxUtil::Initialize(const char* fbxFileName, float sceneUnit) FbxGlobalSettings& settings = s_FbxScene->GetGlobalSettings(); FbxSystemUnit fbxUnit = settings.GetSystemUnit(); - - if ((sceneUnit > 0.0f) && (sceneUnit != fbxUnit.GetScaleFactor())) - { - FbxSystemUnit convertUnit(sceneUnit); - convertUnit.ConvertScene(s_FbxScene); - } + fbxSceneUnit = fbxUnit.GetScaleFactor(); + bool bSupported = GlobalSettings::Inst().isSupportedUnitByUnitInCm(fbxSceneUnit); + bool bNeedConvert = ((toScneUnit > 0.0f) && bConvertUnit && (fabs(toScneUnit - fbxSceneUnit) > 0.001f)); + if (bNeedConvert || !bSupported) + { + // if FBX has a non-supported unit, we still convert its unit + FbxSystemUnit convertUnit(toScneUnit); + convertUnit.ConvertScene(s_FbxScene); + } s_FbxImporter->Destroy(); @@ -186,9 +189,6 @@ bool FbxUtil::Initialize(const char* fbxFileName, float sceneUnit) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// bool FbxUtil::GetGlobalSettings(float* pStartFrame, float* pEndFrame, float *pFps, int *upAxis, char* rootBoneName) { - return false; - - /* if ( !s_FbxScene) return false; @@ -237,7 +237,6 @@ bool FbxUtil::GetGlobalSettings(float* pStartFrame, float* pEndFrame, float *pFp } return true; - */ } ///////////////////////////////////////////////////////////////////////////// @@ -245,9 +244,6 @@ bool FbxUtil::GetGlobalSettings(float* pStartFrame, float* pEndFrame, float *pFp bool FbxUtil::InitializeAnimationCache(AnimationCache& animCache) { - return false; - - /* if (!s_FbxScene) return false; @@ -284,7 +280,6 @@ FbxUtil::InitializeAnimationCache(AnimationCache& animCache) } return true; - */ } //////////////////////////////////////////////////////////////////////////////////////// @@ -326,9 +321,6 @@ static int GetNumMeshPoints( FbxNode* pFbxNode) //////////////////////////////////////////////////////////////////////////////////////// static bool GetBoneData(FbxSkin *pFbxSkin, FbxNode* pFbxNode, NvChar* pBoneNames, atcore_float4x4 *pBindPoses) { - return false; - - /* if (!pFbxSkin || !pFbxNode) return false; @@ -361,7 +353,6 @@ static bool GetBoneData(FbxSkin *pFbxSkin, FbxNode* pFbxNode, NvChar* pBoneNames } } return true; - */ } //////////////////////////////////////////////////////////////////////////////////////// @@ -455,9 +446,6 @@ static bool GetSkinningWeights(FbxSkin* pFbxSkin, atcore_float4* boneIndices, at //////////////////////////////////////////////////////////////////////////////////////// bool FbxUtil::InitializeSkinData( const char* meshName, SkinData& skinData) { - return false; - - /* FbxNode* pFbxNode = FindNodeByName(s_FbxScene, meshName); if (!pFbxNode) return false; @@ -506,11 +494,10 @@ bool FbxUtil::InitializeSkinData( const char* meshName, SkinData& skinData) } return true; - */ } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -bool FbxUtil::GetMeshInfo(int* numMeshes, char** meshNames, char** skinned) +bool FbxUtil::GetMeshInfo(int* numMeshes, char** meshNames, char** parents, char** skinned) { int cnt = 0; @@ -524,6 +511,9 @@ bool FbxUtil::GetMeshInfo(int* numMeshes, char** meshNames, char** skinned) char *pNameBuffer = new char[cnt * 128]; char *pSkinnedBuffer = new char[cnt]; + char *pParentBuffer = new char[cnt * 128]; + memset(pParentBuffer, 0, cnt * 128); + cnt = 0; for (int i = 0; i < s_FbxScene->GetNodeCount(); i++) { @@ -534,6 +524,12 @@ bool FbxUtil::GetMeshInfo(int* numMeshes, char** meshNames, char** skinned) strcpy(pNameBuffer + cnt * 128, pNode->GetName()); + FbxNode* pParentNode = pNode->GetParent(); + if (pParentNode != nullptr) + { + strcpy(pParentBuffer + cnt * 128, pParentNode->GetName()); + } + pSkinnedBuffer[cnt] = checkSkinned(pNode); cnt++; @@ -548,6 +544,7 @@ bool FbxUtil::GetMeshInfo(int* numMeshes, char** meshNames, char** skinned) delete []pSkinnedBuffer; *meshNames = pNameBuffer; + *parents = pParentBuffer; return true; } @@ -563,6 +560,8 @@ bool FbxUtil::GetMeshMaterials( const NvChar* meshName, int *numMaterials, MeshM return false; int numMats = pNode->GetMaterialCount(); + if (numMats == 0) + return false; *materials = new MeshMaterial[numMats]; @@ -663,6 +662,9 @@ bool FbxUtil::CreateMeshDescriptor(const char* meshName, MeshDesc &desc) if (!pMesh) return false; + FbxDouble3 meshColor = pMesh->Color.Get(); + desc.m_ColorRGB = gfsdk_makeFloat3(meshColor[0], meshColor[1], meshColor[2]); + int cpCount = pMesh->GetControlPointsCount(); int triCount = 0; @@ -677,8 +679,12 @@ bool FbxUtil::CreateMeshDescriptor(const char* meshName, MeshDesc &desc) // read positions FbxVector4* points = pMesh->GetControlPoints(); + FbxAMatrix matrixGeo = pNode->EvaluateGlobalTransform(); for (int i = 0; i < desc.m_NumVertices; i++) - desc.m_pVertices[i] = gfsdk_makeFloat3(float(points[i].mData[0]), float(points[i].mData[1]), float(points[i].mData[2])); + { + FbxVector4 v = matrixGeo.MultT(points[i]); + desc.m_pVertices[i] = gfsdk_makeFloat3(v.mData[0], v.mData[1], v.mData[2]); + } memset(desc.m_pTexCoords, 0, sizeof(atcore_float2) * desc.m_NumTriangles * 3); diff --git a/tools/ArtistTools/source/CoreLib/Anim/FbxUtil.h b/tools/ArtistTools/source/CoreLib/Anim/FbxUtil.h index 26e61a9..5cbf18c 100644 --- a/tools/ArtistTools/source/CoreLib/Anim/FbxUtil.h +++ b/tools/ArtistTools/source/CoreLib/Anim/FbxUtil.h @@ -29,7 +29,6 @@ #include "AnimUtil.h" -//#include <Nv/Blast/NvHairSdk.h> //////////////////////////////////////////////////////////////////////////////////////// // Helper for fbx file load @@ -38,7 +37,7 @@ class CORELIB_EXPORT FbxUtil public: /// initialize fbx loader. - static bool Initialize(const nvidia::Char* fbxFileName, nvidia::Float sceneUnit = 0.0f); + static bool Initialize(const nvidia::Char* fbxFileName, nvidia::Float& fbxSceneUnit, float toScneUnit = 0.0f, bool bConvertUnit = true); static bool Release(void); static bool InitializeAnimationCache(AnimationCache& cache); @@ -53,7 +52,7 @@ public: static bool CreateMeshDescriptor(const nvidia::Char* meshName, MeshDesc &meshDesc); /// get all the renderable meshes from the fbx scene - static bool GetMeshInfo(int* numMeshes, char** meshNames, char** skinned = 0); + static bool GetMeshInfo(int* numMeshes, char** meshNames, char** parents, char** skinned); /// get mesh material info from fbx scene static bool GetMeshMaterials(const nvidia::Char* meshName, int *numMaterials, MeshMaterial** materials); |