sideeffects / HoudiniFBX

Houdini's FBX integration.
46 stars 16 forks source link

Instances written as Mesh #1

Open Rayfoundry opened 6 years ago

Rayfoundry commented 6 years ago

The FBX ROP writes instanced geometry as unique Mesh items into the FBX. The documentation on sidefx.com states that Instances are supported for export but is not clear about if it just writes them out somehow or if it uses the FBX Mesh Instance feature. So not completely sure if the behaviour of the FBX ROP is "as-designed" or if it's a bug.

Nevertheless it would be awesome if the FBX ROP would write out only Mesh items for Houdini Geo that is not instanced and associate the Model item in the FBX with the Mesh item written.

Why is this relevant? Unity for example supports FBX with instancing such that it imports the Mesh item only once and then creates elements called prefabs (the FBX Model equivalent) which link to the Mesh.

This saves memory, makes GPU instancing easy and is generally more correct behaviour imho.

Rayfoundry commented 6 years ago

The functionality to support instances semi-exists in ROPDerivedActions as an ROP_FBXCreateInstancesAction. Specifically lines 470-557. There's some comment:

Unbelievably, there is no way to make a copy of a node's attribute in FBX, and they can't be instanced. We're forced to re-create the node from scratch. Arghhh.

The FBX documentation on http://docs.autodesk.com/FBX/2014/ENU/FBX-SDK-Documentation/index.html?url=files/GUID-0D483705-23D9-476D-A567-09609396B190.htm,topicNumber=d30e10223 states that FBXObjects can be copied with

// Copy the data from lSourceMesh into lTargetMesh. Note that // the source object and the target object must be instances of // the same class (FbxMesh in this case). lTargetMesh->Copy(lSourceMesh); In the case of an instance, wouldn't it work (if the attribute (FBXProperty?) itself can't be copied, to copy the whole node and overwrite the specific properties in the next step with the hd instance properties?

Sorry if I'm writing BS, I'm not a C++ coder and on thin ice here. But since many other DCC implemented instances with FBX (or better call it mesh deduplication) there has to be a way.