Quote: "is it possible to get the saved file into agk already?"
Sure, here we go:
You will need my particle 3D lib
type _Particle3DKeyColor
time as float
r as integer
g as integer
b as integer
a as integer
endtype
type _Particle3D
id as integer
name as string
x as float
y as float
z as float
freq as float ` per second
life as float ` seconds
size as float
vel_min as float
vel_max as float
dir_angle1 as float
dir_angle2 as float
dir_vel_x as float
dir_vel_y as float
dir_vel_z as float
dir_emitter_roll as float
start_zone_x1 as float
start_zone_y1 as float
start_zone_z1 as float
start_zone_x2 as float
start_zone_y2 as float
start_zone_z2 as float
additive as integer ` additive or alpha transparent particles
transparency as integer
active as integer
visible as integer
color_interpolation as integer
count_max as integer
key_color as _Particle3DKeyColor[]
img_id as integer
img_filename as string
emitter_mesh as integer
endtype
function particle3D_Create(p ref as _Particle3D)
p.id = Create3DParticles(0.0, 0.0, 0.0)
if p.id = 0 then exitfunction
p.name = ""
p.x = 0.0
p.y = 0.0
p.z = 0.0
p.freq = 100
p.life = 5.0
p.additive = 1
p.size = 0.08
p.vel_min = 0.5
p.vel_max = 3.0
p.dir_angle1 = 0.0
p.dir_angle2 = 0.0
p.start_zone_x1 = -1.0
p.start_zone_y1 = -1.0
p.start_zone_z1 = -1.0
p.start_zone_x2 = 1.0
p.start_zone_y2 = 1.0
p.start_zone_z2 = 1.0
p.transparency = 1
p.active = 1
p.visible = 1
p.color_interpolation = 1
p.dir_vel_x = 0.0
p.dir_vel_y = 3.0
p.dir_vel_z = 0.0
p.dir_emitter_roll = 0.0
p.count_max = -1
Set3DParticlesActive(p.id, p.active)
Set3DParticlesColorInterpolation(p.id, p.color_interpolation)
Set3DParticlesDirection(p.id, p.dir_vel_x, p.dir_vel_y, p.dir_vel_z, p.dir_emitter_roll)
Set3DParticlesDirectionRange(p.id, p.dir_angle1, p.dir_angle2)
Set3DParticlesFrequency(p.id, p.freq)
Set3DParticlesLife(p.id, p.life)
Set3DParticlesSize(p.id, p.size)
Set3DParticlesPosition(p.id, p.x, p.y, p.z)
Set3DParticlesTransparency(p.id, p.transparency)
Set3DParticlesVelocityRange(p.id, p.vel_min, p.vel_max)
Set3DParticlesVisible(p.id, p.visible)
Set3DParticlesMax(p.id, p.count_max)
particle3D_EmitterCreateMesh(p)
particle3D_SetStartZone(p, p.start_zone_x1, p.start_zone_y1, p.start_zone_z1, p.start_zone_x2, p.start_zone_y2, p.start_zone_z2)
endfunction
function particle3D_Destroy(p ref as _Particle3D)
if p.id = 0 then exitfunction
DeleteImage(p.img_id)
Delete3DParticles(p.id)
p.id = 0
p.img_filename = ""
p.key_color.length = -1
endfunction
function particle3D_DestroyAll(p ref as _Particle3D[], resource_del as integer)
i as integer
l as integer
l = p.length
for i = 0 to l
particle3D_Destroy(p[i])
next i
endfunction
function particle3D_Copy(src ref as _Particle3D, dst ref as _Particle3D)
dst.name = src.name
dst.x = src.x
dst.y = src.y
dst.z = src.z
dst.freq = src.freq
dst.life = src.life
dst.size = src.size
dst.vel_min = src.vel_min
dst.vel_max = src.vel_max
dst.dir_angle1 = src.dir_angle1
dst.dir_angle2 = src.dir_angle2
dst.dir_vel_x = src.dir_vel_x
dst.dir_vel_y = src.dir_vel_y
dst.dir_vel_z = src.dir_vel_z
dst.dir_emitter_roll = src.dir_emitter_roll
dst.start_zone_x1 = src.start_zone_x1
dst.start_zone_y1 = src.start_zone_y1
dst.start_zone_z1 = src.start_zone_z1
dst.start_zone_x2 = src.start_zone_x2
dst.start_zone_y2 = src.start_zone_y2
dst.start_zone_z2 = src.start_zone_z2
dst.additive = src.additive
dst.transparency = src.transparency
dst.active = src.active
dst.visible = src.visible
dst.color_interpolation = src.color_interpolation
dst.count_max = src.count_max
dst.key_color = src.key_color
dst.img_id = src.img_id
dst.img_filename = src.img_filename
endfunction
function particle3D_Load(p ref as _Particle3D[], filename as string)
i as integer
l as integer
p.load(filename)
l = p.length
for i = 0 to l
p[i].id = 0
p[i].img_id = 0
p[i].emitter_mesh = 0
next i
endfunction
function particle3D_Save(p ref as _Particle3D[], filename as string)
i as integer
l as integer
pw as _Particle3D[]
pw = p
l = p.length
for i = 0 to l
pw[i].id = 0
pw[i].img_id = 0
pw[i].emitter_mesh = 0
next i
pw.save(filename)
endfunction
function particle3D_Start(p ref as _Particle3D)
i as integer
l as integer
key_color as _Particle3DKeyColor[]
if p.id <= 0 then p.id = Create3DParticles(p.x, p.y, p.z)
Set3DParticlesActive(p.id, p.active)
Set3DParticlesColorInterpolation(p.id, p.color_interpolation)
Set3DParticlesDirection(p.id, p.dir_vel_x, p.dir_vel_y, p.dir_vel_z, p.dir_emitter_roll)
Set3DParticlesDirectionRange(p.id, p.dir_angle1, p.dir_angle2)
Set3DParticlesFrequency(p.id, p.freq)
Set3DParticlesLife(p.id, p.life)
Set3DParticlesSize(p.id, p.size)
Set3DParticlesPosition(p.id, p.x, p.y, p.z)
Set3DParticlesTransparency(p.id, p.transparency)
Set3DParticlesVelocityRange(p.id, p.vel_min, p.vel_max)
Set3DParticlesVisible(p.id, p.visible)
Set3DParticlesMax(p.id, p.count_max)
particle3D_SetStartZone(p, p.start_zone_x1, p.start_zone_y1, p.start_zone_z1, p.start_zone_x2, p.start_zone_y2, p.start_zone_z2)
particle3D_SetImage(p, p.img_filename)
` set key colors, AGK does not support key color modification, it is necesseray to remove all keys and add them again
key_color = p.key_color
particle3D_KeyColorRemoveAll(p)
l = key_color.length
for i = 0 to l
particle3D_KeyColorAdd(p, key_color[i].time, key_color[i].r, key_color[i].g, key_color[i].b, key_color[i].a)
next i
endfunction
function particle3D_SetName(p ref as _Particle3D, name as string)
p.name = name
endfunction
function particle3D_SetPosition(p ref as _Particle3D, x as float, y as float, z as float)
p.x = x
p.y = y
p.z = z
Set3DParticlesPosition(p.id, p.x, p.y, p.z)
endfunction
function particle3D_SetActive(p ref as _Particle3D, active as integer)
if active < 1 then p.active = 0 else p.active = 1
Set3DParticlesActive(p.id, p.active)
endfunction
function particle3D_SetFreq(p ref as _Particle3D, freq as float)
p.freq = Abs(freq)
Set3DParticlesFrequency(p.id, p.freq)
endfunction
function particle3D_SetSize(p ref as _Particle3D, size as float)
p.size = Abs(size)
Set3DParticlesSize(p.id, p.size)
endfunction
function particle3D_SetLife(p ref as _Particle3D, life as float)
oldlife as float
i as integer
percent as float
oldlife = p.life
p.life = Abs(life)
Set3DParticlesLife(p.id, p.life)
if oldlife <> 0 and oldlife <> p.life
for i = 0 to p.key_color.length
percent = p.life / oldlife
p.key_color[i].time = p.key_color[i].time * percent
next
endif
endfunction
function particle3D_SetVelocityRange(p ref as _Particle3D, vmin as float, vmax as float)
p.vel_min = vmin
p.vel_max = vmax
Set3DParticlesVelocityRange(p.id, p.vel_min, p.vel_max)
endfunction
function particle3D_SetDirectionRange(p ref as _Particle3D, angle1 as float, angle2 as float)
p.dir_angle1 = angle1
p.dir_angle2 = angle2
Set3DParticlesDirectionRange(p.id, p.dir_angle1, p.dir_angle2)
endfunction
function particle3D_SetInitialDirectionVel(p ref as _Particle3D, vx as float, vy as float, vz as float, roll as float)
p.dir_vel_x = vx
p.dir_vel_y = vy
p.dir_vel_z = vz
p.dir_emitter_roll = roll
Set3DParticlesDirection(p.id, p.dir_vel_x, p.dir_vel_y, p.dir_vel_z, p.dir_emitter_roll)
endfunction
function particle3D_SetColorInterpolation(p ref as _Particle3D, interpolation as integer)
p.color_interpolation = interpolation
Set3DParticlesColorInterpolation(p.id, p.color_interpolation)
endfunction
function particle3D_SetVisible(p ref as _Particle3D, v as integer)
if v < 1 then p.visible = 0 else p.visible = 1
Set3DParticlesVisible(p.id, p.visible)
endfunction
function particle3D_SetParticlesMax(p ref as _Particle3D, count_max as integer)
if count_max < 0 then p.count_max = -1 else p.count_max = count_max
Set3DParticlesMax(p.id, p.count_max)
if p.count_max > -1 then Reset3DParticleCount(p.id)
endfunction
function particle3D_ResetParticleCount(p ref as _Particle3D)
Reset3DParticleCount(p.id)
endfunction
function particle3D_SetStartZone(p ref as _Particle3D, x1 as float, y1 as float, z1 as float, x2 as float, y2 as float, z2 as float)
p.start_zone_x1 = x1
p.start_zone_y1 = y1
p.start_zone_z1 = z1
p.start_zone_x2 = x2
p.start_zone_y2 = y2
p.start_zone_z2 = z2
Set3DParticlesStartZone(p.id, p.start_zone_x1, p.start_zone_y1, p.start_zone_z1, p.start_zone_x2, p.start_zone_y2, p.start_zone_z2)
endfunction
function particle3D_SetImage(p ref as _Particle3D, img_filename as string)
if img_filename = ""
p.img_filename = ""
DeleteImage(p.img_id)
Set3DParticlesImage(p.id, 0)
exitfunction
endif
p.img_id = LoadImage(img_filename)
if p.img_id > 0
p.img_filename = img_filename
Set3DParticlesImage(p.id, p.img_id)
endif
endfunction
function particle3D_SetTrasnparency(p ref as _Particle3D, transparency as integer)
p.transparency = transparency
Set3DParticlesTransparency(p.id, p.transparency)
endfunction
function particle3D_EmitterCreateMesh(p ref as _Particle3D)
p.emitter_mesh = CreateObjectBox(1.0, 1.0, 1.0)
SetObjectTransparency(p.emitter_mesh, 1)
SetObjectColor(p.emitter_mesh, 255, 255, 255, 255)
endfunction
function particle3D_EmitterSetColor(p ref as _Particle3D, r as integer, g as integer, b as integer)
SetObjectColor(p.emitter_mesh, r, g, b, 255)
endfunction
function particle3D_EmitterSetVisibile(p ref as _Particle3D, visible as integer)
SetObjectVisible(p.emitter_mesh, visible)
endfunction
function particle3D_EmitterGetVisibile(p ref as _Particle3D)
v as integer
v = GetObjectVisible(p.emitter_mesh)
endfunction v
function particle3D_EmitterGetMesh(p ref as _Particle3D)
endfunction p.emitter_mesh
function particle3D_GetName(p ref as _Particle3D)
endfunction p.name
function particle3D_GetX(p ref as _Particle3D)
endfunction p.x
function particle3D_GetY(p ref as _Particle3D)
endfunction p.y
function particle3D_GetZ(p ref as _Particle3D)
endfunction p.z
function particle3D_GetImage(p ref as _Particle3D)
endfunction p.img_id
function particle3D_GetImageFilename(p ref as _Particle3D)
endfunction p.img_filename
function particle3D_KeyColorAdd(p ref as _Particle3D, t as float, r as integer, g as integer, b as integer, a as integer)
key_idx as integer
key_color as _Particle3DKeyColor
key_color.time = t
key_color.r = r
key_color.g = g
key_color.b = b
key_color.a = a
p.key_color.insert(key_color)
key_idx = p.key_color.length
Add3DParticlesColorKeyFrame(p.id, t, r, g, b, a)
endfunction
function particle3D_KeyColorRemoveAll(p ref as _Particle3D)
p.key_color.length = -1
Clear3DParticlesColors(p.id)
endfunction
function particle3D_KeyColorGetRed(p ref as _Particle3D, key_idx as integer)
c as integer
if key_idx < 0 or key_idx > p.key_color.length then exitfunction -1
c = p.key_color[key_idx].r
endfunction c
function particle3D_KeyColorGetGreen(p ref as _Particle3D, key_idx as integer)
c as integer
if key_idx < 0 or key_idx > p.key_color.length then exitfunction -1
c = p.key_color[key_idx].g
endfunction c
function particle3D_KeyColorGetBlue(p ref as _Particle3D, key_idx as integer)
c as integer
if key_idx < 0 or key_idx > p.key_color.length then exitfunction -1
c = p.key_color[key_idx].b
endfunction c
function particle3D_KeyColorGetAlpha(p ref as _Particle3D, key_idx as integer)
c as integer
if key_idx < 0 or key_idx > p.key_color.length then exitfunction -1
c = p.key_color[key_idx].a
endfunction c
function particle3D_KeyColorGetCount(p ref as _Particle3D)
l as integer
l = p.key_color.length + 1
endfunction l
The main code is very simple
// Project: p3d
// Created: 2018-08-22
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "p3d" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
#include "particle3d.agc"
myparticles as _Particle3D[]
particle3D_Load(myparticles, "p3d.json")
for i = 0 to myparticles.length
particle3D_Start(myparticles[i])
next i
do
Print( ScreenFPS() )
Sync()
loop
You can find attached some sample images and a p3d.json file
I am glad that many people find it useful