Merge forge

This commit is contained in:
luboslenco
2025-08-14 21:45:07 +02:00
parent a3b3a7d591
commit 6d6ad5fb89
12 changed files with 85 additions and 85 deletions
-7
View File
@@ -415,14 +415,7 @@ function context_create(): context_t {
c.brush_opacity = 1.0;
c.brush_opacity_handle = ui_handle_create();
c.brush_opacity_handle.value = 1.0;
///if is_forge
let atlas_w: i32 = config_get_scene_atlas_res();
let item_w: i32 = config_get_layer_res();
let atlas_stride: i32 = atlas_w / item_w;
c.brush_scale = atlas_stride;
///else
c.brush_scale = 1.0;
///end
c.brush_angle = 0.0;
c.brush_angle_handle = ui_handle_create();
c.brush_angle_handle.value = 0.0;
+1 -3
View File
@@ -17,11 +17,9 @@ function gizmo_update() {
let paint_object: object_t = context_raw.paint_object.base;
///if is_forge
if (context_raw.selected_object != null) {
if (context_raw.tool == tool_type_t.GIZMO && context_raw.selected_object != null) {
paint_object = context_raw.selected_object;
}
///end
if (is_object) {
gizmo.transform.loc = vec4_clone(paint_object.transform.loc);
+7 -5
View File
@@ -29,11 +29,13 @@ function import_asset_run(path: string, drop_x: f32 = -1.0, drop_y: f32 = -1.0,
}
if (path_is_mesh(path)) {
///if is_forge
project_import_mesh_box(path, false, false, tab_meshes_import_mesh_done);
///else
show_box ? project_import_mesh_box(path) : import_mesh_run(path);
///end
if (context_raw.tool == tool_type_t.GIZMO) {
// project_import_mesh_box(path, false, false, tab_meshes_import_mesh_done);
project_import_mesh_box(path, false, false, tab_scene_import_mesh_done);
}
else {
show_box ? project_import_mesh_box(path) : import_mesh_run(path);
}
if (drop_x > 0) {
ui_box_click_to_hide = false; // Prevent closing when going back to window after drag and drop
}
+3 -3
View File
@@ -216,9 +216,9 @@ function _import_mesh_number_ext(i: i32): string {
function _import_mesh_add_mesh(mesh: raw_mesh_t) {
let raw: mesh_data_t = import_mesh_raw_mesh(mesh);
///if is_forge
util_mesh_ext_pack_uvs(mesh.texa);
///end
if (context_raw.tool == tool_type_t.GIZMO) {
util_mesh_ext_pack_uvs(mesh.texa);
}
let md: mesh_data_t = mesh_data_create(raw);
-2
View File
@@ -159,7 +159,6 @@ function transform_compute_radius(raw: transform_t) {
}
function transform_compute_dim(raw: transform_t) {
///if is_forge
if (raw.object.raw == null && raw.object.ext_type == "mesh_object_t") {
let mo: mesh_object_t = raw.object.ext;
let aabb: vec4_t = mesh_data_calculate_aabb(mo.data);
@@ -167,7 +166,6 @@ function transform_compute_dim(raw: transform_t) {
o.raw = {};
o.raw.dimensions = f32_array_create_xyz(aabb.x, aabb.y, aabb.z);
}
///end
if (raw.object.raw == null || raw.object.raw.dimensions == null) {
raw.dim = vec4_create(2 * raw.scale.x, 2 * raw.scale.y, 2 * raw.scale.z);
+3 -3
View File
@@ -510,9 +510,9 @@ function layers_new_group(): slot_layer_t {
}
function layers_create_fill_layer(uv_type: uv_type_t = uv_type_t.UVMAP, decal_mat: mat4_t = mat4nan, position: i32 = -1) {
///if is_forge
return;
///end
if (context_raw.tool == tool_type_t.GIZMO) {
return;
}
_layers_uv_type = uv_type;
_layers_decal_mat = decal_mat;
+22 -20
View File
@@ -31,9 +31,9 @@ function render_path_raytrace_commands(use_live_layer: bool) {
render_path_raytrace_ready = true;
render_path_raytrace_is_bake = false;
let ext: string = "";
///if is_forge
ext = "forge_";
///end
if (context_raw.tool == tool_type_t.GIZMO) {
ext = "forge_";
}
let mode: string = config_raw.pathtrace_mode == pathtrace_mode_t.FAST ? "core" : "full";
render_path_raytrace_raytrace_init("raytrace_brute_" + ext + mode + render_path_raytrace_ext);
render_path_raytrace_last_envmap = null;
@@ -135,9 +135,9 @@ function render_path_raytrace_commands(use_live_layer: bool) {
// context_raw.ddirty = 1; // _RENDER
///if is_forge
context_raw.ddirty = 1;
///end
if (context_raw.tool == tool_type_t.GIZMO) {
context_raw.ddirty = 1;
}
}
function render_path_raytrace_raytrace_init(shader_name: string, build: bool = true, bake: bool = false) {
@@ -158,17 +158,18 @@ function render_path_raytrace_raytrace_init(shader_name: string, build: bool = t
{
iron_raytrace_as_init();
///if is_forge
for (let i: i32 = 0; i < project_paint_objects.length; ++i) {
let po: mesh_object_t = project_paint_objects[i];
if (!po.base.visible) {
continue;
if (context_raw.tool == tool_type_t.GIZMO) {
for (let i: i32 = 0; i < project_paint_objects.length; ++i) {
let po: mesh_object_t = project_paint_objects[i];
if (!po.base.visible) {
continue;
}
iron_raytrace_as_add(po.data._.vertex_buffer, po.data._.index_buffer, po.base.transform.world_unpack);
}
iron_raytrace_as_add(po.data._.vertex_buffer, po.data._.index_buffer, po.base.transform.world_unpack);
}
///else
iron_raytrace_as_add(render_path_raytrace_vb, render_path_raytrace_ib, render_path_raytrace_transform);
///end
else {
iron_raytrace_as_add(render_path_raytrace_vb, render_path_raytrace_ib, render_path_raytrace_transform);
}
let vb_full: gpu_buffer_t = context_raw.merged_object.data._.vertex_buffer;
let ib_full: gpu_buffer_t = context_raw.merged_object.data._.index_buffer;
@@ -188,11 +189,12 @@ function render_path_raytrace_build_data(bake: bool = false) {
let mo: mesh_object_t = scene_meshes[0];
///end
///if is_forge
render_path_raytrace_transform = mo.base.transform.world_unpack;
///else
render_path_raytrace_transform = mat4_identity();
///end
if (context_raw.tool == tool_type_t.GIZMO) {
render_path_raytrace_transform = mo.base.transform.world_unpack;
}
else {
render_path_raytrace_transform = mat4_identity();
}
if (!bake) {
let sc: f32 = mo.base.transform.scale.x * mo.data.scale_pos;
+7
View File
@@ -101,6 +101,13 @@ function uniforms_ext_f32_link(object: object_t, mat: material_data_t, link: str
return val;
}
else if (link == "_brush_scale") {
if (context_raw.tool == tool_type_t.GIZMO) {
let atlas_w: i32 = config_get_scene_atlas_res();
let item_w: i32 = config_get_layer_res();
let atlas_stride: i32 = atlas_w / item_w;
return atlas_stride;
}
let fill: bool = context_raw.layer.fill_layer != null;
let val: f32 = (fill ? context_raw.layer.scale : context_raw.brush_scale) * context_raw.brush_nodes_scale;
return val;
+6 -5
View File
@@ -3,11 +3,12 @@ let util_mesh_unwrappers: map_t<string, any> = map_create(); // JSValue * -> ((a
function util_mesh_merge(paint_objects: mesh_object_t[] = null) {
if (paint_objects == null) {
///if is_forge
paint_objects = util_mesh_ext_get_unique();
///else
paint_objects = project_paint_objects;
///end
if (context_raw.tool == tool_type_t.GIZMO) {
paint_objects = util_mesh_ext_get_unique();
}
else {
paint_objects = project_paint_objects;
}
}
if (paint_objects.length == 0) {
return;
+23 -22
View File
@@ -52,28 +52,29 @@ function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t
draw_set_pipeline(null);
draw_end();
///if is_forge
// Do not multiply basecol by alpha
draw_begin(layers_expa); // Copy to temp
draw_set_pipeline(pipes_copy);
draw_image(l1.texpaint, 0, 0);
draw_set_pipeline(null);
draw_end();
///else
_gpu_begin(layers_expa);
gpu_set_pipeline(pipes_merge);
gpu_set_texture(pipes_tex0, l1.texpaint);
gpu_set_texture(pipes_tex1, empty);
gpu_set_texture(pipes_texmask, mask);
gpu_set_texture(pipes_texa, layers_temp_image);
gpu_set_float(pipes_opac, slot_layer_get_opacity(l1));
gpu_set_float(pipes_tex1w, empty.width);
gpu_set_int(pipes_blending, layers.length > 1 ? l1.blending : 0);
gpu_set_vertex_buffer(const_data_screen_aligned_vb);
gpu_set_index_buffer(const_data_screen_aligned_ib);
gpu_draw();
gpu_end();
///end
if (context_raw.tool == tool_type_t.GIZMO) {
// Do not multiply basecol by alpha
draw_begin(layers_expa); // Copy to temp
draw_set_pipeline(pipes_copy);
draw_image(l1.texpaint, 0, 0);
draw_set_pipeline(null);
draw_end();
}
else {
_gpu_begin(layers_expa);
gpu_set_pipeline(pipes_merge);
gpu_set_texture(pipes_tex0, l1.texpaint);
gpu_set_texture(pipes_tex1, empty);
gpu_set_texture(pipes_texmask, mask);
gpu_set_texture(pipes_texa, layers_temp_image);
gpu_set_float(pipes_opac, slot_layer_get_opacity(l1));
gpu_set_float(pipes_tex1w, empty.width);
gpu_set_int(pipes_blending, layers.length > 1 ? l1.blending : 0);
gpu_set_vertex_buffer(const_data_screen_aligned_vb);
gpu_set_index_buffer(const_data_screen_aligned_ib);
gpu_draw();
gpu_end();
}
}
if (l1.paint_nor) {
+13 -11
View File
@@ -250,13 +250,14 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad
node_shader_write_frag(kong, "var height: float = " + height + ";");
node_shader_write_frag(kong, "var mat_opacity: float = " + opac + ";");
node_shader_write_frag(kong, "var opacity: float = mat_opacity;");
///if is_forge
node_shader_write_frag(kong, "opacity = 1.0;");
///else
if (context_raw.layer.fill_layer == null) {
node_shader_write_frag(kong, "opacity *= constants.brush_opacity;");
if (context_raw.tool == tool_type_t.GIZMO) {
node_shader_write_frag(kong, "opacity = 1.0;");
}
else {
if (context_raw.layer.fill_layer == null) {
node_shader_write_frag(kong, "opacity *= constants.brush_opacity;");
}
}
///end
if (context_raw.material.paint_emis) {
node_shader_write_frag(kong, "var emis: float = " + emis + ";");
}
@@ -441,11 +442,12 @@ function make_paint_run(data: material_t, matcon: material_context_t): node_shad
node_shader_add_texture(kong, "texpaint_pack_undo", "_texpaint_pack_undo");
node_shader_write_frag(kong, "var sample_nor_undo: float4 = sample_lod(texpaint_nor_undo, sampler_linear, sample_tc, 0.0);");
node_shader_write_frag(kong, "var sample_pack_undo: float4 = sample_lod(texpaint_pack_undo, sampler_linear, sample_tc, 0.0);");
///if is_forge
node_shader_write_frag(kong, "output[0] = float4(" + make_material_blend_mode(kong, context_raw.brush_blending, "sample_undo.rgb", "basecol", "str") + ", mat_opacity);");
///else
node_shader_write_frag(kong, "output[0] = float4(" + make_material_blend_mode(kong, context_raw.brush_blending, "sample_undo.rgb", "basecol", "str") + ", max(str, sample_undo.a));");
///end
if (context_raw.tool == tool_type_t.GIZMO) {
node_shader_write_frag(kong, "output[0] = float4(" + make_material_blend_mode(kong, context_raw.brush_blending, "sample_undo.rgb", "basecol", "str") + ", mat_opacity);");
}
else {
node_shader_write_frag(kong, "output[0] = float4(" + make_material_blend_mode(kong, context_raw.brush_blending, "sample_undo.rgb", "basecol", "str") + ", max(str, sample_undo.a));");
}
node_shader_write_frag(kong, "output[1] = float4(lerp3(sample_nor_undo.rgb, nortan, str), matid);");
if (context_raw.material.paint_height && make_material_height_used) {
node_shader_write_frag(kong, "output[2] = lerp4(sample_pack_undo, float4(occlusion, roughness, metallic, height), str);");
-4
View File
@@ -117,10 +117,8 @@ function sim_duplicate() {
physics_body_init(pbdup, dup.base);
}
///if is_forge
_tab_scene_paint_object_length++;
tab_scene_sort();
///end
}
function sim_delete() {
@@ -129,8 +127,6 @@ function sim_delete() {
mesh_object_remove(so);
sim_remove_body(so.base.uid);
///if is_forge
_tab_scene_paint_object_length--;
tab_scene_sort();
///end
}