fix(editor): resolve sub-node coordinate misalignment via hierarchical basis change
This commit is contained in:
parent
c400f050c1
commit
3a2d9465dd
@ -242,9 +242,12 @@ public:
|
||||
if (instance) {
|
||||
filament::math::mat4f localTransform = tm.getTransform(instance);
|
||||
|
||||
// 转换为 GLM 矩阵
|
||||
glm::mat4 matrix;
|
||||
std::memcpy(glm::value_ptr(matrix), &localTransform[0][0], sizeof(float) * 16);
|
||||
glm::mat4 filamentMatrix;
|
||||
std::memcpy(glm::value_ptr(filamentMatrix), &localTransform[0][0], sizeof(float) * 16);
|
||||
|
||||
glm::mat4 R_minus90X = glm::rotate(glm::mat4(1.0f), glm::radians(-90.0f), {1, 0, 0});
|
||||
glm::mat4 R_plus90X = glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), {1, 0, 0});
|
||||
glm::mat4 matrix = R_minus90X * filamentMatrix * R_plus90X;
|
||||
|
||||
// 拆解矩阵
|
||||
glm::vec3 scale;
|
||||
@ -517,6 +520,15 @@ private:
|
||||
const auto& transform = gameObject.GetComponent<MetaCoreTransformComponent>();
|
||||
glm::mat4 matrix = MetaCoreBuildTransformMatrix(transform);
|
||||
|
||||
// 【关键修复】:如果当前 entity 是子节点(即不是顶级映射的 pivotEntity)
|
||||
// 由于它的父级(assetRoot)带有了 -90X 旋转,我们必须对子节点应用基变换来抵消这个旋转。
|
||||
// 公式:L_filament = R(90X) * L_ecs * R(-90X)
|
||||
if (LoadedAssets_.count(gameObject.GetId()) == 0) {
|
||||
glm::mat4 R_plus90X = glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), {1, 0, 0});
|
||||
glm::mat4 R_minus90X = glm::rotate(glm::mat4(1.0f), glm::radians(-90.0f), {1, 0, 0});
|
||||
matrix = R_plus90X * matrix * R_minus90X;
|
||||
}
|
||||
|
||||
tm.setTransform(instance, *reinterpret_cast<const filament::math::mat4f*>(glm::value_ptr(matrix)));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user