|
|
@ -12,7 +12,10 @@ import DouShouQiModel
|
|
|
|
|
|
|
|
|
|
|
|
class ARKitView: ARView {
|
|
|
|
class ARKitView: ARView {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ObservedObject var playingGameVM: PlayingGameVM
|
|
|
|
|
|
|
|
|
|
|
|
required init(frame frameRect: CGRect) {
|
|
|
|
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)
|
|
|
|
super.init(frame: frameRect)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -20,14 +23,10 @@ class ARKitView: ARView {
|
|
|
|
fatalError("init(coder:) not implemented")
|
|
|
|
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)
|
|
|
|
self.init(frame: UIScreen.main.bounds)
|
|
|
|
do {
|
|
|
|
self.playingGameVM = playingGameVM
|
|
|
|
let game = try Game(withRules: ClassicRules(), andPlayer1: HumanPlayer(withName: "Player 1", andId: .player1)!, andPlayer2: HumanPlayer(withName: "Player 2", andId: .player2)!)
|
|
|
|
initBoard(withBoard: playingGameVM.game.board, andImage: imageBoard)
|
|
|
|
initBoard(withBoard: game.board, andImage: imageBoard)
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
print("error")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func applyConfiguration() {
|
|
|
|
func applyConfiguration() {
|
|
|
@ -40,28 +39,6 @@ class ARKitView: ARView {
|
|
|
|
let arBoard = ARBoard(image: image)
|
|
|
|
let arBoard = ARBoard(image: image)
|
|
|
|
anchor.addChild(arBoard)
|
|
|
|
anchor.addChild(arBoard)
|
|
|
|
self.scene.addAnchor(anchor)
|
|
|
|
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) {}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|