【发布时间】:2021-06-11 18:47:56
【问题描述】:
我正在尝试使用 Three.JS 在 GLB 模型网格中添加视频播放器。虽然这可以使用 VideoTexture 完成,但我正在尝试添加视频播放器默认拥有的所有控件。
这是使用 VideoTexture 的代码 sn-p:
let video = document.createElement( 'video' );
video.loop = true;
video.crossOrigin = 'anonymous';
video.muted = "muted";
video.load();
video.src = videoD;
video.controls = true
let texture = new THREE.VideoTexture( video );
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.LinearFilter;
texture.format = THREE.RGBFormat;
let material = new THREE.MeshBasicMaterial( { map : texture } );
// and then use this material as the material for the glb child mesh
上述方法的问题是我无法添加控件。我目前正在使用反应,所以另一种方式 是使用 HTML 组件并尝试加载它来代替网格,这是使用 react refs 的方法
<>
<primitive ref={stall_ref} object={glb.scene} />
<Html>
<ReactPlayer ref={react_player_ref} id="widget2" url='https://www.youtube.com/watch?v=ysz5S6PUM-U' />
</Html>
</>
然后使用这个 ref 修改视频播放器位置
// I'm actually not sure what I'm doing here
react_player_ref.current.position.copy(meshChild.position)
react_player_ref.current.quaternion.copy(meshChild.quaternion)
react_player_ref.current.matrix.copy(meshChild.matrix)
react_player_ref.current.matrixWorld.copy(meshChild.matrixWorld)
react_player_ref.current.scale.copy(meshChild.scale)
react_player_ref.current.rotation.set(meshChild.rotation)
【问题讨论】:
标签: reactjs three.js react-three-fiber