Create Multiple Instances of Actors
This example shows how to use the For Each Subsystem (Simulink) block to create multiple instances of the same actor type in a 3D environment. Consider this approach if you want to avoid multiple instances of a Simulation 3D Actor block in your model.
In this example model, the For Each Subsystem block implements a Simulation 3D Actor block to create five cylindrical actors. Each cylinder is a different color and has a different initial translation and rotation. During the simulation, you can independently change the translation and rotation of each actor.
The Simulation 3D Actor block rotation, translation, and scale parameters are tunable, allowing the for-each subsystem to partition the parameters.
3D Environment
The model contains Simulation 3D Configuration and For Each Subsystem blocks.
open_system('Sim3DActorForEach')
The For Each Subsystem block masks the tunable Simulation 3D Actor block Translation and Rotation parameters. The Simulation 3D Actor block uses the translation and rotation parameter values to initially place the actors in the 3D environment.
For Each Subsystem
The For Each Subsystem block contains two Simulation 3D Actor blocks. Each block is in a for-each loop. When the for-each subsystem partitions the parameters, the values are the initial Simulation 3D Actor block Translation and Rotation parameter values. The loop index, N, corresponds to the partition dimension. In this example, the loop index is five. To open the for-each subsystem, use this command.
open_system('Sim3DActorForEach/For Each Subsystem','force')
The first Simulation 3D Actor block creates the cylinder actors. The initialization script creates each cylinder actor with a different color.
The second Simulation 3D Actor block controls the translation and rotation of the five actors.
Simulation
During the simulation, you can independently change the translation and rotation of each actor. Use the Transform and Rotation Constant block parameters to change the actor orientation during the simulation. The Constant block values are m
-by-3 arrays. m
is the number of actors. In this example, m
is 5
.
See Also
Simulation 3D Actor | Simulation 3D Scene Configuration | For Each Subsystem (Simulink)