主要内容

Create Light Using Simulink

This example shows how to create custom lighting with a point light, a spot light, and a rectangular light using the Simulation 3D Actor block. First, create a room in the 3D environment. Next, create three actors using sim3d.Actor objects, add them as child actors of the room, and position them inside the room. Then, create a point light, a spot light, and a rectangular light, add them as child actors of the room, and position them above the actors inside the room. Finally, in the Simulation 3D Viewer, view the room and its actors illuminated by the different types of light.

Open the model.

open_system("CreateLightUsingSimulink.slx");

Simulink model with a Simulation 3D Scene Configuration block and a Simulation 3D Actor block.

The model includes a Simulation 3D Scene Configuration block and a Simulation 3D Actor block. The Simulation 3D Scene Configuration block implements a 3D simulation environment and sets a view in the scene with the Scene view parameter. The Simulation 3D Actor block, named Room, creates an actor in the 3D environment. The block first creates an empty actor named Room, as specified by the Actor name parameter. The block then runs the Initialization script. In the Initialization script, use Actor as the handle to the actor object created by the Simulation 3D Actor block and World as the handle to the world object created by the Simulation 3D Scene Configuration block. The script builds a box shape for Actor using the createShape function to create a room in the 3D environment and set the properties of the room to visualize the custom lighting. The Initialization script then creates three actors using sim3d.Actor objects with box, sphere, and cone shapes. Set the translation of the actors to position them inside the room. Add the actors to World as child actors of Actor. The Initialization script finally creates a point light, spot light, and rectangular light using the sim3d.Light objects, positions the lights above the actors inside the room, and adds them to World as child actors of Actor. Transform properties of an actor are relative to its parent actor. Set the properties of the child actors for enhanced lighting effects.

Block parameter dialog box with parameters, actor name and initialization script.

Simulate the model and view the custom lighting in the Simulation 3D Viewer. You can visualize the reflections of each light type on the wall behind the actors.

sim("CreateLightUsingSimulink.slx");

An unlit room featuring a box on the left, a sphere in the center, and a cone on the right, each illuminated differently. The box by a point light, the sphere by a spotlight, and the cone by a rectangular light.

close_system("CreateLightUsingSimulink.slx");

See Also

| | | | |

Topics