Cybertown Mall Cybertown Revival

Tutorial 7 of 10

FINISHING TOUCHES - Lights, Text

CREATOR NOTEby Morning.star, published with permission

LIGHTS

Apart from DirectionalLights built into the worlds your objects will be used in, there are 2 other types of lights - the PointLight ( which can be used in Mall objects ), & the SpotLight ( which should only be used judiciously in Mall objects ).

Typically, a world has adequate lighting already & there is no need to add additional lights except under special circumstances. In other words, don't put them in just for the sake of having them. Too much light present in a world can cause the world & objects placed in it to wash out. My 'Art Studio 4' desk here has one of these lights built into the lamp. Look closely to see the change to the surrounding club walls when you turn the light on.

Lights are DEFd & are usually used with Script coding :

The following is an example of PointLight coding:

Transform { translation 4.32 0.325 -4 children [
Shape { appearance Appearance {
material Material { diffuseColor 0.2 0.2 0.2 }}
geometry Cone { height 0.1 bottomRadius 0.2 side TRUE bottom FALSE }}
]}
DEF PL1 PointLight {
location 0 0.3 0 intensity 0.4 on FALSE radius 5 color 0.6 0.8 0.7 },
DEF TS1 TouchSensor {},
DEF PLS1 Script {
eventIn SFBool touched
field SFBool lit FALSE
eventOut SFBool light_changed
url "javascript:
function touched(value) {
if (value) {
if (lit) {
lit = false;
light_changed = false;
} else {
lit = true;
light_changed = true;
}}
}"
}
]}

ROUTE TS1.isActive TO PLS1.touched ROUTE PLS1.light_changed TO PL1.set_on

QUICK TIP : Bear in mind that visibility sensors are not permitted in CTR, just touch & prox sensors.

  • * * * * * * * * * * * * * * * * * * *

The coding & scripting for a SpotLight is the same except that the attributes are a little different :

PointLight Attributes :

location - like translation for an object intensity - 0 to 1 on - typically set at FALSE & turned on in the animation coding by the TouchSensor, ProxSensor radius - how far afield the light will be cast in meters color - you can add RBG color coding or not, if you leave color out the light will be a default white color

SpotLight Attributes :

Spotlights have all of the above attributes plus 2 others :

direction - points the SpotLight to the left/right, front/back, up & down using plus & minus numbers cutOffAngle - fans out in a cone-shape, like a flower unfolding but either upright, upsidedown or held sideways as defined in direction, a narrower cutOffAngle, for example 0.785, yields a narrow beam of light; a wider cutOffAngle, for example 3.14, gives a broader beam of light

QUICK TIPS

  1. Remember, as with all Script coding, the Script part remains the same as in the example above except that you can change the DEF name of the Script if you want which you should do each time you use it.
  2. Be careful when using color with lights - be subtle about the shades used except in special thematic circumstances.
  • * * * * * * * * * * * * * * * * * * *

ANIMATING MATERIAL ATTRIBUTES

That's not the only method of creating light - sometimes the ILLUSION of light is just what you need. You can achieve this by animating material instead & adjusting the intensity of diffuseColor & emissiveColor as in the example below. My 'Teak Tower Lamp' uses this technique. Check it out in the club - click it on; it turns off by itself. Here's the coding :

Group { children [
Transform { translation 0 0 0 children [
Shape { appearance Appearance {
material DEF Mat Material { diffuseColor 0.5 0.5 0.5 specularColor 0.4 0.4 0.4 emissiveColor 0.3 0.3 0.3 transparency 0.4 }}
geometry Sphere { radius 0.5 }}
]}
DEF TS TouchSensor {},
DEF Clock TimeSensor { cycleInterval 10 loop FALSE },
DEF CI ColorInterpolator {
key [ 0, 0.001, 0.999, 1, ]
keyValue [ 0.3 0.3 0.3, 1 1 1, 1 1 1, 0.3 0.3 0.3, ]},
ROUTE TS.touchTime TO Clock.set_startTime
ROUTE Clock.fraction_changed TO CI.set_fraction
ROUTE CI.value_changed TO Mat.set_emissiveColor
]}
  • * * * * * * * * * * * * * * * * * * *

VRML TEXT

Text is a geometry. You can use material on it, or apply texture as well as manipulate it using translation, rotation, & scale in the same way as those apply to any object :

Here's an example of text coding:

Transform { translation 0 0 0 children [
Shape { appearance Appearance {
material Material { diffuseColor 0.3 0.3 0.3 }}
texture ImageTexture { url "textmat.jpg" }}
geometry Text { string [
"Mary had a little lamb",
"Its fleece was white as snow", ]
fontStyle FontStyle {
family "SERIF" # or "SANS" or "TYPEWRITER"
style "PLAIN" # plain is the default, or you can use "BOLD" or "ITALIC" or "BOLDITALIC"
size 0.2 # in meters
horizontal TRUE # the default is TRUE ... FALSE aligns text vertically
leftToRight TRUE # or FALSE
topToBottom TRUE # or FALSE
justify BEGIN # or MIDDLE or END
spacing 1 } # for every line ... a 2 here means double-spaced etc
maxExtent X # in meters, the width of a line
length [ 10, 10, ]}} # in meters, useful in defining the length of each line where you have more than 1 line
]}

The only attribute necessary for you to define is size, all of the rest ( family, style, horizontal, leftToRight, topToBottom, justify, spacing, maxExtent & length ) can be left out unless you wish to define any of them as something other than the default. In the example above, I have coded 2 lines of text. If you only have 1 line, & you are defining length, you would have only 1 number in the length attribute instead of 2.

WARNING : text is a GEOMETRY which means that processors are going to be processing & rendering each & every plane involved in each letter - therefore - be careful how much text you use because it can produce significant lag for some users ! Turn on the computer on my 'Art Studio 4' desk in the club. The login stuff is text animated with a ScalarInterpolator to appear. Text is an object so it behaves the way any other object does when animated.

Back to top

Written by Morning.star, reproduced unedited and published with her permission. Eleven documents. Morning.star has written many more and they will be added over time; this is not the complete set and does not claim to be.