This commit is contained in:
luboslenco
2025-09-02 19:32:15 +02:00
parent c5317d8e14
commit 107394ba3a
25 changed files with 60 additions and 80 deletions
+7 -15
View File
@@ -2,7 +2,7 @@
type mesh_object_t = {
base?: object_t;
data?: mesh_data_t;
materials?: material_data_t[];
material?: material_data_t;
camera_dist?: f32;
frustum_culling?: bool;
skip_context?: string; // Do not draw this context
@@ -11,14 +11,14 @@ type mesh_object_t = {
let _mesh_object_last_pipeline: gpu_pipeline_t = null;
function mesh_object_create(data: mesh_data_t, materials: material_data_t[]): mesh_object_t {
function mesh_object_create(data: mesh_data_t, material: material_data_t): mesh_object_t {
let raw: mesh_object_t = {};
raw.frustum_culling = true;
raw.base = object_create(false);
raw.base.ext = raw;
raw.base.ext_type = "mesh_object_t";
raw.materials = materials;
raw.material = material;
mesh_object_set_data(raw, data);
array_push(scene_meshes, raw);
return raw;
@@ -43,7 +43,7 @@ function mesh_object_setup_animation(raw: mesh_object_t, oactions: scene_t[] = n
function mesh_object_cull_material(raw: mesh_object_t, context: string): bool {
// Skip render if material does not contain current context
if (!mesh_object_valid_context(raw, raw.materials, context)) {
if (!mesh_object_valid_context(raw, raw.material, context)) {
raw.base.culled = true;
return true;
}
@@ -89,8 +89,7 @@ function mesh_object_render(raw: mesh_object_t, context: string, bind_params: st
let scontext: shader_context_t = null;
let mcontext: material_context_t = null;
for (let i: i32 = 0; i < raw.materials.length; ++i) {
let mat: material_data_t = raw.materials[i];
let mat: material_data_t = raw.material;
for (let j: i32 = 0; j < mat.contexts.length; ++j) {
if (mat.contexts[j].name == context) {
scontext = shader_data_get_context(mat._.shader, context);
@@ -98,7 +97,6 @@ function mesh_object_render(raw: mesh_object_t, context: string, bind_params: st
break;
}
}
}
if (scontext._.pipe != _mesh_object_last_pipeline) {
gpu_set_pipeline(scontext._.pipe);
@@ -112,14 +110,8 @@ function mesh_object_render(raw: mesh_object_t, context: string, bind_params: st
gpu_draw();
}
function mesh_object_valid_context(raw: mesh_object_t, mats: material_data_t[], context: string): bool {
for (let i: i32 = 0; i < mats.length; ++i) {
let mat: material_data_t = mats[i];
if (material_data_get_context(mat, context) != null) {
return true;
}
}
return false;
function mesh_object_valid_context(raw: mesh_object_t, mat: material_data_t, context: string): bool {
return material_data_get_context(mat, context) != null;
}
function mesh_object_compute_camera_dist(raw: mesh_object_t, cam_x: f32, cam_y: f32, cam_z: f32) {
+1 -1
View File
@@ -116,7 +116,7 @@ function render_path_sort_meshes_dist(meshes: mesh_object_t[]) {
function _render_path_sort_shader(a: any_ptr, b: any_ptr): i32 {
let ma: mesh_object_t = DEREFERENCE(a);
let mb: mesh_object_t = DEREFERENCE(b);
return strcmp(ma.materials[0].name, mb.materials[0].name);
return strcmp(ma.material.name, mb.material.name);
}
function render_path_sort_meshes_shader(meshes: mesh_object_t[]) {
+10 -15
View File
@@ -156,8 +156,8 @@ function scene_get_empty(name: string): object_t {
return null;
}
function scene_add_mesh_object(data: mesh_data_t, materials: material_data_t[], parent: object_t = null): mesh_object_t {
let object: mesh_object_t = mesh_object_create(data, materials);
function scene_add_mesh_object(data: mesh_data_t, material: material_data_t, parent: object_t = null): mesh_object_t {
let object: mesh_object_t = mesh_object_create(data, material);
parent != null ? object_set_parent(object.base, parent) : object_set_parent(object.base, _scene_root);
return object;
}
@@ -269,18 +269,13 @@ function scene_create_object(o: obj_t, format: scene_t, parent: object_t): objec
return scene_return_object(object.base, o);
}
else if (o.type == "mesh_object") {
if (o.material_refs == null || o.material_refs.length == 0) {
if (o.material_ref == null) {
return scene_create_mesh_object(o, format, parent, null);
}
else {
// Materials
let materials: material_data_t[] = [];
for (let i: i32 = 0; i < o.material_refs.length; ++i) {
let ref: string = o.material_refs[i];
let ref: string = o.material_ref;
let mat: material_data_t = data_get_material(scene_name, ref);
array_push(materials, mat);
}
return scene_create_mesh_object(o, format, parent, materials);
return scene_create_mesh_object(o, format, parent, mat);
}
}
///if arm_audio
@@ -298,7 +293,7 @@ function scene_create_object(o: obj_t, format: scene_t, parent: object_t): objec
}
}
function scene_create_mesh_object(o: obj_t, format: scene_t, parent: object_t, materials: material_data_t[]): object_t {
function scene_create_mesh_object(o: obj_t, format: scene_t, parent: object_t, material: material_data_t): object_t {
// Mesh reference
let ref: string[] = string_split(o.data_ref, "/");
let object_file: string = "";
@@ -313,12 +308,12 @@ function scene_create_mesh_object(o: obj_t, format: scene_t, parent: object_t, m
data_ref = o.data_ref;
}
return scene_return_mesh_object(object_file, data_ref, materials, parent, o);
return scene_return_mesh_object(object_file, data_ref, material, parent, o);
}
function scene_return_mesh_object(object_file: string, data_ref: string, materials: material_data_t[], parent: object_t, o: obj_t): object_t {
function scene_return_mesh_object(object_file: string, data_ref: string, material: material_data_t, parent: object_t, o: obj_t): object_t {
let mesh: mesh_data_t = data_get_mesh(object_file, data_ref);
let object: mesh_object_t = scene_add_mesh_object(mesh, materials, parent);
let object: mesh_object_t = scene_add_mesh_object(mesh, material, parent);
return scene_return_object(object.base, o);
}
@@ -563,7 +558,7 @@ type obj_t = {
visible?: bool;
spawn?: bool; // Auto add object when creating scene
anim?: anim_t; // Object animation
material_refs?: string[];
material_ref?: string;
children?: obj_t[];
_?: obj_runtime_t;
};
+1 -3
View File
@@ -580,9 +580,7 @@ function uniforms_set_material_consts(context: shader_context_t, material_contex
function current_material(object: object_t): material_data_t {
if (object != null && object.ext != null) {
let mo: mesh_object_t = object.ext;
if (mo.materials != null) {
return mo.materials[0];
}
return mo.material;
}
return null;
}
+1 -1
View File
@@ -32,7 +32,7 @@ function ready() {
name: "Cube",
type: "mesh_object",
data_ref: "cube.arm/Cube",
material_refs: ["MyMaterial"],
material_ref: "MyMaterial",
visible: true,
spawn: true
},
+2 -2
View File
@@ -36,7 +36,7 @@ function ready() {
name: "Cube",
type: "mesh_object",
data_ref: "cube.arm/Cube",
material_refs: ["MyMaterial"],
material_ref: "MyMaterial",
visible: true,
spawn: true
},
@@ -44,7 +44,7 @@ function ready() {
name: "Sphere",
type: "mesh_object",
data_ref: "sphere.arm/Sphere",
material_refs: ["MyMaterial"],
material_ref: "MyMaterial",
visible: true,
spawn: true
},
+1 -1
View File
@@ -125,7 +125,7 @@ class ArmoryExporter(bpy.types.Operator, ExportHelper):
o["visible"] = True
o["spawn"] = True
o["anim"] = None
o["material_refs"] = None
o["material_ref"] = None
o["children"] = None
if bobjectRef["objectType"] == NodeTypeMesh:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2 -2
View File
@@ -138,7 +138,7 @@ function import_arm_run_project(path: string) {
for (let i: i32 = 1; i < project.mesh_datas.length; ++i) {
let raw: mesh_data_t = project.mesh_datas[i];
let md: mesh_data_t = mesh_data_create(raw);
let object: mesh_object_t = scene_add_mesh_object(md, context_raw.paint_object.materials, context_raw.paint_object.base);
let object: mesh_object_t = scene_add_mesh_object(md, context_raw.paint_object.material, context_raw.paint_object.base);
object.base.name = md.name;
object.skip_context = "paint";
array_push(project_paint_objects, object);
@@ -358,7 +358,7 @@ function import_arm_run_mesh(raw: project_format_t) {
object = context_raw.paint_object;
}
else {
object = scene_add_mesh_object(md, context_raw.paint_object.materials, context_raw.paint_object.base);
object = scene_add_mesh_object(md, context_raw.paint_object.material, context_raw.paint_object.base);
object.base.name = md.name;
object.skip_context = "paint";
md._.handle = md.name;
+1 -1
View File
@@ -206,7 +206,7 @@ function _import_mesh_add_mesh(mesh: raw_mesh_t) {
let md: mesh_data_t = mesh_data_create(raw);
let object: mesh_object_t = scene_add_mesh_object(md, context_raw.paint_object.materials, context_raw.paint_object.base);
let object: mesh_object_t = scene_add_mesh_object(md, context_raw.paint_object.material, context_raw.paint_object.base);
object.base.name = mesh.name;
object.skip_context = "paint";
+19 -24
View File
@@ -192,41 +192,35 @@ function project_new(reset_layers: bool = true) {
project_mesh_assets = [];
let raw: mesh_data_t = null;
// if (context_raw.project_type == project_model_t.SPHERE || context_raw.project_type == project_model_t.TESSELLATED_PLANE) {
// let mesh: raw_mesh_t = context_raw.project_type == project_model_t.SPHERE ?
// geom_make_uv_sphere(1, 512, 256) :
// geom_make_plane(1, 1, 512, 512);
// mesh.name = "Tessellated";
// raw = import_mesh_raw_mesh(mesh);
// }
// else {
if (project_mesh_list == null) {
project_mesh_list = ["box_bevel"];
}
let mesh_name: string = project_mesh_list == null ? "box_bevel" : project_mesh_list[context_raw.project_type];
let b: buffer_t = data_get_blob("meshes/" + project_mesh_list[context_raw.project_type] + ".arm");
if (mesh_name == "sphere") {
let mesh: raw_mesh_t = geom_make_uv_sphere(1, 512, 256);
mesh.name = "Tessellated";
raw = import_mesh_raw_mesh(mesh);
}
else if (mesh_name == "plane") {
let mesh: raw_mesh_t = geom_make_plane(1, 1, 512, 512);
mesh.name = "Tessellated";
raw = import_mesh_raw_mesh(mesh);
viewport_set_view(0, 0, 0.75, 0, 0, 0); // Top
}
else {
let b: buffer_t = data_get_blob("meshes/" + mesh_name + ".arm");
_project_scene_mesh_gc = armpack_decode(b);
raw = _project_scene_mesh_gc.mesh_datas[0];
// }
}
let md: mesh_data_t = mesh_data_create(raw);
map_set(data_cached_meshes, "SceneTessellated", md);
// if (context_raw.project_type == project_model_t.TESSELLATED_PLANE) {
// viewport_set_view(0, 0, 0.75, 0, 0, 0); // Top
// }
let n: string = "Tessellated";
// let md: mesh_data_t = data_get_mesh("Scene", n);
let current: gpu_texture_t = _draw_current;
let in_use: bool = gpu_in_use;
if (in_use) draw_end();
let m: material_data_t = data_get_material("Scene", "Material");
if (context_raw.paint_object == null) {
let ms: material_data_t[] = [m];
context_raw.paint_object = mesh_object_create(md, ms);
context_raw.paint_object = mesh_object_create(md, m);
context_raw.paint_object.base.name = "paint_object";
}
else {
@@ -239,7 +233,7 @@ function project_new(reset_layers: bool = true) {
context_raw.paint_object.base.transform.scale = vec4_create(1, 1, 1);
transform_build_matrix(context_raw.paint_object.base.transform);
context_raw.paint_object.base.name = n;
context_raw.paint_object.base.name = "Tessellated";
project_paint_objects = [context_raw.paint_object];
while (project_materials.length > 0) {
slot_material_unload(array_pop(project_materials));
@@ -274,7 +268,8 @@ function project_new(reset_layers: bool = true) {
ui_base_hwnds[tab_area_t.SIDEBAR1].redraws = 2;
if (reset_layers) {
let aspect_ratio_changed: bool = project_layers[0].texpaint.width != config_get_texture_res_x() || project_layers[0].texpaint.height != config_get_texture_res_y();
let aspect_ratio_changed: bool = project_layers[0].texpaint.width != config_get_texture_res_x() ||
project_layers[0].texpaint.height != config_get_texture_res_y();
while (project_layers.length > 0) {
slot_layer_unload(array_pop(project_layers));
}
+2 -2
View File
@@ -760,8 +760,8 @@ function render_path_paint_set_plane_mesh() {
};
let md: mesh_data_t = mesh_data_create(raw);
let mo: mesh_object_t = scene_get_child(".Plane").ext;
let materials: material_data_t[] = mo.materials;
let o: mesh_object_t = scene_add_mesh_object(md, materials);
let material: material_data_t = mo.material;
let o: mesh_object_t = scene_add_mesh_object(md, material);
o.base.name = ".PlaneTiled";
}
+1 -1
View File
@@ -103,7 +103,7 @@ function sim_remove_body(uid: i32) {
function sim_duplicate() {
// Mesh
let so: mesh_object_t = context_raw.selected_object.ext;
let dup: mesh_object_t = scene_add_mesh_object(so.data, so.materials, so.base.parent);
let dup: mesh_object_t = scene_add_mesh_object(so.data, so.material, so.base.parent);
transform_set_matrix(dup.base.transform, so.base.transform.local);
array_push(project_paint_objects, dup);
dup.base.name = so.base.name;
+2 -2
View File
@@ -350,7 +350,7 @@ function tab_meshes_set_default_mesh(name: string) {
scale_tex: mesh.scale_tex
};
let md: mesh_data_t = mesh_data_create(raw);
mo = mesh_object_create(md, context_raw.paint_object.materials);
mo = mesh_object_create(md, context_raw.paint_object.material);
array_remove(scene_meshes, mo);
mo.base.name = "Tessellated";
}
@@ -505,7 +505,7 @@ function tab_scene_new_object(mesh_name: string) {
util_mesh_ext_pack_uvs(raw.mesh_datas[0].vertex_arrays[2].values);
let md: mesh_data_t = mesh_data_create(raw.mesh_datas[0]);
md._.handle = md.name;
let mo: mesh_object_t = scene_add_mesh_object(md, project_paint_objects[0].materials);
let mo: mesh_object_t = scene_add_mesh_object(md, project_paint_objects[0].material);
mo.base.name = md.name;
let o: obj_t = {};
o._ = { _gc: raw };
+1 -1
View File
@@ -327,7 +327,7 @@ function util_clone_obj(o: obj_t): obj_t {
r.visible = o.visible;
r.spawn = o.spawn;
r.anim = util_clone_anim(o.anim);
r.material_refs = util_clone_string_array(o.material_refs);
r.material_ref = o.material_ref;
if (o.children != null) {
r.children = [];
for (let i: i32 = 0; i < o.children.length; ++i) {
+1 -1
View File
@@ -114,7 +114,7 @@ function util_mesh_merge(paint_objects: mesh_object_t[] = null) {
util_mesh_remove_merged();
let md: mesh_data_t = mesh_data_create(raw);
context_raw.merged_object = mesh_object_create(md, context_raw.paint_object.materials);
context_raw.merged_object = mesh_object_create(md, context_raw.paint_object.material);
context_raw.merged_object.base.name = context_raw.paint_object.base.name + "_merged";
context_raw.merged_object.force_context = "paint";
object_set_parent(context_raw.merged_object.base, context_main_object().base);
+1 -1
View File
@@ -32,7 +32,7 @@ function util_particle_init() {
if (obj.name == ".Sphere") {
let particle: obj_t = util_clone_obj(obj);
particle.name = ".Particle";
particle.material_refs = ["MaterialParticle"];
particle.material_ref = "MaterialParticle";
array_push(_scene_raw.objects, particle);
for (let i: i32 = 0; i < 16; ++i) {
particle.transform[i] *= 0.01;
+1 -1
View File
@@ -16,7 +16,7 @@ function util_render_make_material_preview() {
let painto: mesh_object_t = context_raw.paint_object;
context_raw.paint_object = sphere;
sphere.materials[0] = project_materials[0].data;
sphere.material = project_materials[0].data;
context_raw.material.preview_ready = true;
context_raw.saved_camera = mat4_clone(scene_camera.base.transform.local);