Page 1 of 3

Super Particle Editting and Rendering Machine

Posted: Wed Jan 15, 2014 3:03 am
by adnzzzzZ
Image

BIG GIF 1
BIG GIF 2
BIG GIF 3

USAGE

1. Open the .love file and change the save directory (first line in love.load function) to where you wanna save the particle systems to;
2. Use the editor! Controls: CTRL+Click to move the particle system, F1 to hide UI.

Video "tutorial":



GAME INTEGRATION

1. Download the example project and see how it's done there or;
1. Copy the getPS function to somewhere in your game and just call it using the name of the particle system (the name of the .lua file the editor generates to your save directory) and passing an image. It returns a ParticleSystem and you should need to start, update and draw it (and set blend modes yourself, since those don't magically carry over).

Code: Select all

function getPS(name, image)
    local ps_data = require(name)
    local particle_settings = {}
    particle_settings["colors"] = {}
    particle_settings["sizes"] = {}
    for k, v in pairs(ps_data) do
        if k == "colors" then
            local j = 1
            for i = 1, #v , 4 do
                local color = {v[i], v[i+1], v[i+2], v[i+3]}
                particle_settings["colors"][j] = color
                j = j + 1
            end
        elseif k == "sizes" then
            for i = 1, #v do particle_settings["sizes"][i] = v[i] end
        else particle_settings[k] = v end
    end
    local ps = love.graphics.newParticleSystem(image, particle_settings["buffer_size"])
    ps:setAreaSpread(string.lower(particle_settings["area_spread_distribution"]), particle_settings["area_spread_dx"] or 0 , particle_settings["area_spread_dy"] or 0)
    ps:setBufferSize(particle_settings["buffer_size"] or 1)
    local colors = {}
    for i = 1, 8 do 
        if particle_settings["colors"][i][1] ~= 0 or particle_settings["colors"][i][2] ~= 0 or particle_settings["colors"][i][3] ~= 0 or particle_settings["colors"][i][4] ~= 0 then
            table.insert(colors, particle_settings["colors"][i][1] or 0)
            table.insert(colors, particle_settings["colors"][i][2] or 0)
            table.insert(colors, particle_settings["colors"][i][3] or 0)
            table.insert(colors, particle_settings["colors"][i][4] or 0)
        end
    end
    ps:setColors(unpack(colors))
    ps:setColors(unpack(colors))
    ps:setDirection(math.rad(particle_settings["direction"] or 0))
    ps:setEmissionRate(particle_settings["emission_rate"] or 0)
    ps:setEmitterLifetime(particle_settings["emitter_lifetime"] or 0)
    ps:setInsertMode(string.lower(particle_settings["insert_mode"]))
    ps:setLinearAcceleration(particle_settings["linear_acceleration_xmin"] or 0, particle_settings["linear_acceleration_ymin"] or 0, 
                             particle_settings["linear_acceleration_xmax"] or 0, particle_settings["linear_acceleration_ymax"] or 0)
    if particle_settings["offsetx"] ~= 0 or particle_settings["offsety"] ~= 0 then
        ps:setOffset(particle_settings["offsetx"], particle_settings["offsety"])
    end
    ps:setParticleLifetime(particle_settings["plifetime_min"] or 0, particle_settings["plifetime_max"] or 0)
    ps:setRadialAcceleration(particle_settings["radialacc_min"] or 0, particle_settings["radialacc_max"] or 0)
    ps:setRotation(math.rad(particle_settings["rotation_min"] or 0), math.rad(particle_settings["rotation_max"] or 0))
    ps:setSizeVariation(particle_settings["size_variation"] or 0)
    local sizes = {}
    local sizes_i = 1 
    for i = 1, 8 do 
        if particle_settings["sizes"][i] == 0 then
            if i < 8 and particle_settings["sizes"][i+1] == 0 then
                sizes_i = i
                break
            end
        end
    end
    if sizes_i > 1 then
        for i = 1, sizes_i do table.insert(sizes, particle_settings["sizes"][i] or 0) end
        ps:setSizes(unpack(sizes))
    end
    ps:setSpeed(particle_settings["speed_min"] or 0, particle_settings["speed_max"] or 0)
    ps:setSpin(math.rad(particle_settings["spin_min"] or 0), math.rad(particle_settings["spin_max"] or 0))
    ps:setSpinVariation(particle_settings["spin_variation"] or 0)
    ps:setSpread(math.rad(particle_settings["spread"] or 0))
    ps:setTangentialAcceleration(particle_settings["tangential_acceleration_min"] or 0, particle_settings["tangential_acceleration_max"] or 0)
    return ps
end
If you want to use other images to test the particle systems, just unzip the .love, add the images to the same folder level as the main.lua file is in and then run the folder.

Re: Super Particle Editting and Rendering Machine

Posted: Wed Jan 15, 2014 10:24 am
by Snuux
It's awesome! And export work fine! Thanks!

[]

Posted: Wed Jan 15, 2014 10:28 am
by bekey
-snip-

Re: Super Particle Editting and Rendering Machine

Posted: Wed Jan 15, 2014 2:56 pm
by Ranguna259
Realy nice work man :awesome:
This kinda looks like source's particle editing menu, so awesome.

You should take a look at Source for more particle related features.

Re: Super Particle Editting and Rendering Machine

Posted: Wed Jan 15, 2014 11:17 pm
by Helvecta
You had me at Tool. Nice job! I know a lot of people have been waiting for an app like yours. ^^

Re: Super Particle Editting and Rendering Machine

Posted: Thu Jan 16, 2014 10:24 am
by SiENcE
Cool Editor and for 0.9.0. Nice. A performance monitor would be useful.

Saving crashs the editor. It seems you hardcoded the path. I have no User "Waffles" :).

