从对象复制THREE.js矩阵 [英] copy THREE.js matrix from object

查看:167
本文介绍了从对象复制THREE.js矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Three.js中对多个矩阵进行相同的处理.我有一个Object3D,在执行此操作时,我得到了正确的矩阵到console.log:

i need to to same matrix mulitiply in Three.js. I had an Object3D and i get the right matrix to console.log when doing this:

  console.log (scene.getObjectByName( "Pointer" ).matrix)

结果就像:

T…E.Matrix4 {elements:Float32Array [16]} 元素:Float32Array [16] 0:11:02:03:04:05:16:07:08:09:0 0:11 1:0 12:-150 13:0 14:0 0 15:1

T…E.Matrix4 {elements: Float32Array[16]} elements: Float32Array[16] 0: 11: 02: 03: 04: 05: 16: 07: 08: 09: 0 10: 11 1: 0 12: -150 13: 0 14: 0 15: 1

请注意,第12个元素的值是-150(在obj.translationX(-150)之后).

note here that the 12th element have the value -150 (after a obj.translationX(-150)).

      var newMat = new THREE.Matrix4();
      console.log(scene.getObjectByName("Pointer").matrix.elements)
      // output: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
      newMat = newMat.copy(scene.getObjectByName("Pointer").matrix);
      console.log(newMat);
      // output:elements: Float32Array[16] 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1

返回一个恒等矩阵(表示第12个元素是:0)

giving back an identiy matrix (meaning the 12th element is: 0)

这是怎么了?

更新:在renderloop中... newMat.copy(...)..正常!

UPDATE: inside the renderloop... newMat.copy(...).. works fine!

推荐答案

three.js在根据对象的位置,比例和旋转度渲染页面时将更新对象矩阵.因此,当您设置对象矩阵时,它将更快地被重写. 要手动设置对象矩阵,必须将autoupdate设置为false.

three.js will update the object matrix when it render the page according the object position, scale, rotation. So when you set the object matrix, it will sooner be rewrited. To manually set the object matrix, you have to set autoupdate to false.

object.matrixAutoUpdate = false;

然后使用您的代码.

  var newMat = new THREE.Matrix4();
  console.log(scene.getObjectByName("Pointer").matrix.elements)
  // output: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
  newMat = newMat.copy(scene.getObjectByName("Pointer").matrix);
  console.log(newMat);

这篇关于从对象复制THREE.js矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