@react-three/drei 9.74.13 → 9.74.15
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/core/CatmullRomLine.js +0 -2
- package/core/Cloud.js +0 -3
- package/core/CubeCamera.js +0 -1
- package/core/CubicBezierLine.js +0 -2
- package/core/Environment.js +0 -1
- package/core/Example.js +0 -6
- package/core/FaceControls.cjs.js +1 -1
- package/core/FaceControls.js +0 -2
- package/core/FaceLandmarker.cjs.js +1 -1
- package/core/FaceLandmarker.js +3 -4
- package/core/Facemesh.js +0 -2
- package/core/GizmoHelper.js +0 -3
- package/core/GizmoViewcube.js +0 -4
- package/core/GizmoViewport.js +0 -4
- package/core/Gltf.js +0 -4
- package/core/MeshDiscardMaterial.js +0 -2
- package/core/MeshDistortMaterial.js +1 -2
- package/core/MeshReflectorMaterial.js +0 -1
- package/core/MeshRefractionMaterial.js +0 -2
- package/core/MeshTransmissionMaterial.js +0 -1
- package/core/OrthographicCamera.js +0 -1
- package/core/PerspectiveCamera.js +0 -1
- package/core/QuadraticBezierLine.js +0 -2
- package/core/Reflector.js +0 -1
- package/core/SpotLight.js +1 -2
- package/core/Stage.js +0 -7
- package/core/Text3D.js +0 -1
- package/core/Wireframe.js +0 -1
- package/core/index.cjs.js +1 -1
- package/core/index.js +1 -0
- package/core/useKTX2.js +0 -1
- package/core/useMatcapTexture.js +0 -2
- package/core/useNormalTexture.js +0 -1
- package/index.cjs.js +1 -1
- package/materials/DiscardMaterial.js +0 -1
- package/materials/MeshRefractionMaterial.js +1 -1
- package/native/index.cjs.js +1 -1
- package/native/index.js +1 -0
- package/package.json +2 -2
- package/web/Loader.js +0 -2
- package/web/index.cjs.js +1 -1
- package/web/index.js +1 -0
- package/web/pivotControls/AxisArrow.js +0 -3
- package/web/pivotControls/AxisRotator.js +0 -3
- package/web/pivotControls/PlaneSlider.js +0 -3
- package/web/pivotControls/index.js +0 -5
- package/src/core/AccumulativeShadows.js +0 -311
- package/src/core/AdaptiveDpr.js +0 -28
- package/src/core/AdaptiveEvents.js +0 -20
- package/src/core/ArcballControls.js +0 -67
- package/src/core/AsciiRenderer.js +0 -60
- package/src/core/BBAnchor.js +0 -37
- package/src/core/Backdrop.js +0 -36
- package/src/core/BakeShadows.js +0 -16
- package/src/core/Billboard.js +0 -41
- package/src/core/Bounds.js +0 -245
- package/src/core/CameraControls.js +0 -92
- package/src/core/CameraShake.js +0 -61
- package/src/core/CatmullRomLine.js +0 -44
- package/src/core/Caustics.js +0 -375
- package/src/core/Center.js +0 -66
- package/src/core/Clone.js +0 -102
- package/src/core/Cloud.js +0 -59
- package/src/core/ComputedAttribute.js +0 -34
- package/src/core/ContactShadows.js +0 -114
- package/src/core/CubeCamera.js +0 -43
- package/src/core/CubicBezierLine.js +0 -28
- package/src/core/CurveModifier.js +0 -34
- package/src/core/Decal.js +0 -92
- package/src/core/Detailed.js +0 -34
- package/src/core/DeviceOrientationControls.js +0 -51
- package/src/core/Edges.js +0 -36
- package/src/core/Effects.js +0 -93
- package/src/core/Environment.js +0 -132
- package/src/core/Example.js +0 -42
- package/src/core/FaceControls.js +0 -315
- package/src/core/FaceLandmarker.js +0 -43
- package/src/core/Facemesh.js +0 -4545
- package/src/core/FirstPersonControls.js +0 -38
- package/src/core/Float.js +0 -36
- package/src/core/FlyControls.js +0 -55
- package/src/core/GizmoHelper.js +0 -111
- package/src/core/GizmoViewcube.js +0 -152
- package/src/core/GizmoViewport.js +0 -152
- package/src/core/Gltf.js +0 -20
- package/src/core/GradientTexture.js +0 -33
- package/src/core/Grid.js +0 -112
- package/src/core/Hud.js +0 -58
- package/src/core/Image.js +0 -119
- package/src/core/Instances.js +0 -215
- package/src/core/Lightformer.js +0 -51
- package/src/core/Line.js +0 -68
- package/src/core/MapControls.js +0 -64
- package/src/core/MarchingCubes.js +0 -76
- package/src/core/Mask.js +0 -42
- package/src/core/MeshDiscardMaterial.js +0 -15
- package/src/core/MeshDistortMaterial.js +0 -79
- package/src/core/MeshPortalMaterial.js +0 -381
- package/src/core/MeshReflectorMaterial.js +0 -182
- package/src/core/MeshRefractionMaterial.js +0 -79
- package/src/core/MeshTransmissionMaterial.js +0 -395
- package/src/core/MeshWobbleMaterial.js +0 -65
- package/src/core/OrbitControls.js +0 -82
- package/src/core/OrthographicCamera.js +0 -77
- package/src/core/PerformanceMonitor.js +0 -121
- package/src/core/PerspectiveCamera.js +0 -73
- package/src/core/PointMaterial.js +0 -36
- package/src/core/PointerLockControls.js +0 -90
- package/src/core/Points.js +0 -227
- package/src/core/PositionalAudio.js +0 -51
- package/src/core/Preload.js +0 -45
- package/src/core/QuadraticBezierLine.js +0 -44
- package/src/core/Reflector.js +0 -182
- package/src/core/RenderTexture.js +0 -96
- package/src/core/Resize.js +0 -39
- package/src/core/RoundedBox.js +0 -52
- package/src/core/Sampler.js +0 -85
- package/src/core/ScreenQuad.js +0 -24
- package/src/core/ScreenSpace.js +0 -25
- package/src/core/Segments.js +0 -102
- package/src/core/Shadow.js +0 -42
- package/src/core/Sky.js +0 -39
- package/src/core/Sparkles.js +0 -139
- package/src/core/SpotLight.js +0 -231
- package/src/core/SpriteAnimator.js +0 -342
- package/src/core/Stage.js +0 -135
- package/src/core/Stars.js +0 -108
- package/src/core/Stats.js +0 -30
- package/src/core/Svg.js +0 -59
- package/src/core/Text.js +0 -58
- package/src/core/Text3D.js +0 -76
- package/src/core/TrackballControls.js +0 -72
- package/src/core/Trail.js +0 -161
- package/src/core/TransformControls.js +0 -106
- package/src/core/Wireframe.js +0 -185
- package/src/core/meshBounds.js +0 -38
- package/src/core/shaderMaterial.js +0 -39
- package/src/core/shapes.js +0 -68
- package/src/core/softShadows.js +0 -161
- package/src/core/useAnimations.js +0 -56
- package/src/core/useAspect.js +0 -10
- package/src/core/useBVH.js +0 -90
- package/src/core/useBoxProjectedEnv.js +0 -98
- package/src/core/useCamera.js +0 -27
- package/src/core/useContextBridge.js +0 -21
- package/src/core/useCubeCamera.js +0 -49
- package/src/core/useCubeTexture.js +0 -18
- package/src/core/useDepthBuffer.js +0 -38
- package/src/core/useDetectGPU.js +0 -6
- package/src/core/useEnvironment.js +0 -48
- package/src/core/useFBO.js +0 -53
- package/src/core/useFBX.js +0 -12
- package/src/core/useFont.js +0 -20
- package/src/core/useGLTF.js +0 -37
- package/src/core/useHelper.js +0 -31
- package/src/core/useIntersect.js +0 -39
- package/src/core/useKTX2.js +0 -38
- package/src/core/useMatcapTexture.js +0 -45
- package/src/core/useNormalTexture.js +0 -30
- package/src/core/useProgress.js +0 -50
- package/src/core/useTexture.js +0 -35
- package/src/core/useTrailTexture.js +0 -164
- package/src/core/useVideoTexture.js +0 -41
- package/src/helpers/environment-assets.js +0 -14
- package/src/helpers/useEffectfulState.js +0 -18
- package/src/materials/BlurPass.js +0 -75
- package/src/materials/ConvolutionMaterial.js +0 -99
- package/src/materials/DiscardMaterial.js +0 -5
- package/src/materials/MeshReflectorMaterial.js +0 -290
- package/src/materials/MeshRefractionMaterial.js +0 -171
- package/src/materials/SpotLightMaterial.js +0 -111
- package/src/materials/WireframeMaterial.js +0 -235
- package/src/web/CycleRaycast.js +0 -97
- package/src/web/Html.js +0 -417
- package/src/web/KeyboardControls.js +0 -101
- package/src/web/Loader.js +0 -98
- package/src/web/PresentationControls.js +0 -86
- package/src/web/ScrollControls.js +0 -246
- package/src/web/Select.js +0 -175
- package/src/web/View.js +0 -206
- package/src/web/pivotControls/AxisArrow.js +0 -202
- package/src/web/pivotControls/AxisRotator.js +0 -235
- package/src/web/pivotControls/PlaneSlider.js +0 -211
- package/src/web/pivotControls/context.js +0 -5
- package/src/web/pivotControls/index.js +0 -223
- package/src/web/useCursor.js +0 -12
- /package/{src/helpers → helpers}/glsl/DefaultSpotlightShadowShadows.glsl.js +0 -0
- /package/{src/helpers → helpers}/glsl/distort.vert.glsl.js +0 -0
- /package/{src/index.js → index.js} +0 -0
package/src/core/Example.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { Text3D } from './Text3D.js';
|
|
3
|
-
import { Center } from './Center.js';
|
|
4
|
-
|
|
5
|
-
/* eslint react-hooks/exhaustive-deps: 1 */
|
|
6
|
-
const Example = /*#__PURE__*/React.forwardRef(({
|
|
7
|
-
font,
|
|
8
|
-
color = '#cbcbcb',
|
|
9
|
-
bevelSize = 0.04,
|
|
10
|
-
debug = false,
|
|
11
|
-
children,
|
|
12
|
-
...props
|
|
13
|
-
}, fref) => {
|
|
14
|
-
const [counter, setCounter] = React.useState(0);
|
|
15
|
-
const incr = React.useCallback((x = 1) => setCounter(counter + x), [counter]);
|
|
16
|
-
const decr = React.useCallback((x = 1) => setCounter(counter - x), [counter]); // ref-API
|
|
17
|
-
|
|
18
|
-
const api = React.useMemo(() => ({
|
|
19
|
-
incr,
|
|
20
|
-
decr
|
|
21
|
-
}), [incr, decr]);
|
|
22
|
-
React.useImperativeHandle(fref, () => api, [api]);
|
|
23
|
-
return /*#__PURE__*/React.createElement("group", props, /*#__PURE__*/React.createElement(React.Suspense, {
|
|
24
|
-
fallback: null
|
|
25
|
-
}, /*#__PURE__*/React.createElement(Center, {
|
|
26
|
-
top: true,
|
|
27
|
-
cacheKey: JSON.stringify({
|
|
28
|
-
counter,
|
|
29
|
-
font
|
|
30
|
-
})
|
|
31
|
-
}, /*#__PURE__*/React.createElement(Text3D, {
|
|
32
|
-
bevelEnabled: true,
|
|
33
|
-
bevelSize: bevelSize,
|
|
34
|
-
font: font
|
|
35
|
-
}, debug ? /*#__PURE__*/React.createElement("meshNormalMaterial", {
|
|
36
|
-
wireframe: true
|
|
37
|
-
}) : /*#__PURE__*/React.createElement("meshStandardMaterial", {
|
|
38
|
-
color: color
|
|
39
|
-
}), counter))), children);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
export { Example };
|
package/src/core/FaceControls.js
DELETED
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
-
import * as THREE from 'three';
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import { forwardRef, useRef, useState, useCallback, useMemo, useImperativeHandle, useEffect, Suspense, useContext, createContext } from 'react';
|
|
5
|
-
import { useThree, useFrame } from '@react-three/fiber';
|
|
6
|
-
import { easing } from 'maath';
|
|
7
|
-
import { suspend, clear } from 'suspend-react';
|
|
8
|
-
import { useVideoTexture } from './useVideoTexture.js';
|
|
9
|
-
import { Facemesh } from './Facemesh.js';
|
|
10
|
-
import { useFaceLandmarker } from './FaceLandmarker.js';
|
|
11
|
-
|
|
12
|
-
// useVideoTexture 1st arg `src` type
|
|
13
|
-
function mean(v1, v2) {
|
|
14
|
-
return v1.clone().add(v2).multiplyScalar(0.5);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function localToLocal(objSrc, v, objDst) {
|
|
18
|
-
// see: https://discourse.threejs.org/t/object3d-localtolocal/51564
|
|
19
|
-
const v_world = objSrc.localToWorld(v);
|
|
20
|
-
return objDst.worldToLocal(v_world);
|
|
21
|
-
} //
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const FaceControlsContext = /*#__PURE__*/createContext({});
|
|
27
|
-
const FaceControls = /*#__PURE__*/forwardRef(({
|
|
28
|
-
camera,
|
|
29
|
-
autostart = true,
|
|
30
|
-
webcam = true,
|
|
31
|
-
webcamVideoTextureSrc,
|
|
32
|
-
manualUpdate = false,
|
|
33
|
-
manualDetect = false,
|
|
34
|
-
onVideoFrame,
|
|
35
|
-
smoothTime = 0.25,
|
|
36
|
-
offset = true,
|
|
37
|
-
offsetScalar = 80,
|
|
38
|
-
eyes = false,
|
|
39
|
-
eyesAsOrigin = true,
|
|
40
|
-
depth = 0.15,
|
|
41
|
-
debug = false,
|
|
42
|
-
facemesh,
|
|
43
|
-
makeDefault
|
|
44
|
-
}, fref) => {
|
|
45
|
-
var _faces$facialTransfor, _faces$faceBlendshape;
|
|
46
|
-
|
|
47
|
-
const scene = useThree(state => state.scene);
|
|
48
|
-
const defaultCamera = useThree(state => state.camera);
|
|
49
|
-
const set = useThree(state => state.set);
|
|
50
|
-
const get = useThree(state => state.get);
|
|
51
|
-
const explCamera = camera || defaultCamera;
|
|
52
|
-
const webcamApiRef = useRef(null);
|
|
53
|
-
const facemeshApiRef = useRef(null); //
|
|
54
|
-
// computeTarget()
|
|
55
|
-
//
|
|
56
|
-
// Compute `target` position and rotation for the camera (according to <Facemesh>)
|
|
57
|
-
//
|
|
58
|
-
// 1. 👀 either following the 2 eyes
|
|
59
|
-
// 2. 👤 or just the head mesh
|
|
60
|
-
//
|
|
61
|
-
|
|
62
|
-
const [target] = useState(() => new THREE.Object3D());
|
|
63
|
-
const [irisRightDirPos] = useState(() => new THREE.Vector3());
|
|
64
|
-
const [irisLeftDirPos] = useState(() => new THREE.Vector3());
|
|
65
|
-
const [irisRightLookAt] = useState(() => new THREE.Vector3());
|
|
66
|
-
const [irisLeftLookAt] = useState(() => new THREE.Vector3());
|
|
67
|
-
const computeTarget = useCallback(() => {
|
|
68
|
-
// same parent as the camera
|
|
69
|
-
target.parent = explCamera.parent;
|
|
70
|
-
const facemeshApi = facemeshApiRef.current;
|
|
71
|
-
|
|
72
|
-
if (facemeshApi) {
|
|
73
|
-
const {
|
|
74
|
-
outerRef,
|
|
75
|
-
eyeRightRef,
|
|
76
|
-
eyeLeftRef
|
|
77
|
-
} = facemeshApi;
|
|
78
|
-
|
|
79
|
-
if (eyeRightRef.current && eyeLeftRef.current) {
|
|
80
|
-
// 1. 👀
|
|
81
|
-
const {
|
|
82
|
-
irisDirRef: irisRightDirRef
|
|
83
|
-
} = eyeRightRef.current;
|
|
84
|
-
const {
|
|
85
|
-
irisDirRef: irisLeftDirRef
|
|
86
|
-
} = eyeLeftRef.current;
|
|
87
|
-
|
|
88
|
-
if (irisRightDirRef.current && irisLeftDirRef.current && outerRef.current) {
|
|
89
|
-
//
|
|
90
|
-
// position: mean of irisRightDirPos,irisLeftDirPos
|
|
91
|
-
//
|
|
92
|
-
irisRightDirPos.copy(localToLocal(irisRightDirRef.current, new THREE.Vector3(0, 0, 0), outerRef.current));
|
|
93
|
-
irisLeftDirPos.copy(localToLocal(irisLeftDirRef.current, new THREE.Vector3(0, 0, 0), outerRef.current));
|
|
94
|
-
target.position.copy(localToLocal(outerRef.current, mean(irisRightDirPos, irisLeftDirPos), explCamera.parent || scene)); //
|
|
95
|
-
// lookAt: mean of irisRightLookAt,irisLeftLookAt
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
irisRightLookAt.copy(localToLocal(irisRightDirRef.current, new THREE.Vector3(0, 0, 1), outerRef.current));
|
|
99
|
-
irisLeftLookAt.copy(localToLocal(irisLeftDirRef.current, new THREE.Vector3(0, 0, 1), outerRef.current));
|
|
100
|
-
target.lookAt(outerRef.current.localToWorld(mean(irisRightLookAt, irisLeftLookAt)));
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
// 2. 👤
|
|
104
|
-
if (outerRef.current) {
|
|
105
|
-
target.position.copy(localToLocal(outerRef.current, new THREE.Vector3(0, 0, 0), explCamera.parent || scene));
|
|
106
|
-
target.lookAt(outerRef.current.localToWorld(new THREE.Vector3(0, 0, 1)));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return target;
|
|
112
|
-
}, [explCamera, irisLeftDirPos, irisLeftLookAt, irisRightDirPos, irisRightLookAt, scene, target]); //
|
|
113
|
-
// update()
|
|
114
|
-
//
|
|
115
|
-
// Updating the camera `current` position and rotation, following `target`
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
const [current] = useState(() => new THREE.Object3D());
|
|
119
|
-
const update = useCallback(function (delta, target) {
|
|
120
|
-
if (explCamera) {
|
|
121
|
-
var _target;
|
|
122
|
-
|
|
123
|
-
(_target = target) !== null && _target !== void 0 ? _target : target = computeTarget();
|
|
124
|
-
|
|
125
|
-
if (smoothTime > 0) {
|
|
126
|
-
// damping current
|
|
127
|
-
const eps = 1e-9;
|
|
128
|
-
easing.damp3(current.position, target.position, smoothTime, delta, undefined, undefined, eps);
|
|
129
|
-
easing.dampE(current.rotation, target.rotation, smoothTime, delta, undefined, undefined, eps);
|
|
130
|
-
} else {
|
|
131
|
-
// instant
|
|
132
|
-
current.position.copy(target.position);
|
|
133
|
-
current.rotation.copy(target.rotation);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
explCamera.position.copy(current.position);
|
|
137
|
-
explCamera.rotation.copy(current.rotation);
|
|
138
|
-
}
|
|
139
|
-
}, [explCamera, computeTarget, smoothTime, current.position, current.rotation]); //
|
|
140
|
-
// detect()
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
const [faces, setFaces] = useState();
|
|
144
|
-
const faceLandmarker = useFaceLandmarker();
|
|
145
|
-
const detect = useCallback((video, time) => {
|
|
146
|
-
const faces = faceLandmarker == null ? void 0 : faceLandmarker.detectForVideo(video, time);
|
|
147
|
-
setFaces(faces);
|
|
148
|
-
}, [faceLandmarker]);
|
|
149
|
-
useFrame((_, delta) => {
|
|
150
|
-
if (!manualUpdate) {
|
|
151
|
-
update(delta);
|
|
152
|
-
}
|
|
153
|
-
}); // Ref API
|
|
154
|
-
|
|
155
|
-
const api = useMemo(() => Object.assign(Object.create(THREE.EventDispatcher.prototype), {
|
|
156
|
-
detect,
|
|
157
|
-
computeTarget,
|
|
158
|
-
update,
|
|
159
|
-
facemeshApiRef,
|
|
160
|
-
webcamApiRef,
|
|
161
|
-
// shorthands
|
|
162
|
-
play: () => {
|
|
163
|
-
var _webcamApiRef$current, _webcamApiRef$current2;
|
|
164
|
-
|
|
165
|
-
(_webcamApiRef$current = webcamApiRef.current) == null ? void 0 : (_webcamApiRef$current2 = _webcamApiRef$current.videoTextureApiRef.current) == null ? void 0 : _webcamApiRef$current2.texture.source.data.play();
|
|
166
|
-
},
|
|
167
|
-
pause: () => {
|
|
168
|
-
var _webcamApiRef$current3, _webcamApiRef$current4;
|
|
169
|
-
|
|
170
|
-
(_webcamApiRef$current3 = webcamApiRef.current) == null ? void 0 : (_webcamApiRef$current4 = _webcamApiRef$current3.videoTextureApiRef.current) == null ? void 0 : _webcamApiRef$current4.texture.source.data.pause();
|
|
171
|
-
}
|
|
172
|
-
}), [detect, computeTarget, update]);
|
|
173
|
-
useImperativeHandle(fref, () => api, [api]); //
|
|
174
|
-
// events callbacks
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
useEffect(() => {
|
|
178
|
-
const onVideoFrameCb = e => {
|
|
179
|
-
if (!manualDetect) detect(e.texture.source.data, e.time);
|
|
180
|
-
if (onVideoFrame) onVideoFrame(e);
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
api.addEventListener('videoFrame', onVideoFrameCb);
|
|
184
|
-
return () => {
|
|
185
|
-
api.removeEventListener('videoFrame', onVideoFrameCb);
|
|
186
|
-
};
|
|
187
|
-
}, [api, detect, faceLandmarker, manualDetect, onVideoFrame]); // `controls` global state
|
|
188
|
-
|
|
189
|
-
useEffect(() => {
|
|
190
|
-
if (makeDefault) {
|
|
191
|
-
const old = get().controls;
|
|
192
|
-
set({
|
|
193
|
-
controls: api
|
|
194
|
-
});
|
|
195
|
-
return () => set({
|
|
196
|
-
controls: old
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}, [makeDefault, api, get, set]);
|
|
200
|
-
const points = faces == null ? void 0 : faces.faceLandmarks[0];
|
|
201
|
-
const facialTransformationMatrix = faces == null ? void 0 : (_faces$facialTransfor = faces.facialTransformationMatrixes) == null ? void 0 : _faces$facialTransfor[0];
|
|
202
|
-
const faceBlendshapes = faces == null ? void 0 : (_faces$faceBlendshape = faces.faceBlendshapes) == null ? void 0 : _faces$faceBlendshape[0];
|
|
203
|
-
return /*#__PURE__*/React.createElement(FaceControlsContext.Provider, {
|
|
204
|
-
value: api
|
|
205
|
-
}, webcam && /*#__PURE__*/React.createElement(Suspense, {
|
|
206
|
-
fallback: null
|
|
207
|
-
}, /*#__PURE__*/React.createElement(Webcam, {
|
|
208
|
-
ref: webcamApiRef,
|
|
209
|
-
autostart: autostart,
|
|
210
|
-
videoTextureSrc: webcamVideoTextureSrc
|
|
211
|
-
})), /*#__PURE__*/React.createElement(Facemesh, _extends({
|
|
212
|
-
ref: facemeshApiRef
|
|
213
|
-
}, facemesh, {
|
|
214
|
-
points: points,
|
|
215
|
-
depth: depth,
|
|
216
|
-
facialTransformationMatrix: facialTransformationMatrix,
|
|
217
|
-
faceBlendshapes: faceBlendshapes,
|
|
218
|
-
eyes: eyes,
|
|
219
|
-
eyesAsOrigin: eyesAsOrigin,
|
|
220
|
-
offset: offset,
|
|
221
|
-
offsetScalar: offsetScalar,
|
|
222
|
-
debug: debug,
|
|
223
|
-
"rotation-z": Math.PI,
|
|
224
|
-
visible: debug
|
|
225
|
-
}), /*#__PURE__*/React.createElement("meshBasicMaterial", {
|
|
226
|
-
side: THREE.DoubleSide
|
|
227
|
-
})));
|
|
228
|
-
});
|
|
229
|
-
const useFaceControls = () => useContext(FaceControlsContext); //
|
|
230
|
-
// Webcam
|
|
231
|
-
//
|
|
232
|
-
|
|
233
|
-
const Webcam = /*#__PURE__*/forwardRef(({
|
|
234
|
-
videoTextureSrc,
|
|
235
|
-
autostart = true
|
|
236
|
-
}, fref) => {
|
|
237
|
-
const videoTextureApiRef = useRef(null);
|
|
238
|
-
const faceControls = useFaceControls();
|
|
239
|
-
const stream = suspend(async () => {
|
|
240
|
-
return !videoTextureSrc ? await navigator.mediaDevices.getUserMedia({
|
|
241
|
-
audio: false,
|
|
242
|
-
video: {
|
|
243
|
-
facingMode: 'user'
|
|
244
|
-
}
|
|
245
|
-
}) : Promise.resolve(null);
|
|
246
|
-
}, [videoTextureSrc]);
|
|
247
|
-
useEffect(() => {
|
|
248
|
-
faceControls.dispatchEvent({
|
|
249
|
-
type: 'stream',
|
|
250
|
-
stream
|
|
251
|
-
});
|
|
252
|
-
return () => {
|
|
253
|
-
stream == null ? void 0 : stream.getTracks().forEach(track => track.stop());
|
|
254
|
-
clear([videoTextureSrc]);
|
|
255
|
-
};
|
|
256
|
-
}, [stream, faceControls, videoTextureSrc]); // ref-api
|
|
257
|
-
|
|
258
|
-
const api = useMemo(() => ({
|
|
259
|
-
videoTextureApiRef
|
|
260
|
-
}), []);
|
|
261
|
-
useImperativeHandle(fref, () => api, [api]);
|
|
262
|
-
return /*#__PURE__*/React.createElement(Suspense, {
|
|
263
|
-
fallback: null
|
|
264
|
-
}, /*#__PURE__*/React.createElement(VideoTexture, {
|
|
265
|
-
ref: videoTextureApiRef,
|
|
266
|
-
src: videoTextureSrc || stream,
|
|
267
|
-
start: autostart
|
|
268
|
-
}));
|
|
269
|
-
}); //
|
|
270
|
-
// VideoTexture
|
|
271
|
-
//
|
|
272
|
-
|
|
273
|
-
const VideoTexture = /*#__PURE__*/forwardRef(({
|
|
274
|
-
src,
|
|
275
|
-
start
|
|
276
|
-
}, fref) => {
|
|
277
|
-
const texture = useVideoTexture(src, {
|
|
278
|
-
start
|
|
279
|
-
});
|
|
280
|
-
const video = texture.source.data;
|
|
281
|
-
const faceControls = useFaceControls();
|
|
282
|
-
const onVideoFrame = useCallback(time => {
|
|
283
|
-
faceControls.dispatchEvent({
|
|
284
|
-
type: 'videoFrame',
|
|
285
|
-
texture,
|
|
286
|
-
time
|
|
287
|
-
});
|
|
288
|
-
}, [texture, faceControls]);
|
|
289
|
-
useVideoFrame(video, onVideoFrame); // ref-api
|
|
290
|
-
|
|
291
|
-
const api = useMemo(() => ({
|
|
292
|
-
texture
|
|
293
|
-
}), [texture]);
|
|
294
|
-
useImperativeHandle(fref, () => api, [api]);
|
|
295
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
const useVideoFrame = (video, f) => {
|
|
299
|
-
// https://web.dev/requestvideoframecallback-rvfc/
|
|
300
|
-
// https://www.remotion.dev/docs/video-manipulation
|
|
301
|
-
useEffect(() => {
|
|
302
|
-
if (!video || !video.requestVideoFrameCallback) return;
|
|
303
|
-
let handle;
|
|
304
|
-
|
|
305
|
-
function callback(...args) {
|
|
306
|
-
f(...args);
|
|
307
|
-
handle = video.requestVideoFrameCallback(callback);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
video.requestVideoFrameCallback(callback);
|
|
311
|
-
return () => video.cancelVideoFrameCallback(handle);
|
|
312
|
-
}, [video, f]);
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
export { FaceControls, useFaceControls };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { useEffect, useContext, createContext } from 'react';
|
|
3
|
-
import { FilesetResolver as FilesetResolver_1, FaceLandmarker as FaceLandmarker_1 } from '../../node_modules/@mediapipe/tasks-vision/vision_bundle.js';
|
|
4
|
-
import { suspend, clear } from 'suspend-react';
|
|
5
|
-
|
|
6
|
-
/* eslint react-hooks/exhaustive-deps: 1 */
|
|
7
|
-
const FaceLandmarkerContext = /*#__PURE__*/createContext({});
|
|
8
|
-
const FaceLandmarkerDefaults = {
|
|
9
|
-
basePath: 'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0/wasm',
|
|
10
|
-
options: {
|
|
11
|
-
baseOptions: {
|
|
12
|
-
modelAssetPath: 'https://storage.googleapis.com/mediapipe-models/face_landmarker/face_landmarker/float16/1/face_landmarker.task',
|
|
13
|
-
delegate: 'GPU'
|
|
14
|
-
},
|
|
15
|
-
runningMode: 'VIDEO',
|
|
16
|
-
outputFaceBlendshapes: true,
|
|
17
|
-
outputFacialTransformationMatrixes: true
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
function FaceLandmarker({
|
|
21
|
-
basePath = FaceLandmarkerDefaults.basePath,
|
|
22
|
-
options = FaceLandmarkerDefaults.options,
|
|
23
|
-
children
|
|
24
|
-
}) {
|
|
25
|
-
const opts = JSON.stringify(options);
|
|
26
|
-
const faceLandmarker = suspend(async () => {
|
|
27
|
-
return await FilesetResolver_1.forVisionTasks(basePath).then(vision => FaceLandmarker_1.createFromOptions(vision, options));
|
|
28
|
-
}, [basePath, opts]);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
return () => {
|
|
31
|
-
faceLandmarker == null ? void 0 : faceLandmarker.close();
|
|
32
|
-
clear([basePath, opts]);
|
|
33
|
-
};
|
|
34
|
-
}, [faceLandmarker, basePath, opts]);
|
|
35
|
-
return /*#__PURE__*/React.createElement(FaceLandmarkerContext.Provider, {
|
|
36
|
-
value: faceLandmarker
|
|
37
|
-
}, children);
|
|
38
|
-
}
|
|
39
|
-
function useFaceLandmarker() {
|
|
40
|
-
return useContext(FaceLandmarkerContext);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { FaceLandmarker, FaceLandmarkerDefaults, useFaceLandmarker };
|