OBJECT EXPLODER INCLUDE FILE for Persistence of Vision 3.x

Created by Chris Colefax, March 1997

Updated 10 August 1998: updated for POV-Ray 3.1,

Updated 23 August 1998: fixed time_scale bug, updated documentation


INSTALLATION

QUICK START

OPTIONS

GENERATING THE EXPLOSION

TROUBLESHOOTING

COPYRIGHT AND LEGAL INFORMATION

CONTACTING THE AUTHOR


INSTALLATION
Copy the Object Exploder include file (Explode.inc) and the Object Exploder ground plane file (ExplodeG.inc) to one of the directories (folders) in your POV-Ray library path. Normally this is the INCLUDE sub-directory of the directory where you installed POV-Ray, so if you installed POV-Ray in C:\POVRAY you should copy the files to C:\POVRAY\INCLUDE. On a Windows 95 system, this is probably something like:

C:\Program Files\POV-Ray for Windows\Include

On UNIX and similar systems, where filenames are case-sensitive, you may have to rename the include file so that the case of the letters of both files is as shown above. If you want to render the sample files you should also check that the naming of Map.gif is as shown. This will enable you to render the sample files without modification.


QUICK START
The Object Exploder include file will take any existing POV-Ray object, from a simple sphere to a complex CSG object, and explode it into a mass of animated particles. There are many options you can use to affect the way the explosion occurs; to use any of these you simply add the following line to your POV-Ray scene file, before including Explode.inc:

#declare [variable-name] = [value]

substituting the desired variable name and value where appropriate. After you have declared all the options you want to use, you add the following line to your POV-Ray scene file:

#include "Explode.inc"

The Object Exploder include file will then automatically create the animated explosion for you. Although only one option is required to create an explosion (explode_object) you will want to use the options listed below to ensure you get the sort of explosion that you want.

Note that the Object Exploder Include File should never be included at the start of a scene, like colors.inc or textures.inc. It should only be included after declaring all the options you want to use. Also, the Object Exploder Include File supports both British and American English, eg: object_center and object_centre are interchangeable.


OPTIONS


A NOTE ON UNITS
When using the Object Exploder options you will discover a number of variables that must be specified as a certain number of units. Just as in POV-Ray the units you wish to use are entirely up to you, eg. you may specify the object size in microns or miles, and the explosion clock in milliseconds or days.

The important thing is that you keep the units that you use in a particular scene file consistent for that entire file, eg. if you are measuring distances in metres and time in seconds then speeds should be expressed as metres per second. This will ensure that you get the results you expect, and will save you a lot of trouble.


OBJECT OPTIONS
The first step when using the Object Exploder include file is to specify a number of parameters that identify the object you wish to explode, as well as its position in the POV-Ray universe.

explode_object


This parameter indicates the object you want to explode, and can be either a predefined object or a completely new object definition, including textures and transformations, eg:

#declare explode_object = object {MyObject scale 3}
#declare explode_object = sphere {< 0, 5, 0> , 3 pigment {Red}}

Any POV-Ray object can be used, including CSG objects and triangle meshes.

After you have specified the explode_object you must declare a number of variables that indicate the size and position of the object. Four vectors can be used for this, but only two are needed, and only the first two found will be used. For the best results you should try to make these measurements as accurate as possible.

object_centre


This specifies the exact centre of the explode_object, and is best used when exploding spherical or cylindrical objects.

object_size


This specifies the X, Y, and Z dimensions of the explode_object, eg. if the explode_object was a sphere with a radius of 1 then the size would be < 2, 2, 2> .

object_corner1


This specifies the lower-left hand corner of the object, and is best used when exploding box-like objects.

object_corner2


This vector specifies the upper-right hand corner of the object.

object_orientation


Normally the explode object specified using any of the above options is assumed to be in line with the X, Y, and Z axes. Sometimes, however, you may want to explode an object that is at an angle to the axes, eg. a vehicle travelling in a certain direction. You can use the object_orientation option to specify the angles the object is rotated by, around the X, Y, and Z, axes, eg:

