예제 #1
0
// PRIVATE FUNCTION--------------------------------------------------------------------------------------------------------------------------
void FBXReader::initializeSdkObjects(FbxManager*& fbxManager, FbxScene*& scene)
{
    //The first thing to do is to create the FBX Manager which is the object allocator for almost all the classes in the SDK
    fbxManager = FbxManager::Create();
    if (!fbxManager)
    {
        FBXSDK_printf("Error: Unable to create FBX Manager!\n");
        exit(1);
    }
    else FBXSDK_printf("Autodesk FBX SDK version %s\n", fbxManager->GetVersion());

    //Create an IOSettings object. This object holds all import/export settings.
    FbxIOSettings* ios = FbxIOSettings::Create(fbxManager, IOSROOT);
    fbxManager->SetIOSettings(ios);

    //Load plugins from the executable directory (optional)
    FbxString lPath = FbxGetApplicationDirectory();
    fbxManager->LoadPluginsDirectory(lPath.Buffer());

    //Create an FBX scene. This object holds most objects imported/exported from/to files.
    scene = FbxScene::Create(fbxManager, "My Scene");
    if (!scene)
    {
        FBXSDK_printf("Error: Unable to create FBX scene!\n");
        exit(1);
    }
}
예제 #2
0
bool InitializeOpenGL()
{
#if 0
	// Initialize GLEW.
	GLenum lError = glewInit();
	if (lError != GLEW_OK)
	{
		FBXSDK_printf("GLEW Error: %s\n", glewGetErrorString(lError));
		return false;
	}

	//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glClearColor(0.0, 0.0, 0.0, 0.0);

	// OpenGL 1.5 at least.
	if (!GLEW_VERSION_1_5)
	{
		FBXSDK_printf("The OpenGL version should be at least 1.5 to display shaded scene!\n");
		return false;
	}

#endif
	glClearColor(0.0, 0.0, 0.0, 0.0);
	return true;
}
예제 #3
0
bool Scene::output(const char *filename)
{
    FileStream stream(filename);
    if (!stream.openToWrite())
    {
        FBXSDK_printf("Fail to create %s.\n", filename);
        return false;
    }

    int depth = 0;

    if (m_camera != NULL)
    {
        stream.printf("<scene maincamera=\"%s\">\n", m_camera->attributes[0].second.Buffer());
    }
    else
    {
        stream.printf("<scene>\n");
    }

    outputNode(stream, m_root, ++depth);
    
    stream.printf("</scene>");

    return true;
}
예제 #4
0
void Tools::DisplayAnimation::DisplayListCurveKeys( FbxAnimCurve* i_curve, FbxProperty* i_property )
{
	FbxTime keyTime;
	int keyValue;
	char timeString[256];
	FbxString listValue;
	FbxString string;
	int count;

	int keyCount = i_curve->KeyGetCount();

	for(count = 0; count < keyCount; count++)
	{
		keyValue = static_cast<int>( i_curve->KeyGetValue(count) );
		keyTime  = i_curve->KeyGetTime( count );

		string = "            Key Time: ";
		string += keyTime.GetTimeString( timeString, FbxUShort(256) );
		string += ".... Key Value: ";
		string += keyValue;
		string += " (";
		string += i_property->GetEnumValue( keyValue );
		string += ")";
		DisplayCommon::DisplayString( string );
		string += "\n";
		FBXSDK_printf ( string );
	}
}
예제 #5
0
void DrawText::Initialize()
{
    FILE * lFile = NULL;
	FBXSDK_fopen(lFile, TEXTURE_FILENAME, "rb");
    if (lFile == NULL)
    {
        FBXSDK_printf("Warning: Failed to open %s and no text will be displayed.\n", TEXTURE_FILENAME);
        return;
    }

    // Load the texture coordinates and vertex coordinates.
    mGlyph = new Glyph[TEXTURE_GLYPH_COUNT];
    fread(mGlyph, sizeof(Glyph), TEXTURE_GLYPH_COUNT, lFile);

    // Load the texture data, two bytes every pixel.
    // One byte for luminance, always be 0xFF; The other for alpha.
    const int lTextureSize = TEXTURE_WIDTH * TEXTURE_HEIGHT * 2;
    unsigned char * lTextureData = new unsigned char[lTextureSize];
    if (fread(lTextureData, 1, lTextureSize, lFile) == lTextureSize)
    {
        // Save the texture data in GPU
        glGenTextures(1, &mTextureName);
        glBindTexture(GL_TEXTURE_2D, mTextureName);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0,
            GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, lTextureData);
        glBindTexture(GL_TEXTURE_2D, 0);
    }
    delete [] lTextureData;

    fclose(lFile);
}
예제 #6
0
void Tools::DisplayAnimation::DisplayAnimation( FbxAnimLayer* i_animLayer, FbxNode* i_node, bool isSwitcher )
{
	int modecount;
	FbxString string;

	string = "    Node Name: ";
	string += i_node->GetName();
	string += "\n";
	FBXSDK_printf( string );
	DisplayCommon::DisplayString( string );

	DisplayChannels( i_node, i_animLayer, DisplayCurveKeys, DisplayListCurveKeys, isSwitcher );
	FBXSDK_printf ("\n");

	for( modecount = 0; modecount < i_node->GetChildCount(); modecount++ )
	{
		DisplayAnimation( i_animLayer, i_node->GetChild(modecount), isSwitcher );
	}
}
예제 #7
0
void Tools::DisplayAnimation::DisplayAnimation( FbxAnimStack* pAnimStack, FbxNode* i_node, bool isSwitcher )
{
	int l;
	int totalAnimLayers = pAnimStack->GetMemberCount<FbxAnimLayer>();
	FbxString string;

	string = "Animation stack contains ";
	string += totalAnimLayers;
	string += " Animation Layer(s)";
	FBXSDK_printf( string );
	DisplayCommon::DisplayString( string );

	for( l = 0; l < totalAnimLayers; l++ )
	{
		FbxAnimLayer *animLayer = pAnimStack->GetMember<FbxAnimLayer>( l );

		string = "AnimLayer ";
		string += l;
		FBXSDK_printf( string );
		DisplayCommon::DisplayString( string );

		DisplayAnimation( animLayer, i_node, isSwitcher );
	}
}
예제 #8
0
void Tools::DisplayAnimation::DisplayCurveKeys( FbxAnimCurve* i_curve )
{
	static const char *interpolation[] = { "?", "constant", "linear", "cubic"};
	static const char *constantMode[] =  { "?", "Standard", "Next" };
	static const char *cubicMode[] =     { "?", "Auto", "Auto break", "Tcb", "User", "Break", "User break" };
	static const char *tangentWVMode[] = { "?", "None", "Right", "Next left" };

	FbxTime keyTime;
	float keyValue;
	char timeString[256];
	FbxString string;
	int count;

	int keyCount = i_curve->KeyGetCount();

	for( count = 0; count < keyCount; count++ )
	{
		keyValue = static_cast<float>( i_curve->KeyGetValue(count) );
		keyTime  = i_curve->KeyGetTime( count );

		string = "            Key Time: ";
		string += keyTime.GetTimeString( timeString, FbxUShort(256) );
		string += ".... Key Value: ";
		string += keyValue;
		string += " [ ";
		string += interpolation[InterpolationFlagToIndex(i_curve->KeyGetInterpolation(count))];
		if( (i_curve->KeyGetInterpolation(count)&FbxAnimCurveDef::eInterpolationConstant) == FbxAnimCurveDef::eInterpolationConstant )
		{
			string += " | ";
			string += constantMode[ ConstantmodeFlagToIndex(i_curve->KeyGetConstantMode(count)) ];
		}
		else if( (i_curve->KeyGetInterpolation(count)&FbxAnimCurveDef::eInterpolationCubic) == FbxAnimCurveDef::eInterpolationCubic )
		{
			string += " | ";
			string += cubicMode[ TangentmodeFlagToIndex(i_curve->KeyGetTangentMode(count)) ];
			string += " | ";
			string += tangentWVMode[ TangentweightFlagToIndex(i_curve->KeyGet(count).GetTangentWeightMode()) ];
			string += " | ";
			string += tangentWVMode[ TangentVelocityFlagToIndex(i_curve->KeyGet(count).GetTangentVelocityMode()) ];
		}
		string += " ]";
		DisplayCommon::DisplayString( string );
		string += "\n";
		FBXSDK_printf( string );
	}
}
예제 #9
0
void Tools::DisplayAnimation::DisplayAnimation(FbxScene* i_scene)
{
	DisplayCommon::DisplayString( "\n\n--------------------\nAnimation\n--------------------" );

	int i;
	for ( i = 0; i < i_scene->GetSrcObjectCount<FbxAnimStack>(); i++ )
	{
		FbxAnimStack *animStack = i_scene->GetSrcObject<FbxAnimStack>( i );

		FbxString string = "Animation Stack Name: ";
		string += animStack->GetName();
		string += "\n";
		FBXSDK_printf( string );
		DisplayCommon::DisplayString( string );

		DisplayAnimation( animStack, i_scene->GetRootNode(), true );
		DisplayAnimation( animStack, i_scene->GetRootNode() );
	}
}
예제 #10
0
///////////////////////////////////////////////////////////////////////////////////////
// This routine does the heavy lifting.
// finds what types of components this scene has, and extracts all the different
// elements one by one: meshes, lights, joints, etc.
///////////////////////////////////////////////////////////////////////////////////////
void ProcessContent::RecurThroughChildren(FbxNode* pNode)
{
    FbxNodeAttribute::EType lAttributeType;
    int i;

    if(pNode->GetNodeAttribute() == NULL)
    {
		if(G_bVerbose)
	        FBXSDK_printf("\t\t\t* NULL Node Attribute\n");
    }
    else
    {
        lAttributeType = (pNode->GetNodeAttribute()->GetAttributeType());

        switch (lAttributeType)
        {
			//____________ MESHES + MATERIALS + TEXTURES _____________________________________________
			case FbxNodeAttribute::eMesh:
			{
				m_procMesh.Start(pNode, &m_procMat);
				
				break;
			}

			//_____________ LIGHTS ____________________________________________________________________
	       case FbxNodeAttribute::eLight:
			{
				m_procLight.Start(pNode);
		        break;
			}

		} // end of switch(lAttributeType)
	}

    for(i = 0; i < pNode->GetChildCount(); i++)
    {
        RecurThroughChildren(pNode->GetChild(i));
    }
}
예제 #11
0
파일: Node.cpp 프로젝트: Samana/GodComplex
Node::Node( FbxNode& _Node, Node* _pParent ) : m_Node( _Node ), m_pParent( _pParent )
{
	FBXSDK_printf( "Node Name: %s\n", _Node.GetName() );

// 	DisplayUserProperties(&_Node);
// 	DisplayTarget(&_Node);
// 	DisplayPivotsAndLimits(&_Node);
// 	DisplayTransformPropagation(&_Node);
// 	DisplayGeometricTransform(&_Node);

	FbxVector4	T = _Node.GetGeometricTranslation( FbxNode::eSourcePivot );
	FbxVector4	R = _Node.GetGeometricRotation( FbxNode::eSourcePivot );
	FbxVector4	S = _Node.GetGeometricScaling( FbxNode::eSourcePivot );

	m_Local2Parent.SetTRS( T, R, S );

	if ( m_pParent != NULL )
	{
		m_Local2World = m_Local2Parent * m_pParent->m_Local2World;
	}
	else
		m_Local2World = m_Local2Parent;
}
예제 #12
0
void BImporter::DestroySdkObjects(FbxManager* pManager, bool pExitStatus)
{
    //Delete the FBX Manager. All the objects that have been allocated using the FBX Manager and that haven't been explicitly destroyed are also automatically destroyed.
    if( pManager ) pManager->Destroy();
        if( pExitStatus ) FBXSDK_printf("Program Success!\n");
}
예제 #13
0
bool FBXReader::loadScene(FbxManager* fbxManager, FbxDocument* scene, string fileName)
{
    int lFileMajor, lFileMinor, lFileRevision;
    int lSDKMajor, lSDKMinor, lSDKRevision;
    //int lFileFormat = -1;
    int i, lAnimStackCount;
    bool lStatus;
    char lPassword[1024];

    // Get the file version number generate by the FBX SDK.
    FbxManager::GetFileFormatVersion(lSDKMajor, lSDKMinor, lSDKRevision);

    // Create an importer.
    FbxImporter* lImporter = FbxImporter::Create(fbxManager, "");

    // Initialize the importer by providing a filename.
    const bool lImportStatus = lImporter->Initialize(fileName.c_str(), -1, fbxManager->GetIOSettings());
    lImporter->GetFileVersion(lFileMajor, lFileMinor, lFileRevision);

    if (!lImportStatus)
    {
        FbxString error = lImporter->GetStatus().GetErrorString();
        FBXSDK_printf("Call to FbxImporter::Initialize() failed.\n");
        FBXSDK_printf("Error returned: %s\n\n", error.Buffer());

        if (lImporter->GetStatus().GetCode() == FbxStatus::eInvalidFileVersion)
        {
            FBXSDK_printf("FBX file format version for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision);
            FBXSDK_printf("FBX file format version for file '%s' is %d.%d.%d\n\n", fileName, lFileMajor, lFileMinor, lFileRevision);
        }

        return false;
    }

    FBXSDK_printf("FBX file format version for this FBX SDK is %d.%d.%d\n", lSDKMajor, lSDKMinor, lSDKRevision);

    if (lImporter->IsFBX())
    {
        FBXSDK_printf("FBX file format version for file '%s' is %d.%d.%d\n\n", fileName, lFileMajor, lFileMinor, lFileRevision);

        // From this point, it is possible to access animation stack information without
        // the expense of loading the entire file.

        FBXSDK_printf("Animation Stack Information\n");

        lAnimStackCount = lImporter->GetAnimStackCount();

        FBXSDK_printf("    Number of Animation Stacks: %d\n", lAnimStackCount);
        FBXSDK_printf("    Current Animation Stack: \"%s\"\n", lImporter->GetActiveAnimStackName().Buffer());
        FBXSDK_printf("\n");

        for (i = 0; i < lAnimStackCount; i++)
        {
            FbxTakeInfo* lTakeInfo = lImporter->GetTakeInfo(i);

            FBXSDK_printf("    Animation Stack %d\n", i);
            FBXSDK_printf("         Name: \"%s\"\n", lTakeInfo->mName.Buffer());
            FBXSDK_printf("         Description: \"%s\"\n", lTakeInfo->mDescription.Buffer());

            // Change the value of the import name if the animation stack should be imported 
            // under a different name.
            FBXSDK_printf("         Import Name: \"%s\"\n", lTakeInfo->mImportName.Buffer());

            // Set the value of the import state to false if the animation stack should be not
            // be imported. 
            FBXSDK_printf("         Import State: %s\n", lTakeInfo->mSelect ? "true" : "false");
            FBXSDK_printf("\n");
        }

        // Set the import states. By default, the import states are always set to 
        // true. The code below shows how to change these states.
        IOS_REF.SetBoolProp(IMP_FBX_MATERIAL, true);
        IOS_REF.SetBoolProp(IMP_FBX_TEXTURE, true);
        IOS_REF.SetBoolProp(IMP_FBX_LINK, true);
        IOS_REF.SetBoolProp(IMP_FBX_SHAPE, true);
        IOS_REF.SetBoolProp(IMP_FBX_GOBO, true);
        IOS_REF.SetBoolProp(IMP_FBX_ANIMATION, true);
        IOS_REF.SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true);
    }

    // Import the scene.
    lStatus = lImporter->Import(scene);

    if (lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::ePasswordError)
    {
        FBXSDK_printf("Please enter password: "******"%s", lPassword);
        FBXSDK_CRT_SECURE_NO_WARNING_END

            FbxString lString(lPassword);

        IOS_REF.SetStringProp(IMP_FBX_PASSWORD, lString);
        IOS_REF.SetBoolProp(IMP_FBX_PASSWORD_ENABLE, true);

        lStatus = lImporter->Import(scene);

        if (lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::ePasswordError)
        {
            FBXSDK_printf("\nPassword is wrong, import aborted.\n");
        }
    }

    // Destroy the importer.
    lImporter->Destroy();

    return lStatus;
}
예제 #14
0
void Tools::DisplayMaterial::DisplayMaterial( FbxGeometry *i_geometry )
{
	DisplayCommon::DisplayString( "\n\n--------------------\nMaterial\n--------------------" );
	int materialCount = 0;
	FbxNode *node = NULL;

	if( i_geometry )
	{
		node = i_geometry->GetNode();
		if( node )
			materialCount = node->GetMaterialCount();
	}

	if( materialCount > 0 )
	{
		FbxPropertyT<FbxDouble3> double3;
		FbxPropertyT<FbxDouble> double1;
		FbxColor theColor;

		for( int ctr = 0; ctr < materialCount; ctr++ )
		{
			DisplayCommon::DisplayInt( "        Material ", ctr );

			FbxSurfaceMaterial *material = node->GetMaterial( ctr );

			DisplayCommon::DisplayString( "            Name: \"", (char *) material->GetName(), "\"" ); 

#ifdef DISPLAY_HARDWARE_SHADER_INFORMATION
			//Get the implementation to see if it's a hardware shader.
			// Note:: this cause memory leak
			const FbxImplementation* implementation = GetImplementation( material, FBXSDK_IMPLEMENTATION_HLSL );
			FbxString implementationType = "HLSL";
			if( !implementation )
			{
				implementation = GetImplementation( material, FBXSDK_IMPLEMENTATION_CGFX );
				implementationType = "CGFX";
			}

			if( implementation )
			{
				//Now we have a hardware shader, let's read it
				FBXSDK_printf( "            Hardware Shader Type: %s\n", implemenationType.Buffer() );
				DisplayCommon::DisplayString( "            Hardware Shader Type: ", implemenationType );

				const FbxBindingTable* rootTable = implementation->GetRootTable();
				FbxString fileName = rootTable->DescAbsoluteURL.Get();
				FbxString techniqueName = rootTable->DescTAG.Get(); 

				const FbxBindingTable* table = implementation->GetRootTable();
				size_t entryNum = table->GetEntryCount();

				for( int i = 0; i < (int)entryNum; i++ )
				{
					const FbxBindingTableEntry& entry = table->GetEntry( i );
					const char *entrySrcType = entry.GetEntryType( true ); 
					FbxProperty fbxProp;

					FbxString test = entry.GetSource();
					FBXSDK_printf( "            Entry: %s\n", test.Buffer() );
					DisplayCommon::DisplayString( "            Entry: %s\n", test );

					if ( strcmp( FbxPropertyEntryView::sEntryType, entrySrcType ) == 0 )
					{
						fbxProp = material->FindPropertyHierarchical(entry.GetSource()); 
						if( !fbxProp.IsValid() )
						{
							fbxProp = material->RootProperty.FindHierarchical( entry.GetSource() );
						}
					}
					else if( strcmp( FbxConstantEntryView::sEntryType, entrySrcType ) == 0 )
					{
						fbxProp = implementation->GetConstants().FindHierarchical( entry.GetSource() );
					}
					if( fbxProp.IsValid() )
					{
						if( fbxProp.GetSrcObjectCount<FbxTexture>() > 0 )
						{
							//do what you want with the textures
							for( int j = 0; j < fbxProp.GetSrcObjectCount<FbxFileTexture>(); j++ )
							{
								FbxFileTexture *tex = fbxProp.GetSrcObject<FbxFileTexture>( j );
								FBXSDK_printf( "           File Texture: %s\n", tex->GetFileName() );
								DisplayCommon::DisplayString( "           File Texture: %s\n", tex->GetFileName() );
							}
							for( int j = 0; j < fbxProp.GetSrcObjectCount<FbxLayeredTexture>(); j++ )
							{
								FbxLayeredTexture *tex = fbxProp.GetSrcObject<FbxLayeredTexture>( j );
								FBXSDK_printf( "        Layered Texture: %s\n", tex->GetName() );
								DisplayCommon::DisplayString( "        Layered Texture: %s\n", tex->GetName() );
							}
							for( int j = 0; j < fbxProp.GetSrcObjectCount<FbxProceduralTexture>(); j++ )
							{
								FbxProceduralTexture *tex = fbxProp.GetSrcObject<FbxProceduralTexture>( j );
								FBXSDK_printf( "     Procedural Texture: %s\n", tex->GetName() );
								DisplayCommon::DisplayString( "     Procedural Texture: %s\n", tex->GetName() );
							}
						}
						else
						{
							FbxDataType fbxType = fbxProp.GetPropertyDataType();
							FbxString fbxName = fbxType.GetName();
							if( FbxBoolDT == fbxType )
							{
								DisplayCommon::DisplayBool( "                Bool: ", fbxProp.Get<FbxBool>() );
							}
							else if( FbxIntDT == fbxType ||  FbxEnumDT  == fbxType )
							{
								DisplayCommon::DisplayInt( "                Int: ", fbxProp.Get<FbxInt>() );
							}
							else if( FbxFloatDT == fbxType )
							{
								DisplayCommon::DisplayDouble( "                Float: ", fbxProp.Get<FbxFloat>() );
							}
							else if( FbxDoubleDT == fbxType )
							{
								DisplayCommon::DisplayDouble( "                Double: ", fbxProp.Get<FbxDouble>() );
							}
							else if( FbxStringDT == fbxType || FbxUrlDT  == fbxType || FbxXRefUrlDT  == fbxType )
							{
								DisplayCommon::DisplayString( "                String: ", fbxProp.Get<FbxString>().Buffer() );
							}
							else if( FbxDouble2DT == fbxType )
							{
								FbxDouble2 double2 = fbxProp.Get<FbxDouble2>();
								FbxVector2 vector;
								vector[0] = double2[0];
								vector[1] = double2[1];
								DisplayCommon::Display2DVector( "                2D vector: ", vector );
							}
							else if( (FbxDouble3DT == fbxType) || (FbxColor3DT == fbxType) )
							{
								FbxDouble3 double3 = fbxProp.Get<FbxDouble3>();
								FbxVector4 vector;
								vector[0] = double3[0];
								vector[1] = double3[1];
								vector[2] = double3[2];
								DisplayCommon::Display3DVector( "                3D vector: ", vector );
							}
							else if( (FbxDouble4DT == fbxType) || (FbxColor4DT == fbxType) )
							{
								FbxDouble4 double4 = fbxProp.Get<FbxDouble4>();
								FbxVector4 vector;
								vector[0] = double4[0];
								vector[1] = double4[1];
								vector[2] = double4[2];
								vector[3] = double4[3];
								DisplayCommon::Display4DVector( "                4D vector: ", vector );
							}
							else if( FbxDouble4x4DT == fbxType )
							{
								FbxDouble4x4 double44 = fbxProp.Get<FbxDouble4x4>();
								for( int j = 0; j < 4; j++ )
								{
									FbxVector4 vector;
									vector[0] = double44[j][0];
									vector[1] = double44[j][1];
									vector[2] = double44[j][2];
									vector[3] = double44[j][3];
									DisplayCommon::Display4DVector( "                4x4D vector: ", vector );
								}
							}
						}
					}
				}
			}
			else
#endif	// #ifdef DISPLAY_HARDWARE_SHADER_INFORMATION
			if( material->GetClassId().Is(FbxSurfacePhong::ClassId) )
			{
				// We found a Phong material.  Display its properties.

				// Display the Ambient Color
				double3 = ((FbxSurfacePhong *) material)->Ambient;
				theColor.Set( double3.Get()[0], double3.Get()[1], double3.Get()[2] );
				DisplayCommon::DisplayColor( "            Ambient: ", theColor );

				// Display the Diffuse Color
				double3 = ((FbxSurfacePhong *) material)->Diffuse;
				theColor.Set( double3.Get()[0], double3.Get()[1], double3.Get()[2] );
				DisplayCommon::DisplayColor( "            Diffuse: ", theColor );

				// Display the Specular Color (unique to Phong materials)
				double3 = ((FbxSurfacePhong *) material)->Specular;
				theColor.Set( double3.Get()[0], double3.Get()[1], double3.Get()[2] );
				DisplayCommon::DisplayColor( "            Specular: ", theColor );

				// Display the Emissive Color
				double3 = ((FbxSurfacePhong *) material)->Emissive;
				theColor.Set( double3.Get()[0], double3.Get()[1], double3.Get()[2] );
				DisplayCommon::DisplayColor( "            Emissive: ", theColor );

				//Opacity is Transparency factor now
				double1 = ((FbxSurfacePhong *) material)->TransparencyFactor;
				DisplayCommon::DisplayDouble( "            Opacity: ", 1.0-double1.Get() );

				// Display the Shininess
				double1 = ((FbxSurfacePhong *) material)->Shininess;
				DisplayCommon::DisplayDouble( "            Shininess: ", double1.Get() );

				// Display the Reflectivity
				double1 = ((FbxSurfacePhong *) material)->ReflectionFactor;
				DisplayCommon::DisplayDouble( "            Reflectivity: ", double1.Get() );
			}
			else if( material->GetClassId().Is(FbxSurfaceLambert::ClassId) )
			{
				// We found a Lambert material. Display its properties.
				// Display the Ambient Color
				double3 = ((FbxSurfaceLambert *)material)->Ambient;
				theColor.Set( double3.Get()[0], double3.Get()[1], double3.Get()[2] );
				DisplayCommon::DisplayColor( "            Ambient: ", theColor );

				// Display the Diffuse Color
				double3 = ((FbxSurfaceLambert *)material)->Diffuse;
				theColor.Set( double3.Get()[0], double3.Get()[1], double3.Get()[2] );
				DisplayCommon::DisplayColor( "            Diffuse: ", theColor );

				// Display the Emissive
				double3 = ((FbxSurfaceLambert *)material)->Emissive;
				theColor.Set( double3.Get()[0], double3.Get()[1], double3.Get()[2] );
				DisplayCommon::DisplayColor( "            Emissive: ", theColor );

				// Display the Opacity
				double1 = ((FbxSurfaceLambert *)material)->TransparencyFactor;
				DisplayCommon::DisplayDouble( "            Opacity: ", 1.0-double1.Get() );
			}
			else
				DisplayCommon::DisplayString( "Unknown type of Material" );

			FbxPropertyT<FbxString> string;
			string = material->ShadingModel;
			DisplayCommon::DisplayString( "            Shading Model: ", string.Get() );
		}
	}
}
예제 #15
0
void ContentReader(FbxNode* pNode,FbxAMatrix parentMatrix)
{
    FbxNodeAttribute::EType lAttributeType;
    int i;
    if(pNode->GetNodeAttribute() == NULL)
    {
        FBXSDK_printf("NULL Node Attribute\n");
    }
    else
    {
        lAttributeType = (pNode->GetNodeAttribute()->GetAttributeType());
        switch (lAttributeType)
        {
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eUnknown:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eNull:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eMarker:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eSkeleton:
            SkeletonReader(pNode,parentMatrix);
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eMesh:
            MeshReader(pNode);
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eNurbs:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::ePatch:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eCamera:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eCameraStereo:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eCameraSwitcher:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eLight:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eOpticalReference:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eOpticalMarker:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eNurbsCurve:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eTrimNurbsSurface:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eBoundary:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eNurbsSurface:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eShape:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eLODGroup:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eSubDiv:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eCachedEffect:
            break;
        case fbxsdk_2014_1_rc::FbxNodeAttribute::eLine:
            break;
        default:
            break;
        }
    }
    for(i = 0; i<pNode->GetChildCount(); i++)
    {
        ContentReader(pNode->GetChild(i),parentMatrix);
    }

}
예제 #16
0
void Resource::FBX::FBXMaterial::InitMaterial(const FbxSurfaceMaterial *pFbxMaterial, Resource::ResourceManager& rm) {
//	Logger::Debug(pFbxMaterial->GetName());

	Render::MaterialElement& material = AddElement();

	const FbxImplementation *lImplementation = pFbxMaterial->GetDefaultImplementation();
	FbxPropertyT<FbxDouble3> lKFbxDouble3;
	FbxPropertyT<FbxDouble> lKFbxDouble1;
	FbxColor theColor;

	if(lImplementation){
		const FbxBindingTable *lTable = lImplementation->GetRootTable();
		size_t lEntryNum = lTable->GetEntryCount();

		for (int i = 0; i < (int) lEntryNum; ++i) {
			const FbxBindingTableEntry &lEntry = lTable->GetEntry(i);
			const char *lEntrySrcType = lEntry.GetEntryType(true);
			FbxProperty lFbxProp;


			FbxString lTest = lEntry.GetSource();
			FBXSDK_printf("            Entry: %s\n", lTest.Buffer());


			if (strcmp(FbxPropertyEntryView::sEntryType, lEntrySrcType) == 0) {
				lFbxProp = pFbxMaterial->FindPropertyHierarchical(lEntry.GetSource());
				if (!lFbxProp.IsValid()) {
					lFbxProp = pFbxMaterial->RootProperty.FindHierarchical(lEntry.GetSource());
				}


			}
			else if (strcmp(FbxConstantEntryView::sEntryType, lEntrySrcType) == 0) {
				lFbxProp = lImplementation->GetConstants().FindHierarchical(lEntry.GetSource());
			}
		}
	}
	else if (pFbxMaterial->GetClassId().Is(FbxSurfacePhong::ClassId))
	{
		// We found a Phong material.  Display its properties.

		// Display the Ambient Color
		lKFbxDouble3 =((FbxSurfacePhong *) pFbxMaterial)->Ambient;
		theColor.Set(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);

		// Display the Diffuse Color
		lKFbxDouble3 =((FbxSurfacePhong *) pFbxMaterial)->Diffuse;
		theColor.Set(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);

		// Display the Specular Color (unique to Phong materials)
		lKFbxDouble3 =((FbxSurfacePhong *) pFbxMaterial)->Specular;
		theColor.Set(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);

		// Display the Emissive Color
		lKFbxDouble3 =((FbxSurfacePhong *) pFbxMaterial)->Emissive;
		theColor.Set(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);

		//Opacity is Transparency factor now
		lKFbxDouble1 =((FbxSurfacePhong *) pFbxMaterial)->TransparencyFactor;

		// Display the Shininess
		lKFbxDouble1 =((FbxSurfacePhong *) pFbxMaterial)->Shininess;
		double dShininess = lKFbxDouble1.Get();

		lKFbxDouble1 =((FbxSurfacePhong *) pFbxMaterial)->Specular;
		double dSpecular = lKFbxDouble1.Get();

		lKFbxDouble1 =((FbxSurfacePhong *) pFbxMaterial)->SpecularFactor;
		double dSpecularFactor = lKFbxDouble1.Get();

		material.m_fShininess = dShininess;
		material.m_fSpecular = dSpecular * dSpecularFactor;

		// Display the Reflectivity
		lKFbxDouble1 =((FbxSurfacePhong *) pFbxMaterial)->ReflectionFactor;
		material.m_fReflectionFactor = lKFbxDouble1.Get();
	}
	else if(pFbxMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId) )
	{
		// We found a Lambert material. Display its properties.
		// Display the Ambient Color
		lKFbxDouble3=((FbxSurfaceLambert *)pFbxMaterial)->Ambient;
		theColor.Set(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);

		// Display the Diffuse Color
		lKFbxDouble3 =((FbxSurfaceLambert *)pFbxMaterial)->Diffuse;
		theColor.Set(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);

		// Display the Emissive
		lKFbxDouble3 =((FbxSurfaceLambert *)pFbxMaterial)->Emissive;
		theColor.Set(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]);

		// Display the Opacity
		lKFbxDouble1 =((FbxSurfaceLambert *)pFbxMaterial)->TransparencyFactor;
	}
	else
		Logger::Debug("Unknown type of Material");



	FbxProperty prop = pFbxMaterial->FindProperty(FbxSurfaceMaterial::sDiffuse);
	// Check if it's layeredtextures
	int layeredTextureCount = prop.GetSrcObjectCount<FbxLayeredTexture>();
	for (int j = 0; j < layeredTextureCount; j++)
	{
		FbxLayeredTexture* layered_texture = FbxCast<FbxLayeredTexture>(prop.GetSrcObject<FbxLayeredTexture>(j));
		int lcount = layered_texture->GetSrcObjectCount<FbxFileTexture>();

		for (int k = 0; k < lcount; k++)
		{
			FbxFileTexture* texture = FbxCast<FbxFileTexture>(layered_texture->GetSrcObject<FbxFileTexture>(k));
			// Then, you can get all the properties of the texture, include its name
			const char* textureName = texture->GetFileName();

			material.AddTexture(rm.LoadImageFromFile(textureName));
		}
	}

	int textureCount = prop.GetSrcObjectCount<FbxFileTexture>();
	for(int i=0; i<textureCount; ++i){
		FbxFileTexture* texture = FbxCast<FbxFileTexture>(prop.GetSrcObject<FbxFileTexture>(i));
		const char* textureName = texture->GetFileName();

		material.AddTexture(rm.LoadImageFromFile(textureName));
	}

	FbxPropertyT<FbxString> lString;
	lString = pFbxMaterial->ShadingModel;
}
예제 #17
0
bool SceneConverter::convert()
{
    //
    // Construt the scene
    //
    FbxNode *node = m_scene->GetRootNode();
    std::list<FbxNode *> nodes;
    std::map<FbxNode *, SceneNode *> fbxNode2SceneNodes;
    Scene scene;

    nodes.push_back(node);
    SceneNode *sceneNode = makeSceneNode(node);
    scene.addNode(sceneNode);
    fbxNode2SceneNodes.insert(std::make_pair(node, sceneNode));

    while (!nodes.empty())
    {
        FbxNode *ret = nodes.front();
        nodes.pop_front();

        for (int i = 0; i < ret->GetChildCount(); i++)
        {
            FbxNode *child = ret->GetChild(i);
            
            // Only output visible nodes.
            if (child->GetVisibility() && child->Show.Get())
            {
                SceneNode *sceneNode = makeSceneNode(child);
                if (sceneNode != NULL)
                {
                    if (sceneNode->type == "camera")
                    {
                        // The first camera will be the main camera of the scene
                        scene.setCamera(sceneNode);
                    }
                    scene.addNode(sceneNode, fbxNode2SceneNodes[ret]);
                    fbxNode2SceneNodes.insert(std::make_pair(child, sceneNode));
                }
            
                nodes.push_back(child);
            }
        }
    }

    // Create a camera if it is not included in FBX. The camera is evaluated
    // using the bounding box of all visible nodes.
    if (m_numCameras == 0)
    {
        FbxVector4 rootBboxMin;
        FbxVector4 rootBboxMax;
        FbxVector4 rootBboxCenter;

        rootBboxMin = FbxVector4(FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX);
        rootBboxMax = FbxVector4(-FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX);
    
        FbxNode *node = m_scene->GetRootNode();

        nodes.push_back(node);

        while (!nodes.empty())
        {
            FbxNode *ret = nodes.front();
            nodes.pop_front();

            for (int i = 0; i < ret->GetChildCount(); i++)
            {
                FbxNode *child = ret->GetChild(i);
                
                nodes.push_back(child);
            }
                
            if (ret->GetChildCount() == 0 &&
                ret->GetVisibility() && 
                ret->Show.Get() &&
                ret->GetMesh() != NULL)
            {
                FbxVector4 bboxMin;
                FbxVector4 bboxMax;
                FbxVector4 bboxCenter;

                ret->EvaluateGlobalBoundingBoxMinMaxCenter(bboxMin, bboxMax, bboxCenter);

                rootBboxMin[0] = std::min(rootBboxMin[0], bboxMin[0]);
                rootBboxMin[1] = std::min(rootBboxMin[1], bboxMin[1]);
                rootBboxMin[2] = std::min(rootBboxMin[2], bboxMin[2]);
                
                rootBboxMax[0] = std::max(rootBboxMax[0], bboxMax[0]);
                rootBboxMax[1] = std::max(rootBboxMax[1], bboxMax[1]);
                rootBboxMax[2] = std::max(rootBboxMax[2], bboxMax[2]);
            }
        }

        rootBboxCenter = (rootBboxMin + rootBboxMax) / 2;
        FbxVector4 rootBboxSize = rootBboxMax - rootBboxMin;
            
        SceneNode *sceneNode = new SceneNode();

        sceneNode->type = FbxString("camera");
        sceneNode->attributes.push_back(std::make_pair(FbxString("name"), FbxString("camera")));
        sceneNode->attributes.push_back(std::make_pair(FbxString("fixed"), FbxString("true")));

        double diag = sqrt(rootBboxSize[0] * rootBboxSize[0] + 
                           rootBboxSize[1] * rootBboxSize[1] + 
                           rootBboxSize[2] * rootBboxSize[2]) * 0.5;
            
        double eye = diag / tan(15.0 * FBXSDK_PI_DIV_180);

        double position[3];
        double up[3];
        double znear;
        double zfar;
            
        znear = eye - diag - 1.0f;
        zfar  = eye + diag + 1.0f;

        if (rootBboxSize[0] <= rootBboxSize[1] && rootBboxSize[0] <= rootBboxSize[2])
        {
            position[0] = eye + rootBboxCenter[0]; 
            position[1] = rootBboxCenter[1];
            position[2] = rootBboxCenter[2];

            up[0] = 0;
            up[1] = 1;
            up[2] = 0;
        }
        else if (rootBboxSize[1] <= rootBboxSize[0] && rootBboxSize[1] <= rootBboxSize[2])
        {
            position[0] = rootBboxCenter[0]; 
            position[1] = eye + rootBboxCenter[1];
            position[2] = rootBboxCenter[2];

            up[0] = 0;
            up[1] = 0;
            up[2] = 1;
        }
        else
        {
            position[0] = rootBboxCenter[0]; 
            position[1] = rootBboxCenter[1];
            position[2] = eye + rootBboxCenter[2];

            up[0] = 0;
            up[1] = 1;
            up[2] = 0;
        }

        char lookat[1024];
        char perspective[1024];
            
        FBXSDK_sprintf(lookat, 1024, "eye:%8.5f,%8.5f,%8.5f,center:%8.5f,%8.5f,%8.5f,up:%8.5f,%8.5f,%8.5f",
                    (float)position[0], (float)position[1], (float)position[2],
                    (float)rootBboxCenter[0], (float)rootBboxCenter[1], (float)rootBboxCenter[2],
                    (float)up[0], (float)up[1], (float)up[2]);
        sceneNode->attributes.push_back(std::make_pair(FbxString("lookat"), FbxString(lookat)));
            
        FBXSDK_sprintf(perspective, 1024, "perspective,fov:%8.5f,aspect:-1,znear:%8.5f,zfar:%8.5f",
                    30.0f, (float)znear, (float)zfar);
        sceneNode->attributes.push_back(std::make_pair(FbxString("projection"), FbxString(perspective)));
                    
        scene.setCamera(sceneNode);
        scene.addNode(sceneNode, scene.root());
    }

    //
    // Output the file.
    //
    //FbxString outputFilename = FbxPathUtils::GetFileName(m_arguments->FBXFileName.Buffer()).Lower();
    //outputFilename.FindAndReplace(".fbx", ".psc");
    FbxString outputFilename("scene.psc");
    FbxString path = FbxPathUtils::Bind(m_arguments->outputFolder, outputFilename.Buffer());
    bool ret = scene.output(path.Buffer());

    if (!ret)
    {
        FBXSDK_printf("Exporting failed!\n\n");
    }

    return ret;
}
예제 #18
0
void DrawText::Display(const char * pText)
{
    if (!mGlyph || mTextureName == 0)
        return;

    // Push OpenGL attributes.
    glPushAttrib(GL_ENABLE_BIT);
    glPushAttrib(GL_COLOR_BUFFER_BIT);
    glPushAttrib(GL_TEXTURE_BIT);

    glBindTexture(GL_TEXTURE_2D, mTextureName);
    glEnable(GL_TEXTURE_2D);

    // Blend with background color
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    // Visible for double side
    glDisable(GL_CULL_FACE);

    // Blend with foreground color
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glPushMatrix();
    const char * pCharacter = pText;
    while (*pCharacter != '\0')
    {
        if (*pCharacter == '\n')
        {
            glPopMatrix();
            // Move to the next line, left align
            glTranslatef(0, -mPointSize, 0);
            glPushMatrix();
        }
        else
        {
            Glyph * lGlyph = mGlyph + (*pCharacter - TEXTURE_MIN_GLYPH);
            if (lGlyph)
            {
                // Draw a rectangle with texture, alpha on.
                glBegin(GL_POLYGON);
                glTexCoord2f(lGlyph->texture_left, lGlyph->texture_bottom);
                glVertex2f(lGlyph->vertex_left * mPointSize, lGlyph->vertex_bottom * mPointSize);
                glTexCoord2f(lGlyph->texture_right, lGlyph->texture_bottom);
                glVertex2f(lGlyph->vertex_right * mPointSize, lGlyph->vertex_bottom * mPointSize);
                glTexCoord2f(lGlyph->texture_right, lGlyph->texture_top);
                glVertex2f(lGlyph->vertex_right * mPointSize, lGlyph->vertex_top * mPointSize);
                glTexCoord2f(lGlyph->texture_left, lGlyph->texture_top);
                glVertex2f(lGlyph->vertex_left * mPointSize, lGlyph->vertex_top * mPointSize);
                glEnd();

                const float advance = lGlyph->advance * mPointSize + mGap;
                glTranslatef(advance, 0, 0);
            }
            else
            {
                FBXSDK_printf("Invalid character: %c.\n", *pCharacter);
            }
            
        }
        ++pCharacter;
    }
    glPopMatrix();

    // Pop OpenGL attributes.
    glPopAttrib();
    glPopAttrib();
    glPopAttrib();
}
예제 #19
0
void Tools::DisplayNURB::DisplayNURB( FbxNode *i_node )
{
	DisplayCommon::DisplayString( "\n\n--------------------\nNURB\n--------------------" );

	FbxNurbs* NURBs = (FbxNurbs*) i_node->GetNodeAttribute ();
	int i;

	DisplayCommon::DisplayString( "Nurb Name: ", (char *) i_node->GetName() );
	DisplayCommon::DisplayMetaDataConnections( NURBs );

	const char* surfaceModes[] = { "Raw", "Low No Normals", "Low", "High No Normals", "High" };

	DisplayCommon::DisplayString( "    Surface Mode: ", surfaceModes[NURBs->GetSurfaceMode()] );

	int controlPointsCount = NURBs->GetControlPointsCount();
	FbxVector4 *controlPoints = NURBs->GetControlPoints();

	for( i = 0; i < controlPointsCount; i++ )
	{
		DisplayCommon::DisplayInt( "    Control Point ", i );
		DisplayCommon::Display3DVector( "        Coordinates: ", controlPoints[i] );
		DisplayCommon::DisplayDouble( "        Weight: ", controlPoints[i][3] );
	}

	const char* NURBTypes[] = { "Periodic", "Closed", "Open" };

	DisplayCommon::DisplayString( "    Nurb U Type: ", NURBTypes[NURBs->GetNurbsUType()] );
	DisplayCommon::DisplayInt( "    U Count: ", NURBs->GetUCount() );
	DisplayCommon::DisplayString( "    Nurb V Type: ", NURBTypes[NURBs->GetNurbsVType()] );
	DisplayCommon::DisplayInt( "    V Count: ", NURBs->GetVCount() );
	DisplayCommon::DisplayInt( "    U Order: ", NURBs->GetUOrder() );
	DisplayCommon::DisplayInt( "    V Order: ", NURBs->GetVOrder() );
	DisplayCommon::DisplayInt( "    U Step: ", NURBs->GetUStep() );
	DisplayCommon::DisplayInt( "    V Step: ", NURBs->GetVStep() );

	FbxString string;
	int UKnotCount = NURBs->GetUKnotCount();
	int VKnotCount = NURBs->GetVKnotCount();
	int UMultiplicityCount = NURBs->GetUCount();
	int VMultiplicityCount = NURBs->GetVCount();
	double* UKnotVector = NURBs->GetUKnotVector();
	double* VKnotVector = NURBs->GetVKnotVector();
	int* UMultiplicityVector = NURBs->GetUMultiplicityVector();
	int* VMultiplicityVector = NURBs->GetVMultiplicityVector();

	string = "    U Knot Vector: ";

	for( i = 0; i < UKnotCount; i++ )
	{
		string += (float) UKnotVector[i];

		if(i < UKnotCount - 1)
		{
			string += ", ";
		}
	}

	DisplayCommon::DisplayString( string );
	string += "\n";
	FBXSDK_printf( string );

	string = "    V Knot Vector: ";

	for( i = 0; i < VKnotCount; i++ )
	{
		string += (float) VKnotVector[i];

		if( i < VKnotCount - 1 )
		{
			string += ", ";
		}
	}

	DisplayCommon::DisplayString( string );
	string += "\n";
	FBXSDK_printf(string);

	string = "    U Multiplicity Vector: ";

	for( i = 0; i < UMultiplicityCount; i++ )
	{
		string += UMultiplicityVector[i];

		if( i < UMultiplicityCount - 1 )
		{
			string += ", ";
		}
	}

	DisplayCommon::DisplayString( string );
	string += "\n";
	FBXSDK_printf(string);

	string = "    V Multiplicity Vector: ";

	for( i = 0; i < VMultiplicityCount; i++ )
	{
		string += VMultiplicityVector[i];

		if( i < VMultiplicityCount - 1 )
		{
			string += ", ";
		}
	}

	DisplayCommon::DisplayString( string );
	string += "\n";
	FBXSDK_printf( string );

	//DisplayString( "" );

	DisplayTexture::DisplayTexture( NURBs );
	DisplayMaterial::DisplayMaterial( NURBs );
	DisplayLink::DisplayLink( NURBs );
	DisplayShape::DisplayShape( NURBs );
}
예제 #20
0
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
}
예제 #21
0
bool LoaderFbx::loadScene(std::string filename)
{
	bool success = true;

	int fileMajor, fileMinor, fileRevision;
	int sdkMajor, sdkMinor, sdkRevision;
	std::stringstream message;

	FbxManager::GetFileFormatVersion(sdkMajor, sdkMinor, sdkRevision);

	FbxImporter* fbxImporter = FbxImporter::Create(fbxManager_, "");
	success = fbxImporter->Initialize(filename.c_str(), -1, fbxManager_->GetIOSettings());
	fbxImporter->GetFileVersion(fileMajor, fileMinor, fileRevision);

	if(!success)
	{
		message.str("");
		message << "LoaderFbx::loadScene | Call to FbxImporter::Initialize() failed! \n Error returned: " 
				<< fbxImporter->GetStatus().GetErrorString();
		ERROR_MESSAGEBOX(message.str());

		if(fbxImporter->GetStatus().GetCode() == FbxStatus::eInvalidFileVersion)
		{
			std::stringstream message;
			message.str("");
			message << "FBX file format version for this FBX SDK is " << sdkMajor << "." << sdkMinor << "." << sdkRevision << "\n"
					<< "FBX file format version for file " << filename << " is " << fileMajor << "." << fileMinor << "." << fileRevision;
			ERROR_MESSAGEBOX(message.str());
		}
	}
	if(fbxImporter->IsFBX())
	{
		FBXSDK_printf("FBX file format version for file '%s' is %d.%d.%d\n\n", filename, fileMajor, fileMinor, fileRevision);

        // From this point, it is possible to access animation stack information without
        // the expense of loading the entire file.

        FBXSDK_printf("Animation Stack Information\n");

        int animStackCount = fbxImporter->GetAnimStackCount();

        FBXSDK_printf("    Number of Animation Stacks: %d\n", animStackCount);
        FBXSDK_printf("    Current Animation Stack: \"%s\"\n", fbxImporter->GetActiveAnimStackName().Buffer());
        FBXSDK_printf("\n");

        for(int i = 0; i < animStackCount; i++)
        {
            FbxTakeInfo* takeInfo = fbxImporter->GetTakeInfo(i);

            FBXSDK_printf("    Animation Stack %d\n", i);
            FBXSDK_printf("         Name: \"%s\"\n", takeInfo->mName.Buffer());
			const char* debug = takeInfo->mDescription.Buffer();
	//		FBXSDK_printf("         Description: \"%s\"\n", takeInfo->mDescription.Buffer());
            
			// Change the value of the import name if the animation stack should be imported 
            // under a different name.
            FBXSDK_printf("         Import Name: \"%s\"\n", takeInfo->mImportName.Buffer());

            // Set the value of the import state to false if the animation stack should be not
            // be imported. 
            FBXSDK_printf("         Import State: %s\n", takeInfo->mSelect ? "true" : "false");
            FBXSDK_printf("\n");

			
        }

        // Set the import states. By default, the import states are always set to 
        // true. The code below shows how to change these states.
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_MATERIAL,        true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_TEXTURE,         true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_LINK,            true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_SHAPE,           true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_GOBO,            true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_ANIMATION,       true);
        fbxManager_->GetIOSettings()->SetBoolProp(IMP_FBX_GLOBAL_SETTINGS, true);
	}
	
	if(success)
	{
		success = fbxImporter->Import(fbxScene_);
	}

	if(!success)
	{
		message.str("");
		message << "LoaderFbx::loadScene | Call to FbxImporter::Import() failed! \n Error returned: "
				<< fbxImporter->GetStatus().GetErrorString();
		ERROR_MESSAGEBOX(message.str());
	}

	return success;
}