Technically interesting question of the day:

What is the recommended way to get a reference to an arbitrary scene object 
from primitive data such as a string or LONG?

I am trying to improve performance on an exporter I inherited from somebody 
that no longer works here.   We are experiencing major slowdowns in the area of 
exporting render passes for our environments as some scenes take 20+ minutes.  
Our environment scenes contain thousands of objects which are mostly contained 
inside of referenced models and can have parameters overridden using override 
properties applied to partitions.  We currently only support overrides for our 
custom shader parameters and object viewvis/rendvis parameters.  In an effort 
to keep our exported files small, we only export a parameter override if its 
value is different from the default_pass.  If the parameter is exported, its 
original name is used (Parameter.GetFullName() as seen in default pass, not as 
seen in the current pass).  This is to keep mapping 1:1 and efficient in our 
runtime engine.  The area of biggest slowdown is reverse engineering the 
parameter name in the override to determine the parameter it's overriding in 
the default pass.  While the Softimage SDK provides the ability to do this 
(Parameter.GetOverridenObject() ), it's incredibly slow.

The original code calls FindChildren() and iterates through all objects in the 
scene to build a map to cache object visibility and material assignments in the 
default pass.  The object's fullname is used as the key to store/retrieve 
information from the map.  In an effort to reduce data storage requirements, 
and reduce amount of string parsing in downstream helper functions, I converted 
the map to use Object IDs as the look up key.  While it greatly simplified the 
exporter code, to my surprise it made performance noticeably worse.  Caching 
the settings using Object.GetObjectID() was very fast, but when it came to 
retrieving the information downstream in a helper function, I had to use 
CRef.Set( <objectID> ) to convert the Object ID back into an object reference.  
That conversion was really, really, slow in comparison.

In scripting I would use Dictionary.GetObject() which equates to CRef.Set() in 
the C++ API.  But in either case that is not very efficient when dealing with 
thousands of objects in multiple passes.  In scripting I could use 
XSICollection.items = <value> to more quickly create the references and forego 
errors being thrown, but I don't see an equivalent in the C++ API.

So the question is - what is the fastest way to get a reference to an object in 
the scene from an ID or string using the C++ API?

Matt



Reply via email to