getBoundingBoxToWorld获取坐标错误

  • Creator 版本:
    3.7.2
  • 目标平台:
    所有浏览器
  • 重现方式:
    创建个空节点,getBoundingBoxToWorld获取的坐标正常;空节点下创建个子节点,再获取空节点包围盒坐标就错了,y值最高到项目设置坐标的一半,就不往上增加了,只增加height值
  • 之前哪个版本是正常的:
    3.6.3
  • 重现概率:
    必现

在获取世界包围盒的节点上加个父节点,只移动父节点坐标,子节点不动,获取的就正常了,直接获取xy坐标,移动节点超过项目大小的一半就错了

分析了两个版本的代码,终于发现了问题,

3.7.3
public getBoundingBoxToWorld () {
if (this.node.parent) {
const m = this.node.parent.getWorldMatrix();
return this.getBoundingBoxTo(m);
}
return this.getBoundingBox();
}
3.6.3
public getBoundingBoxToWorld () {
if (this.node.parent) {
this.node.parent.getWorldMatrix(_worldMatrix);
return this.getBoundingBoxTo(_worldMatrix);
}
return this.getBoundingBox();
}

3.6.3是把矩阵对象传进去的,
3.7.3用了一个const变量传进去的

getBoundingBoxTo 主要实现里面的问题

Mat4.multiply(_worldMatrix, parentMat, _matrix);
rect.transformMat4(_worldMatrix);

    // query child's BoundingBox
    if (!this.node.children || this.node.children.length === 0) {
        return rect;
    }

    const locChildren = this.node.children;
    for (const child of locChildren) {
        if (child && child.active) {
            const uiTransform = child.getComponent(UITransform);
            if (uiTransform) {
                const childRect = uiTransform.getBoundingBoxTo(parentMat);
                if (childRect) {
                    Rect.union(rect, rect, childRect);
                }
            }
        }
    }

下面计算子节点rect的时候,传进去的必须是当前的世界矩阵,而不是传进来的那个parentMat,
这样应该就没问题了

2赞

这么久了,引擎组能不能修复一下?

很多人都发现了, 他们压根儿不管啊, 整个一副爱用不用的样子