vue 中使用three.js创建天空盒

阅读: 评论:0

vue 中使用three.js创建天空盒

vue 中使用three.js创建天空盒

首先要有六张图片对应天空盒的六个面





// 创建天空盒
addPanorama() {
//相应面对应相应图片const imgUrl = ['Image/Skybox03_textures/sanlan2.jpg','Image/Skybox03_textures/sanlan4.jpg','Image/Skybox03_textures/sanlan5.jpg','Image/Skybox03_textures/sanlan6.jpg','Image/Skybox03_textures/sanlan1.jpg','Image/Skybox03_textures/sanlan3.jpg']// 调用getTexturesFromAtlasFile() 给每个材质加上相应的图片const textures = TexturesFromAtlasFile(imgUrl, 6)const materials = []for (let i = 0; i < 6; i++) {// 创造六个面的材质materials.push(new THREE.MeshBasicMaterial({ map: textures[ i ] }))}
//创造包围盒const skyBox = new THREE.Mesh(new THREE.BoxBufferGeometry(1024, 1024, 1024), materials)// skyBox.position.set(0, 0, 0);ry.scale(1, 1, -1)scene.add(skyBox)
},// 六个面添加图片
getTexturesFromAtlasFile(atlasImgUrl, tilesNum) {const textures = []for (let i = 0; i < tilesNum; i++) {textures[ i ] = new THREE.Texture()}for (let i = 0; i < textures.length; i++) {const imageObj = new Image()imageObj.src = atlasImgUrl[load = () => {let context = ''// let tileWidth = imageObj.height;// let tileWidth = 5000;const canvas = ateElement('canvas')// const canvas: HTMLCanvasElement = this.canvasRef.nativeElement;  // 得到canvas 元素context = Context('2d')const canvasHeight = 720canvas.height = canvasHeightcanvas.width = canvasHeight// context.drawImage( imageObj, canvasHeight * i, 0, canvasHeight, canvasHeight, 0, 0, canvasHeight, canvasHeight );context.drawImage(imageObj, 0, 0, canvasHeight, canvasHeight)textures[ i ].image = canvastextures[ i ].needsUpdate = true}} return textures
},
调用addPanorama() 方法给场景添加天空盒

本文发布于:2024-01-27 18:28:37,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/17063513191893.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:天空   vue   js
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23