Three贴图Textures实例

编程入门 行业动态 更新时间:2024-10-03 10:32:20

Three贴图Textures<a href=https://www.elefans.com/category/jswz/34/1771375.html style=实例"/>

Three贴图Textures实例

基础环境搭建:

新建文件夹,github clone目录下拷贝贴图文件:

纹理功能一:CubeTextureLoader生成天空盒子:

立方纹理(CubeTexture):创建一个由6张图片所组成的纹理对象。

function initScene() {scene = new THREE.Scene()const urls = ['textures/cube/pisa/px.png','textures/cube/pisa/nx.png','textures/cube/pisa/py.png','textures/cube/pisa/ny.png','textures/cube/pisa/pz.png','textures/cube/pisa/nz.png',]cubeTexture = new THREE.CubeTextureLoader().load(urls)scene.background = cubeTexture  //texture:给scene生成一个skybox效果
}

纹理功能二:赋予网格模型实现类似反光效果

function initMeshes() {const geometry = new THREE.SphereGeometry(0.1, 64, 64)const material = new THREE.MeshBasicMaterial({ color: 0xffffff, envMap: cubeTexture });for (let i = 0; i < count; i++) {mesh = new THREE.Mesh(geometry, material)mesh.position.x = Math.random() * 10 - 5mesh.position.y = Math.random() * 10 - 5mesh.position.z = Math.random() * 10 - 5scene.add(mesh)spheres.push(mesh)}
}

让模型动起来:

    let timer = Date.now() * 0.0001for (let i = 0; i < count; i++) {const sphere = spheres[i]sphere.position.x = 5 * Math.cos(timer + i)sphere.position.y = 5 * Math.sin(timer + i * 1.1)}

更多推荐

Three贴图Textures实例

本文发布于:2024-02-27 22:00:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1766287.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实例   贴图   Textures

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!