我正在尝试计算Three.JS中的变换,老实说,我是3D数学的新手。
在Three.JS中有3x3和4x4矩阵类,但没有4x3。
目标:我想了解如何在4x3 * 4x3矩阵上进行乘法运算。
我有一组输入和正确的输出。我通过使用python得到它,因为有一个名为Noesis
的库,它具有4x3矩阵的乘法。
问题是库调用python二进制文件,所以我看不到源代码。
python中的代码只是:modelSpaceMat = boneMat * frameMat
以下是正确数据集的示例:
boneMat= (
(0.0, 0.0, 1.0),
(0.0, 1.0, 0.0),
(-1.0, 0.0, 0.0),
(0.0, 32.29199981689453, -3.2665998935699463)
)
frameMat= (
(0.6425124406814575, -0.06018795818090439, 0.7639083862304688),
(-0.003379624802619219, 0.9966778755187988, 0.08136376738548279),
(-0.7662678360939026, -0.05486864596605301, 0.640174925327301),
(4.438972473144531, -1.4769394397735596, 3.863013744354248)
)
modelSpaceMat=(
(-0.7639083862304688, -0.06018795818090439, 0.6425124406814575),
(-0.08136376738548279, 0.9966778755187988, -0.003379624802619219),
(-0.640174925327301, -0.05486864596605301, -0.7662678360939026),
(-1.1457012760729413e-07, 30.441999435424805, 9.592490357590577e-08)
)
boneMat= (
(1.0, 0.0, 0.0),
(0.0, 1.0, 0.0),
(0.0, 0.0, 1.0),
(0.0, 0.007000000216066837, -3.2665998935699463)
)
frameMat= (
(1.0000004768371582, 2.3320662876358256e-06, -1.4419805665966123e-05),
(2.817355607476202e-06, 0.9999991059303284, -3.3202520626218757e-06),
(1.5038006495160516e-05, -2.133270072590676e-06, 1.0000003576278687),
(-0.0015083501348271966, 0.02300064079463482, 3.266691207885742)
)
modelSpaceMat= (
(1.0000004768371582, 2.3320662876358256e-06, -1.4419805665966123e-05),
(2.817355607476202e-06, 0.9999991059303284, -3.3202520626218757e-06),
(1.5038006495160516e-05, -2.133270072590676e-06, 1.0000003576278687),
(-0.0014612301019951701, 0.030011480674147606, 9.013115777634084e-05)
)
现在我希望能够用javascript做到这一点。
问题:
python模块Noesis有这一行:
def __mul__(self, other):
if isinstance(other, (NoeMat43, list, tuple)):
return noesis.mat43Mul(self, other)
elif isinstance(other, NoeVec3):
return noesis.mat43TransformPoint(self, other)
elif isinstance(other, NoeVec4):
return noesis.mat43TransformVec4(self, other)
else:
return NoeMat43([self.mat43[0]*other, self.mat43[1]*other, self.mat43[2]*other, self.mat43[3]*other])
我无法找到noesis.mat43Mul
的源代码。
测试 Tamas Hegedus 回答:
var boneMat = new THREE.Matrix4().copy(_bone.userData.modelMatrix);
var frameMat = new THREE.Matrix4();
frameMat.set(
bone.rotationMatrix[0], bone.rotationMatrix[1], bone.rotationMatrix[2], bone.positionVector[0],
bone.rotationMatrix[3], bone.rotationMatrix[4], bone.rotationMatrix[5], bone.positionVector[1],
bone.rotationMatrix[6], bone.rotationMatrix[7], bone.rotationMatrix[8], bone.positionVector[2],
0.0, 0.0, 0.0, 1.0
);
var modelSpaceMat = new THREE.Matrix4();
modelSpaceMat.multiplyMatrices(boneMat, frameMatrix);
console.log(boneMat, frameMat, modelSpaceMat);
但是这个modelSpaceMat
的结果与python库的modelSpaceMat
有点不同。就像python中(-1.1457012760729413e-07, 30.441999435424805, 9.592490357590577e-08)
的位置部分一样,但在javascript中是3.863013744354248, 30.815059661865234, -7.705572128295898
。
为什么?