2016-03-28 91 views
0

我需要在Three.js中多元化相同的矩陣。我有一個Object3D和這樣做,當我到達CONSOLE.LOG正確的矩陣:從對象複製THREE.js矩陣

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

結果是這樣的:

的... E.Matrix4 {元素:Float32Array [16]} 元素: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)之後)。

 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 

回饋的identiy矩陣(指第12要素爲:0)

請告訴我是錯在這裏?

更新:裏面的renderloop ... newMat.copy(...)..工作正常!

+0

是你對象名稱指針調用updateMatrix首先我看到這就像THREE.Object3D –

+0

容器對象我試圖對象ubdateMatrix()...但是這didnt幫助。是指針是一個容器對象..我放在loadedJsonObject – vagus1975

+0

child_clone.applyMatrix(容器[i] .object3d.children [j] .parent.matrix); //這是不好的 child_clone.applyMatrix(container [i] .object3d.children [j] .parent.parent.matrix); child_clone.applyMatrix(container [i] .object3d.children [j] .parent.parent.parent.matrix); child_clone.applyMatrix(container [i] .object3d.children [j] .parent.parent.parent.parent.matrix); child_clone.updateMatrixWorld() 道德是將矩陣應用到您的孩子容器從父母,然後updateMatrixWorld(實際上我的矩陣根本沒有更新的原因是我創建我自己的對象,而不是three.js Object3D容器 –

回答

0

three.js將根據對象的位置,比例,旋轉渲染頁面時更新對象矩陣。所以當你設置對象矩陣時,它會很快被重寫。 要手動設置對象矩陣,您必須將autoupdate設置爲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); 
+0

不要設置'matrixAutoUpdate = false',除非你熟悉庫的內部工作並理解這樣做的後果。 – WestLangley