Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Feb 6, 2024
1 parent fd9bdbe commit 779218d
Show file tree
Hide file tree
Showing 110 changed files with 2,368 additions and 2,361 deletions.
136 changes: 68 additions & 68 deletions armorforge/Sources/TabObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,71 @@ class TabObjects {
return Math.round(f) / Math.pow(10, precision);
}

static draw = (htab: HandleRaw) => {
static draw = (htab: zui_handle_t) => {
let ui = UIBase.ui;
if (Zui.tab(htab, tr("Objects"))) {
Zui.beginSticky();
Zui.row([1 / 4]);
if (Zui.button("Import")) {
if (zui_tab(htab, tr("Objects"))) {
zui_begin_sticky();
zui_row([1 / 4]);
if (zui_button("Import")) {
Project.importMesh(false, () => {
BaseObject.setParent(Project.paintObjects.pop().base, null);
object_set_parent(Project.paintObjects.pop().base, null);
});
}
Zui.endSticky();
zui_end_sticky();

if (Zui.panel(Zui.handle("tabobjects_0", {selected: true}), "Outliner")) {
if (zui_panel(zui_handle("tabobjects_0", {selected: true}), "Outliner")) {
// ui.indent();
ui._y -= Zui.ELEMENT_OFFSET(ui);
ui._y -= zui_ELEMENT_OFFSET(ui);

let listX = ui._x;
let listW = ui._w;

let lineCounter = 0;
let drawList = (listHandle: HandleRaw, currentObject: TBaseObject) => {
let drawList = (listHandle: zui_handle_t, currentObject: object_t) => {
if (currentObject.name.charAt(0) == ".") return; // Hidden
let b = false;

// Highlight every other line
if (lineCounter % 2 == 0) {
ui.g.color = ui.t.SEPARATOR_COL;
g2_fill_rect(0, ui._y, ui._windowW, Zui.ELEMENT_H(ui));
g2_fill_rect(0, ui._y, ui._window_w, zui_ELEMENT_H(ui));
ui.g.color = 0xffffffff;
}

// Highlight selected line
if (currentObject == Context.raw.selectedObject) {
ui.g.color = 0xff205d9c;
g2_fill_rect(0, ui._y, ui._windowW, Zui.ELEMENT_H(ui));
g2_fill_rect(0, ui._y, ui._window_w, zui_ELEMENT_H(ui));
ui.g.color = 0xffffffff;
}

if (currentObject.children.length > 0) {
Zui.row([1 / 13, 12 / 13]);
b = Zui.panel(Zui.nest(listHandle, lineCounter, {selected: true}), "", true, false, false);
Zui.text(currentObject.name);
zui_row([1 / 13, 12 / 13]);
b = zui_panel(zui_nest(listHandle, lineCounter, {selected: true}), "", true, false, false);
zui_text(currentObject.name);
}
else {
ui._x += 18; // Sign offset

// Draw line that shows parent relations
ui.g.color = ui.t.ACCENT_COL;
g2_draw_line(ui._x - 10, ui._y + Zui.ELEMENT_H(ui) / 2, ui._x, ui._y + Zui.ELEMENT_H(ui) / 2);
g2_draw_line(ui._x - 10, ui._y + zui_ELEMENT_H(ui) / 2, ui._x, ui._y + zui_ELEMENT_H(ui) / 2);
ui.g.color = 0xffffffff;

Zui.text(currentObject.name);
zui_text(currentObject.name);
ui._x -= 18;
}

lineCounter++;
// Undo applied offset for row drawing caused by endElement() in Zui.hx
ui._y -= Zui.ELEMENT_OFFSET(ui);
ui._y -= zui_ELEMENT_OFFSET(ui);

if (ui.isReleased) {
if (ui.is_released) {
Context.raw.selectedObject = currentObject;
}

if (ui.isHovered && ui.inputReleasedR) {
UIMenu.draw((ui: ZuiRaw) => {
if (ui.is_hovered && ui.input_released_r) {
UIMenu.draw((ui: zui_t) => {
if (UIMenu.menuButton(ui, "Assign Material")) {
TabObjects.materialId++;

Expand All @@ -95,8 +95,8 @@ class TabObjects {
}
}

Data.getMaterial("Scene", "TempMaterial" + TabObjects.materialId, (md: material_data_t) => {
let mo: TMeshObject = currentObject.ext;
data_get_material("Scene", "TempMaterial" + TabObjects.materialId, (md: material_data_t) => {
let mo: mesh_object_t = currentObject.ext;
mo.materials = [md];
MakeMaterial.parseMeshPreviewMaterial(md);
});
Expand All @@ -114,24 +114,24 @@ class TabObjects {

// Draw line that shows parent relations
ui.g.color = ui.t.ACCENT_COL;
g2_draw_line(ui._x + 14, currentY, ui._x + 14, ui._y - Zui.ELEMENT_H(ui) / 2);
g2_draw_line(ui._x + 14, currentY, ui._x + 14, ui._y - zui_ELEMENT_H(ui) / 2);
ui.g.color = 0xffffffff;
}
}
for (let c of _scene_root.children) {
drawList(Zui.handle("tabobjects_1"), c);
drawList(zui_handle("tabobjects_1"), c);
}

// ui.unindent();
}

if (Zui.panel(Zui.handle("tabobjects_2", {selected: true}), 'Properties')) {
if (zui_panel(zui_handle("tabobjects_2", {selected: true}), 'Properties')) {
// ui.indent();

if (Context.raw.selectedObject != null) {
let h = Zui.handle("tabobjects_3");
let h = zui_handle("tabobjects_3");
h.selected = Context.raw.selectedObject.visible;
Context.raw.selectedObject.visible = Zui.check(h, "Visible");
Context.raw.selectedObject.visible = zui_check(h, "Visible");

let t = Context.raw.selectedObject.transform;
let localPos = t.loc;
Expand All @@ -142,41 +142,41 @@ class TabObjects {
vec4_mult(rot, 180 / 3.141592);
let f = 0.0;

Zui.row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
Zui.text("Loc");
zui_row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
zui_text("Loc");

h = Zui.handle("tabobjects_4");
h = zui_handle("tabobjects_4");
h.text = TabObjects.roundfp(localPos.x) + "";
f = parseFloat(Zui.textInput(h, "X"));
f = parseFloat(zui_text_input(h, "X"));
if (h.changed) localPos.x = f;

h = Zui.handle("tabobjects_5");
h = zui_handle("tabobjects_5");
h.text = TabObjects.roundfp(localPos.y) + "";
f = parseFloat(Zui.textInput(h, "Y"));
f = parseFloat(zui_text_input(h, "Y"));
if (h.changed) localPos.y = f;

h = Zui.handle("tabobjects_6");
h = zui_handle("tabobjects_6");
h.text = TabObjects.roundfp(localPos.z) + "";
f = parseFloat(Zui.textInput(h, "Z"));
f = parseFloat(zui_text_input(h, "Z"));
if (h.changed) localPos.z = f;

Zui.row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
Zui.text("Rotation");
zui_row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
zui_text("Rotation");

h = Zui.handle("tabobjects_7");
h = zui_handle("tabobjects_7");
h.text = TabObjects.roundfp(rot.x) + "";
f = parseFloat(Zui.textInput(h, "X"));
f = parseFloat(zui_text_input(h, "X"));
let changed = false;
if (h.changed) { changed = true; rot.x = f; }

h = Zui.handle("tabobjects_8");
h = zui_handle("tabobjects_8");
h.text = TabObjects.roundfp(rot.y) + "";
f = parseFloat(Zui.textInput(h, "Y"));
f = parseFloat(zui_text_input(h, "Y"));
if (h.changed) { changed = true; rot.y = f; }

h = Zui.handle("tabobjects_9");
h = zui_handle("tabobjects_9");
h.text = TabObjects.roundfp(rot.z) + "";
f = parseFloat(Zui.textInput(h, "Z"));
f = parseFloat(zui_text_input(h, "Z"));
if (h.changed) { changed = true; rot.z = f; }

if (changed && Context.raw.selectedObject.name != "Scene") {
Expand All @@ -188,61 +188,61 @@ class TabObjects {
// ///end
}

Zui.row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
Zui.text("Scale");
zui_row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
zui_text("Scale");

h = Zui.handle("tabobjects_10");
h = zui_handle("tabobjects_10");
h.text = TabObjects.roundfp(scale.x) + "";
f = parseFloat(Zui.textInput(h, "X"));
f = parseFloat(zui_text_input(h, "X"));
if (h.changed) scale.x = f;

h = Zui.handle("tabobjects_11");
h = zui_handle("tabobjects_11");
h.text = TabObjects.roundfp(scale.y) + "";
f = parseFloat(Zui.textInput(h, "Y"));
f = parseFloat(zui_text_input(h, "Y"));
if (h.changed) scale.y = f;

h = Zui.handle("tabobjects_12");
h = zui_handle("tabobjects_12");
h.text = TabObjects.roundfp(scale.z) + "";
f = parseFloat(Zui.textInput(h, "Z"));
f = parseFloat(zui_text_input(h, "Z"));
if (h.changed) scale.z = f;

Zui.row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
Zui.text("Dimensions");
zui_row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
zui_text("Dimensions");

h = Zui.handle("tabobjects_13");
h = zui_handle("tabobjects_13");
h.text = TabObjects.roundfp(dim.x) + "";
f = parseFloat(Zui.textInput(h, "X"));
f = parseFloat(zui_text_input(h, "X"));
if (h.changed) dim.x = f;

h = Zui.handle("tabobjects_14");
h = zui_handle("tabobjects_14");
h.text = TabObjects.roundfp(dim.y) + "";
f = parseFloat(Zui.textInput(h, "Y"));
f = parseFloat(zui_text_input(h, "Y"));
if (h.changed) dim.y = f;

h = Zui.handle("tabobjects_15");
h = zui_handle("tabobjects_15");
h.text = TabObjects.roundfp(dim.z) + "";
f = parseFloat(Zui.textInput(h, "Z"));
f = parseFloat(zui_text_input(h, "Z"));
if (h.changed) dim.z = f;

Context.raw.selectedObject.transform.dirty = true;

if (Context.raw.selectedObject.name == "Scene") {
let p = scene_world;
p.strength = Zui.slider(Zui.handle("tabobjects_16", {value: p.strength}), "Environment", 0.0, 5.0, true);
p.strength = zui_slider(zui_handle("tabobjects_16", {value: p.strength}), "Environment", 0.0, 5.0, true);
}
else if (Context.raw.selectedObject.ext.constructor == TLightObject) {
else if (Context.raw.selectedObject.ext.constructor == light_object_t) {
let light = Context.raw.selectedObject.ext;
let lightHandle = Zui.handle("tabobjects_17");
let lightHandle = zui_handle("tabobjects_17");
lightHandle.value = light.data.strength / 10;
light.data.strength = Zui.slider(lightHandle, "Strength", 0.0, 5.0, true) * 10;
light.data.strength = zui_slider(lightHandle, "Strength", 0.0, 5.0, true) * 10;
}
else if (Context.raw.selectedObject.ext.constructor == TCameraObject) {
else if (Context.raw.selectedObject.ext.constructor == camera_object_t) {
let cam = Context.raw.selectedObject.ext;
let fovHandle = Zui.handle("tabobjects_18");
let fovHandle = zui_handle("tabobjects_18");
fovHandle.value = Math.floor(cam.data.fov * 100) / 100;
cam.data.fov = Zui.slider(fovHandle, "FoV", 0.3, 2.0, true);
cam.data.fov = zui_slider(fovHandle, "FoV", 0.3, 2.0, true);
if (fovHandle.changed) {
CameraObject.buildProjection(cam);
camera_object_build_projection(cam);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion armorlab/Sources/MakeMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion armorlab/Sources/MakePaint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions armorlab/Sources/NodesBrush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions armorlab/Sources/RenderPathPaint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 779218d

Please sign in to comment.