Skip to content

useVideoTexture ^3.2.0

A composable to easily use videos as textures in your meshes.

This composable is based on the Drei useVideoTexture

Usage

vue
<script setup lang="ts">
import { OrbitControls } from '@tresjs/cientos'
import { TresCanvas } from '@tresjs/core'
import TheModel from './TheModel.vue'
</script>

<template>
  <TresCanvas clear-color="#333">
    <TresPerspectiveCamera
      :position="[0, 5, 9]"
      :look-at="[0, 1, 0]"
    />
    <OrbitControls />
    <Suspense>
      <TheModel />
    </Suspense>
    <TresGridHelper />
    <TresAmbientLight />
  </TresCanvas>
</template>
vue
<script setup lang="ts">
import { ref } from 'vue'
import { Sphere, useVideoTexture } from '@tresjs/cientos'

const videoPath = 'https://raw.githubusercontent.com/'
  + 'Tresjs/assets/main/textures/video-textures/useVideoTexture.mp4'
const texture = ref()
texture.value = await useVideoTexture(videoPath, { loop: false })
</script>

<template>
   <Sphere :position="[0, 2, 0]">
      <TresMeshBasicMaterial :map="texture" />
    </Sphere>
</template>

Props

PropDescriptionDefault
srcPath to the video.undefined
unsuspendPath to the model file.loadedmetadata
crossOriginWhether to use CORS to fetch the related video.Anonymous
mutedWhether to set the audio silenced.true
loopAutomatically seek back to the start upon reaching the end of the video.true
startTo play to the video once loaded or not.true
playsInlineTo be play the video inline or not.true
  • Any other attribute for a <video> tag is accepted and will automatically set