Skip to content

Instantly share code, notes, and snippets.

@EricTRocks
Last active February 28, 2016 20:53
Show Gist options
  • Save EricTRocks/acdb297705dd58a6226c to your computer and use it in GitHub Desktop.
Save EricTRocks/acdb297705dd58a6226c to your computer and use it in GitHub Desktop.
This is a snippet of code that can be used to bake per frame point positions of a mesh in Softimage to an ICE Attribute for local storage. This code hasn't been tested in this form and has been extracted from a larger tool. May need some editing / optimization.
# Baking point positions to an ICE attribute for local caching.
# Eric Thivierge
from win32com.client import Dispatch
from win32com.client import constants
si = Application
log = LogMessage
sel = si.Selection
playCtrl = si.ActiveProject3.Properties("Play Control")
startFrame = 0
endFrame = 100
if sel.Count < 1:
log("Select a mesh to cache!", 4)
else:
targetMesh = sel(0)
# Add ICE Attr for storing cache
initGeometry = targetMesh.ActivePrimitive.Geometry
pointCacheAttr = initGeometry.AddICEAttribute("bake_pointCache", constants.siICENodeDataVector3, constants.siICENodeStructureArray, constants.siICENodeContextComponent0D)
pointCacheAttr = Dispatch(initGeometry.ICEAttributes('bake_pointCache')) # Dispatch Fix
pointCacheAttr.AlwaysEvaluated = True
# Build and resize / fill 2D array with initial point pos values.
# [
# [1.0, 1.0, 1.0, ... 1.0] # Pnt 0, init pos from 0-100 frames for each point.
# [1.0, 1.0, 1.0, ... 1.0] # Pnt 1
# [1.0, 1.0, 1.0, ... 1.0] # Pnt 2
# [1.0, 1.0, 1.0, ... 1.0] # Pnt 3
# [1.0, 1.0, 1.0, ... 1.0] # Pnt 4 ...
# ]
cacheArray = []
initPointPositions = list(initGeometry.GetICEAttributeFromName("PointPosition").DataArray)
for eachPoint in xrange(initGeometry.Points.Count):
cacheArray.append([initPointPositions[eachPoint] for x in xrange(0, endFrame+1)])
totalFrames = (endFrame + 1) - startFrame
for i in xrange(totalFrames):
playCtrl.Parameters("Current").Value = startFrame + i # change frame
# Get current geometry at this frame
currentGeometry = targetMesh.ActivePrimitive.Geometry
pointPositions = list(currentGeometry.GetICEAttributeFromName("PointPosition").DataArray)
# Store each point pos into the bake data
for eachPoint in xrange(currentGeometry.Points.Count):
bakeData["cacheArray"][eachPoint][startFrame + i] = pointPositions[eachPoint]
# Once done building up the array set it back to the attribute
pointCacheAttr.DataArray2D = cacheArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment