Saturday, March 10, 2007

Day 167: Creating Particle Effects Part 2

In Creating Particle Effects Part 1, we talked about the Particle Script and how to tweak some of its settings to make fire and party effects.

In this part of the tutorial series, we are going to create 2 watery effects: a shower and fog/smoke (hey, fog is made of water :P).

So dig up that "Particle Script - Candle Flame" you have been working with in Part 1, or stop by Sirena Hair & Fashion to pick up a free copy in the Particle Scripts folder.

BTW, if you dont want to actually build these particle gadgets but want to see what they do, you can pick them up in the new Particle Scripts folder from Sirena Hair & Fasion.


1. Cold Shower



We are going to make a cold shower attachment. Its one of those magical things that can only happen in Second Life :P Its a shower head positioned about 0.5M directly in front of your avatar and 1M above your head. It will emit a gentle spray of cold water particles on someone directly in front of you...say, a dance partner?

OK, this borders on griefing :P Its suppose to be funny. But if the person taking the shower does not appreciate the particle effects (they probably wont), please Detach it :)

This did seem like an interesting way to demonstrate water effects and a different pattern (PSYS_SRC_PATTERN_ANGLE_CONE). What? Dont you believe me? :P

OK, lets get building...



Since the object is to demonstrate the water particle effects, we are going to build a simple showerhead. Feel free to jazz it up with texture (to simulate the holes) and other features later (like knobs, etc).

Rez a Cylinder on the ground. Go to the General tab, and change the Name to "Showerhead".

Enter the following dimensions:

     Size X: 0.200
     Size Y: 0.200
     Size Z: 0.100

     Rotation X: 180.00

     Taper X: -0.50 (Note this is a negative value)
     Taper Y: -0.50 (Note this is a negative value)

Go to the Texture tab. Click on the square above "Texture". This will open the Pick:Texture window. Click on the Blank button and the Select button.

Click on the dropdown for "Shininess" and select "High".

Find the "Particle Script - Candle Flame" script in your Inventory (or the copy you got at Sirena Hair & Fashion). Right-click on the "Particle Script - Candle Flame" script and select "Copy". Right-click again on the "Particle Script - Candle Flame" script and select "Paste". This will create a copy of the script.

Right-click on one of the "Particle Script - Candle Flame" scripts and select "Rename". Change the name to "Particle Script - Shower".



Double-click on "Particle Script - Shower" to open and edit it.













Apply the following changes to the script:

     integer pattern = PSYS_SRC_PATTERN_ANGLE_CONE;

     float age = 2.0;
     float maxSpeed = 2.0;
     float minSpeed = 1.0;

     float startAlpha = 1;
     float endAlpha = 1;
     vector startColor = <1,1,1>;
     vector endColor = <1,1,1>;
     vector startSize = <0.02,0.1,0.02>;
     vector endSize = <0.04,0.1,0.04>;
     vector push = <0,0,0>;

     float rate = 0.2;
     float radius = 0.01;
     integer count = 50;
     float beginAngle = 0.2; // This is a NEW setting
     float endAngle = 0; // This is a NEW setting

Now scroll down to the main body of the script, and add "PSYS_SRC_ANGLE_BEGIN" and "PSYS_SRC_ANGLE_END" to llParticleSystem:

     llParticleSystem([ PSYS_PART_MAX_AGE,age,
       PSYS_PART_FLAGS,flags,
       PSYS_PART_START_COLOR, startColor,
       PSYS_PART_END_COLOR, endColor,
       PSYS_PART_START_SCALE,startSize,
       PSYS_PART_END_SCALE,endSize,
       PSYS_SRC_PATTERN, pattern,
       PSYS_SRC_BURST_RATE,rate,
       PSYS_SRC_ACCEL, push,
       PSYS_SRC_BURST_PART_COUNT,count,
       PSYS_SRC_BURST_RADIUS,radius,
       PSYS_SRC_BURST_SPEED_MIN,minSpeed,
       PSYS_SRC_BURST_SPEED_MAX,maxSpeed,
       PSYS_SRC_TARGET_KEY,target,
       PSYS_SRC_INNERANGLE,innerAngle,
       PSYS_SRC_OUTERANGLE,outerAngle,
       PSYS_SRC_ANGLE_BEGIN,beginAngle,
       PSYS_SRC_ANGLE_END,endAngle,

       PSYS_SRC_OMEGA, omega,
       PSYS_SRC_MAX_AGE, life,
       PSYS_SRC_TEXTURE, texture,
       PSYS_PART_START_ALPHA, startAlpha,
       PSYS_PART_END_ALPHA, endAlpha
       ]);

Click on the "Save" button to save your changes and close the script window.

Right-click on the Showerhead and select Edit from the Pie Menu.

Select the Contents tab. Drag-and-drop the "Particle Script - Shower" script from your Inventory into the Contents tab of the Showerhead.



Watch the water flow! :)

Right-click on the Showerhead and select "Take".

Lastly, we need to position the Showerhead.

