Upload
lydung
View
242
Download
0
Embed Size (px)
Citation preview
Visualization and Scriptingd fin Second Life
Sariseelia SoreSenior Lecturer in Mathematics and Computer ScienceSenior Lecturer in Mathematics and Computer Science
Linden Scripting LanguageLSL
BasicsBasics
Behavior of ObjectsBehavior of Objects• Linden Scripting Language (LSL)• Scripts are attached to primitives• Build-in editor• External stand-alone editor (e.g. LSLEditor)
Linden Scripting Language
• Like C or Java• Like C or Java• About 35 ready made event handlers• Hundreds of built-in functions
LSL Portal: • LSL Portal: http://wiki.secondlife.com/wiki/LSL_Portal
Scripts p
• Object 1 Object 2j– Primitive 1:
• Script 1– State 1
Primitive 1:Script 1
State 1Event handler 1State 1
» Event handler 1» Event handler 2» Event handler 3
Event handler 1Event handler 2
Primitive 2:Script 1
– State 2» Event handler 3» Event handler 2
• Script 2
State 1Event handler 1
• Script 2– State 1
» Event handler 2– State 2
» Event handler 4
Events Trigger Event HandlersEvents Trigger Event Handlers
• Object 1• Object 1– Primitive 1:
• Script 1p– State 1
» touch_start()» Event handler 2
St t 2St t 2
triggers
–– State 2State 2»» touch_starttouch_start()()»» Event handler 2Event handler 2
• Script 2Script 2– State 1
» touch_start()» Event handler 2
St t 2– State 2» Event handler 4
Events Trigger Event Handlers
default
Primitive 1: Script1
{state_entry(){
llSay(0, "Hello, Avatar!");}}
touch_start(integer total_number){
llSay(0, " Please, dont touch");}}
…}state melted{
touch_start(integer total_number){
llSay(0, " I’m dying");}
}}
Exercise 1: The First Scriptp
1. Go to a land named IP 2011 and set it to be your 1. Go to a land named IP 2011 and set it to be your
home
2 Create a primitive and add your first script to it:2. Create a primitive and add your first script to it:
Make the primitive to respond to a touch so that
1 th fi t t h ill t t ti 1. the first touch will start a timer
(llSetTimerEvent(float sec) and timer()) showing
the avatar every second an increasing number starting the avatar every second an increasing number starting
from 1, and
2 the second touch will stop the timer2. the second touch will stop the timer
LSL Portal: http://wiki.secondlife.com/wiki/LSL PortalLSL Portal: http://wiki.secondlife.com/wiki/LSL_PortalTimer: http://wiki.secondlife.com/wiki/Timer
Finite State Machines
d l fstate
S1 • A model of behavior
S1default
composed of a finite number of
transitionA1: set color defaultAn: inform about exit
finite number of states, transitionsbetween those
S2between those states, and actions
blueA1: set color blueentry
ti exitAn: inform about exitaction action
Example: Defining StatesExample: Defining States
default {//contents of the default state////goes here
}}
state blue {//contents of state blue goes here
}
States in LSL
• A state is a set of event handlers, that is ,running and waiting for events
• All scripts must have a state named • All scripts must have a state named default, the state SL puts the script in only when it’s only when it s – first compiled and – whenever it’s resetwhenever it s reset
• States cannot have user functions or variables inside their immediate scope variables inside their immediate scope, only event definitions
Several States
• A script may have several states• A script may have several states– The default state must be defined before
all othersall others– Only one state per script can be active at
any one timey• The states are defined with the word
state (except for the default state)state (except for the default state)followed by the name of the state and the contents is enclosed in curly ybrackets
Changing Statesg g
C d f ll d b h • Command state followed by the name of the target state: gstate target_state;
1 Trigger state exit and clear the event 1. Trigger state_exit and clear the event queue
2 Change state to target state2. Change state to target state3. Trigger state_entry in the target state
vector color_default = <1.0, 1.0, 1.0>; // whitevector color_blue = <0.0, 0.0, 1.0>; // blue
default {state_entry() {
llSetColor(color default, ALL SIDES);SetCo o (co o _de au t, _S S);}touch_start(integer total_number) {
state blue; // changes the state to state blue}state_exit() {
llOwnerSay("state_exit() for default state");}}
}state blue {
state entry(){state_entry(){llSetColor(color_blue, ALL_SIDES);
}touch_start(integer total_number){_ _
state default; // changes the state to default state}state_exit() {
llO S (" t t it() f bl t t ")llOwnerSay("state_exit() for blue state");}
}
Data TypesData Types
LSL t b i d t t (i t • LSL supports basic data types (integer, float and string) and the following four:
1. key,2. list,3. vector, and4. rotation
Constants
• Hundreds of predefined • Hundreds of predefined constants: PI, TRUE, , ,ZERO_VECTOR, NULL_KEY, DEG TO RAD etcDEG_TO_RAD, etc.
• Not possible to define own constantsp–Variables can be used as pseudo-
constantsconstants
Some String Functionsg
string message = "add John 1234";llGetSubString(message,4,7) //"John"llStringLength(message) //13llSubStringIndex(message, " ") //3
See more functions: htt // iki dlif / iki/C t LSL F tihttp://wiki.secondlife.com/wiki/Category:LSL_Functions
KeyKey
A i id ifi h ll h i • A unique identifier that all the items in SL have
• Can be used to reference objects and agentsand agents
//Returns the key of the owner of the object//Returns the key of the owner of the objectkey owner = llGetOwner();
//Returns a key for the prim the script is attached to//Returns a key for the prim the script is attached tokey me = llGetKey();
List• Ordered set of values of other data types
(two dimensional lists NOT possible)(two dimensional lists NOT possible)• Created via comma-separated values
l d b b k t ([ ])enclosed by square brackets ([ ])• The values in a list can’t be changed
list lst = []; //Empty list
lst = ["apple", 7];
lst += [6.9, 11]; //lst is now ["apple", 7, 6.9, 11]
integer length llGetListLength(lst); //4integer length = llGetListLength(lst); //4
string s = llList2String(lst, 0); //s is "apple"
lst = llList2List(lst,1,2); //[7, 6.9]lst llList2List(lst,1,2); //[7, 6.9]
integer position = llListFindList(lst,[6.9]); //1
Vector
• Single unit of three floats: <x, y, z>• A vector can represent e.g. position and
colorvector v = ZERO_VECTOR;//Constant ZERO_VECTOR has the value <0.0, 0.0, 0.0>
v = llGetPos(); //Gets the object's position in the sim
v x = 45 6;v.x = 45.6;v.y = v.x + 7.0;//v is now <45.6, 52.6, 0.0>
vector red = <1.0, 0.0, 0.0>; //The components represent red, green, and blue (rgb)
Setting a New Positiong
//Move the object up 1m when someone touches it//Stay there for 2s and return to the origin
vector startPosition;
default {
touch_start(integer total_number) {
startPosition = llGetPos();
ll (ll () 0 0 1 )
+ 1m
llSetPos(llGetPos() + <0,0,1>);
llSleep(2.0);
llSetPos(startPosition);llSetPos(startPosition);}
}
RotationRotation
• Single unit of four floats: <x, y, z, s>Single unit of four floats: <x, y, z, s>– Representation of the mathematical
concept quaternionp q• Represents the orientation of an object
rotation r = ZERO_ROTATION;//Constant ZERO_ROTATION: <0.0, 0.0, 0.0, 1.0>
r = llGetRot();//Gets the object's rotation
r = llEuler2Rot(<0, 45 * DEG TO RAD, 0>);r llEuler2Rot(<0, 45 DEG_TO_RAD, 0>);//45 degrees around the y-axis
Rotation of an Objecti P iin Practice
1 D fi th l f t ti i d ( t )1. Define the angle of rotation in degrees (vector)2. Change it to radians
h3. Convert the vector to rotation4. Set the new orientation (rotation) value for the
objectobject
vector angleInDegrees = <45 0 0>;vector angleInDegrees = <45,0,0>; vector angleInRadians = angleInDegrees * DEG_TO_RAD; rotation rot_x45 = llEuler2Rot(angleInRadians); llSetRot(llGetRot() * rot_x45);
//////// OR ////////
llSetRot(llGetRot()*llEuler2Rot(DEG_TO_RAD*<45,0,0>));
Example: Rotating an Objectp g j//Rotate the object around z-axis when someone touches it//Rotate twice 360 degrees in segments of 15 degrees//Rotate twice 360 degrees in segments of 15 degrees
rotation rot_z15;default {{state_entry() {vector angleInDegrees = <0,0,15>; vector angleInRadians = angleInDegrees * DEG TO RAD;vector angleInRadians angleInDegrees DEG_TO_RAD; rot_z15 = llEuler2Rot(angleInRadians);
}touch start(integer total number){touch_start(integer total_number){integer i;for(i=1; i<49; i++) {llS tR t(llG tR t() * t 15)llSetRot(llGetRot() * rot_z15);
}llSay(0,"Rotation stopped");
}} (48 * 15°)
Creating Opening Doorsg p gThe prims in SL are rotated around their center The around their center. The doors should turn around their side. To achieve the desired result the door may be done
of two linked prims (the • of two linked prims (the actual door and “hinges” on the side, which holds ,the rotation script) or
• one can use the path cut property to cut away half property to cut away half of the prim.
Example: Doordoor(string position) {
if (position == "open") {llSetRot(llEuler2Rot(DEG TO RAD * <0 0 90>));llSetRot(llEuler2Rot(DEG_TO_RAD * <0,0,90>));
}else if (position == "close") {
llSetRot(llEuler2Rot(DEG TO RAD * <0 0 0>));llSetRot(llEuler2Rot(DEG_TO_RAD * <0,0,0>));}
}default {default {
touch_start(integer total_number){door("open");t t t tstate open_state;
}}t t t t {state open_state {
touch_start(integer total_number){door("close");t t d f ltstate default;
}}
Exercise 2: DoorExercise 2: Door
1 Get the house you build from the inventory1. Get the house you build from the inventory
2. Create a door with a doorknob to it
Th d h ll d l h i d k b i – The door shall open and close when its doorknob is
touched
U f diff i i f h d– Use states for different positions of the door
– If the door’s not closed with the touch event for five
d it h ll l t ti llseconds, it shall close automatically
• In this case the door informs the avatar who opened the
door that it’ll be closingdoor that it ll be closing,
e.g.: "Dear Ava Avatar, the door will close!"
Linden Scripting LanguageLSL
Interacting with SurroundingsInteracting with Surroundings
Communicatingg
”I’m a lonely snowman”Channel 0
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐”I’m a lonely snowman”
”Hello”
Channel 50Channel 50‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
”I like rock’n roll”llListen(50,…)
Channel ‐987 654 321
( , )
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐”Hi”
Talking to Channelsg
A channel may be any valid integerA channel may be any valid integerfrom -2,147,483,648 through 2,147,483,647
• llWhisper(channel, msg) – 10 metersp ( , g)• llSay(channel, msg) – 20 meters• llShout(channel msg) – 100 meters• llShout(channel, msg) – 100 meters• llRegionSay(channel, msg)– current sim
Listening to Channelsg
Enable listeningab e s e g• llListen(channel, name, id, msg)
i t h l h l t li t t– integer channel: channel to listen to
– string name: filter for prim/avatar name
– key id: filter for prim/avatar UUID
– string msg: filter for specific chat messagestring msg: filter for specific chat message
Event handler• listen(channel, name, id, msg)
Example: Talking Cubep g
12
Hello to you, Hello Tor Harbour
12
little cube You said Hello to you, little cubeHello to you tooHello to you too
Example: Talking Cubep g
default {default {
state_entry() {llListen(0,"","","");
}
listen(integer ch, string name, key id, string msg) {
integer i;
llSay(0, "Hello " + name + " You said " + msg);
i llS bSt i I d ( "H ll ")i = llSubStringIndex(msg, "Hello");
//returns -1, if pattern is not found
if (i >= 0){if (i >= 0){
llSay(0, "Hello to you too");}
}}}
Dialog BoxgInstead of typing, just
click one optionclick one option44
Channel x‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Friend
OwnerChannel 0
33
Owner ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐Tor Harbour: Hi cube!
Talking Cube:h f d
5511
33Great to have friends!
Talking Cube: Tor Harbour said: Hi cube! 22
Example: Dialog Box…p g
integer channel;integer channel;default {
state_entry() {//C t d h l ithi [500 1000]//Create random channel within range [500,1000]channel =(integer)(llFrand(1000.0-500.0)+501.0);llListen(0,"","","");( , , , )
}listen(integer ch, string name, key id, string msg) {
llOwnerSay(name + " said: " + msg);llOwnerSay(name + " said: " + msg);
//says msg to the owner only
list options = ["Enemy", "Friend", "Nobody"];list options [ Enemy , Friend , Nobody ];
llDialog(id, "You said " + msg, options, channel);
state dialog;g}
}
example continues…example continues
state dialog {state dialog {state_entry() {
llListen(channel,"","","");( , , , );}listen(integer ch, string name, key id, string msg) { {
if (msg == "Friend") llSay(0 "Great to have friends!");llSay(0, Great to have friends! ); state default;
}}
Instant Messaging andOpening URLs
• llInstantMessage(avatar_id, msg); Sends a message to an avatar specified –Sends a message to an avatar specified with the avatar_id
• llLoadURL(avatar_id, msg, url);–Displays a dialog box to the user offering to
load a web page using the default web p g gbrowser
default {
touch_start(integer num_detected){_ g _
key avatarKey = llDetectedKey(0);
llLoadURL(avatarKey, "LUAS Site",
"http://www.lamk.fi/mus/esittely/tarinat/melina.html");}
}}
touchtouch
Using Sensorsg
• Sensors are used to detect objects or avatarsSensors are used to detect objects or avatars• The shape of a sensor is a cone• A script can have only one sensor at a time• A script can have only one sensor at a time• Creating sensors
F i l f ti llS– For a single scan: function llSensor– For repetitive scan: function llSensorRepeat
Needs to be emo ed ith the f nction llS R• Needs to be removed with the function llSensorRemove
• Event handlersWanted found: sensor– Wanted found: sensor
– Wanted not found: no_sensor
Parameters for a Sensor• name: Avatar or object name
id b• id: Avatar or object ID– NULL_KEY is used for searching any key
• type: What to look for• type: What to look for– AGENT: avatars – ACTIVE: objects with active script or moving physical objectsj p g p y j– PASSIVE: objects which are not active– SCRIPTED: objects with active script
Di t h f t ( 96 0 ) • range: Distance how far to sensor (max: 96.0 m)
• arc: The angel (around the x-axis), in radians, to search (range: 0 0 to PI)search (range: 0.0 to PI)
• rate: In seconds, how often to repeat the search
llSensor("Something", NULL_KEY, PASSIVE, 10.0, PI);//Looking for things named Something that are passive//Looking for things named Something that are passive//and within 10 meters and pi radians
llS R t("" llG tO () AGENT 5 0 PI BY TWO 2 0)llSensorRepeat("", llGetOwner(), AGENT, 5.0, PI_BY_TWO, 2.0);//Looking for the owner within 5 meters and pi/2 radians//every two seconds
arc
xllDetectedName(0)
Note
xllDetectedName(0)
llDetectedName(1)
NoteThe angel is arc radians around the forward vector
Example: Sensoring Avatars
default {state entry() {state_entry() {llSensorRepeat("", NULL_KEY, AGENT, 3.0, PI, 8.0);//Range in meters, arc in radians, //repeat time in seconds//repeat time in seconds
}sensor(integer num_detected) {integer i;for (i = 0; i < num_detected; i++) {llInstantMessage(llGetOwner(), "Sensed avatar " +llDetectedName(i) + " at " +(string)llDetectedPos(i));
}}}no_sensor() {llOwnerSay("No avatars in range.");llOwnerSay( No avatars in range. );
}}
Moving Avatarsg
When an avatar sits on a prim, it moves along with the prim.
Elevator
movingdefaultstateenter
targetreached
changed(…)showdialog timer(…) move
elevator
listen(…)
new target set
Some Noticeson the Elevator
• When an avatar sits on an object, the changed(…) event handler is triggered
• To get the key of the avatar sitting on the object, use the function j ,llAvatarOnSitTarget(…)• If the prim lacks a sit target the function If the prim lacks a sit target the function
returns NULL_KEY
• The sit target for a prim is set with the • The sit target for a prim is set with the function llSitTarget(…)
Exercise 3:Getting on the Roof
1. Create a hot-air balloon next to your house
2. When an avatar comes close enough the hot-air 2. When an avatar comes close enough the hot air balloon he/she is shown a dialog box asking whether he/she wants to get up on the roof/ g p
3. If the avatar accepts the invitation she/he is asked to sit on the basket of the hot-air balloon which shall then move up on the roof
4. When the avatar stands up from the basket the 4. When the avatar stands up from the basket the basket will return back to its original place
5. If the owner comes close to the hot-air balloon, 5. If the owner comes close to the hot air balloon, it’ll tell him/her who’s sitting on it
Linden Scripting LanguageLSL
Creating ExperiencesCreating Experiences
Gestures of Avatars
ExampleControlling Gestures of AvatarsControlling Gestures of Avatars
Request permission
R i i i d
Start animation
Runtime permission granted
Start animation
Requesting Permissionsq gllRequestPermissions(key avatar, integer perm);
• Ask an avatar for permissions to run certain classes of functions
• Multiple permissions can be requested simultaneously by oring (using the bit-wise or operator |) the
i i t t t thpermission constants together• PERMISSION_TRIGGER_ANIMATION • PERMISSION_TAKE_CONTROLS• etc.
• If the specified avatar grants the requested permissions the run time permissions( )event permissions, the run_time_permissions(…)event handler will be called
Controlling Gestures of AvatarsControlling Gestures of Avatars
default {
touch_start(integer detected) {
llRequestPermissions(llDetectedKey(0)llRequestPermissions(llDetectedKey(0),
PERMISSION_TRIGGER_ANIMATION);
}}run_time_permissions(integer perm) {
if (perm & PERMISSION_TRIGGER_ANIMATION) {
llStartAnimation("dance5");}
}}
Redirect the Residents Key Commandsy
For example:I t d f ”M th t f d”Instead of: ”Move the avatar forward”
Let the script move the cube upward
ΔKey
pressMove forwardMove forward
ΔpressMove upMove up
The Process of Redirecting the Key Commands
Request permission
Runtime permission granted
Take controls
Runtime permission granted
ΔKey
Move forwardMove forwardlΔpress
Move upMove upA control event occurs
Redirecting Key CommandsRedirecting Key Commands
• Steps to take • Steps to take 1. llRequestPermissions(…) dialog
2. run_time_permissions(…) event
3. if granted llTakeControls(…)g ( )
4. control(…) event
If th t i itti bj t • If the avatar is sitting on an object, permissions are granted implicitly
ith t di lwithout a dialog
Capturing Key InputsCapturing Key Inputs
llTakeControls(integer controls,llTakeControls(integer controls, integer accept, integer pass_on);
• controls: which controls to take
• accept: determines whether input is passed to object i.e. control events are generated (boolean)
• pass on: determines whether input is p _ ppassed to avatar itself (boolean)
Example: Redirecting Key Commands …
vector startPosition;
default{default{
state_entry() {startPosition = llGetPos();
}
touch_start(integer detected) {llRequestPermissions(llDetectedKey(0)llRequestPermissions(llDetectedKey(0),
PERMISSION_TAKE_CONTROLS);}
ti i i (i t ) {run_time_permissions(integer perm) {// Triggered when the avatar responds to the dialogif (perm & PERMISSION_TAKE_CONTROLS) {llTakeControls(CONTROL_FWD|CONTROL_BACK,
TRUE, FALSE);}
}…
… example continuesp…// control: Triggered when change happens in user input// control: Triggered when change happens in user input// levels: controls that are currently pressed// edge: controls that have changed state
control(key avatar, integer levels, integer edges) {
vector position = llGetPos();
if (levels & edges & CONTROL_FWD) {// "move forward" control has been activated
if(position z < (startPosition z + 10 0)) {if(position.z < (startPosition.z + 10.0)) {llSetPos(llGetPos() + <0, 0, 1.0>);
}lelsellSetPos(startPosition);
}}
} // End of state default
Exercise 4:Steering the hot-air balloon1. Take the move up and down controls
(PgUp and PgDn) as well as the ( g p g )forward, backward, left and right controls (arrow keys) from the avatar controls (arrow keys) from the avatar sitting on the hot-air balloon and use h f h b llthem for moving the balloon
2. Make the avatar dance after standing 2. Make the avatar dance after standing up from the balloon
VehiclesVehicles
Defining a Vehicleg
• Linked set of primsLinked set of prims- The vehicle script resides in the root prim
• Physical object (SL physical rules affect it: • Physical object (SL physical rules affect it: material, weight, weather, …)
• Vehicle type (car boat airplane etc )• Vehicle type (car, boat, airplane, etc.)
default {default {
state_entry() {
llSetStatus(STATUS_PHYSICS, TRUE);_
llSetVehicleType(VEHICLE_TYPE_CAR);
}
}
Making a Vehicle Moveg
• A vehicle needs to have a linear motor. It’s defined with the following parameters:• VEHICLE_LINEAR_MOTOR_DIRECTION
• Velocity the linear motor tries to achieve (a vector)
• VEHICLE_LINEAR_MOTOR_TIMESCALEN b f d it t k th li t t hi • Number of seconds it takes the linear motor to achieve its full velocity (a float)
• VEHICLE LINEAR MOTOR DECAY TIMESCALEVEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE• Number of second it takes the linear motor to become
ineffective (a float)
Driving a Vehicle• An avatar sits on the vehicle• The control keys are redirected to the
root prim
Making a Vehicle TurnMaking a Vehicle Turn
• For turning vehicles have an angular motor • For turning, vehicles have an angular motor. It’s defined with the following parameters:
VEHICLE ANGULAR MOTOR DIRECTION• VEHICLE_ANGULAR_MOTOR_DIRECTION• Velocity the angular motor tries to achieve (a vector)
VEHICLE ANGULAR MOTOR TIMESCALE• VEHICLE_ANGULAR_MOTOR_TIMESCALE• Number of seconds it takes the angular motor to
achieve its full velocity (a float)achieve its full velocity (a float)
• VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALEN b f d it t k th l t t b • Number of second it takes the angular motor to become ineffective (a float)
Keeping a VehicleUpright
• The following parameters are used to keep the vehicle’s z-axis pointing upp g p• VEHICLE_VERTICAL_ATTRACTION_TIMESCALE
• Number of seconds it takes the vehicle to align its z-axis Number of seconds it takes the vehicle to align its z axis to the world z-axis (vertical)
• VEHICLE VERTICAL ATTRACTION EFFICIENCY_ _ _• Slider for stability of the vehicle to keep itself upright
• Values between 0.0 (wobbly) and 1.0 (firm as possible) ( y) ( p )
Setting up a Vehicleg p// setting the vehicle parameterssetupVehicle() {p () {
llSetStatus(STATUS_PHYSICS, TRUE);llSetVehicleType(VEHICLE_TYPE_CAR);
// The vehicle will get up to full speed in 1 second and decay after 2llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.0);llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 2.0);
// The angular motor will start almost instantly and decay quicklyllSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.1);llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.5);
// Very strong quick vertical attractorllS t hi l l t ( C C C O C C 0 95)llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.95);llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 0.75);
}
• There are a number of other parameters for vehicles to make them simulate the real life
• See:See:– http://wiki.secondlife.com/wiki/LlSetVehicleVectorParam – http://wiki.secondlife.com/wiki/LlSetVehicleFloatParam
Visual EffectsVisual Effects
ParticlesParticles• 2D floating images (not objects) emitted
from a primitivefrom a primitive• Can be used to simulate fireworks, smoke,
weather, and other effectsweather, and other effects• Each prim has only one particle emitter• A client-side effect• A primitive becomes a particle emitter,
when passing a list to the llP ti l S t f tillParticleSystem function
• The list is a series of name-value pairsParticles can be turned off by calling the • Particles can be turned off by calling the llParticleSystem with an empty list
System Behaviory
PSYS_PART_FLAGS_ _
• Various flags controlling the behavior of the particle system (may be oring together)
llParticleSystem([PSYS PART FLAGSPSYS_PART_FLAGS,
//Particles are moved by windPSYS_PART_WIND_MASK//P ti l lf lit ( l )//Particles are self-lit (glow)| PSYS_PART_EMISSIVE_MASK//Color and alpha transition from their START //settings to their END settings during the//particle's lifetime| PSYS_PART_INTERP_COLOR_MASK_ _ _ _
, …]);
System PresentationyPSYS_SRC_PATTERN• General emission pattern (only one value)
PSYS_SRC_PATTERN_DROP• Particles start at emitter with no velocity
PSYS_SRC_PATTERN_EXPLODEParticles explode from the emitter• Particles explode from the emitter
PSYS_SRC_PATTERN_ANGLE• Particles in a 2-dimensional circular section defined by Particles in a 2 dimensional circular section defined by PSYS_SRC_ANGLE_BEGIN and SYS_SRC_ANGLE_END
PSYS_SRC_PATTERN_ANGLE_CONE• Particles in a 3-dimensional spherical section defined by PSYS_SRC_ANGLE_BEGIN and SYS_SRC_ANGLE_END
Particle AngleParticle Angle
• The angle for the particles to be emitted is defined with parameters PSYS_SRC_ANGLE_BEGIN and PSYS SRC ANGLE ENDand PSYS_SRC_ANGLE_END
90
llParticleSystem([…PSYS_SRC_PATTERN,
°∏/4
PSYS_SRC_PATTERN_ANGLE,
PSYS_SRC_ANGLE_BEGIN, PI/4.0,
PSYS SRC ANGLE END DEG TO RAD*90PSYS_SRC_ANGLE_END, DEG_TO_RAD*90, …]);
Burst parametersBurst parameters
PSYS SRC BURST RATEPSYS_SRC_BURST_RATE• How often, in seconds, to emit particles
PSYS_SRC_BURST_PART_COUNT_ _ _ _• How many particles are emitted each burst
PSYS_SRC_BURST_SPEED_MIN andPSYS SRC BURST SPEED MAXPSYS_SRC_BURST_SPEED_MAX
• The range of initial speeds for particles (m/s)• Each particle is given an initial random speed in this p g p
rangePSYS_SRC_BURST_RADIUS
Di t f th t f th itt t hi h • Distance from the center of the emitter at which particles will be created
Example:Concentric Expanding Rings
llParticleSystem([
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE,
// Emit particles in a complete circlePSYS_SRC_ANGLE_BEGIN, 0.0,PSYS SRC ANGLE END, PI,PSYS_SRC_ANGLE_END, PI,
// Make all the particles spread out at the same speedPSYS_SRC_BURST_SPEED_MIN, 0.3,PSYS SRC BURST SPEED MAX 0 3PSYS_SRC_BURST_SPEED_MAX, 0.3,
// Start the ring 1 meter from the emitterPSYS SRC BURST RADIUS, 1.0,_ _ _ , ,
// Emit 50 particles every 3 secondsPSYS_SRC_BURST_PART_COUNT, 50,PSYS SRC BURST RATE 3 0PSYS_SRC_BURST_RATE, 3.0
]);
Particle Appearancepp
• The change from start to end values requires the PSYS_PART_INTERP_COLOR_MASKt h b tto have been set
• Initial and end color are set with PSYS_PART_START_COLOR and PSYS PART END COLOR_ _ _
• Initial and end transparency are set with PSYS PART START ALPHA and PSYS_PART_START_ALPHA and PSYS_PART_END_ALPHA
• Any texture can be used as a particle • Any texture can be used as a particle. The value is set with PSYS_SRC_TEXTURE
Example: Color Changing and Fading
llParticleSystem( [
// Turn on color interpolationPSYS PART FLAGS PSYS PART INTERP COLOR MASKPSYS_PART_FLAGS, PSYS_PART_INTERP_COLOR_MASK,
// Set the start color to white and //the end color to blue//the end color to bluePSYS_PART_START_COLOR, <1.0, 1.0, 1.0>,PSYS_PART_END_COLOR, <0.0, 0.0, 1.0>,
// Start at full opacity, fade to full transparencyPSYS_PART_START_ALPHA, 1.0,PSYS PART END ALPHA 0 0PSYS_PART_END_ALPHA, 0.0,
// The value is the UUID of the texturePSYS SRC TEXTURE "6ed3abd3 527a 856d 3771 2a04ea4c16e1"PSYS_SRC_TEXTURE, "6ed3abd3-527a-856d-3771-2a04ea4c16e1"
]);
Particle Size
The change from the start to the end value • The change from the start to the end value requires the PSYS_PART_INTERP_SCALE to have been setbeen set
• Initial and end size are set with PSYS START SCALE and PSYS END SCALEPSYS_START_SCALE and PSYS_END_SCALE
llParticleSystem( [// Turn on size interpolationPSYS_PART_FLAGS, PSYS_PART_INTERP_SCALE_MASK,
// Start out small, growPSYS_PART_START_SCALE, <0.25, 0.25, 0.0>,PSYS PART END SCALE, <2.0, 2.0, 0.0>PSYS_PART_END_SCALE, <2.0, 2.0, 0.0>
]);
Th k f Thank you for your tt ti !attention!
FL: Sariseelia SoreSL: Sasse ForzaneSL: Sasse Forzaneemail: [email protected]
Exercise 5:Simple Car
1. Create a simple car
See e.g. http://wiki secondlife com/wiki/Linden Vhttp://wiki.secondlife.com/wiki/Linden_Vehicle_Tutorial
2. The car shall emit gas when moving moving