예제 #1
0
파일: FBXScene.cpp 프로젝트: Malow/NDYGFX
void FBXScene::ProcessScene(FbxScene* pScene)
{
	if ( m_pSkeleton ) delete m_pSkeleton, m_pSkeleton = 0;

	FbxAxisSystem SceneAxisSystem = pScene->GetGlobalSettings().GetAxisSystem();
	FbxAxisSystem OurAxisSystem(FbxAxisSystem::Motionbuilder);

	if( SceneAxisSystem != OurAxisSystem )
	{
		OurAxisSystem.ConvertScene(pScene);
	}
	
	ProcessMaterials(pScene);
	ProcessNode(pScene->GetRootNode(), FbxNodeAttribute::eSkeleton);
	ProcessNode(pScene->GetRootNode(), FbxNodeAttribute::eMesh);	// takes time, guesstimate 50% of it
	ProcessNode(pScene->GetRootNode(), FbxNodeAttribute::eNurbsCurve); 

	if(m_pSkeleton)
		m_pSkeleton->BuildBoneHierarchy();

	ProcessBlendWeights();
	ProcessSkeleteonBoundingBoxes();

	ProcessAnimations(pScene);	// takes time too, other 50%
}
예제 #2
0
/*
Imports all the scene data and creates the mesh and bone instances from it
*/
void SceneImporter::loadFile()
{
	bool lResult = false;
	if (mImporter->Import(mScene) == true)
	{
		// Convert Axis System to what is used in this example, if needed
		FbxAxisSystem SceneAxisSystem = mScene->GetGlobalSettings().GetAxisSystem();
		FbxAxisSystem OurAxisSystem(FbxAxisSystem::eYAxis, FbxAxisSystem::eParityOdd, FbxAxisSystem::eRightHanded);
		if (SceneAxisSystem != OurAxisSystem)
		{
			OurAxisSystem.ConvertScene(mScene);
		}

		// Convert Unit System to what is used in this example, if needed
		FbxSystemUnit SceneSystemUnit = mScene->GetGlobalSettings().GetSystemUnit();
		if (SceneSystemUnit.GetScaleFactor() != 1.0)
		{
			//The unit in this example is centimeter.
			FbxSystemUnit::cm.ConvertScene(mScene);
		}

		// Get the list of all the animation stack.
		mScene->FillAnimStackNameArray(mAnimStackNameArray);
		// Create the animator
		Animator::create(mScene);

		// Convert mesh, NURBS and patch into triangle mesh
		FbxGeometryConverter lGeomConverter(mSdkManager);
		lGeomConverter.Triangulate(mScene, /*replace*/true);

		// Split meshes per material, so that we only have one material per mesh (for VBO support)
		lGeomConverter.SplitMeshesPerMaterial(mScene, /*replace*/true);
		// Extract all bone nodes
		extractBonesRecursive(mScene->GetRootNode());

		// Load all meshes from scene
		FbxAMatrix lDummyGlobalPosition;

		// Extract all meshes
		loadCacheRecursive(mScene->GetRootNode());

		// Load all the animation keyframe data
		Animator::get()->precacheAnimationData();
	}

	// Destroy the importer to release the file.
	mImporter->Destroy();
	mImporter = NULL;
}
bool Model::Load( const char *filename ) {

	buffer.Create( Video::VF_GENERIC );

	KFbxImporter *importer = KFbxImporter::Create( manager, "" );

	if( !importer->Initialize( filename, -1, manager->GetIOSettings()) ){
		printf( "error loading model %s\n", filename );
		return false;
	}

	scene = KFbxScene::Create( manager, "scene1" );
	     
	importer->Import( scene );

	// wtf is this for?
	bool shit = scene->GetGlobalSettings().SetDefaultCamera( PRODUCER_BOTTOM );//(char *) lCamera->GetName());

	// convert axis system (should be done by fbx exporter??)
	KFbxAxisSystem SceneAxisSystem = scene->GetGlobalSettings().GetAxisSystem();
    KFbxAxisSystem OurAxisSystem(KFbxAxisSystem::XAxis, KFbxAxisSystem::ParityOdd, KFbxAxisSystem::RightHanded);
    if( SceneAxisSystem != OurAxisSystem )
    {
        OurAxisSystem.ConvertScene(scene);
    }
	importer->Destroy();

	// Get animation names
	scene->FillAnimStackNameArray( AnimationStackNames );
	
	 
	// identify and triangulate meshes in scene
	FindMeshes( scene->GetRootNode() );

	SetAnimationStack(1);
	
    AnimationFrameTime.SetTime(0, 0, 0, 1, 0, scene->GetGlobalSettings().GetTimeMode());

	return true;
}
예제 #4
0
BGameObject * BImporter::loadObject(string pPath)
{
    //do i really need importer??
    mImporter = FbxImporter::Create(lSdkManager,"");
    int lFileFormat = -1;
	const char* mFileName = pPath.c_str();
    if (!lSdkManager->GetIOPluginRegistry()->DetectReaderFileFormat(mFileName, lFileFormat) )
    {
        // Unrecognizable file format. Try to fall back to FbxImporter::eFBX_BINARY
        lFileFormat = lSdkManager->GetIOPluginRegistry()->FindReaderIDByDescription( "FBX binary (*.fbx)" );;
    }

	if(mImporter->Initialize(pPath.c_str(), lFileFormat) == true)
    {

    }
    //else error
    //mScene->GetRootNode()


        if (mImporter->Import(lScene) == true)
        {
			printf("Importing...");
            // Convert Axis System to what is used in this example, if needed
            FbxAxisSystem SceneAxisSystem = lScene->GetGlobalSettings().GetAxisSystem();
            FbxAxisSystem OurAxisSystem(FbxAxisSystem::eYAxis, FbxAxisSystem::eParityOdd, FbxAxisSystem::eRightHanded);
            if( SceneAxisSystem != OurAxisSystem )
            {
                OurAxisSystem.ConvertScene(lScene);
            }

            // Convert Unit System to what is used in this example, if needed
            FbxSystemUnit SceneSystemUnit = lScene->GetGlobalSettings().GetSystemUnit();
            if( SceneSystemUnit.GetScaleFactor() != 1.0 )
            {
                //The unit in this example is centimeter.
                FbxSystemUnit::cm.ConvertScene( lScene);
            }

            // Get the list of all the animation stack.
            lScene->FillAnimStackNameArray(mAnimStackNameArray);
            // Convert mesh, NURBS and patch into triangle mesh
			FbxGeometryConverter lGeomConverter(lSdkManager);
			lGeomConverter.Triangulate(lScene, true);

			// Split meshes per material, so that we only have one material per mesh (for VBO support)
			lGeomConverter.SplitMeshesPerMaterial(lScene, true);


			BGameObject *lGameObject = prepareVBOMeshes(lScene);
            return lGameObject;
            // Bake the scene for one frame
            //LoadCacheRecursive(mScelGeomConverterne, mCurrentAnimLayer, mFileName, mSupportVBO);

            // Convert any .PC2 point cache data into the .MC format for
            // vertex cache deformer playback.
            //PreparePointCacheData(mScene, mCache_Start, mCache_Stop);

            // Get the list of pose in the scene
            //FillPoseArray(mScene, mPoseArray);

            // Initialize the frame period.
            //mFrameTime.SetTime(0, 0, 0, 1, 0, lScene->GetGlobalSettings().GetTimeMode());
            //lResult = true;
        }
        printf("Cant import this object");
        return NULL;
}
예제 #5
0
void fbxLoader2::loadFbx(char* filename)
{
	//create memory manager
	loaderManager = FbxManager::Create();
	//create settings for input/output
	ios = FbxIOSettings::Create(loaderManager, IOSROOT);
	loaderManager->SetIOSettings(ios);

	lImporter = FbxImporter::Create(loaderManager, "");
	lImportStatus = lImporter->Initialize(filename, -1, loaderManager->GetIOSettings());

	scene = FbxScene::Create(loaderManager, "newscene");

	FbxAxisSystem SceneAxisSystem = scene->GetGlobalSettings().GetAxisSystem();
	FbxAxisSystem OurAxisSystem(FbxAxisSystem::eYAxis, FbxAxisSystem::eParityOdd, FbxAxisSystem::eLeftHanded);

	lImporter->Import(scene);
	lImporter->Destroy();

	lRootNode = scene->GetRootNode();

	//int numberOfChildren = lRootNode->GetChildCount();
	skeleton = new SkeletalData();
	animationStructure = new AnimationData();
	buildSkeleton(findSkeletonRootBone(lRootNode));
	readAnimationTakeData(findSkeletonRootBone(lRootNode)->GetChild(0));
	readVertexData(lRootNode);
	
	indices = new indexesStructure[indicesMaxCount];
	vertexArray = new vertexWeights[vertexMaxCount];

	processNode(lRootNode);

	//processMesh(lRootNode);


	/*for (int i = 0; i< numberOfChildren; i++)
	{
		lNode = lRootNode->GetChild(i);
		printf("Child name: %s\n", lNode->GetName());
		lMesh = lNode->GetMesh();
		if(lMesh == NULL)
		{
			printf("No mesh here\n");
		}
		else
		{
			if(lMesh->IsTriangleMesh())
			{
				int numVerts = lMesh->GetControlPointsCount();

				for (int j = 0; j < numVerts; j++)
				{
					FbxVector4 vert = lMesh->GetControlPointAt(j);
					Vertices[numberVertices].x = (float)vert.mData[0];
					Vertices[numberVertices].y = (float)vert.mData[1];
					Vertices[numberVertices].z = (float)vert.mData[2];
					numberVertices++;
				}
				int *indices = lMesh->GetPolygonVertices();
				numIndices+= lMesh->GetPolygonVertexCount();
			}
			else 
			{
				printf("Mesh not triangulated\n");
			}
			
		}
	}*/
}
예제 #6
0
bool SceneContext::LoadFile()
{
    bool lResult = false;
    // Make sure that the scene is ready to load.
    if (mStatus == MUST_BE_LOADED)
    {
        if (mImporter->Import(mScene) == true)
        {
            // Set the scene status flag to refresh 
            // the scene in the first timer callback.
            mStatus = MUST_BE_REFRESHED;

            // Convert Axis System to what is used in this example, if needed
            FbxAxisSystem SceneAxisSystem = mScene->GetGlobalSettings().GetAxisSystem();
            //FbxAxisSystem OurAxisSystem(FbxAxisSystem::eYAxis, FbxAxisSystem::eParityOdd, FbxAxisSystem::eRightHanded);
            FbxAxisSystem OurAxisSystem(FbxAxisSystem::eOpenGL);
            //m_matGlobal.SetRow(1, float4(0,0,-1,0));
            //m_matGlobal.SetRow(2, float4(0,1,0,0));
            if( SceneAxisSystem != OurAxisSystem )
            {
                OurAxisSystem.ConvertScene(mScene);
            }

            // Convert Unit System to what is used in this example, if needed
            FbxSystemUnit SceneSystemUnit = mScene->GetGlobalSettings().GetSystemUnit();
            if( SceneSystemUnit.GetScaleFactor() != 1.0 )
            {
                //The unit in this example is centimeter.
                FbxSystemUnit::cm.ConvertScene( mScene);
            }

            // Get the list of all the animation stack.
            mScene->FillAnimStackNameArray(mAnimStackNameArray);

            SetCurrentAnimStack(0);

            // Get the list of all the cameras in the scene.
            FillCameraArray(mScene, mCameraArray);

            // Convert mesh, NURBS and patch into triangle mesh
            TriangulateRecursive(mScene->GetRootNode());

            // Bake the scene for one frame
            //LoadCacheRecursive(this, mScene, mCurrentAnimLayer, mFileName, mSupportVBO);

            // Convert any .PC2 point cache data into the .MC format for 
            // vertex cache deformer playback.
            PreparePointCacheData(mScene, mCache_Start, mCache_Stop);

            // Get the list of pose in the scene
            FillPoseArray(mScene, mPoseArray);

            // Initialize the window message.
            mWindowMessage = "File ";
            mWindowMessage += WS2AS(m_FileName);
            mWindowMessage += "\nClick on the right mouse button to enter menu.";
            mWindowMessage += "\nEsc to exit.";

            // Initialize the frame period.
            mFrameTime.SetTime(0, 0, 0, 1, 0, mScene->GetGlobalSettings().GetTimeMode());

            // Print the keyboard shortcuts.
            //FBXSDK_printf("Play/Pause Animation: Space Bar.\n");
            //FBXSDK_printf("Camera Rotate: Left Mouse Button.\n");
            //FBXSDK_printf("Camera Pan: Left Mouse Button + Middle Mouse Button.\n");
            //FBXSDK_printf("Camera Zoom: Middle Mouse Button.\n");

            lResult = true;
        }
        else
        {
            // Import failed, set the scene status flag accordingly.
            mStatus = UNLOADED;

            mWindowMessage = "Unable to import file ";
            mWindowMessage += WS2AS(m_FileName);
            mWindowMessage += "\nError reported: ";
            mWindowMessage += mImporter->GetLastErrorString();
        }

        // Destroy the importer to release the file.
        mImporter->Destroy();
        mImporter = NULL;
    }

    // Bake the scene for one frame
    LoadCacheRecursive(this, mScene, mCurrentAnimLayer, m_FileName, m_bSupportVBO);
    return lResult;
}