avancé arkit avec création et ajout des modèles 3D (sans pouvoir test) 🍻

ARKit
Pierre FERREIRA 10 months ago
parent 9cf08bf3b6
commit f0800dc01b

@ -17,6 +17,7 @@
7B6A02982C18930400877E3F /* SwiftARKitUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6A02972C18930400877E3F /* SwiftARKitUITestsLaunchTests.swift */; };
7B6A02A82C18966400877E3F /* MySwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6A02A72C18966400877E3F /* MySwiftUIView.swift */; };
7B6A02AC2C18A1B000877E3F /* MyARViewRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B6A02AB2C18A1B000877E3F /* MyARViewRepresentable.swift */; };
7BB48C802C256C370090AA60 /* objects in Resources */ = {isa = PBXBuildFile; fileRef = 7BB48C7F2C256C370090AA60 /* objects */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -51,6 +52,7 @@
7B6A02A72C18966400877E3F /* MySwiftUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MySwiftUIView.swift; sourceTree = "<group>"; };
7B6A02A92C189ED700877E3F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
7B6A02AB2C18A1B000877E3F /* MyARViewRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyARViewRepresentable.swift; sourceTree = "<group>"; };
7BB48C7F2C256C370090AA60 /* objects */ = {isa = PBXFileReference; lastKnownFileType = folder; name = objects; path = ../../../SwiftUI_ARKit_2024/objects; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -101,6 +103,7 @@
7B6A02772C18930200877E3F /* SwiftARKit */ = {
isa = PBXGroup;
children = (
7BB48C7F2C256C370090AA60 /* objects */,
7B6A02AA2C18A19C00877E3F /* Struct */,
7B6A02A92C189ED700877E3F /* Info.plist */,
7B6A02A62C18964F00877E3F /* View */,
@ -258,6 +261,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7BB48C802C256C370090AA60 /* objects in Resources */,
7B6A02822C18930400877E3F /* Preview Assets.xcassets in Resources */,
7B6A027F2C18930400877E3F /* Assets.xcassets in Resources */,
);

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "board.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

@ -11,8 +11,7 @@ import RealityKit
struct ContentView : View {
var body: some View {
//ARViewContainer().edgesIgnoringSafeArea(.all)
MyARViewRepresentable()
.ignoresSafeArea()
MyARViewRepresentable().edgesIgnoringSafeArea(.all)
}
}

@ -12,8 +12,20 @@ import RealityKit
struct MyARViewRepresentable : UIViewRepresentable{
public func makeUIView(context: Context) -> MyARView {
MyARView()
// let arView = ARView(frame: .zero)
// let mesh = MeshResource.generateBox(width: 150, height: 500, depth: 50)
// let material = SimpleMaterial(color: .red, isMetallic: true)
// let model = ModelEntity(mesh: mesh, materials: [material]) //, materials: material
// model.transform.translation.y = 0.05
//
// let anchor = AnchorEntity(.plane(.horizontal, classification: .table, minimumBounds: .zero))
//
// arView.scene.anchors.append(anchor)
// return arView
return MyARView()
}
public func updateUIView(_ uiView: UIViewType, context: Context) { }
}

@ -21,14 +21,55 @@ class MyARView : ARView{
convenience init() {
self.init(frame: UIScreen.main.bounds)
addBoardToTheFloor()
}
///Repère où attacher le plan
func applyRunConfiguration(){
//ARWorldTrackingConfiguration.self
let conf = ARWorldTrackingConfiguration()
//conf.planeDetection = .horizontal
session.run(conf)
}
func defineAnchors() {
let anchor = AnchorEntity(world: .zero)
scene.addAnchor(anchor)
}
func addBoardToTheFloor() {
let configuration = ARWorldTrackingConfiguration()
session.run(configuration)
let anchor = AnchorEntity(.plane(.horizontal, classification: .any, minimumBounds: SIMD2<Float>(0.2, 0.2)))
scene.addAnchor(anchor)
let board = try? Entity.load(named: "board")
if let board {
anchor.addChild(board)
}
}
func CreateAnchor(){
//let anchor : AnchorEntity = AnchorEntity(world: ARWorldTrackingConfiguration())
func addMeepleToBoard(){
let configuration = ARWorldTrackingConfiguration()
session.run(configuration)
}
// func createAnchor(){
// let anchor : AnchorEntity = AnchorEntity(world: .zero)
// self.scene.addAnchor(anchor)
//
// let mesh = MeshResource.generateBox(size: 10)
// let material = SimpleMaterial(color: .red, isMetallic: true)
// let model = ModelEntity(mesh: mesh, materials: [material])
// model.transform.translation.y = 0.05
//
// anchor.addChild(model)
//
//// let tv = try? Entity.load(named: "Data")
//// anchor.addChild(tv!)
//
// }
}

Loading…
Cancel
Save