为什么我不能在我的多维数组中声明一个位置?

Why can't I declare a position in my multidimensional array?

我正在尝试制作 L 系统的 3d 版本。但是我不能在我的多维数组中声明元素。当我调试时,我看到元素保持不变。 我调用例如 arraygrowth [0][1] = 100; 但是该位置的元素保持 0

let arraygrowth =[];
arraygrowth.push(new THREE.Vector3(0,0,0)); 
arraygrowth.push(new THREE.Vector3(0,0,0));
arraygrowth.push(new THREE.Vector3(0,0,0));

arraygrowth [0][1] = 100;
arraygrowth [1][1] = 100;
arraygrowth [2][1] = 100;

清理你的代码,你基本上是这样做的:

let arraygrowth =[];
arraygrowth.push(new THREE.Vector3(0,0,0)); 
arraygrowth.push(new THREE.Vector3(0,0,0));
arraygrowth.push(new THREE.Vector3(0,0,0));

arraygrowth [0][1] = 100;
arraygrowth [1][1] = 100;
arraygrowth [2][1] = 100;

这等同于 new THREE.Vector3(0, 0, 0)[1] = 100; ... 这没有意义。这不是您更改 Vector3 的 x, y, z 参数的方式。当你调用 arraygrowth[0] 时,你得到一个 Vector3,现在你必须使用它的一个属性或方法来分配你想要的值。例如:

arraygrowth[0].y = 100; // Sets y value
arraygrowth[0].setY(100); // Also sets y value
arraygrowth[0].setComponent(1) = 100; // Also sets y value

https://threejs.org/docs/#api/en/math/Vector3.setComponent