From 66bccfe4b591a48a34fc5926293c55db6baa0510 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sun, 8 Dec 2019 16:59:08 +0100 Subject: [PATCH] Cleanup --- Sources/arm/App.hx | 4 +- Sources/arm/Config.hx | 49 +++---- Sources/arm/Project.hx | 18 +-- Sources/arm/Tool.hx | 173 ++++++++++++++++++++++- Sources/arm/data/BrushSlot.hx | 4 +- Sources/arm/data/LayerSlot.hx | 15 +- Sources/arm/data/MaterialSlot.hx | 4 +- Sources/arm/io/ExportArm.hx | 3 +- Sources/arm/io/ExportMesh.hx | 3 +- Sources/arm/io/ExportTexture.hx | 9 +- Sources/arm/io/ImportArm.hx | 3 +- Sources/arm/io/ImportObj.hx | 8 +- Sources/arm/node/MakeBake.hx | 40 +++--- Sources/arm/node/MakeMesh.hx | 24 ++-- Sources/arm/node/MakePaint.hx | 14 +- Sources/arm/node/MakeTexcoord.hx | 4 +- Sources/arm/node/MaterialBuilder.hx | 36 ++--- Sources/arm/plugin/Camera.hx | 11 +- Sources/arm/render/RenderPathDeferred.hx | 10 +- Sources/arm/render/RenderPathForward.hx | 4 +- Sources/arm/render/RenderPathPaint.hx | 31 ++-- Sources/arm/render/RenderPathRaytrace.hx | 11 +- Sources/arm/ui/BoxExport.hx | 11 +- Sources/arm/ui/BoxPreferences.hx | 2 +- Sources/arm/ui/UIMenu.hx | 14 +- Sources/arm/ui/UINodes.hx | 20 +-- Sources/arm/ui/UITrait.hx | 108 +++++++------- Sources/arm/ui/UIView2D.hx | 18 +-- Sources/arm/util/RenderUtil.hx | 4 +- Sources/arm/util/ViewportUtil.hx | 3 +- 30 files changed, 420 insertions(+), 238 deletions(-) diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index 83b29af4..d4956ec1 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -270,7 +270,7 @@ class App { } cam.buildProjection(); - if (UITrait.inst.cameraType == 1) { + if (UITrait.inst.cameraType == CameraOrthographic) { ViewportUtil.updateCameraType(UITrait.inst.cameraType); } @@ -320,7 +320,7 @@ class App { UITrait.inst.paintVec.y < 1 && UITrait.inst.paintVec.y > 0; var inLayers = UITrait.inst.htab.position == 0 && mx > UITrait.inst.tabx && my < UITrait.inst.tabh; - var in2dView = UIView2D.inst.show && UIView2D.inst.type == 0 && + var in2dView = UIView2D.inst.show && UIView2D.inst.type == View2DLayer && mx > UIView2D.inst.wx && mx < UIView2D.inst.wx + UIView2D.inst.ww && my > UIView2D.inst.wy && my < UIView2D.inst.wy + UIView2D.inst.wh; var inNodes = UINodes.inst.show && diff --git a/Sources/arm/Config.hx b/Sources/arm/Config.hx index c922d4c3..cd88a9ec 100644 --- a/Sources/arm/Config.hx +++ b/Sources/arm/Config.hx @@ -7,6 +7,7 @@ import iron.data.Data; #if arm_painter import arm.ui.UITrait; import arm.render.Inc; +import arm.Tool; #end class Config { @@ -170,39 +171,39 @@ class Config { public static function getTextureRes():Int { var resHandle = UITrait.inst.resHandle; - if (resHandle.position == 0) return 128; - if (resHandle.position == 1) return 256; - if (resHandle.position == 2) return 512; - if (resHandle.position == 3) return 1024; - if (resHandle.position == 4) return 2048; - if (resHandle.position == 5) return 4096; - if (resHandle.position == 6) return 8192; - if (resHandle.position == 7) return 16384; + if (resHandle.position == Res128) return 128; + if (resHandle.position == Res256) return 256; + if (resHandle.position == Res512) return 512; + if (resHandle.position == Res1024) return 1024; + if (resHandle.position == Res2048) return 2048; + if (resHandle.position == Res4096) return 4096; + if (resHandle.position == Res8192) return 8192; + if (resHandle.position == Res16384) return 16384; return 0; } public static function getTextureResBias():Float { var resHandle = UITrait.inst.resHandle; - if (resHandle.position == 0) return 16.0; - if (resHandle.position == 1) return 8.0; - if (resHandle.position == 2) return 4.0; - if (resHandle.position == 3) return 2.0; - if (resHandle.position == 4) return 1.5; - if (resHandle.position == 5) return 1.0; - if (resHandle.position == 6) return 0.5; - if (resHandle.position == 7) return 0.25; + if (resHandle.position == Res128) return 16.0; + if (resHandle.position == Res256) return 8.0; + if (resHandle.position == Res512) return 4.0; + if (resHandle.position == Res1024) return 2.0; + if (resHandle.position == Res2048) return 1.5; + if (resHandle.position == Res4096) return 1.0; + if (resHandle.position == Res8192) return 0.5; + if (resHandle.position == Res16384) return 0.25; return 1.0; } public static function getTextureResPos(i:Int):Int { - if (i == 128) return 0; - if (i == 256) return 1; - if (i == 512) return 2; - if (i == 1024) return 3; - if (i == 2048) return 4; - if (i == 4096) return 5; - if (i == 8192) return 6; - if (i == 16384) return 7; + if (i == 128) return Res128; + if (i == 256) return Res256; + if (i == 512) return Res512; + if (i == 1024) return Res1024; + if (i == 2048) return Res2048; + if (i == 4096) return Res4096; + if (i == 8192) return Res8192; + if (i == 16384) return Res16384; return 0; } #end diff --git a/Sources/arm/Project.hx b/Sources/arm/Project.hx index 6bc4b37d..288a1f98 100644 --- a/Sources/arm/Project.hx +++ b/Sources/arm/Project.hx @@ -26,6 +26,7 @@ import arm.io.ImportArm; import arm.io.ImportBlend; import arm.io.ImportMesh; import arm.io.ExportArm; +import arm.Tool; using StringTools; class Project { @@ -137,10 +138,9 @@ class Project { Data.deleteMesh(handle); } - if (UITrait.inst.projectType > 0) { - var mesh:Dynamic = UITrait.inst.projectType == 1 ? + if (UITrait.inst.projectType != ModelCube) { + var mesh:Dynamic = UITrait.inst.projectType == ModelSphere ? new arm.format.proc.Sphere(1, 512, 256) : - // new arm.format.proc.Plane(1, 1, 512, 512) : new arm.format.proc.Plane(1, 1, 512, 512); var raw = { name: "Tessellated", @@ -158,27 +158,27 @@ class Project { var md = new MeshData(raw, function(md:MeshData) {}); Data.cachedMeshes.set("SceneTessellated", md); - if (UITrait.inst.projectType == 1) { + if (UITrait.inst.projectType == ModelSphere) { ViewportUtil.setView(0, 0, 1, 0, 0, 0); // Top ViewportUtil.orbit(0, Math.PI / 6); // Orbit down } - else if (UITrait.inst.projectType == 2) { + else if (UITrait.inst.projectType == ModelTessellatedPlane) { ViewportUtil.setView(0, 0, 5, 0, 0, 0); // Top ViewportUtil.orbit(0, Math.PI / 6); // Orbit down } } - var n = UITrait.inst.projectType == 0 ? "Cube" : "Tessellated"; + var n = UITrait.inst.projectType == ModelCube ? "Cube" : "Tessellated"; Data.getMesh("Scene", n, function(md:MeshData) { var current = @:privateAccess kha.graphics4.Graphics2.current; if (current != null) current.end(); - UITrait.inst.pickerMaskHandle.position = 0; + UITrait.inst.pickerMaskHandle.position = MaskNone; Context.paintObject.setData(md); Context.paintObject.transform.scale.set(1, 1, 1); #if arm_creator - if (UITrait.inst.projectType == 2) { + if (UITrait.inst.projectType == ModelTessellatedPlane) { Context.paintObject.transform.loc.set(0, 0, -0.15); Context.paintObject.transform.scale.set(10, 10, 1); } @@ -247,7 +247,7 @@ class Project { if (ui.tab(Id.handle(), "Import Mesh")) { if (path.toLowerCase().endsWith(".obj")) { - UITrait.inst.splitBy = ui.combo(Id.handle({position: 0}), ["Object", "Group", "Material", "UDIM Tile"], "Split By", true); + UITrait.inst.splitBy = ui.combo(Id.handle(), ["Object", "Group", "Material", "UDIM Tile"], "Split By", true); if (ui.isHovered) ui.tooltip("Split .obj mesh into objects"); } diff --git a/Sources/arm/Tool.hx b/Sources/arm/Tool.hx index 5513e16b..d823349e 100644 --- a/Sources/arm/Tool.hx +++ b/Sources/arm/Tool.hx @@ -20,6 +20,177 @@ package arm; @:enum abstract Workspace(Int) from Int to Int { var SpacePaint = 0; - // var SpaceSculpt = 1; var SpaceScene = 1; } + +@:enum abstract BakeType(Int) from Int to Int { + var BakeInit = -1; + var BakeAO = 0; + var BakeCurvature = 1; + var BakeNormal = 2; + var BakeNormalObject = 3; + var BakeHeight = 4; + var BakeDerivative = 5; + var BakePosition = 6; + var BakeTexCoord = 7; + var BakeMaterialID = 8; + var BakeObjectID = 9; + var BakeLightmap = 10; + var BakeBentNormal = 11; + var BakeThickness = 12; +} + +@:enum abstract SplitType(Int) from Int to Int { + var SplitObject = 0; + var SplitGroup = 1; + var SplitMaterial = 2; + var SplitUdim = 3; +} + +@:enum abstract BakeAxis(Int) from Int to Int { + var BakeXYZ = 0; + var BakeX = 1; + var BakeY = 2; + var BakeZ = 3; + var BakeMX = 4; + var BakeMY = 5; + var BakeMZ = 6; +} + +@:enum abstract BakeUpAxis(Int) from Int to Int { + var BakeUpZ = 0; + var BakeUpY = 1; + var BakeUpX = 2; +} + +@:enum abstract ViewportMode(Int) from Int to Int { + var ViewRender = 0; + var ViewBaseColor = 1; + var ViewNormalMap = 2; + var ViewOcclusion = 3; + var ViewRoughness = 4; + var ViewMetallic = 5; + var ViewTexCoord = 6; + var ViewObjectNormal = 7; + var ViewMaterialID = 8; + var ViewObjectID = 9; + var ViewMask = 10; + var ViewPathTrace = 11; +} + +@:enum abstract FillType(Int) from Int to Int { + var FillObject = 0; + var FillFace = 1; + var FillAngle = 2; +} + +@:enum abstract UVType(Int) from Int to Int { + var UVMap = 0; + var UVTriplanar = 1; + var UVProject = 2; +} + +@:enum abstract PickerMask(Int) from Int to Int { + var MaskNone = 0; + var MaskMaterial = 1; +} + +@:enum abstract BlendType(Int) from Int to Int { + var BlendMix = 0; + var BlendDarken = 1; + var BlendMultiply = 2; + var BlendBurn = 3; + var BlendLighten = 4; + var BlendScreen = 5; + var BlendDodge = 6; + var BlendAdd = 7; + var BlendOverlay = 8; + var BlendSoftLight = 9; + var BlendLinearLight = 10; + var BlendDifference = 11; + var BlendSubtract = 12; + var BlendDivide = 13; + var BlendHue = 14; + var BlendSaturation = 15; + var BlendColor = 16; + var BlendValue = 17; +} + +@:enum abstract CameraControls(Int) from Int to Int { + var ControlsOrbit = 0; + var ControlsRotate = 0; + var ControlsFly = 0; +} + +@:enum abstract CameraType(Int) from Int to Int { + var CameraPerspective = 0; + var CameraOrthographic = 1; +} + +@:enum abstract TextureBits(Int) from Int to Int { + var Bits8 = 0; + var Bits16 = 1; + var Bits32 = 2; +} + +@:enum abstract TextureRes(Int) from Int to Int { + var Res128 = 0; + var Res256 = 1; + var Res512 = 2; + var Res1024 = 3; + var Res2048 = 4; + var Res4096 = 5; + var Res8192 = 6; + var Res16384 = 7; +} + +@:enum abstract TextureLdrFormat(Int) from Int to Int { + var FormatPng = 0; + var FormatJpg = 1; +} + +@:enum abstract TextureHdrFormat(Int) from Int to Int { + var FormatExr = 0; +} + +@:enum abstract MeshFormat(Int) from Int to Int { + var FormatObj = 0; + var FormatArm = 1; +} + +@:enum abstract MenuCategory(Int) from Int to Int { + var MenuFile = 0; + var MenuEdit = 1; + var MenuViewport = 2; + var MenuCamera = 3; + var MenuHelp = 4; +} + +@:enum abstract CanvasType(Int) from Int to Int { + var CanvasMaterial = 0; + var CanvasBrush = 1; +} + +@:enum abstract View2DType(Int) from Int to Int { + var View2DLayer = 0; + var View2DAsset = 1; +} + +@:enum abstract BorderSide(Int) from Int to Int { + var SideLeft = 0; + var SideRight = 1; + var SideTop = 2; + var SideBottom = 3; +} + +@:enum abstract PaintTex(Int) from Int to Int { + var TexBase = 0; + var TexNormal = 1; + var TexPack = 2; +} + +@:enum abstract ProjectModel(Int) from Int to Int { + var ModelCube = 0; + var ModelSphere = 1; + var ModelTessellatedPlane = 2; +} diff --git a/Sources/arm/data/BrushSlot.hx b/Sources/arm/data/BrushSlot.hx index cd06ebd6..2887589a 100644 --- a/Sources/arm/data/BrushSlot.hx +++ b/Sources/arm/data/BrushSlot.hx @@ -9,8 +9,8 @@ import iron.data.Data; class BrushSlot { public var nodes = new Nodes(); public var canvas:TNodeCanvas; - public var image:Image = null; // 200 - public var imageIcon:Image = null; // 50 + public var image:Image = null; // 200px + public var imageIcon:Image = null; // 50px public var previewReady = false; public var id = 0; static var defaultCanvas:String = null; diff --git a/Sources/arm/data/LayerSlot.hx b/Sources/arm/data/LayerSlot.hx index eaa2f436..5ad2d856 100644 --- a/Sources/arm/data/LayerSlot.hx +++ b/Sources/arm/data/LayerSlot.hx @@ -6,6 +6,7 @@ import iron.RenderPath; import iron.object.MeshObject; import arm.ui.UITrait; import arm.node.MaterialParser; +import arm.Tool; class LayerSlot { public var id = 0; @@ -27,11 +28,11 @@ class LayerSlot { static var first = true; - public var blending = 0; + public var blending = BlendMix; public var objectMask = 0; public var uvScale = 1.0; public var uvRot = 0.0; - public var uvType = 0; + public var uvType = UVMap; public var paintBase = true; public var paintOpac = true; public var paintOcc = true; @@ -74,8 +75,9 @@ class LayerSlot { } this.ext = ext; name = "Layer " + (id + 1); - var format = UITrait.inst.bitsHandle.position == 0 ? 'RGBA32' : - UITrait.inst.bitsHandle.position == 1 ? 'RGBA64' : 'RGBA128'; + var format = UITrait.inst.bitsHandle.position == Bits8 ? 'RGBA32' : + UITrait.inst.bitsHandle.position == Bits16 ? 'RGBA64' : + 'RGBA128'; { var t = new RenderTargetRaw(); @@ -287,8 +289,9 @@ class LayerSlot { } public function resizeAndSetBits() { - var format = UITrait.inst.bitsHandle.position == 0 ? TextureFormat.RGBA32 : - UITrait.inst.bitsHandle.position == 1 ? TextureFormat.RGBA64 : TextureFormat.RGBA128; + var format = UITrait.inst.bitsHandle.position == Bits8 ? TextureFormat.RGBA32 : + UITrait.inst.bitsHandle.position == Bits16 ? TextureFormat.RGBA64 : + TextureFormat.RGBA128; var res = Config.getTextureRes(); var rts = RenderPath.active.renderTargets; diff --git a/Sources/arm/data/MaterialSlot.hx b/Sources/arm/data/MaterialSlot.hx index 29646983..f97a61ad 100644 --- a/Sources/arm/data/MaterialSlot.hx +++ b/Sources/arm/data/MaterialSlot.hx @@ -11,8 +11,8 @@ import arm.util.RenderUtil; class MaterialSlot { public var nodes = new Nodes(); public var canvas:TNodeCanvas; - public var image:Image = null; // 200 - public var imageIcon:Image = null; // 50 + public var image:Image = null; // 200px + public var imageIcon:Image = null; // 50px public var previewReady = false; public var data:MaterialData; public var id = 0; diff --git a/Sources/arm/io/ExportArm.hx b/Sources/arm/io/ExportArm.hx index a8483b7d..e2833f66 100644 --- a/Sources/arm/io/ExportArm.hx +++ b/Sources/arm/io/ExportArm.hx @@ -9,6 +9,7 @@ import arm.ui.UINodes; import arm.format.Lz4; import arm.sys.Path; import arm.Project; +import arm.Tool; using StringTools; class ExportArm { @@ -63,7 +64,7 @@ class ExportArm { } var bitsPos = UITrait.inst.bitsHandle.position; - var bpp = bitsPos == 0 ? 8 : bitsPos == 1 ? 16 : 32; + var bpp = bitsPos == Bits8 ? 8 : bitsPos == Bits16 ? 16 : 32; var ld:Array = []; for (l in Project.layers) { diff --git a/Sources/arm/io/ExportMesh.hx b/Sources/arm/io/ExportMesh.hx index af200e9c..2fe893c2 100644 --- a/Sources/arm/io/ExportMesh.hx +++ b/Sources/arm/io/ExportMesh.hx @@ -1,11 +1,12 @@ package arm.io; import arm.ui.UITrait; +import arm.Tool; class ExportMesh { public static function run(path:String) { - if (UITrait.inst.exportMeshFormat == 0) ExportObj.run(path); + if (UITrait.inst.exportMeshFormat == FormatObj) ExportObj.run(path); else ExportArm.run(path); } } diff --git a/Sources/arm/io/ExportTexture.hx b/Sources/arm/io/ExportTexture.hx index eb01e054..45cce9cd 100644 --- a/Sources/arm/io/ExportTexture.hx +++ b/Sources/arm/io/ExportTexture.hx @@ -11,6 +11,7 @@ import arm.format.PngTools; import arm.ui.UITrait; import arm.ui.UIFiles; import arm.ui.BoxExport; +import arm.Tool; using StringTools; class ExportTexture { @@ -50,8 +51,8 @@ class ExportTexture { var f = UIFiles.filename; if (f == "") f = "untitled"; var formatType = UITrait.inst.formatType; - var bits = UITrait.inst.bitsHandle.position == 0 ? 8 : 16; - var ext = bits == 16 ? ".exr" : formatType == 0 ? ".png" : ".jpg"; + var bits = UITrait.inst.bitsHandle.position == Bits8 ? 8 : 16; + var ext = bits == 16 ? ".exr" : formatType == FormatPng ? ".png" : ".jpg"; if (f.endsWith(ext)) f = f.substr(0, f.length - 4); ext = udimTile + ext; var texpaint:Image = null; @@ -229,11 +230,11 @@ class ExportTexture { var out = new BytesOutput(); var res = Config.getTextureRes(); var bitsHandle = UITrait.inst.bitsHandle.position; - var bits = bitsHandle == 0 ? 8 : bitsHandle == 1 ? 16 : 32; + var bits = bitsHandle == Bits8 ? 8 : bitsHandle == Bits16 ? 16 : 32; if (bits > 8) { // 16/32bit var writer = new ExrWriter(out, res, res, pixels, bits, type, off); } - else if (UITrait.inst.formatType == 0) { + else if (UITrait.inst.formatType == FormatPng) { var writer = new PngWriter(out); var data = type == 1 ? diff --git a/Sources/arm/io/ImportArm.hx b/Sources/arm/io/ImportArm.hx index 15b340a8..69700764 100644 --- a/Sources/arm/io/ImportArm.hx +++ b/Sources/arm/io/ImportArm.hx @@ -29,6 +29,7 @@ import arm.data.LayerSlot; import arm.data.BrushSlot; import arm.data.MaterialSlot; import arm.node.MaterialParser; +import arm.Tool; using StringTools; class ImportArm { @@ -200,7 +201,7 @@ class ImportArm { var l0 = project.layer_datas[0]; UITrait.inst.resHandle.position = Config.getTextureResPos(l0.res); if (l0.bpp == null) l0.bpp = 8; // TODO: deprecated - var bitsPos = l0.bpp == 8 ? 0 : l0.bpp == 16 ? 1 : 2; + var bitsPos = l0.bpp == 8 ? Bits8 : l0.bpp == 16 ? Bits16 : Bits32; UITrait.inst.bitsHandle.position = bitsPos; var bytesPerPixel = Std.int(l0.bpp / 8); var format = l0.bpp == 8 ? TextureFormat.RGBA32 : l0.bpp == 16 ? TextureFormat.RGBA64 : TextureFormat.RGBA128; diff --git a/Sources/arm/io/ImportObj.hx b/Sources/arm/io/ImportObj.hx index 04a5e045..2c9191bd 100644 --- a/Sources/arm/io/ImportObj.hx +++ b/Sources/arm/io/ImportObj.hx @@ -4,13 +4,17 @@ import kha.Blob; import iron.data.Data; import arm.format.ObjParser; import arm.ui.UITrait; +import arm.Tool; class ImportObj { public static function run(path:String) { var i = UITrait.inst.splitBy; - var isUdim = i == 3; - ObjParser.splitCode = (i == 0 || isUdim) ? "o".code : i == 1 ? "g".code : "u".code; // object, group, usemtl + var isUdim = i == SplitUdim; + ObjParser.splitCode = + (i == SplitObject || isUdim) ? "o".code : + i == SplitGroup ? "g".code : + "u".code; // usemtl Data.getBlob(path, function(b:Blob) { if (isUdim) { var obj = new ObjParser(b, 0, isUdim); diff --git a/Sources/arm/node/MakeBake.hx b/Sources/arm/node/MakeBake.hx index b43a46e0..ad85f2d8 100644 --- a/Sources/arm/node/MakeBake.hx +++ b/Sources/arm/node/MakeBake.hx @@ -10,7 +10,7 @@ import arm.Tool; class MakeBake { public static function run(vert:MaterialShader, frag:MaterialShader) { - if (UITrait.inst.bakeType == 0) { // AO (voxel) + if (UITrait.inst.bakeType == BakeAO) { // Voxel // Apply normal channel frag.wposition = true; frag.n = true; @@ -34,14 +34,14 @@ class MakeBake { var radius = UITrait.inst.bakeAoRadius; var offset = UITrait.inst.bakeAoOffset; frag.write('float ao = traceAO(voxpos, n, $radius, $offset) * $strength;'); - if (UITrait.inst.bakeAxis > 0) { + if (UITrait.inst.bakeAxis != BakeXYZ) { var axis = axisString(UITrait.inst.bakeAxis); frag.write('ao *= dot(n, $axis);'); } frag.write('ao = 1.0 - ao;'); frag.write('fragColor[0] = vec4(ao, ao, ao, 1.0);'); } - else if (UITrait.inst.bakeType == 1) { // Curvature + else if (UITrait.inst.bakeType == BakeCurvature) { var strength = UITrait.inst.bakeCurvStrength * 2.0; var radius = (1.0 / UITrait.inst.bakeCurvRadius) * 0.25; var offset = UITrait.inst.bakeCurvOffset / 10; @@ -50,13 +50,13 @@ class MakeBake { frag.write('vec3 dy = dFdy(n);'); frag.write('float curvature = max(dot(dx, dx), dot(dy, dy));'); frag.write('curvature = clamp(pow(curvature, $radius) * $strength + $offset, 0.0, 1.0);'); - if (UITrait.inst.bakeAxis > 0) { + if (UITrait.inst.bakeAxis != BakeXYZ) { var axis = axisString(UITrait.inst.bakeAxis); frag.write('curvature *= dot(n, $axis);'); } frag.write('fragColor[0] = vec4(curvature, curvature, curvature, 1.0);'); } - else if (UITrait.inst.bakeType == 2) { // Normal (Tangent) + else if (UITrait.inst.bakeType == BakeNormal) { // Tangent frag.n = true; frag.add_uniform('sampler2D texpaint_undo', '_texpaint_undo'); // Baked high-poly normals frag.write('vec3 n0 = textureLod(texpaint_undo, texCoord, 0.0).rgb * vec3(2.0, 2.0, 2.0) - vec3(1.0, 1.0, 1.0);'); @@ -65,21 +65,21 @@ class MakeBake { frag.write('vec3 res = normalize(mul(n0, invTBN)) * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5);'); frag.write('fragColor[0] = vec4(res, 1.0);'); } - else if (UITrait.inst.bakeType == 3) { // Normal (Object) + else if (UITrait.inst.bakeType == BakeNormalObject) { frag.n = true; frag.write('fragColor[0] = vec4(n * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5), 1.0);'); - if (UITrait.inst.bakeUpAxis == 1) { // Y up + if (UITrait.inst.bakeUpAxis == BakeUpY) { frag.write('fragColor[0].rgb = vec3(fragColor[0].r, fragColor[0].b, 1.0 - fragColor[0].g);'); } } - else if (UITrait.inst.bakeType == 4) { // Height + else if (UITrait.inst.bakeType == BakeHeight) { frag.wposition = true; frag.add_uniform('sampler2D texpaint_undo', '_texpaint_undo'); // Baked high-poly positions frag.write('vec3 wpos0 = textureLod(texpaint_undo, texCoord, 0.0).rgb * vec3(2.0, 2.0, 2.0) - vec3(1.0, 1.0, 1.0);'); frag.write('float res = distance(wpos0, wposition) * 10.0;'); frag.write('fragColor[0] = vec4(res, res, res, 1.0);'); } - else if (UITrait.inst.bakeType == 5) { // Derivative + else if (UITrait.inst.bakeType == BakeDerivative) { frag.add_uniform('sampler2D texpaint_undo', '_texpaint_undo'); // Baked height frag.write('vec2 texDx = dFdx(texCoord);'); frag.write('vec2 texDy = dFdy(texCoord);'); @@ -88,17 +88,17 @@ class MakeBake { frag.write('float h2 = textureLod(texpaint_undo, texCoord + texDy, 0.0).r * 100;'); frag.write('fragColor[0] = vec4((h1 - h0) * 0.5 + 0.5, (h2 - h0) * 0.5 + 0.5, 0.0, 1.0);'); } - else if (UITrait.inst.bakeType == 6) { // Position + else if (UITrait.inst.bakeType == BakePosition) { frag.wposition = true; frag.write('fragColor[0] = vec4(wposition * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5), 1.0);'); - if (UITrait.inst.bakeUpAxis == 1) { // Y up + if (UITrait.inst.bakeUpAxis == BakeUpY) { frag.write('fragColor[0].rgb = vec3(fragColor[0].r, fragColor[0].b, 1.0 - fragColor[0].g);'); } } - else if (UITrait.inst.bakeType == 7) { // TexCoord + else if (UITrait.inst.bakeType == BakeTexCoord) { frag.write('fragColor[0] = vec4(texCoord.xy, 0.0, 1.0);'); } - else if (UITrait.inst.bakeType == 8) { // Material ID + else if (UITrait.inst.bakeType == BakeMaterialID) { frag.add_uniform('sampler2D texpaint_nor_undo', '_texpaint_nor_undo'); frag.write('float sample_matid = textureLod(texpaint_nor_undo, texCoord, 0.0).a + 1.0 / 255.0;'); frag.write('float matid_r = fract(sin(dot(vec2(sample_matid, sample_matid * 20.0), vec2(12.9898, 78.233))) * 43758.5453);'); @@ -106,7 +106,7 @@ class MakeBake { frag.write('float matid_b = fract(sin(dot(vec2(sample_matid, sample_matid * 40.0), vec2(12.9898, 78.233))) * 43758.5453);'); frag.write('fragColor[0] = vec4(matid_r, matid_g, matid_b, 1.0);'); } - else if (UITrait.inst.bakeType == 9) { // Object ID + else if (UITrait.inst.bakeType == BakeObjectID) { frag.add_uniform('float objectId', '_objectId'); frag.write('float obid = objectId + 1.0 / 255.0;'); frag.write('float id_r = fract(sin(dot(vec2(obid, obid * 20.0), vec2(12.9898, 78.233))) * 43758.5453);'); @@ -144,11 +144,11 @@ class MakeBake { } static function axisString(i:Int):String { - return i == 1 ? "vec3(1,0,0)" : - i == 2 ? "vec3(0,1,0)" : - i == 3 ? "vec3(0,0,1)" : - i == 4 ? "vec3(-1,0,0)" : - i == 5 ? "vec3(0,-1,0)" : - "vec3(0,0,-1)"; + return i == BakeX ? "vec3(1,0,0)" : + i == BakeY ? "vec3(0,1,0)" : + i == BakeZ ? "vec3(0,0,1)" : + i == BakeMX ? "vec3(-1,0,0)" : + i == BakeMY ? "vec3(0,-1,0)" : + "vec3(0,0,-1)"; } } diff --git a/Sources/arm/node/MakeMesh.hx b/Sources/arm/node/MakeMesh.hx index a2e2fe0d..5b924fe2 100644 --- a/Sources/arm/node/MakeMesh.hx +++ b/Sources/arm/node/MakeMesh.hx @@ -296,41 +296,41 @@ class MakeMesh { frag.write('basecol = pow(basecol, vec3(2.2, 2.2, 2.2));'); frag.write('fragColor[0] = vec4(n.xy, roughness, packFloatInt16(metallic, uint(matid)));'); - var deferred = UITrait.inst.viewportMode == 0 || UITrait.inst.viewportMode == 11; - if (deferred) { // Render, path-trace + var deferred = UITrait.inst.viewportMode == ViewRender || UITrait.inst.viewportMode == ViewPathTrace; + if (deferred) { if (MaterialBuilder.emisUsed) frag.write('if (matid == 1.0) basecol *= 10.0;'); // Boost for bloom frag.write('fragColor[1] = vec4(basecol, packFloat2(occlusion, 1.0));'); // occ/spec } - else if (UITrait.inst.viewportMode == 1) { // Basecol + else if (UITrait.inst.viewportMode == ViewBaseColor) { frag.write('fragColor[1] = vec4(basecol, 1.0);'); } - else if (UITrait.inst.viewportMode == 2) { // Normal Map + else if (UITrait.inst.viewportMode == ViewNormalMap) { frag.write('fragColor[1] = vec4(ntex.rgb, 1.0);'); } - else if (UITrait.inst.viewportMode == 3) { // Occ + else if (UITrait.inst.viewportMode == ViewOcclusion) { frag.write('fragColor[1] = vec4(vec3(occlusion, occlusion, occlusion), 1.0);'); } - else if (UITrait.inst.viewportMode == 4) { // Rough + else if (UITrait.inst.viewportMode == ViewRoughness) { frag.write('fragColor[1] = vec4(vec3(roughness, roughness, roughness), 1.0);'); } - else if (UITrait.inst.viewportMode == 5) { // Met + else if (UITrait.inst.viewportMode == ViewMetallic) { frag.write('fragColor[1] = vec4(vec3(metallic, metallic, metallic), 1.0);'); } - else if (UITrait.inst.viewportMode == 6) { // Texcoord + else if (UITrait.inst.viewportMode == ViewTexCoord) { frag.write('fragColor[1] = vec4(texCoord, 0.0, 1.0);'); } - else if (UITrait.inst.viewportMode == 7) { // Normal + else if (UITrait.inst.viewportMode == ViewObjectNormal) { frag.nAttr = true; frag.write('fragColor[1] = vec4(nAttr, 1.0);'); } - else if (UITrait.inst.viewportMode == 8) { // Material ID + else if (UITrait.inst.viewportMode == ViewMaterialID) { frag.write('float sample_matid = textureLodShared(texpaint_nor, texCoord, 0.0).a + 1.0 / 255.0;'); frag.write('float matid_r = fract(sin(dot(vec2(sample_matid, sample_matid * 20.0), vec2(12.9898, 78.233))) * 43758.5453);'); frag.write('float matid_g = fract(sin(dot(vec2(sample_matid * 20.0, sample_matid), vec2(12.9898, 78.233))) * 43758.5453);'); frag.write('float matid_b = fract(sin(dot(vec2(sample_matid, sample_matid * 40.0), vec2(12.9898, 78.233))) * 43758.5453);'); frag.write('fragColor[1] = vec4(matid_r, matid_g, matid_b, 1.0);'); } - else if (UITrait.inst.viewportMode == 9) { // Object ID + else if (UITrait.inst.viewportMode == ViewObjectID) { frag.add_uniform('float objectId', '_objectId'); frag.write('float obid = objectId + 1.0 / 255.0;'); frag.write('float id_r = fract(sin(dot(vec2(obid, obid * 20.0), vec2(12.9898, 78.233))) * 43758.5453);'); @@ -338,7 +338,7 @@ class MakeMesh { frag.write('float id_b = fract(sin(dot(vec2(obid, obid * 40.0), vec2(12.9898, 78.233))) * 43758.5453);'); frag.write('fragColor[1] = vec4(id_r, id_g, id_b, 1.0);'); } - else if (UITrait.inst.viewportMode == 10) { // Mask + else if (UITrait.inst.viewportMode == ViewMask) { frag.write('float sample_mask = 1.0;'); if (Context.layer.texpaint_mask != null) { frag.add_uniform('sampler2D texpaint_mask_view', '_texpaint_mask'); diff --git a/Sources/arm/node/MakePaint.hx b/Sources/arm/node/MakePaint.hx index 29f11a76..0a347feb 100644 --- a/Sources/arm/node/MakePaint.hx +++ b/Sources/arm/node/MakePaint.hx @@ -32,7 +32,7 @@ class MakePaint { frag.ins = vert.outs; #if kha_direct3d12 - if (Context.tool == ToolBake && UITrait.inst.bakeType == -1) { + if (Context.tool == ToolBake && UITrait.inst.bakeType == BakeInit) { // Init raytraced bake MakeBake.positionAndNormal(vert, frag); con_paint.data.shader_from_source = true; @@ -54,7 +54,7 @@ class MakePaint { return con_paint; } - var faceFill = Context.tool == ToolFill && UITrait.inst.fillTypeHandle.position == 1; + var faceFill = Context.tool == ToolFill && UITrait.inst.fillTypeHandle.position == FillFace; var decal = Context.tool == ToolDecal || Context.tool == ToolText; if (!faceFill && !decal) { // Fix seams at uv borders vert.add_uniform('vec2 sub', '_sub'); @@ -81,7 +81,7 @@ class MakePaint { frag.write_attrib('sp.z -= 0.0001;'); // small bias var uvType = Context.layer.material_mask != null ? Context.layer.uvType : UITrait.inst.brushPaint; - if (uvType == 2) frag.ndcpos = true; // Project + if (uvType == UVProject) frag.ndcpos = true; frag.add_uniform('vec4 inp', '_inputBrush'); frag.add_uniform('vec4 inplast', '_inputBrushLast'); @@ -128,7 +128,7 @@ class MakePaint { } else { // Fill, Bake frag.write('float dist = 0.0;'); - var angleFill = Context.tool == ToolFill && UITrait.inst.fillTypeHandle.position == 2; + var angleFill = Context.tool == ToolFill && UITrait.inst.fillTypeHandle.position == FillAngle; if (angleFill) { frag.add_function(MaterialFunctions.str_octahedronWrap); frag.add_uniform('sampler2D gbuffer0'); @@ -149,7 +149,7 @@ class MakePaint { else if (faceFill) { // TODO: allow to combine with colorid mask MakeDiscard.face(vert, frag); } - if (UITrait.inst.pickerMaskHandle.position == 1) { // material id mask + if (UITrait.inst.pickerMaskHandle.position == MaskMaterial) { MakeDiscard.materialId(vert, frag); } @@ -176,7 +176,7 @@ class MakePaint { Material.parse_height = Context.material.paintHeight; Material.parse_height_as_channel = true; var uvType = Context.layer.material_mask != null ? Context.layer.uvType : UITrait.inst.brushPaint; - Material.triplanar = uvType == 1 && !decal; + Material.triplanar = uvType == UVTriplanar && !decal; var sout = Material.parse(UINodes.inst.getCanvasMaterial(), con_paint, vert, frag, null, null, null, matcon); Material.parse_emission = false; Material.parse_subsurface = false; @@ -266,7 +266,7 @@ class MakePaint { frag.write('vec4 sample_undo = textureLod(texpaint_undo, sample_tc, 0.0);'); var matid = Context.material.id / 255; - if (UITrait.inst.pickerMaskHandle.position == 1) { // material id mask + if (UITrait.inst.pickerMaskHandle.position == MaskMaterial) { matid = UITrait.inst.materialIdPicked / 255; // Keep existing material id in place when mask is set } frag.write('float matid = $matid;'); diff --git a/Sources/arm/node/MakeTexcoord.hx b/Sources/arm/node/MakeTexcoord.hx index 955d39fe..f81eb71c 100644 --- a/Sources/arm/node/MakeTexcoord.hx +++ b/Sources/arm/node/MakeTexcoord.hx @@ -15,7 +15,7 @@ class MakeTexcoord { var decal = Context.tool == ToolDecal || Context.tool == ToolText; // TexCoords - project - if (uvType == 2 || decal) { + if (uvType == UVProject || decal) { frag.add_uniform('float brushScale', '_brushScale'); frag.write_attrib('vec2 uvsp = sp.xy;'); @@ -45,7 +45,7 @@ class MakeTexcoord { } } // TexCoords - uvmap - else if (uvType == 0) { + else if (uvType == UVMap) { vert.add_uniform('float brushScale', '_brushScale'); vert.add_out('vec2 texCoord'); vert.write('texCoord = subtex * brushScale;'); diff --git a/Sources/arm/node/MaterialBuilder.hx b/Sources/arm/node/MaterialBuilder.hx index 587518b3..52c5e913 100644 --- a/Sources/arm/node/MaterialBuilder.hx +++ b/Sources/arm/node/MaterialBuilder.hx @@ -34,65 +34,65 @@ class MaterialBuilder { } public static function blendMode(frag:MaterialShader, blending:Int, cola:String, colb:String, opac:String):String { - if (blending == 0) { // Mix + if (blending == BlendMix) { return 'mix($cola, $colb, $opac)'; } - else if (blending == 1) { // Darken + else if (blending == BlendDarken) { return 'mix($cola, min($cola, $colb), $opac)'; } - else if (blending == 2) { // Multiply + else if (blending == BlendMultiply) { return 'mix($cola, $cola * $colb, $opac)'; } - else if (blending == 3) { // Burn + else if (blending == BlendBurn) { return 'mix($cola, vec3(1.0, 1.0, 1.0) - (vec3(1.0, 1.0, 1.0) - $cola) / $colb, $opac)'; } - else if (blending == 4) { // Lighten + else if (blending == BlendLighten) { return 'max($cola, $colb * $opac)'; } - else if (blending == 5) { // Screen + else if (blending == BlendScreen) { return '(vec3(1.0, 1.0, 1.0) - (vec3(1.0 - $opac, 1.0 - $opac, 1.0 - $opac) + $opac * (vec3(1.0, 1.0, 1.0) - $colb)) * (vec3(1.0, 1.0, 1.0) - $cola))'; } - else if (blending == 6) { // Dodge + else if (blending == BlendDodge) { return 'mix($cola, $cola / (vec3(1.0, 1.0, 1.0) - $colb), $opac)'; } - else if (blending == 7) { // Add + else if (blending == BlendAdd) { return 'mix($cola, $cola + $colb, $opac)'; } - else if (blending == 8) { // Overlay + else if (blending == BlendOverlay) { #if (kha_direct3d11 || kha_direct3d12) return 'mix($cola, ($cola < vec3(0.5, 0.5, 0.5) ? vec3(2.0, 2.0, 2.0) * $cola * $colb : vec3(1.0, 1.0, 1.0) - vec3(2.0, 2.0, 2.0) * (vec3(1.0, 1.0, 1.0) - $colb) * (vec3(1.0, 1.0, 1.0) - $cola)), $opac)'; #else return 'mix($cola, $colb, $opac)'; // TODO #end } - else if (blending == 9) { // Soft Light + else if (blending == BlendSoftLight) { return '((1.0 - $opac) * $cola + $opac * ((vec3(1.0, 1.0, 1.0) - $cola) * $colb * $cola + $cola * (vec3(1.0, 1.0, 1.0) - (vec3(1.0, 1.0, 1.0) - $colb) * (vec3(1.0, 1.0, 1.0) - $cola))))'; } - else if (blending == 10) { // Linear Light + else if (blending == BlendLinearLight) { return '($cola + $opac * (vec3(2.0, 2.0, 2.0) * ($colb - vec3(0.5, 0.5, 0.5))))'; } - else if (blending == 11) { // Difference + else if (blending == BlendDifference) { return 'mix($cola, abs($cola - $colb), $opac)'; } - else if (blending == 12) { // Subtract + else if (blending == BlendSubtract) { return 'mix($cola, $cola - $colb, $opac)'; } - else if (blending == 13) { // Divide + else if (blending == BlendDivide) { return 'vec3(1.0 - $opac, 1.0 - $opac, 1.0 - $opac) * $cola + vec3($opac, $opac, $opac) * $cola / $colb'; } - else if (blending == 14) { // Hue + else if (blending == BlendHue) { frag.add_function(MaterialFunctions.str_hue_sat); return 'mix($cola, hsv_to_rgb(vec3(rgb_to_hsv($colb).r, rgb_to_hsv($cola).g, rgb_to_hsv($cola).b)), $opac)'; } - else if (blending == 15) { // Saturation + else if (blending == BlendSaturation) { frag.add_function(MaterialFunctions.str_hue_sat); return 'mix($cola, hsv_to_rgb(vec3(rgb_to_hsv($cola).r, rgb_to_hsv($colb).g, rgb_to_hsv($cola).b)), $opac)'; } - else if (blending == 16) { // Color + else if (blending == BlendColor) { frag.add_function(MaterialFunctions.str_hue_sat); return 'mix($cola, hsv_to_rgb(vec3(rgb_to_hsv($colb).r, rgb_to_hsv($colb).g, rgb_to_hsv($cola).b)), $opac)'; } - else { // Value + else { // BlendValue frag.add_function(MaterialFunctions.str_hue_sat); return 'mix($cola, hsv_to_rgb(vec3(rgb_to_hsv($cola).r, rgb_to_hsv($cola).g, rgb_to_hsv($colb).b)), $opac)'; } diff --git a/Sources/arm/plugin/Camera.hx b/Sources/arm/plugin/Camera.hx index 0aec6505..fcef39c3 100644 --- a/Sources/arm/plugin/Camera.hx +++ b/Sources/arm/plugin/Camera.hx @@ -6,6 +6,7 @@ import iron.math.Vec4; import iron.math.Mat4; import arm.ui.UITrait; import arm.util.ViewportUtil; +import arm.Tool; class Camera { @@ -42,7 +43,7 @@ class Camera { var modif = kb.down("alt") || kb.down("shift") || kb.down("control") || Config.keymap.action_rotate == "middle"; var controls = UITrait.inst.cameraControls; - if (controls == 0) { // Orbit + if (controls == ControlsOrbit) { if (Operator.shortcut(Config.keymap.action_rotate) || (mouse.down("right") && !modif)) { redraws = 2; camera.transform.move(camera.lookWorld(), dist); @@ -86,7 +87,7 @@ class Camera { light.transform.decompose(); } } - else if (controls == 1) { // Rotate + else if (controls == ControlsRotate) { if (Operator.shortcut(Config.keymap.action_rotate) || (mouse.down("right") && !modif)) { redraws = 2; var t = Context.object.transform; @@ -119,7 +120,7 @@ class Camera { camera.transform.move(camera.look(), mouse.wheelDelta * (-0.1)); } } - else if (controls == 2 && mouse.down("right")) { + else if (controls == ControlsFly && mouse.down("right")) { var moveForward = kb.down("w") || kb.down("up") || mouse.wheelDelta < 0; var moveBackward = kb.down("s") || kb.down("down") || mouse.wheelDelta > 0; var strafeLeft = kb.down("a") || kb.down("left"); @@ -150,7 +151,7 @@ class Camera { var d = Time.delta * speed * fast * ease; if (d > 0.0) { camera.transform.move(dir, d); - if (UITrait.inst.cameraType == 1) { + if (UITrait.inst.cameraType == CameraOrthographic) { ViewportUtil.updateCameraType(UITrait.inst.cameraType); } } @@ -164,7 +165,7 @@ class Camera { redraws--; Context.ddirty = 2; - if (UITrait.inst.cameraType == 1) { + if (UITrait.inst.cameraType == CameraOrthographic) { ViewportUtil.updateCameraType(UITrait.inst.cameraType); } } diff --git a/Sources/arm/render/RenderPathDeferred.hx b/Sources/arm/render/RenderPathDeferred.hx index e247172d..e5c66d4c 100644 --- a/Sources/arm/render/RenderPathDeferred.hx +++ b/Sources/arm/render/RenderPathDeferred.hx @@ -337,7 +337,7 @@ class RenderPathDeferred { #end #if kha_direct3d12 - if (UITrait.inst.viewportMode == 11) { // Ray-traced + if (UITrait.inst.viewportMode == ViewPathTrace) { RenderPathRaytrace.draw(); return; } @@ -358,11 +358,11 @@ class RenderPathDeferred { var cameraType = UITrait.inst.cameraType; var ddirty = Context.ddirty; #else - var cameraType = 0; + var cameraType = CameraPerspective; var ddirty = 2; #end - var ssgi = Config.raw.rp_ssgi != false && cameraType == 0; + var ssgi = Config.raw.rp_ssgi != false && cameraType == CameraPerspective; if (ssgi && ddirty > 0 && taaFrame > 0) { path.setTarget("singlea"); path.bindTarget("_main", "gbufferD"); @@ -425,7 +425,7 @@ class RenderPathDeferred { path.bindTarget("_main", "gbufferD"); path.bindTarget("gbuffer0", "gbuffer0"); path.bindTarget("gbuffer1", "gbuffer1"); - var ssgi = Config.raw.rp_ssgi != false && cameraType == 0; + var ssgi = Config.raw.rp_ssgi != false && cameraType == CameraPerspective; if (ssgi && taaFrame > 0) { path.bindTarget("singlea", "ssaotex"); } @@ -697,7 +697,7 @@ class RenderPathDeferred { drawGbuffer(); #if kha_direct3d12 - UITrait.inst.viewportMode == 11 ? RenderPathRaytrace.draw() : drawDeferred(); + UITrait.inst.viewportMode == ViewPathTrace ? RenderPathRaytrace.draw() : drawDeferred(); #else drawDeferred(); #end diff --git a/Sources/arm/render/RenderPathForward.hx b/Sources/arm/render/RenderPathForward.hx index 1af57a6c..f2c8e113 100644 --- a/Sources/arm/render/RenderPathForward.hx +++ b/Sources/arm/render/RenderPathForward.hx @@ -148,7 +148,7 @@ class RenderPathForward { #end #if kha_direct3d12 - if (UITrait.inst.viewportMode == 11) { // Ray-traced + if (UITrait.inst.viewportMode == ViewPathTrace) { RenderPathRaytrace.draw(); return; } @@ -258,7 +258,7 @@ class RenderPathForward { drawGbuffer(); #if kha_direct3d12 - UITrait.inst.viewportMode == 11 ? RenderPathRaytrace.draw() : drawForward(); + UITrait.inst.viewportMode == ViewPathTrace ? RenderPathRaytrace.draw() : drawForward(); #else drawForward(); #end diff --git a/Sources/arm/render/RenderPathPaint.hx b/Sources/arm/render/RenderPathPaint.hx index 9a8995a3..c76a2914 100644 --- a/Sources/arm/render/RenderPathPaint.hx +++ b/Sources/arm/render/RenderPathPaint.hx @@ -144,7 +144,7 @@ class RenderPathPaint { } else { #if (!kha_direct3d12) - if (Context.tool == ToolBake && UITrait.inst.bakeType == 0) { // AO + if (Context.tool == ToolBake && UITrait.inst.bakeType == BakeAO) { if (initVoxels) { initVoxels = false; // Init voxel texture @@ -185,7 +185,7 @@ class RenderPathPaint { } path.bindTarget(blendB, "paintmask"); #if (!kha_direct3d12) - if (Context.tool == ToolBake && UITrait.inst.bakeType == 0) { // AO + if (Context.tool == ToolBake && UITrait.inst.bakeType == BakeAO) { path.bindTarget("voxels", "voxels"); } #end @@ -194,7 +194,7 @@ class RenderPathPaint { } // Read texcoords from gbuffer - var readTC = (Context.tool == ToolFill && UITrait.inst.fillTypeHandle.position == 1) || // Face fill + var readTC = (Context.tool == ToolFill && UITrait.inst.fillTypeHandle.position == FillFace) || Context.tool == ToolClone || Context.tool == ToolBlur; if (readTC) { @@ -203,7 +203,7 @@ class RenderPathPaint { path.drawMeshes("paint"); - if (Context.tool == ToolBake && UITrait.inst.bakeType == 1 && UITrait.inst.bakeCurvSmooth > 0) { // Curvature + if (Context.tool == ToolBake && UITrait.inst.bakeType == BakeCurvature && UITrait.inst.bakeCurvSmooth > 0) { if (path.renderTargets.get("texpaint_blur") == null) { var t = new RenderTargetRaw(); t.name = "texpaint_blur"; @@ -301,7 +301,7 @@ class RenderPathPaint { var cam = Scene.active.camera; UITrait.inst.savedCamera.setFrom(cam.transform.local); savedFov = cam.data.raw.fov; - ViewportUtil.updateCameraType(0); + ViewportUtil.updateCameraType(CameraPerspective); var m = Mat4.identity(); m.translate(0, 0, 0.5); cam.transform.setMatrix(m); @@ -390,14 +390,11 @@ class RenderPathPaint { if (Context.tool == ToolBake) { if (Context.pdirty > 0) dilated = false; - var isNormal = UITrait.inst.bakeType == 2; // Normal (Tangent) - var isHeight = UITrait.inst.bakeType == 4; - var isDeriv = UITrait.inst.bakeType == 5; - if (isNormal || isHeight || isDeriv) { + if (UITrait.inst.bakeType == BakeNormal || UITrait.inst.bakeType == BakeHeight || UITrait.inst.bakeType == BakeDerivative) { if (!baking && Context.pdirty > 0) { baking = true; var _bakeType = UITrait.inst.bakeType; - UITrait.inst.bakeType = isNormal ? 3 : 6; // Bake high poly object normals / position + UITrait.inst.bakeType = UITrait.inst.bakeType == BakeNormal ? BakeNormalObject : BakePosition; // Bake high poly data MaterialParser.parsePaintMaterial(); var _paintObject = Context.paintObject; var highPoly = Project.paintObjects[UITrait.inst.bakeHighPoly]; @@ -420,7 +417,7 @@ class RenderPathPaint { baking = false; } function _renderDeriv(_) { - UITrait.inst.bakeType = 4; // Bake height + UITrait.inst.bakeType = BakeHeight; MaterialParser.parsePaintMaterial(); Context.pdirty = 1; RenderPathPaint.commandsPaint(); @@ -430,10 +427,10 @@ class RenderPathPaint { iron.App.removeRender(_renderDeriv); iron.App.notifyOnRender(_renderFinal); } - iron.App.notifyOnRender(isDeriv ? _renderDeriv : _renderFinal); + iron.App.notifyOnRender(UITrait.inst.bakeType == BakeDerivative ? _renderDeriv : _renderFinal); } } - else if (UITrait.inst.bakeType == 8) { // Object ID + else if (UITrait.inst.bakeType == BakeObjectID) { var _layerFilter = UITrait.inst.layerFilter; var _paintObject = Context.paintObject; var isMerged = Context.mergedObject != null; @@ -451,10 +448,10 @@ class RenderPathPaint { if (isMerged) Context.mergedObject.visible = _visible; } #if kha_direct3d12 - else if (UITrait.inst.bakeType == 0 || // AO (DXR) - UITrait.inst.bakeType == 10 || // Lightmap (DXR) - UITrait.inst.bakeType == 11 || // Bent Normal (DXR) - UITrait.inst.bakeType == 12) { // Thickness (DXR) + else if (UITrait.inst.bakeType == BakeAO || + UITrait.inst.bakeType == BakeLightmap || + UITrait.inst.bakeType == BakeBentNormal || + UITrait.inst.bakeType == BakeThickness) { RenderPathRaytrace.commandsBake(); } #end diff --git a/Sources/arm/render/RenderPathRaytrace.hx b/Sources/arm/render/RenderPathRaytrace.hx index e77e75ca..9ce498ea 100644 --- a/Sources/arm/render/RenderPathRaytrace.hx +++ b/Sources/arm/render/RenderPathRaytrace.hx @@ -4,6 +4,7 @@ import iron.RenderPath; import iron.Scene; import arm.ui.UITrait; import arm.node.MaterialParser; +import arm.Tool; #if kha_direct3d12 @@ -142,7 +143,7 @@ class RenderPathRaytrace { } var _bakeType = UITrait.inst.bakeType; - UITrait.inst.bakeType = -1; + UITrait.inst.bakeType = BakeInit; MaterialParser.parsePaintMaterial(); path.setTarget("baketex0"); path.clearTarget(0x00000000); // Pixels with alpha of 0.0 are skipped during raytracing @@ -316,10 +317,10 @@ class RenderPathRaytrace { static function getBakeShaderName():String { return - UITrait.inst.bakeType == 0 ? "raytrace_bake_ao.cso" : - UITrait.inst.bakeType == 10 ? "raytrace_bake_light.cso" : - UITrait.inst.bakeType == 11 ? "raytrace_bake_bent.cso" : - "raytrace_bake_thick.cso"; + UITrait.inst.bakeType == BakeAO ? "raytrace_bake_ao.cso" : + UITrait.inst.bakeType == BakeLightmap ? "raytrace_bake_light.cso" : + UITrait.inst.bakeType == BakeBentNormal ? "raytrace_bake_bent.cso" : + "raytrace_bake_thick.cso"; } public static function draw() { diff --git a/Sources/arm/ui/BoxExport.hx b/Sources/arm/ui/BoxExport.hx index 13ad40d0..c84c0215 100644 --- a/Sources/arm/ui/BoxExport.hx +++ b/Sources/arm/ui/BoxExport.hx @@ -8,6 +8,7 @@ import arm.io.ExportMesh; import arm.io.ExportTexture; import arm.sys.Path; import arm.sys.File; +import arm.Tool; using StringTools; class BoxExport { @@ -46,13 +47,13 @@ class BoxExport { } ui.row([1/2, 1/2]); - if (UITrait.inst.bitsHandle.position == 0) { + if (UITrait.inst.bitsHandle.position == Bits8) { UITrait.inst.formatType = ui.combo(Id.handle({position: UITrait.inst.formatType}), ["png", "jpg"], "Format", true); } else { - ui.combo(Id.handle({position: UITrait.inst.formatType}), ["exr"], "Format", true); + UITrait.inst.formatType = ui.combo(Id.handle({position: UITrait.inst.formatType}), ["exr"], "Format", true); } - ui.enabled = UITrait.inst.formatType == 1 && UITrait.inst.bitsHandle.position == 0; + ui.enabled = UITrait.inst.formatType == FormatJpg && UITrait.inst.bitsHandle.position == Bits8; UITrait.inst.formatQuality = ui.slider(Id.handle({value: UITrait.inst.formatQuality}), "Quality", 0.0, 100.0, true, 1); ui.enabled = true; ui.row([1/2, 1/2]); @@ -68,7 +69,7 @@ class BoxExport { } if (ui.button("Export")) { UIBox.show = false; - var filters = UITrait.inst.bitsHandle.position > 0 ? "exr" : UITrait.inst.formatType == 0 ? "png" : "jpg"; + var filters = UITrait.inst.bitsHandle.position != Bits8 ? "exr" : UITrait.inst.formatType == FormatPng ? "png" : "jpg"; UIFiles.show(filters, true, function(path:String) { UITrait.inst.textureExportPath = path; function export(_) { @@ -200,7 +201,7 @@ class BoxExport { } if (ui.button("Export")) { UIBox.show = false; - UIFiles.show(UITrait.inst.exportMeshFormat == 0 ? "obj" : "arm", true, function(path:String) { + UIFiles.show(UITrait.inst.exportMeshFormat == FormatObj ? "obj" : "arm", true, function(path:String) { var f = UIFiles.filename; if (f == "") f = "untitled"; ExportMesh.run(path + "/" + f); diff --git a/Sources/arm/ui/BoxPreferences.hx b/Sources/arm/ui/BoxPreferences.hx index f2663ef0..f4cbdbc5 100644 --- a/Sources/arm/ui/BoxPreferences.hx +++ b/Sources/arm/ui/BoxPreferences.hx @@ -34,7 +34,7 @@ class BoxPreferences { setScale(); } UITrait.inst.hscaleWasChanged = hscale.changed; - var themeHandle = Id.handle({position: 0}); + var themeHandle = Id.handle(); var themes = ["Dark", "Light"]; ui.combo(themeHandle, themes, "Theme", true); if (themeHandle.changed) { diff --git a/Sources/arm/ui/UIMenu.hx b/Sources/arm/ui/UIMenu.hx index c648cf3d..c2db0701 100644 --- a/Sources/arm/ui/UIMenu.hx +++ b/Sources/arm/ui/UIMenu.hx @@ -18,6 +18,7 @@ import arm.sys.Path; import arm.sys.File; import arm.node.MaterialParser; import arm.io.ImportAsset; +import arm.Tool; using StringTools; class UIMenu { @@ -56,7 +57,7 @@ class UIMenu { g.color = ui.t.SEPARATOR_COL; g.fillRect(menuX, menuY, menuW, 28 * menuItems[menuCategory] * ui.SCALE()); - if (menuCategory == 0) { + if (menuCategory == MenuFile) { if (ui.button("New Project...", Left, Config.keymap.file_new)) Project.projectNewBox(); if (ui.button("Open...", Left, Config.keymap.file_open)) Project.projectOpen(); if (ui.button("Save", Left, Config.keymap.file_save)) Project.projectSave(); @@ -73,7 +74,7 @@ class UIMenu { ui.fill(0, 0, sepw, 1, ui.t.ACCENT_SELECT_COL); if (ui.button("Exit", Left)) System.stop(); } - else if (menuCategory == 1) { + else if (menuCategory == MenuEdit) { var stepUndo = ""; var stepRedo = ""; if (History.undos > 0) { @@ -90,7 +91,7 @@ class UIMenu { ui.fill(0, 0, sepw, 1, ui.t.ACCENT_SELECT_COL); if (ui.button("Preferences...", Left, Config.keymap.edit_prefs)) BoxPreferences.show(); } - else if (menuCategory == 2) { + else if (menuCategory == MenuViewport) { if (Scene.active.world.probe.radianceMipmaps.length > 0) { ui.image(Scene.active.world.probe.radianceMipmaps[0]); } @@ -236,7 +237,7 @@ class UIMenu { if (ui.changed) keepOpen = true; } - else if (menuCategory == 3) { + else if (menuCategory == MenuCamera) { if (ui.button("Reset", Left, Config.keymap.view_reset)) { ViewportUtil.resetViewport(); ViewportUtil.scaleToBounds(); } ui.fill(0, 0, sepw, 1, ui.t.ACCENT_SELECT_COL); if (ui.button("Front", Left, Config.keymap.view_front)) { ViewportUtil.setView(0, -1, 0, Math.PI / 2, 0, 0); } @@ -274,9 +275,6 @@ class UIMenu { ViewportUtil.updateCameraType(UITrait.inst.cameraType); } - // UITrait.inst.cameraControls = ui.combo(Id.handle({position: UITrait.inst.cameraControls}), ["Orbit", "Rotate", "Fly"], "Controls"); - // UITrait.inst.cameraType = ui.combo(UITrait.inst.camHandle, ["Perspective", "Orthographic"], "Type"); - UITrait.inst.cameraControls = Ext.inlineRadio(ui, Id.handle({position: UITrait.inst.cameraControls}), ["Orbit", "Rotate", "Fly"], Left); UITrait.inst.cameraType = Ext.inlineRadio(ui, UITrait.inst.camHandle, ["Perspective", "Orthographic"], Left); @@ -288,7 +286,7 @@ class UIMenu { if (ui.changed) keepOpen = true; } - else if (menuCategory == 4) { + else if (menuCategory == MenuHelp) { if (ui.button("Manual", Left)) { File.explorer("https://armorpaint.org/manual"); } diff --git a/Sources/arm/ui/UINodes.hx b/Sources/arm/ui/UINodes.hx index 680961b3..5132a4f0 100644 --- a/Sources/arm/ui/UINodes.hx +++ b/Sources/arm/ui/UINodes.hx @@ -32,7 +32,7 @@ class UINodes { public var wh:Int; public var ui:Zui; - public var canvasType = 0; // material, brush + public var canvasType = CanvasMaterial; var drawMenu = false; var showMenu = false; var hideMenu = false; @@ -86,7 +86,7 @@ class UINodes { } public function getCanvas():TNodeCanvas { - if (canvasType == 0) return getCanvasMaterial(); + if (canvasType == CanvasMaterial) return getCanvasMaterial(); else return Context.brush.canvas; } @@ -97,7 +97,7 @@ class UINodes { public function getNodes():Nodes { var isScene = UITrait.inst.worktab.position == SpaceScene; - if (canvasType == 0) return isScene ? Context.materialScene.nodes : Context.material.nodes; + if (canvasType == CanvasMaterial) return isScene ? Context.materialScene.nodes : Context.material.nodes; else return Context.brush.nodes; } @@ -110,11 +110,11 @@ class UINodes { if (ui.changed) { mchanged = true; if (!mdown) changed = true; - if (canvasType == 1) MaterialParser.parseBrush(); + if (canvasType == CanvasBrush) MaterialParser.parseBrush(); } if ((mreleased && mchanged) || changed) { mchanged = changed = false; - if (canvasType == 0) { + if (canvasType == CanvasMaterial) { canvasChanged(); } if (mreleased) { @@ -211,7 +211,7 @@ class UINodes { var enter = kb.down("enter"); var count = 0; var BUTTON_COL = ui.t.BUTTON_COL; - var nodeList = canvasType == 0 ? NodesMaterial.list : NodesBrush.list; + var nodeList = canvasType == CanvasMaterial ? NodesMaterial.list : NodesBrush.list; for (list in nodeList) { for (n in list) { if (n.name.toLowerCase().indexOf(search) >= 0) { @@ -401,7 +401,7 @@ class UINodes { var BUTTON_COL = ui.t.BUTTON_COL; ui.t.BUTTON_COL = ui.t.WINDOW_BG_COL; - var cats = canvasType == 0 ? NodesMaterial.categories : NodesBrush.categories; + var cats = canvasType == CanvasMaterial ? NodesMaterial.categories : NodesBrush.categories; for (i in 0...cats.length) { if ((ui.button(cats[i], Left) && UITrait.inst.ui.comboSelectedHandle == null) || (ui.isHovered && drawMenu)) { addNodeButton = true; @@ -428,8 +428,8 @@ class UINodes { g.begin(false); if (drawMenu) { - var list = canvasType == 0 ? NodesMaterial.list : NodesBrush.list; - var canvas = canvasType == 0 ? Context.material.canvas : Context.brush.canvas; + var list = canvasType == CanvasMaterial ? NodesMaterial.list : NodesBrush.list; + var canvas = canvasType == CanvasMaterial ? Context.material.canvas : Context.brush.canvas; var numNodes = list[menuCategory].length; var ph = numNodes * ui.t.ELEMENT_H * ui.SCALE(); @@ -471,7 +471,7 @@ class UINodes { } public function acceptAssetDrag(assetIndex:Int) { - var n = canvasType == 0 ? NodesMaterial.createNode("TEX_IMAGE") : NodesBrush.createNode("TEX_IMAGE"); + var n = canvasType == CanvasMaterial ? NodesMaterial.createNode("TEX_IMAGE") : NodesBrush.createNode("TEX_IMAGE"); n.buttons[0].default_value = assetIndex; getNodes().nodesSelected = [n]; } diff --git a/Sources/arm/ui/UITrait.hx b/Sources/arm/ui/UITrait.hx index b523893e..85328cf3 100644 --- a/Sources/arm/ui/UITrait.hx +++ b/Sources/arm/ui/UITrait.hx @@ -73,7 +73,7 @@ class UITrait { public var uvxPicked = 0.0; public var uvyPicked = 0.0; public var pickerSelectMaterial = true; - public var pickerMaskHandle = new Handle({position: 0}); + public var pickerMaskHandle = new Handle(); var borderStarted = 0; var borderHandle:Handle = null; @@ -97,7 +97,7 @@ class UITrait { public var ui:Zui; public var colorIdHandle = Id.handle(); - public var formatType = 0; + public var formatType = FormatPng; public var formatQuality = 100.0; public var layersExport = 0; public var isBase = true; @@ -118,7 +118,7 @@ class UITrait { public var isHeightSpace = 0; public var isSubs = false; public var isSubsSpace = 0; - public var splitBy = 0; + public var splitBy = SplitObject; public var parseTransform = false; public var hwnd = Id.handle(); public var hwnd1 = Id.handle(); @@ -131,17 +131,17 @@ class UITrait { #end public var decalImage:Image = null; public var decalPreview = false; - public var viewportMode = 0; + public var viewportMode = ViewRender; public var hscaleWasChanged = false; - public var exportMeshFormat = 0; + public var exportMeshFormat = FormatObj; public var nativeBrowser = true; public var cacheDraws = false; public var textToolImage:Image = null; public var textToolText = "Text"; - public var textToolHandle = new Handle({position: 0}); + public var textToolHandle = new Handle(); public var decalMaskImage:Image = null; - public var decalMaskHandle = new Handle({position: 0}); + public var decalMaskHandle = new Handle(); public var particleMaterial:MaterialData = null; public var layerFilter = 0; @@ -177,21 +177,21 @@ class UITrait { public var brushRadiusHandle = new Handle({value: 0.5}); public var brushScaleX = 1.0; public var brushScaleXHandle = new Handle({value: 1.0}); - public var brushBlending = 0; + public var brushBlending = BlendMix; public var brushOpacity = 1.0; public var brushOpacityHandle = new Handle({value: 1.0}); public var brushScale = 1.0; public var brushRot = 0.0; public var brushHardness = 0.8; public var brushBias = 1.0; - public var brushPaint = 0; + public var brushPaint = UVMap; public var brush3d = true; public var brushDepthReject = true; public var brushAngleReject = true; public var brushAngleRejectDot = 0.5; - public var bakeType = 0; - public var bakeAxis = 0; - public var bakeUpAxis = 0; + public var bakeType = BakeAO; + public var bakeAxis = BakeXYZ; + public var bakeUpAxis = BakeUpZ; public var bakeAoStrength = 1.0; public var bakeAoRadius = 1.0; public var bakeAoOffset = 1.0; @@ -208,12 +208,12 @@ class UITrait { public var symZ = false; public var showCompass = true; public var fillTypeHandle = new Handle(); - public var resHandle = new Handle({position: 4}); // 2048 - public var bitsHandle = new Handle({position: 0}); // 8bit + public var resHandle = new Handle({position: Res2048}); + public var bitsHandle = new Handle(); #if arm_creator - public var projectType = 2; // cube, sphere, tessellated plane + public var projectType = ModelTessellatedPlane; #else - public var projectType = 0; + public var projectType = ModelCube; #end public var projectObjects:Array; @@ -232,8 +232,8 @@ class UITrait { public var brushLocked = false; var brushCanLock = false; var brushCanUnlock = false; - public var cameraType = 0; - public var camHandle = new Handle({position: 0}); + public var cameraType = CameraPerspective; + public var camHandle = new Handle(); public var fovHandle:Handle = null; public var undoHandle:Handle = null; public var hssgi:Handle = null; @@ -258,11 +258,11 @@ class UITrait { var lastCombo:Handle = null; var lastTooltip:Image = null; - public var cameraControls = 0; - public var htab = Id.handle({position: 0}); - public var htab1 = Id.handle({position: 0}); - public var htab2 = Id.handle({position: 0}); - public var worktab = Id.handle({position: 0}); + public var cameraControls = ControlsOrbit; + public var htab = Id.handle(); + public var htab1 = Id.handle(); + public var htab2 = Id.handle(); + public var worktab = Id.handle(); public var toolNames = ["Brush", "Eraser", "Fill", "Decal", "Text", "Clone", "Blur", "Particle", "Bake", "ColorID", "Picker"]; public function new() { @@ -544,7 +544,7 @@ class UITrait { else if (Operator.shortcut(Config.keymap.view_bottom)) ViewportUtil.setView(0, 0, -1, Math.PI, 0, Math.PI); else if (Operator.shortcut(Config.keymap.view_top)) ViewportUtil.setView(0, 0, 1, 0, 0, 0); else if (Operator.shortcut(Config.keymap.view_camera_type)) { - cameraType = cameraType == 0 ? 1 : 0; + cameraType = cameraType == CameraPerspective ? CameraOrthographic : CameraPerspective; camHandle.position = cameraType; ViewportUtil.updateCameraType(cameraType); statusHandle.redraws = 2; @@ -571,7 +571,7 @@ class UITrait { if (borderHandle != null) { if (borderHandle == UINodes.inst.hwnd || borderHandle == UIView2D.inst.hwnd) { - if (borderStarted == 0) { + if (borderStarted == SideLeft) { UINodes.inst.defaultWindowW -= Std.int(mouse.movementX); if (UINodes.inst.defaultWindowW < 32) UINodes.inst.defaultWindowW = 32; else if (UINodes.inst.defaultWindowW > System.windowWidth() * 0.7) UINodes.inst.defaultWindowW = Std.int(System.windowWidth() * 0.7); @@ -583,7 +583,7 @@ class UITrait { } } else { - if (borderStarted == 0) { + if (borderStarted == SideLeft) { defaultWindowW -= Std.int(mouse.movementX); if (defaultWindowW < 32) defaultWindowW = 32; else if (defaultWindowW > System.windowWidth() - 32) defaultWindowW = System.windowWidth() - 32; @@ -591,13 +591,13 @@ class UITrait { } else { var my = Std.int(mouse.movementY); - if (borderHandle == hwnd1 && borderStarted == 2) { + if (borderHandle == hwnd1 && borderStarted == SideTop) { if (tabh + my > 32 && tabh1 - my > 32) { tabh += my; tabh1 -= my; } } - else if (borderHandle == hwnd2 && borderStarted == 2) { + else if (borderHandle == hwnd2 && borderStarted == SideTop) { if (tabh1 + my > 32 && tabh2 - my > 32) { tabh1 += my; tabh2 -= my; @@ -795,7 +795,7 @@ class UITrait { g.color = 0xffffffff; } - var in2dView = UIView2D.inst.show && UIView2D.inst.type == 0 && + var in2dView = UIView2D.inst.show && UIView2D.inst.type == View2DLayer && mx > UIView2D.inst.wx && mx < UIView2D.inst.wx + UIView2D.inst.ww && my > UIView2D.inst.wy && my < UIView2D.inst.wy + UIView2D.inst.wh; var decal = Context.tool == ToolDecal || Context.tool == ToolText; @@ -827,8 +827,8 @@ class UITrait { // Clear input state as ui receives input events even when not drawn @:privateAccess UINodes.inst.ui.endInput(); - if (UINodes.inst.show && UINodes.inst.canvasType == 0) UINodes.inst.show = false; - else { UINodes.inst.show = true; UINodes.inst.canvasType = 0; } + if (UINodes.inst.show && UINodes.inst.canvasType == CanvasMaterial) UINodes.inst.show = false; + else { UINodes.inst.show = true; UINodes.inst.canvasType = CanvasMaterial; } App.resize(); } @@ -836,8 +836,8 @@ class UITrait { // Clear input state as ui receives input events even when not drawn @:privateAccess UINodes.inst.ui.endInput(); - if (UINodes.inst.show && UINodes.inst.canvasType == 1) UINodes.inst.show = false; - else { UINodes.inst.show = true; UINodes.inst.canvasType = 1; } + if (UINodes.inst.show && UINodes.inst.canvasType == CanvasBrush) UINodes.inst.show = false; + else { UINodes.inst.show = true; UINodes.inst.canvasType = CanvasBrush; } App.resize(); } @@ -910,11 +910,11 @@ class UITrait { var BUTTON_COL = ui.t.BUTTON_COL; ui.t.BUTTON_COL = ui.t.SEPARATOR_COL; - menuButton("File", 0); - menuButton("Edit", 1); - menuButton("Viewport", 2); - menuButton("Camera", 3); - menuButton("Help", 4); + menuButton("File", MenuFile); + menuButton("Edit", MenuEdit); + menuButton("Viewport", MenuViewport); + menuButton("Camera", MenuCamera); + menuButton("Help", MenuHelp); ui._w = _w; ui.t.ELEMENT_OFFSET = ELEMENT_OFFSET; @@ -992,15 +992,15 @@ class UITrait { bakes.push("Thickness"); #end bakeType = ui.combo(bakeHandle, bakes, "Bake"); - if (bakeType == 3 || bakeType == 6 || bakeType == 11) { + if (bakeType == BakeNormalObject || bakeType == BakePosition || bakeType == BakeBentNormal) { var bakeUpAxisHandle = Id.handle({position: bakeUpAxis}); bakeUpAxis = ui.combo(bakeUpAxisHandle, ["Z", "Y"], "Up Axis"); } - if (bakeType == 0 || bakeType == 1) { // ao, curvature + if (bakeType == BakeAO || bakeType == BakeCurvature) { var bakeAxisHandle = Id.handle({position: bakeAxis}); bakeAxis = ui.combo(bakeAxisHandle, ["XYZ", "X", "Y", "Z", "-X", "-Y", "-Z"], "Axis"); } - if (bakeType == 0) { // ao + if (bakeType == BakeAO) { var strengthHandle = Id.handle({value: bakeAoStrength}); bakeAoStrength = ui.slider(strengthHandle, "Strength", 0.0, 2.0, true); var radiusHandle = Id.handle({value: bakeAoRadius}); @@ -1009,12 +1009,12 @@ class UITrait { bakeAoOffset = ui.slider(offsetHandle, "Offset", 0.0, 2.0, true); } #if kha_direct3d12 - if (bakeType == 0 || bakeType == 10 || bakeType == 11 || bakeType == 12) { // ao, bent, lightmap, thick + if (bakeType == BakeAO || bakeType == BakeLightmap || bakeType == BakeBentNormal || bakeType == BakeThickness) { ui.text("Rays/pix: " + arm.render.RenderPathRaytrace.raysPix); ui.text("Rays/sec: " + arm.render.RenderPathRaytrace.raysSec); } #end - if (bakeType == 1) { // Curvature + if (bakeType == BakeCurvature) { var strengthHandle = Id.handle({value: bakeCurvStrength}); bakeCurvStrength = ui.slider(strengthHandle, "Strength", 0.0, 2.0, true); var radiusHandle = Id.handle({value: bakeCurvRadius}); @@ -1024,7 +1024,7 @@ class UITrait { var smoothHandle = Id.handle({value: bakeCurvSmooth}); bakeCurvSmooth = Std.int(ui.slider(smoothHandle, "Smooth", 0, 5, false, 1)); } - if (bakeType == 2 || bakeType == 4 || bakeType == 5) { // Normal (Tang), Height + if (bakeType == BakeNormal || bakeType == BakeHeight || bakeType == BakeDerivative) { var ar = [for (p in Project.paintObjects) p.name]; var polyHandle = Id.handle({position: bakeHighPoly}); bakeHighPoly = ui.combo(polyHandle, ar, "High Poly"); @@ -1110,7 +1110,7 @@ class UITrait { if (Context.tool == ToolFill) { ui.combo(fillTypeHandle, ["Object", "Face", "Angle"], "Fill Mode"); if (fillTypeHandle.changed) { - if (fillTypeHandle.position == 1) { + if (fillTypeHandle.position == FillFace) { ui.g.end(); // UVUtil.cacheUVMap(); UVUtil.cacheTriangleMap(); @@ -1154,14 +1154,14 @@ class UITrait { if (ui.window(statusHandle, iron.App.x(), System.windowHeight() - headerh, System.windowWidth() - toolbarw - windowW, headerh)) { ui._y += 2; - var modeHandle = Id.handle({position: 0}); + var modeHandle = Id.handle(); var modes = ["Render", "Base Color", "Normal", "Occlusion", "Roughness", "Metallic", "TexCoord", "Normal (Object)", "Material ID", "Object ID", "Mask"]; #if kha_direct3d12 modes.push("Path-Trace"); #end UITrait.inst.viewportMode = ui.combo(modeHandle, modes, "Mode"); if (modeHandle.changed) { - var deferred = UITrait.inst.viewportMode == 0 || UITrait.inst.viewportMode == 11; + var deferred = UITrait.inst.viewportMode == ViewRender || UITrait.inst.viewportMode == ViewPathTrace; if (deferred) { RenderPath.active.commands = RenderPathDeferred.commands; } @@ -1250,14 +1250,14 @@ class UITrait { function onBorderHover(handle:Handle, side:Int) { if (!App.uienabled) return; if (handle != hwnd && handle != hwnd1 && handle != hwnd2 && handle != UINodes.inst.hwnd && handle != UIView2D.inst.hwnd) return; // Scalable handles - if (handle == UINodes.inst.hwnd && side != 0 && side != 2) return; // Left/top border of node canvas - if (handle == UINodes.inst.hwnd && side == 2 && !UIView2D.inst.show) return; // Left/top border of node canvas - if (handle == UIView2D.inst.hwnd && side != 0) return; // Left border of 2d view - if (handle == hwnd && side == 2) return; // Window top - if (handle == hwnd2 && side == 3) return; // Window bottom - if (side == 1) return; // UI is snapped to the right side + if (handle == UINodes.inst.hwnd && side != SideLeft && side != SideTop) return; + if (handle == UINodes.inst.hwnd && side == SideTop && !UIView2D.inst.show) return; + if (handle == UIView2D.inst.hwnd && side != SideLeft) return; + if (handle == hwnd && side == SideTop) return; + if (handle == hwnd2 && side == SideBottom) return; + if (side == SideRight) return; // UI is snapped to the right side - side == 0 || side == 1 ? + side == SideLeft || side == SideRight ? Krom.setMouseCursor(6) : // Horizontal Krom.setMouseCursor(5); // Vertical diff --git a/Sources/arm/ui/UIView2D.hx b/Sources/arm/ui/UIView2D.hx index cdd84275..328bd348 100644 --- a/Sources/arm/ui/UIView2D.hx +++ b/Sources/arm/ui/UIView2D.hx @@ -20,7 +20,7 @@ class UIView2D { public static var inst:UIView2D; public var show = false; - public var type = 0; // Layer, texture + public var type = View2DLayer; public var wx:Int; public var wy:Int; public var ww:Int; @@ -31,7 +31,7 @@ class UIView2D { public var panY = 0.0; public var panScale = 1.0; var pipe:PipelineState; - var texType = 0; + var texType = TexBase; var uvmapShow = false; public function new() { @@ -98,11 +98,11 @@ class UIView2D { var l = Context.layer; var tex:Image = null; - if (type == 0) { // Layer - tex = texType == 0 ? l.texpaint : texType == 1 ? l.texpaint_nor : l.texpaint_pack; + if (type == View2DLayer) { + tex = texType == TexBase ? l.texpaint : texType == TexNormal ? l.texpaint_nor : l.texpaint_pack; if (Context.layerIsMask) tex = l.texpaint_mask; } - else { // Texture + else { // View2DAsset tex = UITrait.inst.getImage(Context.texture); } @@ -120,7 +120,7 @@ class UIView2D { ui.g.pipeline = null; // UV map - if (type == 0 && uvmapShow) { + if (type == View2DLayer && uvmapShow) { ui.g.drawScaledImage(UVUtil.uvmap, tx, ty, tw, th); } @@ -138,7 +138,7 @@ class UIView2D { ui._w = Std.int(ui.ELEMENT_W() * 1.4); var h = Id.handle(); - if (type == 0) { + if (type == View2DLayer) { h.text = l.name; l.name = ui.textInput(h, "", Right); } @@ -160,7 +160,7 @@ class UIView2D { ui.fontSize = FONT_SIZE; // Controls - if (type == 0) { + if (type == View2DLayer) { var ew = Std.int(ui.ELEMENT_W()); ui.g.color = ui.t.WINDOW_BG_COL; ui.g.fillRect(0, 0, ww, ui.ELEMENT_H() + ui.ELEMENT_OFFSET()); @@ -209,7 +209,7 @@ class UIView2D { if (panScale > 3.0) panScale = 3.0; } - if (type == 0 && + if (type == View2DLayer && (Operator.shortcut(Config.keymap.action_paint) || Operator.shortcut(Config.keymap.brush_ruler + "+" + Config.keymap.action_paint))) { UITrait.inst.paint2d = true; diff --git a/Sources/arm/util/RenderUtil.hx b/Sources/arm/util/RenderUtil.hx index ee49b222..21d7bdda 100644 --- a/Sources/arm/util/RenderUtil.hx +++ b/Sources/arm/util/RenderUtil.hx @@ -42,7 +42,7 @@ class RenderUtil { Scene.active.camera.transform.setMatrix(m); var savedFov = Scene.active.camera.data.raw.fov; Scene.active.camera.data.raw.fov = 0.92; - ViewportUtil.updateCameraType(0); + ViewportUtil.updateCameraType(CameraPerspective); var light = Scene.active.lights[0]; var savedLight = light.data.raw.strength; var probe = Scene.active.world.probe; @@ -111,7 +111,7 @@ class RenderUtil { Scene.active.camera.transform.setMatrix(m); var savedFov = Scene.active.camera.data.raw.fov; Scene.active.camera.data.raw.fov = 0.92; - ViewportUtil.updateCameraType(0); + ViewportUtil.updateCameraType(CameraPerspective); var light = Scene.active.lights[0]; light.visible = false; Scene.active.world.envmap = UITrait.inst.previewEnvmap; diff --git a/Sources/arm/util/ViewportUtil.hx b/Sources/arm/util/ViewportUtil.hx index 011f5dfa..df78d2e8 100644 --- a/Sources/arm/util/ViewportUtil.hx +++ b/Sources/arm/util/ViewportUtil.hx @@ -4,6 +4,7 @@ import kha.arrays.Float32Array; import iron.Scene; import iron.math.Vec4; import arm.ui.UITrait; +import arm.Tool; class ViewportUtil { @@ -63,7 +64,7 @@ class ViewportUtil { public static function updateCameraType(cameraType:Int) { var cam = Scene.active.cameras[0]; var light = Scene.active.lights[0]; - if (cameraType == 0) { + if (cameraType == CameraPerspective) { cam.data.raw.ortho = null; light.visible = true; }