我使用gdb
创建了一个立方体网格,并使用矩阵变换在顶点着色器中实现了网格旋转和缩放。这些矩阵都用作统一变量。在对网格进行位移更改后,网格成功地在场景中实现了位移,但是随后我使用THREE.BoxBufferGeometry
获取了javascript中网格的位置,发现网格的值未更改。{{1 }}未更新。
mesh.position
顶点着色器代码:
mesh.position
通过矩阵更改网格的位置:
material = new THREE.ShaderMaterial( {
vertexShader: document.getElementById( 'volumeVertex' ).textContent,
fragmentShader: document.getElementById( 'volumeFragment' ).textContent,
side: THREE.DoubleSide,
uniforms: {
rotateMatrix:{value:rotateMatrix.elements},
scaleMatrix:{value:scaleMatrix.elements},
translateMatrix:{value:translateMatrix.elements}
}
});
boxGeometry = new THREE.BoxBufferGeometry(2, 2, 2);
boxGeometry.doubleSided = true;
mesh = new THREE.Mesh( boxGeometry, material );
scene.add( mesh );
网格可以移动到<script id="volumeVertex" type="x-shader/x-vertex">
uniform mat4 rotateMatrix;
uniform mat4 translateMatrix;
uniform mat4 scaleMatrix;
void main()
{
vec4 newPos = translateMatrix * rotateMatrix *scaleMatrix * vec4(position,1.0);
gl_Position = projectionMatrix * modelViewMatrix * newPos;
}
,但是当我 var translateMatrix = new THREE.Matrix4();
translateMatrix.makeTranslation(5,5,5);
var preTransMatrix = new THREE.Matrix4();
preTransMatrix.elements = mesh.material.uniforms.translateMatrix.value;
translateMatrix.multiply(preTransMatrix);
mesh.material.uniforms.translateMatrix.value = translateMatrix.elements;
时,结果是初始位置(5,5,5)
。如何在矩阵移动后更新console.log(mesh.position.x,mesh.position.y,mesh.position.z)
? >