2026-03-09 13:17:15 +01:00
|
|
|
|
|
|
|
|
#include "global.h"
|
|
|
|
|
|
2026-03-06 12:56:38 +01:00
|
|
|
void util_particle_init() {
|
2026-04-05 16:41:00 +02:00
|
|
|
if (g_context->particle_material != NULL) {
|
2026-03-06 12:56:38 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
render_target_t *t = render_target_create();
|
|
|
|
|
t->name = "texparticle";
|
|
|
|
|
t->width = 0;
|
|
|
|
|
t->height = 0;
|
|
|
|
|
t->format = "R8";
|
|
|
|
|
t->scale = render_path_base_get_super_sampling();
|
|
|
|
|
render_path_create_render_target(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i32 i = 0; i < _scene_raw->material_datas->length; ++i) {
|
|
|
|
|
material_data_t *mat = _scene_raw->material_datas->buffer[i];
|
|
|
|
|
if (string_equals(mat->name, "Material2")) {
|
|
|
|
|
material_data_t *m = util_clone_material_data(mat);
|
|
|
|
|
m->name = "MaterialParticle";
|
|
|
|
|
any_array_push(_scene_raw->material_datas, m);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-21 10:52:27 +02:00
|
|
|
material_data_t *md = data_get_material("Scene", "MaterialParticle");
|
2026-04-05 16:41:00 +02:00
|
|
|
g_context->particle_material = md;
|
2026-03-06 12:56:38 +01:00
|
|
|
|
|
|
|
|
for (i32 i = 0; i < _scene_raw->objects->length; ++i) {
|
|
|
|
|
obj_t *obj = _scene_raw->objects->buffer[i];
|
|
|
|
|
if (string_equals(obj->name, ".Sphere")) {
|
|
|
|
|
obj_t *particle = util_clone_obj(obj);
|
|
|
|
|
particle->name = ".Particle";
|
|
|
|
|
particle->material_ref = "MaterialParticle";
|
|
|
|
|
any_array_push(_scene_raw->objects, particle);
|
|
|
|
|
for (i32 i = 0; i < 16; ++i) {
|
|
|
|
|
particle->transform->buffer[i] *= 0.01;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-07 21:12:59 +01:00
|
|
|
object_t *o = scene_spawn_object(".Sphere", NULL, true);
|
2026-03-06 12:56:38 +01:00
|
|
|
mesh_object_t *mo = o->ext;
|
|
|
|
|
mo->base->name = ".ParticleEmitter";
|
|
|
|
|
mo->base->raw = util_clone_obj(mo->base->raw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void util_particle_init_mesh() {
|
2026-04-05 16:41:00 +02:00
|
|
|
if (g_context->paint_body != NULL) {
|
2026-03-06 12:56:38 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-05 16:41:00 +02:00
|
|
|
if (g_context->merged_object == NULL) {
|
2026-03-07 21:12:59 +01:00
|
|
|
util_mesh_merge(NULL);
|
2026-03-06 12:56:38 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 10:52:27 +02:00
|
|
|
mesh_object_t *po = g_context->merged_object;
|
|
|
|
|
po->base->transform->scale.x = po->base->parent->transform->scale.x;
|
|
|
|
|
po->base->transform->scale.y = po->base->parent->transform->scale.y;
|
|
|
|
|
po->base->transform->scale.z = po->base->parent->transform->scale.z;
|
2026-04-05 16:41:00 +02:00
|
|
|
g_context->paint_body = physics_body_create();
|
|
|
|
|
g_context->paint_body->shape = PHYSICS_SHAPE_MESH;
|
|
|
|
|
physics_body_init(g_context->paint_body, po->base);
|
2026-03-06 12:56:38 +01:00
|
|
|
}
|
2026-04-04 21:38:20 +02:00
|
|
|
|
|
|
|
|
void util_particle_init_physics() {
|
|
|
|
|
if (physics_world_active != NULL) {
|
|
|
|
|
util_particle_init_mesh();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
physics_world_create();
|
|
|
|
|
util_particle_init_mesh();
|
|
|
|
|
}
|