gpt4 book ai didi

javascript - 三.js、WebGl对象定位

转载 作者:行者123 更新时间:2023-11-29 18:22:06 25 4
gpt4 key购买 nike

我正在使用 WebGl、Three.js。谁能告诉我我做错了什么?我试图获得我定制网格的位置。无论我尝试什么方法,每次我都得到值 (0,0,0)。

没有一种方法对我有用:

  • vector.getPositionFromMatrix(矩阵);
  • obj.matrix.getPosition().x

这是我的代码:

squareGeometry = new THREE.Geometry();
squareGeometry.vertices.push(new THREE.Vector3( this.x, this.y, this.z));
squareGeometry.vertices.push(new THREE.Vector3( this.x + this.w, this.y, this.z));
squareGeometry.vertices.push(new THREE.Vector3( this.x + this.w, this.y - this.h, this.z));
squareGeometry.vertices.push(new THREE.Vector3( this.x, this.y - this.h, this.z));
squareGeometry.faces.push(new THREE.Face4(0, 1, 2, 3));

squareMaterial = new THREE.MeshBasicMaterial({
color:this.color,
side:THREE.DoubleSide
});

squareMesh = new THREE.Mesh(squareGeometry, squareMaterial);

scene.add(squareMesh);
squareMesh.updateMatrix()
scene.updateMatrixWorld();

vec = new THREE.Vector3();
matrix = squareMesh.matrix;
localPosition = squareMesh.position; // 0,0,0
worldPosition = vec.getPositionFromMatrix( matrix ); // 0,0,0

// this also doesnt work
squareMesh.matrix.getPosition().x // 0

最佳答案

为什么说没用呢?

整个网格有 0,0,0 位置。要更改它,请尝试更改 squareMesh.position 属性。

关于javascript - 三.js、WebGl对象定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17471868/

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