Virtools2

advertisement

Virtools2: materials, textures, lights, interaction, shortcuts, parameter operations, hierarchies, cameras

1) Materials: Bring in a simple .nmo of an object. There are two ways to change/place the material on the object

(and you should try both of them). You can modify the existing material by selecting it. Or you can add a new material on the left side third row down in the “add” group and then, in the Level view, drag the material onto the object (the outline will turn yellow). Notice that objects have meshes and it is the meshes that have materials. You will see this sequence if you look at the various setups. If you open a material setup notice the options you will have. You can set the ambient color as well as the diffuse and specular. You will not notice these changes unless you have a light in your world. However, you can set the emissive property and immediately notice a change. Notice that materials may be shared by different objects. The default mode is opaque (as opposed to transparent) and both-sided is not checked. This means that if you have a cylinder, for example, you could walk all around the cylinder and see it; but if you were inside the cylinder you would not see it.

2) Texture Mapping. Bring in an object (perhaps a box) and a texture. The texture can be placed directly onto the object (in which case it will be part of the material) or you can map it to the material in the material’s set-up.

Hint: the compound numbers texture is a pretty good one that enables you to see different mappings. Recall that textures get mapped to materials (in the material set-up) and materials get mapped to meshes. Set up a script to use the different mappings to see how textures are placed. For example, use a Spherical Mapping BB on the box to see what happens; try changing the UV tile numbers to see what happens. You can play with a lot of the other texture building blocks also. Notice the mip levels and how they can be set automatically.

3) Lights, level setup: In order to see the diffuse and specular components of your object you will need to add a light. This can be done from the “add” group (it’s the second one in the top row). Lights may be point, spot or directional. Point lights are like light bulbs: they shine in all directions. Spotlights are much as the name implies and have a cone of illumination. Directional lights are like the sun, they shine in a certain direction, but as if from far away, and then illuminate objects equally. Try creating one or more lights and moving them around (you can do this either from the interface panel or from the setup of the light by adjusting the numbers for the position

(remember to IC when you have your preferred position). Try out some of the settings for different kinds of lights. You can also choose to see your lights or not (this can be set under general preferences at the top of the screen (looks like a circle). Lights can also move dynamically. So set up a composition with several objects and at least one light. Try setting up a script that moves the light and thus shows different illuminations on your objects.

Note: In order to set up ambient lighting for the entire scene, go to the Level (in Level Manager) and right click on it and get to the Setup. There you can set ambient lighting, as well as fog and other attributes such as background color or a background image.

4) Interaction and key presses, adding input parameters: Notice that there are many building blocks that apply to materials. Try out some of these (under Material-Textures/Basic): for example, Set Diffuse. Now add some interactivity by letting the user have some choice. Bring in the building block Key Event, choose a particular key

(say ‘b’) and then connect that building block to the Set Diffuse building block to change the material’s diffuse setting to blue. You could set up these building blocks for each choice, but a more efficient way to do it would be to use the Switch on Key building block. For a bit of variety, try creating a Level Script and adding this building block. There are two pIn parameters (across the top) and you can set each of them to a different key. The bOut’s

(on the right) correspond to each of these choices; set up two different Set Diffuse building blocks to correspond to each of them and notice that you need to also set the Target Parameter for them (this is the difference between adding this building block to a script for a specific material and adding it to the Level). So now you can change different materials. The Switch Key building block also has the ability to add as many input parameter

(hence key choices) as you wish. Right click on the building block and choose Construct-> Add behavior Output.

This will cause an additional choice to appear (both as an input parameter and as the corresponding behavior output. You can add as many of these as you wish.

5) Shortcuts across scripts and parameter operations: We saw in the first lab an example of using shortcuts to see output. Shortcuts can also be used instead of links and can also be used to move variables across script lines

(which links can not do). Create two objects in different places. Create a script to rotate Obj1 and a script to

1

rotate Obj2. Copy the angle parameter of the Rotate BB for Obj1 (it’s the rectangle above the triangle). Go to the script for Obj2 and use the Paste as Shortcut command. Now make a link from the angle parameter (it’s the second from the left top) in the Rotate BB of Obj2 to this shortcut (it will turn green as usual). TIP: you must connect FROM the parameter TO the shortcut – Virtools won’t let you go the other way around. Run the scripts and notice that if you change the angle for Obj1 then it will automatically change for Obj2. Once this is running, modify the angle for Obj2 to be twice that of Obj1. You can do this by creating a parameter operation: use the context menu to create a parameter operation (Add Parameter Operation). Parameter operations created in this way are free-standing and evaluated when needed; another alternative (which will also have bIn and bOut) is with the Op BB. Parameter operations have two inputs; set the type of these input(s) and then choose the operation you wish to perform (in this case multiplication). You can use the locks to limit choices. Set the other input parameter to a constant (for example, 2). Use the angle parameter shortcut (from Obj1) as one of the inputs. Link the output of the multiplication operation to the input angle parameter for the Rotate of Obj2.

6) Hierarchies: Bring in an object (or modify the last step) and set up keyboard controls (Switch on Key) to rotate and translate it according to arrow presses- ie put in the ability to “drive” the object (careful about your referentials). Bring in a second object. Open the Hierarchy Manager (under the Editor menu) and make this second object a child of the first (drag it). Check your Rotate and Translate BB to make sure the hierarchy box is checked and now move the first and see the second come along with it. You could also bring in a third object and make it a child of the second, etc.

7) Cameras: Create a camera and play around with some of the options in its setup. Notice that you can select the near and far clipping plane. Try changing from perspective to orthogonal. You should also experiment with the viewing angle (up to 180 degrees). Add the camera and a script to your previous exercise to make the camera follow the object. Use the Look At BB from 3D Transformations>Constraint (you will need to loop it back to itself to have it keep following). The higher the % for following, the closer it will follow. To see the full effects of this you might want a third object in your world that stays stationary.

8) More cameras: Set up key presses to “drive” an object by using a Switch on Key BB (see step 4) that connects to translations and rotations. Then set a camera to look at it. Call the camera that looks at the object while you are driving it the Looking Camera. Now we’ll create a camera that follows the object as your drive it. Create a second camera (call it Following Camera) and place it behind your object and oriented in the same direction. Be sure to set the initial conditions for this camera. Set your Following Camera to be a child of your object. Now when you drive the object, the camera should stay behind it. You may have to adjust your distances and orientations so that this happens. Notice what happens when you turn the hierarchy option off the translate and rotate BB’s for your object. You may want to put the reference grids in the player mode (under General references in the top tab). When all this is working, put in a level script that switches from camera to camera: link a Switch on Key BB to a Parameter Selector BB (according to the bIn slot it chooses the corresponding pIn to send to the pOut – in Logics>Streaming- notice the V in the lower left corner); right-click the output parameter and edit it to be a camera (notice the pIns change); edit the input parameters to be the two cameras; link the output parameter to the input parameter of the Set As Active Camera BB (in Cameras>Montage).

2

Download