-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
428 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
Sources/GaussianSplatSupport/GaussianSplatConfiguration.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Metal | ||
import PanoramaSupport | ||
#if !targetEnvironment(simulator) | ||
import MetalFX | ||
#endif | ||
import MetalKit | ||
import os | ||
import simd | ||
import SwiftUI | ||
|
||
public struct GaussianSplatConfiguration { | ||
public enum SortMethod { | ||
case gpuBitonic | ||
case cpuRadix | ||
} | ||
|
||
public var debugMode: Bool | ||
public var metalFXRate: Float | ||
public var discardRate: Float | ||
public var clearColor: MTLClearColor | ||
public var skyboxTexture: MTLTexture? | ||
public var verticalAngleOfView: Angle | ||
public var sortMethod: SortMethod | ||
public var renderSkybox: Bool = true | ||
public var renderSplats: Bool = true | ||
|
||
public init(debugMode: Bool = false, metalFXRate: Float = 2, discardRate: Float = 0.0, clearColor: MTLClearColor = .init(red: 0, green: 0, blue: 0, alpha: 1), skyboxTexture: MTLTexture? = nil, verticalAngleOfView: Angle = .degrees(90), sortMethod: SortMethod = .cpuRadix) { | ||
self.debugMode = debugMode | ||
self.metalFXRate = metalFXRate | ||
self.discardRate = discardRate | ||
self.clearColor = clearColor | ||
self.skyboxTexture = skyboxTexture | ||
self.verticalAngleOfView = verticalAngleOfView | ||
self.sortMethod = sortMethod | ||
} | ||
|
||
@MainActor | ||
public static func defaultSkyboxTexture(device: MTLDevice) -> MTLTexture? { | ||
let gradient = LinearGradient( | ||
stops: [ | ||
.init(color: .white, location: 0), | ||
.init(color: .white, location: 0.4), | ||
.init(color: Color(red: 135 / 255, green: 206 / 255, blue: 235 / 255), location: 0.5), | ||
.init(color: Color(red: 135 / 255, green: 206 / 255, blue: 235 / 255), location: 1) | ||
], | ||
startPoint: .init(x: 0, y: 0), | ||
endPoint: .init(x: 0, y: 1) | ||
) | ||
|
||
guard var cgImage = ImageRenderer(content: Rectangle().fill(gradient).frame(width: 1024, height: 1024)).cgImage else { | ||
fatalError("Could not render image.") | ||
} | ||
let bitmapInfo: CGBitmapInfo | ||
if cgImage.byteOrderInfo == .order32Little { | ||
bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedFirst.rawValue | CGBitmapInfo.byteOrder32Big.rawValue) | ||
} else { | ||
bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedFirst.rawValue | CGBitmapInfo.byteOrder32Little.rawValue) | ||
} | ||
cgImage = cgImage.convert(bitmapInfo: bitmapInfo)! | ||
|
||
let textureLoader = MTKTextureLoader(device: device) | ||
let texture = try! textureLoader.newTexture(cgImage: cgImage, options: nil) | ||
texture.label = "Skybox Gradient" | ||
return texture | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Foundation | ||
import MetalKit | ||
import Observation | ||
import PanoramaSupport | ||
import simd | ||
import SwiftUI | ||
|
||
// swiftlint:disable force_unwrapping | ||
|
||
@available(iOS 17, macOS 14, visionOS 1, *) | ||
public struct UFOView: View { | ||
@Environment(\.metalDevice) | ||
private var device | ||
|
||
@Environment(GaussianSplatViewModel<SplatC>.self) | ||
private var viewModel | ||
|
||
@State | ||
private var bounds: ConeBounds | ||
|
||
public init(bounds: ConeBounds) { | ||
self.bounds = bounds | ||
} | ||
|
||
public var body: some View { | ||
@Bindable | ||
var viewModel = viewModel | ||
|
||
return GaussianSplatRenderView<SplatC>() | ||
#if os(iOS) | ||
.ignoresSafeArea() | ||
#endif | ||
.modifier(CameraConeController(cameraCone: bounds, transform: $viewModel.scene.unsafeCurrentCameraNode.transform)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.