@webspatial/platform-visionos 1.1.0 → 1.2.0
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.
- package/package.json +1 -1
- package/web-spatial/JSBCommand.swift +45 -53
- package/web-spatial/SpatialObject.swift +30 -14
- package/web-spatial/WebMsgCommand.swift +50 -66
- package/web-spatial/manager/Dynamic3DManager.swift +10 -12
- package/web-spatial/manager/FileCoordinator.swift +20 -0
- package/web-spatial/manager/WKWebViewManager.swift +9 -1
- package/web-spatial/manifest.swift +4 -1
- package/web-spatial/model/SpatialScene.swift +7 -13
- package/web-spatial/model/Spatialized2DElement.swift +2 -0
- package/web-spatial/model/SpatializedElement.swift +5 -6
- package/web-spatial/model/dynamic3d/SpatialEntity.swift +72 -69
- package/web-spatial/view/Spatialized2DElementView.swift +1 -1
- package/web-spatial/view/SpatializedDynamic3DView.swift +19 -79
- package/web-spatial/view/SpatializedElementView.swift +42 -46
- package/web-spatial.xcodeproj/project.pbxproj +1 -0
- package/web-spatial.xcodeproj/xcshareddata/xcschemes/web-spatial.xcscheme +2 -2
|
@@ -3,6 +3,10 @@ import SwiftUI
|
|
|
3
3
|
// zIndex() have some bug, so use zOrderBias to simulate zIndex effect
|
|
4
4
|
let zOrderBias = 0.001
|
|
5
5
|
|
|
6
|
+
final class GestureFlags {
|
|
7
|
+
var isDrag = false
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
struct SpatializedElementView<Content: View>: View {
|
|
7
11
|
@Environment(SpatializedElement.self) var spatializedElement: SpatializedElement
|
|
8
12
|
@Environment(SpatialScene.self) var spatialScene: SpatialScene
|
|
@@ -10,6 +14,8 @@ struct SpatializedElementView<Content: View>: View {
|
|
|
10
14
|
var parentScrollOffset: Vec2
|
|
11
15
|
var content: Content
|
|
12
16
|
|
|
17
|
+
@State private var gestureFlags = GestureFlags()
|
|
18
|
+
|
|
13
19
|
init(parentScrollOffset: Vec2, @ViewBuilder content: () -> Content) {
|
|
14
20
|
self.parentScrollOffset = parentScrollOffset
|
|
15
21
|
self.content = content()
|
|
@@ -17,7 +23,7 @@ struct SpatializedElementView<Content: View>: View {
|
|
|
17
23
|
|
|
18
24
|
// Begin Interaction
|
|
19
25
|
var gesture: some Gesture {
|
|
20
|
-
DragGesture()
|
|
26
|
+
DragGesture(minimumDistance: 10)
|
|
21
27
|
.onChanged(onDragging)
|
|
22
28
|
.onEnded(onDraggingEnded)
|
|
23
29
|
.simultaneously(with:
|
|
@@ -37,54 +43,49 @@ struct SpatializedElementView<Content: View>: View {
|
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
private func onRotateGesture3D(_ event: RotateGesture3D.Value) {
|
|
40
|
-
if spatializedElement.enableRotateGesture
|
|
41
|
-
let
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
if spatializedElement.enableRotateGesture {
|
|
47
|
+
let quaternion = event.rotation.quaternion
|
|
48
|
+
let x = quaternion.imag.x
|
|
49
|
+
let y = quaternion.imag.y
|
|
50
|
+
let z = quaternion.imag.z
|
|
51
|
+
let w = quaternion.real
|
|
52
|
+
let detail = WebSpatialRotateGuestureEventDetail(quaternion: .init(x: x, y: y, z: z, w: w))
|
|
53
|
+
|
|
54
|
+
let gestureEvent = WebSpatialRotateGuestureEvent(detail: detail)
|
|
47
55
|
spatialScene.sendWebMsg(spatializedElement.id, gestureEvent)
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
private func onRotateGesture3DEnd(_ event: RotateGesture3D.Value) {
|
|
52
60
|
if spatializedElement.enableRotateEndGesture {
|
|
53
|
-
|
|
54
|
-
detail: .init(
|
|
55
|
-
rotation: event.rotation,
|
|
56
|
-
startAnchor3D: event.startAnchor3D,
|
|
57
|
-
startLocation3D: event.startLocation3D
|
|
58
|
-
))
|
|
59
|
-
spatialScene.sendWebMsg(spatializedElement.id, gestureEvent)
|
|
61
|
+
spatialScene.sendWebMsg(spatializedElement.id, WebSpatialRotateEndGuestureEvent())
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
private func onDragging(_ event: DragGesture.Value) {
|
|
64
|
-
if spatializedElement.enableDragStartGesture
|
|
66
|
+
if spatializedElement.enableDragStartGesture, !gestureFlags.isDrag {
|
|
67
|
+
let gestureEvent = WebSpatialDragStartGuestureEvent(detail: .init(
|
|
68
|
+
startLocation3D: event.startLocation3D
|
|
69
|
+
))
|
|
70
|
+
|
|
71
|
+
spatialScene.sendWebMsg(spatializedElement.id, gestureEvent)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if spatializedElement.enableDragGesture {
|
|
65
75
|
let gestureEvent = WebSpatialDragGuestureEvent(detail: .init(
|
|
66
|
-
|
|
67
|
-
startLocation3D: event.startLocation3D,
|
|
68
|
-
translation3D: event.translation3D,
|
|
69
|
-
predictedEndTranslation3D: event.predictedEndTranslation3D,
|
|
70
|
-
predictedEndLocation3D: event.predictedEndLocation3D,
|
|
71
|
-
velocity: event.velocity
|
|
76
|
+
translation3D: event.translation3D
|
|
72
77
|
))
|
|
78
|
+
|
|
73
79
|
spatialScene.sendWebMsg(spatializedElement.id, gestureEvent)
|
|
74
80
|
}
|
|
81
|
+
|
|
82
|
+
gestureFlags.isDrag = true
|
|
75
83
|
}
|
|
76
84
|
|
|
77
85
|
private func onDraggingEnded(_ event: DragGesture.Value) {
|
|
86
|
+
gestureFlags.isDrag = false
|
|
78
87
|
if spatializedElement.enableDragEndGesture {
|
|
79
|
-
let gestureEvent = WebSpatialDragEndGuestureEvent(
|
|
80
|
-
detail: .init(
|
|
81
|
-
location3D: event.location3D,
|
|
82
|
-
startLocation3D: event.startLocation3D,
|
|
83
|
-
translation3D: event.translation3D,
|
|
84
|
-
predictedEndTranslation3D: event.predictedEndTranslation3D,
|
|
85
|
-
predictedEndLocation3D: event.predictedEndLocation3D,
|
|
86
|
-
velocity: event.velocity
|
|
87
|
-
))
|
|
88
|
+
let gestureEvent = WebSpatialDragEndGuestureEvent()
|
|
88
89
|
spatialScene.sendWebMsg(spatializedElement.id, gestureEvent)
|
|
89
90
|
}
|
|
90
91
|
}
|
|
@@ -96,13 +97,10 @@ struct SpatializedElementView<Content: View>: View {
|
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
private func onMagnifyGesture(_ event: MagnifyGesture.Value) {
|
|
99
|
-
if spatializedElement.enableMagnifyGesture
|
|
100
|
+
if spatializedElement.enableMagnifyGesture {
|
|
100
101
|
let gestureEvent = WebSpatialMagnifyGuestureEvent(
|
|
101
102
|
detail: .init(
|
|
102
|
-
magnification: event.magnification
|
|
103
|
-
velocity: event.velocity,
|
|
104
|
-
startLocation3D: event.startLocation3D,
|
|
105
|
-
startAnchor3D: event.startAnchor3D
|
|
103
|
+
magnification: event.magnification
|
|
106
104
|
))
|
|
107
105
|
spatialScene.sendWebMsg(spatializedElement.id, gestureEvent)
|
|
108
106
|
}
|
|
@@ -110,14 +108,7 @@ struct SpatializedElementView<Content: View>: View {
|
|
|
110
108
|
|
|
111
109
|
private func onMagnifyGestureEnd(_ event: MagnifyGesture.Value) {
|
|
112
110
|
if spatializedElement.enableMagnifyEndGesture {
|
|
113
|
-
|
|
114
|
-
detail: .init(
|
|
115
|
-
magnification: event.magnification,
|
|
116
|
-
velocity: event.velocity,
|
|
117
|
-
startLocation3D: event.startLocation3D,
|
|
118
|
-
startAnchor3D: event.startAnchor3D
|
|
119
|
-
))
|
|
120
|
-
spatialScene.sendWebMsg(spatializedElement.id, gestureEvent)
|
|
111
|
+
spatialScene.sendWebMsg(spatializedElement.id, WebSpatialMagnifyEndGuestureEvent())
|
|
121
112
|
}
|
|
122
113
|
}
|
|
123
114
|
|
|
@@ -145,9 +136,13 @@ struct SpatializedElementView<Content: View>: View {
|
|
|
145
136
|
let z = translation.z + (spatializedElement.zIndex * zOrderBias)
|
|
146
137
|
let smallOffset = z == 0.0 ? 0.0001 : 0
|
|
147
138
|
|
|
148
|
-
|
|
139
|
+
// when spatialdiv have regular/thick/thin material and alignment is back, there'll be a bug that clipping content
|
|
140
|
+
// so when spatializedElement is spatialdiv, .center alignment will be applied
|
|
141
|
+
let alignment = spatializedElement.defaultAlignment
|
|
142
|
+
|
|
143
|
+
content
|
|
149
144
|
.frame(width: width, height: height)
|
|
150
|
-
.frame(depth: depth, alignment:
|
|
145
|
+
.frame(depth: depth, alignment: alignment)
|
|
151
146
|
.onGeometryChange3D(for: AffineTransform3D.self) { proxy in
|
|
152
147
|
let rect3d = proxy.frame(in: .named("SpatialScene"))
|
|
153
148
|
spatialScene.sendWebMsg(spatializedElement.id, SpatiaizedContainerClientCube(origin: rect3d.origin, size: rect3d.size))
|
|
@@ -174,5 +169,6 @@ struct SpatializedElementView<Content: View>: View {
|
|
|
174
169
|
.offset(z: spatializedElement.backOffset)
|
|
175
170
|
.opacity(opacity)
|
|
176
171
|
.hidden(!visible)
|
|
172
|
+
.simultaneousGesture(enableGesture ? gesture : nil)
|
|
177
173
|
}
|
|
178
174
|
}
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
</EnvironmentVariables>
|
|
73
73
|
<AdditionalOptions>
|
|
74
74
|
<AdditionalOption
|
|
75
|
-
key = "
|
|
75
|
+
key = "MallocScribble"
|
|
76
76
|
value = ""
|
|
77
77
|
isEnabled = "YES">
|
|
78
78
|
</AdditionalOption>
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
isEnabled = "YES">
|
|
83
83
|
</AdditionalOption>
|
|
84
84
|
<AdditionalOption
|
|
85
|
-
key = "
|
|
85
|
+
key = "MallocStackLogging"
|
|
86
86
|
value = ""
|
|
87
87
|
isEnabled = "YES">
|
|
88
88
|
</AdditionalOption>
|