paint: expose physics to script
This commit is contained in:
@@ -453,6 +453,11 @@ config_t *script_get_config();
|
||||
project_t *script_get_project();
|
||||
object_t *script_get_object(char *s);
|
||||
object_t *script_shape_add(char *name);
|
||||
void script_physics_set_shape(object_t *o, i32 shape);
|
||||
void script_physics_set_mass(object_t *o, f32 mass);
|
||||
void script_physics_apply_impulse(object_t *o, f32 x, f32 y, f32 z);
|
||||
void script_physics_set_velocity(object_t *o, f32 x, f32 y, f32 z);
|
||||
void script_physics_sync_transform(object_t *o);
|
||||
void script_draw_particles(gpu_texture_t *texture, float x, float y, float w, float h, int atlas_x, int atlas_frames);
|
||||
void ui_files_show2(char *filters, bool is_save, bool open_multiple, void *files_done);
|
||||
char *project_filepath_get();
|
||||
|
||||
@@ -434,6 +434,7 @@ void minic_register_builtins() {
|
||||
|
||||
MINIC_ENUM("gpu_texture_format_t", "GPU_TEXTURE_FORMAT_RGBA32", "GPU_TEXTURE_FORMAT_RGBA64", "GPU_TEXTURE_FORMAT_RGBA128", "GPU_TEXTURE_FORMAT_R8",
|
||||
"GPU_TEXTURE_FORMAT_R16", "GPU_TEXTURE_FORMAT_R32", "GPU_TEXTURE_FORMAT_D32", "GPU_TEXTURE_FORMAT_RGBA32_BC7");
|
||||
MINIC_ENUM("asim_shape_t", "ASIM_SHAPE_BOX", "ASIM_SHAPE_SPHERE", "ASIM_SHAPE_TERRAIN", "ASIM_SHAPE_MESH");
|
||||
MINIC_ENUM("tool_type_t", "TOOL_TYPE_BRUSH", "TOOL_TYPE_ERASER", "TOOL_TYPE_FILL", "TOOL_TYPE_DECAL", "TOOL_TYPE_TEXT", "TOOL_TYPE_CLONE", "TOOL_TYPE_BLUR",
|
||||
"TOOL_TYPE_PARTICLE", "TOOL_TYPE_COLORID", "TOOL_TYPE_PICKER", "TOOL_TYPE_MATERIAL", "TOOL_TYPE_CURSOR", "TOOL_TYPE_SELECT", "TOOL_TYPE_BAKE");
|
||||
|
||||
@@ -1231,6 +1232,11 @@ void minic_register_builtins() {
|
||||
R(script_get_project, "p()");
|
||||
R(script_get_object, "p(p s)");
|
||||
R(script_shape_add, "p(p name)");
|
||||
R(script_physics_set_shape, "v(p o,i shape)");
|
||||
R(script_physics_set_mass, "v(p o,f mass)");
|
||||
R(script_physics_apply_impulse, "v(p o,f x,f y,f z)");
|
||||
R(script_physics_set_velocity, "v(p o,f x,f y,f z)");
|
||||
R(script_physics_sync_transform, "v(p o)");
|
||||
R(script_set_stage, "v(p name)");
|
||||
R(script_show_envmap, "v(i b)");
|
||||
R(script_fade_to_stage, "v(p stage)");
|
||||
|
||||
@@ -194,9 +194,9 @@ static void script_paint_begin_stroke(void) {
|
||||
history_paint();
|
||||
}
|
||||
|
||||
script_paint_active = true;
|
||||
script_paint_first = true;
|
||||
g_context->brush_time = sys_delta();
|
||||
script_paint_active = true;
|
||||
script_paint_first = true;
|
||||
g_context->brush_time = sys_delta();
|
||||
g_context->prev_paint_vec_x = -1.0f;
|
||||
g_context->prev_paint_vec_y = -1.0f;
|
||||
}
|
||||
@@ -619,6 +619,57 @@ object_t *script_shape_add(char *name) {
|
||||
return mo->base;
|
||||
}
|
||||
|
||||
static asim_body_t *script_physics_body(object_t *o) {
|
||||
return o != NULL && o->_ != NULL ? o->_->body : NULL;
|
||||
}
|
||||
|
||||
void script_physics_set_shape(object_t *o, i32 shape) {
|
||||
if (o == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
asim_body_t *body = script_physics_body(o);
|
||||
if (body != NULL) {
|
||||
asim_body_remove(body);
|
||||
}
|
||||
g_project->mesh_physics_shapes = i32_array_create(0);
|
||||
if (shape < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool dynamic = shape == ASIM_SHAPE_BOX || shape == ASIM_SHAPE_SPHERE;
|
||||
sim_add_body(o, (asim_shape_t)shape, dynamic ? 1.0 : 0.0);
|
||||
}
|
||||
|
||||
void script_physics_set_mass(object_t *o, f32 mass) {
|
||||
asim_body_t *body = script_physics_body(o);
|
||||
if (body != NULL) {
|
||||
asim_body_set_mass(body, mass);
|
||||
g_project->mesh_physics_shapes = i32_array_create(0);
|
||||
}
|
||||
}
|
||||
|
||||
void script_physics_apply_impulse(object_t *o, f32 x, f32 y, f32 z) {
|
||||
asim_body_t *body = script_physics_body(o);
|
||||
if (body != NULL) {
|
||||
asim_body_apply_impulse(body->_body, (vec4_t){x, y, z, 0.0});
|
||||
}
|
||||
}
|
||||
|
||||
void script_physics_set_velocity(object_t *o, f32 x, f32 y, f32 z) {
|
||||
asim_body_t *body = script_physics_body(o);
|
||||
if (body != NULL) {
|
||||
asim_body_set_velocity(body->_body, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
void script_physics_sync_transform(object_t *o) {
|
||||
asim_body_t *body = script_physics_body(o);
|
||||
if (body != NULL) {
|
||||
asim_body_sync_transform(body);
|
||||
}
|
||||
}
|
||||
|
||||
extern string_array_t *_path_texture_formats;
|
||||
extern string_array_t *_path_mesh_formats;
|
||||
extern string_array_t *_path_text_formats;
|
||||
|
||||
Reference in New Issue
Block a user