vue3+three.js给glb模型设置视频贴图

1.在网上下载一个显示屏或者自己画一个,在blender中设置好显示屏的Mesh,UV设置好,这样方便代码中添加纹理贴图。可以让美术在建模软件中,先随机设置一张图片作为纹理,验证UV是否设置好

关于如何 在blender中给模型设置UV贴图百度很多的

typescript 复制代码
// 视频
import * as THREE from "three"
// 加载建筑模型
import {
  GLTFLoader
} from 'three/examples/jsm/loaders/GLTFLoader.js'
import {
  DRACOLoader
} from 'three/examples/jsm/loaders/DRACOLoader'
export function getVideo(th) {
  console.log('th', th) // this
  var that = th
  const loader = new GLTFLoader().setPath('/models/')
  const dracoLoader = new DRACOLoader()
  dracoLoader.setDecoderPath('/draco/')
  loader.setDRACOLoader(dracoLoader)
  loader.load("SP.glb", function (gltf) {
    gltf.scene.position.set(-50, 0, 90); // 模型位置
    gltf.scene.rotation.y = Math.PI; // 180度等于PI弧度
    gltf.scene.traverse(function (child) {
      console.log('child', child)
      child.castShadow = true;
      child.receiveShadow = true;
      // 下面的这几个判断,就是用来给模型添加视频的
      if (child.name === '显示屏') {
        let video = document.createElement('video');
        video.src = "/public/data/123.mp4";
        video.muted = true;
        video.autoplay = "autoplay";
        video.loop = true;
        video.play();
        const videoTexture = new THREE.VideoTexture(video);
        const videoMaterial = new THREE.MeshBasicMaterial({
          map: videoTexture
        });
        console.log('videoMaterial', videoMaterial)
        child.material = videoMaterial; 
      }
    });
    // 设置模型的大小
    const modelScale = 2.5; // 定义模型的缩放比例
    gltf.scene.scale.set(modelScale, modelScale, modelScale);
    that.scene.add(gltf.scene);
  });
}

结果

相关推荐
NiNg_1_2349 分钟前
Vue3 Pinia持久化存储
开发语言·javascript·ecmascript
读心悦10 分钟前
如何在 Axios 中封装事件中心EventEmitter
javascript·http
神之王楠43 分钟前
如何通过js加载css和html
javascript·css·html
余生H1 小时前
前端的全栈混合之路Meteor篇:关于前后端分离及与各框架的对比
前端·javascript·node.js·全栈
流烟默1 小时前
Vue中watch监听属性的一些应用总结
前端·javascript·vue.js·watch
茶卡盐佑星_1 小时前
meta标签作用/SEO优化
前端·javascript·html
与衫2 小时前
掌握嵌套子查询:复杂 SQL 中 * 列的准确表列关系
android·javascript·sql
金灰2 小时前
HTML5--裸体回顾
java·开发语言·前端·javascript·html·html5
Promise5202 小时前
总结汇总小工具
前端·javascript
Манго нектар2 小时前
JavaScript for循环语句
开发语言·前端·javascript