Object Hierarchy | 関連する C++クラス:SimulationEnvironment
SimulationEnvironment
v4.2
SimulationEnvironment オブジェクトは、シミュレーションを定義するために使用される構造を表します。現在
SimulationEnvironment オブジェクトは RigidBody
シミュレーションにのみ使用されます。シミュレーション環境は接続コンテナのセットです。各コンテナはシミュレーション内のエレメントの種類(リジッドボディオブジェクト、リジッドボディコンストレイント、フォース)に対応します。この環境ではシミュレーション内のオブジェクト間の関係が追跡され、ダイナミクスオペレータが適用されるオブジェクトが決定します。ダイナミクス
オペレータは、この環境内のすべてのエレメントについてシミュレーションを計算します。 さらに、TimeControlオブジェクトでは、この環境のシミュレーションをどのように再生するかを指定します。
環境は、CreateActiveRigidBodyまたはCreatePassiveRigidBodyを使用して取得できる
RigidBody オブジェクトを作成すると、作成されます。CreateEnvironmentを使用して、環境を明示的に作成することもできます。SimulationEnvironment
オブジェクトは、Scene.ActiveSimulationEnvironmentまたはScene.SimulationEnvironmentsによって取得できます。
/*
This example illustrates how to create a cached RigidBody simulation and
apply that cache to animate the simulated objects directly without using
the simulation.
*/
NewScene( null, false );
var oCone = ActiveSceneRoot.AddGeometry( "cone","MeshSurface" );
var oModel = ActiveSceneRoot.AddModel();
oModel.Name = "Model";
var oGrid = oModel.AddGeometry( "grid","MeshSurface" );
// Move the cone
oCone.posy.value = 6.0;
// Modify the grid
oGrid.ulength.value = 24;
oGrid.vlength.value = 24;
oGrid.subdivu.value = 24;
oGrid.subdivv.value = 24;
// The following line creates the SimulationEnvironment object.
CreatePassiveRigidBody( oGrid );
CreateActiveRigidBody( oCone );
CreateForce( "Gravity" );
var oEnvironment = ActiveProject.ActiveScene.ActiveSimulationEnvironment;
var oSimulationTimeControl = oEnvironment.SimulationTimeControl;
// Turn the caching on.
oSimulationTimeControl.caching.value = true;
oSimulationTimeControl.playmode.value = 0; //Standard play mode.
// Simulate
// To make sure that all frames get simulated
for ( i=0; i<100; i++ ) {
NextFrame();
Refresh();
}
// Get all models in the scene (getting the identifier of the Scene Root's class = Model)
var sModelClassID = XSIUtils.DataRepository.GetIdentifier( ActiveSceneRoot, siObjectCLSID );
var oModels = FindObjects( "", sModelClassID );
ApplyCurrentEnvironmentCacheToSimulateObjectForModels( oModels );
// The FCurve animated objects
PlayForwardsFromStart();
// This function takes the cached simulation and copies it directly
// on the driven objects as FCurves. It also turns off the simulation
// so that we could
function ApplyCurrentEnvironmentCacheToSimulateObjectForModels( in_models )
{
var eModels = new Enumerator( in_models );
var oCurrEnvironment = ActiveProject.ActiveScene.ActiveSimulationEnvironment;
var oSimulationTimeControl = oCurrEnvironment.SimulationTimeControl;
// Deactivate the simulation so that objects are driven by their
// animation.
oSimulationTimeControl.Active.Value = false;
for ( ; !eModels.atEnd(); eModels.moveNext() ) {
var oCurrModel = eModels.item();
var oCache = oCurrEnvironment.FindCacheForModel( oCurrModel );
var oSourceItems = oCache.SourceItems;
var eSourceItems = new Enumerator(oSourceItems);
for( ; !eSourceItems.atEnd(); eSourceItems.moveNext() ) {
var oSourceItem = eSourceItems.item();
strTarget = oSourceItem.Target;
if ( oCurrModel.IsEqualTo(ActiveSceneRoot) == false ) {
// ActionSource keeps the relative name of an
// animated parameter. We need to prepend the
// model name if the model owner is not the scene
// root in order to fetch the parameter.
strTarget = oCurrModel.Name + "." + strTarget;
}
var oTargetParameter = Dictionary.GetObject(strTarget);
// The RigidBody simulation caches linear acceleration which
// is not animatable. We won't be copying those values on
// the global transform.
if ( oTargetParameter.Animatable ) {
var oCachedFCurve = oSourceItem.Source;
CopyFCurveOnParameter( oCachedFCurve, oTargetParameter );
}
}
}
}
// This function creates a copy of an FCurve on a parameter by creating a new
// FCurve on the parameter and adding all keys. It will take use the default
// Tangent and Interpolation.
function CopyFCurveOnParameter( in_FCurve, in_Parameter )
{
var oNewFCurve = in_Parameter.AddFCurve2();
var oFCurveKeys = in_FCurve.Keys;
var eFCurveKeys = new Enumerator( oFCurveKeys );
oNewFCurve.BeginEdit();
for( ; !eFCurveKeys.atEnd(); eFCurveKeys.moveNext() ) {
var oCurrentKey = eFCurveKeys.item();
oNewFCurve.AddKey( oCurrentKey.time, oCurrentKey.value );
}
oNewFCurve.EndEdit();
}
|
#
# This example illustrates how to create cached RigidBody simulations, export
# that cache as an action source, import it into a new scene, and then
# instantiate it as a clip in the new mixer.
#
from win32com.client import constants as c
Application.NewScene( "", 0 )
oRoot = Application.ActiveSceneRoot
oCone = oRoot.AddGeometry( "cone","MeshSurface" )
oModel = oRoot.AddModel()
oModel.Name = "TestModel"
oGrid = oModel.AddGeometry( "grid","MeshSurface" )
# Move the cone
oCone.posy.Value = 6.0
# Modify the grid
oGrid.ulength.Value = 24
oGrid.vlength.Value = 24
oGrid.subdivu.Value = 24
oGrid.subdivv.Value = 24
# The following line creates the SimulationEnvironment object.
Application.CreatePassiveRigidBody( oGrid )
Application.CreateActiveRigidBody( oCone )
Application.CreateForce( "Gravity" )
oEnvironment = Application.ActiveProject.ActiveScene.ActiveSimulationEnvironment
oSimulationTimeControl = oEnvironment.SimulationTimeControl
# Turn the caching on.
oSimulationTimeControl.caching.Value = 1;
oSimulationTimeControl.playmode.Value = 0; #Standard play mode.
# Simulate, making sure that all frames get simulated
i=0
while i < 100 :
Application.NextFrame()
Application.Refresh()
i = i + 1
# Export the action sources
aModelNames = [ "two", "one", "two", "one" ]
sPath = Application.InstallationPath( c.siProjectPath )
for oActionSource in oEnvironment.Caches :
Application.ExportAction( oActionSource, sPath + "\\Actions\\SimCache"
+ aModelNames.pop() + ".xsi" )
# Dump the current scene and open a new one
Application.NewScene( "", 0 )
oRoot = Application.ActiveSceneRoot
oCone = oRoot.AddGeometry( "cone","MeshSurface" )
oGrid = oRoot.AddGeometry( "grid","MeshSurface" )
# Reload the sources
oNewAction = Application.ImportAction( oRoot, sPath + "\\Actions\\SimCache"
+ aModelNames.pop() + ".xsi", "MyImportedAction1", c.siSourceStorageTypeInternal )
Application.AddClip( oRoot, oNewAction )
oNewAction = Application.ImportAction( oRoot, sPath + "\\Actions\\SimCache"
+ aModelNames.pop() + ".xsi", "MyImportedAction2", c.siSourceStorageTypeInternal )
Application.AddClip( oRoot, oNewAction );
# Playback the results
Application.PlayForwardsFromStart()
|