Categories

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

How to make a particle kaleido-thingy

Here’s a simple object that has a fairly cool effect. This started as a test for one of the recent additions to LSL (Linden Scripting Language). I created the essential particle script using my Porgan by the fabled Jopsy Pendragon of Particle Lab fame. The Porgan is an intuitive real-time development tool for making particle effects, and is much simpler than trying to edit script parameters, though I do usually end up tweaking the scripts. I did, in fact edit the params pretty heavily on this, primarily to introduce random changes.

First point I want to make is that there are a number of new functions in LSL, that affect object links. They’re all basically the same as the old functions except that you can now use one script in (say) the root prim to do the same effect in one or more child prims. These new functions are a sort of expansion of the very useful llSetLinkPrimitiveParams function. For example, in order to set all or other prim alphas with the params function, you would have to use the PRIM_COLOR flag:

llSetLinkPrimitiveParams(LINK_SET, 
[PRIM_COLOR, integer face, vector color, float alpha ]);

But if you didn’t want to set the color, you’d have to use llSetAlpha(float x, integer face) in each prim and use a link_message or some such to communicate (or set object alpha manually in Edit, of course).

With the new functions you can place a script in any prim and then specify which prim(s) in the object for it to affect. Syntax is like llSetLinkPrimitiveParams, but with only one parameter, so in this case you would use llSetLinkAlpha(LINK_SET, float alpha, integer face). You can, of course, specify all the usual link variations (LINK_THIS, LINK_ALL_OTHERS, an individual link number, etc,).

So for this project I simply used the llSetLinkParticleSystem function. The huge advantage this has is that you can create a single script particle effect that will be emitted by all the child prims at once, in perfect sync. In this case I created a central prim and an array of 8 orbiting prims. The central prim has a llTargetOmega rotator, and 5 random number generators: an event timer, the 3 floats for the color vector, and a particle acceleration randomizer that causes the rendered particles to rise or fall slowly. The rotation direction in llTargetOmega uses the random x float from the color randomizer (so in effect,  llFrand(1)-0.5 = some number between 0.5 and minus 0.5 on the spinrate).

While this is in itself a cool gadget, I figured it would be much cooler to have 3 sets in concentric orbits. I just drag-copied the original and made 2 copies, each larger than the last. So this thing has 27 prims altogether (9 x 3) including 24 particle emitters all working with only 3 total scripts. Woot!

The script:

//--------------
//Particle Kaleidoscope by FreeWee Ling
//Licensed under a Creative Commons Attribution 3.0 Unported License.
//---- (use as you want, but give credit) ----------
//Global variables to be set later:
float x;
float y;
float z;
float accel;

default {
    state_entry() {
        llSetTimerEvent(5);//Start timer
        llLinkParticleSystem(LINK_SET,[]);//Turn off particles that may be running.
        }
timer(){
//Set random vector components
    x=llFrand(1);
    y=llFrand(1);
    z=llFrand(1);
    accel=llFrand(1)-0.5; //Particles rise or fall slowly (optional)
    llTargetOmega(<0,1,0>,x-.5,1);//Spinrate between 0.5 and -0.5
//The particles:
    //Starts the particles on all linked prims, 
    //but not on the one with the script:
    llLinkParticleSystem(LINK_ALL_OTHERS,[ 
            // texture parameters:
    PSYS_SRC_TEXTURE , "",
    PSYS_PART_START_SCALE , <0.3,4.0,0.00>, 
    PSYS_PART_END_SCALE , <0.1,1.0,0.00>,
    PSYS_PART_START_COLOR , <x,y,z>,//Here are the random color vectors
    PSYS_PART_END_COLOR , <x,y,z>,
    PSYS_PART_START_ALPHA , (float)1.0, 
    PSYS_PART_END_ALPHA , (float)0.0,
                    // production parameters:
    PSYS_SRC_BURST_PART_COUNT , 1,
    PSYS_SRC_BURST_RATE , (float)0.05,
    PSYS_PART_MAX_AGE , (float)10.0,
    PSYS_SRC_MAX_AGE , (float)0.00,
                    // placement parameters:
    PSYS_SRC_PATTERN , 8,
    PSYS_SRC_BURST_SPEED_MIN , (float)z, //Using color floats for motion.
    PSYS_SRC_BURST_SPEED_MAX , (float)y,
    PSYS_SRC_BURST_RADIUS , (float)3.50,
                    // placement parameters (for angles only):
    PSYS_SRC_ANGLE_BEGIN , (float)3.04,
    PSYS_SRC_ANGLE_END , (float)3.04,
    PSYS_SRC_OMEGA , <0.00,0.00,0.00>,
                    // after-effects & influences:
    PSYS_SRC_ACCEL , <0.00,0.00,accel>, //z axis float causes particles to rise or fall
    PSYS_SRC_TARGET_KEY , (key)"",
    PSYS_PART_FLAGS , ( 0 // texture & influence options:
                           | PSYS_PART_INTERP_COLOR_MASK
                           | PSYS_PART_INTERP_SCALE_MASK
                        // | PSYS_PART_BOUNCE_MASK
                        // | PSYS_PART_WIND_MASK
                        // | PSYS_PART_FOLLOW_SRC_MASK
                         | PSYS_PART_FOLLOW_VELOCITY_MASK
                   //      | PSYS_PART_TARGET_POS_MASK
                        // | PSYS_PART_TARGET_LINEAR_MASK
                           | PSYS_PART_EMISSIVE_MASK
                    )] );
 llSetTimerEvent(llFrand(3)+5);//Reset the timer to between 3 and 8 seconds
        }
    }

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  

Categories

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.