fix rotation with anchor (#9453)

This commit is contained in:
ChiaNing
2021-10-11 11:29:52 +08:00
committed by GitHub
parent 628257b8c8
commit 8d916b9816
2 changed files with 11 additions and 18 deletions
+7 -7
View File
@@ -43,6 +43,7 @@ import { NodeEventProcessor } from '../../core/scene-graph/node-event-processor'
const _vec2a = new Vec2();
const _vec2b = new Vec2();
const _vec3a = new Vec3();
const _mat4_temp = new Mat4();
const _matrix = new Mat4();
const _worldMatrix = new Mat4();
@@ -70,7 +71,7 @@ export class UITransform extends Component {
* 内容尺寸。
*/
@displayOrder(0)
@tooltip('i18n:ui_transform.conten_size')
@tooltip('i18n:ui_transform.content_size')
// @constget
get contentSize (): Readonly<Size> {
return this._contentSize;
@@ -256,14 +257,14 @@ export class UITransform extends Component {
// macro.UI_GPU_DRIVEN
declare public _rectDirty: boolean;
declare public _rectWithScale: Vec3;
declare public _anchorCache: Vec2;
declare public _anchorCache: Vec3;
constructor () {
super();
if (UI_GPU_DRIVEN) {
this._rectDirty = true;
this._rectWithScale = new Vec3();
this._anchorCache = new Vec2();
this._anchorCache = new Vec3();
}
}
@@ -684,16 +685,15 @@ export class UITransform extends Component {
}
}
public checkAndUpdateRect (scale: Vec3) {
public checkAndUpdateRect (rot: Quat, scale: Vec3) {
if (this._rectDirty) {
this._rectWithScale.x = scale.x * this.width;
this._rectWithScale.y = scale.y * this.height;
this._rectWithScale.z = scale.z;
const eulerZ = this.node.angle / 180 * Math.PI;
const lenX = (0.5 - this.anchorPoint.x) * this.width * scale.x;
const lenY = (0.5 - this.anchorPoint.y) * this.height * scale.y;
this._anchorCache.x = (lenX) * Math.cos(eulerZ) - (lenY) * Math.sin(eulerZ);
this._anchorCache.y = (lenX) * Math.sin(eulerZ) + (lenY) * Math.cos(eulerZ);
Vec3.transformQuat(this._anchorCache, _vec3a.set(lenX, lenY, 0), rot);
}
}
+4 -11
View File
@@ -76,12 +76,8 @@ export class DrawBatch2DGPU extends DrawBatch2D {
// @ts-expect-error using private members
const { _pos: t, _rot: r, _scale: s } = renderComp.node;
DrawBatch2DGPU._tempRect = renderComp.node._uiProps.uiTransformComp!;
DrawBatch2DGPU._tempRect.checkAndUpdateRect(s);
DrawBatch2DGPU._tempAnchor.set(DrawBatch2DGPU._tempRect._anchorCache);
DrawBatch2DGPU._tempPosition.x = t.x + DrawBatch2DGPU._tempAnchor.x;
DrawBatch2DGPU._tempPosition.y = t.y + DrawBatch2DGPU._tempAnchor.y;
DrawBatch2DGPU._tempPosition.z = t.z;
DrawBatch2DGPU._tempRect.checkAndUpdateRect(r, s);
Vec3.add(DrawBatch2DGPU._tempPosition, t, DrawBatch2DGPU._tempRect._anchorCache);
let mode = 0;
let fillType = 0;
@@ -167,11 +163,8 @@ export class DrawBatch2DGPU extends DrawBatch2D {
DrawBatch2DGPU._tempRect = node._uiProps.uiTransformComp!;
// @ts-expect-error using private members
const { _pos: t, _rot: r, _scale: s } = renderComp.node;
DrawBatch2DGPU._tempRect.checkAndUpdateRect(s);
DrawBatch2DGPU._tempAnchor.set(DrawBatch2DGPU._tempRect._anchorCache);
DrawBatch2DGPU._tempPosition.x = t.x + DrawBatch2DGPU._tempAnchor.x;
DrawBatch2DGPU._tempPosition.y = t.y + DrawBatch2DGPU._tempAnchor.y;
DrawBatch2DGPU._tempPosition.z = t.z;
DrawBatch2DGPU._tempRect.checkAndUpdateRect(r, s);
Vec3.add(DrawBatch2DGPU._tempPosition, t, DrawBatch2DGPU._tempRect._anchorCache);
if (node.hasChangedFlags & TransformBit.RS || DrawBatch2DGPU._tempRect._rectDirty) {
localBuffer.updateDataTRSByDirty(bufferInfo.instanceID, bufferInfo.UBOIndex,