示例#1
0
bool CreateScene(KFbxSdkManager *pSdkManager, KFbxScene* pScene)
{
    // create scene info
    KFbxDocumentInfo* sceneInfo = KFbxDocumentInfo::Create(pSdkManager,"SceneInfo");
    sceneInfo->mTitle = "Mesh";
    sceneInfo->mSubject = "Mesh thing";
    sceneInfo->mAuthor = "Team opennirospcleigenubuntuvmware";
    sceneInfo->mRevision = "0.1";
    sceneInfo->mKeywords = "mesh";
    sceneInfo->mComment = "none";

    // we need to add the sceneInfo before calling AddThumbNailToScene because
    // that function is asking the scene for the sceneInfo.
    pScene->SetSceneInfo(sceneInfo);

    KFbxNode* lPatch = CreateMesh(pScene, "Patch");
    KFbxNode* lSkeletonRoot = CreateSkeleton(pScene, "Skeleton");


    // Build the node tree.
    KFbxNode* lRootNode = pScene->GetRootNode();
    lRootNode->AddChild(lPatch);
    lRootNode->AddChild(lSkeletonRoot);

/*
	// Store poses
    LinkPatchToSkeleton(pScene, lPatch, lSkeletonRoot);
    StoreBindPose(pScene, lPatch, lSkeletonRoot);
    StoreRestPose(pScene, lSkeletonRoot);

	// Animation
    AnimateSkeleton(pScene, lSkeletonRoot);
*/
    return true;
}
示例#2
0
bool Fbx::addPolygonObjectToScene( std::vector<KFbxVector4> &vertex_list )
{
	assert(vertex_list.size()>=3);
	if(!_output_scene)
	{
		//std::cout << " Not scene has been created!! " << std::endl;
		return false;
	}

	KFbxNode *root = _output_scene->GetRootNode();

	if(!root)
	{
		//std::cout<<"Don't have root!"<< std::endl;
		return false;
	}

	KFbxMesh *mesh = KFbxMesh::Create(_sdk_manager, "");
	if(!mesh)
		return false;


	mesh->BeginPolygon();
	std::vector<KFbxVector4>::iterator it;
	int index = 0;
	for (it = vertex_list.begin(); it != vertex_list.end(); it++, index++)
	{
		mesh->SetControlPointAt((*it), index);
		mesh->AddPolygon(index);
	}
	mesh->EndPolygon();
	mesh->BuildMeshEdgeArray();

	_mesh_list.push_back(mesh);

	KFbxNode *polygon_node = KFbxNode::Create(_sdk_manager, "");
	assert(polygon_node->AddNodeAttribute(mesh));

	assert(root->AddChild(polygon_node));


	return true;
}
示例#3
0
//Read the custom file and reconstruct node hierarchy.
bool FBXImporterReader::Read(KFbxDocument* pDocument, KFbxStreamOptions* pStreamOptions)
{
    if (!pDocument)
    {
        GetError().SetLastErrorID(eINVALID_DOCUMENT_HANDLE);
        return false;
    }
    KFbxScene*      lScene = KFbxCast<KFbxScene>(pDocument);
    bool            lIsAScene = (lScene != NULL);
    bool            lResult = false;

    if(lIsAScene)
    {
        KFbxNode* lRootNode = lScene->GetRootNode();
        KFbxNodeAttribute * lRootNodeAttribute = KFbxNull::Create(mManager,"");
        lRootNode->SetNodeAttribute(lRootNodeAttribute);

        int lSize;
        char* lBuffer;    
        if(mFilePointer != NULL)
        {
            //To obtain file size
            fseek (mFilePointer , 0 , SEEK_END);
            lSize = ftell (mFilePointer);
            rewind (mFilePointer);

            //Read file content to a string.
            lBuffer = (char*) malloc (sizeof(char)*lSize);
            size_t lRead = fread(lBuffer, 1, lSize, mFilePointer);
            lBuffer[lRead]='\0';
            KString lString(lBuffer);

            //Parse the string to get name and relation of Nodes. 
            KString lSubString, lChildName, lParentName;
            KFbxNode* lChildNode;
            KFbxNode* lParentNode;
            KFbxNodeAttribute* lChildAttribute;
            int lEndTokenCount = lString.GetTokenCount("\n");

            for (int i = 0; i < lEndTokenCount; i++)
            {
                lSubString = lString.GetToken(i, "\n");
                KString lNodeString;
                lChildName = lSubString.GetToken(0, "\"");
                lParentName = lSubString.GetToken(2, "\"");

                //Build node hierarchy.
                if(lParentName == "RootNode")
                {
                    lChildNode = KFbxNode::Create(mManager,lChildName.Buffer());
                    lChildAttribute = KFbxNull::Create(mManager,"");
                    lChildNode->SetNodeAttribute(lChildAttribute);

                    lRootNode->AddChild(lChildNode);
                }
                else
                {
                    lChildNode = KFbxNode::Create(mManager,lChildName.Buffer());
                    lChildAttribute = KFbxNull::Create(mManager,"");
                    lChildNode->SetNodeAttribute(lChildAttribute);

                    lParentNode = lRootNode->FindChild(lParentName.Buffer());
                    lParentNode->AddChild(lChildNode);
                }
            }
        }
        lResult = true;
    }    
    return lResult;
}