three.js水星纹理贴图
时间: 2023-11-16 15:00:49 浏览: 148
Three.js中实现水星纹理贴图的步骤如下:
```javascript
// 创建场景
var scene = new THREE.Scene();
// 创建相机
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
// 创建渲染器
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// 创建水星球体
var geometry = new THREE.SphereGeometry(1, 32, 32);
var texture = new THREE.TextureLoader().load('mercury.jpg');
var material = new THREE.MeshBasicMaterial({ map: texture });
var mercury = new THREE.Mesh(geometry, material);
scene.add(mercury);
// 渲染场景
function animate() {
requestAnimationFrame(animate);
mercury.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();
```
其中,`THREE.TextureLoader().load('mercury.jpg')`用于加载水星的纹理贴图,`THREE.MeshBasicMaterial({ map: texture })`用于将纹理贴图应用到水星球体上。
阅读全文