Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

FBX sdk how to set custom property into a FbxScene

FBX sdk how to set custom property into a FbxScene

Anonymous
Not applicable
2,144 Views
1 Reply
Message 1 of 2

FBX sdk how to set custom property into a FbxScene

Anonymous
Not applicable

Not sure if this is the correct forum for such questions.

 

I want to serialize some custom strings into an FbxScene, which is to be passed to FbxExporter.

Using FbxProperty, I have seen code snippets like

FbxProperty::Create(pNode, ...) 

but these work on a particular node, whereas the strings i want to serialize are global to the .fbx file.

I am thinking of something along the lines of this, but I am not sure of the specific functions to call:

// To save
FbxScene scene;string myString = "string to add";scene->getPropertyHandle().add("myPropertyName", myString);

// To load
FbxScene scene;string myString = scene->findProperty("myPropertyName").get<string>();

 

0 Likes
Accepted solutions (1)
2,145 Views
1 Reply
Reply (1)
Message 2 of 2

regalir
Autodesk
Autodesk
Accepted solution

You can create properties directly to the FbxScene object (see code snippet) . Just be aware that an FBX reader that does not know about your custom properties will ignore them. Also,  if you plan to write ASCII files, I strongly suggest you write your strings into an FbxBlob because the ascii parser has a limited string length that it can support (I believe around 4000 characters). Sure it is a little bit more of work and the strings are not readable until extracted, but you save yourself from creating corrupted FBX files 😉

 

FbxPropertyT<FbxString> lP = FbxProperty::Create(lScene, FbxStringDT, "PropOnScene");
lP.Set("a dynamic property directly on the scene");

 

The above code snipped will produce the following data in the FBX file:

 

; Documents Description
;------------------------------------------------------------------

Documents:  {
	Count: 1
	Document: 1400889389744, "My Scene", "Scene" {
		Properties70:  {
			P: "SourceObject", "object", "", ""
			P: "ActiveAnimStackName", "KString", "", "", ""
			P: "PropOnScene", "KString", "", "", "a dynamic property directly on the scene"
		}
		RootNode: 0
	}
}

 

To get the property back, you can call FindProperty:

FbxProperty p = lScene->FindProperty("PropOnScene");
if (p.IsValid())
    FBXSDK_printf("PropOnScene=%s\n", p.Get <FbxString>().Buffer());

 

Maybe, however, it may be more appropriate to add them to the FbxDocumentInfo object (it really depend on your goals). If you have more than one property, I also suggest that you attach them under a parent property. Something like this should work:

 

FbxDocumentInfo* lDocInfo = lScene->GetDocumentInfo();
if (lDocInfo)
{
    FbxProperty lMyCustomPropertyGroup = FbxProperty::Create(lDocInfo, FbxCompoundDT, "MyCustomProperties");
    FbxPropertyT<FbxString>  lProp = FbxProperty::Create(lMyCustomPropertyGroup, FbxStringDT, "PropA");
    lProp.Set("This is my first custom property string value");

    lProp = FbxProperty::Create(lMyCustomPropertyGroup, FbxStringDT, "PropN");
    lProp.Set("and a second string property");
}

 

and will produce:

	SceneInfo: "SceneInfo::GlobalInfo", "UserData" {
		Type: "UserData"
		Version: 100
		MetaData:  {
			Version: 100
			Title: ""
			Subject: ""
			Author: ""
			Keywords: ""
			Revision: ""
			Comment: ""
		}
		Properties70:  {
			P: "DocumentUrl", "KString", "Url", "", "c:\temp\customProp.fbx"
			P: "SrcDocumentUrl", "KString", "Url", "", "c:\temp\customProp.fbx"
			P: "Original", "Compound", "", ""
			P: "Original|ApplicationVendor", "KString", "", "", ""
			P: "Original|ApplicationName", "KString", "", "", ""
			P: "Original|ApplicationVersion", "KString", "", "", ""
			P: "Original|DateTime_GMT", "DateTime", "", "", ""
			P: "Original|FileName", "KString", "", "", ""
			P: "LastSaved", "Compound", "", ""
			P: "LastSaved|ApplicationVendor", "KString", "", "", ""
			P: "LastSaved|ApplicationName", "KString", "", "", ""
			P: "LastSaved|ApplicationVersion", "KString", "", "", ""
			P: "LastSaved|DateTime_GMT", "DateTime", "", "", ""
			P: "MyCustomProperties", "Compound", "", ""
			P: "MyCustomProperties|PropA", "KString", "", "", "This is my first custom property string value"
			P: "MyCustomProperties|PropN", "KString", "", "", "and a second string property"
		}
	}
}