🚧 Add: ARViews

master
Nathan VERDIER 10 months ago
parent 30b9bdeeba
commit a951fff464

@ -11,7 +11,7 @@ class ARBoard: Entity {
required init(image: String) {
super.init()
if let boardEntity = try? Entity.load(named: image) {
if let boardEntity = try? Entity.loadModel(named: image) {
self.addChild(boardEntity)
}
}

@ -7,15 +7,17 @@
import SwiftUI
import DouShouQiModel
import ARKit
import RealityKit
struct ARKitUIViewBoard: UIViewRepresentable {
struct ARKitUIViewRepresentable: UIViewRepresentable {
var aRKitViewRepresentable: ARKitViewRepresentable
var aRKitView: ARKitView
func makeUIView(context: Context) -> ARKitViewRepresentable {
return aRKitViewRepresentable
func makeUIView(context: Context) -> ARKitView {
return aRKitView
}
func updateUIView(_ uiView: ARKitViewRepresentable, context: Context) {}
func updateUIView(_ uiView: ARKitView, context: Context) {}
}

@ -12,7 +12,10 @@ import DouShouQiModel
class ARKitView: ARView {
@ObservedObject var playingGameVM: PlayingGameVM
required init(frame frameRect: CGRect) {
self.playingGameVM = PlayingGameVM(withRules: ClassicRules(), andPlayer1: HumanPlayer(withName: "Player 1", andId: .player1)!, andPlayer2: HumanPlayer(withName: "Player 2", andId: .player2)!)!
super.init(frame: frameRect)
}
@ -20,14 +23,10 @@ class ARKitView: ARView {
fatalError("init(coder:) not implemented")
}
convenience init(imageBoard: String = "board", cell_size: Float = 0.1145) {
convenience init(playingGameVM: PlayingGameVM, imageBoard: String = "board", cell_size: Float = 0.1145) {
self.init(frame: UIScreen.main.bounds)
do {
let game = try Game(withRules: ClassicRules(), andPlayer1: HumanPlayer(withName: "Player 1", andId: .player1)!, andPlayer2: HumanPlayer(withName: "Player 2", andId: .player2)!)
initBoard(withBoard: game.board, andImage: imageBoard)
} catch {
print("error")
}
self.playingGameVM = playingGameVM
initBoard(withBoard: playingGameVM.game.board, andImage: imageBoard)
}
func applyConfiguration() {
@ -40,28 +39,6 @@ class ARKitView: ARView {
let arBoard = ARBoard(image: image)
anchor.addChild(arBoard)
self.scene.addAnchor(anchor)
arBoard.setPosition(SIMD3(x: 0, y: 0, z: 0), relativeTo: anchor)
}
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
// Create a cube model
let mesh = MeshResource.generateBox(size: 0.1, cornerRadius: 0.005)
let material = SimpleMaterial(color: .gray, roughness: 0.15, isMetallic: true)
let model = ModelEntity(mesh: mesh, materials: [material])
model.transform.translation.y = 0.05
// Create horizontal plane anchor for the content
let anchor = AnchorEntity(.plane(.horizontal, classification: .any, minimumBounds: SIMD2<Float>(0.2, 0.2)))
anchor.children.append(model)
// Add the horizontal plane anchor to the scene
arView.scene.anchors.append(anchor)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {}
}

Loading…
Cancel
Save