UNPKG

17.3 kBJavaScriptView Raw
1import { Constants } from 'expo-constants';
2import { Dimensions, NativeEventEmitter, NativeModules, Platform, findNodeHandle, } from 'react-native';
3const ExponentAR = NativeModules.ExponentAR || {};
4const emitter = new NativeEventEmitter(ExponentAR);
5/**
6 * Tracking Configuration
7 * Options for how ARKit constructs a scene coordinate system based on real-world device motion.
8 * https://developer.apple.com/documentation/arkit/arconfiguration
9 */
10export var TrackingConfiguration;
11(function (TrackingConfiguration) {
12 /**
13 * Provides high-quality AR experiences that use the rear-facing camera precisely track a device's
14 * position and orientation and allow plane detection and hit testing.
15 */
16 TrackingConfiguration["World"] = "ARWorldTrackingConfiguration";
17 /**
18 * Provides basic AR experiences that use the rear-facing camera and track only a device's
19 * orientation.
20 */
21 TrackingConfiguration["Orientation"] = "AROrientationTrackingConfiguration";
22 /**
23 * Provides AR experiences that use the front-facing camera and track the movement and expressions
24 * of the user's face.
25 */
26 TrackingConfiguration["Face"] = "ARFaceTrackingConfiguration";
27})(TrackingConfiguration || (TrackingConfiguration = {}));
28export var DepthDataQuality;
29(function (DepthDataQuality) {
30 DepthDataQuality["Low"] = "AVDepthDataQualityLow";
31 DepthDataQuality["High"] = "AVDepthDataQualityHigh";
32})(DepthDataQuality || (DepthDataQuality = {}));
33export var DepthDataAccuracy;
34(function (DepthDataAccuracy) {
35 DepthDataAccuracy["Absolute"] = "AVDepthDataAccuracyAbsolute";
36 DepthDataAccuracy["Relative"] = "AVDepthDataAccuracyRelative";
37})(DepthDataAccuracy || (DepthDataAccuracy = {}));
38export 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 = {}));
92export var FaceAnchorProp;
93(function (FaceAnchorProp) {
94 FaceAnchorProp["Geometry"] = "geometry";
95 FaceAnchorProp["BlendShapes"] = "blendShapes";
96})(FaceAnchorProp || (FaceAnchorProp = {}));
97/**
98 * Plane Detection
99 * Options for whether and how ARKit detects flat surfaces in captured images.
100 * https://developer.apple.com/documentation/arkit/arplanedetection
101 */
102export var PlaneDetection;
103(function (PlaneDetection) {
104 /**
105 * No plane detection is run
106 */
107 PlaneDetection["None"] = "none";
108 /**
109 * Plane detection determines horizontal planes in the scene
110 */
111 PlaneDetection["Horizontal"] = "horizontal";
112 /**
113 * Plane detection determines horizontal planes in the scene
114 */
115 PlaneDetection["Vertical"] = "vertical";
116})(PlaneDetection || (PlaneDetection = {}));
117/**
118 * Hit-Test Result Types
119 * Possible types for specifying a hit-test search, or for the result of a hit-test search.
120 * https://developer.apple.com/documentation/arkit/arhittestresulttype
121 */
122export var HitTestResultTypes;
123(function (HitTestResultTypes) {
124 /**
125 * Result type from intersecting the nearest feature point.
126 */
127 HitTestResultTypes["FeaturePoint"] = "featurePoint";
128 /**
129 * Result type from intersecting a horizontal plane estimate, determined for the current frame.
130 */
131 HitTestResultTypes["HorizontalPlane"] = "horizontalPlane";
132 /**
133 * Result type from intersecting a vertical plane estimate, determined for the current frame.
134 */
135 HitTestResultTypes["VerticalPlane"] = "verticalPlane";
136 /**
137 * Result type from intersecting with an existing plane anchor.
138 */
139 HitTestResultTypes["ExistingPlane"] = "existingPlane";
140 /**
141 * Result type from intersecting with an existing plane anchor, taking into account the plane’s
142 * extent.
143 */
144 HitTestResultTypes["ExistingPlaneUsingExtent"] = "existingPlaneUsingExtent";
145 /**
146 * Result type from intersecting with an existing plane anchor, taking into account the plane’s
147 * geometry.
148 */
149 HitTestResultTypes["ExistingPlaneUsingGeometry"] = "existingPlaneUsingGeometry";
150})(HitTestResultTypes || (HitTestResultTypes = {}));
151/**
152 * World Alignment
153 * Options for how ARKit constructs a scene coordinate system based on real-world device motion.
154 * https://developer.apple.com/documentation/arkit/arworldalignment
155 */
156export var WorldAlignment;
157(function (WorldAlignment) {
158 /**
159 * Aligns the world with gravity that is defined by vector (0, -1, 0).
160 */
161 WorldAlignment["Gravity"] = "gravity";
162 /**
163 * Aligns the world with gravity that is defined by the vector (0, -1, 0) and heading (w.r.t. true
164 * north) that is given by the vector (0, 0, -1).
165 */
166 WorldAlignment["GravityAndHeading"] = "gravityAndHeading";
167 /**
168 * Aligns the world with the camera’s orientation.
169 */
170 WorldAlignment["AlignmentCamera"] = "alignmentCamera";
171})(WorldAlignment || (WorldAlignment = {}));
172export 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 = {}));
181export var AnchorType;
182(function (AnchorType) {
183 AnchorType["Face"] = "ARFaceAnchor";
184 AnchorType["Image"] = "ARImageAnchor";
185 AnchorType["Plane"] = "ARPlaneAnchor";
186 AnchorType["Anchor"] = "ARAnchor";
187})(AnchorType || (AnchorType = {}));
188export var AnchorEventType;
189(function (AnchorEventType) {
190 AnchorEventType["Add"] = "add";
191 AnchorEventType["Update"] = "update";
192 AnchorEventType["Remove"] = "remove";
193})(AnchorEventType || (AnchorEventType = {}));
194export var FrameAttribute;
195(function (FrameAttribute) {
196 FrameAttribute["Anchors"] = "anchors";
197 FrameAttribute["RawFeaturePoints"] = "rawFeaturePoints";
198 FrameAttribute["LightEstimation"] = "lightEstimation";
199 FrameAttribute["CapturedDepthData"] = "capturedDepthData";
200})(FrameAttribute || (FrameAttribute = {}));
201export var TrackingState;
202(function (TrackingState) {
203 /** Tracking is not available. */
204 TrackingState["NotAvailable"] = "ARTrackingStateNotAvailable";
205 /** Tracking is limited. See tracking reason for details. */
206 TrackingState["Limited"] = "ARTrackingStateLimited";
207 /** Tracking is Normal. */
208 TrackingState["Normal"] = "ARTrackingStateNormal";
209})(TrackingState || (TrackingState = {}));
210export var TrackingStateReason;
211(function (TrackingStateReason) {
212 /** Tracking is not limited. */
213 TrackingStateReason["None"] = "ARTrackingStateReasonNone";
214 /** Tracking is limited due to initialization in progress. */
215 TrackingStateReason["Initializing"] = "ARTrackingStateReasonInitializing";
216 /** Tracking is limited due to a excessive motion of the camera. */
217 TrackingStateReason["ExcessiveMotion"] = "ARTrackingStateReasonExcessiveMotion";
218 /** Tracking is limited due to a lack of features visible to the camera. */
219 TrackingStateReason["InsufficientFeatures"] = "ARTrackingStateReasonInsufficientFeatures";
220 /** Tracking is limited due to a relocalization in progress. */
221 TrackingStateReason["Relocalizing"] = "ARTrackingStateReasonRelocalizing";
222})(TrackingStateReason || (TrackingStateReason = {}));
223export function getVersion() {
224 return ExponentAR.ARKitVersion;
225}
226const 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};
231export function isAvailable() {
232 if (!Constants.isDevice || // Prevent Simulators
233 // @ts-ignore
234 Platform.isTVOS ||
235 Platform.OS !== 'ios' || // Device is iOS
236 Constants.deviceYearClass < 2015 || // Device has A9 chip
237 !ExponentAR.isSupported || // ARKit is included in the build
238 !ExponentAR.startAsync // Older SDK versions (27 and lower) that are fully compatible
239 ) {
240 return false;
241 }
242 return true;
243}
244export function getUnavailabilityReason() {
245 if (!Constants.isDevice) {
246 return AvailabilityErrorMessages.Simulator;
247 }
248 else if (Platform.OS !== 'ios') {
249 return `${AvailabilityErrorMessages.ARKitOnlyOnIOS} ${Platform.OS} device`;
250 }
251 else if (Constants.deviceYearClass < 2015) {
252 return `${AvailabilityErrorMessages.ANineChip} ${Constants.deviceYearClass} device`;
253 }
254 return 'Unknown Reason';
255}
256export function onFrameDidUpdate(listener) {
257 return _addListener(EventType.FrameDidUpdate, listener);
258}
259export function onDidFailWithError(listener) {
260 return _addListener(EventType.DidFailWithError, listener);
261}
262export function onAnchorsDidUpdate(listener) {
263 return _addListener(EventType.AnchorsDidUpdate, listener);
264}
265export function onCameraDidChangeTrackingState(listener) {
266 return _addListener(EventType.CameraDidChangeTrackingState, listener);
267}
268export function onSessionWasInterrupted(listener) {
269 return _addListener(EventType.SessionWasInterrupted, listener);
270}
271export function onSessionInterruptionEnded(listener) {
272 return _addListener(EventType.SessionInterruptionEnded, listener);
273}
274function _addListener(eventType, event) {
275 return emitter.addListener(eventType, event);
276}
277export function removeAllListeners(eventType) {
278 emitter.removeAllListeners(eventType);
279}
280// TODO: support multiple types (take an array or bit flags)
281export function performHitTest(point, types) {
282 if (ExponentAR.performHitTest) {
283 return ExponentAR.performHitTest(point, types);
284 }
285 throw new Error(`AR hit testing is not supported on this device`);
286}
287export async function setDetectionImagesAsync(images) {
288 if (ExponentAR.setDetectionImagesAsync) {
289 await ExponentAR.setDetectionImagesAsync(images);
290 }
291}
292export function getCurrentFrame(attributes) {
293 if (ExponentAR.getCurrentFrame) {
294 return ExponentAR.getCurrentFrame(attributes);
295 }
296 throw new Error(`AR is not supported on this device`);
297}
298export function getARMatrices(near, far) {
299 if (ExponentAR.getARMatrices) {
300 return ExponentAR.getARMatrices(near, far);
301 }
302 throw new Error(`AR is not supported on this device`);
303}
304export async function stopAsync() {
305 if (ExponentAR.stopAsync) {
306 await ExponentAR.stopAsync();
307 }
308}
309export async function startAsync(node, configuration) {
310 let handle = typeof node === 'number' ? node : _getNodeHandle(node);
311 if (ExponentAR.startAsync) {
312 return await ExponentAR.startAsync(handle, configuration);
313 }
314 throw new Error(`AR is not supported on this device`);
315}
316function _getNodeHandle(component) {
317 let handle = findNodeHandle(component);
318 if (handle === null) {
319 throw new Error(`Could not find the React node handle for the AR component: ${component}`);
320 }
321 return handle;
322}
323export function reset() {
324 if (ExponentAR.reset) {
325 ExponentAR.reset();
326 }
327}
328export function resume() {
329 if (ExponentAR.resume) {
330 ExponentAR.resume();
331 }
332}
333export function pause() {
334 if (ExponentAR.pause) {
335 ExponentAR.pause();
336 }
337}
338export async function setConfigurationAsync(configuration) {
339 if (ExponentAR.setConfigurationAsync) {
340 await ExponentAR.setConfigurationAsync(configuration);
341 }
342}
343export function getProvidesAudioData() {
344 if (ExponentAR.getProvidesAudioData) {
345 return ExponentAR.getProvidesAudioData();
346 }
347 return false;
348}
349export function setProvidesAudioData(providesAudioData) {
350 if (ExponentAR.setProvidesAudioData) {
351 ExponentAR.setProvidesAudioData(providesAudioData);
352 }
353}
354export function setPlaneDetection(planeDetection) {
355 if (ExponentAR.setPlaneDetection) {
356 ExponentAR.setPlaneDetection(planeDetection);
357 }
358}
359export function getPlaneDetection() {
360 if (ExponentAR.getPlaneDetection) {
361 return ExponentAR.getPlaneDetection();
362 }
363 throw new Error(`AR plane detection is not supported on this device`);
364}
365export function getCameraTexture() {
366 if (ExponentAR.getCameraTexture) {
367 return ExponentAR.getCameraTexture();
368 }
369 throw new Error(`AR camera textures are not supported on this device`);
370}
371export async function setWorldOriginAsync(matrix_float4x4) {
372 if (ExponentAR.setWorldOriginAsync) {
373 await ExponentAR.setWorldOriginAsync(matrix_float4x4);
374 }
375}
376export function setLightEstimationEnabled(isLightEstimationEnabled) {
377 if (ExponentAR.setLightEstimationEnabled) {
378 ExponentAR.setLightEstimationEnabled(isLightEstimationEnabled);
379 }
380}
381export function getLightEstimationEnabled() {
382 if (ExponentAR.getLightEstimationEnabled) {
383 return ExponentAR.getLightEstimationEnabled();
384 }
385 return false;
386}
387export function setAutoFocusEnabled(isAutoFocusEnabled) {
388 if (ExponentAR.setAutoFocusEnabled) {
389 ExponentAR.setAutoFocusEnabled(isAutoFocusEnabled);
390 }
391}
392export function getAutoFocusEnabled() {
393 if (ExponentAR.getAutoFocusEnabled) {
394 return ExponentAR.getAutoFocusEnabled();
395 }
396 return false;
397}
398export function setWorldAlignment(worldAlignment) {
399 if (ExponentAR.setWorldAlignment) {
400 ExponentAR.setWorldAlignment(worldAlignment);
401 }
402}
403export function getWorldAlignment() {
404 if (ExponentAR.getWorldAlignment) {
405 return ExponentAR.getWorldAlignment();
406 }
407 throw new Error(`AR world alignment is not supported on this device`);
408}
409export function isConfigurationAvailable(configuration) {
410 const { width, height } = Dimensions.get('window');
411 // @ts-ignore: re-evaluate this for the new iPhones (2018)
412 const isX = (width === 812 || height === 812) && !Platform.isTVOS && !Platform.isPad;
413 if (configuration === TrackingConfiguration.Face && isX && isAvailable()) {
414 return true;
415 }
416 return !!ExponentAR[configuration];
417}
418export function getSupportedVideoFormats(configuration) {
419 const videoFormats = {
420 [TrackingConfiguration.World]: 'WorldTrackingVideoFormats',
421 [TrackingConfiguration.Orientation]: 'OrientationTrackingVideoFormats',
422 [TrackingConfiguration.Face]: 'FaceTrackingVideoFormats',
423 };
424 const videoFormat = videoFormats[configuration];
425 return ExponentAR[videoFormat] || [];
426}
427export function isFrontCameraAvailable() {
428 return isConfigurationAvailable(TrackingConfiguration.Face);
429}
430export function isRearCameraAvailable() {
431 return isConfigurationAvailable(TrackingConfiguration.World);
432}
433//# sourceMappingURL=AR.js.map
\No newline at end of file