【发布时间】:2022-08-02 16:04:45
【问题描述】:
我正在阅读有关如何在 three.js 文档中绘制线条的教程,使用的代码如下所示:
代码很好,没有问题。
<!DOCTYPE html>
<html>
<head>
<meta charset=\"utf-8\">
<title>My first three.js app</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<script src=\"///C:/Users/pc/Desktop/threejs_tutorial/build_threejs.html\"></script>
<script>
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 500 );
camera.position.set( 0, 0, 100 );
camera.lookAt( 0, 0, 0 );
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
//create a blue LineBasicMaterial
const material = new THREE.LineBasicMaterial( { color: 0x0000ff } );
const points = [];
points.push( new THREE.Vector3( - 10, 0, 0 ) );
points.push( new THREE.Vector3( 0, 10, 0 ) );
points.push( new THREE.Vector3( 10, 0, 0 ) );
const geometry = new THREE.BufferGeometry().setFromPoints( points );
const line = new THREE.Line( geometry, material );
scene.add( line );
renderer.render( scene, camera );
</script>
</body>
</html>
但引起我注意的是常量点 = [],点数.push和矢量3部分代码。
const points = [];
points.push( new THREE.Vector3( - 10, 0, 0 ) );
points.push( new THREE.Vector3( 0, 10, 0 ) );
points.push( new THREE.Vector3( 10, 0, 0 ) );
我不明白的功能常量点 = [];以及为什么使用它。
我不明白的功能点数.push以及为什么使用它。
Three.Vector3 命令看起来像是在 3D 平面中定位点。对于这种情况,它看起来像这样:
我们如何在 three.js 中可视化 Vector3,为什么输出看起来像这样?