Find the Showerhead in your Inventory (should be in the Objects folder). Right-click on the Showerhead, select "Attach To>", and "Mouth".



The Showerhead will be facing the wrong way at first (No laughing...totally not funny!). Right-click on the Showerhead and select Edit. Enter these settings:



     Rotation X: 180.00

Lastly, use the Red and Blue arrows to position the Showerhead about 0.5M in front of you and 1M above your head. The display at the top of your screen should read about: X:0.500 Y:0.000 Z:1.000.



That's it! An instant Second Life cold shower :)

By the way, since the Showerhead is attached to your head, the water may spray all over, depending on which way you are looking. You can move it to a different attachment point, such as Chest/Spine or Stomach/Pelvis. But I generally like to save these attachment points for clothing :)


2. How Does the Cold Shower Work?

Well, really cold water makes the guy rethink....oh, you mean the script? :P

The Showerhead uses a new pattern called Angle Cone. This enables you to create a spray of particles, like water in the shower.

Angle Cone uses 2 new settings in the new version of SL client: PSYS_SRC_ANGLE_BEGIN (or beginAngle), and PSYS_SRC_ANGLE_END (or endAngle). Thats why you had to add these 2 new settings to the llParticleSystem. These 2 new settings are apparently easier ways to specify the size of the cone.

As to what settings to use for these 2 settings, I have to admit: I totally cheated...



I went to the Particle Laboratory to figure out the Angle Cone thing. They have a really cool display right here that lets you try different Angle Cone settings. It looks just about right with beginAngle = 0.2 and endAngle = 0. I will pay attention in Math class in my next life :P



Also, the Particle Laboratory has a really nice display explaining the rate at which you should produce particles. Most SL clients will show only about 4000 particles, total (for all avatars in the area). This is controled by the Edit/Preferences.../Adv. Graphics/Max. Particle Count setting on each individual computer. Actually, my computer is set to 1500 to keep lag to a minimum. So if you put out too many particles, I cant see it!

The Age, Rate, and Count settings affect the number of particles used by a particular particle emitter. In the case of the Showerhead, Age = 2 (seconds), Rate = 0.2 (seconds between each burst of particles), and Count = 50 (particles per burst). The Particle Laboratory provides this nice formula that even I understand :)

     ( Age / Rate ) * Count

The Showerhead will use 500 particles by itself. So be sure to keep an eye on the particle count when you are creating particle effects!


3. Smokey Feet



Ever seen other avatars leave a trail of footprints behind them as they walk? These footprints are particle effects. In most cases, they use textures, which we will discuss in the next parts of this tutorial series.

We are going to to make a simpler version of footprints using particle fog/smoke. You can tweak the fog/smoke effect for many other uses, including effects smoke for a dance floor, from a fire, or purely decorative (like from a fountain).

We are going to make a transparent prim as the particle emitter. We will attach one of these prims to the Left and Right Lower Legs.



Rez a Sphere on the ground. Go to the General tab, and change the Name to "Smokey Feet (L)".






Enter the following dimensions:

     Size X: 0.050
     Size Y: 0.200
     Size Z: 0.200

     Rotation Y: 90.00

Go to the Texture tab. Click on the square above "Texture". This will open the Pick:Texture window. Click on the Blank button and the Select button.

Click on the square above "Color". This will open the Color Picker window. Select the bright red square on the bottom row and click the "Select" button.

Find the "Particle Script - Shower" script in your Inventory. Right-click on the "Particle Script - Shower" script and select "Copy". Right-click again on the "Particle Script - Shower" script and select "Paste". This will create a copy of the script.

Right-click on one of the "Particle Script - Shower" scripts and select "Rename". Change the name to "Particle Script - Smokey Feet".

Double-click on "Particle Script - Smokey Feet" to open and edit it.

Apply the following changes to the script:

     integer pattern = PSYS_SRC_PATTERN_ANGLE;

     float age = 5.0;
     float maxSpeed = 0.01;
     float minSpeed = 0.01;

     float startAlpha = 1;
     float endAlpha = 0;
     vector startColor = <1,1,1>;
     vector endColor = <1,1,1>;
     vector startSize = <0.1,0.2,0.1>;
     vector endSize = <0.3,0.5,0.3>;
     vector push = <0,0,0>;

     float rate = 0.02;
     float radius = 0.03;
     integer count = 1;
     float beginAngle = 0;
     float endAngle = PI;

Now here comes the tricky part. We need to add the ability to make this prim transparent via Chat commands. So we need to replace a section of the existing script.

Look for the following at the bottom of the script:

     default
     {
          state_entry()
          {
               updateParticles();
          }
     }

Replace the entire section with this:

     integer channel = 22;

     default
     {
          state_entry()
          {
               updateParticles();
               llListen(channel, "", llGetOwner(), "");
          }
     
          listen(integer channel, string name, key id, string message)
          {
               if (message == "smoke hide")
               {
                    llSetLinkAlpha( LINK_SET, 0, ALL_SIDES );
                    llInstantMessage( llGetOwner(), "Smokey Feet hidden." );
               } else if (message == "smoke show") {
                    llSetLinkAlpha( LINK_SET, 1, ALL_SIDES );
                    llInstantMessage( llGetOwner(), "Smokey Feet shown." );
               }
          }
     }

