Created
August 9, 2018 06:51
-
-
Save xhsdnn/d6701983fc2ba809fc088991f0682202 to your computer and use it in GitHub Desktop.
three.js中创建辅助坐标系
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 绘制坐标系 | |
* scene —— 要绘制坐标系的场景(let scene = new THREE.Scene()) | |
*/ | |
function drawCoordSystem(scene) { | |
// 创建三个坐标轴的几何模型 | |
let geometryX = new THREE.Geometry(); | |
geometryX.vertices.push( | |
new THREE.Vector3(-5, 0, 0), | |
new THREE.Vector3(5, 0, 0), | |
new THREE.Vector3(4.8, 0.2, 0) | |
); | |
let geometryY = new THREE.Geometry(); | |
geometryY.vertices.push( | |
new THREE.Vector3(0, -5, 0), | |
new THREE.Vector3(0, 5, 0), | |
new THREE.Vector3(0.2, 4.8, 0) | |
); | |
let geometryZ = new THREE.Geometry(); | |
geometryZ.vertices.push( | |
new THREE.Vector3(0, 0, -5), | |
new THREE.Vector3(0, 0, 5), | |
new THREE.Vector3(0, 0.2, 4.8) | |
); | |
// 选择材料 | |
let materialX = new THREE.LineBasicMaterial({ color: 0xff0000 }); | |
let materialY = new THREE.LineBasicMaterial({ color: 0x00ff00 }); | |
let materialZ = new THREE.LineBasicMaterial({ color: 0x0000ff }); | |
// 创建对象 | |
let axisX = new THREE.Line(geometryX, materialX); | |
let axisY = new THREE.Line(geometryY, materialY); | |
let axisZ = new THREE.Line(geometryZ, materialZ); | |
// 添加到场景中 | |
scene.add(axisX); | |
scene.add(axisY); | |
scene.add(axisZ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment