Refactor
This commit is contained in:
@@ -93,7 +93,7 @@ class MakeMaterial {
|
||||
scon2._override_context = {};
|
||||
scon2._override_context.addressing = "repeat";
|
||||
let mcon3: material_context_t;
|
||||
MaterialContext.create(mcon2, (_mcon: material_context_t) => { mcon3 = _mcon; });
|
||||
material_context_create(mcon2, (_mcon: material_context_t) => { mcon3 = _mcon; });
|
||||
|
||||
m._shader.contexts.push(scon2);
|
||||
m._shader._contexts.push(scon2);
|
||||
|
||||
@@ -18,7 +18,7 @@ class MakePaint {
|
||||
con_paint.data.color_writes_green = [true, true, true, true];
|
||||
con_paint.data.color_writes_blue = [true, true, true, true];
|
||||
con_paint.data.color_writes_alpha = [true, true, true, true];
|
||||
con_paint.allow_vcols = MeshData.getVArray(Context.raw.paintObject.data, "col") != null;
|
||||
con_paint.allow_vcols = mesh_data_get_vertex_array(Context.raw.paintObject.data, "col") != null;
|
||||
|
||||
let vert = NodeShaderContext.make_vert(con_paint);
|
||||
let frag = NodeShaderContext.make_frag(con_paint);
|
||||
|
||||
@@ -11,7 +11,7 @@ class NodesBrush {
|
||||
|
||||
static categories = [_tr("Input"), _tr("Model")];
|
||||
|
||||
static list: TNode[][] = [
|
||||
static list: zui_node_t[][] = [
|
||||
[ // Input
|
||||
ImageTextureNode.def,
|
||||
RGBNode.def,
|
||||
@@ -26,7 +26,7 @@ class NodesBrush {
|
||||
]
|
||||
];
|
||||
|
||||
static createNode = (nodeType: string): TNode => {
|
||||
static createNode = (nodeType: string): zui_node_t => {
|
||||
for (let c of NodesBrush.list) {
|
||||
for (let n of c) {
|
||||
if (n.type == nodeType) {
|
||||
|
||||
@@ -165,7 +165,7 @@ class RenderPathPaint {
|
||||
|
||||
let nodes = UINodes.getNodes();
|
||||
let canvas = UINodes.getCanvas(true);
|
||||
let inpaint = nodes.nodesSelectedId.length > 0 && Nodes.getNode(canvas.nodes, nodes.nodesSelectedId[0]).type == "InpaintNode";
|
||||
let inpaint = nodes.nodesSelectedId.length > 0 && zui_get_node(canvas.nodes, nodes.nodesSelectedId[0]).type == "InpaintNode";
|
||||
|
||||
if (!Base.uiEnabled || Base.isDragging || !inpaint) {
|
||||
return;
|
||||
@@ -174,8 +174,8 @@ class RenderPathPaint {
|
||||
let mx = Context.raw.paintVec.x;
|
||||
let my = 1.0 - Context.raw.paintVec.y;
|
||||
if (Context.raw.brushLocked) {
|
||||
mx = (Context.raw.lockStartedX - App.x()) / App.w();
|
||||
my = 1.0 - (Context.raw.lockStartedY - App.y()) / App.h();
|
||||
mx = (Context.raw.lockStartedX - app_x()) / app_w();
|
||||
my = 1.0 - (Context.raw.lockStartedY - app_y()) / app_h();
|
||||
}
|
||||
let radius = Context.raw.brushRadius;
|
||||
RenderPathPaint.drawCursor(mx, my, radius / 3.4);
|
||||
@@ -195,15 +195,15 @@ class RenderPathPaint {
|
||||
g4_set_float2(Base.cursorMouse, mx, my);
|
||||
g4_set_float2(Base.cursorTexStep, 1 / gbuffer0.width, 1 / gbuffer0.height);
|
||||
g4_set_float(Base.cursorRadius, radius);
|
||||
let right = vec4_normalize(CameraObject.rightWorld(scene_camera));
|
||||
let right = vec4_normalize(camera_object_right_world(scene_camera));
|
||||
g4_set_float3(Base.cursorCameraRight, right.x, right.y, right.z);
|
||||
g4_set_float3(Base.cursorTint, tintR, tintG, tintB);
|
||||
g4_set_mat(Base.cursorVP, scene_camera.VP);
|
||||
g4_set_mat(Base.cursorVP, scene_camera.vp);
|
||||
let helpMat = mat4_identity();
|
||||
mat4_get_inv(helpMat, scene_camera.VP);
|
||||
mat4_get_inv(helpMat, scene_camera.vp);
|
||||
g4_set_mat(Base.cursorInvVP, helpMat);
|
||||
///if (krom_metal || krom_vulkan)
|
||||
g4_set_vertex_buffer(MeshData.get(geom, [{name: "tex", data: "short2norm"}]));
|
||||
g4_set_vertex_buffer(mesh_data_get(geom, [{name: "tex", data: "short2norm"}]));
|
||||
///else
|
||||
g4_set_vertex_buffer(geom._vertexBuffer);
|
||||
///end
|
||||
@@ -255,7 +255,7 @@ class RenderPathPaint {
|
||||
let nodes = UINodes.getNodes();
|
||||
let canvas = UINodes.getCanvas(true);
|
||||
if (nodes.nodesSelectedId.length > 0) {
|
||||
let node = Nodes.getNode(canvas.nodes, nodes.nodesSelectedId[0]);
|
||||
let node = zui_get_node(canvas.nodes, nodes.nodesSelectedId[0]);
|
||||
let brushNode = ParserLogic.getLogicNode(node);
|
||||
if (brushNode != null) {
|
||||
image = brushNode.getCachedImage();
|
||||
@@ -285,7 +285,7 @@ class RenderPathPaint {
|
||||
|
||||
let nodes = UINodes.getNodes();
|
||||
let canvas = UINodes.getCanvas(true);
|
||||
let node = Nodes.getNode(canvas.nodes, nodes.nodesSelectedId[0]);
|
||||
let node = zui_get_node(canvas.nodes, nodes.nodesSelectedId[0]);
|
||||
let inpaint = node.type == "InpaintNode";
|
||||
if (inpaint) {
|
||||
let brushNode = ParserLogic.getLogicNode(node);
|
||||
|
||||
@@ -5,13 +5,13 @@ class UINodesExt {
|
||||
|
||||
static drawButtons = (ew: f32, startY: f32) => {
|
||||
let ui = UINodes.ui;
|
||||
if (Zui.button(tr("Run"))) {
|
||||
if (zui_button(tr("Run"))) {
|
||||
Console.progress(tr("Processing"));
|
||||
|
||||
let delayIdleSleep = (_: any) => {
|
||||
Krom.delayIdleSleep();
|
||||
}
|
||||
App.notifyOnRender2D(delayIdleSleep);
|
||||
app_notify_on_render_2d(delayIdleSleep);
|
||||
|
||||
let tasks = 1;
|
||||
|
||||
@@ -20,7 +20,7 @@ class UINodesExt {
|
||||
if (tasks == 0) {
|
||||
Console.progress(null);
|
||||
Context.raw.ddirty = 2;
|
||||
App.removeRender2D(delayIdleSleep);
|
||||
app_remove_render_2d(delayIdleSleep);
|
||||
|
||||
///if (krom_direct3d12 || krom_vulkan || krom_metal)
|
||||
RenderPathRaytrace.ready = false;
|
||||
@@ -55,7 +55,7 @@ class UINodesExt {
|
||||
|
||||
if (Base.pipeCopy == null) Base.makePipe();
|
||||
if (Base.pipeCopyA == null) Base.makePipeCopyA();
|
||||
if (ConstData.screenAlignedVB == null) ConstData.createScreenAlignedData();
|
||||
if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data();
|
||||
|
||||
let texpaint_pack = render_path_render_targets.get("texpaint_pack").image;
|
||||
|
||||
@@ -79,8 +79,8 @@ class UINodesExt {
|
||||
g4_begin(texpaint_pack.g4);
|
||||
g4_set_pipeline(Base.pipeCopyA);
|
||||
g4_set_tex(Base.pipeCopyATex, texheight);
|
||||
g4_set_vertex_buffer(ConstData.screenAlignedVB);
|
||||
g4_set_index_buffer(ConstData.screenAlignedIB);
|
||||
g4_set_vertex_buffer(const_data_screen_aligned_vb);
|
||||
g4_set_index_buffer(const_data_screen_aligned_ib);
|
||||
g4_draw();
|
||||
g4_end();
|
||||
|
||||
@@ -135,9 +135,9 @@ class UINodesExt {
|
||||
ui._y = 2 + startY;
|
||||
|
||||
///if (krom_android || krom_ios)
|
||||
Zui.combo(Base.resHandle, ["2K", "4K"], tr("Resolution"));
|
||||
zui_combo(Base.resHandle, ["2K", "4K"], tr("Resolution"));
|
||||
///else
|
||||
Zui.combo(Base.resHandle, ["2K", "4K", "8K", "16K"], tr("Resolution"));
|
||||
zui_combo(Base.resHandle, ["2K", "4K", "8K", "16K"], tr("Resolution"));
|
||||
///end
|
||||
if (Base.resHandle.changed) {
|
||||
Base.onLayersResized();
|
||||
|
||||
@@ -20,7 +20,7 @@ class ImageTextureNode extends LogicNode {
|
||||
return image;
|
||||
}
|
||||
|
||||
static def: TNode = {
|
||||
static def: zui_node_t = {
|
||||
id: 0,
|
||||
name: _tr("Image Texture"),
|
||||
type: "ImageTextureNode",
|
||||
|
||||
@@ -40,11 +40,11 @@ class InpaintNode extends LogicNode {
|
||||
}
|
||||
}
|
||||
|
||||
static buttons = (ui: ZuiRaw, nodes: NodesRaw, node: TNode) => {
|
||||
static buttons = (ui: zui_t, nodes: zui_nodes_t, node: zui_node_t) => {
|
||||
InpaintNode.auto = node.buttons[0].default_value == 0 ? false : true;
|
||||
if (!InpaintNode.auto) {
|
||||
InpaintNode.strength = Zui.slider(Zui.handle("inpaintnode_0", {value: InpaintNode.strength}), tr("strength"), 0, 1, true);
|
||||
InpaintNode.prompt = Zui.textArea(Zui.handle("inpaintnode_1"), Align.Left, true, tr("prompt"), true);
|
||||
InpaintNode.strength = zui_slider(zui_handle("inpaintnode_0", { value: InpaintNode.strength }), tr("strength"), 0, 1, true);
|
||||
InpaintNode.prompt = zui_text_area(zui_handle("inpaintnode_1"), Align.Left, true, tr("prompt"), true);
|
||||
node.buttons[1].height = 1 + InpaintNode.prompt.split("\n").length;
|
||||
}
|
||||
else node.buttons[1].height = 0;
|
||||
@@ -68,13 +68,13 @@ class InpaintNode extends LogicNode {
|
||||
Base.notifyOnNextFrame(() => {
|
||||
this.inputs[0].getAsImage((source: image_t) => {
|
||||
if (Base.pipeCopy == null) Base.makePipe();
|
||||
if (ConstData.screenAlignedVB == null) ConstData.createScreenAlignedData();
|
||||
if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data();
|
||||
g4_begin(InpaintNode.image.g4);
|
||||
g4_set_pipeline(Base.pipeInpaintPreview);
|
||||
g4_set_tex(Base.tex0InpaintPreview, source);
|
||||
g4_set_tex(Base.texaInpaintPreview, InpaintNode.mask);
|
||||
g4_set_vertex_buffer(ConstData.screenAlignedVB);
|
||||
g4_set_index_buffer(ConstData.screenAlignedIB);
|
||||
g4_set_vertex_buffer(const_data_screen_aligned_vb);
|
||||
g4_set_index_buffer(const_data_screen_aligned_ib);
|
||||
g4_draw();
|
||||
g4_end();
|
||||
});
|
||||
@@ -106,7 +106,7 @@ class InpaintNode extends LogicNode {
|
||||
let u8 = new Uint8Array(bytes_img);
|
||||
let f32mask = new Float32Array(4 * 64 * 64);
|
||||
|
||||
Data.getBlob("models/sd_vae_encoder.quant.onnx", (vae_encoder_blob: ArrayBuffer) => {
|
||||
data_get_blob("models/sd_vae_encoder.quant.onnx", (vae_encoder_blob: ArrayBuffer) => {
|
||||
// for (let x = 0; x < Math.floor(image.width / 512); ++x) {
|
||||
// for (let y = 0; y < Math.floor(image.height / 512); ++y) {
|
||||
let x = 0;
|
||||
@@ -175,7 +175,7 @@ class InpaintNode extends LogicNode {
|
||||
});
|
||||
}
|
||||
|
||||
static def: TNode = {
|
||||
static def: zui_node_t = {
|
||||
id: 0,
|
||||
name: _tr("Inpaint"),
|
||||
type: "InpaintNode",
|
||||
|
||||
@@ -67,7 +67,7 @@ class PhotoToPBRNode extends LogicNode {
|
||||
f32a[i + PhotoToPBRNode.tileWithBorderW * PhotoToPBRNode.tileWithBorderW * 2] = (u8a[i * 4 + 2] / 255 - 0.5) / 0.5;
|
||||
}
|
||||
|
||||
Data.getBlob("models/photo_to_" + PhotoToPBRNode.modelNames[from] + ".quant.onnx", (model_blob: ArrayBuffer) => {
|
||||
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 ar = new Float32Array(buf);
|
||||
let u8a = new Uint8Array(4 * PhotoToPBRNode.tileW * PhotoToPBRNode.tileW);
|
||||
@@ -168,7 +168,7 @@ class PhotoToPBRNode extends LogicNode {
|
||||
}
|
||||
///end
|
||||
|
||||
static def: TNode = {
|
||||
static def: zui_node_t = {
|
||||
id: 0,
|
||||
name: _tr("Photo to PBR"),
|
||||
type: "PhotoToPBRNode",
|
||||
|
||||
@@ -30,7 +30,7 @@ class RGBNode extends LogicNode {
|
||||
return this.image;
|
||||
}
|
||||
|
||||
static def: TNode = {
|
||||
static def: zui_node_t = {
|
||||
id: 0,
|
||||
name: _tr("RGB"),
|
||||
type: "RGBNode",
|
||||
|
||||
@@ -23,16 +23,16 @@ class TextToPhotoNode extends LogicNode {
|
||||
return TextToPhotoNode.image;
|
||||
}
|
||||
|
||||
static buttons = (ui: ZuiRaw, nodes: NodesRaw, node: TNode) => {
|
||||
static buttons = (ui: zui_t, nodes: zui_nodes_t, node: zui_node_t) => {
|
||||
TextToPhotoNode.tiling = node.buttons[0].default_value == 0 ? false : true;
|
||||
TextToPhotoNode.prompt = Zui.textArea(Zui.handle("texttophotonode_0"), Align.Left, true, tr("prompt"), true);
|
||||
TextToPhotoNode.prompt = zui_text_area(zui_handle("texttophotonode_0"), Align.Left, true, tr("prompt"), true);
|
||||
node.buttons[1].height = TextToPhotoNode.prompt.split("\n").length;
|
||||
}
|
||||
|
||||
static stableDiffusion = (prompt: string, done: (img: image_t)=>void, inpaintLatents: Float32Array = null, offset = 0, upscale = true, mask: Float32Array = null, latents_orig: Float32Array = null) => {
|
||||
Data.getBlob("models/sd_text_encoder.quant.onnx", (_text_encoder_blob: ArrayBuffer) => {
|
||||
Data.getBlob("models/sd_unet.quant.onnx", (_unet_blob: ArrayBuffer) => {
|
||||
Data.getBlob("models/sd_vae_decoder.quant.onnx", (_vae_decoder_blob: ArrayBuffer) => {
|
||||
data_get_blob("models/sd_text_encoder.quant.onnx", (_text_encoder_blob: ArrayBuffer) => {
|
||||
data_get_blob("models/sd_unet.quant.onnx", (_unet_blob: ArrayBuffer) => {
|
||||
data_get_blob("models/sd_vae_decoder.quant.onnx", (_vae_decoder_blob: ArrayBuffer) => {
|
||||
TextToPhotoNode.text_encoder_blob = _text_encoder_blob;
|
||||
TextToPhotoNode.unet_blob = _unet_blob;
|
||||
TextToPhotoNode.vae_decoder_blob = _vae_decoder_blob;
|
||||
@@ -188,11 +188,11 @@ class TextToPhotoNode extends LogicNode {
|
||||
}
|
||||
|
||||
if (counter == (51 - offset)) {
|
||||
App.removeRender2D(processing);
|
||||
app_remove_render_2d(processing);
|
||||
done(latents);
|
||||
}
|
||||
}
|
||||
App.notifyOnRender2D(processing);
|
||||
app_notify_on_render_2d(processing);
|
||||
}
|
||||
|
||||
static vaeDecoder = (latents: Float32Array, upscale: bool, done: (img: image_t)=>void) => {
|
||||
@@ -241,7 +241,7 @@ class TextToPhotoNode extends LogicNode {
|
||||
});
|
||||
}
|
||||
|
||||
static def: TNode = {
|
||||
static def: zui_node_t = {
|
||||
id: 0,
|
||||
name: _tr("Text to Photo"),
|
||||
type: "TextToPhotoNode",
|
||||
|
||||
@@ -18,11 +18,11 @@ class TilingNode extends LogicNode {
|
||||
}
|
||||
}
|
||||
|
||||
static buttons = (ui: ZuiRaw, nodes: NodesRaw, node: TNode) => {
|
||||
static buttons = (ui: zui_t, nodes: zui_nodes_t, node: zui_node_t) => {
|
||||
TilingNode.auto = node.buttons[0].default_value == 0 ? false : true;
|
||||
if (!TilingNode.auto) {
|
||||
TilingNode.strength = Zui.slider(Zui.handle("tilingnode_0", {value: TilingNode.strength}), tr("strength"), 0, 1, true);
|
||||
TilingNode.prompt = Zui.textArea(Zui.handle("tilingnode_1"), Align.Left, true, tr("prompt"), true);
|
||||
TilingNode.strength = zui_slider(zui_handle("tilingnode_0", { value: TilingNode.strength }), tr("strength"), 0, 1, true);
|
||||
TilingNode.prompt = zui_text_area(zui_handle("tilingnode_1"), Align.Left, true, tr("prompt"), true);
|
||||
node.buttons[1].height = 1 + TilingNode.prompt.split("\n").length;
|
||||
}
|
||||
else node.buttons[1].height = 0;
|
||||
@@ -85,7 +85,7 @@ class TilingNode extends LogicNode {
|
||||
InpaintNode.sdInpaint(tile, mask, done);
|
||||
}
|
||||
|
||||
static def: TNode = {
|
||||
static def: zui_node_t = {
|
||||
id: 0,
|
||||
name: _tr("Tiling"),
|
||||
type: "TilingNode",
|
||||
|
||||
@@ -31,7 +31,7 @@ class UpscaleNode extends LogicNode {
|
||||
}
|
||||
|
||||
static loadBlob = (done: ()=>void) => {
|
||||
Data.getBlob("models/esrgan.quant.onnx", (_esrgan_blob: ArrayBuffer) => {
|
||||
data_get_blob("models/esrgan.quant.onnx", (_esrgan_blob: ArrayBuffer) => {
|
||||
UpscaleNode.esrgan_blob = _esrgan_blob;
|
||||
done();
|
||||
});
|
||||
@@ -119,7 +119,7 @@ class UpscaleNode extends LogicNode {
|
||||
return result;
|
||||
}
|
||||
|
||||
static def: TNode = {
|
||||
static def: zui_node_t = {
|
||||
id: 0,
|
||||
name: _tr("Upscale"),
|
||||
type: "UpscaleNode",
|
||||
|
||||
@@ -18,8 +18,8 @@ class VarianceNode extends LogicNode {
|
||||
}
|
||||
}
|
||||
|
||||
static buttons = (ui: ZuiRaw, nodes: NodesRaw, node: TNode) => {
|
||||
VarianceNode.prompt = Zui.textArea(Zui.handle("variancenode_0"), Align.Left, true, tr("prompt"), true);
|
||||
static buttons = (ui: zui_t, nodes: zui_nodes_t, node: zui_node_t) => {
|
||||
VarianceNode.prompt = zui_text_area(zui_handle("variancenode_0"), Align.Left, true, tr("prompt"), true);
|
||||
node.buttons[0].height = VarianceNode.prompt.split("\n").length;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class VarianceNode extends LogicNode {
|
||||
|
||||
Console.progress(tr("Processing") + " - " + tr("Variance"));
|
||||
Base.notifyOnNextFrame(() => {
|
||||
Data.getBlob("models/sd_vae_encoder.quant.onnx", (vae_encoder_blob: ArrayBuffer) => {
|
||||
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 = new Float32Array(latents_buf);
|
||||
for (let i = 0; i < latents.length; ++i) {
|
||||
@@ -75,7 +75,7 @@ class VarianceNode extends LogicNode {
|
||||
return VarianceNode.image;
|
||||
}
|
||||
|
||||
static def: TNode = {
|
||||
static def: zui_node_t = {
|
||||
id: 0,
|
||||
name: _tr("Variance"),
|
||||
type: "VarianceNode",
|
||||
|
||||
Reference in New Issue
Block a user