In this tutorial, we will discuss about loading various assets from file system into SmartBody. As a character animation system, SmartBody requires several different types of data to work. For example, a skeleton is used to define the character structure, a motion is used to animate the character, a skin mesh is used to deform and render the character, and a script file stores macros of multiple Python commands.
To load the data, we need to first get the 'asset manager' object from scene object.
assetManager = scene.getAssetManager()
Then we can define the local paths for asset manager to find different type of asset files.
assetManager.addAssetPath('motion', 'ChrBrad') assetManager.addAssetPath('mesh', 'mesh') assetManager.addAssetPath('script', 'scripts')
For example, here the first 'addAssetPath' means we will add a search path 'ChrBrad' for 'motion' type of assets into the asset manager. So the system will search 'ChrBrad' directory when trying to load new motions or skeletons. Note that 'ChrBrad' is a relative directory to the system media path ( default media path is $SmartBodyDirectory/data ). You can use scene.setMediaPath to change the media path directory. Similarly, the other 'addAssetPath' commands will set the search path for 'mesh' and 'script' assets.
Once we setup the search paths for assets, we can have the system load up the skeleton and motion files by calling :
assetManager.loadAssets()
This command will go through each search path, and load the skeleton and motion asset files inside those paths. Note that 'mesh' and 'script' files will not be loaded by this command, but the search paths will be used when the system needs to look for such assets. For example, you can execute a Python script file directly by calling :
scene.run('zebra2-map.py')
The system will then search for script file 'zebra2-map.py' in the 'script' asset paths and execute it. If we didn't set the asset paths for 'script', then the system will not be able to find the script file and will produce an error.
Once the system finish loading all motions and skeletons from asset paths, we can query for the list of names of the assets ( motions and skeletons ) currently loaded into the system :
motionNames = assetManager.getMotionNames() skelNames = assetManager.getSkeletonNames() for i in range(0,len(motionNames)): print 'motion ' + str(i) + ' = ' + motionNames[i] for i in range(0,len(skelNames)): print 'skeleton ' + str(i) + ' = ' + skelNames[i]
These asset files can then be used to create and animate a character. We will discuss this in the next tutorial.