gpt4 book ai didi

javascript - 关联数组查找(来自 Three.js 中的代码)

转载 作者:行者123 更新时间:2023-11-29 20:03:18 24 4
gpt4 key购买 nike

我正在查看 three.js 中的代码,特别是用于创建球体的 THREE.SphereGeometry 方法: https://github.com/mrdoob/three.js/blob/master/src/extras/geometries/SphereGeometry.js

有两组循环 - 我正在看第二组。

我的问题是:创建了一个数组数组,称为顶点。在此数组中添加了对象数组。

稍后,使用索引检索单个对象,具体为:

var v1 = vertices[ y ][ x + 1 ];

然后,就在这下面,似乎再次引用了该对象,但使用的是这种语法:

var n1 = this.vertices[ v1 ].clone().normalize();

尽我所能,这对我来说似乎是一个错误.. this.vertices[v1] 不会返回 undefined 吗?

最佳答案

认为 造成这种混淆的是 this.verticesvertices。它们实际上是两种不同的结构。

// first loop
for (...) {
/* ... */

// this.verticies will have every vertex
this.vertices.push( vertex );

verticesRow.push( this.vertices.length - 1 );
/* ... */
}

// notice we pushed a row of vertices to `vertices` not `this.verticies`
vertices.push( verticesRow );


// second loop
for (...) for (...) {
// grab the vertex from the local list
var v1 = vertices[ y ][ x + 1 ];

// use it to grab something from the object's list
var n1 = this.vertices[ v1 ].clone().normalize();
}

关于javascript - 关联数组查找(来自 Three.js 中的代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13202468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com