Ogre Particle System and particle script

Source: Internet
Author: User

Mage Group
Email: norman_chen@163.com

Renwind@163.com

QQ: 18725262
Http://www.173d8.com

Http://blog.csdn.net/pizi0475

 

Particle System and particle script
Particle systems play an important role in 3D display, such as rain, snow, fountains, and explosion effects in 3D.
We can use a program to virtualize the scenario where the US Columbia space shuttle is exploding in space: the fragments of large and small pieces splash everywhere, dazzling sparks, and smoke, most of these elements are chaotic. From a technical point of view, most of the results in this scenario benefit from an excellent particle system. Smoke, spark, and the effects of these 3D images are generally created using particle systems.
Basic Concepts
Grain
A child is represented by a quadrilateral. It has length and width, and its direction, quantity, material, and weight. These attributes are enclosed in the particle property converter (affector), which contains color fading.
¬ Colourfaderaffector and linearforceaffector ). Particle generation by particle generator
(Emmiter. It contains boxemmitter and point particle generator (
Contains pointemmiter), composed of these particle script files, with the. Particle extension. Point particle generator randomly emits particles from a single point; box particle generator random
From a region. By creating plugins, you can add a new transmitter to ogre. Currently, ogre only supports point particle generators and box particle transmitters.
When the particle generator continuously emits a large number of particles, it can form smoke, fire, explosion and other effects.
Particle System Structure:
 
Particle System script
Ogre provides the particle system scripting language, which allows you to set various attributes of particles in the script without re-compiling the program. This makes it easy for users. Note that the particle system script file has its own syntax, similar to C ++: The annotation uses "//" and the "{}" to differentiate boundaries. However, annotations are not supported after the code.
The particle system is defined as a template in the script. You can create multiple instances during the running period.
Load particle script
Grain
Subsystem scripts are loaded during system initialization. By default, the system searches for all extensions under the public resource path (root: specified by the soursourcelocation function ).
For ". Particle" files and parse them. If you want to specify other extensions, you can use
Particle systemmanager: getsingleton (). parseallsources method. to parse a single particle system script file
You can use the particle systemmanager: getsingleton (). parsescript method.
Once the particle system script is loaded, you
You can use the particle systemmanager: getsingleton (). createsystem () method to create an instantiated particle system,
This method receives two parameters: the name of the particle system, and the name of the template to be referenced (that is, the Template Name Defined in the script.
Format
Multiple Particle System templates can be defined in a script file.
The following is a typical particle script, which contains three Particle System templates used in the Ogre particle demo. You can run this demo to view the actual effect. You can also modify these attributes to change the effect.
// Particle System Template Name
// Exudes greeny participant which float upwards
Examples/greenynimbus
{
// Material of the particle
Material examples/flare
// Particle width
Particle _ width 30
// Particle height
Particle _ height 30
// Particle cropping mode: overall box cropping or single particle cropping.
Cull_each false
// Number of particles
Quota 10000
// Announcement board type: point indicates that the Quadrilateral of the particle is always oriented to the camera.
Billboard_type point

// Box-like particle Transmitter
Emitter box
{
// Maximum deviation from direction during particle emission
Angle 30
// Transmission rate (per second)
Emission_rate 30
// Particle survival time (seconds)
Time_to_live 50
// Particle emission direction
Direction 0 1 0
// Speed
Velocity 10
// Color start value
Colour_range_start 1 1 0
// Color end value (random number between the start value and the end value)
Colour_range_end 0.3 1 0.3
// Define the size of the particle transmitter box
Width 60
Height 60
Depth 60
}

// Linearforce: add an external force to the particle in motion to influence its trajectory.
// Make em float upwards
Affector linearforce
{
// Specify the influence of external force (expressed by vector)
Force_vector 0 100 0
// Add: The motion vector of the particle plus the vector of the external force. Effect: uniformly accelerated motion.
Force_application add
}

// Colourfader: affects the color of particles.
// Fader
Affector colourfader
{
// Attenuation per second: 0.25
Red-0.25
Greenton-0.25
Blue-1, 0.25
}

}

// A Sparkly Purple Fountain
Examples/purplefountain
{
Material examples/flare2
Particle _ width 20
Particle _ height 20
Cull_each false
Quota 10000
Billboard_type oriented_self

// Area Emitter
Emitter point
{
Angle 15
Emission_rate 75
Time_to_live 3
Direction 0 1 0
Velocity_min 250
Velocity_max 300
// Upper and lower limit of Color Conversion
Colour_range_start 0 0 0
Colour_range_end 1 1 1
}

// Gravity
Affector linearforce
{
Force_vector 0-100 0
Force_application add
}

// Fader
Affector colourfader
{
Red-0.25
Greenton-0.25
Blue-1, 0.25
}
}

// A downpour
Examples/rain
{
Material examples/Droplet
Participant _width 50
Particle _ Height 100
Cull_each true
Quota 10000
// Make common direction straight down (faster than self oriented)
Billboard_type oriented_common
Common_direction 0-1 0

// Area Emitter
Emitter box
{
Angle 0
E-mapreduce _ rate 100
Time_to_live 5
Direction 0-1 0
Velocity 50
Colour_range_start 0.3 1 0.3
Colour_range_end 0.7 1 0.7
Width 1000
The height is 1000.
Depth 0
}

// Gravity
Affector linearforce
{
Force_vector 0-200 0
Force_application add
}

}

Each particle system template in the script must have a name and must be the first line before. This name must be unique. The name can contain "/" to form a path, but the Ogre engine only treats it as a string and does not really analyze the path. It only facilitates programmers to differentiate layers.
A particle system can set upper attributes, such as quota, which indicates the maximum number of particles allowed. In addition to the basic attributes, you must also nest the transmitter emitters and attribute converter affectors in a particle system template. Their internal attributes are related to their types.
The particle system script has many attributes. See the particle scripts section in ogre tutorial.

Example 1
Open emample. particle in the Ogre demo and try to change the particle transmitter (emitter box and Emitter
Point) and particle emission rate (for example, change emission_rate 100 to emission_rate
30), particle survival time (seconds) (time_to_live
Wait, and then run demo_participant fx.exe to check the effect.
Example 2
Open the demo_particle FX project in ogre, view the code, and understand the calling method of the particle system.
When the program is running, there is a piranet in the scene, braving the green smoke (particle system) on the head, there are two moving particle generators next to the burst of colorful points (or particle system ).
The ogre engine automatically loads the script file of the particle system during initialization.
In
In the createscene function of the program
Particle systemmanager: getsingleton (). createsystem ("Nimbus ",
"Examples/greenynimbus"); creates an actual Particle System Nimbus, which uses the template "Examples
/Greenynimbus is defined in the particle system script.
This program has three particle systems, and the Creation methods are the same, but the templates used are different.
After the particle system is created, attach it to the scene node to facilitate motion control. The Code is as follows:
Mscenemgr-> getrootscenenode ()-> createchild ()-> attachobject (psys1 );
Once the particle system is attach to the scene node, the framelistener's framestarted method can be used to control the node movement. Of course, the particles also erupt while moving.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.