Cleanup
This commit is contained in:
@@ -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,14 +89,12 @@ 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];
|
||||
for (let j: i32 = 0; j < mat.contexts.length; ++j) {
|
||||
if (mat.contexts[j].name == context) {
|
||||
scontext = shader_data_get_context(mat._.shader, context);
|
||||
mcontext = mat.contexts[j];
|
||||
break;
|
||||
}
|
||||
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);
|
||||
mcontext = mat.contexts[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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[]) {
|
||||
|
||||
+11
-16
@@ -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 mat: material_data_t = data_get_material(scene_name, ref);
|
||||
array_push(materials, mat);
|
||||
}
|
||||
return scene_create_mesh_object(o, format, parent, materials);
|
||||
let ref: string = o.material_ref;
|
||||
let mat: material_data_t = data_get_material(scene_name, ref);
|
||||
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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
},
|
||||
|
||||
@@ -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
|
||||
},
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user