Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Feb 10, 2024
1 parent c73e63b commit 156f3eb
Show file tree
Hide file tree
Showing 63 changed files with 444 additions and 449 deletions.
2 changes: 1 addition & 1 deletion armorforge/Sources/TabObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class TabObjects {
fovHandle.value = Math.floor(cam.data.fov * 100) / 100;
cam.data.fov = zui_slider(fovHandle, "FoV", 0.3, 2.0, true);
if (fovHandle.changed) {
camera_object_build_projection(cam);
camera_object_build_proj(cam);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions armorlab/Sources/UINodesExt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class UINodesExt {
Console.progress(tr("Processing"));

let delayIdleSleep = () => {
Krom.delayIdleSleep();
krom_delay_idle_sleep();
}
app_notify_on_render_2d(delayIdleSleep);

Expand Down Expand Up @@ -90,7 +90,7 @@ class UINodesExt {
// Make copy of vertices before displacement
let o = Project.paintObjects[0];
let g = o.data;
let vertices = vertex_buffer_lock(g._vertex_buffer);
let vertices = g4_vertex_buffer_lock(g._vertex_buffer);
if (UINodesExt.lastVertices == null || UINodesExt.lastVertices.byteLength != vertices.byteLength) {
UINodesExt.lastVertices = new DataView(new ArrayBuffer(vertices.byteLength));
for (let i = 0; i < Math.floor(vertices.byteLength / 2); ++i) {
Expand All @@ -102,7 +102,7 @@ class UINodesExt {
vertices.setInt16(i * 2, UINodesExt.lastVertices.getInt16(i * 2, true), true);
}
}
vertex_buffer_unlock(g._vertex_buffer);
g4_vertex_buffer_unlock(g._vertex_buffer);

// Apply displacement
if (Config.raw.displace_strength > 0) {
Expand All @@ -121,7 +121,7 @@ class UINodesExt {
}

Console.log("Processing finished in " + (time_time() - timer));
Krom.mlUnload();
krom_ml_unload();

taskDone();
});
Expand Down
2 changes: 1 addition & 1 deletion armorlab/Sources/nodes/InpaintNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class InpaintNode extends LogicNode {
f32a[i + 512 * 512 * 2] = (u8a[i * 4 + 2] / 255.0) * 2.0 - 1.0;
}

let latents_buf = Krom.mlInference(vae_encoder_blob, [f32a.buffer], [[1, 3, 512, 512]], [1, 4, 64, 64], Config.raw.gpu_inference);
let latents_buf = krom_ml_inference(vae_encoder_blob, [f32a.buffer], [[1, 3, 512, 512]], [1, 4, 64, 64], Config.raw.gpu_inference);
let latents = new Float32Array(latents_buf);
for (let i = 0; i < latents.length; ++i) {
latents[i] = 0.18215 * latents[i];
Expand Down
2 changes: 1 addition & 1 deletion armorlab/Sources/nodes/PhotoToPBRNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class PhotoToPBRNode extends LogicNode {
}

data_get_blob("models/photo_to_" + PhotoToPBRNode.modelNames[from] + ".quant.onnx", (model_blob: ArrayBuffer) => {
let buf = Krom.mlInference(model_blob, [f32a.buffer], null, null, Config.raw.gpu_inference);
let buf = krom_ml_inference(model_blob, [f32a.buffer], null, null, Config.raw.gpu_inference);
let ar = new Float32Array(buf);
let u8a = new Uint8Array(4 * PhotoToPBRNode.tileW * PhotoToPBRNode.tileW);
let offsetG = (from == ChannelType.ChannelBaseColor || from == ChannelType.ChannelNormalMap) ? PhotoToPBRNode.tileWithBorderW * PhotoToPBRNode.tileWithBorderW : 0;
Expand Down
8 changes: 4 additions & 4 deletions armorlab/Sources/nodes/TextToPhotoNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class TextToPhotoNode extends LogicNode {
}

let i32a = new Int32Array(TextToPhotoNode.text_input_ids);
let text_embeddings_buf = Krom.mlInference(TextToPhotoNode.text_encoder_blob, [i32a.buffer], [[1, 77]], [1, 77, 768], Config.raw.gpu_inference);
let text_embeddings_buf = krom_ml_inference(TextToPhotoNode.text_encoder_blob, [i32a.buffer], [[1, 77]], [1, 77, 768], Config.raw.gpu_inference);
let text_embeddings = new Float32Array(text_embeddings_buf);

i32a = new Int32Array(TextToPhotoNode.uncond_input_ids);
let uncond_embeddings_buf = Krom.mlInference(TextToPhotoNode.text_encoder_blob, [i32a.buffer], [[1, 77]], [1, 77, 768], Config.raw.gpu_inference);
let uncond_embeddings_buf = krom_ml_inference(TextToPhotoNode.text_encoder_blob, [i32a.buffer], [[1, 77]], [1, 77, 768], Config.raw.gpu_inference);
let uncond_embeddings = new Float32Array(uncond_embeddings_buf);

let f32a = new Float32Array(uncond_embeddings.length + text_embeddings.length);
Expand Down Expand Up @@ -104,7 +104,7 @@ class TextToPhotoNode extends LogicNode {

let t32 = new Int32Array(2);
t32[0] = timestep;
let noise_pred_buf = Krom.mlInference(TextToPhotoNode.unet_blob, [latent_model_input.buffer, t32.buffer, text_embeddings.buffer], [[2, 4, 64, 64], [1], [2, 77, 768]], [2, 4, 64, 64], Config.raw.gpu_inference);
let noise_pred_buf = krom_ml_inference(TextToPhotoNode.unet_blob, [latent_model_input.buffer, t32.buffer, text_embeddings.buffer], [[2, 4, 64, 64], [1], [2, 77, 768]], [2, 4, 64, 64], Config.raw.gpu_inference);
let noise_pred = new Float32Array(noise_pred_buf);

for (let i = 0; i < noise_pred_uncond.length; ++i) noise_pred_uncond[i] = noise_pred[i];
Expand Down Expand Up @@ -202,7 +202,7 @@ class TextToPhotoNode extends LogicNode {
latents[i] = 1.0 / 0.18215 * latents[i];
}

let pyimage_buf = Krom.mlInference(TextToPhotoNode.vae_decoder_blob, [latents.buffer], [[1, 4, 64, 64]], [1, 3, 512, 512], Config.raw.gpu_inference);
let pyimage_buf = krom_ml_inference(TextToPhotoNode.vae_decoder_blob, [latents.buffer], [[1, 4, 64, 64]], [1, 3, 512, 512], Config.raw.gpu_inference);
let pyimage = new Float32Array(pyimage_buf);

for (let i = 0; i < pyimage.length; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion armorlab/Sources/nodes/UpscaleNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class UpscaleNode extends LogicNode {
f32a[i + size1w * size1w * 2] = (u8a[i * 4 + 2] / 255);
}

let esrgan2x_buf = Krom.mlInference(UpscaleNode.esrgan_blob, [f32a.buffer], [[1, 3, size1w, size1h]], [1, 3, size2w, size2h], Config.raw.gpu_inference);
let esrgan2x_buf = krom_ml_inference(UpscaleNode.esrgan_blob, [f32a.buffer], [[1, 3, size1w, size1h]], [1, 3, size2w, size2h], Config.raw.gpu_inference);
let esrgan2x = new Float32Array(esrgan2x_buf);
for (let i = 0; i < esrgan2x.length; ++i) {
if (esrgan2x[i] < 0) esrgan2x[i] = 0;
Expand Down
2 changes: 1 addition & 1 deletion armorlab/Sources/nodes/VarianceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class VarianceNode extends LogicNode {
Console.progress(tr("Processing") + " - " + tr("Variance"));
Base.notifyOnNextFrame(() => {
data_get_blob("models/sd_vae_encoder.quant.onnx", (vae_encoder_blob: ArrayBuffer) => {
let latents_buf = Krom.mlInference(vae_encoder_blob, [f32a.buffer], [[1, 3, 512, 512]], [1, 4, 64, 64], Config.raw.gpu_inference);
let latents_buf = krom_ml_inference(vae_encoder_blob, [f32a.buffer], [[1, 3, 512, 512]], [1, 4, 64, 64], Config.raw.gpu_inference);
let latents = new Float32Array(latents_buf);
for (let i = 0; i < latents.length; ++i) {
latents[i] = 0.18215 * latents[i];
Expand Down
18 changes: 9 additions & 9 deletions armorpaint/Sources/RenderPathPaint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ class RenderPathPaint {

let mo: mesh_object_t = scene_get_child(".ParticleEmitter").ext;
mo.base.visible = true;
mesh_object_render(mo, "mesh",render_path_bind_params);
mesh_object_render(mo, "mesh",_render_path_bind_params);
mo.base.visible = false;

mo = scene_get_child(".Particle").ext;
mo.base.visible = true;
mesh_object_render(mo, "mesh",render_path_bind_params);
mesh_object_render(mo, "mesh",_render_path_bind_params);
mo.base.visible = false;
render_path_end();
}
Expand Down Expand Up @@ -353,7 +353,7 @@ class RenderPathPaint {
let cc_context = shaderContexts[0];
if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data();
g4_set_pipeline(cc_context._pipe_state);
uniforms_set_context_consts(cc_context,render_path_bind_params);
uniforms_set_context_consts(cc_context,_render_path_bind_params);
uniforms_set_obj_consts(cc_context, Project.paintObjects[0].base);
uniforms_set_material_consts(cc_context, materialContexts[0]);
g4_set_vertex_buffer(const_data_screen_aligned_vb);
Expand Down Expand Up @@ -800,8 +800,8 @@ class RenderPathPaint {
mat4_translate(m, 0, 0, 0.5);
transform_set_matrix(cam.base.transform, m);
cam.data.fov = Base.defaultFov;
camera_object_build_projection(cam);
camera_object_build_matrix(cam);
camera_object_build_proj(cam);
camera_object_build_mat(cam);

let tw = 0.95 * UIView2D.panScale;
let tx = UIView2D.panX / UIView2D.ww;
Expand Down Expand Up @@ -845,11 +845,11 @@ class RenderPathPaint {
Context.raw.paintObject = RenderPathPaint.planeo;

let v = vec4_create();
let sx = vec4_len(vec4_set(v, m._00, m._01, m._02));
let sx = vec4_len(vec4_set(v, m.m[0], m.m[1], m.m[2]));
quat_from_euler(RenderPathPaint.planeo.base.transform.rot, -Math.PI / 2, 0, 0);
vec4_set(RenderPathPaint.planeo.base.transform.scale, sx, 1.0, sx);
RenderPathPaint.planeo.base.transform.scale.z *= Config.getTextureResY() / Config.getTextureResX();
vec4_set(RenderPathPaint.planeo.base.transform.loc, m._30, -m._31, 0.0);
vec4_set(RenderPathPaint.planeo.base.transform.loc, m.m[12], -m.m[13], 0.0);
transform_build_matrix(RenderPathPaint.planeo.base.transform);
}

Expand All @@ -867,8 +867,8 @@ class RenderPathPaint {
transform_set_matrix(scene_camera.base.transform, Context.raw.savedCamera);
scene_camera.data.fov = RenderPathPaint.savedFov;
Viewport.updateCameraType(Context.raw.cameraType);
camera_object_build_projection(scene_camera);
camera_object_build_matrix(scene_camera);
camera_object_build_proj(scene_camera);
camera_object_build_mat(scene_camera);

RenderPathBase.drawGbuffer();
}
Expand Down
4 changes: 2 additions & 2 deletions armorpaint/Sources/SlotFont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ class SlotFontRaw {
image: image_t = null; // 200px
previewReady = false;
id = 0;
font: font_t;
font: g2_font_t;
name: string;
file: string;
}

class SlotFont {

static create(name: string, font: font_t, file = ""): SlotFontRaw {
static create(name: string, font: g2_font_t, file = ""): SlotFontRaw {
let raw = new SlotFontRaw();
for (let slot of Project.fonts) if (slot.id >= raw.id) raw.id = slot.id + 1;
raw.name = name;
Expand Down
10 changes: 5 additions & 5 deletions armorpaint/Sources/TabLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,9 @@ class TabLayers {
if (l.fill_layer == null && SlotLayer.isMask(l)) {
g2_set_pipeline(UIView2D.pipe);
///if krom_opengl
Krom.setPipeline(UIView2D.pipe.pipeline_);
krom_g4_set_pipeline(UIView2D.pipe.pipeline_);
///end
Krom.setInt(UIView2D.channelLocation, 1);
krom_g4_set_int(UIView2D.channelLocation, 1);
}

let state = zui_image(icon, 0xffffffff, iconH);
Expand All @@ -632,8 +632,8 @@ class TabLayers {
if (!isTyping) {
if (i < 9 && Operator.shortcut(Config.keymap.select_layer, ShortcutType.ShortcutDown)) {
let number = String(i + 1) ;
let width = font_width(ui.font, ui.font_size, number) + 10;
let height = font_height(ui.font, ui.font_size);
let width = g2_font_width(ui.font, ui.font_size, number) + 10;
let height = g2_font_height(ui.font, ui.font_size);
g2_set_color(ui.t.TEXT_COL);
g2_fill_rect(uix, uiy, width, height);
g2_set_color(ui.t.ACCENT_COL);
Expand Down Expand Up @@ -710,7 +710,7 @@ class TabLayers {
let f = UIFiles.filename;
if (f == "") f = tr("untitled");
if (!f.endsWith(".png")) f += ".png";
Krom.writePng(path + Path.sep + f, image_get_pixels(l.texpaint), l.texpaint.width, l.texpaint.height, 3); // RRR1
krom_write_png(path + Path.sep + f, image_get_pixels(l.texpaint), l.texpaint.width, l.texpaint.height, 3); // RRR1
});
}
else {
Expand Down
2 changes: 1 addition & 1 deletion armorsculpt/Sources/ExportObj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ class ExportObj {
if (!path.endsWith(".obj")) path += ".obj";

let b = Uint8Array.from(o).buffer;
Krom.fileSaveBytes(path, b, b.byteLength);
krom_file_save_bytes(path, b, b.byteLength);
}
}
28 changes: 14 additions & 14 deletions base/Sources/Args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class Args {
///end

static parse = () => {
if (Krom.getArgCount() > 1) {
if (krom_get_arg_count() > 1) {
Args.useArgs = true;

let i = 0;
while (i < Krom.getArgCount()) {
while (i < krom_get_arg_count()) {
// Process each arg
let currentArg = Krom.getArg(i);
let currentArg = krom_get_arg(i);

if (Path.isProject(currentArg)) {
Project.filepath = currentArg;
Expand All @@ -40,25 +40,25 @@ class Args {
else if (Path.isTexture(currentArg)) {
Args.assetPath = currentArg;
}
else if (currentArg == "--export-textures" && (i + 3) <= Krom.getArgCount()) {
else if (currentArg == "--export-textures" && (i + 3) <= krom_get_arg_count()) {
Args.exportTextures = true;
++i;
Args.exportTexturesType = Krom.getArg(i);
Args.exportTexturesType = krom_get_arg(i);
++i;
Args.exportTexturesPreset = Krom.getArg(i);
Args.exportTexturesPreset = krom_get_arg(i);
++i;
Args.exportTexturesPath = Krom.getArg(i);
Args.exportTexturesPath = krom_get_arg(i);
}
///end

///if (is_paint || is_sculpt)
else if (currentArg == "--reload-mesh") {
Args.reimportMesh = true;
}
else if (currentArg == "--export-mesh" && (i + 1) <= Krom.getArgCount()) {
else if (currentArg == "--export-mesh" && (i + 1) <= krom_get_arg_count()) {
Args.exportMesh = true;
++i;
Args.exportMeshPath = Krom.getArg(i);
Args.exportMeshPath = krom_get_arg(i);
}
else if (Path.isMesh(currentArg) ||
(i > 1 && !currentArg.startsWith("-") && Path.isFolder(currentArg))) {
Expand All @@ -67,10 +67,10 @@ class Args {
///end

///if is_paint
else if (currentArg == "--export-material" && (i + 1) <= Krom.getArgCount()) {
else if (currentArg == "--export-material" && (i + 1) <= krom_get_arg_count()) {
Args.exportMaterial = true;
++i;
Args.exportMaterialPath = Krom.getArg(i);
Args.exportMaterialPath = krom_get_arg(i);
}
///end

Expand Down Expand Up @@ -156,11 +156,11 @@ class Args {
});
}
else {
Krom.log(tr("Invalid export directory"));
krom_log(tr("Invalid export directory"));
}
}
else {
Krom.log(tr("Invalid texture type"));
krom_log(tr("Invalid texture type"));
}
}
///end
Expand All @@ -173,7 +173,7 @@ class Args {
ExportMesh.run(Args.exportMeshPath + Path.sep + f, null, false);
}
else {
Krom.log(tr("Invalid export directory"));
krom_log(tr("Invalid export directory"));
}
}
///end
Expand Down
Loading

0 comments on commit 156f3eb

Please sign in to comment.