首页 > 其他分享 >THREE.JS中 CubeTextureLoader 使用避坑

THREE.JS中 CubeTextureLoader 使用避坑

时间:2024-05-25 21:22:04浏览次数:24  
标签:CubeTextureLoader sea2 THREE jpg JS 避坑 cubeTexture

最近在跟着教程学THREE.JS,毕竟在现在的前端开发市场上,THREE.JS太火爆了。

今天学到“纹理”这一块的时候,跟着教程敲代码,发现自己的没有正确显示,百思不得其解,打开控制台发现,如下WARNING:

localhost/:1 [.WebGL-000060380A191C00] GL_INVALID_VALUE: Each cubemap face must have equal width and height.

然后突然意识到,自己的图片是网上随机找的,而CubeTextureLoader需要每一个面的素材都是“正方形”!

示例代码如下:

// 创建场景
const scene = new THREE.Scene();

// 添加雾;

// scene.fog = new THREE.Fog(0xcccccc, 10, 16);

// 创建立体的纹理,左右上下前后
const cubeTexture = new THREE.CubeTextureLoader();
cubeTexture.setPath("/");

scene.background = cubeTexture.load([
  "sea.jpg",
  "sea2.jpg",
  "sea2.jpg",
  "sea4.jpg",
  "sea2.jpg",
  "sea2.jpg",
]);

 

标签:CubeTextureLoader,sea2,THREE,jpg,JS,避坑,cubeTexture
From: https://www.cnblogs.com/aursordev/p/18213024

相关文章

  • 基于three.js的Instanced Draw+LOD+Frustum Cull的改进实现
    大家好,本文在上文的基础上,优化了InstancedDraw+LOD+FrustumCull的性能,性能提升了3倍以上关键词:three.js、InstancedDraw、大场景、LOD、FrustumCull、优化、Web3D、WebGL、开源上文:three.js使用InstancedDraw+FrustumCull+LOD来渲染大场景(开源)相对于上文的改进点相对于......
  • three-gltf-viewer 3d模型展示
    因为工作需要开发了一个通用的3d模型模板展示 内容包含背景颜色、环境光、自动旋转、以及资源监视器,只需要把模型传进去即可。然后我发布到npm上面。目前更新到了1.0.5,喜欢的话就去下载吧。 需要源码的联系我。 yarn add three-gltf-viewer main.js使用importglt......
  • three.js之动画
    动画<canvasid="mainCanvas"></canvas><scripttype="importmap">{"imports":{"three":"./js/build/three.module.js","three/addons/":"./js/jsm/"......
  • three.js基础之Material
    MeshBasicMaterial<canvasid="mainCanvas"></canvas><scripttype="importmap">{"imports":{"three":"./js/build/three.module.js","three/addons/":"./js......
  • three.js之加载模型
    加载各种模型<canvasid="mainCanvas"></canvas><scripttype="importmap">{"imports":{"three":"./js/build/three.module.js","three/addons/":"./js/jsm/"......
  • three.js之Group
    Group<canvasid="mainCanvas"></canvas><scripttype="importmap">{"imports":{"three":"./js/build/three.module.js","three/addons/":"./js/jsm/"......
  • The three little pigs
    Onadarkandwindynight,I,thebigbadwolf,embarkedonmyhuntforthethreelittlepigs.Followingtheirdistinctscent,Itraversedthedenseforestinsearchoftheirwhereabouts.Eventually,Istumbleduponthefirstpig'sstrawhouseinan......
  • threejs饼图
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width,initial-scale=1.0"/><title>Cake</title>......
  • 利用three.js七步实现VR看房
    这里我用的是vue框架:首先下载安装three.js=>npminstallthree;然后import*asTHREEfrom'three'导入组件中;接下来就可以在组件中编写我们的three.js代码创建场景:constscene=newTHREE.Scene()创建相机:constcamera=newTHREE.PerspectiveCamera( 70,//视角度......
  • three.js基础之mesh属性
    mesh之位置、缩放、平移、旋转属性<canvasid="mesh-properties"></canvas><scripttype="importmap">{"imports":{"three":"./js/build/three.module.js","three/addons/":&quo......