Cleanup
This commit is contained in:
@@ -42,17 +42,7 @@ function mesh_data_create(raw: mesh_data_t): mesh_data_t {
|
||||
raw._.vertex_buffer_map = map_create();
|
||||
raw._.ready = false;
|
||||
|
||||
// Mesh data
|
||||
let indices: u32_array_t[] = [];
|
||||
let material_indices: i32[] = [];
|
||||
|
||||
for (let i: i32 = 0; i < raw.index_arrays.length; ++i) {
|
||||
let ind: index_array_t = raw.index_arrays[i];
|
||||
array_push(indices, ind.values);
|
||||
array_push(material_indices, ind.material);
|
||||
}
|
||||
|
||||
// Skinning
|
||||
///if arm_skin
|
||||
// Prepare vertex array for skinning and fill size data
|
||||
let vertex_arrays: vertex_array_t[] = raw.vertex_arrays;
|
||||
if (raw.skin != null) {
|
||||
@@ -95,10 +85,9 @@ function mesh_data_create(raw: mesh_data_t): mesh_data_t {
|
||||
vertex_arrays[vertex_arrays.length - 2].values = bonea;
|
||||
vertex_arrays[vertex_arrays.length - 1].values = weighta;
|
||||
}
|
||||
///end
|
||||
|
||||
// Make vertex buffers
|
||||
raw._.indices = indices;
|
||||
raw._.material_indices = material_indices;
|
||||
raw._.structure = mesh_data_get_vertex_struct(raw.vertex_arrays);
|
||||
|
||||
return raw;
|
||||
@@ -199,8 +188,8 @@ function mesh_data_get(raw: mesh_data_t, vs: vertex_element_t[]): gpu_buffer_t {
|
||||
let vstruct: gpu_vertex_structure_t = mesh_data_get_vertex_struct(vertex_arrays);
|
||||
let size: i32 = mesh_data_get_vertex_size(positions.data);
|
||||
vb = gpu_create_vertex_buffer(math_floor(positions.values.length / size), vstruct);
|
||||
raw._.vertices = gpu_lock_vertex_buffer(vb);
|
||||
mesh_data_build_vertices(raw._.vertices, vertex_arrays, 0, has_tex && uvs == null, tex_offset);
|
||||
let vertices: buffer_t = gpu_lock_vertex_buffer(vb);
|
||||
mesh_data_build_vertices(vertices, vertex_arrays, 0, has_tex && uvs == null, tex_offset);
|
||||
gpu_vertex_buffer_unlock(vb);
|
||||
map_set(raw._.vertex_buffer_map, key, vb);
|
||||
if (has_tex && uvs == null) {
|
||||
@@ -221,8 +210,8 @@ function mesh_data_build(raw: mesh_data_t) {
|
||||
let positions: vertex_array_t = mesh_data_get_vertex_array(raw, "pos");
|
||||
let size: i32 = mesh_data_get_vertex_size(positions.data);
|
||||
raw._.vertex_buffer = gpu_create_vertex_buffer(math_floor(positions.values.length / size), raw._.structure);
|
||||
raw._.vertices = gpu_lock_vertex_buffer(raw._.vertex_buffer);
|
||||
mesh_data_build_vertices(raw._.vertices, raw.vertex_arrays);
|
||||
let vertices: buffer_t = gpu_lock_vertex_buffer(raw._.vertex_buffer);
|
||||
mesh_data_build_vertices(vertices, raw.vertex_arrays);
|
||||
gpu_vertex_buffer_unlock(raw._.vertex_buffer);
|
||||
|
||||
let struct_str: string = "";
|
||||
@@ -234,18 +223,13 @@ function mesh_data_build(raw: mesh_data_t) {
|
||||
|
||||
raw._.index_buffers = [];
|
||||
|
||||
for (let i: i32 = 0; i < raw._.indices.length; ++i) {
|
||||
let id: u32_array_t = raw._.indices[i];
|
||||
if (id.length == 0) {
|
||||
continue;
|
||||
}
|
||||
for (let i: i32 = 0; i < raw.index_arrays.length; ++i) {
|
||||
let id: u32_array_t = raw.index_arrays[i].values;
|
||||
let index_buffer: gpu_buffer_t = gpu_create_index_buffer(id.length);
|
||||
|
||||
let indices_array: u32_array_t = gpu_lock_index_buffer(index_buffer);
|
||||
for (let i: i32 = 0; i < indices_array.length; ++i) {
|
||||
indices_array[i] = id[i];
|
||||
}
|
||||
|
||||
gpu_index_buffer_unlock(index_buffer);
|
||||
array_push(raw._.index_buffers, index_buffer);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ type mesh_object_t = {
|
||||
base?: object_t;
|
||||
data?: mesh_data_t;
|
||||
materials?: material_data_t[];
|
||||
material_index?: i32;
|
||||
camera_dist?: f32;
|
||||
screen_size?: f32;
|
||||
frustum_culling?: bool;
|
||||
@@ -17,7 +16,6 @@ let _mesh_object_shader_contexts: shader_context_t[] = [];
|
||||
|
||||
function mesh_object_create(data: mesh_data_t, materials: material_data_t[]): mesh_object_t {
|
||||
let raw: mesh_object_t = {};
|
||||
raw.material_index = 0;
|
||||
raw.screen_size = 0.0;
|
||||
raw.frustum_culling = true;
|
||||
raw.base = object_create(false);
|
||||
@@ -154,35 +152,21 @@ function mesh_object_render(raw: mesh_object_t, context: string, bind_params: st
|
||||
transform_update(raw.base.transform);
|
||||
|
||||
// Render mesh
|
||||
for (let i: i32 = 0; i < raw.data._.index_buffers.length; ++i) {
|
||||
let scontext: shader_context_t = shader_contexts[0];
|
||||
let elems: vertex_element_t[] = scontext.vertex_elements;
|
||||
|
||||
let mi: i32 = raw.data._.material_indices[i];
|
||||
if (shader_contexts.length <= mi || shader_contexts[mi] == null) {
|
||||
continue;
|
||||
}
|
||||
raw.material_index = mi;
|
||||
|
||||
let scontext: shader_context_t = shader_contexts[mi];
|
||||
if (scontext == null) {
|
||||
continue;
|
||||
}
|
||||
let elems: vertex_element_t[] = scontext.vertex_elements;
|
||||
|
||||
// Uniforms
|
||||
if (scontext._.pipe_state != _mesh_object_last_pipeline) {
|
||||
gpu_set_pipeline(scontext._.pipe_state);
|
||||
_mesh_object_last_pipeline = scontext._.pipe_state;
|
||||
}
|
||||
uniforms_set_context_consts(scontext, bind_params);
|
||||
uniforms_set_obj_consts(scontext, raw.base);
|
||||
if (material_contexts.length > mi) {
|
||||
uniforms_set_material_consts(scontext, material_contexts[mi]);
|
||||
}
|
||||
|
||||
gpu_set_vertex_buffer(mesh_data_get(raw.data, elems));
|
||||
gpu_set_index_buffer(raw.data._.index_buffers[i]);
|
||||
gpu_draw();
|
||||
// Uniforms
|
||||
if (scontext._.pipe_state != _mesh_object_last_pipeline) {
|
||||
gpu_set_pipeline(scontext._.pipe_state);
|
||||
_mesh_object_last_pipeline = scontext._.pipe_state;
|
||||
}
|
||||
uniforms_set_context_consts(scontext, bind_params);
|
||||
uniforms_set_obj_consts(scontext, raw.base);
|
||||
uniforms_set_material_consts(scontext, material_contexts[0]);
|
||||
|
||||
gpu_set_vertex_buffer(mesh_data_get(raw.data, elems));
|
||||
gpu_set_index_buffer(raw.data._.index_buffers[0]);
|
||||
gpu_draw();
|
||||
}
|
||||
|
||||
function mesh_object_valid_context(raw: mesh_object_t, mats: material_data_t[], context: string): bool {
|
||||
|
||||
@@ -479,9 +479,6 @@ type mesh_data_runtime_t = {
|
||||
vertex_buffer_map?: map_t<string, gpu_buffer_t>;
|
||||
index_buffers?: gpu_buffer_t[];
|
||||
ready?: bool;
|
||||
vertices?: buffer_t;
|
||||
indices?: u32_array_t[];
|
||||
material_indices?: i32[];
|
||||
structure?: gpu_vertex_structure_t;
|
||||
///if arm_skin
|
||||
skeleton_transforms_inv?: mat4_t[];
|
||||
|
||||
@@ -588,7 +588,7 @@ 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[mo.material_index];
|
||||
return mo.materials[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -57,8 +57,7 @@ function physics_body_init(body: physics_body_t, obj: object_t) {
|
||||
let scale: vec4_t = obj.transform.scale;
|
||||
|
||||
let positions: i16_array_t = mesh_data_get_vertex_array(data, "pos").values;
|
||||
let indices: u32_array_t[] = data._.indices;
|
||||
let indices0: u32_array_t = indices[0];
|
||||
let indices0: u32_array_t = data.index_arrays[0].values;
|
||||
|
||||
scale_pos = scale.x * data.scale_pos;
|
||||
posa = positions;
|
||||
|
||||
@@ -56,7 +56,6 @@ function plugin_uv_unwrap_button() {
|
||||
md.vertex_arrays[1].values = mesh.nora;
|
||||
md.vertex_arrays[2].values = mesh.texa;
|
||||
md.index_arrays[0].values = mesh.inda;
|
||||
md._.indices[0] = mesh.inda;
|
||||
md._.ready = false;
|
||||
mesh_data_build(md);
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ function util_mesh_calc_normals(smooth: bool = false) {
|
||||
let o: mesh_object_t = objects[i];
|
||||
let g: mesh_data_t = o.data;
|
||||
let l: i32 = gpu_vertex_struct_size(g._.structure) / 2;
|
||||
let inda: u32_array_t = g._.indices[0];
|
||||
let inda: u32_array_t = g.index_arrays[0].values;
|
||||
let vertices: buffer_t = gpu_lock_vertex_buffer(g._.vertex_buffer); // posnortex
|
||||
for (let i: i32 = 0; i < math_floor(inda.length / 3); ++i) {
|
||||
let i1: i32 = inda[i * 3 ];
|
||||
|
||||
@@ -97,7 +97,8 @@ function ui_nodes_ext_run() {
|
||||
if (ui_nodes_ext_last_vertices == null || ui_nodes_ext_last_vertices.length != vertices.length) {
|
||||
ui_nodes_ext_last_vertices = buffer_create(vertices.length);
|
||||
for (let i: i32 = 0; i < math_floor((vertices.length) / 2); ++i) {
|
||||
buffer_set_i16(ui_nodes_ext_last_vertices, i * 2, buffer_get_i16(vertices, i * 2));
|
||||
// buffer_set_i16(ui_nodes_ext_last_vertices, i * 2, buffer_get_i16(vertices, i * 2)); ////
|
||||
buffer_set_i16(ui_nodes_ext_last_vertices, i * 2, buffer_get_i16(g._.vertices, i * 2));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user