Click on the "Save" button to save your changes and close the script window.

Right-click on the "Smokey Feet (L)" and select Edit from the Pie Menu.

Select the Contents tab. Drag-and-drop the "Particle Script - Smokey Feet" script from your Inventory into the Contents tab of the "Smokey Feet (L)".



The smoke should start flowing!

Right-click on the "Smokey Feet (L)" and select "Take".

Lastly, we need to position the "Smokey Feet (L)".

Find the "Smokey Feet (L)" in your Inventory (should be in the Objects folder). Right-click on the "Smokey Feet (L)", select "Attach To>", and "Left Lower Leg".

Right-click on the "Smokey Feet (L)" on your leg and select Edit. Enter these settings:

     Rotation Y: 90.00



Lastly, use the Blue arrow to position the "Smokey Feet (L)" until the smoke goes around your feet. The display at the top of your screen should read about:

     X:0.000 Y:0.000 Z:-0.340.

Right-click on "Smokey Feet (L)" and select "Detach" from the Pie Menu.

Now, we need to make a copy of "Smokey Feet (L)" and attach it to the Right Lower Leg.

Look for "Smokey Feet (L)" in your Inventory. Right-click on "Smokey Feet (L)" and select "Copy". Right-click on "Smokey Feet (L)" and select "Paste". This will make a copy of "Smokey Feet (L)".

Right-click on one of the "Smokey Feet (L)" and select "Rename". Change the name to "Smokey Feet (R)".

Right-click on "Smokey Feet (R)", select "Attach To >", and "Right Lower Leg".

Right-click on the "Smokey Feet (R)" on your leg and select Edit. Enter these settings:

     Rotation Y: 90.00

You should not have to re-position "Smokey Feet (R)"

Right-click on "Smokey Feet (R)" and select "Detach" from the Pie Menu.



Now that both Smokey Feet prims are in position, we need to make them invisible. Go ahead and Wear both "Smokey Feet (L)" and "Smokey Feet (R)".



Say this command in Chat: "/22 smoke hide". *Poof* the emitter is transparent, and all you see are the smokey footprints! :)


4. How Did Our Feet Start Smoking?

Smokey Feet use yet another pattern called Angle. Unlike a cone, Angle sprays the particles like a flat sheet or fan from the emitter. You can, of course, control the angle of the spray. Again, the angle uses the 2 new settings we added: PSYS_SRC_ANGLE_BEGIN (or beginAngle), and PSYS_SRC_ANGLE_END (or endAngle).

So guess how I figured out that beginAngle = 0 and endAngle = PI? Yep, I cheated and went to the Particle Laboratory. :)

As for the section of the script we replace at the bottom, that is a generic Chat script used to hide prims by setting its Alpha to 0 (thus making it completely transparent). You hide the prims by saying "/22 smoke hide". You can show the prims again by saying "/22 smoke show". You can, of course, change the channel from 22 to whatever you like.

Have fun with these new particle gadgets :)

In Part 3 of this particle tutorial, we will talk about creating particles that use textures.




numly esn 22136-071006-138497-92

© 2007 All Rights Reserved.

7 comments:

Anonymous said...

Awesome info...
I've always wondered how to do crap like this.
>>;
Scripts confuse the bejeesus out of me.

Trouble Houston said...

Combining smoke and the cold shower, maybe you could make a warm shower. heheh.

;o)

Tr

Anonymous said...

Natalia, you are a genius, both your blog and tutorials are the best I ever read; please do not stop and .... never delete the blog, at least not before I copied all the tuts ;-)

Jackson Racer said...

*cold shower makes a guy rethink* humm yeah, it does :D Nice job! I'm making some condos lol I think the shower feature might be a fun addition.

SLNatalia said...

Dear Anonymous, scripts are over my head too...the best I can do is cut and paste between scripts after weeks of scripting classes :P Thankfully, particles dont *really* need scripting, just changing numbers. I can do that!

Trouble, heehee you can always add a temperature knob to the showerhead for the warm shower :)

Dear Anonymous, thank you very much! Im just writing down what Ive learned from other places.

I dont plan on deleting the blog, but Blogger might decide to do that for me :P I always wondered what might happen if it all went away!

Jackson, lol I was just kidding :P

There are some shower animations you can buy inworld. You should also be able to make a mounted showerhead turn on and off by touching it or something. I saw questions on that in the SL forums. So good luck on your condo!

Anonymous said...

Confusing - On the 'this is a new value' - had no idea where to ad it. Gave up.

SLNatalia said...

Dear Anonymous, Im sorry, but Im confused about the whole scripting thing too ;P The 2 new values are in the sample script. They have a comment next to them: "// This is a NEW setting".