1 | import Constants from 'expo-constants';
|
2 | import { Dimensions, NativeEventEmitter, NativeModules, Platform, findNodeHandle, } from 'react-native';
|
3 | const ExponentAR = NativeModules.ExponentAR || {};
|
4 | const emitter = new NativeEventEmitter(ExponentAR);
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export var TrackingConfiguration;
|
11 | (function (TrackingConfiguration) {
|
12 | |
13 |
|
14 |
|
15 |
|
16 | TrackingConfiguration["World"] = "ARWorldTrackingConfiguration";
|
17 | |
18 |
|
19 |
|
20 |
|
21 | TrackingConfiguration["Orientation"] = "AROrientationTrackingConfiguration";
|
22 | |
23 |
|
24 |
|
25 |
|
26 | TrackingConfiguration["Face"] = "ARFaceTrackingConfiguration";
|
27 | })(TrackingConfiguration || (TrackingConfiguration = {}));
|
28 | export var DepthDataQuality;
|
29 | (function (DepthDataQuality) {
|
30 | DepthDataQuality["Low"] = "AVDepthDataQualityLow";
|
31 | DepthDataQuality["High"] = "AVDepthDataQualityHigh";
|
32 | })(DepthDataQuality || (DepthDataQuality = {}));
|
33 | export var DepthDataAccuracy;
|
34 | (function (DepthDataAccuracy) {
|
35 | DepthDataAccuracy["Absolute"] = "AVDepthDataAccuracyAbsolute";
|
36 | DepthDataAccuracy["Relative"] = "AVDepthDataAccuracyRelative";
|
37 | })(DepthDataAccuracy || (DepthDataAccuracy = {}));
|
38 | export var BlendShape;
|
39 | (function (BlendShape) {
|
40 | BlendShape["BrowDownL"] = "browDown_L";
|
41 | BlendShape["BrowDownR"] = "browDown_R";
|
42 | BlendShape["BrowInnerUp"] = "browInnerUp";
|
43 | BlendShape["BrowOuterUpL"] = "browOuterUp_L";
|
44 | BlendShape["BrowOuterUpR"] = "browOuterUp_R";
|
45 | BlendShape["CheekPuff"] = "cheekPuff";
|
46 | BlendShape["CheekSquintL"] = "cheekSquint_L";
|
47 | BlendShape["CheekSquintR"] = "cheekSquint_R";
|
48 | BlendShape["EyeBlinkL"] = "eyeBlink_L";
|
49 | BlendShape["EyeBlinkR"] = "eyeBlink_R";
|
50 | BlendShape["EyeLookDownL"] = "eyeLookDown_L";
|
51 | BlendShape["EyeLookDownR"] = "eyeLookDown_R";
|
52 | BlendShape["EyeLookInL"] = "eyeLookIn_L";
|
53 | BlendShape["EyeLookInR"] = "eyeLookIn_R";
|
54 | BlendShape["EyeLookOutL"] = "eyeLookOut_L";
|
55 | BlendShape["EyeLookOutR"] = "eyeLookOut_R";
|
56 | BlendShape["EyeLookUpL"] = "eyeLookUp_L";
|
57 | BlendShape["EyeLookUpR"] = "eyeLookUp_R";
|
58 | BlendShape["EyeSquintL"] = "eyeSquint_L";
|
59 | BlendShape["EyeSquintR"] = "eyeSquint_R";
|
60 | BlendShape["EyeWideL"] = "eyeWide_L";
|
61 | BlendShape["EyeWideR"] = "eyeWide_R";
|
62 | BlendShape["JawForward"] = "jawForward";
|
63 | BlendShape["JawLeft"] = "jawLeft";
|
64 | BlendShape["JawOpen"] = "jawOpen";
|
65 | BlendShape["JawRight"] = "jawRight";
|
66 | BlendShape["MouthClose"] = "mouthClose";
|
67 | BlendShape["MouthDimpleL"] = "mouthDimple_L";
|
68 | BlendShape["MouthDimpleR"] = "mouthDimple_R";
|
69 | BlendShape["MouthFrownL"] = "mouthFrown_L";
|
70 | BlendShape["MouthFrownR"] = "mouthFrown_R";
|
71 | BlendShape["MouthFunnel"] = "mouthFunnel";
|
72 | BlendShape["MouthLeft"] = "mouthLeft";
|
73 | BlendShape["MouthLowerDownL"] = "mouthLowerDown_L";
|
74 | BlendShape["MouthLowerDownR"] = "mouthLowerDown_R";
|
75 | BlendShape["MouthPressL"] = "mouthPress_L";
|
76 | BlendShape["MouthPressR"] = "mouthPress_R";
|
77 | BlendShape["MouthPucker"] = "mouthPucker";
|
78 | BlendShape["MouthRight"] = "mouthRight";
|
79 | BlendShape["MouthRollLower"] = "mouthRollLower";
|
80 | BlendShape["MouthRollUpper"] = "mouthRollUpper";
|
81 | BlendShape["MouthShrugLower"] = "mouthShrugLower";
|
82 | BlendShape["MouthShrugUpper"] = "mouthShrugUpper";
|
83 | BlendShape["MouthSmileL"] = "mouthSmile_L";
|
84 | BlendShape["MouthSmileR"] = "mouthSmile_R";
|
85 | BlendShape["MouthStretchL"] = "mouthStretch_L";
|
86 | BlendShape["MouthStretchR"] = "mouthStretch_R";
|
87 | BlendShape["MouthUpperUpL"] = "mouthUpperUp_L";
|
88 | BlendShape["MouthUpperUpR"] = "mouthUpperUp_R";
|
89 | BlendShape["NoseSneerL"] = "noseSneer_L";
|
90 | BlendShape["NoseSneerR"] = "noseSneer_R";
|
91 | })(BlendShape || (BlendShape = {}));
|
92 | export var FaceAnchorProp;
|
93 | (function (FaceAnchorProp) {
|
94 | FaceAnchorProp["Geometry"] = "geometry";
|
95 | FaceAnchorProp["BlendShapes"] = "blendShapes";
|
96 | })(FaceAnchorProp || (FaceAnchorProp = {}));
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | export var PlaneDetection;
|
103 | (function (PlaneDetection) {
|
104 | |
105 |
|
106 |
|
107 | PlaneDetection["None"] = "none";
|
108 | |
109 |
|
110 |
|
111 | PlaneDetection["Horizontal"] = "horizontal";
|
112 | |
113 |
|
114 |
|
115 | PlaneDetection["Vertical"] = "vertical";
|
116 | })(PlaneDetection || (PlaneDetection = {}));
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | export var HitTestResultTypes;
|
123 | (function (HitTestResultTypes) {
|
124 | |
125 |
|
126 |
|
127 | HitTestResultTypes["FeaturePoint"] = "featurePoint";
|
128 | |
129 |
|
130 |
|
131 | HitTestResultTypes["HorizontalPlane"] = "horizontalPlane";
|
132 | |
133 |
|
134 |
|
135 | HitTestResultTypes["VerticalPlane"] = "verticalPlane";
|
136 | |
137 |
|
138 |
|
139 | HitTestResultTypes["ExistingPlane"] = "existingPlane";
|
140 | |
141 |
|
142 |
|
143 |
|
144 | HitTestResultTypes["ExistingPlaneUsingExtent"] = "existingPlaneUsingExtent";
|
145 | |
146 |
|
147 |
|
148 |
|
149 | HitTestResultTypes["ExistingPlaneUsingGeometry"] = "existingPlaneUsingGeometry";
|
150 | })(HitTestResultTypes || (HitTestResultTypes = {}));
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | export var WorldAlignment;
|
157 | (function (WorldAlignment) {
|
158 | |
159 |
|
160 |
|
161 | WorldAlignment["Gravity"] = "gravity";
|
162 | |
163 |
|
164 |
|
165 |
|
166 | WorldAlignment["GravityAndHeading"] = "gravityAndHeading";
|
167 | |
168 |
|
169 |
|
170 | WorldAlignment["AlignmentCamera"] = "alignmentCamera";
|
171 | })(WorldAlignment || (WorldAlignment = {}));
|
172 | export var EventType;
|
173 | (function (EventType) {
|
174 | EventType[EventType["FrameDidUpdate"] = ExponentAR.frameDidUpdate] = "FrameDidUpdate";
|
175 | EventType[EventType["DidFailWithError"] = ExponentAR.didFailWithError] = "DidFailWithError";
|
176 | EventType[EventType["AnchorsDidUpdate"] = ExponentAR.anchorsDidUpdate] = "AnchorsDidUpdate";
|
177 | EventType[EventType["CameraDidChangeTrackingState"] = ExponentAR.cameraDidChangeTrackingState] = "CameraDidChangeTrackingState";
|
178 | EventType[EventType["SessionWasInterrupted"] = ExponentAR.sessionWasInterrupted] = "SessionWasInterrupted";
|
179 | EventType[EventType["SessionInterruptionEnded"] = ExponentAR.sessionInterruptionEnded] = "SessionInterruptionEnded";
|
180 | })(EventType || (EventType = {}));
|
181 | export var AnchorType;
|
182 | (function (AnchorType) {
|
183 | AnchorType["Face"] = "ARFaceAnchor";
|
184 | AnchorType["Image"] = "ARImageAnchor";
|
185 | AnchorType["Plane"] = "ARPlaneAnchor";
|
186 | AnchorType["Anchor"] = "ARAnchor";
|
187 | })(AnchorType || (AnchorType = {}));
|
188 | export var AnchorEventType;
|
189 | (function (AnchorEventType) {
|
190 | AnchorEventType["Add"] = "add";
|
191 | AnchorEventType["Update"] = "update";
|
192 | AnchorEventType["Remove"] = "remove";
|
193 | })(AnchorEventType || (AnchorEventType = {}));
|
194 | export var FrameAttribute;
|
195 | (function (FrameAttribute) {
|
196 | FrameAttribute["Anchors"] = "anchors";
|
197 | FrameAttribute["RawFeaturePoints"] = "rawFeaturePoints";
|
198 | FrameAttribute["LightEstimation"] = "lightEstimation";
|
199 | FrameAttribute["CapturedDepthData"] = "capturedDepthData";
|
200 | })(FrameAttribute || (FrameAttribute = {}));
|
201 | export var TrackingState;
|
202 | (function (TrackingState) {
|
203 |
|
204 | TrackingState["NotAvailable"] = "ARTrackingStateNotAvailable";
|
205 |
|
206 | TrackingState["Limited"] = "ARTrackingStateLimited";
|
207 |
|
208 | TrackingState["Normal"] = "ARTrackingStateNormal";
|
209 | })(TrackingState || (TrackingState = {}));
|
210 | export var TrackingStateReason;
|
211 | (function (TrackingStateReason) {
|
212 |
|
213 | TrackingStateReason["None"] = "ARTrackingStateReasonNone";
|
214 |
|
215 | TrackingStateReason["Initializing"] = "ARTrackingStateReasonInitializing";
|
216 |
|
217 | TrackingStateReason["ExcessiveMotion"] = "ARTrackingStateReasonExcessiveMotion";
|
218 |
|
219 | TrackingStateReason["InsufficientFeatures"] = "ARTrackingStateReasonInsufficientFeatures";
|
220 |
|
221 | TrackingStateReason["Relocalizing"] = "ARTrackingStateReasonRelocalizing";
|
222 | })(TrackingStateReason || (TrackingStateReason = {}));
|
223 | export function getVersion() {
|
224 | return ExponentAR.ARKitVersion;
|
225 | }
|
226 | const AvailabilityErrorMessages = {
|
227 | Simulator: `Cannot run EXGL in a simulator`,
|
228 | ANineChip: `ARKit can only run on iOS devices with A9 (2015) or greater chips! This is a`,
|
229 | ARKitOnlyOnIOS: `ARKit can only run on an iOS device! This is a`,
|
230 | };
|
231 | export function isAvailable() {
|
232 |
|
233 | const hasA9Chip = Constants.deviceYearClass && Constants.deviceYearClass > 2014;
|
234 | if (!Constants.isDevice ||
|
235 |
|
236 | Platform.isTVOS ||
|
237 | Platform.OS !== 'ios' ||
|
238 | !hasA9Chip ||
|
239 | !ExponentAR.isSupported ||
|
240 | !ExponentAR.startAsync
|
241 | ) {
|
242 | return false;
|
243 | }
|
244 | return true;
|
245 | }
|
246 | export function getUnavailabilityReason() {
|
247 | if (!Constants.isDevice) {
|
248 | return AvailabilityErrorMessages.Simulator;
|
249 | }
|
250 | else if (Platform.OS !== 'ios') {
|
251 | return `${AvailabilityErrorMessages.ARKitOnlyOnIOS} ${Platform.OS} device`;
|
252 | }
|
253 | else if (Constants.deviceYearClass == null || Constants.deviceYearClass < 2015) {
|
254 | return `${AvailabilityErrorMessages.ANineChip} ${Constants.deviceYearClass} device`;
|
255 | }
|
256 | return 'Unknown Reason';
|
257 | }
|
258 | export function onFrameDidUpdate(listener) {
|
259 | return _addListener(EventType.FrameDidUpdate, listener);
|
260 | }
|
261 | export function onDidFailWithError(listener) {
|
262 | return _addListener(EventType.DidFailWithError, listener);
|
263 | }
|
264 | export function onAnchorsDidUpdate(listener) {
|
265 | return _addListener(EventType.AnchorsDidUpdate, listener);
|
266 | }
|
267 | export function onCameraDidChangeTrackingState(listener) {
|
268 | return _addListener(EventType.CameraDidChangeTrackingState, listener);
|
269 | }
|
270 | export function onSessionWasInterrupted(listener) {
|
271 | return _addListener(EventType.SessionWasInterrupted, listener);
|
272 | }
|
273 | export function onSessionInterruptionEnded(listener) {
|
274 | return _addListener(EventType.SessionInterruptionEnded, listener);
|
275 | }
|
276 | function _addListener(eventType, event) {
|
277 | return emitter.addListener(eventType, event);
|
278 | }
|
279 | export function removeAllListeners(eventType) {
|
280 | emitter.removeAllListeners(eventType);
|
281 | }
|
282 |
|
283 | export function performHitTest(point, types) {
|
284 | if (ExponentAR.performHitTest) {
|
285 | return ExponentAR.performHitTest(point, types);
|
286 | }
|
287 | throw new Error(`AR hit testing is not supported on this device`);
|
288 | }
|
289 | export async function setDetectionImagesAsync(images) {
|
290 | if (ExponentAR.setDetectionImagesAsync) {
|
291 | await ExponentAR.setDetectionImagesAsync(images);
|
292 | }
|
293 | }
|
294 | export function getCurrentFrame(attributes) {
|
295 | if (ExponentAR.getCurrentFrame) {
|
296 | return ExponentAR.getCurrentFrame(attributes);
|
297 | }
|
298 | throw new Error(`AR is not supported on this device`);
|
299 | }
|
300 | export function getARMatrices(near, far) {
|
301 | if (ExponentAR.getARMatrices) {
|
302 | return ExponentAR.getARMatrices(near, far);
|
303 | }
|
304 | throw new Error(`AR is not supported on this device`);
|
305 | }
|
306 | export async function stopAsync() {
|
307 | if (ExponentAR.stopAsync) {
|
308 | await ExponentAR.stopAsync();
|
309 | }
|
310 | }
|
311 | export async function startAsync(node, configuration) {
|
312 | let handle = typeof node === 'number' ? node : _getNodeHandle(node);
|
313 | if (ExponentAR.startAsync) {
|
314 | return await ExponentAR.startAsync(handle, configuration);
|
315 | }
|
316 | throw new Error(`AR is not supported on this device`);
|
317 | }
|
318 | function _getNodeHandle(component) {
|
319 | let handle = findNodeHandle(component);
|
320 | if (handle === null) {
|
321 | throw new Error(`Could not find the React node handle for the AR component: ${component}`);
|
322 | }
|
323 | return handle;
|
324 | }
|
325 | export function reset() {
|
326 | if (ExponentAR.reset) {
|
327 | ExponentAR.reset();
|
328 | }
|
329 | }
|
330 | export function resume() {
|
331 | if (ExponentAR.resume) {
|
332 | ExponentAR.resume();
|
333 | }
|
334 | }
|
335 | export function pause() {
|
336 | if (ExponentAR.pause) {
|
337 | ExponentAR.pause();
|
338 | }
|
339 | }
|
340 | export async function setConfigurationAsync(configuration) {
|
341 | if (ExponentAR.setConfigurationAsync) {
|
342 | await ExponentAR.setConfigurationAsync(configuration);
|
343 | }
|
344 | }
|
345 | export function getProvidesAudioData() {
|
346 | if (ExponentAR.getProvidesAudioData) {
|
347 | return ExponentAR.getProvidesAudioData();
|
348 | }
|
349 | return false;
|
350 | }
|
351 | export function setProvidesAudioData(providesAudioData) {
|
352 | if (ExponentAR.setProvidesAudioData) {
|
353 | ExponentAR.setProvidesAudioData(providesAudioData);
|
354 | }
|
355 | }
|
356 | export function setPlaneDetection(planeDetection) {
|
357 | if (ExponentAR.setPlaneDetection) {
|
358 | ExponentAR.setPlaneDetection(planeDetection);
|
359 | }
|
360 | }
|
361 | export function getPlaneDetection() {
|
362 | if (ExponentAR.getPlaneDetection) {
|
363 | return ExponentAR.getPlaneDetection();
|
364 | }
|
365 | throw new Error(`AR plane detection is not supported on this device`);
|
366 | }
|
367 | export function getCameraTexture() {
|
368 | if (ExponentAR.getCameraTexture) {
|
369 | return ExponentAR.getCameraTexture();
|
370 | }
|
371 | throw new Error(`AR camera textures are not supported on this device`);
|
372 | }
|
373 | export async function setWorldOriginAsync(matrix_float4x4) {
|
374 | if (ExponentAR.setWorldOriginAsync) {
|
375 | await ExponentAR.setWorldOriginAsync(matrix_float4x4);
|
376 | }
|
377 | }
|
378 | export function setLightEstimationEnabled(isLightEstimationEnabled) {
|
379 | if (ExponentAR.setLightEstimationEnabled) {
|
380 | ExponentAR.setLightEstimationEnabled(isLightEstimationEnabled);
|
381 | }
|
382 | }
|
383 | export function getLightEstimationEnabled() {
|
384 | if (ExponentAR.getLightEstimationEnabled) {
|
385 | return ExponentAR.getLightEstimationEnabled();
|
386 | }
|
387 | return false;
|
388 | }
|
389 | export function setAutoFocusEnabled(isAutoFocusEnabled) {
|
390 | if (ExponentAR.setAutoFocusEnabled) {
|
391 | ExponentAR.setAutoFocusEnabled(isAutoFocusEnabled);
|
392 | }
|
393 | }
|
394 | export function getAutoFocusEnabled() {
|
395 | if (ExponentAR.getAutoFocusEnabled) {
|
396 | return ExponentAR.getAutoFocusEnabled();
|
397 | }
|
398 | return false;
|
399 | }
|
400 | export function setWorldAlignment(worldAlignment) {
|
401 | if (ExponentAR.setWorldAlignment) {
|
402 | ExponentAR.setWorldAlignment(worldAlignment);
|
403 | }
|
404 | }
|
405 | export function getWorldAlignment() {
|
406 | if (ExponentAR.getWorldAlignment) {
|
407 | return ExponentAR.getWorldAlignment();
|
408 | }
|
409 | throw new Error(`AR world alignment is not supported on this device`);
|
410 | }
|
411 | export function isConfigurationAvailable(configuration) {
|
412 | const { width, height } = Dimensions.get('window');
|
413 |
|
414 | const isX = (width === 812 || height === 812) && !Platform.isTVOS && !Platform.isPad;
|
415 | if (configuration === TrackingConfiguration.Face && isX && isAvailable()) {
|
416 | return true;
|
417 | }
|
418 | return !!ExponentAR[configuration];
|
419 | }
|
420 | export function getSupportedVideoFormats(configuration) {
|
421 | const videoFormats = {
|
422 | [TrackingConfiguration.World]: 'WorldTrackingVideoFormats',
|
423 | [TrackingConfiguration.Orientation]: 'OrientationTrackingVideoFormats',
|
424 | [TrackingConfiguration.Face]: 'FaceTrackingVideoFormats',
|
425 | };
|
426 | const videoFormat = videoFormats[configuration];
|
427 | return ExponentAR[videoFormat] || [];
|
428 | }
|
429 | export function isFrontCameraAvailable() {
|
430 | return isConfigurationAvailable(TrackingConfiguration.Face);
|
431 | }
|
432 | export function isRearCameraAvailable() {
|
433 | return isConfigurationAvailable(TrackingConfiguration.World);
|
434 | }
|
435 |
|
\ | No newline at end of file |