JNIEXPORT void JNICALL Java_de_tesis_dynaware_javafx_graphics_importers_fbx_JFbxLib_triangulate(JNIEnv *env, jobject obj, jint attributeIndex) { // Check FBX file has been opened. if (!isOpen()) { throwFileClosedException(env); } // Check attribute index bounds for safety. if (!checkAttributeBounds(attributeIndex)) { throwArrayOutOfBoundsException(env); } // Check attribute type for safety. if (!isValidType(attributeIndex, FbxNodeAttribute::EType::eMesh) && !isValidType(attributeIndex, FbxNodeAttribute::EType::ePatch) && !isValidType(attributeIndex, FbxNodeAttribute::EType::eNurbs) && !isValidType(attributeIndex, FbxNodeAttribute::EType::eNurbsSurface)) { return; } FbxGeometryConverter *converter = new FbxGeometryConverter(sdkManager); converter->Triangulate(currentNode->GetNodeAttributeByIndex(attributeIndex), true); }
// 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(); }
bool gltfPackage::LoadScene (const std::string &fn) { auto pMgr =fbxSdkMgr::Instance ()->fbxMgr () ; FbxAutoDestroyPtr<FbxImporter> pImporter (FbxImporter::Create (pMgr, "")) ; if ( !pImporter->Initialize ((fn).c_str (), -1, pMgr->GetIOSettings ()) ) return (false) ; if ( pImporter->IsFBX () ) { // From this point, it is possible to access animation stack information without // the expense of loading the entire file. // Set the import states. By default, the import states are always set to true. } bool bStatus =pImporter->Import (_scene) ; if ( _ioSettings._name.length () ) _scene->SetName ((_ioSettings._name).c_str ()) ; else if ( _scene->GetName () == FbxString ("") ) //_scene->SetName ("untitled") ; _scene->SetName ((gltfPackage::filename (fn)).c_str ()) ; //if ( bStatus == false && pImporter->GetStatus ().GetCode () == FbxStatus::ePasswordError ) { //} // Get current UpAxis of the FBX file. // This have to be done before ConvertiAxisSystem(), cause the function will always change SceneAxisSystem to Y-up. // First, however, if we have the ForcedFileAxis activated, we need to overwrite the global settings. //switch ( IOS_REF.GetEnumProp (IMP_FILE_UP_AXIS, FbxMayaUtility::eUPAXIS_AUTO) ) { // default: // case FbxMayaUtility::eUPAXIS_AUTO: // break ; // case FbxMayaUtility::eUPAXIS_Y: // _scene->GetGlobalSettings ().SetAxisSystem (FbxAxisSystem::MayaYUp) ; // break ; // case FbxMayaUtility::eUPAXIS_Z: // _scene->GetGlobalSettings ().SetAxisSystem (FbxAxisSystem::MayaZUp) ; // break ; //} //FbxAxisSystem sceneAxisSystem =_scene->GetGlobalSettings ().GetAxisSystem () ; //int lSign =0 ; //FbxAxisSystem::EUpVector upVectorFromFile =sceneAxisSystem.GetUpVector (lSign) ; FbxAxisSystem::MayaYUp.ConvertScene (_scene) ; // We want the Y up axis for glTF FbxSystemUnit sceneSystemUnit =_scene->GetGlobalSettings ().GetSystemUnit () ; // We want meter as default unit for gltTF if ( sceneSystemUnit != FbxSystemUnit::m ) { //const FbxSystemUnit::ConversionOptions conversionOptions ={ // false, // mConvertRrsNodes // true, // mConvertAllLimits // true, // mConvertClusters // false, // mConvertLightIntensity // true, // mConvertPhotometricLProperties // false // mConvertCameraClipPlanes //} ; //FbxSystemUnit::m.ConvertScene (_scene, conversionOptions) ; FbxSystemUnit::m.ConvertScene (_scene) ; } FbxGeometryConverter converter (fbxSdkMgr::Instance ()->fbxMgr ()) ; converter.Triangulate (_scene, true) ; // glTF supports triangles only converter.SplitMeshesPerMaterial (_scene, true) ; // Split meshes per material, so we only have one material per mesh (VBO support) // Set the current peripheral to be the NULL so FBX geometries that have been imported can be flushed _scene->SetPeripheral (NULL_PERIPHERAL) ; //int nb =_scene->GetSrcObjectCount<FbxNodeAttribute> () ; //int nbTot =5 * nb ; //int nbRest =4 * nb ; //int nbSteps =nbRest / 8 ; //FbxArray<FbxNode *> pBadMeshes =RemoveBadPolygonsFromMeshes (_scene) ; return (true) ; }