From 18c30d212f834de76ed8e8e05a1edbd55635aef2 Mon Sep 17 00:00:00 2001 From: YangLei Date: Thu, 9 Sep 2021 17:24:22 +0800 Subject: [PATCH] add VideoTexture --- src/materials/VideoTexture.ts | 22 ++++++++++++++++++++++ src/materials/index.ts | 1 + 2 files changed, 23 insertions(+) create mode 100644 src/materials/VideoTexture.ts diff --git a/src/materials/VideoTexture.ts b/src/materials/VideoTexture.ts new file mode 100644 index 0000000..dd2a716 --- /dev/null +++ b/src/materials/VideoTexture.ts @@ -0,0 +1,22 @@ +import { defineComponent, watch } from 'vue' +import { VideoTexture } from 'three' +import Texture from './Texture' + +export default defineComponent({ + extends: Texture, + props: { + videoId: { + type: String, + required: true, + }, + }, + created() { + watch(() => this.videoId, this.refreshTexture) + }, + methods: { + createTexture() { + const video = document.getElementById(this.videoId) as HTMLVideoElement + return new VideoTexture(video) + }, + }, +}) diff --git a/src/materials/index.ts b/src/materials/index.ts index c2403bd..7051713 100644 --- a/src/materials/index.ts +++ b/src/materials/index.ts @@ -5,5 +5,6 @@ export { default as SubSurfaceMaterial } from './SubSurfaceMaterial' export { default as Texture } from './Texture' export { default as CubeTexture } from './CubeTexture' +export { default as VideoTexture } from './VideoTexture' export type { MaterialPublicInterface } from './Material'