void FBXSceneInstance::ProcessNode(FbxNode* pNode, FbxNodeAttribute::EType attributeType) { if( !pNode ) return; FbxNodeAttribute* pNodeAttribute = pNode->GetNodeAttribute(); if (pNodeAttribute) { if( pNodeAttribute->GetAttributeType() == attributeType ) { switch(pNodeAttribute->GetAttributeType()) { case FbxNodeAttribute::EType::eSkeleton: { ProcessSkeleton(pNode); break; } default: break; }; } } for( int i = 0; i < pNode->GetChildCount(); ++i ) { ProcessNode(pNode->GetChild(i), attributeType); } }
void FBXSceneImporter::read_node(FbxNode* pNode) { for (int i = 0; i < pNode->GetNodeAttributeCount(); i++) { FbxNodeAttribute* pAttribute = pNode->GetNodeAttributeByIndex(i); FbxNodeAttribute::EType attribute_type = pAttribute->GetAttributeType(); if (attribute_type == FbxNodeAttribute::eMesh) { FbxMesh* pMesh = (FbxMesh*)pAttribute; read_mesh(pNode, pMesh); } else if (attribute_type == FbxNodeAttribute::eLight) { FbxLight* pLight = (FbxLight*)pAttribute; read_light(pNode, pLight); } else if (attribute_type == FbxNodeAttribute::eCamera) { FbxCamera* pCamera = (FbxCamera*)pAttribute; read_camera(pNode, pCamera); } } int materialCount = pNode->GetSrcObjectCount<FbxSurfaceMaterial>(); // Recursively print the children. for (int j = 0; j < pNode->GetChildCount(); j++) { read_node(pNode->GetChild(j)); } }
// 三角形化 void CFBXLoader::TriangulateRecursive(FbxNode* pNode) { FbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute(); if (lNodeAttribute) { if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh || lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eNurbs || lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eNurbsSurface || lNodeAttribute->GetAttributeType() == FbxNodeAttribute::ePatch) { FbxGeometryConverter lConverter(pNode->GetFbxManager()); // これでどんな形状も三角形化 #if 0 lConverter.TriangulateInPlace(pNode); // 古い手法 #endif // 0 lConverter.Triangulate( mScene, true ); } } const int lChildCount = pNode->GetChildCount(); for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex) { // 子ノードを探索 TriangulateRecursive(pNode->GetChild(lChildIndex)); } }
void FBXImporter::WalkHierarchy(FbxNode* fbxNode, int depth) { FbxNodeAttribute* nodeAttribute = fbxNode->GetNodeAttribute(); if (nodeAttribute == nullptr) { Log("Name:%s NodeType:None\n", fbxNode->GetName()); } else { switch (nodeAttribute->GetAttributeType()) { case FbxNodeAttribute::eMarker: break; case FbxNodeAttribute::eSkeleton: break; case FbxNodeAttribute::eMesh: Log("Name:%s NodeType:Mesh\n", fbxNode->GetName()); ProcessMesh(nodeAttribute); break; case FbxNodeAttribute::eCamera: Log("Name:%s NodeType:Camera\n", fbxNode->GetName()); break; case FbxNodeAttribute::eLight: Log("Name:%s NodeType:Light\n", fbxNode->GetName()); break; case FbxNodeAttribute::eBoundary: break; case FbxNodeAttribute::eOpticalMarker: break; case FbxNodeAttribute::eOpticalReference: break; case FbxNodeAttribute::eCameraSwitcher: break; case FbxNodeAttribute::eNull: break; case FbxNodeAttribute::ePatch: break; case FbxNodeAttribute::eNurbs: break; case FbxNodeAttribute::eNurbsSurface: break; case FbxNodeAttribute::eNurbsCurve: break; case FbxNodeAttribute::eTrimNurbsSurface: break; case FbxNodeAttribute::eUnknown: break; default: break; } } for (int i = 0; i < fbxNode->GetChildCount(); i++) { WalkHierarchy(fbxNode->GetChild(i), depth + 1); } }
bool fbxLoader2::IsMeshSkeleton(FbxNode* node) { FbxNodeAttribute * attrib = node->GetNodeAttribute(); if( !attrib ) return false; bool result = attrib->GetAttributeType() == FbxNodeAttribute::eSkeleton;// && !((FbxSkeleton*) attrib)->GetSkeletonType() == FbxSkeleton::eLimbNode; return result; }
void FBXMesh::Builder::unloadCacheRecursive(FbxNode * pNode) { // Unload the material cache const int lMaterialCount = pNode->GetMaterialCount(); for (int lMaterialIndex = 0; lMaterialIndex < lMaterialCount; ++lMaterialIndex) { FbxSurfaceMaterial * lMaterial = pNode->GetMaterial(lMaterialIndex); if (lMaterial && lMaterial->GetUserDataPtr()) { FBXMaterialCache* lMaterialCache = static_cast<FBXMaterialCache*>(lMaterial->GetUserDataPtr()); lMaterial->SetUserDataPtr(NULL); delete lMaterialCache; } } FbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute(); if (lNodeAttribute) { // Unload the mesh cache if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh) { FbxMesh * lMesh = pNode->GetMesh(); if (lMesh && lMesh->GetUserDataPtr()) { #ifndef USE_META_DATA VBOMesh * lMeshCache = static_cast<VBOMesh *>(lMesh->GetUserDataPtr()); lMesh->SetUserDataPtr(NULL); delete lMeshCache; #else FbxMetaData * fbxMetaData = static_cast<FbxMetaData*>(lMesh->GetUserDataPtr()); lMesh->SetUserDataPtr(NULL); delete fbxMetaData; #endif } } // Unload the light cache else if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eLight) { FbxLight * lLight = pNode->GetLight(); if (lLight && lLight->GetUserDataPtr()) { FBXLightCache* lLightCache = static_cast<FBXLightCache*>(lLight->GetUserDataPtr()); lLight->SetUserDataPtr(NULL); delete lLightCache; } } } const int lChildCount = pNode->GetChildCount(); for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex) { unloadCacheRecursive(pNode->GetChild(lChildIndex)); } }
// Bake node attributes and materials under this node recursively. // Currently only mesh, light and material. void LoadCacheRecursive(SceneContext* pSceneCtx, FbxNode * pNode, FbxAnimLayer * pAnimLayer, bool pSupportVBO) { // Bake material and hook as user data. const int lMaterialCount = pNode->GetMaterialCount(); for (int lMaterialIndex = 0; lMaterialIndex < lMaterialCount; ++lMaterialIndex) { FbxSurfaceMaterial * lMaterial = pNode->GetMaterial(lMaterialIndex); if (lMaterial && !lMaterial->GetUserDataPtr()) { FbxAutoPtr<MaterialCache> lMaterialCache(new MaterialCache); if (lMaterialCache->Initialize(lMaterial)) { lMaterial->SetUserDataPtr(lMaterialCache.Release()); } } } FbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute(); if (lNodeAttribute) { // Bake mesh as VBO(vertex buffer object) into GPU. if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh) { FbxMesh * lMesh = pNode->GetMesh(); if (pSupportVBO && lMesh && !lMesh->GetUserDataPtr()) { FbxAutoPtr<VBOMesh> lMeshCache(new VBOMesh); if (lMeshCache->Initialize(pSceneCtx, lMesh)) { lMesh->SetUserDataPtr(lMeshCache.Release()); } } } // Bake light properties. else if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eLight) { FbxLight * lLight = pNode->GetLight(); if (lLight && !lLight->GetUserDataPtr()) { FbxAutoPtr<LightCache> lLightCache(new LightCache); if (lLightCache->Initialize(lLight, pAnimLayer)) { lLight->SetUserDataPtr(lLightCache.Release()); } } } } const int lChildCount = pNode->GetChildCount(); for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex) { LoadCacheRecursive(pSceneCtx, pNode->GetChild(lChildIndex), pAnimLayer, pSupportVBO); } }
//Recursive function going through the entire FBX node hierarchy looking for mesh nodes void FbxFileReader::ReadMeshesRecursive(FbxNode* pNode) { FbxNodeAttribute* pAttribute = pNode->GetNodeAttribute(); if(pAttribute && pAttribute->GetAttributeType() == FbxNodeAttribute::eMesh) m_Meshes.push_back( Mesh( pNode->GetMesh() ) ); //Search children unsigned int nrOfChildren = pNode->GetChildCount(); for(unsigned int i=0; i < nrOfChildren; ++i) ReadMeshesRecursive(pNode->GetChild(i)); }
void LoadMeshes(FbxNode* pFbxNode, packed_freelist<Mesh>& sceneMeshes) { // Material const uint32_t materialCount = pFbxNode->GetMaterialCount(); for (uint32_t i = 0; i < materialCount; ++i) { FbxSurfaceMaterial* pFbxMaterial = pFbxNode->GetMaterial(i); if (pFbxMaterial && !pFbxMaterial->GetUserDataPtr()) { FbxAutoPtr<Material> pMaterial(new Material); if (pMaterial->init(pFbxMaterial)) { pFbxMaterial->SetUserDataPtr(pMaterial.Release()); } } } FbxNodeAttribute* nodeAttribute = pFbxNode->GetNodeAttribute(); if (nodeAttribute) { // Mesh if (nodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh) { FbxMesh* pFbxMesh = pFbxNode->GetMesh(); if (pFbxMesh && !pFbxMesh->GetUserDataPtr()) { Mesh mesh; if (mesh.init(pFbxMesh)) { sceneMeshes.insert(mesh); } // TODO: FbxAutoPtr<Mesh> pMesh(new Mesh); if (pMesh->init(pFbxMesh)) { pFbxMesh->SetUserDataPtr(pMesh.Release()); } } } // Light else if (nodeAttribute->GetAttributeType() == FbxNodeAttribute::eLight) { FbxLight* pFbxLight = pFbxNode->GetLight(); if (pFbxLight && !pFbxLight->GetUserDataPtr()) { FbxAutoPtr<Light> pLight(new Light); if (pLight->init(pFbxLight)) { pFbxLight->SetUserDataPtr(pLight.Release()); } } } } const int childCount = pFbxNode->GetChildCount(); for (int i = 0; i < childCount; ++i) { LoadMeshes(pFbxNode->GetChild(i), sceneMeshes); } }
// Unload the cache and release the memory under this node recursively. void UnloadCacheRecursive(FbxNode * pNode) { // Unload the material cache const int lMaterialCount = pNode->GetMaterialCount(); for (int lMaterialIndex = 0; lMaterialIndex < lMaterialCount; ++lMaterialIndex) { FbxSurfaceMaterial * lMaterial = pNode->GetMaterial(lMaterialIndex); if (lMaterial && lMaterial->GetUserDataPtr()) { MaterialCache * lMaterialCache = static_cast<MaterialCache *>(lMaterial->GetUserDataPtr()); lMaterial->SetUserDataPtr(NULL); delete lMaterialCache; } } FbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute(); if (lNodeAttribute) { // Unload the mesh cache if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh) { FbxMesh * lMesh = pNode->GetMesh(); if (lMesh && lMesh->GetUserDataPtr()) { VBOMesh * lMeshCache = static_cast<VBOMesh *>(lMesh->GetUserDataPtr()); lMesh->SetUserDataPtr(NULL); delete lMeshCache; } } // Unload the light cache else if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eLight) { FbxLight * lLight = pNode->GetLight(); if (lLight && lLight->GetUserDataPtr()) { LightCache * lLightCache = static_cast<LightCache *>(lLight->GetUserDataPtr()); lLight->SetUserDataPtr(NULL); delete lLightCache; } } } const int lChildCount = pNode->GetChildCount(); for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex) { UnloadCacheRecursive(pNode->GetChild(lChildIndex)); } }
void WalkHierarchy(FbxNode *fbxNode) { FbxNodeAttribute* nodeAtt = fbxNode->GetNodeAttribute(); std::string out; if(nodeAtt == NULL) { printf("null node"); } else { switch (nodeAtt->GetAttributeType()) { case FbxNodeAttribute::eMarker: break; case FbxNodeAttribute::eSkeleton: break; case FbxNodeAttribute::eMesh: ProcessMesh(fbxNode,out); break; case FbxNodeAttribute::eCamera: break; case FbxNodeAttribute::eLight: break; case FbxNodeAttribute::eBoundary: break; case FbxNodeAttribute::eOpticalMarker: break; case FbxNodeAttribute::eOpticalReference: break; case FbxNodeAttribute::eCameraSwitcher: break; case FbxNodeAttribute::eNull: break; case FbxNodeAttribute::ePatch: break; case FbxNodeAttribute::eNurbs: break; case FbxNodeAttribute::eNurbsSurface: break; case FbxNodeAttribute::eNurbsCurve: break; case FbxNodeAttribute::eTrimNurbsSurface: break; case FbxNodeAttribute::eUnknown: break; } } //process children for (int i=0;i<fbxNode->GetChildCount();i++) { WalkHierarchy(fbxNode->GetChild(i)); } void* hFile = CreateFile("test.txt",GENERIC_WRITE ,0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); DWORD byteswrite; WriteFile(hFile, out.c_str(), out.size(),&byteswrite,NULL); FBXSDK_printf("Convert complete!\n"); }
void FbxParser::LoadNode(GameObjectPtr node, FbxNode * fbxNode) { GameObject::Ptr childNode = GameObject::Create(fbxNode->GetName()); ApplyLocalTransform(childNode, fbxNode); childNode->SetParent(node, false); FbxNodeAttribute* fbxNodeAttr = fbxNode->GetNodeAttribute(); if (fbxNodeAttr != nullptr) { auto attrType = fbxNodeAttr->GetAttributeType(); if (attrType == FbxNodeAttribute::eMesh) { LoadMesh(childNode, fbxNode); } } }
// Load Fbx File void GenerateLOD::LoadFbx() { FbxManager *fbxManager = FbxManager::Create(); //Create an IOSetting FbxIOSettings *ios = FbxIOSettings::Create(fbxManager, IOSROOT); fbxManager->SetIOSettings(ios); //Create an impoter FbxImporter *lImporter = FbxImporter::Create(fbxManager, "myImporter"); std::string tmp = std::string(".\\LODs\\") + srcFbxName; bool lImporterStatus = lImporter->Initialize(tmp.c_str(), -1, fbxManager->GetIOSettings()); if (!lImporterStatus) { MessageBox(NULL, "No Scuh File in .\\LODs\\ directory !", "Warning", 0); return; } FbxScene *fbxScene = FbxScene::Create(fbxManager, "myScene"); lImporter->Import(fbxScene); FbxNode *rootNode = fbxScene->GetRootNode(); if (rootNode != NULL) { for (int i = 0; i < rootNode->GetChildCount(); ++i) { FbxNode *node = rootNode->GetChild(i); FbxNodeAttribute *Att = node->GetNodeAttribute(); if (Att != NULL && Att->GetAttributeType() == FbxNodeAttribute::eMesh) { FbxMesh *lMesh = (FbxMesh *)(Att); //FbxMesh *lMesh = dynamic_cast<FbxMesh *>(Att); if (!lMesh->IsTriangleMesh()) { FbxGeometryConverter converter = FbxGeometryConverter(fbxManager); FbxNodeAttribute *Attr = converter.Triangulate(lMesh, true); lMesh = (FbxMesh *)(Attr); } //Following is the SImplification Reduction_EdgesCollapse_UV(node, lMesh, fbxManager, fbxScene); } } } //MessageBox(NULL, "Export Succeed!", "Export", 0); fbxManager->Destroy(); }
void FbxUtil::LoadNode(const SceneNode::Ptr &ntNode, FbxNode* fbxNode) { SceneNode::Ptr childNode = SceneNode::Create(fbxNode->GetName()); // copy transforms. FbxQuaternion fbxQ; fbxQ.ComposeSphericalXYZ(fbxNode->LclRotation.Get()); FbxDouble3 fbxT = fbxNode->LclTranslation.Get(); FbxDouble3 fbxS = fbxNode->LclScaling.Get(); Vector4 furyT((float)fbxT.mData[0] * m_ScaleFactor, (float)fbxT.mData[1] * m_ScaleFactor, (float)fbxT.mData[2] * m_ScaleFactor, 1.0f); Vector4 furyS((float)fbxS.mData[0] * m_ScaleFactor, (float)fbxS.mData[1] * m_ScaleFactor, (float)fbxS.mData[2] * m_ScaleFactor, 1.0f); Quaternion furyR((float)fbxQ.mData[0], (float)fbxQ.mData[1], (float)fbxQ.mData[2], (float)fbxQ.mData[3]); childNode->SetLocalPosition(furyT); childNode->SetLocalRoattion(furyR); childNode->SetLocalScale(furyS); // add to scene graph ntNode->AddChild(childNode); // read Components FbxNodeAttribute* fbxNodeAttr = fbxNode->GetNodeAttribute(); if (fbxNodeAttr != NULL) { FbxNodeAttribute::EType fbxNodeAttrType = fbxNodeAttr->GetAttributeType(); if (fbxNodeAttrType == FbxNodeAttribute::eMesh) { LoadMesh(childNode, fbxNode); } else if (fbxNodeAttrType == FbxNodeAttribute::eLight) { LoadLight(childNode, fbxNode); } } // read child nodes. for (int i = 0; i < fbxNode->GetChildCount(); i++) LoadNode(ntNode, fbxNode->GetChild(i)); }
/* Extract Mesh objects by recursing the scene. They will initialise themselves. */ void SceneImporter::loadCacheRecursive(FbxNode * pNode) { // Bake material and hook as user data. FbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute(); if (lNodeAttribute) { if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh) { FbxMesh * lMesh = pNode->GetMesh(); if (lMesh && !lMesh->GetUserDataPtr()) { _meshes.push_back(std::auto_ptr<Mesh>(new Mesh(lMesh))); } } } const int lChildCount = pNode->GetChildCount(); for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex) { loadCacheRecursive(pNode->GetChild(lChildIndex)); } }
//----------------------------------------------------------------------------------- static void ImportSkeletons(SceneImport* import, FbxNode* node, MatrixStack4x4& matrixStack, Skeleton* skeleton, int parentJointIndex, std::map<int, FbxNode*>& nodeToJointIndex) { if (nullptr == node) { return; } Matrix4x4 mat = GetNodeTransform(node); matrixStack.Push(mat); //Walk the attributes, looking for doot doots. int attributeCount = node->GetNodeAttributeCount(); for (int attributeIndex = 0; attributeIndex < attributeCount; ++attributeIndex) { FbxNodeAttribute* attribute = node->GetNodeAttributeByIndex(attributeIndex); if ((attribute != nullptr) && (attribute->GetAttributeType() == FbxNodeAttribute::eSkeleton)) { //So we have a skeleton FbxSkeleton* fbxSkele = (FbxSkeleton*)attribute; Skeleton* newSkeleton = ImportSkeleton(import, matrixStack, skeleton, parentJointIndex, fbxSkele, nodeToJointIndex); //newSkeleton will either be the same skeleton passed, or a new skeleton, or no skeleton if it was a bad node. //If we got something back- it's what we p[ass on to the next generation. if (newSkeleton != nullptr) { skeleton = newSkeleton; parentJointIndex = skeleton->GetLastAddedJointIndex(); } } } //do the rest of the tree int childCount = node->GetChildCount(); for (int childIndex = 0; childIndex < childCount; ++childIndex) { ImportSkeletons(import, node->GetChild(childIndex), matrixStack, skeleton, parentJointIndex, nodeToJointIndex); } matrixStack.Pop(); }
bool id::FBX::Model::initRec(FbxNode* node, int parentIndex) { FbxNodeAttribute* attrib; size_t numChild; int me = -1; if (node == nullptr) return true; attrib = node->GetNodeAttribute(); if (attrib != nullptr && attrib->GetAttributeType() == FbxNodeAttribute::eMesh) { try { _meshes.push_back(id::FBX::Mesh()); } catch (std::bad_alloc ba) { ba.what(); return false; } me = _meshes.size() - 1; if (_meshes[me].init(node->GetMesh()) == false) return false; if (_hasTexture) _hasTexture = _meshes[me].getHasUV(); } else if (attrib != nullptr && attrib->GetAttributeType() == FbxNodeAttribute::eSkeleton) { if (!initBone(node, parentIndex)) return false; me = _bones.size() - 1; } numChild = node->GetChildCount(); for (size_t i = 0 ; i < numChild ; ++i) if (!initRec(node->GetChild(i), me)) return false; return true; }
void FBXTriangulateRecursive( FbxNode* pNode ) { FbxNodeAttribute* pNodeAttr = pNode->GetNodeAttribute(); if( pNodeAttr ) { if( pNodeAttr->GetAttributeType() == FbxNodeAttribute::eMesh || pNodeAttr->GetAttributeType() == FbxNodeAttribute::eNurbs || pNodeAttr->GetAttributeType() == FbxNodeAttribute::eNurbsSurface || pNodeAttr->GetAttributeType() == FbxNodeAttribute::ePatch ) { FbxGeometryConverter lConverter( pNode->GetFbxManager() ); lConverter.TriangulateInPlace( pNode ); } } const int nChildCount = pNode->GetChildCount(); for( int i = 0; i < nChildCount; i++ ) { FBXTriangulateRecursive( pNode->GetChild( i ) ); } }
/* Recurses through the scene and creates Bones from the eSkeleton nodes found */ void SceneImporter::extractBonesRecursive(FbxNode* pNode) { // Bake material and hook as user data. FbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute(); if (lNodeAttribute) { // Bake mesh as VBO(vertex buffer object) into GPU. if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eSkeleton) { // Add a reference to the Bone object to the node so any meshes that have clusters using this bone can obtain the Bone reference shared_ptr<Bone> bone(new Bone(pNode)); _bones.push_back(bone); pNode->SetUserDataPtr(&_bones.back()); } } const int lChildCount = pNode->GetChildCount(); for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex) { extractBonesRecursive(pNode->GetChild(lChildIndex)); } }
void FBXSceneEncoder::triangulateRecursive(FbxNode* fbxNode) { // Triangulate all NURBS, patch and mesh under this node recursively. FbxNodeAttribute* nodeAttribute = fbxNode->GetNodeAttribute(); if (nodeAttribute) { FbxNodeAttribute::EType type = nodeAttribute->GetAttributeType(); if (type == FbxNodeAttribute::eMesh || type == FbxNodeAttribute::eNurbs || type == FbxNodeAttribute::eNurbsSurface || type == FbxNodeAttribute::ePatch) { FbxGeometryConverter converter(fbxNode->GetFbxManager()); converter.TriangulateInPlace(fbxNode); } } const int childCount = fbxNode->GetChildCount(); for (int childIndex = 0; childIndex < childCount; ++childIndex) { triangulateRecursive(fbxNode->GetChild(childIndex)); } }
// Triangulate all NURBS, patch and mesh under this node recursively. void TriangulateRecursive(FbxNode* pNode) { FbxNodeAttribute* lNodeAttribute = pNode->GetNodeAttribute(); if (lNodeAttribute) { FbxNodeAttribute::EType eAttrType = lNodeAttribute->GetAttributeType(); if (eAttrType == FbxNodeAttribute::eMesh || eAttrType == FbxNodeAttribute::eNurbs || eAttrType == FbxNodeAttribute::eNurbsSurface || eAttrType == FbxNodeAttribute::ePatch) { FbxGeometryConverter lConverter(pNode->GetFbxManager()); lConverter.TriangulateInPlace(pNode); } } const int lChildCount = pNode->GetChildCount(); for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex) { TriangulateRecursive(pNode->GetChild(lChildIndex)); } }
void FBXScene::ProcessAnimation(FbxNode* pNode, const char* strTakeName, float fFrameRate, float fStart, float fStop) { FbxNodeAttribute* pNodeAttribute = pNode->GetNodeAttribute(); if (pNodeAttribute) { if (pNodeAttribute->GetAttributeType() == FbxNodeAttribute::EType::eSkeleton) { if( m_pSkeleton ) { SkeletonBone* pBone = m_pSkeleton->FindBone(pNode->GetName()); if( pBone ) { AnimationKeyFrames* pAnimationKeyFrames = new AnimationKeyFrames(strTakeName); double fTime = 0; while( fTime <= fStop ) { FbxTime takeTime; takeTime.SetSecondDouble(fTime); FbxMatrix matAbsoluteTransform2 = GetAbsoluteTransformFromCurrentTake2(pNode, takeTime); FbxMatrix matParentAbsoluteTransform2 = GetAbsoluteTransformFromCurrentTake2(pNode->GetParent(), takeTime); FbxMatrix matInvParentAbsoluteTransform2 = matParentAbsoluteTransform2.Inverse(); FbxMatrix matTransform2 = matInvParentAbsoluteTransform2 * matAbsoluteTransform2; pAnimationKeyFrames->AddKeyFrame(matTransform2); fTime += 1.0f / fFrameRate; } pBone->AddAnimationKeyFrames(pAnimationKeyFrames); } } } else if (pNodeAttribute->GetAttributeType() == FbxNodeAttribute::EType::eMesh) { Model* pModel = m_Models.Find(pNode->GetName(), NULL); if( pModel ) { AnimationKeyFrames* pAnimationKeyFrames = new AnimationKeyFrames(strTakeName); double fTime = 0; while( fTime <= fStop ) { FbxTime takeTime; takeTime.SetSecondDouble(fTime); FbxMatrix matAbsoluteTransform2 = GetAbsoluteTransformFromCurrentTake2(pNode, takeTime); pAnimationKeyFrames->AddKeyFrame(matAbsoluteTransform2); fTime += 1.0f/fFrameRate; } pModel->AddAnimationKeyFrames(pAnimationKeyFrames); } } } for( int i = 0; i < pNode->GetChildCount(); ++i ) { ProcessAnimation(pNode->GetChild(i), strTakeName, fFrameRate, fStart, fStop); } }
void Tools::DisplayAnimation::DisplayChannels( FbxNode* i_node, FbxAnimLayer* i_animLayer, void (*DisplayCurve) (FbxAnimCurve* i_curve), void (*DisplayListCurve) (FbxAnimCurve* i_curve, FbxProperty* i_property), bool isSwitcher ) { FbxAnimCurve *animCurve = NULL; // Display general curves. if (!isSwitcher) { animCurve = i_node->LclTranslation.GetCurve( i_animLayer, FBXSDK_CURVENODE_COMPONENT_X ); if( animCurve ) { FBXSDK_printf( " TX\n" ); DisplayCommon::DisplayString( " TX" ); DisplayCurve( animCurve ); } animCurve = i_node->LclTranslation.GetCurve( i_animLayer, FBXSDK_CURVENODE_COMPONENT_Y ); if( animCurve ) { FBXSDK_printf( " TY\n" ); DisplayCommon::DisplayString( " TY" ); DisplayCurve( animCurve ); } animCurve = i_node->LclTranslation.GetCurve( i_animLayer, FBXSDK_CURVENODE_COMPONENT_Z ); if( animCurve ) { FBXSDK_printf( " TZ\n" ); DisplayCommon::DisplayString( " TZ" ); DisplayCurve( animCurve ); } animCurve = i_node->LclRotation.GetCurve( i_animLayer, FBXSDK_CURVENODE_COMPONENT_X ); if( animCurve ) { FBXSDK_printf( " RX\n" ); DisplayCommon::DisplayString( " RX" ); DisplayCurve( animCurve ); } animCurve = i_node->LclRotation.GetCurve( i_animLayer, FBXSDK_CURVENODE_COMPONENT_Y ); if( animCurve ) { FBXSDK_printf( " RY\n" ); DisplayCommon::DisplayString( " RY" ); DisplayCurve( animCurve ); } animCurve = i_node->LclRotation.GetCurve( i_animLayer, FBXSDK_CURVENODE_COMPONENT_Z ); if( animCurve ) { FBXSDK_printf( " RZ\n" ); DisplayCommon::DisplayString( " RZ" ); DisplayCurve( animCurve ); } animCurve = i_node->LclScaling.GetCurve( i_animLayer, FBXSDK_CURVENODE_COMPONENT_X ); if( animCurve ) { FBXSDK_printf( " SX\n" ); DisplayCommon::DisplayString( " SX" ); DisplayCurve( animCurve ); } animCurve = i_node->LclScaling.GetCurve( i_animLayer, FBXSDK_CURVENODE_COMPONENT_Y ); if( animCurve ) { FBXSDK_printf( " SY\n" ); DisplayCommon::DisplayString( " SY" ); DisplayCurve( animCurve ); } animCurve = i_node->LclScaling.GetCurve( i_animLayer, FBXSDK_CURVENODE_COMPONENT_Z ); if( animCurve ) { FBXSDK_printf( " SZ\n" ); DisplayCommon::DisplayString( " SZ" ); DisplayCurve( animCurve ); } } // Display curves specific to a light or marker. FbxNodeAttribute *nodeAttribute = i_node->GetNodeAttribute(); if( nodeAttribute ) { animCurve = nodeAttribute->Color.GetCurve( i_animLayer, FBXSDK_CURVENODE_COLOR_RED ); if( animCurve ) { FBXSDK_printf( " Red\n" ); DisplayCommon::DisplayString( " Red" ); DisplayCurve( animCurve ); } animCurve = nodeAttribute->Color.GetCurve( i_animLayer, FBXSDK_CURVENODE_COLOR_GREEN ); if( animCurve ) { FBXSDK_printf( " Green\n" ); DisplayCommon::DisplayString( " Green" ); DisplayCurve( animCurve ); } animCurve = nodeAttribute->Color.GetCurve( i_animLayer, FBXSDK_CURVENODE_COLOR_BLUE ); if( animCurve ) { FBXSDK_printf( " Blue\n" ); DisplayCommon::DisplayString( " Blue" ); DisplayCurve( animCurve ); } // Display curves specific to a light. FbxLight *light = i_node->GetLight(); if( light ) { animCurve = light->Intensity.GetCurve( i_animLayer ); if( animCurve ) { FBXSDK_printf( " Intensity\n" ); DisplayCommon::DisplayString( " Intensity" ); DisplayCurve( animCurve ); } animCurve = light->OuterAngle.GetCurve( i_animLayer ); if( animCurve ) { FBXSDK_printf( " Outer Angle\n" ); DisplayCommon::DisplayString( " Outer Angle" ); DisplayCurve( animCurve ); } animCurve = light->Fog.GetCurve( i_animLayer ); if( animCurve ) { FBXSDK_printf( " Fog\n" ); DisplayCommon::DisplayString( " Fog" ); DisplayCurve( animCurve ); } } // Display curves specific to a camera. FbxCamera *camera = i_node->GetCamera(); if( camera ) { animCurve = camera->FieldOfView.GetCurve( i_animLayer ); if( animCurve ) { FBXSDK_printf( " Field of View\n" ); DisplayCommon::DisplayString( " Field of View" ); DisplayCurve( animCurve ); } animCurve = camera->FieldOfViewX.GetCurve( i_animLayer ); if( animCurve ) { FBXSDK_printf( " Field of View X\n" ); DisplayCommon::DisplayString( " Field of View X" ); DisplayCurve( animCurve ); } animCurve = camera->FieldOfViewY.GetCurve( i_animLayer ); if( animCurve ) { FBXSDK_printf( " Field of View Y\n" ); DisplayCommon::DisplayString( " Field of View Y" ); DisplayCurve( animCurve ); } animCurve = camera->OpticalCenterX.GetCurve( i_animLayer ); if( animCurve ) { FBXSDK_printf( " Optical Center X\n" ); DisplayCommon::DisplayString( " Optical Center X" ); DisplayCurve( animCurve ); } animCurve = camera->OpticalCenterY.GetCurve( i_animLayer ); if( animCurve ) { FBXSDK_printf( " Optical Center Y\n" ); DisplayCommon::DisplayString( " Optical Center Y" ); DisplayCurve( animCurve ); } animCurve = camera->Roll.GetCurve( i_animLayer ); if( animCurve ) { FBXSDK_printf( " Roll\n" ); DisplayCommon::DisplayString( " Roll" ); DisplayCurve( animCurve ); } } // Display curves specific to a geometry. if (nodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh || nodeAttribute->GetAttributeType() == FbxNodeAttribute::eNurbs || nodeAttribute->GetAttributeType() == FbxNodeAttribute::ePatch) { FbxGeometry *geometry = (FbxGeometry*) nodeAttribute; int blendShapeDeformerCount = geometry->GetDeformerCount( FbxDeformer::eBlendShape ); for( int blendShapeIndex = 0; blendShapeIndex<blendShapeDeformerCount; blendShapeIndex++ ) { FbxBlendShape *blendShape = (FbxBlendShape*)geometry->GetDeformer( blendShapeIndex, FbxDeformer::eBlendShape ); int blendShapeChannelCount = blendShape->GetBlendShapeChannelCount(); for( int channelIndex = 0; channelIndex<blendShapeChannelCount; channelIndex++ ) { FbxBlendShapeChannel *channel = blendShape->GetBlendShapeChannel( channelIndex ); const char *channelName = channel->GetName(); animCurve = geometry->GetShapeChannel( blendShapeIndex, channelIndex, i_animLayer, true ); if( animCurve ) { FBXSDK_printf( " Shape %s\n", channelName ); DisplayCommon::DisplayString( " Shape ", channelName ); DisplayCurve( animCurve ); } } } } } // Display curves specific to properties FbxProperty lProperty = i_node->GetFirstProperty(); while( lProperty.IsValid() ) { if( lProperty.GetFlag(FbxPropertyAttr::eUserDefined) ) { FbxString lFbxFCurveNodeName = lProperty.GetName(); FbxAnimCurveNode* curveNode = lProperty.GetCurveNode( i_animLayer ); if( !curveNode ) { lProperty = i_node->GetNextProperty( lProperty ); continue; } FbxDataType dataType = lProperty.GetPropertyDataType(); if( dataType.GetType() == eFbxBool || dataType.GetType() == eFbxDouble || dataType.GetType() == eFbxFloat || dataType.GetType() == eFbxInt ) { FbxString message; message = " Property "; message += lProperty.GetName(); if( lProperty.GetLabel().GetLen() > 0 ) { message += " (Label: "; message += lProperty.GetLabel(); message += ")"; }; DisplayCommon::DisplayString( message ); for( int c = 0; c < curveNode->GetCurveCount(0U); c++ ) { animCurve = curveNode->GetCurve( 0U, c ); if( animCurve ) DisplayCurve( animCurve ); } } else if( dataType.GetType() == eFbxDouble3 || dataType.GetType() == eFbxDouble4 || dataType.Is(FbxColor3DT) || dataType.Is(FbxColor4DT) ) { char* componentName1 = (dataType.Is(FbxColor3DT) ||dataType.Is(FbxColor4DT)) ? (char*)FBXSDK_CURVENODE_COLOR_RED : (char*)"X"; char* componentName2 = (dataType.Is(FbxColor3DT) ||dataType.Is(FbxColor4DT)) ? (char*)FBXSDK_CURVENODE_COLOR_GREEN : (char*)"Y"; char* componentName3 = (dataType.Is(FbxColor3DT) ||dataType.Is(FbxColor4DT)) ? (char*)FBXSDK_CURVENODE_COLOR_BLUE : (char*)"Z"; FbxString message; message = " Property "; message += lProperty.GetName(); if( lProperty.GetLabel().GetLen() > 0 ) { message += " (Label: "; message += lProperty.GetLabel(); message += ")"; } DisplayCommon::DisplayString( message ); for( int c = 0; c < curveNode->GetCurveCount(0U); c++ ) { animCurve = curveNode->GetCurve( 0U, c ); if( animCurve ) { DisplayCommon::DisplayString( " Component ", componentName1 ); DisplayCurve( animCurve ); } } for( int c = 0; c < curveNode->GetCurveCount(1U); c++ ) { animCurve = curveNode->GetCurve(1U, c); if( animCurve ) { DisplayCommon::DisplayString( " Component ", componentName2 ); DisplayCurve( animCurve ); } } for( int c = 0; c < curveNode->GetCurveCount(2U); c++ ) { animCurve = curveNode->GetCurve( 2U, c ); if( animCurve ) { DisplayCommon::DisplayString( " Component ", componentName3 ); DisplayCurve( animCurve ); } } } else if( dataType.GetType() == eFbxEnum ) { FbxString message; message = " Property "; message += lProperty.GetName(); if( lProperty.GetLabel().GetLen() > 0 ) { message += " (Label: "; message += lProperty.GetLabel(); message += ")"; }; DisplayCommon::DisplayString( message ); for( int c = 0; c < curveNode->GetCurveCount(0U); c++ ) { animCurve = curveNode->GetCurve( 0U, c ); if( animCurve ) DisplayListCurve( animCurve, &lProperty ); } } } lProperty = i_node->GetNextProperty( lProperty ); } // while }
void LoadAnimation(AnimationData& aAnimation,FbxNode* aNode,FbxAMatrix& aParentOrientation, FbxPose* aPose, FbxAnimLayer* aCurrentAnimLayer, int parentBone) { FbxAMatrix lGlobalPosition = GetGlobalPosition(aNode, static_cast<FbxTime>(0.0f), aPose, &aParentOrientation); FbxNodeAttribute* lNodeAttribute = aNode->GetNodeAttribute(); int boneId = -1; if (lNodeAttribute) { if(lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eSkeleton) { Bone newBone; newBone.myAnimationTime = GetAnimationTime(aNode,aCurrentAnimLayer); float oneFrameTime = 1.0f/24.0f; CU::Matrix44f fixMatrix; fixMatrix.myMatrix[0] = -1; FbxAMatrix lLocalTransform = aNode->EvaluateLocalTransform(); newBone.myBaseOrientation = fixMatrix * CreateMatrix(lLocalTransform) * fixMatrix; char buffer[32]; _itoa_s<32>(parentBone,buffer,10); newBone.myName = aNode->GetName(); newBone.myName += buffer; int lNodeIndex = aPose->Find(aNode); auto bindPoseMatrix = aPose->GetMatrix(lNodeIndex); FbxAMatrix bindMatrix; memcpy((double*)bindMatrix, (double*)bindPoseMatrix, sizeof(bindMatrix.mData)); FbxAMatrix localPosOffset; memcpy((double*)localPosOffset, (double*)bindPoseMatrix, sizeof(localPosOffset.mData)); localPosOffset = localPosOffset * aParentOrientation.Inverse(); newBone.myBindMatrix = fixMatrix * CreateMatrix(lGlobalPosition.Inverse()) * fixMatrix; CU::Matrix44f localStartOffset = CreateMatrix(bindMatrix.Inverse()); for(float currentFrameTime = 0.0f;currentFrameTime < newBone.myAnimationTime;currentFrameTime+= oneFrameTime) { KeyFrame keyFrame; keyFrame.myTime = currentFrameTime; FbxTime time; time.SetSecondDouble(currentFrameTime); keyFrame.myMatrix = fixMatrix * CreateMatrix(aNode->EvaluateLocalTransform(time)) * fixMatrix; newBone.myFrames.push_back(keyFrame); } FbxAMatrix animationMatrix; FbxSkeleton* sekeleton = aNode->GetSkeleton(); if(sekeleton->IsSkeletonRoot()) { aAnimation.myBindMatrix = CU::Matrix44<float>(); aAnimation.myRootBone = aAnimation.myBones.size(); } boneId = aAnimation.myBones.size(); aNode->SetUserDataPtr((void*)boneId); if(parentBone != -1) { aAnimation.myBones[parentBone].myChilds.push_back(boneId); } newBone.myId = boneId; aAnimation.myBones.push_back(newBone); } } const int lChildCount = aNode->GetChildCount(); for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex) { LoadAnimation( aAnimation, aNode->GetChild(lChildIndex), lGlobalPosition , aPose, aCurrentAnimLayer, boneId); } }
CC_FILE_ERROR FBXFilter::loadFile(const char* filename, ccHObject& container, bool alwaysDisplayLoadDialog/*=true*/, bool* coordinatesShiftEnabled/*=0*/, CCVector3d* coordinatesShift/*=0*/) { // Initialize the SDK manager. This object handles memory management. FbxManager* lSdkManager = FbxManager::Create(); // Create the IO settings object. FbxIOSettings *ios = FbxIOSettings::Create(lSdkManager, IOSROOT); lSdkManager->SetIOSettings(ios); // Import options determine what kind of data is to be imported. // True is the default, but here we’ll set some to true explicitly, and others to false. //(*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_MATERIAL, true); //(*(lSdkManager->GetIOSettings())).SetBoolProp(IMP_FBX_TEXTURE, true); // Create an importer using the SDK manager. FbxImporter* lImporter = FbxImporter::Create(lSdkManager,""); CC_FILE_ERROR result = CC_FERR_NO_ERROR; // Use the first argument as the filename for the importer. if (!lImporter->Initialize(filename, -1, lSdkManager->GetIOSettings())) { ccLog::Warning(QString("[FBX] Error: %1").arg(lImporter->GetStatus().GetErrorString())); result = CC_FERR_READING; } else { // Create a new scene so that it can be populated by the imported file. FbxScene* lScene = FbxScene::Create(lSdkManager,"myScene"); // Import the contents of the file into the scene. if (lImporter->Import(lScene)) { // Print the nodes of the scene and their attributes recursively. // Note that we are not printing the root node because it should // not contain any attributes. FbxNode* lRootNode = lScene->GetRootNode(); std::vector<FbxNode*> nodes; nodes.push_back(lRootNode); while (!nodes.empty()) { FbxNode* lNode = nodes.back(); nodes.pop_back(); const char* nodeName = lNode->GetName(); #ifdef _DEBUG ccLog::Print(QString("Node: %1 - %2 properties").arg(nodeName).arg(lNode->GetNodeAttributeCount())); #endif // scan the node's attributes. for(int i=0; i<lNode->GetNodeAttributeCount(); i++) { FbxNodeAttribute* pAttribute = lNode->GetNodeAttributeByIndex(i); FbxNodeAttribute::EType type = pAttribute->GetAttributeType(); #ifdef _DEBUG ccLog::Print(QString("\tProp. #%1").arg(GetAttributeTypeName(type))); #endif switch(type) { case FbxNodeAttribute::eMesh: { ccMesh* mesh = FromFbxMesh(static_cast<FbxMesh*>(pAttribute),alwaysDisplayLoadDialog,coordinatesShiftEnabled,coordinatesShift); if (mesh) { //apply transformation FbxAMatrix& transform = lNode->EvaluateGlobalTransform(); ccGLMatrix mat; float* data = mat.data(); for (int c=0; c<4; ++c) { FbxVector4 C = transform.GetColumn(c); *data++ = static_cast<float>(C[0]); *data++ = static_cast<float>(C[1]); *data++ = static_cast<float>(C[2]); *data++ = static_cast<float>(C[3]); } mesh->applyGLTransformation_recursive(&mat); if (mesh->getName().isEmpty()) mesh->setName(nodeName); container.addChild(mesh); } } break; case FbxNodeAttribute::eUnknown: case FbxNodeAttribute::eNull: case FbxNodeAttribute::eMarker: case FbxNodeAttribute::eSkeleton: case FbxNodeAttribute::eNurbs: case FbxNodeAttribute::ePatch: case FbxNodeAttribute::eCamera: case FbxNodeAttribute::eCameraStereo: case FbxNodeAttribute::eCameraSwitcher: case FbxNodeAttribute::eLight: case FbxNodeAttribute::eOpticalReference: case FbxNodeAttribute::eOpticalMarker: case FbxNodeAttribute::eNurbsCurve: case FbxNodeAttribute::eTrimNurbsSurface: case FbxNodeAttribute::eBoundary: case FbxNodeAttribute::eNurbsSurface: case FbxNodeAttribute::eShape: case FbxNodeAttribute::eLODGroup: case FbxNodeAttribute::eSubDiv: default: //not handled yet break; } } // Recursively add the children. for(int j=0; j<lNode->GetChildCount(); j++) { nodes.push_back(lNode->GetChild(j)); } } } } // The file is imported, so get rid of the importer. lImporter->Destroy(); // Destroy the SDK manager and all the other objects it was handling. lSdkManager->Destroy(); return container.getChildrenNumber() == 0 ? CC_FERR_NO_LOAD : CC_FERR_NO_ERROR; }
void LoadNodeRecursive(FbxModelData* aModel,AnimationData& aAnimation,FbxNode* aNode,FbxAMatrix& aParentOrientation, FbxPose* aPose, FbxAnimLayer* aCurrentAnimLayer, int parentBone) { parentBone; FbxAMatrix lGlobalPosition = GetGlobalPosition(aNode, static_cast<FbxTime>(0.0f), aPose, &aParentOrientation); FbxNodeAttribute* lNodeAttribute = aNode->GetNodeAttribute(); if (lNodeAttribute && lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eSkeleton) { return; } CU::Matrix44f fixMatrix; fixMatrix = CU::Matrix44<float>::CreateReflectionMatrixAboutAxis(CU::Vector3f(1, 0, 0)); FbxAMatrix lGeometryOffset = GetGeometry(aNode); FbxAMatrix lGlobalOffPosition = lGlobalPosition * lGeometryOffset; FbxAMatrix lRotationOffset = GetRotaionPivot(aNode); aModel->myRotationPivot = fixMatrix * CreateMatrix(lRotationOffset) * fixMatrix; aModel->myOrientation = fixMatrix * CreateMatrix(lGlobalOffPosition) * fixMatrix; int boneId = -1; if (lNodeAttribute) { if(lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eMesh) { aModel->myData = new ModelData(); aModel->myData->myLayout.Init(8); // Geometry offset. // it is not inherited by the children. FillData(aModel->myData, aNode, &aAnimation); } else if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eLight) { FBXLight* newLight = new FBXLight(); FbxLight* light = aNode->GetLight(); newLight->myIntensity = static_cast<float>(light->Intensity); auto color = light->Color.Get(); newLight->myColor = CU::Vector3<float>(static_cast<float>(color.mData[0]), static_cast<float>(color.mData[1]), static_cast<float>(color.mData[2])); auto type = light->LightType.Get(); if (type == FbxLight::eDirectional) { newLight->myType = EDirectionalLight; } else if (type == FbxLight::ePoint) { newLight->myType = EPointLight; } else if (type == FbxLight::eSpot) { newLight->myInnerAngle = static_cast<float>(light->InnerAngle); newLight->myOuterAngle = static_cast<float>(light->OuterAngle); } aModel->myLight = newLight; } else if (lNodeAttribute->GetAttributeType() == FbxNodeAttribute::eCamera) { aModel->myCamera = new Camera(); auto orgCamera = aNode->GetCamera(); aModel->myCamera->myFov = static_cast<float>(orgCamera->FieldOfViewY); } FbxTimeSpan animationInterval; if (aNode->GetAnimationInterval(animationInterval)) { aModel->myAnimationCurves = new AnimationCurves(); aModel->myAnimationCurves->myRotationCurve[0] = aNode->LclRotation.GetCurve(aCurrentAnimLayer, FBXSDK_CURVENODE_COMPONENT_X); aModel->myAnimationCurves->myRotationCurve[1] = aNode->LclRotation.GetCurve(aCurrentAnimLayer, FBXSDK_CURVENODE_COMPONENT_Y); aModel->myAnimationCurves->myRotationCurve[2] = aNode->LclRotation.GetCurve(aCurrentAnimLayer, FBXSDK_CURVENODE_COMPONENT_Z); aModel->myAnimationCurves->myRotationCurve[3] = aNode->LclRotation.GetCurve(aCurrentAnimLayer, FBXSDK_CURVENODE_ROTATION); aModel->myAnimationCurves->myScalingCurve[0] = aNode->LclScaling.GetCurve(aCurrentAnimLayer, FBXSDK_CURVENODE_COMPONENT_X); aModel->myAnimationCurves->myScalingCurve[1] = aNode->LclScaling.GetCurve(aCurrentAnimLayer, FBXSDK_CURVENODE_COMPONENT_Y); aModel->myAnimationCurves->myScalingCurve[2] = aNode->LclScaling.GetCurve(aCurrentAnimLayer, FBXSDK_CURVENODE_COMPONENT_Z); aModel->myAnimationCurves->myTtranslationCurve[0] = aNode->LclTranslation.GetCurve(aCurrentAnimLayer, FBXSDK_CURVENODE_COMPONENT_X); aModel->myAnimationCurves->myTtranslationCurve[1] = aNode->LclTranslation.GetCurve(aCurrentAnimLayer, FBXSDK_CURVENODE_COMPONENT_Y); aModel->myAnimationCurves->myTtranslationCurve[2] = aNode->LclTranslation.GetCurve(aCurrentAnimLayer, FBXSDK_CURVENODE_COMPONENT_Z); int nrOfKeys = 0; nrOfKeys; float startTime = (float)animationInterval.GetStart().GetSecondDouble(); float endTime = (float)animationInterval.GetStop().GetSecondDouble(); aModel->myAnimatedOrientation.Init((int)((endTime - startTime) / (1.0f / 24.0f))); for (float currentTime = startTime; currentTime < endTime; currentTime += 1.0f / 24.0f) { FbxTime time; time.SetSecondDouble(currentTime); KeyFrame animationFrame; animationFrame.myTime = currentTime; animationFrame.myMatrix = fixMatrix * CreateMatrix(aNode->EvaluateLocalTransform(time)) * fixMatrix; aModel->myAnimatedOrientation.Add(animationFrame); } } } const int lChildCount = aNode->GetChildCount(); if(lChildCount > 0) { aModel->myChilds.Init(lChildCount); for (int lChildIndex = 0; lChildIndex < lChildCount; ++lChildIndex) { aModel->myChilds.Add(new FbxModelData()); LoadNodeRecursive(aModel->myChilds.GetLast(), aAnimation, aNode->GetChild(lChildIndex), lGlobalPosition , aPose, aCurrentAnimLayer, boneId); } } }
/***************************************************************** * ProcessLevelNode() Processes a single fbx node and loads in appropiate data * * Ins: node * * Outs: meshes * * Returns: bool * * Mod. Date: 09/02/2015 * Mod. Initials: NH *****************************************************************/ bool CLevelLoader::ProcessLevelNode(FbxNode* node, vector<CMesh>& meshes) { FbxNodeAttribute* attribute = node->GetNodeAttribute(); if (attribute != NULL) { if (attribute->GetAttributeType() == FbxNodeAttribute::eMesh) { CMesh* tempMesh = new CMesh; FbxMesh* attributeMesh = (FbxMesh*)attribute; CAssetManager * assetManager = CAssetManager::GetInstance(); bool errorCheck = assetManager->LoadMesh(attributeMesh, *tempMesh); if (errorCheck == false) { attribute->Destroy(); return false; } //now get prefix and apply texture, collision, etc... const char* objName = node->GetName(); std::string prefix = " "; for (unsigned int i = 0; i < 4; i++) { prefix[i] = objName[i]; } if (strcmp(prefix.c_str(), "Wal_") == 0)//wall prefab { tempMesh->ConvertVertices(); CWallObject* tempWall = new CWallObject("Wall"); tempWall->AddCollider(new CCollider(false, Bounds::AABB, tempMesh->GetVertices())); tempWall->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetNormalMapPS(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Maze_Wall.dds")); tempWall->GetRenderMesh()->SetNormals(L"../Game/Assets/Art/2D/Normal Maps/Rocky.dds"); tempWall->GetRenderMesh()->GetSpecular() = 0.5f; m_cpEnvironmentObjects.push_back(tempWall); m_cpObjectManager->AddObject(tempWall, CObjectManager::eObjectType::Static); } else if (strcmp(prefix.c_str(), "Flr_") == 0)//floor prefab { tempMesh->ConvertVertices(); CFloorObject* tempFloor = new CFloorObject("Floor"); tempFloor->AddCollider(new CCollider(false, Bounds::Plane, tempMesh->GetVertices())); tempFloor->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetNormalMapPS(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Maze_Ground.dds")); tempFloor->GetRenderMesh()->SetNormals(L"../Game/Assets/Art/2D/Normal Maps/Rocky.dds"); tempFloor->GetRenderMesh()->GetSpecular() = 1.5f; m_cpEnvironmentObjects.push_back(tempFloor); m_cpObjectManager->AddObject(tempFloor, CObjectManager::eObjectType::Static); } else if (strcmp(prefix.c_str(), "Grd_") == 0)//ground prefab(around pits) { tempMesh->ConvertVertices(); /* float f3Min[3] = { FLT_MAX, FLT_MAX, FLT_MAX }; float f3Max[3] = { -FLT_MAX, -FLT_MAX, -FLT_MAX }; for (unsigned int i = 0; i < tempMesh->GetVertices().size(); i++) { for (unsigned int xyz = 0; xyz < 3; xyz++) { if (tempMesh->GetVertices()[i].m_fPosition[xyz] < f3Min[xyz]) { f3Min[xyz] = tempMesh->GetVertices()[i].m_fPosition[xyz]; } if (tempMesh->GetVertices()[i].m_fPosition[xyz] > f3Max[xyz]) { f3Max[xyz] = tempMesh->GetVertices()[i].m_fPosition[xyz]; } } } XMFLOAT3 f3Center; f3Center.x = (f3Min[0] + f3Max[0]) / 2.0f; f3Center.y = (f3Min[1] + f3Max[1]) / 2.0f; f3Center.z = (f3Min[2] + f3Max[2]) / 2.0f; f3Center.y -= 20.0f; XMFLOAT3 f3Extents; f3Extents.x = f3Max[0] - f3Center.x; f3Extents.y = f3Max[1] - f3Center.y; f3Extents.z = f3Max[2] - f3Center.z; CBounds* tempBounds = new CAABB(f3Center, f3Extents); */ CPitWallObject* tempPitWall = new CPitWallObject("PitWall"); //tempPitWall->AddCollider(new CCollider(false, tempBounds, true)); tempPitWall->AddCollider(new CCollider(false, Bounds::AABB, tempMesh->GetVertices())); tempPitWall->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetNormalMapPS(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Maze_Ground.dds")); tempPitWall->GetRenderMesh()->SetNormals(L"../Game/Assets/Art/2D/Normal Maps/Rocky.dds"); tempPitWall->GetRenderMesh()->GetSpecular() = 1.5f; //try moving collider down //XMFLOAT3 newCenter = ((CAABB*)(tempPitWall->GetColliders()[0]->GetBounds()))->GetCenter(); //newCenter.y -= 20.0f; //((CAABB*)(tempPitWall->GetColliders()[0]->GetBounds()))->SetCenter(newCenter); m_cpEnvironmentObjects.push_back(tempPitWall); m_cpObjectManager->AddObject(tempPitWall, CObjectManager::eObjectType::Static); } else if (strcmp(prefix.c_str(), "Dor_") == 0)//door prefab { //tempMesh->ConvertVertices(); // //CDoorObject* tempDoor = new CDoorObject("Door"); ////tempDoor-> ////tempDoor-> // //m_cpEnvironmentObjects.push_back(tempDoor); // //m_cpObjectManager->AddObject(tempDoor, CObjectManager::eObjectType::Dynamic); } else if (strcmp(prefix.c_str(), "Pit_") == 0)//pit bottom prefab { tempMesh->ConvertVertices(); CPitObject* tempPit = new CPitObject("Pit"); tempPit->AddCollider(new CCollider(false, Bounds::Plane, tempMesh->GetVertices())); tempPit->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetNormalMapPS(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Maze_Ground.dds")); tempPit->GetRenderMesh()->SetNormals(L"../Game/Assets/Art/2D/Normal Maps/Rocky.dds"); tempPit->GetRenderMesh()->GetSpecular() = 1.5f; m_cpEnvironmentObjects.push_back(tempPit); m_cpObjectManager->AddObject(tempPit, CObjectManager::eObjectType::Static); } else if (strcmp(prefix.c_str(), "BPT_") == 0)//big pit bottom prefab { tempMesh->ConvertVertices(); CPitObject* tempBigPit = new CPitObject("BigPit"); tempBigPit->AddCollider(new CCollider(false, Bounds::Plane, tempMesh->GetVertices())); tempBigPit->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetNormalMapPS(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Maze_Ground.dds")); tempBigPit->GetRenderMesh()->SetNormals(L"../Game/Assets/Art/2D/Normal Maps/Rocky.dds"); tempBigPit->GetRenderMesh()->GetSpecular() = 1.5f; m_cpEnvironmentObjects.push_back(tempBigPit); m_cpBigPitObjects.push_back(tempBigPit); m_cpObjectManager->AddObject(tempBigPit, CObjectManager::eObjectType::Static); //now create teleporter for this bridge location XMFLOAT3 teleportPoint = { 0.0f, 0.0f, 0.0f }; if (((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetExtents().x > ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetExtents().z) { teleportPoint.x = ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetCenter().x + 1000.0f; teleportPoint.y = ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetCenter().y + 1000.0f; teleportPoint.z = ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetCenter().z; } else { teleportPoint.x = ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetCenter().x; teleportPoint.y = ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetCenter().y + 1000.0f; teleportPoint.z = ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetCenter().z + 1000.0f; } CWaypointObject* bridgeTeleport = new CWaypointObject("BridgeTeleporter"); bridgeTeleport->SetPosition(teleportPoint); m_cpBridgeTeleporters.push_back(bridgeTeleport); } else if (strcmp(prefix.c_str(), "Ext_") == 0)//exit door { m_cvExitDoorMeshes.push_back(*tempMesh); } else if (strcmp(prefix.c_str(), "GFL_") == 0)//grass floor { tempMesh->ConvertVertices(); CFloorObject* tempGrassFloor = new CFloorObject("SafeHavenFloor"); tempGrassFloor->AddCollider(new CCollider(false, Bounds::Plane, tempMesh->GetVertices())); tempGrassFloor->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetPixelShader(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Ground_Grass.dds")); m_cpEnvironmentObjects.push_back(tempGrassFloor); m_cpObjectManager->AddObject(tempGrassFloor, CObjectManager::eObjectType::Static); } else if (strcmp(prefix.c_str(), "Skl_") == 0)//skeleton spawn point { tempMesh->ConvertVertices(); XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices()); CSpawnerObject* tempSpawner = new CSpawnerObject("SkeletonSpawn"); tempSpawner->GetSpawnPosition() = tempPos; m_cpSkeletonSpawnObjects.push_back(tempSpawner); } else if (strcmp(prefix.c_str(), "Orc_") == 0)//orc spawn point { tempMesh->ConvertVertices(); XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices()); CSpawnerObject* tempSpawner = new CSpawnerObject("OrcSpawn"); tempSpawner->GetSpawnPosition() = tempPos; m_cpOrcSpawnObjects.push_back(tempSpawner); } else if (strcmp(prefix.c_str(), "ECS_") == 0)//enemy cave spawners { } else if (strcmp(prefix.c_str(), "Min_") == 0)//minotaur spawn point { tempMesh->ConvertVertices(); XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices()); CSpawnerObject* tempSpawner = new CSpawnerObject("MinotaurSpawn"); tempSpawner->GetSpawnPosition() = tempPos; m_cpMinotaurSpawnObjects.push_back(tempSpawner); } else if (strcmp(prefix.c_str(), "Mpt_") == 0)//minotaur waypoints { #pragma region Minotaur Waypoints string tempName = " "; for (int i = 4; i < 30; i++) { tempName[i] = objName[i]; if ((int)objName[i] == 'e') { break; } } //get waypoint ID int firstNum = (int)tempName[4] - 48; int secondNum = (int)tempName[5] - 48; int thirdNum = (int)tempName[6] - 48; int WayPointID = (firstNum * 100) + (secondNum * 10) + thirdNum; //get adjacent waypoint IDs int AdjacentIDs[4] = { -1, -1, -1, -1 }; int nextAdjacent = 0; for (int i = 7; i < 30; i++) { if ((int)tempName[i] == '_') { nextAdjacent++; continue; } if ((int)tempName[i] == 'e') { break; } int firstNum = (int)tempName[i] - 48; int secondNum = (int)tempName[i + 1] - 48; int thirdNum = (int)tempName[i + 2] - 48; AdjacentIDs[nextAdjacent] = (firstNum * 100) + (secondNum * 10) + thirdNum; if (AdjacentIDs[nextAdjacent] >= 147) { break; } i += 2; } //create node tempMesh->ConvertVertices(); XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices()); CNode* tempNode = new CNode(WayPointID, tempPos); //create and add edges for (unsigned int i = 0; i < 4; i++) { if (AdjacentIDs[i] == -1) { continue; } tempNode->addEdge(new CEdge(1.0f, AdjacentIDs[i])); } //add node to navgraph m_cpMinotaurNavGraph->AddNode(tempNode); #pragma endregion } else if (strcmp(prefix.c_str(), "CWL_") == 0)//cracked wall location { //tempMesh->ConvertVertices(); //CCrackedWall* tempCrackedWall = new CCrackedWall("CrackedWall"); //tempCrackedWall->AddCollider(new CCollider(false, Bounds::AABB, tempMesh->GetVertices())); //tempCrackedWall->SetRenderMesh(new CRenderMesh(tempMesh->GetIndices(), tempMesh->GetVertices(), GRAPHICS->GetVertexShader(), GRAPHICS->GetPixelShader(), nullptr, nullptr, nullptr)); //m_cpEnvironmentObjects.push_back(tempCrackedWall); //m_cpObjectManager->AddObject(tempCrackedWall, CObjectManager::eObjectType::Static); } else if (strcmp(prefix.c_str(), "LWC_") == 0)//light weapon upgrade chest location { } else if (strcmp(prefix.c_str(), "HWC_") == 0)//heavy weapon upgrade chest location { } else if (strcmp(prefix.c_str(), "HUC_") == 0)//health upgrade chest location { } else if (strcmp(prefix.c_str(), "Tor_") == 0)//torch location { #pragma region Torches std::string tempName = " "; for (unsigned int i = 4; i < 12; i++) { tempName[i] = objName[i]; } XMFLOAT3 tiltDirection = { 0, 0, 0 }; //get x value int secondNum = (int)tempName[5] - 48; if (tempName[4] == 'n') { tiltDirection.x = -((float)secondNum); } else { tiltDirection.x = (float)secondNum; } //get y value secondNum = (int)tempName[8] - 48; if (tempName[7] == 'n') { tiltDirection.y = -((float)secondNum); } else { tiltDirection.y = (float)secondNum; } //get z value secondNum = (int)tempName[11] - 48; if (tempName[10] == 'n') { tiltDirection.z = -((float)secondNum); } else { tiltDirection.z = (float)secondNum; } tempMesh->ConvertVertices(); XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices()); m_cpTorchObjects.push_back(new CTorch(m_cpObjectManager, tempPos, tiltDirection)); #pragma endregion } else if (strcmp(prefix.c_str(), "STL_") == 0)//pressure plate spike trap { tempMesh->ConvertVertices(); XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices()); m_cpSpikeTrapObjects.push_back(new CSpikeTrap(tempPos, true, 0.0f, 1.0f)); } else if (strcmp(prefix.c_str(), "AST_") == 0)//alternating spike trap { std::string tempName = " "; for (unsigned int i = 4; i < 9; i++) { tempName[i] = objName[i]; } int firstNum = (int)tempName[4] - 48; int secondNum = (int)tempName[5] - 48; float startTime = (float)firstNum + ((float)secondNum / 10.0f); firstNum = (int)tempName[7] - 48; secondNum = (int)tempName[8] - 48; float offsetTime = (float)firstNum + ((float)secondNum / 10.0f); tempMesh->ConvertVertices(); XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices()); m_cpAltSpikeTrapObjects.push_back(new CSpikeTrap(tempPos, false, startTime, offsetTime)); } else if (strcmp(prefix.c_str(), "SBT_") == 0)//spinning blade trap { std::string tempName = " "; for (unsigned int i = 4; i < 7; i++) { tempName[i] = objName[i]; } int firstNum = (int)tempName[4] - 48; int secondNum = (int)tempName[5] - 48; float rotationTime = (float)firstNum + ((float)secondNum / 10.0f); tempMesh->ConvertVertices(); XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices()); m_cpSpinningBladeObjects.push_back(new CSpinningBlade(tempPos, rotationTime)); } else if (strcmp(prefix.c_str(), "FTE_") == 0)//fire trap emmiter { #pragma region Fire Trap std::string tempName = " "; for (unsigned int i = 4; i < 12; i++) { tempName[i] = objName[i]; } XMFLOAT3 fireDirection = { 0, 0, 0 }; int secondNum = (int)tempName[5] - 48; if (tempName[4] == 'n') { fireDirection.x = -((float)secondNum); } else { fireDirection.x = (float)secondNum; } secondNum = (int)tempName[8] - 48; if (tempName[7] == 'n') { fireDirection.y = -((float)secondNum); } else { fireDirection.y = (float)secondNum; } secondNum = (int)tempName[11] - 48; if (tempName[10] == 'n') { fireDirection.z = -((float)secondNum); } else { fireDirection.z = (float)secondNum; } tempMesh->ConvertVertices(); XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices()); m_cpFireTrapObjects.push_back(new CFireTrap(m_cpObjectManager, tempPos, fireDirection)); #pragma endregion } else if (strcmp(prefix.c_str(), "Tre_") == 0)//cuttable trees { } else if (strcmp(prefix.c_str(), "Bsh_") == 0)//bushes { tempMesh->ConvertVertices(); XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices()); m_cpBushObjects.push_back(new CBush(m_cpObjectManager, tempPos)); } else if (strcmp(prefix.c_str(), "EDT_") == 0)//exit door teleporters { m_cvExitTeleporterMeshes.push_back(*tempMesh); } else if (strcmp(prefix.c_str(), "Inv_") == 0)//invisible walls { tempMesh->ConvertVertices(); CWallObject* tempWall = new CWallObject("Wall"); tempWall->AddCollider(new CCollider(false, Bounds::AABB, tempMesh->GetVertices())); tempWall->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetPixelShader())); tempWall->GetRenderMesh()->GetRender() = false; m_cpInvisibleWallObjects.push_back(tempWall); m_cpObjectManager->AddObject(tempWall, CObjectManager::eObjectType::Static); } else if (strcmp(prefix.c_str(), "Kil_") == 0)//kill floor { tempMesh->ConvertVertices(); CFloorObject* tempFloor = new CFloorObject("KillFloor"); tempFloor->AddCollider(new CCollider(false, Bounds::Plane, tempMesh->GetVertices())); tempFloor->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetPixelShader())); tempFloor->GetRenderMesh()->GetRender() = false; m_cpKillFloorObjects.push_back(tempFloor); m_cpObjectManager->AddObject(tempFloor, CObjectManager::eObjectType::Static); } else { meshes.push_back(*tempMesh); } attributeMesh->Destroy(); delete tempMesh; } } for (int i = 0; i < node->GetChildCount(); i++) { ProcessLevelNode(node->GetChild(i), meshes); } return true; }
// This method is templated on the implementation of hctMayaSceneExporter::createHkxNodes() void FbxToHkxConverter::addNodesRecursive(hkxScene *scene, FbxNode* fbxNode, hkxNode* node, int animStackIndex) { for (int childIndex = 0; childIndex < fbxNode->GetChildCount(); childIndex++) { FbxNode* fbxChildNode = fbxNode->GetChild(childIndex); FbxNodeAttribute* fbxNodeAtttrib = fbxChildNode->GetNodeAttribute(); bool selected = fbxChildNode->GetSelected(); // Ignore nodes(and their descendants) if they're invisible and we ignore invisible objects if ( !(!m_options.m_visibleOnly || fbxNode->GetVisibility()) ) continue; // Ignore nodes(and their descendants) if they're not selected and we ignore deselected objects if ( !(!m_options.m_selectedOnly || selected) ) continue; hkxNode* newChildNode = new hkxNode(); { newChildNode->m_name = fbxChildNode->GetName(); node->m_children.pushBack(newChildNode); } newChildNode->m_selected = selected; // Extract the following types of data from this node (taken from hkxScene.h): if (fbxNodeAtttrib != NULL) { switch (fbxNodeAtttrib->GetAttributeType()) { case FbxNodeAttribute::eMesh: { // Generate hkxMesh and all its dependent data (ie: hkxSkinBinding, hkxMeshSection, hkxMaterial) if (m_options.m_exportMeshes) { addMesh(scene, fbxChildNode, newChildNode); } break; } case FbxNodeAttribute::eNurbsCurve: { if (m_options.m_exportSplines) { addSpline(scene, fbxChildNode, newChildNode); } break; } case FbxNodeAttribute::eCamera: { // Generate hkxCamera if (m_options.m_exportCameras) { addCamera(scene, fbxChildNode, newChildNode); } break; } case FbxNodeAttribute::eLight: { // Generate hkxLight if (m_options.m_exportLights) { addLight(scene, fbxChildNode, newChildNode); } break; } case FbxNodeAttribute::eSkeleton: { // Flag this node as a bone if it's associated with a skeleton attribute newChildNode->m_bone = true; break; } default: break; } } // Extract this node's animation data and bind transform extractKeyFramesAndAnnotations(scene, fbxChildNode, newChildNode, animStackIndex); if (m_options.m_exportAttributes) { addSampledNodeAttributeGroups(scene, animStackIndex, fbxChildNode, newChildNode); } GetCustomVisionData(fbxChildNode, newChildNode->m_userProperties); addNodesRecursive(scene, fbxChildNode, newChildNode, animStackIndex); newChildNode->removeReference(); } }