@remotion/three 4.0.387 → 4.0.389
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/dist/cjs/index.d.ts +9 -5
- package/dist/cjs/index.js +5 -7
- package/dist/esm/index.mjs +216 -7
- package/package.json +5 -5
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
export { ThreeCanvas, ThreeCanvasProps } from './ThreeCanvas';
|
|
2
|
+
import type { UseOffthreadVideoTextureOptions as UseOffthreadVideoTextureOptionsType } from './use-offthread-video-texture';
|
|
3
|
+
import { useOffthreadVideoTexture as useOffthreadVideoTextureType } from './use-offthread-video-texture';
|
|
4
|
+
import type { UseVideoTextureOptions as UseVideoTextureOptionsType } from './use-video-texture';
|
|
2
5
|
/**
|
|
3
6
|
* @deprecated useOffthreadVideoTexture has been deprecated.
|
|
4
7
|
* Use the approach documented at https://remotion.dev/docs/videos/as-threejs-texture instead.
|
|
5
8
|
*/
|
|
6
|
-
|
|
9
|
+
declare const useOffthreadVideoTexture: typeof useOffthreadVideoTextureType;
|
|
7
10
|
/**
|
|
8
11
|
* @deprecated useOffthreadVideoTexture has been deprecated.
|
|
9
12
|
* Use the approach documented at https://remotion.dev/docs/videos/as-threejs-texture instead.
|
|
10
13
|
*/
|
|
11
|
-
|
|
14
|
+
type UseOffthreadVideoTextureOptions = UseOffthreadVideoTextureOptionsType;
|
|
12
15
|
/**
|
|
13
16
|
* @deprecated useVideoTexture has been deprecated.
|
|
14
17
|
* Use the approach documented at https://remotion.dev/docs/videos/as-threejs-texture instead.
|
|
15
18
|
*/
|
|
16
|
-
|
|
19
|
+
declare const useVideoTexture: (videoRef: React.RefObject<HTMLVideoElement | null>) => import("three").VideoTexture | null;
|
|
17
20
|
/**
|
|
18
21
|
* @deprecated useVideoTexture has been deprecated.
|
|
19
|
-
* Use the approach documented at https://remotion.dev/docs/videos/as-threejs-texture
|
|
22
|
+
* Use the approach documented at https://remotion.dev/docs/videos/as-threejs-texture instead.
|
|
20
23
|
*/
|
|
21
|
-
|
|
24
|
+
type UseVideoTextureOptions = UseVideoTextureOptionsType;
|
|
25
|
+
export { useOffthreadVideoTexture, UseOffthreadVideoTextureOptions, useVideoTexture, UseVideoTextureOptions, };
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,19 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useVideoTexture = exports.useOffthreadVideoTexture = exports.ThreeCanvas = void 0;
|
|
4
4
|
var ThreeCanvas_1 = require("./ThreeCanvas");
|
|
5
5
|
Object.defineProperty(exports, "ThreeCanvas", { enumerable: true, get: function () { return ThreeCanvas_1.ThreeCanvas; } });
|
|
6
|
+
const use_offthread_video_texture_1 = require("./use-offthread-video-texture");
|
|
7
|
+
const use_video_texture_1 = require("./use-video-texture");
|
|
6
8
|
/**
|
|
7
9
|
* @deprecated useOffthreadVideoTexture has been deprecated.
|
|
8
10
|
* Use the approach documented at https://remotion.dev/docs/videos/as-threejs-texture instead.
|
|
9
11
|
*/
|
|
10
|
-
const useOffthreadVideoTexture =
|
|
11
|
-
throw new Error('useOffthreadVideoTexture has been deprecated. Please see https://remotion.dev/docs/videos/as-threejs-texture for alternatives.');
|
|
12
|
-
};
|
|
12
|
+
const useOffthreadVideoTexture = use_offthread_video_texture_1.useOffthreadVideoTexture;
|
|
13
13
|
exports.useOffthreadVideoTexture = useOffthreadVideoTexture;
|
|
14
14
|
/**
|
|
15
15
|
* @deprecated useVideoTexture has been deprecated.
|
|
16
|
-
* Use the approach documented at https://remotion.dev/docs/videos/as-threejs-texture
|
|
16
|
+
* Use the approach documented at https://remotion.dev/docs/videos/as-threejs-texture instead.
|
|
17
17
|
*/
|
|
18
|
-
const useVideoTexture =
|
|
19
|
-
throw new Error('useVideoTexture has been deprecated. Please see https://remotion.dev/docs/videos/as-threejs-texture for alternatives.');
|
|
20
|
-
};
|
|
18
|
+
const useVideoTexture = use_video_texture_1.useVideoTexture;
|
|
21
19
|
exports.useVideoTexture = useVideoTexture;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
7
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
8
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
9
|
+
for (let key of __getOwnPropNames(mod))
|
|
10
|
+
if (!__hasOwnProp.call(to, key))
|
|
11
|
+
__defProp(to, key, {
|
|
12
|
+
get: () => mod[key],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
18
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
19
|
+
}) : x)(function(x) {
|
|
20
|
+
if (typeof require !== "undefined")
|
|
21
|
+
return require.apply(this, arguments);
|
|
22
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
23
|
+
});
|
|
24
|
+
|
|
1
25
|
// src/ThreeCanvas.tsx
|
|
2
26
|
import { Canvas, useThree } from "@react-three/fiber";
|
|
3
27
|
import { useCallback, useEffect, useLayoutEffect as useLayoutEffect2, useState } from "react";
|
|
@@ -98,16 +122,201 @@ var ThreeCanvas = (props) => {
|
|
|
98
122
|
})
|
|
99
123
|
});
|
|
100
124
|
};
|
|
125
|
+
// src/use-offthread-video-texture.ts
|
|
126
|
+
import { useCallback as useCallback2, useLayoutEffect as useLayoutEffect3, useMemo, useState as useState2 } from "react";
|
|
127
|
+
import {
|
|
128
|
+
Internals as Internals2,
|
|
129
|
+
useCurrentFrame as useCurrentFrame2,
|
|
130
|
+
useDelayRender as useDelayRender3,
|
|
131
|
+
useRemotionEnvironment as useRemotionEnvironment2,
|
|
132
|
+
useVideoConfig
|
|
133
|
+
} from "remotion";
|
|
134
|
+
import { NoReactInternals as NoReactInternals2 } from "remotion/no-react";
|
|
135
|
+
var useInnerVideoTexture = ({
|
|
136
|
+
playbackRate,
|
|
137
|
+
src,
|
|
138
|
+
transparent,
|
|
139
|
+
toneMapped,
|
|
140
|
+
delayRenderRetries,
|
|
141
|
+
delayRenderTimeoutInMilliseconds
|
|
142
|
+
}) => {
|
|
143
|
+
const frame = useCurrentFrame2();
|
|
144
|
+
const { fps } = useVideoConfig();
|
|
145
|
+
const mediaStartsAt = Internals2.useMediaStartsAt();
|
|
146
|
+
const currentTime = useMemo(() => {
|
|
147
|
+
return NoReactInternals2.getExpectedMediaFrameUncorrected({
|
|
148
|
+
frame,
|
|
149
|
+
playbackRate,
|
|
150
|
+
startFrom: -mediaStartsAt
|
|
151
|
+
}) / fps;
|
|
152
|
+
}, [frame, playbackRate, mediaStartsAt, fps]);
|
|
153
|
+
const offthreadVideoFrameSrc = useMemo(() => {
|
|
154
|
+
return NoReactInternals2.getOffthreadVideoSource({
|
|
155
|
+
currentTime,
|
|
156
|
+
src,
|
|
157
|
+
transparent,
|
|
158
|
+
toneMapped
|
|
159
|
+
});
|
|
160
|
+
}, [toneMapped, currentTime, src, transparent]);
|
|
161
|
+
const [textLoaderPromise] = useState2(() => import("three/src/loaders/TextureLoader.js"));
|
|
162
|
+
const [imageTexture, setImageTexture] = useState2(null);
|
|
163
|
+
const { delayRender, continueRender, cancelRender } = useDelayRender3();
|
|
164
|
+
const fetchTexture = useCallback2(() => {
|
|
165
|
+
const imageTextureHandle = delayRender("fetch offthread video frame", {
|
|
166
|
+
retries: delayRenderRetries ?? undefined,
|
|
167
|
+
timeoutInMilliseconds: delayRenderTimeoutInMilliseconds ?? undefined
|
|
168
|
+
});
|
|
169
|
+
let textureLoaded = null;
|
|
170
|
+
let cleanedUp = false;
|
|
171
|
+
textLoaderPromise.then((loader) => {
|
|
172
|
+
new loader.TextureLoader().loadAsync(offthreadVideoFrameSrc).then((texture) => {
|
|
173
|
+
textureLoaded = texture;
|
|
174
|
+
if (cleanedUp) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
setImageTexture(texture);
|
|
178
|
+
continueRender(imageTextureHandle);
|
|
179
|
+
}).catch((err) => {
|
|
180
|
+
cancelRender(err);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
return () => {
|
|
184
|
+
cleanedUp = true;
|
|
185
|
+
textureLoaded?.dispose();
|
|
186
|
+
continueRender(imageTextureHandle);
|
|
187
|
+
};
|
|
188
|
+
}, [
|
|
189
|
+
offthreadVideoFrameSrc,
|
|
190
|
+
textLoaderPromise,
|
|
191
|
+
delayRenderRetries,
|
|
192
|
+
delayRenderTimeoutInMilliseconds,
|
|
193
|
+
continueRender,
|
|
194
|
+
delayRender,
|
|
195
|
+
cancelRender
|
|
196
|
+
]);
|
|
197
|
+
useLayoutEffect3(() => {
|
|
198
|
+
const cleanup = fetchTexture();
|
|
199
|
+
return () => {
|
|
200
|
+
cleanup();
|
|
201
|
+
};
|
|
202
|
+
}, [offthreadVideoFrameSrc, fetchTexture]);
|
|
203
|
+
return imageTexture;
|
|
204
|
+
};
|
|
205
|
+
function useOffthreadVideoTexture({
|
|
206
|
+
src,
|
|
207
|
+
playbackRate = 1,
|
|
208
|
+
transparent = false,
|
|
209
|
+
toneMapped = true,
|
|
210
|
+
delayRenderRetries,
|
|
211
|
+
delayRenderTimeoutInMilliseconds
|
|
212
|
+
}) {
|
|
213
|
+
if (!src) {
|
|
214
|
+
throw new Error("src must be provided to useOffthreadVideoTexture");
|
|
215
|
+
}
|
|
216
|
+
const env = useRemotionEnvironment2();
|
|
217
|
+
const { isRendering, isClientSideRendering } = env;
|
|
218
|
+
if (isClientSideRendering) {
|
|
219
|
+
throw new Error("useOffthreadVideoTexture() cannot be used in client-side rendering.");
|
|
220
|
+
}
|
|
221
|
+
if (!isRendering) {
|
|
222
|
+
throw new Error("useOffthreadVideoTexture() can only be used during rendering. Use useRemotionEnvironment().isRendering to render it conditionally.");
|
|
223
|
+
}
|
|
224
|
+
return useInnerVideoTexture({
|
|
225
|
+
playbackRate,
|
|
226
|
+
src,
|
|
227
|
+
transparent,
|
|
228
|
+
toneMapped,
|
|
229
|
+
delayRenderRetries,
|
|
230
|
+
delayRenderTimeoutInMilliseconds
|
|
231
|
+
});
|
|
232
|
+
}
|
|
101
233
|
|
|
102
|
-
// src/
|
|
103
|
-
|
|
104
|
-
|
|
234
|
+
// src/use-video-texture.ts
|
|
235
|
+
import React3, { useCallback as useCallback3, useEffect as useEffect2, useState as useState3 } from "react";
|
|
236
|
+
import {
|
|
237
|
+
useCurrentFrame as useCurrentFrame3,
|
|
238
|
+
useDelayRender as useDelayRender4,
|
|
239
|
+
useRemotionEnvironment as useRemotionEnvironment3
|
|
240
|
+
} from "remotion";
|
|
241
|
+
var warned = false;
|
|
242
|
+
var warnAboutRequestVideoFrameCallback = () => {
|
|
243
|
+
if (warned) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
warned = true;
|
|
247
|
+
console.warn("Browser does not support requestVideoFrameCallback. Cannot display video.");
|
|
105
248
|
};
|
|
106
|
-
var useVideoTexture = () => {
|
|
107
|
-
|
|
249
|
+
var useVideoTexture = (videoRef) => {
|
|
250
|
+
const { delayRender, continueRender, cancelRender } = useDelayRender4();
|
|
251
|
+
const [loaded] = useState3(() => {
|
|
252
|
+
if (typeof document === "undefined") {
|
|
253
|
+
return 0;
|
|
254
|
+
}
|
|
255
|
+
return delayRender(`Waiting for texture in useVideoTexture() to be loaded`);
|
|
256
|
+
});
|
|
257
|
+
const environment = useRemotionEnvironment3();
|
|
258
|
+
const { isClientSideRendering } = environment;
|
|
259
|
+
if (isClientSideRendering) {
|
|
260
|
+
throw new Error("useVideoTexture() cannot be used in client side rendering.");
|
|
261
|
+
}
|
|
262
|
+
const [videoTexture, setVideoTexture] = useState3(null);
|
|
263
|
+
const [vidText] = useState3(() => import("three/src/textures/VideoTexture.js"));
|
|
264
|
+
const frame = useCurrentFrame3();
|
|
265
|
+
const onReady = useCallback3(() => {
|
|
266
|
+
vidText.then(({ VideoTexture }) => {
|
|
267
|
+
if (!videoRef.current) {
|
|
268
|
+
throw new Error("Video not ready");
|
|
269
|
+
}
|
|
270
|
+
const vt = new VideoTexture(videoRef.current);
|
|
271
|
+
videoRef.current.width = videoRef.current.videoWidth;
|
|
272
|
+
videoRef.current.height = videoRef.current.videoHeight;
|
|
273
|
+
setVideoTexture(vt);
|
|
274
|
+
continueRender(loaded);
|
|
275
|
+
}).catch((err) => {
|
|
276
|
+
cancelRender(err);
|
|
277
|
+
});
|
|
278
|
+
}, [loaded, vidText, videoRef, continueRender, cancelRender]);
|
|
279
|
+
React3.useLayoutEffect(() => {
|
|
280
|
+
if (!videoRef.current) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (videoRef.current.readyState >= 2) {
|
|
284
|
+
onReady();
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
videoRef.current.addEventListener("loadeddata", () => {
|
|
288
|
+
onReady();
|
|
289
|
+
}, { once: true });
|
|
290
|
+
}, [loaded, onReady, videoRef]);
|
|
291
|
+
React3.useEffect(() => {
|
|
292
|
+
const { current } = videoRef;
|
|
293
|
+
if (!current) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (!current.requestVideoFrameCallback) {
|
|
297
|
+
warnAboutRequestVideoFrameCallback();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const ready = () => {};
|
|
301
|
+
current.requestVideoFrameCallback(ready);
|
|
302
|
+
}, [frame, loaded, videoRef]);
|
|
303
|
+
useEffect2(() => {
|
|
304
|
+
return () => {
|
|
305
|
+
continueRender(loaded);
|
|
306
|
+
};
|
|
307
|
+
}, [loaded, continueRender]);
|
|
308
|
+
if (typeof HTMLVideoElement === "undefined" || !HTMLVideoElement.prototype.requestVideoFrameCallback) {
|
|
309
|
+
continueRender(loaded);
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
return videoTexture;
|
|
108
313
|
};
|
|
314
|
+
|
|
315
|
+
// src/index.ts
|
|
316
|
+
var useOffthreadVideoTexture2 = useOffthreadVideoTexture;
|
|
317
|
+
var useVideoTexture2 = useVideoTexture;
|
|
109
318
|
export {
|
|
110
|
-
useVideoTexture,
|
|
111
|
-
useOffthreadVideoTexture,
|
|
319
|
+
useVideoTexture2 as useVideoTexture,
|
|
320
|
+
useOffthreadVideoTexture2 as useOffthreadVideoTexture,
|
|
112
321
|
ThreeCanvas
|
|
113
322
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"url": "https://github.com/remotion-dev/remotion/tree/main/packages/three"
|
|
4
4
|
},
|
|
5
5
|
"name": "@remotion/three",
|
|
6
|
-
"version": "4.0.
|
|
6
|
+
"version": "4.0.389",
|
|
7
7
|
"description": "Include React Three Fiber components in a Remotion video",
|
|
8
8
|
"main": "dist/cjs/index.js",
|
|
9
9
|
"types": "dist/cjs/index.d.ts",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"url": "https://github.com/remotion-dev/remotion/issues"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"remotion": "4.0.
|
|
24
|
+
"remotion": "4.0.389"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@react-three/fiber": ">=8.0.0",
|
|
28
28
|
"react": ">=16.8.0",
|
|
29
29
|
"react-dom": ">=16.8.0",
|
|
30
30
|
"three": ">=0.137.0",
|
|
31
|
-
"remotion": "4.0.
|
|
31
|
+
"remotion": "4.0.389"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@react-three/fiber": "9.2.0",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"@types/web": "0.0.166",
|
|
38
38
|
"react": "19.2.3",
|
|
39
39
|
"react-dom": "19.2.3",
|
|
40
|
-
"remotion": "4.0.
|
|
40
|
+
"remotion": "4.0.389",
|
|
41
41
|
"three": "0.178.0",
|
|
42
|
-
"@remotion/eslint-config-internal": "4.0.
|
|
42
|
+
"@remotion/eslint-config-internal": "4.0.389",
|
|
43
43
|
"eslint": "9.19.0"
|
|
44
44
|
},
|
|
45
45
|
"keywords": [
|