#declare explode_object = cylinder {< 0, 0, 0> , < 0, 3, 0> , .5 rotate < 45, 45, 0> }
#declare object_centre = < 0, 1.5, 0> ;
#declare object_size = < 1, 3, 1> ;
#declare object_orientation = < 45, 45, 0> ;

The particles produced by the explosion will now face in the correct direction (note that the rotation specified by object_orientation is performed about the centre of the object, not necessarily the origin).

object_hollow


This is a true / false value that indicates whether the explode_object is to be considered as a surface model only, or as a solid object. If object_hollow = true (default) then the object is considered to be hollow inside, and particles are created from the surface of the object.

If object_hollow = false then the object is considered to be solid, and when it is exploded particles will be created inside the object as well as on the surface. Note that this may not work with all objects (eg. triangles, polygons) as they do not have clearly defined insides and outsides.


PARTICLE OPTIONS
After you have specified all the desired object variables you can specify a number of options which will adjust the shape, size, and number of particles created when the object is exploded.

particle_res


This is the most important of the particle options, and specifies the number of particles to create. It should be specified as a vector, but may be specified as a float (eg. 3 = < 3, 3, 3> ). When the object is exploded it is broken up into a grid of particles, with the number of particles in each direction taken from the X, Y, and Z components of this vector, eg. #declare particle_res = < 7, 3, 5> ; will create 7 particles in the X direction, 3 in the Y direction, and 5 in the Z direction, which gives 7 * 3 * 5 particles, or 105 particles in total.

Each component of the vector can be 1 or larger. However, adjusting this variable can drastically alter the speed it takes to generate the explosion, so keep this in mind when trying larger numbers.

particle_object


This specifies the shape of the individual particles created by the Object Exploder, and should generally be a unit sized object centred around the origin (the default is box {< -.5, -.5, -.5> , < .5, .5, .5> }).

The particle_object can include texture information, but this will only be used if object_hollow is false. Note also that this will give all particles the same texture; if you want the particles to be textured based on their location inside the object you should use the particle_texture option.

particle_texture


This specifies the texture of the inside of the object, and will only be used if object_hollow is false. Using this option allows you to texture particles differently according to their position within the object, eg. if you use a gradient that goes from white at the bottom of the object to red at the top, any particles from the bottom of the object will be white while any from the top will be red. The default particle_texture is texture {pigment {rgb < .5, .5, .5> }}

disintegration


This option is used in conjunction with the explode_life option, and can be used to make the exploded particles gradually shrink (disintegrate) over time. The main advantage of explode_life is that it allows you to only calculate an explosion for a selected period during an animation, after which the particles will no longer form a part of the scene, reducing parsing and rendering time. To prevent the particles from disappearing suddenly when the explosion's life is over, you can use set this option to a value larger than 0. A value of 1 gives a linear disintegration, while smaller values give slower disintegration, and larger values increase the speed of disintegration. An interesting effect can be achieved by using this option with an exp_strength value of 0, which doesn't actually cause the object to explode, but merely to dissolve in place. The default value of disintegration is 0.5


EXPLOSION OPTIONS
The following parameters specify the actual characteristics of the explosion itself (ie. the force that breaks apart the object).

exp_location


This specifies the vector location of the explosion, and determines the direction in which the particles will move after the explosion, eg. making this the same as the object_centre will explode the particles outwards in all directions, while placing this below the object will explode the particles upwards. By default this is located at the origin.

exp_strength


This specifies the force of the explosion. It is actually the velocity given to each particle at the start of the explosion. Larger numbers will make the objects explode more quickly, while smaller numbers will make the explosion seem smaller. Specifying 0 for this option will not actually move the particles, and is useful for giving the impression of an object that cracks without actually blowing up (it is best used with the exp_gravity or disintegration option).

Specifying negative numbers will cause the particles to move in the opposite direction, and can be used to create an imploding object, rather than an exploding object.

exp_falloff


