three.js添加xyz坐标轴
时间: 2024-04-18 21:22:58 浏览: 122
Three.js是一个用于创建和渲染3D图形的JavaScript库。要在Three.js中添加XYZ坐标轴,可以按照以下步骤进行操作:
1. 导入Three.js库:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
```
2. 创建场景(Scene):
```javascript
const scene = new THREE.Scene();
```
3. 创建相机(Camera):
```javascript
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
```
4. 创建渲染器(Renderer)并设置大小:
```javascript
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
```
5. 创建坐标轴(AxisHelper):
```javascript
const axisHelper = new THREE.AxisHelper(3); // 参数为坐标轴长度
scene.add(axisHelper);
```
6. 渲染场景:
```javascript
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
```
这样就可以在Three.js中添加XYZ坐标轴了。
阅读全文