Compare commits

..

No commits in common. "d535fe82c0570345dd93f947bdc4247d2243a29e" and "feecb3a380c203b0cee970a3e99e5d53a8c820a0" have entirely different histories.

3 changed files with 27 additions and 81 deletions

View File

@ -233,19 +233,20 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
protected needUpdate: boolean = false;
/** 该元素的变换矩阵 */
transform: Transform = new Transform();
private _transform: Transform = new Transform();
/** 设置该渲染元素的模型变换矩阵 */
set transform(value: Transform) {
this._transform = value;
this.update();
}
/** 获取该渲染元素的模型变换矩阵 */
get transform() {
this.update();
return this._transform;
}
/** 该渲染元素的子元素 */
children: Set<RenderItem<ERenderItemEvent>> = new Set();
get x() {
return this.transform.x;
}
get y() {
return this.transform.y;
}
/** 渲染缓存信息 */
protected cache: MotaOffscreenCanvas2D = new MotaOffscreenCanvas2D();
/** 是否需要更新缓存 */
@ -266,7 +267,6 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
this.transformFallThrough = transformFallThrough;
this.type = type;
this.transform.bind(this);
this.cache.withGameScale(true);
}
@ -315,7 +315,7 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
if (this.hidden) return;
this.emit('beforeRender', transform);
this.needUpdate = false;
const tran = this.transformFallThrough ? transform : this.transform;
const tran = this.transformFallThrough ? transform : this._transform;
const ax = -this.anchorX * this.width;
const ay = -this.anchorY * this.height;

View File

@ -13,7 +13,7 @@ import { ElementNamespace, ComponentInternalInstance } from 'vue';
* Line BezierCurve QuadraticCurve
*/
export interface ILineProperty {
interface ILineProperty {
/** 线宽 */
lineWidth: number;
/** 线的虚线设置 */
@ -28,8 +28,8 @@ export interface ILineProperty {
miterLimit: number;
}
export interface IGraphicProperty extends ILineProperty {
/** 渲染模式,参考 {@link GraphicMode} */
interface IGraphicProperty extends ILineProperty {
/** 渲染模式,可选 {@link GraphicMode.Fill}, {@link GraphicMode.Stroke}, {@link GraphicMode.All} */
mode: GraphicMode;
/** 填充样式 */
fill: CanvasStyle;
@ -74,22 +74,10 @@ export abstract class GraphicItemBase
setLineOption(options: Partial<ILineProperty>) {}
/**
*
*
* @param style
*/
setFillStyle(style: CanvasStyle) {}
/**
*
* @param style
*/
setStrokeStyle(style: CanvasStyle) {}
/**
*
* @param rule
*/
setFillRule(rule: CanvasFillRule) {}
setStyle(style: CanvasStyle) {}
/**
*
@ -97,15 +85,6 @@ export abstract class GraphicItemBase
*/
setMode(mode: GraphicMode) {}
/**
*
* @param canvas
*/
protected setCanvasState(canvas: MotaOffscreenCanvas2D) {
const ctx = canvas.ctx;
ctx.fillStyle = this.fill; // 示例后面的都按这个写不需要save restore写完把这个注释删了
}
patchProp(
key: string,
prevValue: any,
@ -123,28 +102,18 @@ export class Rect extends GraphicItemBase {
protected render(
canvas: MotaOffscreenCanvas2D,
transform: Transform
): void {
const ctx = canvas.ctx;
this.setCanvasState(canvas);
ctx.beginPath();
ctx.rect(this.x, this.y, this.width, this.height);
): void {}
switch (this.mode) {
case GraphicMode.Fill:
ctx.fill(this.fillRule);
break;
case GraphicMode.Stroke:
ctx.stroke();
break;
case GraphicMode.FillAndStroke:
ctx.fill(this.fillRule);
ctx.stroke();
break;
case GraphicMode.StrokeAndFill:
ctx.stroke();
ctx.fill(this.fillRule);
break;
patchProp(
key: string,
prevValue: any,
nextValue: any,
namespace?: ElementNamespace,
parentComponent?: ComponentInternalInstance | null
): void {
switch (key) {
}
super.patchProp(key, prevValue, nextValue, namespace, parentComponent);
}
}

View File

@ -1,9 +1,5 @@
import { mat3, ReadonlyMat3, ReadonlyVec3, vec2, vec3 } from 'gl-matrix';
export interface ITransformUpdatable {
update(): void;
}
export class Transform {
mat: mat3 = mat3.create();
@ -16,17 +12,6 @@ export class Transform {
/** 有没有对这个Transform进行过修改用于优化常规表现 */
private modified: boolean = false;
/** 绑定的可更新元素 */
bindedObject?: ITransformUpdatable;
/**
* update
* @param obj
*/
bind(obj?: ITransformUpdatable) {
this.bindedObject = obj;
}
/**
*
*/
@ -48,7 +33,6 @@ export class Transform {
this.scaleX *= x;
this.scaleY *= y;
this.modified = true;
this.bindedObject?.update();
}
/**
@ -59,7 +43,6 @@ export class Transform {
this.x += x;
this.y += y;
this.modified = true;
this.bindedObject?.update();
}
/**
@ -73,7 +56,6 @@ export class Transform {
this.rad -= n * Math.PI * 2;
}
this.modified = true;
this.bindedObject?.update();
}
/**
@ -84,7 +66,6 @@ export class Transform {
this.scaleX = x;
this.scaleY = y;
this.modified = true;
this.bindedObject?.update();
}
/**
@ -95,7 +76,6 @@ export class Transform {
this.x = x;
this.y = y;
this.modified = true;
this.bindedObject?.update();
}
/**
@ -105,7 +85,6 @@ export class Transform {
mat3.rotate(this.mat, this.mat, rad - this.rad);
this.rad = rad;
this.modified = true;
this.bindedObject?.update();
}
/**
@ -131,7 +110,6 @@ export class Transform {
mat3.fromValues(a, b, 0, c, d, 0, e, f, 1)
);
this.calAttributes();
this.bindedObject?.update();
}
/**
@ -153,7 +131,6 @@ export class Transform {
) {
mat3.set(this.mat, a, b, 0, c, d, 0, e, f, 1);
this.calAttributes();
this.bindedObject?.update();
}
/**