移除 transform
This commit is contained in:
111
demo/libs/framework/framework.d.ts
vendored
111
demo/libs/framework/framework.d.ts
vendored
@@ -150,7 +150,6 @@ declare abstract class Component extends egret.DisplayObjectContainer {
|
||||
onRemovedFromEntity(): void;
|
||||
onEnabled(): void;
|
||||
onDisabled(): void;
|
||||
onEntityTransformChanged(comp: ComponentTransform): void;
|
||||
update(): void;
|
||||
debugRender(): void;
|
||||
registerComponent(): void;
|
||||
@@ -193,7 +192,6 @@ declare class Entity extends egret.DisplayObjectContainer {
|
||||
update(): void;
|
||||
onAddedToScene(): void;
|
||||
onRemovedFromScene(): void;
|
||||
onTransformChanged(comp: ComponentTransform): void;
|
||||
destroy(): void;
|
||||
}
|
||||
declare class Scene extends egret.DisplayObjectContainer {
|
||||
@@ -240,70 +238,6 @@ declare class SceneManager {
|
||||
static render(): void;
|
||||
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
|
||||
}
|
||||
declare enum DirtyType {
|
||||
clean = 0,
|
||||
positionDirty = 1,
|
||||
scaleDirty = 2,
|
||||
rotationDirty = 3
|
||||
}
|
||||
declare enum ComponentTransform {
|
||||
position = 0,
|
||||
scale = 1,
|
||||
rotation = 2
|
||||
}
|
||||
declare class Transform {
|
||||
readonly entity: Entity;
|
||||
private _children;
|
||||
private _parent;
|
||||
private _localPosition;
|
||||
private _localRotation;
|
||||
private _localScale;
|
||||
private _translationMatrix;
|
||||
private _rotationMatrix;
|
||||
private _scaleMatrix;
|
||||
private _worldTransform;
|
||||
private _worldToLocalTransform;
|
||||
private _worldInverseTransform;
|
||||
private _rotation;
|
||||
private _position;
|
||||
private _scale;
|
||||
private _localTransform;
|
||||
private _hierachyDirty;
|
||||
private _localDirty;
|
||||
private _localPositionDirty;
|
||||
private _localScaleDirty;
|
||||
private _localRotationDirty;
|
||||
private _positionDirty;
|
||||
private _worldToLocalDirty;
|
||||
private _worldInverseDirty;
|
||||
readonly childCount: number;
|
||||
constructor(entity: Entity);
|
||||
getChild(index: number): Transform;
|
||||
readonly worldInverseTransform: Matrix2D;
|
||||
readonly localToWorldTransform: Matrix2D;
|
||||
readonly worldToLocalTransform: Matrix2D;
|
||||
parent: Transform;
|
||||
setParent(parent: Transform): this;
|
||||
rotation: number;
|
||||
localRotation: number;
|
||||
position: Vector2;
|
||||
localPosition: Vector2;
|
||||
scale: Vector2;
|
||||
localScale: Vector2;
|
||||
rotationDegrees: number;
|
||||
localRotationDegrees: number;
|
||||
setLocalScale(scale: Vector2): this;
|
||||
setScale(scale: Vector2): this;
|
||||
setLocalRotationDegrees(degrees: number): this;
|
||||
setLocalRotation(radians: number): this;
|
||||
setRotation(radians: number): this;
|
||||
setRotationDegrees(degrees: number): this;
|
||||
setLocalPosition(localPosition: Vector2): this;
|
||||
setPosition(position: Vector2): this;
|
||||
setDirty(dirtyFlagType: DirtyType): void;
|
||||
roundPosition(): void;
|
||||
updateTransform(): void;
|
||||
}
|
||||
declare class Camera extends Component {
|
||||
private _zoom;
|
||||
private _origin;
|
||||
@@ -347,26 +281,6 @@ declare class ComponentPool<T extends PooledComponent> {
|
||||
obtain(): T;
|
||||
free(component: T): void;
|
||||
}
|
||||
declare class Mesh extends Component {
|
||||
private _verts;
|
||||
private _primitiveCount;
|
||||
private _triangles;
|
||||
private _topLeftVertPosition;
|
||||
private _width;
|
||||
private _height;
|
||||
initialize(): void;
|
||||
setVertPosition(positions: Vector2[]): this;
|
||||
setTriangles(triangles: number[]): this;
|
||||
recalculateBounds(): this;
|
||||
render(): void;
|
||||
}
|
||||
declare class VertexPosition {
|
||||
position: Vector2;
|
||||
constructor(position: Vector2);
|
||||
}
|
||||
declare class PolygonMesh extends Mesh {
|
||||
constructor(points: Vector2[], arePointsCCW?: boolean);
|
||||
}
|
||||
declare abstract class PooledComponent extends Component {
|
||||
abstract reset(): any;
|
||||
}
|
||||
@@ -386,10 +300,15 @@ declare abstract class RenderableComponent extends PooledComponent implements IR
|
||||
protected onBecameInvisible(): void;
|
||||
abstract render(camera: Camera): any;
|
||||
isVisibleFromCamera(camera: Camera): boolean;
|
||||
onEntityTransformChanged(comp: ComponentTransform): void;
|
||||
}
|
||||
declare class ScreenSpaceCamera extends Camera {
|
||||
protected updateMatrixes(): void;
|
||||
declare class Mesh extends RenderableComponent {
|
||||
private _mesh;
|
||||
constructor();
|
||||
setTexture(texture: egret.Texture): Mesh;
|
||||
onAddedToEntity(): void;
|
||||
onRemovedFromEntity(): void;
|
||||
render(camera: Camera): void;
|
||||
reset(): void;
|
||||
}
|
||||
declare class Sprite {
|
||||
texture2D: egret.Texture;
|
||||
@@ -446,7 +365,6 @@ declare abstract class Collider extends Component {
|
||||
collidesWith(collider: Collider, motion: Vector2): CollisionResult;
|
||||
onAddedToEntity(): void;
|
||||
onRemovedFromEntity(): void;
|
||||
onEntityTransformChanged(comp: ComponentTransform): void;
|
||||
onEnabled(): void;
|
||||
onDisabled(): void;
|
||||
}
|
||||
@@ -528,7 +446,6 @@ declare class ComponentList {
|
||||
getComponent<T extends Component>(type: any, onlyReturnInitializedComponents: boolean): T;
|
||||
getComponents(typeName: string | any, components?: any): any;
|
||||
update(): void;
|
||||
onEntityTransformChanged(comp: any): void;
|
||||
}
|
||||
declare class ComponentTypeManager {
|
||||
private static _componentTypesMask;
|
||||
@@ -632,8 +549,6 @@ declare class Viewport {
|
||||
bounds: Rectangle;
|
||||
constructor(x: number, y: number, width: number, height: number);
|
||||
}
|
||||
declare abstract class GraphicsResource {
|
||||
}
|
||||
declare class GaussianBlurEffect extends egret.CustomFilter {
|
||||
private static blur_frag;
|
||||
constructor();
|
||||
@@ -656,16 +571,6 @@ declare class PostProcessor {
|
||||
protected drawFullscreenQuad(): void;
|
||||
unload(): void;
|
||||
}
|
||||
declare class BloomSettings {
|
||||
readonly threshold: any;
|
||||
readonly blurAmount: any;
|
||||
readonly intensity: any;
|
||||
readonly baseIntensity: any;
|
||||
readonly saturation: any;
|
||||
readonly baseStaturation: any;
|
||||
constructor(bloomThreshold: number, blurAmount: number, bloomIntensity: number, baseIntensity: number, bloomSaturation: number, baseSaturation: number);
|
||||
static presetSettings: BloomSettings[];
|
||||
}
|
||||
declare class GaussianBlurPostProcessor extends PostProcessor {
|
||||
onAddedToScene(scene: Scene): void;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
5251
demo/libs/framework/framework.min.js
vendored
5251
demo/libs/framework/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -2,6 +2,7 @@ class PlayerController extends Component {
|
||||
private down: boolean = false;
|
||||
private touchPoint: Vector2 = Vector2.zero;
|
||||
private mover: Mover;
|
||||
private spriteRenderer: SpriteRenderer;
|
||||
|
||||
public onAddedToEntity(){
|
||||
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this);
|
||||
@@ -23,13 +24,33 @@ class PlayerController extends Component {
|
||||
if (!this.mover)
|
||||
this.mover = this.entity.getComponent<Mover>(Mover);
|
||||
|
||||
if (!this.spriteRenderer)
|
||||
this.spriteRenderer = this.entity.getComponent<SpriteRenderer>(SpriteRenderer);
|
||||
|
||||
if (!this.mover)
|
||||
return;
|
||||
|
||||
if (!SpriteRenderer)
|
||||
return;
|
||||
|
||||
if (this.down){
|
||||
let camera = SceneManager.scene.camera;
|
||||
this.mover.move(Input.touchPositionDelta);
|
||||
console.log(Input.touchPositionDelta);
|
||||
let moveLeft: number = 0;
|
||||
let moveRight: number = 0;
|
||||
let speed = 200;
|
||||
let worldPos = Input.touchPosition;
|
||||
if (worldPos.x < this.spriteRenderer.x){
|
||||
moveLeft = -1;
|
||||
} else if(worldPos.x > this.spriteRenderer.x){
|
||||
moveLeft = 1;
|
||||
}
|
||||
|
||||
if (worldPos.y < this.spriteRenderer.y){
|
||||
moveRight = -1;
|
||||
} else if(worldPos.y > this.spriteRenderer.y){
|
||||
moveRight = 1;
|
||||
}
|
||||
this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
111
source/bin/framework.d.ts
vendored
111
source/bin/framework.d.ts
vendored
@@ -150,7 +150,6 @@ declare abstract class Component extends egret.DisplayObjectContainer {
|
||||
onRemovedFromEntity(): void;
|
||||
onEnabled(): void;
|
||||
onDisabled(): void;
|
||||
onEntityTransformChanged(comp: ComponentTransform): void;
|
||||
update(): void;
|
||||
debugRender(): void;
|
||||
registerComponent(): void;
|
||||
@@ -193,7 +192,6 @@ declare class Entity extends egret.DisplayObjectContainer {
|
||||
update(): void;
|
||||
onAddedToScene(): void;
|
||||
onRemovedFromScene(): void;
|
||||
onTransformChanged(comp: ComponentTransform): void;
|
||||
destroy(): void;
|
||||
}
|
||||
declare class Scene extends egret.DisplayObjectContainer {
|
||||
@@ -240,70 +238,6 @@ declare class SceneManager {
|
||||
static render(): void;
|
||||
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
|
||||
}
|
||||
declare enum DirtyType {
|
||||
clean = 0,
|
||||
positionDirty = 1,
|
||||
scaleDirty = 2,
|
||||
rotationDirty = 3
|
||||
}
|
||||
declare enum ComponentTransform {
|
||||
position = 0,
|
||||
scale = 1,
|
||||
rotation = 2
|
||||
}
|
||||
declare class Transform {
|
||||
readonly entity: Entity;
|
||||
private _children;
|
||||
private _parent;
|
||||
private _localPosition;
|
||||
private _localRotation;
|
||||
private _localScale;
|
||||
private _translationMatrix;
|
||||
private _rotationMatrix;
|
||||
private _scaleMatrix;
|
||||
private _worldTransform;
|
||||
private _worldToLocalTransform;
|
||||
private _worldInverseTransform;
|
||||
private _rotation;
|
||||
private _position;
|
||||
private _scale;
|
||||
private _localTransform;
|
||||
private _hierachyDirty;
|
||||
private _localDirty;
|
||||
private _localPositionDirty;
|
||||
private _localScaleDirty;
|
||||
private _localRotationDirty;
|
||||
private _positionDirty;
|
||||
private _worldToLocalDirty;
|
||||
private _worldInverseDirty;
|
||||
readonly childCount: number;
|
||||
constructor(entity: Entity);
|
||||
getChild(index: number): Transform;
|
||||
readonly worldInverseTransform: Matrix2D;
|
||||
readonly localToWorldTransform: Matrix2D;
|
||||
readonly worldToLocalTransform: Matrix2D;
|
||||
parent: Transform;
|
||||
setParent(parent: Transform): this;
|
||||
rotation: number;
|
||||
localRotation: number;
|
||||
position: Vector2;
|
||||
localPosition: Vector2;
|
||||
scale: Vector2;
|
||||
localScale: Vector2;
|
||||
rotationDegrees: number;
|
||||
localRotationDegrees: number;
|
||||
setLocalScale(scale: Vector2): this;
|
||||
setScale(scale: Vector2): this;
|
||||
setLocalRotationDegrees(degrees: number): this;
|
||||
setLocalRotation(radians: number): this;
|
||||
setRotation(radians: number): this;
|
||||
setRotationDegrees(degrees: number): this;
|
||||
setLocalPosition(localPosition: Vector2): this;
|
||||
setPosition(position: Vector2): this;
|
||||
setDirty(dirtyFlagType: DirtyType): void;
|
||||
roundPosition(): void;
|
||||
updateTransform(): void;
|
||||
}
|
||||
declare class Camera extends Component {
|
||||
private _zoom;
|
||||
private _origin;
|
||||
@@ -347,26 +281,6 @@ declare class ComponentPool<T extends PooledComponent> {
|
||||
obtain(): T;
|
||||
free(component: T): void;
|
||||
}
|
||||
declare class Mesh extends Component {
|
||||
private _verts;
|
||||
private _primitiveCount;
|
||||
private _triangles;
|
||||
private _topLeftVertPosition;
|
||||
private _width;
|
||||
private _height;
|
||||
initialize(): void;
|
||||
setVertPosition(positions: Vector2[]): this;
|
||||
setTriangles(triangles: number[]): this;
|
||||
recalculateBounds(): this;
|
||||
render(): void;
|
||||
}
|
||||
declare class VertexPosition {
|
||||
position: Vector2;
|
||||
constructor(position: Vector2);
|
||||
}
|
||||
declare class PolygonMesh extends Mesh {
|
||||
constructor(points: Vector2[], arePointsCCW?: boolean);
|
||||
}
|
||||
declare abstract class PooledComponent extends Component {
|
||||
abstract reset(): any;
|
||||
}
|
||||
@@ -386,10 +300,15 @@ declare abstract class RenderableComponent extends PooledComponent implements IR
|
||||
protected onBecameInvisible(): void;
|
||||
abstract render(camera: Camera): any;
|
||||
isVisibleFromCamera(camera: Camera): boolean;
|
||||
onEntityTransformChanged(comp: ComponentTransform): void;
|
||||
}
|
||||
declare class ScreenSpaceCamera extends Camera {
|
||||
protected updateMatrixes(): void;
|
||||
declare class Mesh extends RenderableComponent {
|
||||
private _mesh;
|
||||
constructor();
|
||||
setTexture(texture: egret.Texture): Mesh;
|
||||
onAddedToEntity(): void;
|
||||
onRemovedFromEntity(): void;
|
||||
render(camera: Camera): void;
|
||||
reset(): void;
|
||||
}
|
||||
declare class Sprite {
|
||||
texture2D: egret.Texture;
|
||||
@@ -446,7 +365,6 @@ declare abstract class Collider extends Component {
|
||||
collidesWith(collider: Collider, motion: Vector2): CollisionResult;
|
||||
onAddedToEntity(): void;
|
||||
onRemovedFromEntity(): void;
|
||||
onEntityTransformChanged(comp: ComponentTransform): void;
|
||||
onEnabled(): void;
|
||||
onDisabled(): void;
|
||||
}
|
||||
@@ -528,7 +446,6 @@ declare class ComponentList {
|
||||
getComponent<T extends Component>(type: any, onlyReturnInitializedComponents: boolean): T;
|
||||
getComponents(typeName: string | any, components?: any): any;
|
||||
update(): void;
|
||||
onEntityTransformChanged(comp: any): void;
|
||||
}
|
||||
declare class ComponentTypeManager {
|
||||
private static _componentTypesMask;
|
||||
@@ -632,8 +549,6 @@ declare class Viewport {
|
||||
bounds: Rectangle;
|
||||
constructor(x: number, y: number, width: number, height: number);
|
||||
}
|
||||
declare abstract class GraphicsResource {
|
||||
}
|
||||
declare class GaussianBlurEffect extends egret.CustomFilter {
|
||||
private static blur_frag;
|
||||
constructor();
|
||||
@@ -656,16 +571,6 @@ declare class PostProcessor {
|
||||
protected drawFullscreenQuad(): void;
|
||||
unload(): void;
|
||||
}
|
||||
declare class BloomSettings {
|
||||
readonly threshold: any;
|
||||
readonly blurAmount: any;
|
||||
readonly intensity: any;
|
||||
readonly baseIntensity: any;
|
||||
readonly saturation: any;
|
||||
readonly baseStaturation: any;
|
||||
constructor(bloomThreshold: number, blurAmount: number, bloomIntensity: number, baseIntensity: number, bloomSaturation: number, baseSaturation: number);
|
||||
static presetSettings: BloomSettings[];
|
||||
}
|
||||
declare class GaussianBlurPostProcessor extends PostProcessor {
|
||||
onAddedToScene(scene: Scene): void;
|
||||
}
|
||||
|
||||
10451
source/bin/framework.js
10451
source/bin/framework.js
File diff suppressed because it is too large
Load Diff
5251
source/bin/framework.min.js
vendored
5251
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -45,10 +45,6 @@ abstract class Component extends egret.DisplayObjectContainer {
|
||||
|
||||
}
|
||||
|
||||
public onEntityTransformChanged(comp: ComponentTransform){
|
||||
|
||||
}
|
||||
|
||||
public update(){
|
||||
|
||||
}
|
||||
|
||||
@@ -1,57 +1,32 @@
|
||||
class Mesh extends Component {
|
||||
private _verts: VertexPosition[];
|
||||
private _primitiveCount: number;
|
||||
private _triangles: number[];
|
||||
private _topLeftVertPosition: Vector2;
|
||||
private _width;
|
||||
private _height;
|
||||
///<reference path="./RenderableComponent.ts" />
|
||||
class Mesh extends RenderableComponent {
|
||||
private _mesh: egret.Mesh;
|
||||
|
||||
public initialize() {
|
||||
constructor(){
|
||||
super();
|
||||
|
||||
this._mesh = new egret.Mesh();
|
||||
}
|
||||
|
||||
public setVertPosition(positions: Vector2[]){
|
||||
let createVerts = !this._verts || this._verts.length != positions.length;
|
||||
if (createVerts)
|
||||
this._verts = new Array(positions.length);
|
||||
|
||||
for (let i = 0; i < this._verts.length; i ++){
|
||||
this._verts[i] = new VertexPosition(positions[i]);
|
||||
}
|
||||
public setTexture(texture: egret.Texture): Mesh{
|
||||
this._mesh.texture = texture;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public setTriangles(triangles: number[]){
|
||||
this._primitiveCount = triangles.length / 3;
|
||||
this._triangles = triangles;
|
||||
return this;
|
||||
public onAddedToEntity(){
|
||||
this.addChild(this._mesh);
|
||||
}
|
||||
|
||||
public recalculateBounds(){
|
||||
this._topLeftVertPosition = new Vector2(Number.MAX_VALUE, Number.MAX_VALUE);
|
||||
let max = new Vector2(Number.MIN_VALUE, Number.MIN_VALUE);
|
||||
|
||||
for (let i = 0; i < this._verts.length; i ++){
|
||||
this._topLeftVertPosition.x = Math.min(this._topLeftVertPosition.x, this._verts[i].position.x);
|
||||
this._topLeftVertPosition.y = Math.min(this._topLeftVertPosition.y, this._verts[i].position.y);
|
||||
max.x = Math.max(max.x, this._verts[i].position.x);
|
||||
max.y = Math.max(max.y, this._verts[i].position.y);
|
||||
}
|
||||
|
||||
this._width = max.x - this._topLeftVertPosition.x;
|
||||
this._height = max.y - this._topLeftVertPosition.y;
|
||||
|
||||
return this;
|
||||
public onRemovedFromEntity(){
|
||||
this.removeChild(this._mesh);
|
||||
}
|
||||
|
||||
public render(){
|
||||
}
|
||||
}
|
||||
|
||||
class VertexPosition{
|
||||
public position: Vector2;
|
||||
|
||||
constructor(position: Vector2){
|
||||
this.position = position;
|
||||
public render(camera: Camera){
|
||||
this.x = this.entity.position.x - camera.position.x + camera.origin.x;
|
||||
this.y = this.entity.position.y - camera.position.y + camera.origin.y;
|
||||
}
|
||||
|
||||
public reset() {
|
||||
}
|
||||
}
|
||||
@@ -104,23 +104,6 @@ abstract class Collider extends Component{
|
||||
this._isParentEntityAddedToScene = false;
|
||||
}
|
||||
|
||||
public onEntityTransformChanged(comp: ComponentTransform){
|
||||
switch (comp){
|
||||
case ComponentTransform.position:
|
||||
this._isPositionDirty = true;
|
||||
break;
|
||||
case ComponentTransform.scale:
|
||||
this._isPositionDirty = true;
|
||||
break;
|
||||
case ComponentTransform.rotation:
|
||||
this._isRotationDirty = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (this._isColliderRegistered)
|
||||
Physics.updateCollider(this);
|
||||
}
|
||||
|
||||
public onEnabled(){
|
||||
this.registerColliderWithPhysicsSystem();
|
||||
this._isPositionDirty = this._isRotationDirty = true;
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
class PolygonMesh extends Mesh {
|
||||
constructor(points: Vector2[], arePointsCCW: boolean = true){
|
||||
super();
|
||||
|
||||
let triangulator = new Triangulator();
|
||||
triangulator.triangulate(points, arePointsCCW);
|
||||
|
||||
this.setVertPosition(points);
|
||||
this.setTriangles(triangulator.triangleIndices);
|
||||
this.recalculateBounds();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
///<reference path="./PooledComponent.ts" />
|
||||
/**
|
||||
* 所有可渲染组件的基类
|
||||
*/
|
||||
@@ -52,8 +53,4 @@ abstract class RenderableComponent extends PooledComponent implements IRenderabl
|
||||
this.isVisible = camera.getBounds().intersects(this.getBounds());
|
||||
return this.isVisible;
|
||||
}
|
||||
|
||||
public onEntityTransformChanged(comp: ComponentTransform){
|
||||
this._areBoundsDirty = true;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class ScreenSpaceCamera extends Camera {
|
||||
protected updateMatrixes(){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -193,10 +193,6 @@ class Entity extends egret.DisplayObjectContainer {
|
||||
this.components.removeAllComponents();
|
||||
}
|
||||
|
||||
public onTransformChanged(comp: ComponentTransform){
|
||||
this.components.onEntityTransformChanged(comp);
|
||||
}
|
||||
|
||||
public destroy(){
|
||||
this._isDestoryed = true;
|
||||
this.scene.entities.remove(this);
|
||||
|
||||
@@ -1,345 +0,0 @@
|
||||
enum DirtyType{
|
||||
clean,
|
||||
positionDirty,
|
||||
scaleDirty,
|
||||
rotationDirty,
|
||||
}
|
||||
|
||||
enum ComponentTransform{
|
||||
position,
|
||||
scale,
|
||||
rotation
|
||||
}
|
||||
|
||||
class Transform {
|
||||
/** 相关联的实体 */
|
||||
public readonly entity: Entity;
|
||||
private _children: Transform[];
|
||||
private _parent: Transform;
|
||||
|
||||
private _localPosition: Vector2;
|
||||
private _localRotation: number = 0;
|
||||
private _localScale: Vector2;
|
||||
|
||||
private _translationMatrix: Matrix2D;
|
||||
private _rotationMatrix: Matrix2D;
|
||||
private _scaleMatrix: Matrix2D;
|
||||
|
||||
private _worldTransform = Matrix2D.identity;
|
||||
private _worldToLocalTransform = Matrix2D.identity;
|
||||
private _worldInverseTransform = Matrix2D.identity;
|
||||
|
||||
private _rotation: number = 0;
|
||||
private _position: Vector2;
|
||||
private _scale: Vector2;
|
||||
|
||||
private _localTransform;
|
||||
private _hierachyDirty: DirtyType;
|
||||
private _localDirty: boolean;
|
||||
private _localPositionDirty: boolean;
|
||||
private _localScaleDirty: boolean;
|
||||
private _localRotationDirty: boolean;
|
||||
private _positionDirty: boolean;
|
||||
private _worldToLocalDirty: boolean;
|
||||
private _worldInverseDirty: boolean;
|
||||
|
||||
public get childCount(){
|
||||
return this._children.length;
|
||||
}
|
||||
|
||||
constructor(entity: Entity){
|
||||
this.entity = entity;
|
||||
this._scale = this._localScale = Vector2.one;
|
||||
this._children = [];
|
||||
}
|
||||
|
||||
public getChild(index: number){
|
||||
return this._children[index];
|
||||
}
|
||||
|
||||
public get worldInverseTransform(){
|
||||
this.updateTransform();
|
||||
if (this._worldInverseDirty){
|
||||
this._worldInverseTransform = Matrix2D.invert(this._worldTransform, this._worldInverseTransform);
|
||||
this._worldInverseDirty = false;
|
||||
}
|
||||
|
||||
return this._worldInverseTransform;
|
||||
}
|
||||
|
||||
public get localToWorldTransform(){
|
||||
this.updateTransform();
|
||||
return this._worldTransform;
|
||||
}
|
||||
|
||||
public get worldToLocalTransform(){
|
||||
if (this._worldToLocalDirty){
|
||||
if (!this.parent){
|
||||
this._worldInverseTransform = new Matrix2D();
|
||||
} else{
|
||||
this.parent.updateTransform();
|
||||
this._worldToLocalTransform = Matrix2D.invert(this.parent._worldTransform, this._worldToLocalTransform);
|
||||
}
|
||||
|
||||
this._worldToLocalDirty = false;
|
||||
}
|
||||
|
||||
return this._worldToLocalTransform;
|
||||
}
|
||||
|
||||
public get parent(){
|
||||
return this._parent;
|
||||
}
|
||||
|
||||
public set parent(value: Transform){
|
||||
this.setParent(value);
|
||||
}
|
||||
|
||||
public setParent(parent: Transform){
|
||||
if (this._parent == parent)
|
||||
return this;
|
||||
|
||||
if (this._parent)
|
||||
this._parent._children.remove(this);
|
||||
|
||||
if (parent)
|
||||
parent._children.push(this);
|
||||
|
||||
this._parent = parent;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public get rotation() {
|
||||
this.updateTransform();
|
||||
return this._rotation;
|
||||
}
|
||||
|
||||
public set rotation(value: number){
|
||||
this.setRotation(value);
|
||||
}
|
||||
|
||||
public get localRotation(){
|
||||
this.updateTransform();
|
||||
return this._localRotation;
|
||||
}
|
||||
|
||||
public set localRotation(value: number){
|
||||
this.setLocalRotation(value);
|
||||
}
|
||||
|
||||
public get position(){
|
||||
this.updateTransform();
|
||||
if (this._positionDirty){
|
||||
if (!this.parent){
|
||||
this._position = this._localPosition;
|
||||
}else{
|
||||
this.parent.updateTransform();
|
||||
this._position = Vector2Ext.transformR(this._localPosition, this.parent._worldTransform);
|
||||
}
|
||||
|
||||
this._positionDirty = false;
|
||||
}
|
||||
|
||||
|
||||
return this._position;
|
||||
}
|
||||
|
||||
public set position(value: Vector2){
|
||||
this.setPosition(value);
|
||||
}
|
||||
|
||||
public get localPosition(){
|
||||
this.updateTransform();
|
||||
return this._localPosition;
|
||||
}
|
||||
|
||||
public set localPosition(value: Vector2){
|
||||
this.setLocalPosition(value);
|
||||
}
|
||||
|
||||
public get scale(){
|
||||
this.updateTransform();
|
||||
return this._scale;
|
||||
}
|
||||
|
||||
public set scale(value: Vector2){
|
||||
this.setScale(value);
|
||||
}
|
||||
|
||||
public get localScale(){
|
||||
this.updateTransform();
|
||||
return this._localScale;
|
||||
}
|
||||
|
||||
public set localScale(value: Vector2){
|
||||
this.setLocalScale(value);
|
||||
}
|
||||
|
||||
public get rotationDegrees(){
|
||||
return MathHelper.toDegrees(this._rotation);
|
||||
}
|
||||
|
||||
public set rotationDegrees(value: number){
|
||||
this.setRotation(MathHelper.toRadians(value));
|
||||
}
|
||||
|
||||
public get localRotationDegrees(){
|
||||
return MathHelper.toDegrees(this._localRotation);
|
||||
}
|
||||
|
||||
public set localRotationDegrees(value: number){
|
||||
this.localRotation = MathHelper.toRadians(value);
|
||||
}
|
||||
|
||||
public setLocalScale(scale: Vector2){
|
||||
this._localScale = scale;
|
||||
this._localDirty = this._positionDirty = this._localScaleDirty = true;
|
||||
this.setDirty(DirtyType.scaleDirty);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public setScale(scale: Vector2){
|
||||
this._scale = scale;
|
||||
if (this.parent){
|
||||
this.localScale = Vector2.divide(scale, this.parent._scale);
|
||||
}else{
|
||||
this.localScale = scale;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public setLocalRotationDegrees(degrees: number){
|
||||
return this.setLocalRotation(MathHelper.toRadians(degrees));
|
||||
}
|
||||
|
||||
public setLocalRotation(radians: number){
|
||||
this._localRotation = radians;
|
||||
this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true;
|
||||
this.setDirty(DirtyType.rotationDirty);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public setRotation(radians: number){
|
||||
this._rotation = radians;
|
||||
if (this.parent){
|
||||
this.localRotation = this.parent.rotation + radians;
|
||||
} else {
|
||||
this.localRotation = radians;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public setRotationDegrees(degrees: number){
|
||||
return this.setRotation(MathHelper.toRadians(degrees));
|
||||
}
|
||||
|
||||
public setLocalPosition(localPosition: Vector2){
|
||||
if (localPosition == this._localPosition)
|
||||
return this;
|
||||
|
||||
this._localPosition = localPosition;
|
||||
this._localDirty = this._positionDirty = this._localPositionDirty = this._localRotationDirty = this._localScaleDirty = true;
|
||||
this.setDirty(DirtyType.positionDirty);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public setPosition(position: Vector2){
|
||||
if (position == this._position)
|
||||
return this;
|
||||
|
||||
this._position = position;
|
||||
if (this.parent){
|
||||
this.localPosition = Vector2.transform(this._position, this._worldToLocalTransform);
|
||||
}else{
|
||||
this.localPosition = position;
|
||||
}
|
||||
|
||||
this._positionDirty = false;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public setDirty(dirtyFlagType: DirtyType){
|
||||
if ((this._hierachyDirty & dirtyFlagType) == 0){
|
||||
this._hierachyDirty |= dirtyFlagType;
|
||||
|
||||
switch (dirtyFlagType){
|
||||
case DirtyType.positionDirty:
|
||||
this.entity.onTransformChanged(ComponentTransform.position);
|
||||
break;
|
||||
case DirtyType.rotationDirty:
|
||||
this.entity.onTransformChanged(ComponentTransform.rotation);
|
||||
break;
|
||||
case DirtyType.scaleDirty:
|
||||
this.entity.onTransformChanged(ComponentTransform.scale);
|
||||
break;
|
||||
}
|
||||
|
||||
if (this._children == null)
|
||||
this._children = [];
|
||||
|
||||
for (let i = 0; i < this._children.length; i ++){
|
||||
this._children[i].setDirty(dirtyFlagType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public roundPosition(){
|
||||
this.position = this._position.round();
|
||||
}
|
||||
|
||||
public updateTransform(){
|
||||
if (this._hierachyDirty != DirtyType.clean){
|
||||
if (this.parent)
|
||||
this.parent.updateTransform();
|
||||
|
||||
if (this._localDirty){
|
||||
if (this._localPositionDirty){
|
||||
this._translationMatrix = Matrix2D.createTranslation(this._localPosition.x, this._localPosition.y);
|
||||
this._localPositionDirty = false;
|
||||
}
|
||||
|
||||
if (this._localRotationDirty){
|
||||
this._rotationMatrix = Matrix2D.createRotation(this._localRotation);
|
||||
this._localRotationDirty = false;
|
||||
}
|
||||
|
||||
if (this._localScaleDirty){
|
||||
this._scaleMatrix = Matrix2D.createScale(this._localScale.x, this._localScale.y);
|
||||
this._localScaleDirty = false;
|
||||
}
|
||||
|
||||
this._localTransform = Matrix2D.multiply(this._scaleMatrix, this._rotationMatrix);
|
||||
this._localTransform = Matrix2D.multiply(this._localTransform, this._translationMatrix);
|
||||
|
||||
if (!this.parent){
|
||||
this._worldTransform = this._localTransform;
|
||||
this._rotation = this._localRotation;
|
||||
this._scale = this._localScale;
|
||||
this._worldInverseDirty = true;
|
||||
}
|
||||
|
||||
this._localDirty = false;
|
||||
}
|
||||
|
||||
if (this.parent){
|
||||
this._worldTransform = Matrix2D.multiply(this._localTransform, this.parent._worldTransform);
|
||||
|
||||
this._rotation = this._localRotation + this.parent._rotation;
|
||||
this._scale = Vector2.multiply( this.parent._scale, this._localScale);
|
||||
this._worldInverseDirty = true;
|
||||
}
|
||||
|
||||
this._worldToLocalDirty = true;
|
||||
this._positionDirty = true;
|
||||
this._hierachyDirty = DirtyType.clean;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -171,16 +171,4 @@ class ComponentList {
|
||||
component.update();
|
||||
}
|
||||
}
|
||||
|
||||
public onEntityTransformChanged(comp){
|
||||
for (let i = 0; i < this._components.length; i++){
|
||||
if (this._components[i].enabled)
|
||||
this._components[i].onEntityTransformChanged(comp);
|
||||
}
|
||||
|
||||
for (let i = 0; i < this._componentsToAdd.length; i ++){
|
||||
if (this._componentsToAdd[i].enabled)
|
||||
this._componentsToAdd[i].onEntityTransformChanged(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
abstract class GraphicsResource {
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
class BloomSettings {
|
||||
public readonly threshold;
|
||||
public readonly blurAmount;
|
||||
public readonly intensity;
|
||||
public readonly baseIntensity;
|
||||
public readonly saturation;
|
||||
public readonly baseStaturation;
|
||||
|
||||
constructor(bloomThreshold: number, blurAmount: number, bloomIntensity: number,baseIntensity: number,
|
||||
bloomSaturation: number, baseSaturation: number){
|
||||
this.threshold = bloomThreshold;
|
||||
this.blurAmount = blurAmount;
|
||||
this.intensity = bloomIntensity;
|
||||
this.baseIntensity = baseIntensity;
|
||||
this.saturation = bloomSaturation;
|
||||
this.baseStaturation = baseSaturation;
|
||||
}
|
||||
|
||||
public static presetSettings: BloomSettings[] = [
|
||||
new BloomSettings(0.1, 0.6, 2, 1, 1, 0),
|
||||
new BloomSettings(0, 3, 1, 1, 1, 1),
|
||||
new BloomSettings(0.5, 8, 2, 1, 0, 1),
|
||||
new BloomSettings(0.25, 8, 1.3, 1, 1, 0),
|
||||
new BloomSettings(0, 2, 1, 0.1, 1, 1),
|
||||
new BloomSettings(0.5, 2, 1, 1, 1, 1)
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user