replate-camera 0.1.44 → 0.1.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -207,7 +207,7 @@ class ReplateCameraView: UIView, ARSessionDelegate {
|
|
|
207
207
|
let extent = planeAnchor.extent
|
|
208
208
|
|
|
209
209
|
var dotPositions: [SIMD3<Float>] = []
|
|
210
|
-
let dotSpacing: Float = 0.
|
|
210
|
+
let dotSpacing: Float = 0.05 // Adjust the spacing of dots (smaller value for more dots)
|
|
211
211
|
|
|
212
212
|
for x in stride(from: -extent.x / 2, through: extent.x / 2, by: dotSpacing) {
|
|
213
213
|
for z in stride(from: -extent.z / 2, through: extent.z / 2, by: dotSpacing) {
|
|
@@ -219,19 +219,31 @@ class ReplateCameraView: UIView, ARSessionDelegate {
|
|
|
219
219
|
// Add the dots to the ARView
|
|
220
220
|
for position in dotPositions {
|
|
221
221
|
let dotAnchor = AnchorEntity(world: planeAnchor.transform)
|
|
222
|
-
let dot =
|
|
222
|
+
let dot = createDot(at: position) // Assuming you're using the circle function
|
|
223
223
|
dot.position.y = 0 // Ensure the dot position matches the plane's height
|
|
224
224
|
dotAnchor.addChild(dot)
|
|
225
225
|
ReplateCameraView.arView.scene.addAnchor(dotAnchor)
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
+
|
|
228
229
|
|
|
229
|
-
func
|
|
230
|
-
|
|
231
|
-
let
|
|
232
|
-
let
|
|
233
|
-
|
|
234
|
-
|
|
230
|
+
func createDot(at position: SIMD3<Float>) -> ModelEntity {
|
|
231
|
+
// Define the dimensions of the box
|
|
232
|
+
let width: Float = 0.005 // 1 cm width
|
|
233
|
+
let height: Float = 0.0001 // Very small height to make it almost flat
|
|
234
|
+
let depth: Float = width // 1 cm depth
|
|
235
|
+
let cornerRadius: Float = width/2.0 // Half of the width to make it look like a circle
|
|
236
|
+
|
|
237
|
+
// Generate a box with rounded corners
|
|
238
|
+
let cylinderMesh = MeshResource.generateBox(size: [width, height, depth], cornerRadius: cornerRadius)
|
|
239
|
+
|
|
240
|
+
// Create the material
|
|
241
|
+
let material = SimpleMaterial(color: .white, roughness: 1, isMetallic: false)
|
|
242
|
+
|
|
243
|
+
// Create the entity
|
|
244
|
+
let circleEntity = ModelEntity(mesh: cylinderMesh, materials: [material])
|
|
245
|
+
circleEntity.position = position
|
|
246
|
+
return circleEntity
|
|
235
247
|
}
|
|
236
248
|
|
|
237
249
|
|
|
@@ -473,6 +485,8 @@ class ReplateCameraView: UIView, ARSessionDelegate {
|
|
|
473
485
|
if (session.identifier == ReplateCameraView.sessionId) {
|
|
474
486
|
ReplateCameraView.arView.session.pause()
|
|
475
487
|
ReplateCameraView.isPaused = true
|
|
488
|
+
ReplateCameraView.arView.removeFromSuperview()
|
|
489
|
+
ReplateCameraView.arView = nil
|
|
476
490
|
}
|
|
477
491
|
}
|
|
478
492
|
|
|
@@ -595,19 +609,19 @@ class ReplateCameraController: NSObject {
|
|
|
595
609
|
let distanceBetweenCircles = ReplateCameraView.distanceBetweenCircles
|
|
596
610
|
let point1Y = anchorPosition.y + spheresHeight
|
|
597
611
|
let point2Y = anchorPosition.y + distanceBetweenCircles + spheresHeight
|
|
598
|
-
let twoThirdsDistance =
|
|
599
|
-
|
|
612
|
+
let twoThirdsDistance = spheresHeight + (distanceBetweenCircles/5) * 4
|
|
600
613
|
var deviceTargetInFocus = -1
|
|
601
614
|
let angleThreshold: Float = 0.6
|
|
602
|
-
|
|
615
|
+
var relativeCameraTransform: simd_float4x4
|
|
603
616
|
if let cameraTransform = ReplateCameraView.arView.session.currentFrame?.camera.transform {
|
|
617
|
+
relativeCameraTransform = ReplateCameraController.getTransformRelativeToAnchor(anchor: anchorNode, cameraTransform: cameraTransform)
|
|
604
618
|
let cameraPosition = SIMD3<Float>(cameraTransform.columns.3.x, cameraTransform.columns.3.y, cameraTransform.columns.3.z)
|
|
605
619
|
let deviceDirection = normalize(SIMD3<Float>(-cameraTransform.columns.2.x, -cameraTransform.columns.2.y, -cameraTransform.columns.2.z))
|
|
606
620
|
let directionToAnchor = normalize(anchorPosition - cameraPosition)
|
|
607
621
|
let angleToAnchor = acos(dot(deviceDirection, directionToAnchor))
|
|
608
622
|
|
|
609
623
|
if angleToAnchor < angleThreshold {
|
|
610
|
-
let cameraHeight =
|
|
624
|
+
let cameraHeight = relativeCameraTransform.columns.3.y
|
|
611
625
|
if cameraHeight < twoThirdsDistance {
|
|
612
626
|
deviceTargetInFocus = 0
|
|
613
627
|
print("Is pointing at first point")
|
|
@@ -625,7 +639,7 @@ class ReplateCameraController: NSObject {
|
|
|
625
639
|
}
|
|
626
640
|
|
|
627
641
|
if deviceTargetInFocus != -1 {
|
|
628
|
-
updateSpheres(deviceTargetInFocus: deviceTargetInFocus) { result in
|
|
642
|
+
updateSpheres(deviceTargetInFocus: deviceTargetInFocus, cameraTransform: relativeCameraTransform) { result in
|
|
629
643
|
if !unlimited && !result {
|
|
630
644
|
safeRejecter("[ReplateCameraController]", "Too many images and the last one's not from a new angle", NSError(domain: "ReplateCameraController", code: 005, userInfo: nil))
|
|
631
645
|
return
|
|
@@ -710,7 +724,7 @@ class ReplateCameraController: NSObject {
|
|
|
710
724
|
}
|
|
711
725
|
}
|
|
712
726
|
|
|
713
|
-
func updateSpheres(deviceTargetInFocus: Int, completion: @escaping (Bool) -> Void) {
|
|
727
|
+
func updateSpheres(deviceTargetInFocus: Int, cameraTransform: simd_float4x4, completion: @escaping (Bool) -> Void) {
|
|
714
728
|
// Ensure the function handles a single completion call
|
|
715
729
|
var completionCalled = false
|
|
716
730
|
func callCompletion(_ result: Bool) {
|
|
@@ -742,9 +756,7 @@ class ReplateCameraController: NSObject {
|
|
|
742
756
|
callCompletion(false)
|
|
743
757
|
return
|
|
744
758
|
}
|
|
745
|
-
|
|
746
|
-
let cameraTransform = frame.camera.transform
|
|
747
|
-
|
|
759
|
+
|
|
748
760
|
// Calculate the angle between the camera and the anchor
|
|
749
761
|
let angleDegrees = ReplateCameraController.angleBetweenAnchorXAndCamera(anchor: anchorNode,
|
|
750
762
|
cameraTransform: cameraTransform)
|
|
@@ -818,13 +830,18 @@ class ReplateCameraController: NSObject {
|
|
|
818
830
|
callCompletion(newAngle)
|
|
819
831
|
}
|
|
820
832
|
|
|
821
|
-
static func
|
|
822
|
-
// Extract the position of the anchor and the camera from their transforms, ignoring the y-axis
|
|
823
|
-
let anchorPositionXZ = simd_float2(anchor.transform.translation.x, anchor.transform.translation.z)
|
|
833
|
+
static func getTransformRelativeToAnchor(anchor: AnchorEntity, cameraTransform: simd_float4x4) -> simd_float4x4{
|
|
824
834
|
// Transform the camera position to the anchor's local space
|
|
825
835
|
let anchorTransform = anchor.transformMatrix(relativeTo: nil)
|
|
826
836
|
let relativePosition = anchorTransform.inverse * cameraTransform
|
|
827
|
-
|
|
837
|
+
return relativePosition
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
static func angleBetweenAnchorXAndCamera(anchor: AnchorEntity, cameraTransform: simd_float4x4) -> Float {
|
|
841
|
+
// Extract the position of the anchor and the camera from their transforms, ignoring the y-axis
|
|
842
|
+
let anchorTransform = anchor.transformMatrix(relativeTo: nil)
|
|
843
|
+
let anchorPositionXZ = simd_float2(anchor.transform.translation.x, anchor.transform.translation.z)
|
|
844
|
+
let relativeCameraPositionXZ = simd_float2(cameraTransform.columns.3.x, cameraTransform.columns.3.z)
|
|
828
845
|
|
|
829
846
|
// Calculate the direction vector from the anchor to the camera in the XZ plane
|
|
830
847
|
let directionXZ = relativeCameraPositionXZ - anchorPositionXZ
|