three.js制作南北半球
时间: 2023-11-28 22:45:47 浏览: 73
以下是使用Three.js制作南北半球的步骤:
1.创建场景和相机
```javascript
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
```
2.创建半球体
```javascript
var geometry = new THREE.SphereGeometry( 500, 60, 40 );
var material = new THREE.MeshBasicMaterial( {color: 0xffff00} );
material.side = THREE.BackSide; // 只渲染半球体的背面
var hemisphere = new THREE.Mesh( geometry, material );
scene.add( hemisphere );
```
3.创建光源
```javascript
var light = new THREE.PointLight(0xffffff, 1, 0);
light.position.set(0, 0, 0);
scene.add(light);
```
4.渲染场景
```javascript
function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
render();
```
完整代码如下:
```javascript
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var geometry = new THREE.SphereGeometry( 500, 60, 40 );
var material = new THREE.MeshBasicMaterial( {color: 0xffff00} );
material.side = THREE.BackSide;
var hemisphere = new THREE.Mesh( geometry, material );
scene.add( hemisphere );
var light = new THREE.PointLight(0xffffff, 1, 0);
light.position.set(0, 0, 0);
scene.add(light);
camera.position.z = 5;
function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
render();
```
阅读全文