Scripting – Finding the objects in different SimulationEnvironments

Here’s a script that goes through the SimulationEnvironments of a scene and find the 3d objects in each SimulationEnvironment. This snippet builds a dictionary of 3d objects, indexed by simulation environment.

from siutils import si
si = si()					# win32com.client.Dispatch('XSI.Application')
from siutils import log		# LogMessage
from siutils import disp	# win32com.client.Dispatch
from siutils import C		# win32com.client.constants

from xml.etree import ElementTree as ET

# Use a dictionary to store the 3d objects keyed by Environmen
dict = {}
for e in si.ActiveProject2.ActiveScene.SimulationEnvironments:
	stack = XSIUtils.DataRepository.GetConnectionStackInfo( e.SimulationTimeControl )
	xmlRoot = ET.fromstring( stack )
	for xmlConnections in xmlRoot.findall('connection'):
		o = xmlConnections.find( 'object' )
		dict[ si.Dictionary.GetObject( o.text ).Parent3DObject.FullName ] = e.FullName
log( "3DObjects and their SimulationEnvironments" )
for key, value in dict.items():
	log( "\t%s, %s" % (key,value) )

log( "" )

log( "SimulationEnvironments and 3DObjects" )
dictvals = set( dict.values() )
for env in dictvals:
	log( "\t%s" % env )
	list = [k for k, v in dict.iteritems() if v == env]
	for o in list:
		log( "\t\t%s" % o )

Here’s some sample output from the script:

# INFO : 3DObjects and their SimulationEnvironments
# INFO : 	pointcloud1, Environments.Environment
# INFO : 	Point_cloud_chaser.pointcloud2, Environments.Environment1
# INFO : 	grid, Environments.Environment
# INFO : 	Point_cloud_chaser.pointcloud1, Environments.Environment1
# INFO : 	pointcloud, Environments.Environment
# INFO : 	Point_cloud_chaser.pointcloud, Environments.Environment1
# INFO : 
# INFO : SimulationEnvironments and 3DObjects
# INFO : 	Environments.Environment1
# INFO : 		Point_cloud_chaser.pointcloud2
# INFO : 		Point_cloud_chaser.pointcloud1
# INFO : 		Point_cloud_chaser.pointcloud
# INFO : 	Environments.Environment
# INFO : 		pointcloud1
# INFO : 		grid
# INFO : 		pointcloud

Rigid body dynamic (RBD) precision and subframe sampling

About precision and subframe sampling for rigid body dynamics…here’s my understanding of how these two are related. Note that nobody confirmed this when I asked around, but then again nobody gainsaid it either 😉

The precision determines how frequently the simulation is calculated. For example, if Precision=120, then there is at most 1/120 of a second between calculations.

The subframe sampling determines the number of samples per frame.

So, if you are have this:

  • 30 fps
  • Precision = 120 per second
  • Subframe sampling =2 per frame

Then the RBD simulation is updated/calculated 4 times per frame (120/30), and ICE takes 2 samples of those calculated values per frame.

Offsetting ICE simulations

In this video, I take a look at how to offset ICE simulations, and I look into the role of the Simulation Environment.

  • Use the Limit by Time Range node to control when a simulation (emission) is active.
  • When you create a simulated ICE tree, it is added to the current simulation environment.
  • Models don’t include the simulation environment.
  • Merged scenes usually bring in their own simulation environment, which doesn’t always match the number of frames in the current scene.