我已经从文件中加载了一些坐标
var koloader = new THREE.FileLoader();
koloader.load('Koordinate.txt',
function ( data ) {
// output the text to the console
const kord = data.split('\n').map(line =>line.trim()).map(line => line
.split(' ') // split by ' '
.map(parseFloat),line => line
.split(' ') // split by ' '
.map(parseFloat)) // and parse the parts to numbers
.map(([ x, y, z]) => ({ x, y, z }));
kord [0] .x是我文件中的第一个x,kord [0] .y是我文件中的第一个y ..
我想设置我的vector3的循环
for( let i = 0; i < kord.length; i++){
//missing
}
我尝试过vec3t.set(kord[i].x,kord[i].y,kord[i].z);
,但这会覆盖我的数据
..我想要这样:
Vector3 [0] .x = 1,Vector3 [0] .y = 4,Vector3 [0] .z = 0,
Vector3 [1] .x = 5,..我要访问每个Vector3
答案 0 :(得分:0)
类似这样的东西:
var vectors;
var koloader = new THREE.FileLoader();
koloader.load('https://cywarr.github.io/small-shop/example.txt', (data) => {
vectors = data.split('\n').map(line => {
let l = line.split(' ');
return new THREE.Vector3(parseFloat(l[0]), parseFloat(l[1]), parseFloat(l[2]));
}).filter((vector) => {
return typeof vector !== 'undefined'
});
console.log(vectors[0].x, vectors[0].y, vectors[0].z);
console.log(vectors[1].x, vectors[1].y, vectors[1].z);
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/100/three.min.js"></script>
此后,vectors
变量将是THREE.Vector3()
的数组,因此您将能够通过索引和字段名称(x,y,z)访问它们的值。