From 5d5727096d9f2e995cbe6236f7a9d471c21e5169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?furby=E2=84=A2?= Date: Thu, 9 May 2024 05:27:32 -0600 Subject: [PATCH] Core UI grid development, layout begins. --- Kraken.usda | 28 +++- Sources/Kraken/KR/KR.Kraken.swift | 124 +++++++++++++----- .../Kraken/UI/Editors/KUI.CodeEditor.swift | 75 ++++++----- .../Kraken/UI/Editors/KUI.CodeLanguage.swift | 62 +++++---- Sources/Kraken/UI/Editors/KUI.SceneView.swift | 62 +++++++++ .../Kraken/UI/Windows/KUI.MicaWindow.swift | 62 +++++---- 6 files changed, 284 insertions(+), 129 deletions(-) create mode 100644 Sources/Kraken/UI/Editors/KUI.SceneView.swift diff --git a/Kraken.usda b/Kraken.usda index ae73e7a7..f1352701 100644 --- a/Kraken.usda +++ b/Kraken.usda @@ -9,9 +9,29 @@ def Xform "Geometry" double3 xformOp:translate = (0, 5, 0) uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:scale"] - def Capsule "Sphere" + def Sphere "Sphere" ( + prepend apiSchemas = ["MaterialBindingAPI"] + ) { - double3 xformOp:translate = (0, 0, -3) + rel material:binding = + double3 xformOp:translate = (0, 0, -5) uniform token[] xformOpOrder = ["xformOp:translate"] - } -} \ No newline at end of file + } +} + +def "Materials" +{ + def Material "RedMaterial" + { + token outputs:surface.connect = + + def Shader "PBRShader" + { + uniform token info:id = "UsdPreviewSurface" + color3f inputs:diffuseColor = (0.992, 0.207, 0.061) + float inputs:metallic = 0 + float inputs:roughness = 0.4 + token outputs:surface + } + } +} diff --git a/Sources/Kraken/KR/KR.Kraken.swift b/Sources/Kraken/KR/KR.Kraken.swift index 52d0d872..f1f3d1bb 100644 --- a/Sources/Kraken/KR/KR.Kraken.swift +++ b/Sources/Kraken/KR/KR.Kraken.swift @@ -1,28 +1,32 @@ -/* -------------------------------------------------------------- - * :: : K R A K E N : :: - * -------------------------------------------------------------- - * @wabistudios :: metaverse :: kraken +/* ---------------------------------------------------------------- + * :: : M E T A V E R S E : :: + * ---------------------------------------------------------------- + * This software is Licensed under the terms of the Apache License, + * version 2.0 (the "Apache License") with the following additional + * modification; you may not use this file except within compliance + * of the Apache License and the following modification made to it. + * Section 6. Trademarks. is deleted and replaced with: * - * This program is free software; you can redistribute it, and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. + * Trademarks. This License does not grant permission to use any of + * its trade names, trademarks, service marks, or the product names + * of this Licensor or its affiliates, except as required to comply + * with Section 4(c.) of this License, and to reproduce the content + * of the NOTICE file. * - * This program is distributed in the hope that it will be useful - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out - * the GNU General Public License for more details. + * This software is distributed in the hope that it will be useful, + * but WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND without even an + * implied warranty of MERCHANTABILITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the Apache License for more details. * - * You should have received a copy for this software license, the - * GNU General Public License along with this program; or, if not - * write to the Free Software Foundation, Inc., to the address of + * You should have received a copy for this software license of the + * Apache License along with this program; or, if not, please write + * to the Free Software Foundation Inc., with the following address * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (C) 2023 Wabi Foundation. - * All Rights Reserved. - * -------------------------------------------------------------- + * Copyright (C) 2024 Wabi Foundation. All Rights Reserved. + * ---------------------------------------------------------------- * . x x x . o o o . x x x . : : : . o x o . : : : . - * -------------------------------------------------------------- */ + * ---------------------------------------------------------------- */ import CxxStdlib import Foundation @@ -89,26 +93,78 @@ public struct Kraken: SwiftUI.App } else { - HStack + VStack(spacing: 0) { - Kraken.UI.CodeEditor( - document: $usdFile, - stage: $stage, - fileURL: usdFile.fileURL - ) + Divider() - VStack + HStack(spacing: 0) { - SceneView( - scene: try? SCNScene(url: usdFile.fileURL ?? Kraken.IO.Stage.manager.getTmpURL()), - options: [ - .allowsCameraControl, - .autoenablesDefaultLighting, - ], - antialiasingMode: .multisampling4X + Button + {} label: + { + Image("wabi.hexagon.fill", bundle: .module) + } + .buttonStyle(.borderless) + .font(.system(size: 12, weight: .medium)) + .padding(.init(top: 4, leading: 12, bottom: 4, trailing: 12)) + .foregroundStyle(.white.opacity(0.7)) + .background(RoundedRectangle(cornerRadius: 4, style: .continuous).fill(.clear)) + + Button("File") + {} + .buttonStyle(.borderless) + .font(.system(size: 12, weight: .medium)) + .padding(.init(top: 4, leading: 12, bottom: 4, trailing: 12)) + .foregroundStyle(.white.opacity(0.7)) + .background(RoundedRectangle(cornerRadius: 4, style: .continuous).fill(.clear)) + + Button("Edit") + {} + .buttonStyle(.borderless) + .font(.system(size: 12, weight: .medium)) + .padding(.init(top: 4, leading: 12, bottom: 4, trailing: 12)) + .foregroundStyle(.white.opacity(0.7)) + .background(RoundedRectangle(cornerRadius: 4, style: .continuous).fill(.clear)) + + Button("Render") + {} + .buttonStyle(.borderless) + .font(.system(size: 12, weight: .medium)) + .padding(.init(top: 4, leading: 12, bottom: 4, trailing: 12)) + .foregroundStyle(.white.opacity(0.7)) + .background(RoundedRectangle(cornerRadius: 4, style: .continuous).fill(.clear)) + + Button("Window") + {} + .buttonStyle(.borderless) + .font(.system(size: 12, weight: .medium)) + .padding(.init(top: 4, leading: 12, bottom: 4, trailing: 12)) + .foregroundStyle(.white.opacity(0.7)) + .background(RoundedRectangle(cornerRadius: 4, style: .continuous).fill(.clear)) + + Spacer() + } + .frame(height: 17) + .padding(4) + .zIndex(2) + .background(.black.opacity(0.3)) + + Divider() + + HStack(spacing: 0) + { + Kraken.UI.CodeEditor( + document: $usdFile, + stage: $stage, + fileURL: usdFile.fileURL + ) + + Divider() + + Kraken.UI.SceneView( + fileURL: usdFile.fileURL ?? Kraken.IO.Stage.manager.getTmpURL() ) } - .frame(maxWidth: .infinity, alignment: .leading) } } } diff --git a/Sources/Kraken/UI/Editors/KUI.CodeEditor.swift b/Sources/Kraken/UI/Editors/KUI.CodeEditor.swift index a0f8ddbb..5d801d95 100644 --- a/Sources/Kraken/UI/Editors/KUI.CodeEditor.swift +++ b/Sources/Kraken/UI/Editors/KUI.CodeEditor.swift @@ -1,28 +1,32 @@ -/* -------------------------------------------------------------- - * :: : K R A K E N : :: - * -------------------------------------------------------------- - * @wabistudios :: metaverse :: kraken +/* ---------------------------------------------------------------- + * :: : M E T A V E R S E : :: + * ---------------------------------------------------------------- + * This software is Licensed under the terms of the Apache License, + * version 2.0 (the "Apache License") with the following additional + * modification; you may not use this file except within compliance + * of the Apache License and the following modification made to it. + * Section 6. Trademarks. is deleted and replaced with: * - * This program is free software; you can redistribute it, and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. + * Trademarks. This License does not grant permission to use any of + * its trade names, trademarks, service marks, or the product names + * of this Licensor or its affiliates, except as required to comply + * with Section 4(c.) of this License, and to reproduce the content + * of the NOTICE file. * - * This program is distributed in the hope that it will be useful - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out - * the GNU General Public License for more details. + * This software is distributed in the hope that it will be useful, + * but WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND without even an + * implied warranty of MERCHANTABILITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the Apache License for more details. * - * You should have received a copy for this software license, the - * GNU General Public License along with this program; or, if not - * write to the Free Software Foundation, Inc., to the address of + * You should have received a copy for this software license of the + * Apache License along with this program; or, if not, please write + * to the Free Software Foundation Inc., with the following address * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (C) 2023 Wabi Foundation. - * All Rights Reserved. - * -------------------------------------------------------------- + * Copyright (C) 2024 Wabi Foundation. All Rights Reserved. + * ---------------------------------------------------------------- * . x x x . o o o . x x x . : : : . o x o . : : : . - * -------------------------------------------------------------- */ + * ---------------------------------------------------------------- */ import CodeLanguages import CosmoEditor @@ -69,23 +73,6 @@ public extension Kraken.UI { VStack(spacing: 0) { - HStack - { - Text("Language") - - LanguagePicker(language: $language) - .frame(maxWidth: 100) - - Toggle("Wrap Lines", isOn: $wrapLines) - Spacer() - Text(getLabel(cursorPositions)) - } - .padding(4) - .zIndex(2) - .background(Color(NSColor.windowBackgroundColor)) - - Divider() - Editor.Code.Cosmo( $document.text, language: language, @@ -107,6 +94,22 @@ public extension Kraken.UI stage: &stage ) } + + Divider() + + HStack + { + LanguagePicker(language: $language) + .frame(maxWidth: 35) + + Spacer() + + Text(getLabel(cursorPositions)) + .font(.system(size: 8, weight: .bold, design: .monospaced)) + } + .padding(4) + .zIndex(2) + .background(.ultraThinMaterial) } .onAppear { diff --git a/Sources/Kraken/UI/Editors/KUI.CodeLanguage.swift b/Sources/Kraken/UI/Editors/KUI.CodeLanguage.swift index 84a61778..0c5b93ef 100644 --- a/Sources/Kraken/UI/Editors/KUI.CodeLanguage.swift +++ b/Sources/Kraken/UI/Editors/KUI.CodeLanguage.swift @@ -1,28 +1,32 @@ -/* -------------------------------------------------------------- - * :: : K R A K E N : :: - * -------------------------------------------------------------- - * @wabistudios :: metaverse :: kraken +/* ---------------------------------------------------------------- + * :: : M E T A V E R S E : :: + * ---------------------------------------------------------------- + * This software is Licensed under the terms of the Apache License, + * version 2.0 (the "Apache License") with the following additional + * modification; you may not use this file except within compliance + * of the Apache License and the following modification made to it. + * Section 6. Trademarks. is deleted and replaced with: * - * This program is free software; you can redistribute it, and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. + * Trademarks. This License does not grant permission to use any of + * its trade names, trademarks, service marks, or the product names + * of this Licensor or its affiliates, except as required to comply + * with Section 4(c.) of this License, and to reproduce the content + * of the NOTICE file. * - * This program is distributed in the hope that it will be useful - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out - * the GNU General Public License for more details. + * This software is distributed in the hope that it will be useful, + * but WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND without even an + * implied warranty of MERCHANTABILITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the Apache License for more details. * - * You should have received a copy for this software license, the - * GNU General Public License along with this program; or, if not - * write to the Free Software Foundation, Inc., to the address of + * You should have received a copy for this software license of the + * Apache License along with this program; or, if not, please write + * to the Free Software Foundation Inc., with the following address * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (C) 2023 Wabi Foundation. - * All Rights Reserved. - * -------------------------------------------------------------- + * Copyright (C) 2024 Wabi Foundation. All Rights Reserved. + * ---------------------------------------------------------------- * . x x x . o o o . x x x . : : : . o x o . : : : . - * -------------------------------------------------------------- */ + * ---------------------------------------------------------------- */ import CodeLanguages import CosmoEditor @@ -36,15 +40,27 @@ public extension Kraken.UI.CodeEditor public var body: some View { - Picker("Language", selection: $language) + Menu { - ForEach([.default] + Editor.Code.Language.allLanguages, id: \.id) - { language in + Picker("Language", selection: $language) + { + ForEach([.default] + Editor.Code.Language.allLanguages, id: \.id) + { language in + Text(language.id.rawValue) + .font(.system(size: 11, weight: .bold, design: .monospaced)) + .tag(language) + } + } + } label: + { + HStack + { Text(language.id.rawValue) - .tag(language) + .font(.system(size: 8, weight: .bold, design: .monospaced)) } } .labelsHidden() + .buttonStyle(.borderless) } } } diff --git a/Sources/Kraken/UI/Editors/KUI.SceneView.swift b/Sources/Kraken/UI/Editors/KUI.SceneView.swift new file mode 100644 index 00000000..0f2b35a7 --- /dev/null +++ b/Sources/Kraken/UI/Editors/KUI.SceneView.swift @@ -0,0 +1,62 @@ +/* ---------------------------------------------------------------- + * :: : M E T A V E R S E : :: + * ---------------------------------------------------------------- + * This software is Licensed under the terms of the Apache License, + * version 2.0 (the "Apache License") with the following additional + * modification; you may not use this file except within compliance + * of the Apache License and the following modification made to it. + * Section 6. Trademarks. is deleted and replaced with: + * + * Trademarks. This License does not grant permission to use any of + * its trade names, trademarks, service marks, or the product names + * of this Licensor or its affiliates, except as required to comply + * with Section 4(c.) of this License, and to reproduce the content + * of the NOTICE file. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND without even an + * implied warranty of MERCHANTABILITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the Apache License for more details. + * + * You should have received a copy for this software license of the + * Apache License along with this program; or, if not, please write + * to the Free Software Foundation Inc., with the following address + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright (C) 2024 Wabi Foundation. All Rights Reserved. + * ---------------------------------------------------------------- + * . x x x . o o o . x x x . : : : . o x o . : : : . + * ---------------------------------------------------------------- */ + +import Foundation +import SceneKit +import SwiftUI + +public extension Kraken.UI +{ + struct SceneView: NSViewRepresentable + { + public typealias NSViewType = SCNView + + public var fileURL: URL + + public init(fileURL: URL) + { + self.fileURL = fileURL + } + + public func updateNSView(_: NSViewType, context _: Context) + {} + + public func makeNSView(context _: Context) -> NSViewType + { + let view = SCNView() + view.backgroundColor = NSColor.clear + view.allowsCameraControl = true + view.autoenablesDefaultLighting = true + + view.scene = try? SCNScene(url: fileURL) + return view + } + } +} diff --git a/Sources/Kraken/UI/Windows/KUI.MicaWindow.swift b/Sources/Kraken/UI/Windows/KUI.MicaWindow.swift index 1e58bf68..0caf7348 100644 --- a/Sources/Kraken/UI/Windows/KUI.MicaWindow.swift +++ b/Sources/Kraken/UI/Windows/KUI.MicaWindow.swift @@ -1,28 +1,32 @@ -/* -------------------------------------------------------------- - * :: : K R A K E N : :: - * -------------------------------------------------------------- - * @wabistudios :: metaverse :: kraken +/* ---------------------------------------------------------------- + * :: : M E T A V E R S E : :: + * ---------------------------------------------------------------- + * This software is Licensed under the terms of the Apache License, + * version 2.0 (the "Apache License") with the following additional + * modification; you may not use this file except within compliance + * of the Apache License and the following modification made to it. + * Section 6. Trademarks. is deleted and replaced with: * - * This program is free software; you can redistribute it, and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. + * Trademarks. This License does not grant permission to use any of + * its trade names, trademarks, service marks, or the product names + * of this Licensor or its affiliates, except as required to comply + * with Section 4(c.) of this License, and to reproduce the content + * of the NOTICE file. * - * This program is distributed in the hope that it will be useful - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Check out - * the GNU General Public License for more details. + * This software is distributed in the hope that it will be useful, + * but WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND without even an + * implied warranty of MERCHANTABILITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the Apache License for more details. * - * You should have received a copy for this software license, the - * GNU General Public License along with this program; or, if not - * write to the Free Software Foundation, Inc., to the address of + * You should have received a copy for this software license of the + * Apache License along with this program; or, if not, please write + * to the Free Software Foundation Inc., with the following address * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (C) 2023 Wabi Foundation. - * All Rights Reserved. - * -------------------------------------------------------------- + * Copyright (C) 2024 Wabi Foundation. All Rights Reserved. + * ---------------------------------------------------------------- * . x x x . o o o . x x x . : : : . o x o . : : : . - * -------------------------------------------------------------- */ + * ---------------------------------------------------------------- */ import SwiftUI @@ -53,20 +57,14 @@ public extension Kraken.UI { WindowGroup(title, id: id) { - #if !os(Linux) - ZStack - { - Color.clear.ignoresSafeArea() + ZStack + { + Color.clear.ignoresSafeArea() - view - } - .background(Kraken.UI.MicaMaterial(material: .sidebar).ignoresSafeArea()) - #else /* os(Linux) */ - HStack - { - view - } - #endif /* !os(Linux) */ + view + } + .background(Kraken.UI.MicaMaterial(material: .sidebar).ignoresSafeArea()) + .frame(minWidth: 800, maxWidth: .infinity, minHeight: 500, maxHeight: .infinity) } #if os(macOS) .windowStyle(.hiddenTitleBar)