awayjs-display
Version:
AwayJS displaylist classes
188 lines (152 loc) • 4.44 kB
text/typescript
import AbstractMethodError from "awayjs-core/lib/errors/AbstractMethodError";
import AssetEvent from "awayjs-core/lib/events/AssetEvent";
import Matrix3D from "awayjs-core/lib/geom/Matrix3D";
import Matrix from "awayjs-core/lib/geom/Matrix";
import ColorTransform from "awayjs-core/lib/geom/ColorTransform";
import AssetBase from "awayjs-core/lib/library/AssetBase";
import IAnimator from "../animators/IAnimator";
import Camera from "../display/Camera";
import Sprite from "../display/Sprite";
import RenderableEvent from "../events/RenderableEvent";
import MaterialBase from "../materials/MaterialBase";
import Style from "../base/Style";
import StyleEvent from "../events/StyleEvent";
import IRenderable from "../base/IRenderable";
import Graphics from "../graphics/Graphics";
import ElementsBase from "../graphics/ElementsBase";
import IPickingCollider from "../pick/IPickingCollider";
import PickingCollision from "../pick/PickingCollision";
import DisplayObject from "../display/DisplayObject";
/**
* Graphic wraps a Elements as a scene graph instantiation. A Graphic is owned by a Sprite object.
*
*
* @see away.base.ElementsBase
* @see away.entities.Sprite
*
* @class away.base.Graphic
*/
class Graphic extends AssetBase implements IRenderable
{
public static _available:Array<Graphic> = new Array<Graphic>();
public static assetType:string = "[asset Graphic]";
public _iIndex:number = 0;
private _style:Style;
private _material:MaterialBase;
private _onInvalidatePropertiesDelegate:(event:StyleEvent) => void;
public parent:Graphics;
/**
* The Elements object which provides the geometry data for this Graphic.
*/
public elements:ElementsBase;
/**
*
*/
public get assetType():string
{
return Graphic.assetType;
}
/**
*
*/
public get animator():IAnimator
{
return this.parent.animator;
}
//TODO test shader picking
// public get shaderPickingDetails():boolean
// {
//
// return this.sourceEntity.shaderPickingDetails;
// }
/**
* The material used to render the current TriangleGraphic. If set to null, its parent Sprite's material will be used instead.
*/
public get material():MaterialBase
{
return this._material || this.parent.material;
}
public set material(value:MaterialBase)
{
if (this.material)
this.material.iRemoveOwner(this);
this._material = value;
if (this.material)
this.material.iAddOwner(this);
}
/**
* The style used to render the current TriangleGraphic. If set to null, its parent Sprite's style will be used instead.
*/
public get style():Style
{
return this._style || this.parent.style;
}
public set style(value:Style)
{
if (this._style == value)
return;
if (this._style)
this._style.removeEventListener(StyleEvent.INVALIDATE_PROPERTIES, this._onInvalidatePropertiesDelegate);
this._style = value;
if (this._style)
this._style.addEventListener(StyleEvent.INVALIDATE_PROPERTIES, this._onInvalidatePropertiesDelegate);
this.invalidateSurface();
}
/**
* Creates a new Graphic object
*/
constructor(index:number, parent:Graphics, elements:ElementsBase, material:MaterialBase = null, style:Style = null)
{
super();
this._onInvalidatePropertiesDelegate = (event:StyleEvent) => this._onInvalidateProperties(event);
this._iIndex = index;
this.parent = parent;
this.elements = elements;
this.material = material;
this.style = style;
}
/**
*
*/
public dispose()
{
super.dispose();
this.parent.removeGraphic(this);
this.parent = null;
Graphic._available.push(this);
}
public invalidateElements()
{
this.dispatchEvent(new RenderableEvent(RenderableEvent.INVALIDATE_ELEMENTS, this));
}
public invalidateSurface()
{
this.dispatchEvent(new RenderableEvent(RenderableEvent.INVALIDATE_RENDER_OWNER, this));
}
public _iGetExplicitMaterial():MaterialBase
{
return this._material;
}
public _iGetExplicitStyle():Style
{
return this._style;
}
private _onInvalidateProperties(event:StyleEvent)
{
this.invalidateSurface();
}
/**
* //TODO
*
* @param shortestCollisionDistance
* @param findClosest
* @returns {boolean}
*
* @internal
*/
public _iTestCollision(pickingCollision:PickingCollision, pickingCollider:IPickingCollider):boolean
{
return this.elements._iTestCollision(pickingCollider, this.material, pickingCollision)
}
}
export default Graphic;