Jump to content
  • entries
    943
  • comments
    5,899
  • views
    923,763

Particle Plugins and More


Josh

1,647 views

 Share

The Leadwerks 5 beta will soon be updated with particle emitters and an example particle system plugin. Previously, I showed some impressive results with physically interactive particles that collide with and exert forces on the environment. I decided to use the plugin system for controlling particle behavior, as this offers the best performance and can be run on the physics thread. 

A particle system plugin uses some predefined structures and functions to modify the behavior of particles when they are emitted or as they are updated. This allows for unlimited features to be added to the particle system, because anything you want can be added with a plugin. A system for sending settings to the plugin will be implemented in the future so you can adjust the plugin settings and see the results. The default particle settings and features will probably stay pretty barebones and I will just use the plugin system to add any advanced functionality since it is so flexible.

void EmitParticle(ParticleModifier* mod, ParticleSystem* particlesystem, Particle* particle)
{
    if (mod->emissionshape == EMISSION_SHAPE_BOX)
    {
        particle->position[0] = Random(-mod->area[0], mod->area[0]);
        particle->position[1] = Random(-mod->area[1], mod->area[1]);
        particle->position[2] = Random(-mod->area[2], mod->area[2]);
    }
    else if (mod->emissionshape == EMISSION_SHAPE_CYLINDER)
    {
        particle->position[0] = Random(-mod->area[0], mod->area[0]);
        particle->position[1] = Random(-mod->area[1], mod->area[1]);
        particle->position[2] = Random(-mod->area[2], mod->area[2]);
        auto l = sqrt(particle->position[0] * particle->position[0] + particle->position[1] * particle->position[1] + particle->position[2] * particle->position[2]);
        if (l > 0.0f)
        {
            particle->position[0] /= l;
            particle->position[1] /= l;
            particle->position[2] /= l;
        }
    }
    particle->position[0] += particlesystem->matrix[12];
    particle->position[1] += particlesystem->matrix[13];
    particle->position[2] += particlesystem->matrix[14];
}

There are three other new Lua examples included. Coroutines.lua shows how a sequence of actions can be added to an entity before the game starts, and the actions will be executed in order:

--Create model
local model = CreateBox(world)

--Add some behaviors to be executed in order
model:AddCoroutine(MoveToPoint, Vec3(3,0,0), 2)
model:AddCoroutine(MoveToPoint, Vec3(-3,0,0), 2)
model:AddCoroutine(MoveToPoint, Vec3(0,0,0), 2)

--Main loop
while window:Closed() == false do
	world:Update()
	world:Render(framebuffer)
end

This is great for setting up cut scenes or other sequences of events.

An example showing how to enable tessellation is also included. Tessellation is now a per-camera setting.

camera:SetTessellation(10)

The number you input is the size in pixels of the tessellated primitives. Use zero to disable tessellation. Tessellation is disabled by default on all cameras.

Finally, an example showing how to use a texture loader plugin is included. All you have to do is load the plugin and after that textures can be loaded in VTF format:

local vtfloader = LoadPlugin("Plugins/VTF.dll")
local tex = LoadTexture("Materials/wall01.vtf")

 

  • Like 2
  • Thanks 1
 Share

2 Comments


Recommended Comments

Another trick you can use is to place a script in the Scripts/Start folder that loads a plugin into a global variable. That way the plugin will always be loaded automatically when your game starts.

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...