写在前面:
1. Three.js中的纹理功能
2.照片纹理
2.1 将图片作为纹理应用到几何体对象上
2.2 示例
3. 纹理属性调整
3.1 重复(Repeat)
3.2 偏移(Offset)
3.3 旋转(Rotation)
3.4 翻转(flip)
3.5 缩放(scale)
3.6 环境映射(envMap)
3.7 透明度(opacity)
3.8 混合模式(blending)
3.9 反射率(reflectivity)
3.10 各向异性(anisotropy)
4 示例演示
// 创建场景、摄像机和渲染器等代码省略
// 创建球体几何体
const geometry = new THREE.SphereGeometry(5, 32, 32);
// 加载地球贴图
const textureLoader = new THREE.TextureLoader();
const texture = textureLoader.load('earth.jpg', () => {
// 创建材质对象并应用纹理
const material = new THREE.MeshBasicMaterial({ map: texture });
// 创建球体对象并应用材质
const sphere = new THREE.Mesh(geometry, material);
scene.add(sphere);
// 渲染场景等代码省略
// 调整纹理属性
texture.repeat.set(2, 2); // 重复纹理两次
texture.offset.set(0.5, 0.5); // 平移纹理的位置
texture.rotation = Math.PI / 4; // 旋转纹理
// 更新场景渲染
function animate() {
// 更新纹理属性
texture.rotation += 0.01;
// 渲染场景
renderer.render(scene, camera);
// 循环调用动画函数
requestAnimationFrame(animate);
}
// 开始执行动画
animate();