Indirect Reference Example

The following MAXScript code and diagram illustrate an example when a reference hierarchy would need to be circular. The MAXScript code creates references that point upwards in the reference hierarchy using indirect references. A diagram of the various scene entities and their relationships follows. The dashed lines in the diagram represent indirect references. If these indirect references were assumed to be ordinary or strong references, code that followed the reference tree would find itself in an infinite loop.

-- Create two spheres
s1 = sphere pos:[100,100,0] 
s2 = sphere pos:[-100,100,0]
 
-- Create a float contoller for the radius
rc = float_script()
s2.radius.controller = rc  
 
-- Create a teapot
t1 = teapot()
rc.AddNode "teapot" t1
 
-- Create and assign a position controller to the teapot
sc = Position_Script()
t.pos.controller = sc
 
-- Display the controller dialogs
displayControlDialog rc "sphere radius"
displayControlDialog sc "teapotpos"
 
-- Add the sphere as a node to the script controller
sc.AddNode "s1_Node_Node" s1
rtm = RefTargMonitor refTarg:s2.baseobject 
sc.AddObject "s_base_object"
 
-- Post load
sc = $teapot01.pos.controller
rc = $sphere02.radius.controller
displayControlDialog rc "sphere radius"
displayControlDialog sc "teapotpos"
rtm = sc.getVarValue "s_base_object"
rtm.reftarg

The 3ds Max SDK provides the following indirect reference makers that plug-in developers can use: INodeMonitor, INodeTransformMonitor, IRefTargMonitorClass, and IIndirectRefTargContainer.