@react-three/fiber 8.15.3 → 8.15.5
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/CHANGELOG.md +12 -0
- package/dist/declarations/src/core/events.d.ts +22 -0
- package/dist/declarations/src/core/hooks.d.ts +25 -0
- package/dist/declarations/src/core/index.d.ts +30 -0
- package/dist/declarations/src/core/loop.d.ts +20 -0
- package/dist/declarations/src/core/store.d.ts +43 -1
- package/dist/declarations/src/core/utils.d.ts +24 -0
- package/dist/declarations/src/native/Canvas.d.ts +4 -0
- package/dist/declarations/src/native/events.d.ts +1 -0
- package/dist/declarations/src/three-types.d.ts +68 -10
- package/dist/declarations/src/web/Canvas.d.ts +11 -0
- package/dist/declarations/src/web/events.d.ts +1 -0
- package/native/dist/react-three-fiber-native.cjs.dev.js +80 -123
- package/native/dist/react-three-fiber-native.cjs.prod.js +80 -123
- package/native/dist/react-three-fiber-native.esm.js +80 -123
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @react-three/fiber
|
|
2
2
|
|
|
3
|
+
## 8.15.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0e44fd8b: fix(types): preserve deprecated JSX annotations
|
|
8
|
+
|
|
9
|
+
## 8.15.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 634e5db5: fix(native): harden Blob URI check for Android
|
|
14
|
+
|
|
3
15
|
## 8.15.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -3,18 +3,29 @@ import type { UseBoundStore } from 'zustand';
|
|
|
3
3
|
import type { RootState } from './store';
|
|
4
4
|
import type { Properties } from '../three-types';
|
|
5
5
|
export interface Intersection extends THREE.Intersection {
|
|
6
|
+
/** The event source (the object which registered the handler) */
|
|
6
7
|
eventObject: THREE.Object3D;
|
|
7
8
|
}
|
|
8
9
|
export interface IntersectionEvent<TSourceEvent> extends Intersection {
|
|
10
|
+
/** The event source (the object which registered the handler) */
|
|
9
11
|
eventObject: THREE.Object3D;
|
|
12
|
+
/** An array of intersections */
|
|
10
13
|
intersections: Intersection[];
|
|
14
|
+
/** vec3.set(pointer.x, pointer.y, 0).unproject(camera) */
|
|
11
15
|
unprojectedPoint: THREE.Vector3;
|
|
16
|
+
/** Normalized event coordinates */
|
|
12
17
|
pointer: THREE.Vector2;
|
|
18
|
+
/** Delta between first click and this event */
|
|
13
19
|
delta: number;
|
|
20
|
+
/** The ray that pierced it */
|
|
14
21
|
ray: THREE.Ray;
|
|
22
|
+
/** The camera that was used by the raycaster */
|
|
15
23
|
camera: Camera;
|
|
24
|
+
/** stopPropagation will stop underlying handlers from firing */
|
|
16
25
|
stopPropagation: () => void;
|
|
26
|
+
/** The original host event */
|
|
17
27
|
nativeEvent: TSourceEvent;
|
|
28
|
+
/** If the event was stopped by calling stopPropagation */
|
|
18
29
|
stopped: boolean;
|
|
19
30
|
}
|
|
20
31
|
export declare type Camera = THREE.OrthographicCamera | THREE.PerspectiveCamera;
|
|
@@ -50,14 +61,25 @@ export declare type EventHandlers = {
|
|
|
50
61
|
export declare type FilterFunction = (items: THREE.Intersection[], state: RootState) => THREE.Intersection[];
|
|
51
62
|
export declare type ComputeFunction = (event: DomEvent, root: RootState, previous?: RootState) => void;
|
|
52
63
|
export interface EventManager<TTarget> {
|
|
64
|
+
/** Determines if the event layer is active */
|
|
53
65
|
enabled: boolean;
|
|
66
|
+
/** Event layer priority, higher prioritized layers come first and may stop(-propagate) lower layer */
|
|
54
67
|
priority: number;
|
|
68
|
+
/** The compute function needs to set up the raycaster and an xy- pointer */
|
|
55
69
|
compute?: ComputeFunction;
|
|
70
|
+
/** The filter can re-order or re-structure the intersections */
|
|
56
71
|
filter?: FilterFunction;
|
|
72
|
+
/** The target node the event layer is tied to */
|
|
57
73
|
connected?: TTarget;
|
|
74
|
+
/** All the pointer event handlers through which the host forwards native events */
|
|
58
75
|
handlers?: Events;
|
|
76
|
+
/** Allows re-connecting to another target */
|
|
59
77
|
connect?: (target: TTarget) => void;
|
|
78
|
+
/** Removes all existing events handlers from the target */
|
|
60
79
|
disconnect?: () => void;
|
|
80
|
+
/** Triggers a onPointerMove with the last known event. This can be useful to enable raycasting without
|
|
81
|
+
* explicit user interaction, for instance when the camera moves a hoverable object underneath the cursor.
|
|
82
|
+
*/
|
|
61
83
|
update?: () => void;
|
|
62
84
|
}
|
|
63
85
|
export interface PointerCaptureTarget {
|
|
@@ -17,11 +17,36 @@ export declare type Extensions<T extends {
|
|
|
17
17
|
}> = (loader: T['prototype']) => void;
|
|
18
18
|
export declare type ConditionalType<Child, Parent, Truthy, Falsy> = Child extends Parent ? Truthy : Falsy;
|
|
19
19
|
export declare type BranchingReturn<T, Parent, Coerced> = ConditionalType<T, Parent, Coerced, T>;
|
|
20
|
+
/**
|
|
21
|
+
* Exposes an object's {@link LocalState}.
|
|
22
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#useInstanceHandle
|
|
23
|
+
*
|
|
24
|
+
* **Note**: this is an escape hatch to react-internal fields. Expect this to change significantly between versions.
|
|
25
|
+
*/
|
|
20
26
|
export declare function useInstanceHandle<O>(ref: React.MutableRefObject<O>): React.MutableRefObject<LocalState>;
|
|
21
27
|
export declare function useStore(): import("zustand").UseBoundStore<RootState, import("zustand").StoreApi<RootState>>;
|
|
28
|
+
/**
|
|
29
|
+
* Accesses R3F's internal state, containing renderer, canvas, scene, etc.
|
|
30
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usethree
|
|
31
|
+
*/
|
|
22
32
|
export declare function useThree<T = RootState>(selector?: StateSelector<RootState, T>, equalityFn?: EqualityChecker<T>): T;
|
|
33
|
+
/**
|
|
34
|
+
* Executes a callback before render in a shared frame loop.
|
|
35
|
+
* Can order effects with render priority or manually render with a positive priority.
|
|
36
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useframe
|
|
37
|
+
*/
|
|
23
38
|
export declare function useFrame(callback: RenderCallback, renderPriority?: number): null;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a node graph of an object with named nodes & materials.
|
|
41
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#usegraph
|
|
42
|
+
*/
|
|
24
43
|
export declare function useGraph(object: THREE.Object3D): ObjectMap;
|
|
44
|
+
/**
|
|
45
|
+
* Synchronously loads and caches assets with a three loader.
|
|
46
|
+
*
|
|
47
|
+
* Note: this hook's caller must be wrapped with `React.Suspense`
|
|
48
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/hooks#useloader
|
|
49
|
+
*/
|
|
25
50
|
export declare function useLoader<T, U extends string | string[], L extends LoaderProto<T>, R = LoaderReturnType<T, L>>(Proto: L, input: U, extensions?: Extensions<L>, onProgress?: (event: ProgressEvent<EventTarget>) => void): U extends any[] ? BranchingReturn<R, GLTF, GLTF & ObjectMap>[] : BranchingReturn<R, GLTF, GLTF & ObjectMap>;
|
|
26
51
|
export declare namespace useLoader {
|
|
27
52
|
var preload: <T, U extends string | string[], L extends LoaderProto<T>>(Proto: L, input: U, extensions?: Extensions<L> | undefined) => undefined;
|
|
@@ -15,23 +15,53 @@ declare const invalidate: (state?: RootState | undefined, frames?: number) => vo
|
|
|
15
15
|
declare const reconciler: import("react-reconciler").Reconciler<UseBoundStore<RootState, import("zustand").StoreApi<RootState>>, import("./renderer").Instance, void, import("./renderer").Instance, import("./renderer").Instance>, applyProps: typeof import("./utils").applyProps;
|
|
16
16
|
declare type GLProps = Renderer | ((canvas: Canvas) => Renderer) | Partial<Properties<THREE.WebGLRenderer> | THREE.WebGLRendererParameters> | undefined;
|
|
17
17
|
export declare type RenderProps<TCanvas extends Canvas> = {
|
|
18
|
+
/** A threejs renderer instance or props that go into the default renderer */
|
|
18
19
|
gl?: GLProps;
|
|
20
|
+
/** Dimensions to fit the renderer to. Will measure canvas dimensions if omitted */
|
|
19
21
|
size?: Size;
|
|
22
|
+
/**
|
|
23
|
+
* Enables shadows (by default PCFsoft). Can accept `gl.shadowMap` options for fine-tuning,
|
|
24
|
+
* but also strings: 'basic' | 'percentage' | 'soft' | 'variance'.
|
|
25
|
+
* @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.shadowMap
|
|
26
|
+
*/
|
|
20
27
|
shadows?: boolean | 'basic' | 'percentage' | 'soft' | 'variance' | Partial<THREE.WebGLShadowMap>;
|
|
28
|
+
/**
|
|
29
|
+
* Disables three r139 color management.
|
|
30
|
+
* @see https://threejs.org/docs/#manual/en/introduction/Color-management
|
|
31
|
+
*/
|
|
21
32
|
legacy?: boolean;
|
|
33
|
+
/** Switch off automatic sRGB color space and gamma correction */
|
|
22
34
|
linear?: boolean;
|
|
35
|
+
/** Use `THREE.NoToneMapping` instead of `THREE.ACESFilmicToneMapping` */
|
|
23
36
|
flat?: boolean;
|
|
37
|
+
/** Creates an orthographic camera */
|
|
24
38
|
orthographic?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* R3F's render mode. Set to `demand` to only render on state change or `never` to take control.
|
|
41
|
+
* @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#on-demand-rendering
|
|
42
|
+
*/
|
|
25
43
|
frameloop?: 'always' | 'demand' | 'never';
|
|
44
|
+
/**
|
|
45
|
+
* R3F performance options for adaptive performance.
|
|
46
|
+
* @see https://docs.pmnd.rs/react-three-fiber/advanced/scaling-performance#movement-regression
|
|
47
|
+
*/
|
|
26
48
|
performance?: Partial<Omit<Performance, 'regress'>>;
|
|
49
|
+
/** Target pixel ratio. Can clamp between a range: `[min, max]` */
|
|
27
50
|
dpr?: Dpr;
|
|
51
|
+
/** Props that go into the default raycaster */
|
|
28
52
|
raycaster?: Partial<THREE.Raycaster>;
|
|
53
|
+
/** A `THREE.Scene` instance or props that go into the default scene */
|
|
29
54
|
scene?: THREE.Scene | Partial<ReactThreeFiber.Object3DNode<THREE.Scene, typeof THREE.Scene>>;
|
|
55
|
+
/** A `THREE.Camera` instance or props that go into the default camera */
|
|
30
56
|
camera?: (Camera | Partial<ReactThreeFiber.Object3DNode<THREE.Camera, typeof THREE.Camera> & ReactThreeFiber.Object3DNode<THREE.PerspectiveCamera, typeof THREE.PerspectiveCamera> & ReactThreeFiber.Object3DNode<THREE.OrthographicCamera, typeof THREE.OrthographicCamera>>) & {
|
|
57
|
+
/** Flags the camera as manual, putting projection into your own hands */
|
|
31
58
|
manual?: boolean;
|
|
32
59
|
};
|
|
60
|
+
/** An R3F event manager to manage elements' pointer events */
|
|
33
61
|
events?: (store: UseBoundStore<RootState>) => EventManager<HTMLElement>;
|
|
62
|
+
/** Callback after the canvas has rendered (but not yet committed) */
|
|
34
63
|
onCreated?: (state: RootState) => void;
|
|
64
|
+
/** Response for pointer clicks that have missed any target */
|
|
35
65
|
onPointerMissed?: (event: MouseEvent) => void;
|
|
36
66
|
};
|
|
37
67
|
export declare type ReconcilerRoot<TCanvas extends Canvas> = {
|
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
import { Root } from './renderer';
|
|
2
2
|
import { RootState } from './store';
|
|
3
3
|
export declare type GlobalRenderCallback = (timeStamp: number) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Adds a global render callback which is called each frame.
|
|
6
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addEffect
|
|
7
|
+
*/
|
|
4
8
|
export declare const addEffect: (callback: GlobalRenderCallback) => () => void;
|
|
9
|
+
/**
|
|
10
|
+
* Adds a global after-render callback which is called each frame.
|
|
11
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addAfterEffect
|
|
12
|
+
*/
|
|
5
13
|
export declare const addAfterEffect: (callback: GlobalRenderCallback) => () => void;
|
|
14
|
+
/**
|
|
15
|
+
* Adds a global callback which is called when rendering stops.
|
|
16
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#addTail
|
|
17
|
+
*/
|
|
6
18
|
export declare const addTail: (callback: GlobalRenderCallback) => () => void;
|
|
7
19
|
export declare type GlobalEffectType = 'before' | 'after' | 'tail';
|
|
8
20
|
export declare function flushGlobalEffects(type: GlobalEffectType, timestamp: number): void;
|
|
9
21
|
export declare function createLoop<TCanvas>(roots: Map<TCanvas, Root>): {
|
|
10
22
|
loop: (timestamp: number) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Invalidates the view, requesting a frame to be rendered. Will globally invalidate unless passed a root's state.
|
|
25
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#invalidate
|
|
26
|
+
*/
|
|
11
27
|
invalidate: (state?: RootState | undefined, frames?: number) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Advances the frameloop and runs render effects, useful for when manually rendering via `frameloop="never"`.
|
|
30
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/additional-exports#advance
|
|
31
|
+
*/
|
|
12
32
|
advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState | undefined, frame?: import("three").XRFrame | undefined) => void;
|
|
13
33
|
};
|
|
@@ -19,21 +19,32 @@ export declare type Size = {
|
|
|
19
19
|
height: number;
|
|
20
20
|
top: number;
|
|
21
21
|
left: number;
|
|
22
|
+
/** @deprecated `updateStyle` is now disabled for OffscreenCanvas and will be removed in v9. */
|
|
22
23
|
updateStyle?: boolean;
|
|
23
24
|
};
|
|
24
25
|
export declare type Viewport = Size & {
|
|
26
|
+
/** The initial pixel ratio */
|
|
25
27
|
initialDpr: number;
|
|
28
|
+
/** Current pixel ratio */
|
|
26
29
|
dpr: number;
|
|
30
|
+
/** size.width / viewport.width */
|
|
27
31
|
factor: number;
|
|
32
|
+
/** Camera distance */
|
|
28
33
|
distance: number;
|
|
34
|
+
/** Camera aspect ratio: width / height */
|
|
29
35
|
aspect: number;
|
|
30
36
|
};
|
|
31
37
|
export declare type RenderCallback = (state: RootState, delta: number, frame?: _XRFrame) => void;
|
|
32
38
|
export declare type Performance = {
|
|
39
|
+
/** Current performance normal, between min and max */
|
|
33
40
|
current: number;
|
|
41
|
+
/** How low the performance can go, between 0 and max */
|
|
34
42
|
min: number;
|
|
43
|
+
/** How high the performance can go, between min and max */
|
|
35
44
|
max: number;
|
|
45
|
+
/** Time until current returns to max in ms */
|
|
36
46
|
debounce: number;
|
|
47
|
+
/** Sets current to min, puts the system in regression */
|
|
37
48
|
regress: () => void;
|
|
38
49
|
};
|
|
39
50
|
export declare type Renderer = {
|
|
@@ -54,40 +65,71 @@ export declare type InternalState = {
|
|
|
54
65
|
subscribe: (callback: React.MutableRefObject<RenderCallback>, priority: number, store: UseBoundStore<RootState, StoreApi<RootState>>) => () => void;
|
|
55
66
|
};
|
|
56
67
|
export declare type RootState = {
|
|
68
|
+
/** Set current state */
|
|
57
69
|
set: SetState<RootState>;
|
|
70
|
+
/** Get current state */
|
|
58
71
|
get: GetState<RootState>;
|
|
72
|
+
/** The instance of the renderer */
|
|
59
73
|
gl: THREE.WebGLRenderer;
|
|
74
|
+
/** Default camera */
|
|
60
75
|
camera: Camera & {
|
|
61
76
|
manual?: boolean;
|
|
62
77
|
};
|
|
78
|
+
/** Default scene */
|
|
63
79
|
scene: THREE.Scene;
|
|
80
|
+
/** Default raycaster */
|
|
64
81
|
raycaster: THREE.Raycaster;
|
|
82
|
+
/** Default clock */
|
|
65
83
|
clock: THREE.Clock;
|
|
84
|
+
/** Event layer interface, contains the event handler and the node they're connected to */
|
|
66
85
|
events: EventManager<any>;
|
|
86
|
+
/** XR interface */
|
|
67
87
|
xr: {
|
|
68
88
|
connect: () => void;
|
|
69
89
|
disconnect: () => void;
|
|
70
90
|
};
|
|
91
|
+
/** Currently used controls */
|
|
71
92
|
controls: THREE.EventDispatcher | null;
|
|
93
|
+
/** Normalized event coordinates */
|
|
72
94
|
pointer: THREE.Vector2;
|
|
95
|
+
/** @deprecated Normalized event coordinates, use "pointer" instead! */
|
|
73
96
|
mouse: THREE.Vector2;
|
|
74
97
|
legacy: boolean;
|
|
98
|
+
/** Shortcut to gl.outputColorSpace = THREE.LinearSRGBColorSpace */
|
|
75
99
|
linear: boolean;
|
|
100
|
+
/** Shortcut to gl.toneMapping = NoTonemapping */
|
|
76
101
|
flat: boolean;
|
|
102
|
+
/** Render loop flags */
|
|
77
103
|
frameloop: 'always' | 'demand' | 'never';
|
|
104
|
+
/** Adaptive performance interface */
|
|
78
105
|
performance: Performance;
|
|
106
|
+
/** Reactive pixel-size of the canvas */
|
|
79
107
|
size: Size;
|
|
108
|
+
/** Reactive size of the viewport in threejs units */
|
|
80
109
|
viewport: Viewport & {
|
|
81
110
|
getCurrentViewport: (camera?: Camera, target?: THREE.Vector3 | Parameters<THREE.Vector3['set']>, size?: Size) => Omit<Viewport, 'dpr' | 'initialDpr'>;
|
|
82
111
|
};
|
|
112
|
+
/** Flags the canvas for render, but doesn't render in itself */
|
|
83
113
|
invalidate: (frames?: number) => void;
|
|
114
|
+
/** Advance (render) one step */
|
|
84
115
|
advance: (timestamp: number, runGlobalEffects?: boolean) => void;
|
|
116
|
+
/** Shortcut to setting the event layer */
|
|
85
117
|
setEvents: (events: Partial<EventManager<any>>) => void;
|
|
86
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Shortcut to manual sizing
|
|
120
|
+
*/
|
|
121
|
+
setSize: (width: number, height: number,
|
|
122
|
+
/** @deprecated `updateStyle` is now disabled for OffscreenCanvas and will be removed in v9. */
|
|
123
|
+
updateStyle?: boolean, top?: number, left?: number) => void;
|
|
124
|
+
/** Shortcut to manual setting the pixel ratio */
|
|
87
125
|
setDpr: (dpr: Dpr) => void;
|
|
126
|
+
/** Shortcut to frameloop flags */
|
|
88
127
|
setFrameloop: (frameloop?: 'always' | 'demand' | 'never') => void;
|
|
128
|
+
/** When the canvas was clicked but nothing was hit */
|
|
89
129
|
onPointerMissed?: (event: MouseEvent) => void;
|
|
130
|
+
/** If this state model is layerd (via createPortal) then this contains the previous layer */
|
|
90
131
|
previousRoot?: UseBoundStore<RootState, StoreApi<RootState>>;
|
|
132
|
+
/** Internals */
|
|
91
133
|
internal: InternalState;
|
|
92
134
|
};
|
|
93
135
|
declare const context: React.Context<UseBoundStore<RootState, StoreApi<RootState>>>;
|
|
@@ -7,6 +7,9 @@ declare type _DeprecatedXRFrame = THREE.XRFrame;
|
|
|
7
7
|
export declare type _XRFrame = THREE.WebGLRenderTargetOptions extends {
|
|
8
8
|
samples?: number;
|
|
9
9
|
} ? XRFrame : _DeprecatedXRFrame;
|
|
10
|
+
/**
|
|
11
|
+
* Returns `true` with correct TS type inference if an object has a configurable color space (since r152).
|
|
12
|
+
*/
|
|
10
13
|
export declare const hasColorSpace: <T extends object | Renderer | THREE.Texture, P = T extends Renderer ? {
|
|
11
14
|
outputColorSpace: string;
|
|
12
15
|
} : {
|
|
@@ -17,10 +20,22 @@ export declare type ColorManagementRepresentation = {
|
|
|
17
20
|
} | {
|
|
18
21
|
legacyMode: boolean | never;
|
|
19
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* The current THREE.ColorManagement instance, if present.
|
|
25
|
+
*/
|
|
20
26
|
export declare const getColorManagement: () => ColorManagementRepresentation | null;
|
|
21
27
|
export declare type Camera = THREE.OrthographicCamera | THREE.PerspectiveCamera;
|
|
22
28
|
export declare const isOrthographicCamera: (def: Camera) => def is THREE.OrthographicCamera;
|
|
23
29
|
export declare const isRef: (obj: any) => obj is React.MutableRefObject<unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* An SSR-friendly useLayoutEffect.
|
|
32
|
+
*
|
|
33
|
+
* React currently throws a warning when using useLayoutEffect on the server.
|
|
34
|
+
* To get around it, we can conditionally useEffect on the server (no-op) and
|
|
35
|
+
* useLayoutEffect elsewhere.
|
|
36
|
+
*
|
|
37
|
+
* @see https://github.com/facebook/react/issues/14927
|
|
38
|
+
*/
|
|
24
39
|
export declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
|
|
25
40
|
export declare function useMutableCallback<T>(fn: T): React.MutableRefObject<T>;
|
|
26
41
|
export declare type SetBlock = false | Promise<null> | null;
|
|
@@ -65,10 +80,16 @@ export declare type ObjectMap = {
|
|
|
65
80
|
};
|
|
66
81
|
};
|
|
67
82
|
export declare function calculateDpr(dpr: Dpr): number;
|
|
83
|
+
/**
|
|
84
|
+
* Returns instance root state
|
|
85
|
+
*/
|
|
68
86
|
export declare const getRootState: (obj: THREE.Object3D) => RootState | undefined;
|
|
69
87
|
export declare type EquConfig = {
|
|
88
|
+
/** Compare arrays by reference equality a === b (default), or by shallow equality */
|
|
70
89
|
arrays?: 'reference' | 'shallow';
|
|
90
|
+
/** Compare objects by reference equality a === b (default), or by shallow equality */
|
|
71
91
|
objects?: 'reference' | 'shallow';
|
|
92
|
+
/** If true the keys in both a and b must match 1:1 (default), if false a's keys must intersect b's */
|
|
72
93
|
strict?: boolean;
|
|
73
94
|
};
|
|
74
95
|
export declare const is: {
|
|
@@ -81,6 +102,9 @@ export declare const is: {
|
|
|
81
102
|
arr: (a: any) => boolean;
|
|
82
103
|
equ(a: any, b: any, { arrays, objects, strict }?: EquConfig): boolean;
|
|
83
104
|
};
|
|
105
|
+
/**
|
|
106
|
+
* Collects nodes and materials from a THREE.Object3D.
|
|
107
|
+
*/
|
|
84
108
|
export declare function buildGraph(object: THREE.Object3D): ObjectMap;
|
|
85
109
|
export declare function dispose<TObj extends {
|
|
86
110
|
dispose?: () => void;
|
|
@@ -7,4 +7,8 @@ export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'size'
|
|
|
7
7
|
}
|
|
8
8
|
export interface Props extends CanvasProps {
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* A native canvas which accepts threejs elements as children.
|
|
12
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
13
|
+
*/
|
|
10
14
|
export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<View>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UseBoundStore } from 'zustand';
|
|
2
2
|
import { RootState } from '../core/store';
|
|
3
3
|
import { EventManager } from '../core/events';
|
|
4
|
+
/** Default R3F event manager for react-native */
|
|
4
5
|
export declare function createTouchEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
|
|
@@ -8,9 +8,15 @@ export declare type NonFunctionKeys<T> = {
|
|
|
8
8
|
[K in keyof T]-?: T[K] extends Function ? never : K;
|
|
9
9
|
}[keyof T];
|
|
10
10
|
export declare type Overwrite<T, O> = Omit<T, NonFunctionKeys<O>> & O;
|
|
11
|
+
/**
|
|
12
|
+
* If **T** contains a constructor, @see ConstructorParameters must be used, otherwise **T**.
|
|
13
|
+
*/
|
|
11
14
|
declare type Args<T> = T extends new (...args: any) => any ? ConstructorParameters<T> : T;
|
|
12
15
|
export declare type Euler = THREE.Euler | Parameters<THREE.Euler['set']>;
|
|
13
16
|
export declare type Matrix4 = THREE.Matrix4 | Parameters<THREE.Matrix4['set']> | Readonly<THREE.Matrix4['set']>;
|
|
17
|
+
/**
|
|
18
|
+
* Turn an implementation of THREE.Vector in to the type that an r3f component would accept as a prop.
|
|
19
|
+
*/
|
|
14
20
|
declare type VectorLike<VectorClass extends THREE.Vector> = VectorClass | Parameters<VectorClass['set']> | Readonly<Parameters<VectorClass['set']>> | Parameters<VectorClass['setScalar']>[0];
|
|
15
21
|
export declare type Vector2 = VectorLike<THREE.Vector2>;
|
|
16
22
|
export declare type Vector3 = VectorLike<THREE.Vector3>;
|
|
@@ -22,6 +28,7 @@ export declare type Quaternion = THREE.Quaternion | Parameters<THREE.Quaternion[
|
|
|
22
28
|
export declare type AttachCallback = string | ((child: any, parentInstance: any) => void);
|
|
23
29
|
export interface NodeProps<T, P> {
|
|
24
30
|
attach?: AttachType;
|
|
31
|
+
/** Constructor arguments */
|
|
25
32
|
args?: Args<P>;
|
|
26
33
|
children?: React.ReactNode;
|
|
27
34
|
ref?: React.Ref<T>;
|
|
@@ -67,23 +74,71 @@ export declare type CubeCameraProps = Object3DNode<THREE.CubeCamera, typeof THRE
|
|
|
67
74
|
export declare type ArrayCameraProps = Object3DNode<THREE.ArrayCamera, typeof THREE.ArrayCamera>;
|
|
68
75
|
export declare type InstancedBufferGeometryProps = BufferGeometryNode<THREE.InstancedBufferGeometry, typeof THREE.InstancedBufferGeometry>;
|
|
69
76
|
export declare type BufferGeometryProps = BufferGeometryNode<THREE.BufferGeometry, typeof THREE.BufferGeometry>;
|
|
77
|
+
/** @ts-ignore */
|
|
70
78
|
export declare type BoxBufferGeometryProps = BufferGeometryNode<THREE.BoxBufferGeometry, typeof THREE.BoxBufferGeometry>;
|
|
71
|
-
export declare type CircleBufferGeometryProps = BufferGeometryNode<
|
|
79
|
+
export declare type CircleBufferGeometryProps = BufferGeometryNode<
|
|
80
|
+
/** @ts-ignore */
|
|
81
|
+
THREE.CircleBufferGeometry,
|
|
82
|
+
/** @ts-ignore */
|
|
83
|
+
typeof THREE.CircleBufferGeometry>;
|
|
84
|
+
/** @ts-ignore */
|
|
72
85
|
export declare type ConeBufferGeometryProps = BufferGeometryNode<THREE.ConeBufferGeometry, typeof THREE.ConeBufferGeometry>;
|
|
73
|
-
export declare type CylinderBufferGeometryProps = BufferGeometryNode<
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
86
|
+
export declare type CylinderBufferGeometryProps = BufferGeometryNode<
|
|
87
|
+
/** @ts-ignore */
|
|
88
|
+
THREE.CylinderBufferGeometry,
|
|
89
|
+
/** @ts-ignore */
|
|
90
|
+
typeof THREE.CylinderBufferGeometry>;
|
|
91
|
+
export declare type DodecahedronBufferGeometryProps = BufferGeometryNode<
|
|
92
|
+
/** @ts-ignore */
|
|
93
|
+
THREE.DodecahedronBufferGeometry,
|
|
94
|
+
/** @ts-ignore */
|
|
95
|
+
typeof THREE.DodecahedronBufferGeometry>;
|
|
96
|
+
export declare type ExtrudeBufferGeometryProps = BufferGeometryNode<
|
|
97
|
+
/** @ts-ignore */
|
|
98
|
+
THREE.ExtrudeBufferGeometry,
|
|
99
|
+
/** @ts-ignore */
|
|
100
|
+
typeof THREE.ExtrudeBufferGeometry>;
|
|
101
|
+
export declare type IcosahedronBufferGeometryProps = BufferGeometryNode<
|
|
102
|
+
/** @ts-ignore */
|
|
103
|
+
THREE.IcosahedronBufferGeometry,
|
|
104
|
+
/** @ts-ignore */
|
|
105
|
+
typeof THREE.IcosahedronBufferGeometry>;
|
|
106
|
+
/** @ts-ignore */
|
|
77
107
|
export declare type LatheBufferGeometryProps = BufferGeometryNode<THREE.LatheBufferGeometry, typeof THREE.LatheBufferGeometry>;
|
|
78
|
-
export declare type OctahedronBufferGeometryProps = BufferGeometryNode<
|
|
108
|
+
export declare type OctahedronBufferGeometryProps = BufferGeometryNode<
|
|
109
|
+
/** @ts-ignore */
|
|
110
|
+
THREE.OctahedronBufferGeometry,
|
|
111
|
+
/** @ts-ignore */
|
|
112
|
+
typeof THREE.OctahedronBufferGeometry>;
|
|
113
|
+
/** @ts-ignore */
|
|
79
114
|
export declare type PlaneBufferGeometryProps = BufferGeometryNode<THREE.PlaneBufferGeometry, typeof THREE.PlaneBufferGeometry>;
|
|
80
|
-
export declare type PolyhedronBufferGeometryProps = BufferGeometryNode<
|
|
115
|
+
export declare type PolyhedronBufferGeometryProps = BufferGeometryNode<
|
|
116
|
+
/** @ts-ignore */
|
|
117
|
+
THREE.PolyhedronBufferGeometry,
|
|
118
|
+
/** @ts-ignore */
|
|
119
|
+
typeof THREE.PolyhedronBufferGeometry>;
|
|
120
|
+
/** @ts-ignore */
|
|
81
121
|
export declare type RingBufferGeometryProps = BufferGeometryNode<THREE.RingBufferGeometry, typeof THREE.RingBufferGeometry>;
|
|
122
|
+
/** @ts-ignore */
|
|
82
123
|
export declare type ShapeBufferGeometryProps = BufferGeometryNode<THREE.ShapeBufferGeometry, typeof THREE.ShapeBufferGeometry>;
|
|
83
|
-
export declare type SphereBufferGeometryProps = BufferGeometryNode<
|
|
84
|
-
|
|
124
|
+
export declare type SphereBufferGeometryProps = BufferGeometryNode<
|
|
125
|
+
/** @ts-ignore */
|
|
126
|
+
THREE.SphereBufferGeometry,
|
|
127
|
+
/** @ts-ignore */
|
|
128
|
+
typeof THREE.SphereBufferGeometry>;
|
|
129
|
+
export declare type TetrahedronBufferGeometryProps = BufferGeometryNode<
|
|
130
|
+
/** @ts-ignore */
|
|
131
|
+
THREE.TetrahedronBufferGeometry,
|
|
132
|
+
/** @ts-ignore */
|
|
133
|
+
typeof THREE.TetrahedronBufferGeometry>;
|
|
134
|
+
/** @ts-ignore */
|
|
85
135
|
export declare type TorusBufferGeometryProps = BufferGeometryNode<THREE.TorusBufferGeometry, typeof THREE.TorusBufferGeometry>;
|
|
86
|
-
export declare type TorusKnotBufferGeometryProps = BufferGeometryNode<
|
|
136
|
+
export declare type TorusKnotBufferGeometryProps = BufferGeometryNode<
|
|
137
|
+
/** @ts-ignore */
|
|
138
|
+
THREE.TorusKnotBufferGeometry,
|
|
139
|
+
/** @ts-ignore */
|
|
140
|
+
typeof THREE.TorusKnotBufferGeometry>;
|
|
141
|
+
/** @ts-ignore */
|
|
87
142
|
export declare type TubeBufferGeometryProps = BufferGeometryNode<THREE.TubeBufferGeometry, typeof THREE.TubeBufferGeometry>;
|
|
88
143
|
export declare type WireframeGeometryProps = BufferGeometryNode<THREE.WireframeGeometry, typeof THREE.WireframeGeometry>;
|
|
89
144
|
export declare type TetrahedronGeometryProps = BufferGeometryNode<THREE.TetrahedronGeometry, typeof THREE.TetrahedronGeometry>;
|
|
@@ -139,7 +194,9 @@ export declare type DirectionalLightShadowProps = Node<THREE.DirectionalLightSha
|
|
|
139
194
|
export declare type DirectionalLightProps = LightNode<THREE.DirectionalLight, typeof THREE.DirectionalLight>;
|
|
140
195
|
export declare type AmbientLightProps = LightNode<THREE.AmbientLight, typeof THREE.AmbientLight>;
|
|
141
196
|
export declare type LightShadowProps = Node<THREE.LightShadow, typeof THREE.LightShadow>;
|
|
197
|
+
/** @ts-ignore */
|
|
142
198
|
export declare type AmbientLightProbeProps = LightNode<THREE.AmbientLightProbe, typeof THREE.AmbientLightProbe>;
|
|
199
|
+
/** @ts-ignore */
|
|
143
200
|
export declare type HemisphereLightProbeProps = LightNode<THREE.HemisphereLightProbe, typeof THREE.HemisphereLightProbe>;
|
|
144
201
|
export declare type LightProbeProps = LightNode<THREE.LightProbe, typeof THREE.LightProbe>;
|
|
145
202
|
export declare type SpotLightHelperProps = Object3DNode<THREE.SpotLightHelper, typeof THREE.SpotLightHelper>;
|
|
@@ -158,6 +215,7 @@ export declare type AxesHelperProps = Object3DNode<THREE.AxesHelper, typeof THRE
|
|
|
158
215
|
export declare type TextureProps = Node<THREE.Texture, typeof THREE.Texture>;
|
|
159
216
|
export declare type VideoTextureProps = Node<THREE.VideoTexture, typeof THREE.VideoTexture>;
|
|
160
217
|
export declare type DataTextureProps = Node<THREE.DataTexture, typeof THREE.DataTexture>;
|
|
218
|
+
/** @ts-ignore */
|
|
161
219
|
export declare type DataTexture3DProps = Node<THREE.DataTexture3D, typeof THREE.DataTexture3D>;
|
|
162
220
|
export declare type CompressedTextureProps = Node<THREE.CompressedTexture, typeof THREE.CompressedTexture>;
|
|
163
221
|
export declare type CubeTextureProps = Node<THREE.CubeTexture, typeof THREE.CubeTexture>;
|
|
@@ -3,11 +3,22 @@ import type { Options as ResizeOptions } from 'react-use-measure';
|
|
|
3
3
|
import { RenderProps } from '../core';
|
|
4
4
|
export interface CanvasProps extends Omit<RenderProps<HTMLCanvasElement>, 'size'>, React.HTMLAttributes<HTMLDivElement> {
|
|
5
5
|
children: React.ReactNode;
|
|
6
|
+
/** Canvas fallback content, similar to img's alt prop */
|
|
6
7
|
fallback?: React.ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Options to pass to useMeasure.
|
|
10
|
+
* @see https://github.com/pmndrs/react-use-measure#api
|
|
11
|
+
*/
|
|
7
12
|
resize?: ResizeOptions;
|
|
13
|
+
/** The target where events are being subscribed to, default: the div that wraps canvas */
|
|
8
14
|
eventSource?: HTMLElement | React.MutableRefObject<HTMLElement>;
|
|
15
|
+
/** The event prefix that is cast into canvas pointer x/y events, default: "offset" */
|
|
9
16
|
eventPrefix?: 'offset' | 'client' | 'page' | 'layer' | 'screen';
|
|
10
17
|
}
|
|
11
18
|
export interface Props extends CanvasProps {
|
|
12
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* A DOM canvas which accepts threejs elements as children.
|
|
22
|
+
* @see https://docs.pmnd.rs/react-three-fiber/api/canvas
|
|
23
|
+
*/
|
|
13
24
|
export declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLCanvasElement>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UseBoundStore } from 'zustand';
|
|
2
2
|
import { RootState } from '../core/store';
|
|
3
3
|
import { EventManager } from '../core/events';
|
|
4
|
+
/** Default R3F event manager for web */
|
|
4
5
|
export declare function createPointerEvents(store: UseBoundStore<RootState>): EventManager<HTMLElement>;
|
|
@@ -282,18 +282,71 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(p
|
|
|
282
282
|
})));
|
|
283
283
|
});
|
|
284
284
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
285
|
+
// http://stackoverflow.com/questions/105034
|
|
286
|
+
function uuidv4() {
|
|
287
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
288
|
+
const r = Math.random() * 16 | 0,
|
|
289
|
+
v = c == 'x' ? r : r & 0x3 | 0x8;
|
|
290
|
+
return v.toString(16);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
async function getAsset(input) {
|
|
294
|
+
if (typeof input === 'string') {
|
|
295
|
+
var _NativeModules$BlobMo;
|
|
296
|
+
// Don't process storage
|
|
297
|
+
if (input.startsWith('file:')) return input;
|
|
298
|
+
|
|
299
|
+
// Unpack Blobs from react-native BlobManager
|
|
300
|
+
// https://github.com/facebook/react-native/issues/22681#issuecomment-523258955
|
|
301
|
+
if (input.startsWith('blob:') || input.startsWith((_NativeModules$BlobMo = reactNative.NativeModules.BlobModule) == null ? void 0 : _NativeModules$BlobMo.BLOB_URI_SCHEME)) {
|
|
302
|
+
const blob = await new Promise((res, rej) => {
|
|
303
|
+
const xhr = new XMLHttpRequest();
|
|
304
|
+
xhr.open('GET', input);
|
|
305
|
+
xhr.responseType = 'blob';
|
|
306
|
+
xhr.onload = () => res(xhr.response);
|
|
307
|
+
xhr.onerror = rej;
|
|
308
|
+
xhr.send();
|
|
309
|
+
});
|
|
310
|
+
const data = await new Promise((res, rej) => {
|
|
311
|
+
const reader = new FileReader();
|
|
312
|
+
reader.onload = () => res(reader.result);
|
|
313
|
+
reader.onerror = rej;
|
|
314
|
+
reader.readAsText(blob);
|
|
315
|
+
});
|
|
316
|
+
input = `data:${blob.type};base64,${data}`;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Create safe URI for JSI serialization
|
|
320
|
+
if (input.startsWith('data:')) {
|
|
321
|
+
const [header, data] = input.split(';base64,');
|
|
322
|
+
const [, type] = header.split('/');
|
|
323
|
+
const uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
|
|
324
|
+
await fs__namespace.writeAsStringAsync(uri, data, {
|
|
325
|
+
encoding: fs__namespace.EncodingType.Base64
|
|
326
|
+
});
|
|
327
|
+
return uri;
|
|
328
|
+
}
|
|
293
329
|
}
|
|
294
330
|
|
|
295
|
-
//
|
|
331
|
+
// Download bundler module or external URL
|
|
332
|
+
const asset = await expoAsset.Asset.fromModule(input).downloadAsync();
|
|
333
|
+
let uri = asset.localUri || asset.uri;
|
|
334
|
+
|
|
335
|
+
// Unpack assets in Android Release Mode
|
|
336
|
+
if (!uri.includes(':')) {
|
|
337
|
+
const file = `${fs__namespace.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
|
|
338
|
+
await fs__namespace.copyAsync({
|
|
339
|
+
from: uri,
|
|
340
|
+
to: file
|
|
341
|
+
});
|
|
342
|
+
uri = file;
|
|
343
|
+
}
|
|
344
|
+
return uri;
|
|
345
|
+
}
|
|
346
|
+
function polyfills() {
|
|
347
|
+
// Patch Blob for ArrayBuffer and URL if unsupported
|
|
296
348
|
// https://github.com/facebook/react-native/pull/39276
|
|
349
|
+
// https://github.com/pmndrs/react-three-fiber/issues/3058
|
|
297
350
|
if (reactNative.Platform.OS !== 'web') {
|
|
298
351
|
try {
|
|
299
352
|
const blob = new Blob([new ArrayBuffer(4)]);
|
|
@@ -301,124 +354,34 @@ function polyfills() {
|
|
|
301
354
|
URL.revokeObjectURL(url);
|
|
302
355
|
} catch (_) {
|
|
303
356
|
const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
if (BlobModule && typeof BlobModule.BLOB_URI_SCHEME === 'string') {
|
|
309
|
-
BLOB_URL_PREFIX = BlobModule.BLOB_URI_SCHEME + ':';
|
|
310
|
-
if (typeof BlobModule.BLOB_URI_HOST === 'string') {
|
|
311
|
-
BLOB_URL_PREFIX += `//${BlobModule.BLOB_URI_HOST}/`;
|
|
357
|
+
const createObjectURL = URL.createObjectURL;
|
|
358
|
+
URL.createObjectURL = function (blob) {
|
|
359
|
+
if (blob.data._base64) {
|
|
360
|
+
return `data:${blob.type};base64,${blob.data._base64}`;
|
|
312
361
|
}
|
|
313
|
-
|
|
314
|
-
URL.createObjectURL = function createObjectURL(blob) {
|
|
315
|
-
const data = blob.data;
|
|
316
|
-
if (BLOB_URL_PREFIX === null) {
|
|
317
|
-
// https://github.com/pmndrs/react-three-fiber/issues/3058
|
|
318
|
-
// throw new Error('Cannot create URL for blob!')
|
|
319
|
-
return `data:${blob.type};base64,${data._base64}`;
|
|
320
|
-
}
|
|
321
|
-
return `${BLOB_URL_PREFIX}${data.blobId}?offset=${data.offset}&size=${blob.size}`;
|
|
362
|
+
return createObjectURL(blob);
|
|
322
363
|
};
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
364
|
+
const createFromParts = BlobManager.createFromParts;
|
|
365
|
+
BlobManager.createFromParts = function (parts, options) {
|
|
366
|
+
var _NativeModules$BlobMo2;
|
|
367
|
+
parts = parts.map(part => {
|
|
326
368
|
if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
|
|
327
|
-
|
|
328
|
-
return {
|
|
329
|
-
data,
|
|
330
|
-
type: 'string'
|
|
331
|
-
};
|
|
332
|
-
} else if (part instanceof Blob) {
|
|
333
|
-
return {
|
|
334
|
-
data: part.data,
|
|
335
|
-
type: 'blob'
|
|
336
|
-
};
|
|
337
|
-
} else {
|
|
338
|
-
return {
|
|
339
|
-
data: String(part),
|
|
340
|
-
type: 'string'
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
const size = items.reduce((acc, curr) => {
|
|
345
|
-
if (curr.type === 'string') {
|
|
346
|
-
return acc + global.unescape(encodeURI(curr.data)).length;
|
|
347
|
-
} else {
|
|
348
|
-
return acc + curr.data.size;
|
|
369
|
+
part = base64Js.fromByteArray(new Uint8Array(part));
|
|
349
370
|
}
|
|
350
|
-
|
|
351
|
-
reactNative.NativeModules.BlobModule.createFromParts(items, blobId);
|
|
352
|
-
const blob = BlobManager.createFromOptions({
|
|
353
|
-
blobId,
|
|
354
|
-
offset: 0,
|
|
355
|
-
size,
|
|
356
|
-
type: options ? options.type : '',
|
|
357
|
-
lastModified: options ? options.lastModified : Date.now()
|
|
371
|
+
return part;
|
|
358
372
|
});
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
373
|
+
const blob = createFromParts(parts, options);
|
|
374
|
+
if (!((_NativeModules$BlobMo2 = reactNative.NativeModules.BlobModule) != null && _NativeModules$BlobMo2.BLOB_URI_SCHEME)) {
|
|
375
|
+
blob.data._base64 = '';
|
|
376
|
+
for (const part of parts) {
|
|
377
|
+
var _data$_base, _data;
|
|
378
|
+
blob.data._base64 += (_data$_base = (_data = part.data) == null ? void 0 : _data._base64) != null ? _data$_base : part;
|
|
364
379
|
}
|
|
365
|
-
blob.data._base64 = data;
|
|
366
380
|
}
|
|
367
381
|
return blob;
|
|
368
382
|
};
|
|
369
383
|
}
|
|
370
384
|
}
|
|
371
|
-
async function getAsset(input) {
|
|
372
|
-
if (typeof input === 'string') {
|
|
373
|
-
// Don't process storage
|
|
374
|
-
if (input.startsWith('file:')) return input;
|
|
375
|
-
|
|
376
|
-
// Unpack Blobs from react-native BlobManager
|
|
377
|
-
if (input.startsWith('blob:')) {
|
|
378
|
-
const blob = await new Promise((res, rej) => {
|
|
379
|
-
const xhr = new XMLHttpRequest();
|
|
380
|
-
xhr.open('GET', input);
|
|
381
|
-
xhr.responseType = 'blob';
|
|
382
|
-
xhr.onload = () => res(xhr.response);
|
|
383
|
-
xhr.onerror = rej;
|
|
384
|
-
xhr.send();
|
|
385
|
-
});
|
|
386
|
-
const data = await new Promise((res, rej) => {
|
|
387
|
-
const reader = new FileReader();
|
|
388
|
-
reader.onload = () => res(reader.result);
|
|
389
|
-
reader.onerror = rej;
|
|
390
|
-
reader.readAsText(blob);
|
|
391
|
-
});
|
|
392
|
-
input = `data:${blob.type};base64,${data}`;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// Create safe URI for JSI
|
|
396
|
-
if (input.startsWith('data:')) {
|
|
397
|
-
const [header, data] = input.split(';base64,');
|
|
398
|
-
const [, type] = header.split('/');
|
|
399
|
-
const uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
|
|
400
|
-
await fs__namespace.writeAsStringAsync(uri, data, {
|
|
401
|
-
encoding: fs__namespace.EncodingType.Base64
|
|
402
|
-
});
|
|
403
|
-
return uri;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// Download bundler module or external URL
|
|
408
|
-
const asset = await expoAsset.Asset.fromModule(input).downloadAsync();
|
|
409
|
-
let uri = asset.localUri || asset.uri;
|
|
410
|
-
|
|
411
|
-
// Unpack assets in Android Release Mode
|
|
412
|
-
if (!uri.includes(':')) {
|
|
413
|
-
const file = `${fs__namespace.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
|
|
414
|
-
await fs__namespace.copyAsync({
|
|
415
|
-
from: uri,
|
|
416
|
-
to: file
|
|
417
|
-
});
|
|
418
|
-
uri = file;
|
|
419
|
-
}
|
|
420
|
-
return uri;
|
|
421
|
-
}
|
|
422
385
|
|
|
423
386
|
// Don't pre-process urls, let expo-asset generate an absolute URL
|
|
424
387
|
const extractUrlBase = THREE__namespace.LoaderUtils.extractUrlBase.bind(THREE__namespace.LoaderUtils);
|
|
@@ -427,7 +390,6 @@ function polyfills() {
|
|
|
427
390
|
// There's no Image in native, so create a data texture instead
|
|
428
391
|
THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
429
392
|
if (this.path && typeof url === 'string') url = this.path + url;
|
|
430
|
-
this.manager.itemStart(url);
|
|
431
393
|
const texture = new THREE__namespace.Texture();
|
|
432
394
|
getAsset(url).then(async uri => {
|
|
433
395
|
// https://github.com/expo/expo-three/pull/266
|
|
@@ -453,12 +415,7 @@ function polyfills() {
|
|
|
453
415
|
// @ts-ignore
|
|
454
416
|
texture.isDataTexture = true;
|
|
455
417
|
onLoad == null ? void 0 : onLoad(texture);
|
|
456
|
-
}).catch(
|
|
457
|
-
onError == null ? void 0 : onError(error);
|
|
458
|
-
this.manager.itemError(url);
|
|
459
|
-
}).finally(() => {
|
|
460
|
-
this.manager.itemEnd(url);
|
|
461
|
-
});
|
|
418
|
+
}).catch(onError);
|
|
462
419
|
return texture;
|
|
463
420
|
};
|
|
464
421
|
|
|
@@ -282,18 +282,71 @@ const Canvas = /*#__PURE__*/React__namespace.forwardRef(function CanvasWrapper(p
|
|
|
282
282
|
})));
|
|
283
283
|
});
|
|
284
284
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
285
|
+
// http://stackoverflow.com/questions/105034
|
|
286
|
+
function uuidv4() {
|
|
287
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
288
|
+
const r = Math.random() * 16 | 0,
|
|
289
|
+
v = c == 'x' ? r : r & 0x3 | 0x8;
|
|
290
|
+
return v.toString(16);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
async function getAsset(input) {
|
|
294
|
+
if (typeof input === 'string') {
|
|
295
|
+
var _NativeModules$BlobMo;
|
|
296
|
+
// Don't process storage
|
|
297
|
+
if (input.startsWith('file:')) return input;
|
|
298
|
+
|
|
299
|
+
// Unpack Blobs from react-native BlobManager
|
|
300
|
+
// https://github.com/facebook/react-native/issues/22681#issuecomment-523258955
|
|
301
|
+
if (input.startsWith('blob:') || input.startsWith((_NativeModules$BlobMo = reactNative.NativeModules.BlobModule) == null ? void 0 : _NativeModules$BlobMo.BLOB_URI_SCHEME)) {
|
|
302
|
+
const blob = await new Promise((res, rej) => {
|
|
303
|
+
const xhr = new XMLHttpRequest();
|
|
304
|
+
xhr.open('GET', input);
|
|
305
|
+
xhr.responseType = 'blob';
|
|
306
|
+
xhr.onload = () => res(xhr.response);
|
|
307
|
+
xhr.onerror = rej;
|
|
308
|
+
xhr.send();
|
|
309
|
+
});
|
|
310
|
+
const data = await new Promise((res, rej) => {
|
|
311
|
+
const reader = new FileReader();
|
|
312
|
+
reader.onload = () => res(reader.result);
|
|
313
|
+
reader.onerror = rej;
|
|
314
|
+
reader.readAsText(blob);
|
|
315
|
+
});
|
|
316
|
+
input = `data:${blob.type};base64,${data}`;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Create safe URI for JSI serialization
|
|
320
|
+
if (input.startsWith('data:')) {
|
|
321
|
+
const [header, data] = input.split(';base64,');
|
|
322
|
+
const [, type] = header.split('/');
|
|
323
|
+
const uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
|
|
324
|
+
await fs__namespace.writeAsStringAsync(uri, data, {
|
|
325
|
+
encoding: fs__namespace.EncodingType.Base64
|
|
326
|
+
});
|
|
327
|
+
return uri;
|
|
328
|
+
}
|
|
293
329
|
}
|
|
294
330
|
|
|
295
|
-
//
|
|
331
|
+
// Download bundler module or external URL
|
|
332
|
+
const asset = await expoAsset.Asset.fromModule(input).downloadAsync();
|
|
333
|
+
let uri = asset.localUri || asset.uri;
|
|
334
|
+
|
|
335
|
+
// Unpack assets in Android Release Mode
|
|
336
|
+
if (!uri.includes(':')) {
|
|
337
|
+
const file = `${fs__namespace.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
|
|
338
|
+
await fs__namespace.copyAsync({
|
|
339
|
+
from: uri,
|
|
340
|
+
to: file
|
|
341
|
+
});
|
|
342
|
+
uri = file;
|
|
343
|
+
}
|
|
344
|
+
return uri;
|
|
345
|
+
}
|
|
346
|
+
function polyfills() {
|
|
347
|
+
// Patch Blob for ArrayBuffer and URL if unsupported
|
|
296
348
|
// https://github.com/facebook/react-native/pull/39276
|
|
349
|
+
// https://github.com/pmndrs/react-three-fiber/issues/3058
|
|
297
350
|
if (reactNative.Platform.OS !== 'web') {
|
|
298
351
|
try {
|
|
299
352
|
const blob = new Blob([new ArrayBuffer(4)]);
|
|
@@ -301,124 +354,34 @@ function polyfills() {
|
|
|
301
354
|
URL.revokeObjectURL(url);
|
|
302
355
|
} catch (_) {
|
|
303
356
|
const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
if (BlobModule && typeof BlobModule.BLOB_URI_SCHEME === 'string') {
|
|
309
|
-
BLOB_URL_PREFIX = BlobModule.BLOB_URI_SCHEME + ':';
|
|
310
|
-
if (typeof BlobModule.BLOB_URI_HOST === 'string') {
|
|
311
|
-
BLOB_URL_PREFIX += `//${BlobModule.BLOB_URI_HOST}/`;
|
|
357
|
+
const createObjectURL = URL.createObjectURL;
|
|
358
|
+
URL.createObjectURL = function (blob) {
|
|
359
|
+
if (blob.data._base64) {
|
|
360
|
+
return `data:${blob.type};base64,${blob.data._base64}`;
|
|
312
361
|
}
|
|
313
|
-
|
|
314
|
-
URL.createObjectURL = function createObjectURL(blob) {
|
|
315
|
-
const data = blob.data;
|
|
316
|
-
if (BLOB_URL_PREFIX === null) {
|
|
317
|
-
// https://github.com/pmndrs/react-three-fiber/issues/3058
|
|
318
|
-
// throw new Error('Cannot create URL for blob!')
|
|
319
|
-
return `data:${blob.type};base64,${data._base64}`;
|
|
320
|
-
}
|
|
321
|
-
return `${BLOB_URL_PREFIX}${data.blobId}?offset=${data.offset}&size=${blob.size}`;
|
|
362
|
+
return createObjectURL(blob);
|
|
322
363
|
};
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
364
|
+
const createFromParts = BlobManager.createFromParts;
|
|
365
|
+
BlobManager.createFromParts = function (parts, options) {
|
|
366
|
+
var _NativeModules$BlobMo2;
|
|
367
|
+
parts = parts.map(part => {
|
|
326
368
|
if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
|
|
327
|
-
|
|
328
|
-
return {
|
|
329
|
-
data,
|
|
330
|
-
type: 'string'
|
|
331
|
-
};
|
|
332
|
-
} else if (part instanceof Blob) {
|
|
333
|
-
return {
|
|
334
|
-
data: part.data,
|
|
335
|
-
type: 'blob'
|
|
336
|
-
};
|
|
337
|
-
} else {
|
|
338
|
-
return {
|
|
339
|
-
data: String(part),
|
|
340
|
-
type: 'string'
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
const size = items.reduce((acc, curr) => {
|
|
345
|
-
if (curr.type === 'string') {
|
|
346
|
-
return acc + global.unescape(encodeURI(curr.data)).length;
|
|
347
|
-
} else {
|
|
348
|
-
return acc + curr.data.size;
|
|
369
|
+
part = base64Js.fromByteArray(new Uint8Array(part));
|
|
349
370
|
}
|
|
350
|
-
|
|
351
|
-
reactNative.NativeModules.BlobModule.createFromParts(items, blobId);
|
|
352
|
-
const blob = BlobManager.createFromOptions({
|
|
353
|
-
blobId,
|
|
354
|
-
offset: 0,
|
|
355
|
-
size,
|
|
356
|
-
type: options ? options.type : '',
|
|
357
|
-
lastModified: options ? options.lastModified : Date.now()
|
|
371
|
+
return part;
|
|
358
372
|
});
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
373
|
+
const blob = createFromParts(parts, options);
|
|
374
|
+
if (!((_NativeModules$BlobMo2 = reactNative.NativeModules.BlobModule) != null && _NativeModules$BlobMo2.BLOB_URI_SCHEME)) {
|
|
375
|
+
blob.data._base64 = '';
|
|
376
|
+
for (const part of parts) {
|
|
377
|
+
var _data$_base, _data;
|
|
378
|
+
blob.data._base64 += (_data$_base = (_data = part.data) == null ? void 0 : _data._base64) != null ? _data$_base : part;
|
|
364
379
|
}
|
|
365
|
-
blob.data._base64 = data;
|
|
366
380
|
}
|
|
367
381
|
return blob;
|
|
368
382
|
};
|
|
369
383
|
}
|
|
370
384
|
}
|
|
371
|
-
async function getAsset(input) {
|
|
372
|
-
if (typeof input === 'string') {
|
|
373
|
-
// Don't process storage
|
|
374
|
-
if (input.startsWith('file:')) return input;
|
|
375
|
-
|
|
376
|
-
// Unpack Blobs from react-native BlobManager
|
|
377
|
-
if (input.startsWith('blob:')) {
|
|
378
|
-
const blob = await new Promise((res, rej) => {
|
|
379
|
-
const xhr = new XMLHttpRequest();
|
|
380
|
-
xhr.open('GET', input);
|
|
381
|
-
xhr.responseType = 'blob';
|
|
382
|
-
xhr.onload = () => res(xhr.response);
|
|
383
|
-
xhr.onerror = rej;
|
|
384
|
-
xhr.send();
|
|
385
|
-
});
|
|
386
|
-
const data = await new Promise((res, rej) => {
|
|
387
|
-
const reader = new FileReader();
|
|
388
|
-
reader.onload = () => res(reader.result);
|
|
389
|
-
reader.onerror = rej;
|
|
390
|
-
reader.readAsText(blob);
|
|
391
|
-
});
|
|
392
|
-
input = `data:${blob.type};base64,${data}`;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// Create safe URI for JSI
|
|
396
|
-
if (input.startsWith('data:')) {
|
|
397
|
-
const [header, data] = input.split(';base64,');
|
|
398
|
-
const [, type] = header.split('/');
|
|
399
|
-
const uri = fs__namespace.cacheDirectory + uuidv4() + `.${type}`;
|
|
400
|
-
await fs__namespace.writeAsStringAsync(uri, data, {
|
|
401
|
-
encoding: fs__namespace.EncodingType.Base64
|
|
402
|
-
});
|
|
403
|
-
return uri;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// Download bundler module or external URL
|
|
408
|
-
const asset = await expoAsset.Asset.fromModule(input).downloadAsync();
|
|
409
|
-
let uri = asset.localUri || asset.uri;
|
|
410
|
-
|
|
411
|
-
// Unpack assets in Android Release Mode
|
|
412
|
-
if (!uri.includes(':')) {
|
|
413
|
-
const file = `${fs__namespace.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
|
|
414
|
-
await fs__namespace.copyAsync({
|
|
415
|
-
from: uri,
|
|
416
|
-
to: file
|
|
417
|
-
});
|
|
418
|
-
uri = file;
|
|
419
|
-
}
|
|
420
|
-
return uri;
|
|
421
|
-
}
|
|
422
385
|
|
|
423
386
|
// Don't pre-process urls, let expo-asset generate an absolute URL
|
|
424
387
|
const extractUrlBase = THREE__namespace.LoaderUtils.extractUrlBase.bind(THREE__namespace.LoaderUtils);
|
|
@@ -427,7 +390,6 @@ function polyfills() {
|
|
|
427
390
|
// There's no Image in native, so create a data texture instead
|
|
428
391
|
THREE__namespace.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
429
392
|
if (this.path && typeof url === 'string') url = this.path + url;
|
|
430
|
-
this.manager.itemStart(url);
|
|
431
393
|
const texture = new THREE__namespace.Texture();
|
|
432
394
|
getAsset(url).then(async uri => {
|
|
433
395
|
// https://github.com/expo/expo-three/pull/266
|
|
@@ -453,12 +415,7 @@ function polyfills() {
|
|
|
453
415
|
// @ts-ignore
|
|
454
416
|
texture.isDataTexture = true;
|
|
455
417
|
onLoad == null ? void 0 : onLoad(texture);
|
|
456
|
-
}).catch(
|
|
457
|
-
onError == null ? void 0 : onError(error);
|
|
458
|
-
this.manager.itemError(url);
|
|
459
|
-
}).finally(() => {
|
|
460
|
-
this.manager.itemEnd(url);
|
|
461
|
-
});
|
|
418
|
+
}).catch(onError);
|
|
462
419
|
return texture;
|
|
463
420
|
};
|
|
464
421
|
|
|
@@ -257,18 +257,71 @@ const Canvas = /*#__PURE__*/React.forwardRef(function CanvasWrapper(props, ref)
|
|
|
257
257
|
})));
|
|
258
258
|
});
|
|
259
259
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
260
|
+
// http://stackoverflow.com/questions/105034
|
|
261
|
+
function uuidv4() {
|
|
262
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
263
|
+
const r = Math.random() * 16 | 0,
|
|
264
|
+
v = c == 'x' ? r : r & 0x3 | 0x8;
|
|
265
|
+
return v.toString(16);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
async function getAsset(input) {
|
|
269
|
+
if (typeof input === 'string') {
|
|
270
|
+
var _NativeModules$BlobMo;
|
|
271
|
+
// Don't process storage
|
|
272
|
+
if (input.startsWith('file:')) return input;
|
|
273
|
+
|
|
274
|
+
// Unpack Blobs from react-native BlobManager
|
|
275
|
+
// https://github.com/facebook/react-native/issues/22681#issuecomment-523258955
|
|
276
|
+
if (input.startsWith('blob:') || input.startsWith((_NativeModules$BlobMo = NativeModules.BlobModule) == null ? void 0 : _NativeModules$BlobMo.BLOB_URI_SCHEME)) {
|
|
277
|
+
const blob = await new Promise((res, rej) => {
|
|
278
|
+
const xhr = new XMLHttpRequest();
|
|
279
|
+
xhr.open('GET', input);
|
|
280
|
+
xhr.responseType = 'blob';
|
|
281
|
+
xhr.onload = () => res(xhr.response);
|
|
282
|
+
xhr.onerror = rej;
|
|
283
|
+
xhr.send();
|
|
284
|
+
});
|
|
285
|
+
const data = await new Promise((res, rej) => {
|
|
286
|
+
const reader = new FileReader();
|
|
287
|
+
reader.onload = () => res(reader.result);
|
|
288
|
+
reader.onerror = rej;
|
|
289
|
+
reader.readAsText(blob);
|
|
290
|
+
});
|
|
291
|
+
input = `data:${blob.type};base64,${data}`;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Create safe URI for JSI serialization
|
|
295
|
+
if (input.startsWith('data:')) {
|
|
296
|
+
const [header, data] = input.split(';base64,');
|
|
297
|
+
const [, type] = header.split('/');
|
|
298
|
+
const uri = fs.cacheDirectory + uuidv4() + `.${type}`;
|
|
299
|
+
await fs.writeAsStringAsync(uri, data, {
|
|
300
|
+
encoding: fs.EncodingType.Base64
|
|
301
|
+
});
|
|
302
|
+
return uri;
|
|
303
|
+
}
|
|
268
304
|
}
|
|
269
305
|
|
|
270
|
-
//
|
|
306
|
+
// Download bundler module or external URL
|
|
307
|
+
const asset = await Asset.fromModule(input).downloadAsync();
|
|
308
|
+
let uri = asset.localUri || asset.uri;
|
|
309
|
+
|
|
310
|
+
// Unpack assets in Android Release Mode
|
|
311
|
+
if (!uri.includes(':')) {
|
|
312
|
+
const file = `${fs.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
|
|
313
|
+
await fs.copyAsync({
|
|
314
|
+
from: uri,
|
|
315
|
+
to: file
|
|
316
|
+
});
|
|
317
|
+
uri = file;
|
|
318
|
+
}
|
|
319
|
+
return uri;
|
|
320
|
+
}
|
|
321
|
+
function polyfills() {
|
|
322
|
+
// Patch Blob for ArrayBuffer and URL if unsupported
|
|
271
323
|
// https://github.com/facebook/react-native/pull/39276
|
|
324
|
+
// https://github.com/pmndrs/react-three-fiber/issues/3058
|
|
272
325
|
if (Platform.OS !== 'web') {
|
|
273
326
|
try {
|
|
274
327
|
const blob = new Blob([new ArrayBuffer(4)]);
|
|
@@ -276,124 +329,34 @@ function polyfills() {
|
|
|
276
329
|
URL.revokeObjectURL(url);
|
|
277
330
|
} catch (_) {
|
|
278
331
|
const BlobManager = require('react-native/Libraries/Blob/BlobManager.js');
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (BlobModule && typeof BlobModule.BLOB_URI_SCHEME === 'string') {
|
|
284
|
-
BLOB_URL_PREFIX = BlobModule.BLOB_URI_SCHEME + ':';
|
|
285
|
-
if (typeof BlobModule.BLOB_URI_HOST === 'string') {
|
|
286
|
-
BLOB_URL_PREFIX += `//${BlobModule.BLOB_URI_HOST}/`;
|
|
332
|
+
const createObjectURL = URL.createObjectURL;
|
|
333
|
+
URL.createObjectURL = function (blob) {
|
|
334
|
+
if (blob.data._base64) {
|
|
335
|
+
return `data:${blob.type};base64,${blob.data._base64}`;
|
|
287
336
|
}
|
|
288
|
-
|
|
289
|
-
URL.createObjectURL = function createObjectURL(blob) {
|
|
290
|
-
const data = blob.data;
|
|
291
|
-
if (BLOB_URL_PREFIX === null) {
|
|
292
|
-
// https://github.com/pmndrs/react-three-fiber/issues/3058
|
|
293
|
-
// throw new Error('Cannot create URL for blob!')
|
|
294
|
-
return `data:${blob.type};base64,${data._base64}`;
|
|
295
|
-
}
|
|
296
|
-
return `${BLOB_URL_PREFIX}${data.blobId}?offset=${data.offset}&size=${blob.size}`;
|
|
337
|
+
return createObjectURL(blob);
|
|
297
338
|
};
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
339
|
+
const createFromParts = BlobManager.createFromParts;
|
|
340
|
+
BlobManager.createFromParts = function (parts, options) {
|
|
341
|
+
var _NativeModules$BlobMo2;
|
|
342
|
+
parts = parts.map(part => {
|
|
301
343
|
if (part instanceof ArrayBuffer || ArrayBuffer.isView(part)) {
|
|
302
|
-
|
|
303
|
-
return {
|
|
304
|
-
data,
|
|
305
|
-
type: 'string'
|
|
306
|
-
};
|
|
307
|
-
} else if (part instanceof Blob) {
|
|
308
|
-
return {
|
|
309
|
-
data: part.data,
|
|
310
|
-
type: 'blob'
|
|
311
|
-
};
|
|
312
|
-
} else {
|
|
313
|
-
return {
|
|
314
|
-
data: String(part),
|
|
315
|
-
type: 'string'
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
const size = items.reduce((acc, curr) => {
|
|
320
|
-
if (curr.type === 'string') {
|
|
321
|
-
return acc + global.unescape(encodeURI(curr.data)).length;
|
|
322
|
-
} else {
|
|
323
|
-
return acc + curr.data.size;
|
|
344
|
+
part = fromByteArray(new Uint8Array(part));
|
|
324
345
|
}
|
|
325
|
-
|
|
326
|
-
NativeModules.BlobModule.createFromParts(items, blobId);
|
|
327
|
-
const blob = BlobManager.createFromOptions({
|
|
328
|
-
blobId,
|
|
329
|
-
offset: 0,
|
|
330
|
-
size,
|
|
331
|
-
type: options ? options.type : '',
|
|
332
|
-
lastModified: options ? options.lastModified : Date.now()
|
|
346
|
+
return part;
|
|
333
347
|
});
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
348
|
+
const blob = createFromParts(parts, options);
|
|
349
|
+
if (!((_NativeModules$BlobMo2 = NativeModules.BlobModule) != null && _NativeModules$BlobMo2.BLOB_URI_SCHEME)) {
|
|
350
|
+
blob.data._base64 = '';
|
|
351
|
+
for (const part of parts) {
|
|
352
|
+
var _data$_base, _data;
|
|
353
|
+
blob.data._base64 += (_data$_base = (_data = part.data) == null ? void 0 : _data._base64) != null ? _data$_base : part;
|
|
339
354
|
}
|
|
340
|
-
blob.data._base64 = data;
|
|
341
355
|
}
|
|
342
356
|
return blob;
|
|
343
357
|
};
|
|
344
358
|
}
|
|
345
359
|
}
|
|
346
|
-
async function getAsset(input) {
|
|
347
|
-
if (typeof input === 'string') {
|
|
348
|
-
// Don't process storage
|
|
349
|
-
if (input.startsWith('file:')) return input;
|
|
350
|
-
|
|
351
|
-
// Unpack Blobs from react-native BlobManager
|
|
352
|
-
if (input.startsWith('blob:')) {
|
|
353
|
-
const blob = await new Promise((res, rej) => {
|
|
354
|
-
const xhr = new XMLHttpRequest();
|
|
355
|
-
xhr.open('GET', input);
|
|
356
|
-
xhr.responseType = 'blob';
|
|
357
|
-
xhr.onload = () => res(xhr.response);
|
|
358
|
-
xhr.onerror = rej;
|
|
359
|
-
xhr.send();
|
|
360
|
-
});
|
|
361
|
-
const data = await new Promise((res, rej) => {
|
|
362
|
-
const reader = new FileReader();
|
|
363
|
-
reader.onload = () => res(reader.result);
|
|
364
|
-
reader.onerror = rej;
|
|
365
|
-
reader.readAsText(blob);
|
|
366
|
-
});
|
|
367
|
-
input = `data:${blob.type};base64,${data}`;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// Create safe URI for JSI
|
|
371
|
-
if (input.startsWith('data:')) {
|
|
372
|
-
const [header, data] = input.split(';base64,');
|
|
373
|
-
const [, type] = header.split('/');
|
|
374
|
-
const uri = fs.cacheDirectory + uuidv4() + `.${type}`;
|
|
375
|
-
await fs.writeAsStringAsync(uri, data, {
|
|
376
|
-
encoding: fs.EncodingType.Base64
|
|
377
|
-
});
|
|
378
|
-
return uri;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// Download bundler module or external URL
|
|
383
|
-
const asset = await Asset.fromModule(input).downloadAsync();
|
|
384
|
-
let uri = asset.localUri || asset.uri;
|
|
385
|
-
|
|
386
|
-
// Unpack assets in Android Release Mode
|
|
387
|
-
if (!uri.includes(':')) {
|
|
388
|
-
const file = `${fs.cacheDirectory}ExponentAsset-${asset.hash}.${asset.type}`;
|
|
389
|
-
await fs.copyAsync({
|
|
390
|
-
from: uri,
|
|
391
|
-
to: file
|
|
392
|
-
});
|
|
393
|
-
uri = file;
|
|
394
|
-
}
|
|
395
|
-
return uri;
|
|
396
|
-
}
|
|
397
360
|
|
|
398
361
|
// Don't pre-process urls, let expo-asset generate an absolute URL
|
|
399
362
|
const extractUrlBase = THREE.LoaderUtils.extractUrlBase.bind(THREE.LoaderUtils);
|
|
@@ -402,7 +365,6 @@ function polyfills() {
|
|
|
402
365
|
// There's no Image in native, so create a data texture instead
|
|
403
366
|
THREE.TextureLoader.prototype.load = function load(url, onLoad, onProgress, onError) {
|
|
404
367
|
if (this.path && typeof url === 'string') url = this.path + url;
|
|
405
|
-
this.manager.itemStart(url);
|
|
406
368
|
const texture = new THREE.Texture();
|
|
407
369
|
getAsset(url).then(async uri => {
|
|
408
370
|
// https://github.com/expo/expo-three/pull/266
|
|
@@ -428,12 +390,7 @@ function polyfills() {
|
|
|
428
390
|
// @ts-ignore
|
|
429
391
|
texture.isDataTexture = true;
|
|
430
392
|
onLoad == null ? void 0 : onLoad(texture);
|
|
431
|
-
}).catch(
|
|
432
|
-
onError == null ? void 0 : onError(error);
|
|
433
|
-
this.manager.itemError(url);
|
|
434
|
-
}).finally(() => {
|
|
435
|
-
this.manager.itemEnd(url);
|
|
436
|
-
});
|
|
393
|
+
}).catch(onError);
|
|
437
394
|
return texture;
|
|
438
395
|
};
|
|
439
396
|
|