Normally all particles are given the same velocity (specified by exp_strength) at the start of the explosion, regardless of their distance from the explosion itself. You can use the exp_falloff option to make particles further from the explosion receive less of the explosion's force than particles that are near the explosion. The number specified actually indicates the distance at which the exp_strength drops to 25% of its original strength, eg. #declare exp_falloff = 10; means that a particle 10 units away from the exp_location will only receive 25% of the force specified by exp_strength.

exp_gravity


This specifies the strength of the force of gravity, declared as a float (not a vector). Normally this is 0 (ie. no gravity), but specifying otherwise will cause particles to be pulled to the ground.

exp_sky


This specifies the direction vector that points in the up direction (normally this is y, ie. < 0, 1, 0> ). It works in a similar way to the sky keyword in the POV-Ray camera, and it useful when using a different coordinate system (eg. #declare exp_sky = z; if the z-axis points upwards). This vector determines the direction of the gravity (opposite to the sky, of course) and is also used as the normal of the ground plane if one is specified (see Ground Plane Options).

exp_spin


This option can be used to cause the exploded particles to spin as they move through space. It can be specified as a vector or float, and indicates the number of spins to make per each unit of time, eg. #declare exp_spin = < .5, 1, 0> ; will spin each particle 180 degrees about the x-axis and 360 degrees about the y-axis for every unit of time that passes. Usually it is easier to declare this option as a float value that indicates the amount of spin you wish to give each particle, eg. #declare exp_spin = .3;


GROUND PLANE OPTIONS
The Object Exploder include file has the ability to add a ground plane to the scene. If a particle hits this plane it can automatically rebound off it or it can stop and come to rest on the plane.

Note that the Object Exploder include file will not actually create a ground plane object for you, giving you the option to use any sort of object you like to represent the ground.

ground_plane


This is a true / false value that indicates whether a ground plane is present or not. Normally this is false, but setting it to true will cause the Object Exploder to check each particle's movement against this plane to see if it rebounds or stops. Also, any particles underneath the plane will not be created.

ground_dist


This specifies the distance of the ground from the origin, and is the same as the distance value as specified in the plane object. Note that the normal direction of the plane is always the same as exp_sky (the default if < 0, 1, 0> ). By default the ground_dist is 0.

ground_reflection


This specifies the amount of energy a particle retains after hitting the ground plane. ground_reflection = 1 means that the particle retains all of its energy, and will bounce back to the same height each time it hits the ground. ground_reflection = 0 (the default) means that the particle retains none of its energy after hitting the plane, and therefore it comes to a stop. Values in between 0 and 1 will cause the particle to bounce less high each time it hits the plane, eventually coming to a stop. Values larger than 1 will cause the particle to bounce higher each time it hits the plane.

max_bounces


This option specifies the maximum number of times a particle will rebound off a plane before coming to a stop (even if ground_reflection is 1). This is necessary because of the way the rebounds are calculated: each time a particle is checked for rebounds all the particles rebounds prior to the current rebound need to be recalculated (this is a limitation in the way POV-Ray handles variables from frame to frame in an animation). This means that on a particle's second rebound the first rebound has to be calculated again, while on the third rebound the first and second rebounds have to recalculated.

Because calculating each rebound requires solving a quadratic equation as well as a number of other calculations, this can add a considerable amount to the time needed to generate the explosion. For this reason, you can use the max_bounces option to limit the number of bounces a particle will make. By default this is set to 1 (ie. each particle will bounce once, and then stop). Setting it to 0 will stop particles bouncing at all, while increasing the number will allow particles to bounce more times before coming to a stop.


TURBULENCE OPTIONS
By default the Object Exploder include file creates the explosion particles in a perfect grid (specified by the particle_res option), and each particle is the same size, and travels at the same speed. While this is fine for some explosions it is less than realistic. To remedy this you can add turbulence to the explosion, adding a little randomness to each particle's size and speed.

exp_turb


This option controls the overall amount of turbulence added to the explosion (normally this is 0). Good values range from 0 (no turbulence) to 1 (lots of turbulence), but any value can be used. Changing this value will add equal turbulence to all aspects of the explosion. If you wish to adjust the turbulence of individual areas of the explosion you can use the following parameters. (Note that all the individual turbulence options are multiplied by exp_turb to find the final turbulence, so you will have to make sure that exp_turb is not 0 before using the other turbulence options).

scale_turb


This option controls the amount of turbulence added to the scaling of the particles. It is specified as a factor of the particle size, eg. scale_turb = .5 will give particles scaled up to 50% larger or smaller than normal.

rotate_turb


This option controls the amount of turbulence added to the rotation of the particles. It is specified as a fraction of 360 degrees, eg. rotate_turb = .1 will give particles rotated up to 36 degrees away from normal.

vel_turb


This option controls the amount of turbulence added to the velocity of the particles. It is specified as a factor of the particle velocity, eg. #declare vel_turb = .3; will give particles with velocities up to 30% more or less than normal.

dir_turb


This option controls the amount of turbulence added to the direction of the particles movement. It is specified as a fraction of 360 degrees, eg. #declare dir_turb = .2; will give particles that move up to 20 degrees away from normal.

spin_turb


This option controls the amount of turbulence added to the spin of each particle, and only applies when you have specified a non-zero value for exp_spin. It is measured as a factor of the total spin amount, eg. #declare spin_turb = .7; will give particles that spin up to 70% more or less than normal.

exp_seed


This option specifies the random number seed used when adding turbulence to the explosion. Normally this is 0, but any integer value can be used.


GENERATING THE EXPLOSION
After you have declared all the desired variables you must specify how you want the object to explode in relation to POV-Ray's internal clock (and then include the Explode.inc file, of course). The following options control how the explosion is generated:

explode_clock


This variable indicates the current time value of the explosion, where 0 is just before the explosion starts. Normally the explode_clock is equal to POV-Ray's internal clock variable. This may not, however, be what you require for a particular scene. Because of this you are given the option to #declare explode_clock to be any value you want. You can use this to create still scenes from a particular point in time through the explosion, eg. #declare explode_clock = 1.47; will create a still scene of the explosion 1.47 units of time after it started. (Note that when explode_clock is less than or equal to 0 the explode_object is placed in the scene without being altered at all).

explode_start


Although setting the explode_clock to a static value is fine for still images, for animations you will normally want to specify the clock value at which you want the explosion to start, eg. #declare explode_start = .5; will start exploding the object when the internal clock reaches this value. If you use explode_start to control the explosion, there is no need to use the explode_clock variable.

explode_life


Normally the explosion starts at the time specified by either of the above options, and then continues until the end of the animation. Setting this option to a number greater than 0 will cause the explosion to only occupy a selected period of the animation, reducing parsing and rendering time, eg. setting explode_start to 0.3 and explode_life to 0.5 will cause the exploded particles to disappear after the internal clock reaches 0.8. By default, disintegration is enabled when you specify an explode_life value, so the particles will gradually shrink in size before they disappear.

time_scale


You can use this option to increase (if you use a number larger than 1) or decrease (if you use a number smaller than 1) the speed of the exploded particles, eg. #declare time_scale = 5; would make the explosion run five times as fast as normal, while #declare time_scale = .1 would make the explosion run 10 times slower than normal. However, it has no effect on the explode_start or explode_life options, so these can be used to specify absolute clock values, while the time_scale sets the relative speed of the animated explosion. The default value of time_scale is 1


ADVANCED EXPLODE CLOCK OPTIONS
Generally, using the explode_start and possibly the explode_life options will be enough to control the explosion in an animation. Alternatively, however, you can set the explode_clock using any of POV-Ray's mathematical functions to create varying effects. You might want a more complicated explode_clock, such as one that travels backwards, or one that starts fast and slows down. All of these can be easily accomplished using POV-Ray's various float functions, and the #if and #switch directives.

For some examples of using explode_clock in this way take a look at the sample animations that come with the Object Exploder include file.


TROUBLESHOOTING


Q: I have created an animation with the Object Exploder but it seems to render very slowly?
A: This is probably related to POV-Ray's bounding threshold setting. The default is 25 objects, and if your animation starts with less than this (before the explosion), bounding will be turned off and rendering the exploded particles will be much slower than normal. To enable bounding, use the Bounding=0 setting in an INI file, or the +MB0 setting on the POV-Ray command line.


Q: I want to explode part of an object, not the entire object all at once?
A: You can do this quite easily by using a CSG intersection and/or difference to separate the object into the part to be exploded, and the unexploded part. First decide the shape and size of the section you want to explode, eg. to create an exploding crater on the side of a planet:

#declare Planet = sphere {< 0, 0, 0> , 100 texture {PlanetTexture}}
#declare CraterCutout = sphere {x * 100, 5 scale < 1, 2, 2> texture {CraterTexture}}

Now, use this cutout shape to create the explode_object (as an intersection), and the main object (as a difference). The various object options should fit the intersection you use as the explode_object (not the main, unexploded object), eg:

// Unexploded Planet
difference {object {Planet} object {CraterCutout}}

// Exploding crater (object variables fit the intersection, not the CraterCutout or Planet objects
#declare explode_object = intersection {object {Planet} object {CraterCutout}}
#declare object_center = x * (100 - 2.5);
#declare object_size = < 5, 20, 20 > ;

You can now set the remaining explode options you want to use, and include the Object Exploder to create the exploding crater. In the time before the explosion starts, the intersected crater object will fit exactly into the differenced planet object, giving a seamlessly whole planet.


Q: I want to explode an object, but not all at once?
A: The method for exploding different parts of objects at different times is exactly the same as exploding an object partially (as detailed in the above question). Rather than creating an intersected explode_object and a differenced main object, you can use intersections to cut your main object into multiple pieces, each with different explode settings, eg:

#declare Ship = #include "ShipObj.inc"

#declare explode_object = object {Ship clipped_by {box {< -20, -7.5, -15> , < -5, 5, 10> }}}
#declare object_corner1 = < -20, -7.5, -15> ;
#declare object_corner2 = < -5, 5, 10> ;
#declare explode_start = .2;
#include "Explode.inc"

#declare explode_object = object {Ship clipped_by {box {< 5, -7.5, -15> , < 20, 5, 10> }}}
#declare object_corner1 = < 5, -7.5, -15> ;
#declare object_corner2 = < 20, 5, 10> ;
#declare explode_start = .4;
#include "Explode.inc"

As in the previous example, before both explosions occur the entire ship object will recreated seamlessly. After the first half explodes (at clock = 0.2), the second half will remain unexploded, until the time at which it also explodes. For best results (if using an intersection, rather than a clipping object), you will probably want to use a more irregular cutout shape, or a rough-looking texture (so the exploded edges are not to clean).


COPYRIGHT AND LEGAL INFORMATION
The Object Exploder Include File, including Explode.inc, ExplodeG.inc, all documentation, and associated sample *.POV files are Copyright 1997, 1998 by Chris Colefax. Full permission is granted to the user to modify any or all of the files for his/her own use. If modified versions are to be distributed the user should make clear the modifications that have been made by him/herself.

The Object Exploder Include File may be bundled with or without other software on CD-ROM collections, Bulletin Board systems and other file archives, providing that all associated files, including documentation and samples, are included. I would also request that persons intending to distribute the Object Exploder Include File in this manner or otherwise would first contact me to ensure that they are in possession of the latest available version.

Further, no restrictions of any sort are placed on the usage of the include files themselves (Explode.inc and ExplodeG.inc), and scene files or images created using the include files remain entirely the property of the user or users who have created them. I claim no liability or responsibility for damages or loss resulting from usage of the include files, or any part of the include file package.


CONTACTING THE AUTHOR
If you wish to contact me with bug reports, bug fixes, criticisms, comments, suggested improvements, questions, etc. you can reach me by email at:

ccolefax@geocities.com

or by regular mail at:


POV-RayTM and Persistence of VisionTM are registered trademarks of the POV-Ray TeamTM