Bugfix for your example:
instead of:

Code: Select all

function getPS(name)
this:

Code: Select all

function getPS(name, image)

Re: Super Particle Editting and Rendering Machine

Posted: Sun Jan 19, 2014 11:13 pm
by Zarty55
Really awesome!

When you set the buffer to negative or nil the program crashes, when loading the preset already loaded it crashes as well btw. But it is really cool and useful :D

Re: Super Particle Editting and Rendering Machine

Posted: Wed Feb 26, 2014 3:49 pm
by Tapatun
That thing really helped me in creating astounding sword effects with very little effort! Great tool, though there're a couple of annonying bugs still not fixed..
One of them is that getPS() cannot find an image for rendering particles, e.g. "square.png", "plus.png" etc.
Here's the code causing problem:

Code: Select all

local ps = love.graphics.newParticleSystem(image, particle_settings["buffer_size"])
As image is not declared as the second argument for getPS() function, it gets thrown away:

Code: Select all

square = love.graphics.newImage("data/square.png")
ps = getPS('Blue Fire', square) -- ignores the square image, have to hardcode it into the body of getPS function

--[[ ]]--

function getPS(name) -- Takes name only
Hope you'll continue developing and extending that LÖVEly editor!

Re: Super Particle Editting and Rendering Machine

Posted: Thu Feb 27, 2014 2:59 am
by adnzzzzZ
You're supposed to just change that function yourself to fit your needs. In any case, the code in the first post does take an image like you mentioned, so I don't understand what problems you're having.
1. Copy the getPS function to somewhere in your game and just call it using the name of the particle system (the name of the .lua file the editor generates to your save directory) and passing an image. It returns a ParticleSystem and you should need to start, update and draw it (and set blend modes yourself, since those don't magically carry over).

Re: Super Particle Editting and Rendering Machine

Posted: Thu Feb 27, 2014 9:59 am
by Tapatun
adnzzzzZ wrote:You're supposed to just change that function yourself to fit your needs. In any case, the code in the first post does take an image like you mentioned, so I don't understand what problems you're having.
..Ah, got it
Instead of manually copying getPS() function from the first post, I've downloaded the example project, which is bugged!

By the way, wiki says that setting buffer size as an argument for newParticleSystem() function will be available since unreleased LÖVE 0.9.1, but you are using it.. A typo?