- .pipe(sourcemaps.init()) // sourcemaps init. currently redundant directory def, waiting for this - https://github.com/floridoo/gulp-sourcemaps/issues/111
- .pipe(typescript({
- noExternalResolve: true,
- target: 'ES5',
- declarationFiles: true,
- typescript: require('typescript'),
- experimentalDecorators: true
- }));
- return tsResult.js
- .pipe(sourcemaps.write("./")) // sourcemaps are written.
- * Update a BoundingInfo2D object using the given min/max values as input
- * @param xmin the smallest x coordinate
- * @param xmax the biggest x coordinate
- * @param ymin the smallest y coordinate
- * @param ymax the buggest y coordinate
- * @param b must be a valid/allocated object, it will contain the result of the operation
- */
- BoundingInfo2D.CreateFromMinMaxToRef = function (xmin, xmax, ymin, ymax, b) {
- var w = xmax - xmin;
- var h = ymax - ymin;
- b.center = new BABYLON.Vector2(xmin + w / 2, ymin + h / 2);
- b.extent = new BABYLON.Vector2(xmax - b.center.x, ymax - b.center.y);
- b.radius = b.extent.length();
- };
- /**
- * Duplicate this instance and return a new one
- * @return the duplicated instance
- */
- BoundingInfo2D.prototype.clone = function () {
- var r = new BoundingInfo2D();
- r.center = this.center.clone();
- r.radius = this.radius;
- r.extent = this.extent.clone();
- return r;
- };
- BoundingInfo2D.prototype.clear = function () {
- this.center.copyFromFloats(0, 0);
- this.radius = 0;
- this.extent.copyFromFloats(0, 0);
- };
- BoundingInfo2D.prototype.copyFrom = function (src) {
- this.center.copyFrom(src.center);
- this.radius = src.radius;
- this.extent.copyFrom(src.extent);
- };
- /**
- * return the max extend of the bounding info
- */
- BoundingInfo2D.prototype.max = function () {
- var r = BABYLON.Vector2.Zero();
- this.maxToRef(r);
- return r;
- };
- /**
- * Update a vector2 with the max extend of the bounding info
- * @param result must be a valid/allocated vector2 that will contain the result of the operation
- */
- BoundingInfo2D.prototype.maxToRef = function (result) {
- result.x = this.center.x + this.extent.x;
- result.y = this.center.y + this.extent.y;
- };
- /**
- * Apply a transformation matrix to this BoundingInfo2D and return a new instance containing the result
- * @param matrix the transformation matrix to apply
- * @return the new instance containing the result of the transformation applied on this BoundingInfo2D
- */
- BoundingInfo2D.prototype.transform = function (matrix) {
- var r = new BoundingInfo2D();
- this.transformToRef(matrix, r);
- return r;
- };
- /**
- * Compute the union of this BoundingInfo2D with a given one, returns a new BoundingInfo2D as a result
- * @param other the second BoundingInfo2D to compute the union with this one
- * @return a new instance containing the result of the union
- */
- BoundingInfo2D.prototype.union = function (other) {
- var r = new BoundingInfo2D();
- this.unionToRef(other, r);
- return r;
- };
- /**
- * Transform this BoundingInfo2D with a given matrix and store the result in an existing BoundingInfo2D instance.
- * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
- * @param matrix The matrix to use to compute the transformation
- * @param result A VALID (i.e. allocated) BoundingInfo2D object where the result will be stored
- */
- BoundingInfo2D.prototype.transformToRef = function (matrix, result) {
- // Construct a bounding box based on the extent values
- var p = BoundingInfo2D._transform;
- p[0].x = this.center.x + this.extent.x;
- p[0].y = this.center.y + this.extent.y;
- p[1].x = this.center.x + this.extent.x;
- p[1].y = this.center.y - this.extent.y;
- p[2].x = this.center.x - this.extent.x;
- p[2].y = this.center.y - this.extent.y;
- p[3].x = this.center.x - this.extent.x;
- p[3].y = this.center.y + this.extent.y;
- // Transform the four points of the bounding box with the matrix
- * Compute the union of this BoundingInfo2D with another one and store the result in a third valid BoundingInfo2D object
- * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
- * @param other the second object used to compute the union
- * @param result a VALID BoundingInfo2D instance (i.e. allocated) where the result will be stored
- */
- BoundingInfo2D.prototype.unionToRef = function (other, result) {
- var xmax = Math.max(this.center.x + this.extent.x, other.center.x + other.extent.x);
- var ymax = Math.max(this.center.y + this.extent.y, other.center.y + other.extent.y);
- var xmin = Math.min(this.center.x - this.extent.x, other.center.x - other.extent.x);
- var ymin = Math.min(this.center.y - this.extent.y, other.center.y - other.extent.y);
- * This class handles a circle area and a bounding rectangle one.
- */
- export class BoundingInfo2D {
-
- /**
- * The coordinate of the center of the bounding info
- */
- public center: Vector2;
-
- /**
- * The radius of the bounding circle, from the center of the bounded object
- */
- public radius: number;
-
- /**
- * The extent of the bounding rectangle, from the center of the bounded object.
- * This is an absolute value in both X and Y of the vector which describe the right/top corner of the rectangle, you can easily reconstruct the whole rectangle by negating X &| Y.
- */
- public extent: Vector2;
-
- constructor() {
- this.radius = 0;
- this.center = Vector2.Zero();
- this.extent = Vector2.Zero();
- }
-
- /**
- * Create a BoundingInfo2D object from a given size
- * @param size the size that will be used to set the extend, radius will be computed from it.
- */
- public static CreateFromSize(size: Size): BoundingInfo2D {
- let r = new BoundingInfo2D();
- BoundingInfo2D.CreateFromSizeToRef(size, r);
- return r;
- }
-
- /**
- * Create a BoundingInfo2D object from a given radius
- * @param radius the radius to use, the extent will be computed from it.
- */
- public static CreateFromRadius(radius: number): BoundingInfo2D {
- * Transform this BoundingInfo2D with a given matrix and store the result in an existing BoundingInfo2D instance.
- * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
- * @param matrix The matrix to use to compute the transformation
- * @param result A VALID (i.e. allocated) BoundingInfo2D object where the result will be stored
- */
- public transformToRef(matrix: Matrix, result: BoundingInfo2D) {
- // Construct a bounding box based on the extent values
- let p = BoundingInfo2D._transform;
- p[0].x = this.center.x + this.extent.x;
- p[0].y = this.center.y + this.extent.y;
- p[1].x = this.center.x + this.extent.x;
- p[1].y = this.center.y - this.extent.y;
- p[2].x = this.center.x - this.extent.x;
- p[2].y = this.center.y - this.extent.y;
- p[3].x = this.center.x - this.extent.x;
- p[3].y = this.center.y + this.extent.y;
-
- // Transform the four points of the bounding box with the matrix
- * Compute the union of this BoundingInfo2D with another one and store the result in a third valid BoundingInfo2D object
- * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
- * @param other the second object used to compute the union
- * @param result a VALID BoundingInfo2D instance (i.e. allocated) where the result will be stored
- */
- public unionToRef(other: BoundingInfo2D, result: BoundingInfo2D) {
- let xmax = Math.max(this.center.x + this.extent.x, other.center.x + other.extent.x);
- let ymax = Math.max(this.center.y + this.extent.y, other.center.y + other.extent.y);
- let xmin = Math.min(this.center.x - this.extent.x, other.center.x - other.extent.x);
- let ymin = Math.min(this.center.y - this.extent.y, other.center.y - other.extent.y);
- * @returns the color object. Note that it's not a clone of the actual object stored in the instance so you MUST NOT modify it, otherwise unexpected behavior might occurs.
- */
- get: function () {
- return this._color;
- },
- set: function (value) {
- if (this.isLocked()) {
- return;
- }
- this._color = value;
- },
- enumerable: true,
- configurable: true
- });
- /**
- * Return a unique identifier of the instance, which is simply the hexadecimal representation (CSS Style) of the solid color.
- */
- SolidColorBrush2D.prototype.toString = function () {
- * This interface is used to implement a lockable instance pattern.
- * Classes that implements it may be locked at any time, making their content immutable from now on.
- * You also can query if a given instance is locked or not.
- * This allow instances to be shared among several 'consumers'.
- */
- export interface ILockable {
- /**
- * Query the lock state
- * @returns returns true if the object is locked and immutable, false if it's not
- */
- isLocked(): boolean;
-
- /**
- * A call to this method will definitely lock the instance, making its content immutable
- * @returns the previous lock state of the object. so if true is returned the object were already locked and this method does nothing, if false is returned it means the object wasn't locked and this call locked it for good.
- */
- lock(): boolean;
- }
-
- /**
- * This interface defines the IBrush2D contract.
- * Classes implementing a new type of Brush2D must implement this interface
- */
- export interface IBrush2D extends ILockable {
- /**
- * Define if the brush will use transparency / alpha blending
- * @returns true if the brush use transparency
- */
- isTransparent(): boolean;
-
- /**
- * It is critical for each instance of a given Brush2D type to return a unique string that identifies it because the Border instance will certainly be part of the computed ModelKey for a given Primitive
- * @returns A string identifier that uniquely identify the instance
- */
- toString(): string;
- }
-
- /**
- * Base class implementing the ILocable interface.
- * The particularity of this class is to call the protected onLock() method when the instance is about to be locked for good.
- */
- export class LockableBase implements ILockable {
- isLocked(): boolean {
- return this._isLocked;
- }
-
- private _isLocked: boolean;
-
- lock(): boolean {
- if (this._isLocked) {
- return true;
- }
-
- this.onLock();
- this._isLocked = true;
- return false;
- }
-
- /**
- * Protected handler that will be called when the instance is about to be locked.
- */
- protected onLock() {
-
- }
- }
-
- @className("SolidColorBrush2D", "BABYLON")
- /**
- * This class implements a Brush that will be drawn with a uniform solid color (i.e. the same color everywhere in the content where the brush is assigned to).
- */
- export class SolidColorBrush2D extends LockableBase implements IBrush2D {
- * Return true if the brush is transparent, false if it's totally opaque
- */
- isTransparent(): boolean {
- return this._color && this._color.a < 1.0;
- }
-
- /**
- * The color used by this instance to render
- * @returns the color object. Note that it's not a clone of the actual object stored in the instance so you MUST NOT modify it, otherwise unexpected behavior might occurs.
- */
- public get color(): Color4 {
- return this._color;
- }
-
- public set color(value: Color4) {
- if (this.isLocked()) {
- return;
- }
-
- this._color = value;
- }
-
- /**
- * Return a unique identifier of the instance, which is simply the hexadecimal representation (CSS Style) of the solid color.
- */
- public toString(): string {
- return this._color.toHexString();
- }
- private _color: Color4;
- }
-
- @className("GradientColorBrush2D", "BABYLON")
- /**
- * This class implements a Gradient Color Brush, the brush color will blend from a first given color to a second one.
- */
- export class GradientColorBrush2D extends LockableBase implements IBrush2D {
- * A stack panel layout. Primitive will be stack either horizontally or vertically.
- * This Layout type must be used as a Singleton, use the StackPanelLayoutEngine.Horizontal for an horizontal stack panel or StackPanelLayoutEngine.Vertical for a vertical one.
- */
- export class StackPanelLayoutEngine extends LayoutEngineBase {
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id: a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - size: the size of the group. Alternatively the width and height properties can be set. Default will be [10;10].
- * - subdivision: the number of subdivision to create the ellipse perimeter, default is 64.
- * - fill: the brush used to draw the fill content of the ellipse, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
- * - border: the brush used to draw the border of the ellipse, you can set null to draw nothing (but you will have to set a fill brush), default is null. can be a string value (see Canvas2D.GetBrushFromString)
- * - borderThickness: the thickness of the drawn border, default is 1.
- * - isVisible: true if the group must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- */
- function Ellipse2D(settings) {
- // Avoid checking every time if the object exists
- if (settings == null) {
- settings = {};
- }
- _super.call(this, settings);
- if (settings.size != null) {
- this.size = settings.size;
- }
- else if (settings.width || settings.height) {
- var size = new BABYLON.Size(settings.width, settings.height);
- this.size = size;
- }
- var sub = (settings.subdivisions == null) ? 64 : settings.subdivisions;
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id: a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - size: the size of the group. Alternatively the width and height properties can be set. Default will be [10;10].
- * - subdivision: the number of subdivision to create the ellipse perimeter, default is 64.
- * - fill: the brush used to draw the fill content of the ellipse, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
- * - border: the brush used to draw the border of the ellipse, you can set null to draw nothing (but you will have to set a fill brush), default is null. can be a string value (see Canvas2D.GetBrushFromString)
- * - borderThickness: the thickness of the drawn border, default is 1.
- * - isVisible: true if the group must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- */
- constructor(settings?: {
-
- parent ?: Prim2DBase,
- children ?: Array<Prim2DBase>,
- id ?: string,
- position ?: Vector2,
- x ?: number,
- y ?: number,
- rotation ?: number,
- scale ?: number,
- scaleX ?: number,
- scaleY ?: number,
- dontInheritParentScale?: boolean,
- opacity ?: number,
- zOrder ?: number,
- origin ?: Vector2,
- size ?: Size,
- width ?: number,
- height ?: number,
- subdivisions ?: number,
- fill ?: IBrush2D | string,
- border ?: IBrush2D | string,
- borderThickness ?: number,
- isVisible ?: boolean,
- isPickable ?: boolean,
- isContainer ?: boolean,
- childrenFlatZOrder ?: boolean,
- marginTop ?: number | string,
- marginLeft ?: number | string,
- marginRight ?: number | string,
- marginBottom ?: number | string,
- margin ?: number | string,
- marginHAlignment ?: number,
- marginVAlignment ?: number,
- marginAlignment ?: string,
- paddingTop ?: number | string,
- paddingLeft ?: number | string,
- paddingRight ?: number | string,
- paddingBottom ?: number | string,
- padding ?: string,
- }) {
-
- // Avoid checking every time if the object exists
- if (settings == null) {
- settings = {};
- }
-
- super(settings);
-
- if (settings.size != null) {
- this.size = settings.size;
- }
- else if (settings.width || settings.height) {
- let size = new Size(settings.width, settings.height);
- this.size = size;
- }
-
- let sub = (settings.subdivisions == null) ? 64 : settings.subdivisions;
- * Create an Rectangle 2D Shape primitive. May be a sharp rectangle (with sharp corners), or a rounded one.
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y settings can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - size: the size of the group. Alternatively the width and height settings can be set. Default will be [10;10].
- * - roundRadius: if the rectangle has rounded corner, set their radius, default is 0 (to get a sharp edges rectangle).
- * - fill: the brush used to draw the fill content of the rectangle, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
- * - border: the brush used to draw the border of the rectangle, you can set null to draw nothing (but you will have to set a fill brush), default is null. can also be a string value (see Canvas2D.GetBrushFromString)
- * - borderThickness: the thickness of the drawn border, default is 1.
- * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- */
- function Rectangle2D(settings) {
- // Avoid checking every time if the object exists
- if (settings == null) {
- settings = {};
- }
- _super.call(this, settings);
- if (settings.size != null) {
- this.size = settings.size;
- }
- else if (settings.width || settings.height) {
- var size = new BABYLON.Size(settings.width, settings.height);
- Rectangle2D.prototype.levelIntersect = function (intersectInfo) {
- // If we got there it mean the boundingInfo intersection succeed, if the rectangle has not roundRadius, it means it succeed!
- if (this.notRounded) {
- return true;
- }
- // If we got so far it means the bounding box at least passed, so we know it's inside the bounding rectangle, but it can be outside the roundedRectangle.
- // The easiest way is to check if the point is inside on of the four corners area (a little square of roundRadius size at the four corners)
- // If it's the case for one, check if the mouse is located in the quarter that we care about (the one who is visible) then finally make a distance check with the roundRadius radius to see if it's inside the circle quarter or outside.
- // First let remove the origin out the equation, to have the rectangle with an origin at bottom/left
- // We override this method because if there's a roundRadius set, we will reduce the initial Content Area to make sure the computed area won't intersect with the shape contour. The formula is simple: we shrink the incoming size by the amount of the roundRadius
- Rectangle2D.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
- // Fall back to default implementation if there's no round Radius
- @modelLevelProperty(Shape2D.SHAPE2D_PROPCOUNT + 2, pi => Rectangle2D.notRoundedProperty = pi)
- /**
- * Get if the rectangle is notRound (returns true) or rounded (returns false).
- * Don't use the setter, it's for internal purpose only
- */
- public get notRounded(): boolean {
- return this._notRounded;
- }
-
- public set notRounded(value: boolean) {
- this._notRounded = value;
- }
-
- @instanceLevelProperty(Shape2D.SHAPE2D_PROPCOUNT + 3, pi => Rectangle2D.roundRadiusProperty = pi)
- /**
- * Get/set the round Radius, a value of 0 for a sharp edges rectangle, otherwise the value will be used as the diameter of the round to apply on corder. The Rectangle2D.notRounded property will be updated accordingly.
- // If we got there it mean the boundingInfo intersection succeed, if the rectangle has not roundRadius, it means it succeed!
- if (this.notRounded) {
- return true;
- }
-
- // If we got so far it means the bounding box at least passed, so we know it's inside the bounding rectangle, but it can be outside the roundedRectangle.
- // The easiest way is to check if the point is inside on of the four corners area (a little square of roundRadius size at the four corners)
- // If it's the case for one, check if the mouse is located in the quarter that we care about (the one who is visible) then finally make a distance check with the roundRadius radius to see if it's inside the circle quarter or outside.
-
- // First let remove the origin out the equation, to have the rectangle with an origin at bottom/left
- * Create an Rectangle 2D Shape primitive. May be a sharp rectangle (with sharp corners), or a rounded one.
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y settings can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - size: the size of the group. Alternatively the width and height settings can be set. Default will be [10;10].
- * - roundRadius: if the rectangle has rounded corner, set their radius, default is 0 (to get a sharp edges rectangle).
- * - fill: the brush used to draw the fill content of the rectangle, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
- * - border: the brush used to draw the border of the rectangle, you can set null to draw nothing (but you will have to set a fill brush), default is null. can also be a string value (see Canvas2D.GetBrushFromString)
- * - borderThickness: the thickness of the drawn border, default is 1.
- * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- */
- constructor(settings ?: {
- parent ?: Prim2DBase,
- children ?: Array<Prim2DBase>,
- id ?: string,
- position ?: Vector2,
- x ?: number,
- y ?: number,
- rotation ?: number,
- scale ?: number,
- scaleX ?: number,
- scaleY ?: number,
- dontInheritParentScale?: boolean,
- opacity ?: number,
- zOrder ?: number,
- origin ?: Vector2,
- size ?: Size,
- width ?: number,
- height ?: number,
- roundRadius ?: number,
- fill ?: IBrush2D | string,
- border ?: IBrush2D | string,
- borderThickness ?: number,
- isVisible ?: boolean,
- isPickable ?: boolean,
- isContainer ?: boolean,
- childrenFlatZOrder ?: boolean,
- marginTop ?: number | string,
- marginLeft ?: number | string,
- marginRight ?: number | string,
- marginBottom ?: number | string,
- margin ?: number | string,
- marginHAlignment ?: number,
- marginVAlignment ?: number,
- marginAlignment ?: string,
- paddingTop ?: number | string,
- paddingLeft ?: number | string,
- paddingRight ?: number | string,
- paddingBottom ?: number | string,
- padding ?: string,
- }) {
-
- // Avoid checking every time if the object exists
- if (settings == null) {
- settings = {};
- }
-
- super(settings);
-
- if (settings.size != null) {
- this.size = settings.size;
- }
- else if (settings.width || settings.height) {
- let size = new Size(settings.width, settings.height);
- // We override this method because if there's a roundRadius set, we will reduce the initial Content Area to make sure the computed area won't intersect with the shape contour. The formula is simple: we shrink the incoming size by the amount of the roundRadius
- // At this stage we have everything correctly initialized, ModelRenderCache is setup, Model Instance data are good too, they have allocated elements in the Instanced DynamicFloatArray.
- // The last thing to do is check if the instanced related data must be updated because a InstanceLevel property had changed or the primitive visibility changed.
- var pd = new BABYLON.ModelRenderCachePartData();
- this._modelRenderCache._partData.push(pd);
- var cat = this.getUsedShaderCategories(dataPart);
- var cti = dataPart.getClassTreeInfo();
- // Make sure the instance is visible other the properties won't be set and their size/offset wont be computed
- var curVisible = this.isVisible;
- this.isVisible = true;
- // We manually trigger refreshInstanceData for the only sake of evaluating each instance property size and offset in the instance data, this can only be made at runtime. Once it's done we have all the information to create the instance data buffer.
- //console.log("Build Prop Layout for " + Tools.getClassName(this._instanceDataParts[0]));
- var joinCat = ";" + cat.join(";") + ";";
- pd._partJoinedUsedCategories = joinCat;
- InstanceClassInfo._CurCategories = joinCat;
- var obj = this.beforeRefreshForLayoutConstruction(dataPart);
- if (!this.refreshInstanceDataPart(dataPart)) {
- console.log("Layout construction for " + BABYLON.Tools.getClassName(this._instanceDataParts[0]) + " failed because refresh returned false");
- console.log("ERROR: Couldn't detect the size of the Property " + v.attributeName + " from type " + BABYLON.Tools.getClassName(cti.type) + ". Property is ignored.");
- * Transform a given point using the Primitive's origin setting.
- * This method requires the Primitive's actualSize to be accurate
- * @param p the point to transform
- * @param originOffset an offset applied on the current origin before performing the transformation. Depending on which frame of reference your data is expressed you may have to apply a offset. (if you data is expressed from the bottom/left, no offset is required. If it's expressed from the center the a [-0.5;-0.5] offset has to be applied.
- * @param res an allocated Vector2 that will receive the transformed content
- */
- RenderablePrim2D.prototype.transformPointWithOriginByRef = function (p, originOffset, res) {
- * Get the info for a given effect based on the dataPart metadata
- * @param dataPartId partId in part list to get the info
- * @param vertexBufferAttributes vertex buffer attributes to manually add
- * @param uniforms uniforms to manually add
- * @param useInstanced specified if Instanced Array should be used, if null the engine caps will be used (so true if WebGL supports it, false otherwise), but you have the possibility to override the engine capability. However, if you manually set true but the engine does not support Instanced Array, this method will return null
- */
- RenderablePrim2D.prototype.getDataPartEffectInfo = function (dataPartId, vertexBufferAttributes, uniforms, useInstanced) {
- RenderablePrim2D.prototype.createModelRenderCache = function (modelKey) {
- return null;
- };
- RenderablePrim2D.prototype.setupModelRenderCache = function (modelRenderCache) {
- };
- RenderablePrim2D.prototype.createInstanceDataParts = function () {
- return null;
- };
- RenderablePrim2D.prototype.getUsedShaderCategories = function (dataPart) {
- return [];
- };
- RenderablePrim2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
- };
- RenderablePrim2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
- };
- RenderablePrim2D.prototype.applyActualScaleOnTransform = function () {
- return true;
- };
- RenderablePrim2D.prototype.refreshInstanceDataPart = function (part) {
- if (!this.isVisible) {
- return false;
- }
- part.isVisible = this.isVisible;
- // Which means, if there's only one data element, we're update it from this method, otherwise it is the responsibility of the derived class to call updateInstanceDataPart as many times as needed, properly (look at Text2D's implementation for more information)
- if (part.dataElementCount === 1) {
- part.curElement = 0;
- this.updateInstanceDataPart(part);
- }
- return true;
- };
- /**
- * Update the instanceDataBase level properties of a part
- * @param part the part to update
- * @param positionOffset to use in multi part per primitive (e.g. the Text2D has N parts for N letter to display), this give the offset to apply (e.g. the position of the letter from the bottom/left corner of the text).
- */
- RenderablePrim2D.prototype.updateInstanceDataPart = function (part, positionOffset) {
- var t = this._globalTransform.multiply(this.renderGroup.invGlobalTransform); // Compute the transformation into the renderGroup's space
- var rgScale = this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? RenderablePrim2D._uV : this.renderGroup.actualScale; // We still need to apply the scale of the renderGroup to our rendering, so get it.
- var size = this.renderGroup.viewportSize;
- var zBias = this.actualZOffset;
- var offX = 0;
- var offY = 0;
- // If there's an offset, apply the global transformation matrix on it to get a global offset
- // Have to convert the coordinates to clip space which is ranged between [-1;1] on X and Y axis, with 0,0 being the left/bottom corner
- // Current coordinates are expressed in renderGroup coordinates ([0, renderGroup.actualSize.width|height]) with 0,0 being at the left/top corner
- // So for X:
- // - tx.x = value * 2 / width: is to switch from [0, renderGroup.width] to [0, 2]
- // - tx.w = (value * 2 / width) - 1: w stores the translation in renderGroup coordinates so (value * 2 / width) to switch to a clip space translation value. - 1 is to offset the overall [0;2] to [-1;1].
- // At last we don't forget to apply the actualScale of the Render Group to tx[0] and ty[1] to propagate scaling correctly
- // At this stage we have everything correctly initialized, ModelRenderCache is setup, Model Instance data are good too, they have allocated elements in the Instanced DynamicFloatArray.
-
- // The last thing to do is check if the instanced related data must be updated because a InstanceLevel property had changed or the primitive visibility changed.
- let ctiArray = new Array<ClassTreeInfo<InstanceClassInfo, InstancePropInfo>>();
- this._modelRenderCache._partData = new Array<ModelRenderCachePartData>();
- for (let dataPart of parts) {
- var pd = new ModelRenderCachePartData();
- this._modelRenderCache._partData.push(pd)
- var cat = this.getUsedShaderCategories(dataPart);
- var cti = dataPart.getClassTreeInfo();
- // Make sure the instance is visible other the properties won't be set and their size/offset wont be computed
- let curVisible = this.isVisible;
- this.isVisible = true;
- // We manually trigger refreshInstanceData for the only sake of evaluating each instance property size and offset in the instance data, this can only be made at runtime. Once it's done we have all the information to create the instance data buffer.
- //console.log("Build Prop Layout for " + Tools.getClassName(this._instanceDataParts[0]));
- var joinCat = ";" + cat.join(";") + ";";
- pd._partJoinedUsedCategories = joinCat;
- InstanceClassInfo._CurCategories = joinCat;
- let obj = this.beforeRefreshForLayoutConstruction(dataPart);
- if (!this.refreshInstanceDataPart(dataPart)) {
- console.log(`Layout construction for ${Tools.getClassName(this._instanceDataParts[0])} failed because refresh returned false`);
- * Transform a given point using the Primitive's origin setting.
- * This method requires the Primitive's actualSize to be accurate
- * @param p the point to transform
- * @param originOffset an offset applied on the current origin before performing the transformation. Depending on which frame of reference your data is expressed you may have to apply a offset. (if you data is expressed from the bottom/left, no offset is required. If it's expressed from the center the a [-0.5;-0.5] offset has to be applied.
- * @param res an allocated Vector2 that will receive the transformed content
- * Get the info for a given effect based on the dataPart metadata
- * @param dataPartId partId in part list to get the info
- * @param vertexBufferAttributes vertex buffer attributes to manually add
- * @param uniforms uniforms to manually add
- * @param useInstanced specified if Instanced Array should be used, if null the engine caps will be used (so true if WebGL supports it, false otherwise), but you have the possibility to override the engine capability. However, if you manually set true but the engine does not support Instanced Array, this method will return null
- // Which means, if there's only one data element, we're update it from this method, otherwise it is the responsibility of the derived class to call updateInstanceDataPart as many times as needed, properly (look at Text2D's implementation for more information)
- if (part.dataElementCount === 1) {
- part.curElement = 0;
- this.updateInstanceDataPart(part);
- }
- return true;
- }
-
- private static _uV = new Vector2(1, 1);
-
- /**
- * Update the instanceDataBase level properties of a part
- * @param part the part to update
- * @param positionOffset to use in multi part per primitive (e.g. the Text2D has N parts for N letter to display), this give the offset to apply (e.g. the position of the letter from the bottom/left corner of the text).
- let t = this._globalTransform.multiply(this.renderGroup.invGlobalTransform); // Compute the transformation into the renderGroup's space
- let rgScale = this._areSomeFlagsSet(SmartPropertyPrim.flagDontInheritParentScale) ? RenderablePrim2D._uV : this.renderGroup.actualScale; // We still need to apply the scale of the renderGroup to our rendering, so get it.
- let size = (<Size>this.renderGroup.viewportSize);
- let zBias = this.actualZOffset;
-
- let offX = 0;
- let offY = 0;
- // If there's an offset, apply the global transformation matrix on it to get a global offset
- // Have to convert the coordinates to clip space which is ranged between [-1;1] on X and Y axis, with 0,0 being the left/bottom corner
- // Current coordinates are expressed in renderGroup coordinates ([0, renderGroup.actualSize.width|height]) with 0,0 being at the left/top corner
- // So for X:
- // - tx.x = value * 2 / width: is to switch from [0, renderGroup.width] to [0, 2]
- // - tx.w = (value * 2 / width) - 1: w stores the translation in renderGroup coordinates so (value * 2 / width) to switch to a clip space translation value. - 1 is to offset the overall [0;2] to [-1;1].
- // At last we don't forget to apply the actualScale of the Render Group to tx[0] and ty[1] to propagate scaling correctly
- * @param texture the texture that stores the sprite to render
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - spriteSize: the size of the sprite (in pixels), if null the size of the given texture will be used, default is null.
- * - spriteLocation: the location (in pixels) in the texture of the top/left corner of the Sprite to display, default is null (0,0)
- * - spriteScaleFactor: say you want to display a sprite twice as big as its bitmap which is 64,64, you set the spriteSize to 128,128 and have to set the spriteScaleFactory to 0.5,0.5 in order to address only the 64,64 pixels of the bitmaps. Default is 1,1.
- * - invertY: if true the texture Y will be inverted, default is false.
- * - alignToPixel: if true the sprite's texels will be aligned to the rendering viewport pixels, ensuring the best rendering quality but slow animations won't be done as smooth as if you set false. If false a texel could lies between two pixels, being blended by the texture sampling mode you choose, the rendering result won't be as good, but very slow animation will be overall better looking. Default is true: content will be aligned.
- * - isVisible: true if the sprite must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- if (settings.spriteSize == null || !texture.isReady()) {
- if (texture.isReady()) {
- this.size = texture.getBaseSize();
- }
- else {
- texture.onLoadObservable.add(function () {
- if (settings.spriteSize == null) {
- _this.size = texture.getBaseSize();
- }
- _this._positioningDirty();
- _this._instanceDirtyFlags |= BABYLON.Prim2DBase.originProperty.flagId | Sprite2D.textureProperty.flagId; // To make sure the sprite is issued again for render
- @dynamicLevelProperty(RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, pi => Sprite2D.useAlphaFromTextureProperty = pi)
- /**
- * If true and the texture has an Alpha Channel which is used (BaseTexture.hasAlpha = true) the Sprite2d will be rendered as a Transparent Primitive, if false and the texture has an Alpha Channel which is used (BaseTexture.hasAlpha = true) the Sprite2d will be rendered as Alpha Test. If false or if the Texture has no alpha or it's not used (BaseTexture.hasAlpha = false) the Sprite2d will be rendered as an Opaque Primitive
- */
- public get useAlphaFromTexture(): boolean {
- return this._useAlphaFromTexture;
- }
-
- public set useAlphaFromTexture(value: boolean) {
- // If we've made it so far it means the boundingInfo intersection test succeed, the Sprite2D is shaped the same, so we always return true
- return true;
- }
-
- /**
- * Create an 2D Sprite primitive
- * @param texture the texture that stores the sprite to render
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - spriteSize: the size of the sprite (in pixels), if null the size of the given texture will be used, default is null.
- * - spriteLocation: the location (in pixels) in the texture of the top/left corner of the Sprite to display, default is null (0,0)
- * - spriteScaleFactor: say you want to display a sprite twice as big as its bitmap which is 64,64, you set the spriteSize to 128,128 and have to set the spriteScaleFactory to 0.5,0.5 in order to address only the 64,64 pixels of the bitmaps. Default is 1,1.
- * - invertY: if true the texture Y will be inverted, default is false.
- * - alignToPixel: if true the sprite's texels will be aligned to the rendering viewport pixels, ensuring the best rendering quality but slow animations won't be done as smooth as if you set false. If false a texel could lies between two pixels, being blended by the texture sampling mode you choose, the rendering result won't be as good, but very slow animation will be overall better looking. Default is true: content will be aligned.
- * - isVisible: true if the sprite must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- */
- constructor(texture: Texture, settings?: {
-
- parent ?: Prim2DBase,
- children ?: Array<Prim2DBase>,
- id ?: string,
- position ?: Vector2,
- x ?: number,
- y ?: number,
- rotation ?: number,
- scale ?: number,
- scaleX ?: number,
- scaleY ?: number,
- dontInheritParentScale?: boolean,
- opacity ?: number,
- zOrder ?: number,
- origin ?: Vector2,
- spriteSize ?: Size,
- spriteLocation ?: Vector2,
- spriteScaleFactor ?: Vector2,
- invertY ?: boolean,
- alignToPixel ?: boolean,
- isVisible ?: boolean,
- isPickable ?: boolean,
- isContainer ?: boolean,
- childrenFlatZOrder ?: boolean,
- marginTop ?: number | string,
- marginLeft ?: number | string,
- marginRight ?: number | string,
- marginBottom ?: number | string,
- margin ?: number | string,
- marginHAlignment ?: number,
- marginVAlignment ?: number,
- marginAlignment ?: string,
- paddingTop ?: number | string,
- paddingLeft ?: number | string,
- paddingRight ?: number | string,
- paddingBottom ?: number | string,
- padding ?: string,
- }) {
-
- if (!settings) {
- settings = {};
- }
-
- super(settings);
-
- this.texture = texture;
- this.texture.wrapU = Texture.CLAMP_ADDRESSMODE;
- this.texture.wrapV = Texture.CLAMP_ADDRESSMODE;
- this.size = settings.spriteSize;
- this.spriteLocation = settings.spriteLocation || new Vector2(0, 0);
- this.spriteScaleFactor = settings.spriteScaleFactor || new Vector2(1, 1);
- if (settings.spriteSize == null || !texture.isReady()) {
- if (texture.isReady()) {
- this.size = <Size>texture.getBaseSize();
- } else {
- texture.onLoadObservable.add(() => {
- if (settings.spriteSize == null) {
- this.size = <Size>texture.getBaseSize();
- }
- this._positioningDirty();
- this._instanceDirtyFlags |= Prim2DBase.originProperty.flagId | Sprite2D.textureProperty.flagId; // To make sure the sprite is issued again for render
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - fontName: the name/size/style of the font to use, following the CSS notation. Default is "12pt Arial".
- * - fontSuperSample: if true the text will be rendered with a superSampled font (the font is twice the given size). Use this settings if the text lies in world space or if it's scaled in.
- * - defaultFontColor: the color by default to apply on each letter of the text to display, default is plain white.
- * - areaSize: the size of the area in which to display the text, default is auto-fit from text content.
- * - tabulationSize: number of space character to insert when a tabulation is encountered, default is 4
- * - isVisible: true if the text must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- Text2D.prototype.levelIntersect = function (intersectInfo) {
- // For now I can't do something better that boundingInfo is a hit, detecting an intersection on a particular letter would be possible, but do we really need it? Not for now...
- return true;
- };
- Text2D.prototype.createModelRenderCache = function (modelKey) {
- var renderCache = new Text2DRenderCache(this.owner.engine, modelKey);
- return renderCache;
- };
- Text2D.prototype.setupModelRenderCache = function (modelRenderCache) {
- // Looks like a hack!? Yes! Because that's what it is!
- // For the InstanceData layer to compute correctly we need to set all the properties involved, which won't be the case if there's no text
- // This method is called before the layout construction for us to detect this case, set some text and return the initial one to restore it after (there can be some text without char to display, say "\t\n" for instance)
- Text2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
- if (!this._charCount) {
- var curText = this._text;
- this.text = "A";
- return curText;
- }
- };
- // if obj contains something, we restore the _text property
- Text2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
- if (obj !== undefined) {
- this.text = obj;
- }
- };
- Text2D.prototype.refreshInstanceDataPart = function (part) {
- if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
- return false;
- }
- if (part.id === Text2D.TEXT2D_MAINPARTID) {
- var d = part;
- var texture = this.fontTexture;
- var superSampleFactor = texture.isSuperSampled ? 0.5 : 1;
- var ts = texture.getSize();
- var offset = BABYLON.Vector2.Zero();
- var lh = this.fontTexture.lineHeight;
- offset.y = ((this.textSize.height / lh) - 1) * lh; // Origin is bottom, not top, so the offset is starting with a y that is the top location of the text
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - fontName: the name/size/style of the font to use, following the CSS notation. Default is "12pt Arial".
- * - fontSuperSample: if true the text will be rendered with a superSampled font (the font is twice the given size). Use this settings if the text lies in world space or if it's scaled in.
- * - defaultFontColor: the color by default to apply on each letter of the text to display, default is plain white.
- * - areaSize: the size of the area in which to display the text, default is auto-fit from text content.
- * - tabulationSize: number of space character to insert when a tabulation is encountered, default is 4
- * - isVisible: true if the text must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- // For now I can't do something better that boundingInfo is a hit, detecting an intersection on a particular letter would be possible, but do we really need it? Not for now...
- // Looks like a hack!? Yes! Because that's what it is!
- // For the InstanceData layer to compute correctly we need to set all the properties involved, which won't be the case if there's no text
- // This method is called before the layout construction for us to detect this case, set some text and return the initial one to restore it after (there can be some text without char to display, say "\t\n" for instance)
- protected beforeRefreshForLayoutConstruction(part: InstanceDataBase): any {
- if (!this._charCount) {
- let curText = this._text;
- this.text = "A";
- return curText;
- }
- }
-
- // if obj contains something, we restore the _text property
- // Overload the SmartPropertyBase's method to provide the additional logic of returning the parent's dataSource if there's no dataSource specified at this level.
- protected _getDataSource(): IPropertyChanged {
- let levelDS = super._getDataSource();
- if (levelDS != null) {
- return levelDS;
- }
-
- let p = this.parent;
- if (p != null) {
- return p.dataSource;
- }
-
- return null;
- }
-
- protected createVisualTree() {
- let res = this._renderingTemplate.createVisualTree(this, this._visualPlaceholder);
- * The purpose of this class is to provide a base implementation of the IPropertyChanged interface for the user to avoid rewriting a code needlessly.
- * Typical use of this class is to check for equality in a property set(), then call the onPropertyChanged method if values are different after the new value is set. The protected method will notify observers of the change.
- * Remark: onPropertyChanged detects reentrant code and acts in a way to make sure everything is fine, fast and allocation friendly (when there no reentrant code which should be 99% of the time)
- */
- export abstract class PropertyChangedBase implements IPropertyChanged {
-
- /**
- * Protected method to call when there's a change of value in a property set
- * @param propName the name of the concerned property
- * An observable that is triggered when a property (using of the XXXXLevelProperty decorator) has its value changing.
- * You can add an observer that will be triggered only for a given set of Properties using the Mask feature of the Observable and the corresponding Prim2DPropInfo.flagid value (e.g. Prim2DBase.positionProperty.flagid|Prim2DBase.rotationProperty.flagid to be notified only about position or rotation change)
- */
- public get propertyChanged(): Observable<PropertyChangedInfo> {
- if (!this._propertyChanged) {
- this._propertyChanged = new Observable<PropertyChangedInfo>();
- }
- return this._propertyChanged;
- }
-
- public _propertyChanged: Observable<PropertyChangedInfo> = null;
- private static pci = new PropertyChangedInfo();
- private static calling: boolean = false;
- }
-
- /**
- * Class for the ObservableArray.onArrayChanged observable
- */
- export class ArrayChanged<T> {
- constructor() {
- this.action = 0;
- this.newItems = new Array<{index: number, value: T }>();
- this.removedItems = new Array<{ index: number, value: T }>();
- this.changedItems = new Array<{ index: number, value: T }>();
- this.newStartingIndex = -1;
- this.removedStartingIndex = -1;
- }
-
- /**
- * Contain the action that were made on the ObservableArray, it's one of the ArrayChanged.xxxAction members.
- * Note the action's value can be used in the "mask" field of the Observable to only be notified about given action(s)
- */
- public action: number;
-
- /**
- * Only valid if the action is newItemsAction
- */
- public newItems: { index: number, value: T }[];
-
- /**
- * Only valid if the action is removedItemsAction
- */
- public removedItems: { index: number, value: T }[];
-
- /**
- * Only valid if the action is changedItemAction
- */
- public changedItems: { index: number, value: T }[];
-
- /**
- * Get the index of the first item inserted
- */
- public newStartingIndex: number;
-
- /**
- * Get the index of the first item removed
- */
- public removedStartingIndex: number;
-
- /**
- * Get the index of the first changed item
- */
- public changedStartingIndex: number;
-
- /**
- * The content of the array was totally cleared
- */
- public static get clearAction() {
- return ArrayChanged._clearAction;
- }
-
- /**
- * A new item was added, the newItems field contains the key/value pairs
- */
- public static get newItemsAction() {
- return ArrayChanged._newItemsAction;
- }
-
- /**
- * An existing item was removed, the removedKey field contains its key
- */
- public static get removedItemsAction() {
- return ArrayChanged._removedItemsAction;
- }
-
- /**
- * One or many items in the array were changed, the
- */
- public static get changedItemAction() {
- return ArrayChanged._changedItemAction;
- }
-
- /**
- * The array's content was totally changed
- * Depending on the method that used this mode the ChangedArray object may contains more information
- * @param items Additional items to add to the end of array1.
- */
- concat(...items: T[]): ObservableArray<T> {
- return new ObservableArray<T>(this._watchObjectsPropertyChange, this._array.concat(...items));
- }
-
- /**
- * Adds all the elements of an array separated by the specified separator string.
- * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
- */
- join(separator?: string): string {
- return this._array.join(separator);
- }
-
- /**
- * Reverses the elements in an Array.
- * The arrayChanged action is
- */
- reverse(): T[] {
- let res = this._array.reverse();
-
- let ac = this.getArrayChangedObject();
- ac.action = ArrayChanged.replacedArrayAction;
-
- return res;
- }
-
- /**
- * Removes the first element from an array and returns it, shift all subsequents element one element before.
- * The ArrayChange action is replacedArrayAction, the whole array changes and must be reevaluate as such, the removed element is in removedItems.
- return new ObservableArray<T>(this._watchObjectsPropertyChange, this._array.slice(start, end));
- }
-
- /**
- * Sorts an array.
- * @param compareFn The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.
- * On the contrary of the Javascript Array's implementation, this method returns nothing
- * Determines whether all the members of an array satisfy the specified test.
- * @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
- * Determines whether the specified callback function returns true for any element of an array.
- * @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
- * Performs the specified action for each element in an array.
- * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
- * Calls a defined callback function on each element of an array, and returns an array that contains the results.
- * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
- * Returns the elements of an array that meet the condition specified in a callback function.
- * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
- * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
- * Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
- * Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
- * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
- * @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
- * @param value the value corresponding to the key
- * @return true if the operation completed successfully, false if we couldn't insert the key/value because there was already this key in the dictionary
- .pipe(sourcemaps.init()) // sourcemaps init. currently redundant directory def, waiting for this - https://github.com/floridoo/gulp-sourcemaps/issues/111
- .pipe(typescript({
- noExternalResolve: true,
- target: 'ES5',
- declarationFiles: true,
- typescript: require('typescript'),
- experimentalDecorators: true
- }));
- return tsResult.js
- .pipe(sourcemaps.write("./")) // sourcemaps are written.
- * Update a BoundingInfo2D object using the given min/max values as input
- * @param xmin the smallest x coordinate
- * @param xmax the biggest x coordinate
- * @param ymin the smallest y coordinate
- * @param ymax the buggest y coordinate
- * @param b must be a valid/allocated object, it will contain the result of the operation
- */
- BoundingInfo2D.CreateFromMinMaxToRef = function (xmin, xmax, ymin, ymax, b) {
- var w = xmax - xmin;
- var h = ymax - ymin;
- b.center = new BABYLON.Vector2(xmin + w / 2, ymin + h / 2);
- b.extent = new BABYLON.Vector2(xmax - b.center.x, ymax - b.center.y);
- b.radius = b.extent.length();
- };
- /**
- * Duplicate this instance and return a new one
- * @return the duplicated instance
- */
- BoundingInfo2D.prototype.clone = function () {
- var r = new BoundingInfo2D();
- r.center = this.center.clone();
- r.radius = this.radius;
- r.extent = this.extent.clone();
- return r;
- };
- BoundingInfo2D.prototype.clear = function () {
- this.center.copyFromFloats(0, 0);
- this.radius = 0;
- this.extent.copyFromFloats(0, 0);
- };
- BoundingInfo2D.prototype.copyFrom = function (src) {
- this.center.copyFrom(src.center);
- this.radius = src.radius;
- this.extent.copyFrom(src.extent);
- };
- /**
- * return the max extend of the bounding info
- */
- BoundingInfo2D.prototype.max = function () {
- var r = BABYLON.Vector2.Zero();
- this.maxToRef(r);
- return r;
- };
- /**
- * Update a vector2 with the max extend of the bounding info
- * @param result must be a valid/allocated vector2 that will contain the result of the operation
- */
- BoundingInfo2D.prototype.maxToRef = function (result) {
- result.x = this.center.x + this.extent.x;
- result.y = this.center.y + this.extent.y;
- };
- /**
- * Apply a transformation matrix to this BoundingInfo2D and return a new instance containing the result
- * @param matrix the transformation matrix to apply
- * @return the new instance containing the result of the transformation applied on this BoundingInfo2D
- */
- BoundingInfo2D.prototype.transform = function (matrix) {
- var r = new BoundingInfo2D();
- this.transformToRef(matrix, r);
- return r;
- };
- /**
- * Compute the union of this BoundingInfo2D with a given one, returns a new BoundingInfo2D as a result
- * @param other the second BoundingInfo2D to compute the union with this one
- * @return a new instance containing the result of the union
- */
- BoundingInfo2D.prototype.union = function (other) {
- var r = new BoundingInfo2D();
- this.unionToRef(other, r);
- return r;
- };
- /**
- * Transform this BoundingInfo2D with a given matrix and store the result in an existing BoundingInfo2D instance.
- * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
- * @param matrix The matrix to use to compute the transformation
- * @param result A VALID (i.e. allocated) BoundingInfo2D object where the result will be stored
- */
- BoundingInfo2D.prototype.transformToRef = function (matrix, result) {
- // Construct a bounding box based on the extent values
- var p = BoundingInfo2D._transform;
- p[0].x = this.center.x + this.extent.x;
- p[0].y = this.center.y + this.extent.y;
- p[1].x = this.center.x + this.extent.x;
- p[1].y = this.center.y - this.extent.y;
- p[2].x = this.center.x - this.extent.x;
- p[2].y = this.center.y - this.extent.y;
- p[3].x = this.center.x - this.extent.x;
- p[3].y = this.center.y + this.extent.y;
- // Transform the four points of the bounding box with the matrix
- * Compute the union of this BoundingInfo2D with another one and store the result in a third valid BoundingInfo2D object
- * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
- * @param other the second object used to compute the union
- * @param result a VALID BoundingInfo2D instance (i.e. allocated) where the result will be stored
- */
- BoundingInfo2D.prototype.unionToRef = function (other, result) {
- var xmax = Math.max(this.center.x + this.extent.x, other.center.x + other.extent.x);
- var ymax = Math.max(this.center.y + this.extent.y, other.center.y + other.extent.y);
- var xmin = Math.min(this.center.x - this.extent.x, other.center.x - other.extent.x);
- var ymin = Math.min(this.center.y - this.extent.y, other.center.y - other.extent.y);
- * This class handles a circle area and a bounding rectangle one.
- */
- export class BoundingInfo2D {
-
- /**
- * The coordinate of the center of the bounding info
- */
- public center: Vector2;
-
- /**
- * The radius of the bounding circle, from the center of the bounded object
- */
- public radius: number;
-
- /**
- * The extent of the bounding rectangle, from the center of the bounded object.
- * This is an absolute value in both X and Y of the vector which describe the right/top corner of the rectangle, you can easily reconstruct the whole rectangle by negating X &| Y.
- */
- public extent: Vector2;
-
- constructor() {
- this.radius = 0;
- this.center = Vector2.Zero();
- this.extent = Vector2.Zero();
- }
-
- /**
- * Create a BoundingInfo2D object from a given size
- * @param size the size that will be used to set the extend, radius will be computed from it.
- */
- public static CreateFromSize(size: Size): BoundingInfo2D {
- let r = new BoundingInfo2D();
- BoundingInfo2D.CreateFromSizeToRef(size, r);
- return r;
- }
-
- /**
- * Create a BoundingInfo2D object from a given radius
- * @param radius the radius to use, the extent will be computed from it.
- */
- public static CreateFromRadius(radius: number): BoundingInfo2D {
- * Transform this BoundingInfo2D with a given matrix and store the result in an existing BoundingInfo2D instance.
- * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
- * @param matrix The matrix to use to compute the transformation
- * @param result A VALID (i.e. allocated) BoundingInfo2D object where the result will be stored
- */
- public transformToRef(matrix: Matrix, result: BoundingInfo2D) {
- // Construct a bounding box based on the extent values
- let p = BoundingInfo2D._transform;
- p[0].x = this.center.x + this.extent.x;
- p[0].y = this.center.y + this.extent.y;
- p[1].x = this.center.x + this.extent.x;
- p[1].y = this.center.y - this.extent.y;
- p[2].x = this.center.x - this.extent.x;
- p[2].y = this.center.y - this.extent.y;
- p[3].x = this.center.x - this.extent.x;
- p[3].y = this.center.y + this.extent.y;
-
- // Transform the four points of the bounding box with the matrix
- * Compute the union of this BoundingInfo2D with another one and store the result in a third valid BoundingInfo2D object
- * This is a GC friendly version, try to use it as much as possible, specially if your transformation is inside a loop, allocate the result object once for good outside of the loop and use it every time.
- * @param other the second object used to compute the union
- * @param result a VALID BoundingInfo2D instance (i.e. allocated) where the result will be stored
- */
- public unionToRef(other: BoundingInfo2D, result: BoundingInfo2D) {
- let xmax = Math.max(this.center.x + this.extent.x, other.center.x + other.extent.x);
- let ymax = Math.max(this.center.y + this.extent.y, other.center.y + other.extent.y);
- let xmin = Math.min(this.center.x - this.extent.x, other.center.x - other.extent.x);
- let ymin = Math.min(this.center.y - this.extent.y, other.center.y - other.extent.y);
- * @returns the color object. Note that it's not a clone of the actual object stored in the instance so you MUST NOT modify it, otherwise unexpected behavior might occurs.
- */
- get: function () {
- return this._color;
- },
- set: function (value) {
- if (this.isLocked()) {
- return;
- }
- this._color = value;
- },
- enumerable: true,
- configurable: true
- });
- /**
- * Return a unique identifier of the instance, which is simply the hexadecimal representation (CSS Style) of the solid color.
- */
- SolidColorBrush2D.prototype.toString = function () {
- return this._color.toHexString();
- };
- SolidColorBrush2D = __decorate([
- BABYLON.className("SolidColorBrush2D")
- ], SolidColorBrush2D);
- return SolidColorBrush2D;
- }(LockableBase));
- BABYLON.SolidColorBrush2D = SolidColorBrush2D;
- var GradientColorBrush2D = (function (_super) {
- __extends(GradientColorBrush2D, _super);
- function GradientColorBrush2D(color1, color2, translation, rotation, scale, lock) {
- * This interface is used to implement a lockable instance pattern.
- * Classes that implements it may be locked at any time, making their content immutable from now on.
- * You also can query if a given instance is locked or not.
- * This allow instances to be shared among several 'consumers'.
- */
- export interface ILockable {
- /**
- * Query the lock state
- * @returns returns true if the object is locked and immutable, false if it's not
- */
- isLocked(): boolean;
-
- /**
- * A call to this method will definitely lock the instance, making its content immutable
- * @returns the previous lock state of the object. so if true is returned the object were already locked and this method does nothing, if false is returned it means the object wasn't locked and this call locked it for good.
- */
- lock(): boolean;
- }
-
- /**
- * This interface defines the IBrush2D contract.
- * Classes implementing a new type of Brush2D must implement this interface
- */
- export interface IBrush2D extends ILockable {
- /**
- * Define if the brush will use transparency / alpha blending
- * @returns true if the brush use transparency
- */
- isTransparent(): boolean;
-
- /**
- * It is critical for each instance of a given Brush2D type to return a unique string that identifies it because the Border instance will certainly be part of the computed ModelKey for a given Primitive
- * @returns A string identifier that uniquely identify the instance
- */
- toString(): string;
- }
-
- /**
- * Base class implementing the ILocable interface.
- * The particularity of this class is to call the protected onLock() method when the instance is about to be locked for good.
- */
- export class LockableBase implements ILockable {
- isLocked(): boolean {
- return this._isLocked;
- }
-
- private _isLocked: boolean;
-
- lock(): boolean {
- if (this._isLocked) {
- return true;
- }
-
- this.onLock();
- this._isLocked = true;
- return false;
- }
-
- /**
- * Protected handler that will be called when the instance is about to be locked.
- */
- protected onLock() {
-
- }
- }
-
- @className("SolidColorBrush2D")
- /**
- * This class implements a Brush that will be drawn with a uniform solid color (i.e. the same color everywhere in the content where the brush is assigned to).
- */
- export class SolidColorBrush2D extends LockableBase implements IBrush2D {
- * Return true if the brush is transparent, false if it's totally opaque
- */
- isTransparent(): boolean {
- return this._color && this._color.a < 1.0;
- }
-
- /**
- * The color used by this instance to render
- * @returns the color object. Note that it's not a clone of the actual object stored in the instance so you MUST NOT modify it, otherwise unexpected behavior might occurs.
- */
- public get color(): Color4 {
- return this._color;
- }
-
- public set color(value: Color4) {
- if (this.isLocked()) {
- return;
- }
-
- this._color = value;
- }
-
- /**
- * Return a unique identifier of the instance, which is simply the hexadecimal representation (CSS Style) of the solid color.
- */
- public toString(): string {
- return this._color.toHexString();
- }
- private _color: Color4;
- }
-
- @className("GradientColorBrush2D")
- /**
- * This class implements a Gradient Color Brush, the brush color will blend from a first given color to a second one.
- */
- export class GradientColorBrush2D extends LockableBase implements IBrush2D {
- * A stack panel layout. Primitive will be stack either horizontally or vertically.
- * This Layout type must be used as a Singleton, use the StackPanelLayoutEngine.Horizontal for an horizontal stack panel or StackPanelLayoutEngine.Vertical for a vertical one.
- */
- export class StackPanelLayoutEngine extends LayoutEngineBase {
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id: a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - size: the size of the group. Alternatively the width and height properties can be set. Default will be [10;10].
- * - subdivision: the number of subdivision to create the ellipse perimeter, default is 64.
- * - fill: the brush used to draw the fill content of the ellipse, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
- * - border: the brush used to draw the border of the ellipse, you can set null to draw nothing (but you will have to set a fill brush), default is null. can be a string value (see Canvas2D.GetBrushFromString)
- * - borderThickness: the thickness of the drawn border, default is 1.
- * - isVisible: true if the group must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- */
- function Ellipse2D(settings) {
- // Avoid checking every time if the object exists
- if (settings == null) {
- settings = {};
- }
- _super.call(this, settings);
- if (settings.size != null) {
- this.size = settings.size;
- }
- else if (settings.width || settings.height) {
- var size = new BABYLON.Size(settings.width, settings.height);
- this.size = size;
- }
- var sub = (settings.subdivisions == null) ? 64 : settings.subdivisions;
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id: a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - size: the size of the group. Alternatively the width and height properties can be set. Default will be [10;10].
- * - subdivision: the number of subdivision to create the ellipse perimeter, default is 64.
- * - fill: the brush used to draw the fill content of the ellipse, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
- * - border: the brush used to draw the border of the ellipse, you can set null to draw nothing (but you will have to set a fill brush), default is null. can be a string value (see Canvas2D.GetBrushFromString)
- * - borderThickness: the thickness of the drawn border, default is 1.
- * - isVisible: true if the group must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- */
- constructor(settings?: {
-
- parent ?: Prim2DBase,
- children ?: Array<Prim2DBase>,
- id ?: string,
- position ?: Vector2,
- x ?: number,
- y ?: number,
- rotation ?: number,
- scale ?: number,
- scaleX ?: number,
- scaleY ?: number,
- dontInheritParentScale?: boolean,
- opacity ?: number,
- zOrder ?: number,
- origin ?: Vector2,
- size ?: Size,
- width ?: number,
- height ?: number,
- subdivisions ?: number,
- fill ?: IBrush2D | string,
- border ?: IBrush2D | string,
- borderThickness ?: number,
- isVisible ?: boolean,
- isPickable ?: boolean,
- isContainer ?: boolean,
- childrenFlatZOrder ?: boolean,
- marginTop ?: number | string,
- marginLeft ?: number | string,
- marginRight ?: number | string,
- marginBottom ?: number | string,
- margin ?: number | string,
- marginHAlignment ?: number,
- marginVAlignment ?: number,
- marginAlignment ?: string,
- paddingTop ?: number | string,
- paddingLeft ?: number | string,
- paddingRight ?: number | string,
- paddingBottom ?: number | string,
- padding ?: string,
- }) {
-
- // Avoid checking every time if the object exists
- if (settings == null) {
- settings = {};
- }
-
- super(settings);
-
- if (settings.size != null) {
- this.size = settings.size;
- }
- else if (settings.width || settings.height) {
- let size = new Size(settings.width, settings.height);
- this.size = size;
- }
-
- let sub = (settings.subdivisions == null) ? 64 : settings.subdivisions;
- * Create an Rectangle 2D Shape primitive. May be a sharp rectangle (with sharp corners), or a rounded one.
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y settings can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - size: the size of the group. Alternatively the width and height settings can be set. Default will be [10;10].
- * - roundRadius: if the rectangle has rounded corner, set their radius, default is 0 (to get a sharp edges rectangle).
- * - fill: the brush used to draw the fill content of the rectangle, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
- * - border: the brush used to draw the border of the rectangle, you can set null to draw nothing (but you will have to set a fill brush), default is null. can also be a string value (see Canvas2D.GetBrushFromString)
- * - borderThickness: the thickness of the drawn border, default is 1.
- * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- */
- function Rectangle2D(settings) {
- // Avoid checking every time if the object exists
- if (settings == null) {
- settings = {};
- }
- _super.call(this, settings);
- if (settings.size != null) {
- this.size = settings.size;
- }
- else if (settings.width || settings.height) {
- var size = new BABYLON.Size(settings.width, settings.height);
- Rectangle2D.prototype.levelIntersect = function (intersectInfo) {
- // If we got there it mean the boundingInfo intersection succeed, if the rectangle has not roundRadius, it means it succeed!
- if (this.notRounded) {
- return true;
- }
- // If we got so far it means the bounding box at least passed, so we know it's inside the bounding rectangle, but it can be outside the roundedRectangle.
- // The easiest way is to check if the point is inside on of the four corners area (a little square of roundRadius size at the four corners)
- // If it's the case for one, check if the mouse is located in the quarter that we care about (the one who is visible) then finally make a distance check with the roundRadius radius to see if it's inside the circle quarter or outside.
- // First let remove the origin out the equation, to have the rectangle with an origin at bottom/left
- // We override this method because if there's a roundRadius set, we will reduce the initial Content Area to make sure the computed area won't intersect with the shape contour. The formula is simple: we shrink the incoming size by the amount of the roundRadius
- Rectangle2D.prototype._getInitialContentAreaToRef = function (primSize, initialContentPosition, initialContentArea) {
- // Fall back to default implementation if there's no round Radius
- @modelLevelProperty(Shape2D.SHAPE2D_PROPCOUNT + 2, pi => Rectangle2D.notRoundedProperty = pi)
- /**
- * Get if the rectangle is notRound (returns true) or rounded (returns false).
- * Don't use the setter, it's for internal purpose only
- */
- public get notRounded(): boolean {
- return this._notRounded;
- }
-
- public set notRounded(value: boolean) {
- this._notRounded = value;
- }
-
- @instanceLevelProperty(Shape2D.SHAPE2D_PROPCOUNT + 3, pi => Rectangle2D.roundRadiusProperty = pi)
- /**
- * Get/set the round Radius, a value of 0 for a sharp edges rectangle, otherwise the value will be used as the diameter of the round to apply on corder. The Rectangle2D.notRounded property will be updated accordingly.
- // If we got there it mean the boundingInfo intersection succeed, if the rectangle has not roundRadius, it means it succeed!
- if (this.notRounded) {
- return true;
- }
-
- // If we got so far it means the bounding box at least passed, so we know it's inside the bounding rectangle, but it can be outside the roundedRectangle.
- // The easiest way is to check if the point is inside on of the four corners area (a little square of roundRadius size at the four corners)
- // If it's the case for one, check if the mouse is located in the quarter that we care about (the one who is visible) then finally make a distance check with the roundRadius radius to see if it's inside the circle quarter or outside.
-
- // First let remove the origin out the equation, to have the rectangle with an origin at bottom/left
- * Create an Rectangle 2D Shape primitive. May be a sharp rectangle (with sharp corners), or a rounded one.
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y settings can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - size: the size of the group. Alternatively the width and height settings can be set. Default will be [10;10].
- * - roundRadius: if the rectangle has rounded corner, set their radius, default is 0 (to get a sharp edges rectangle).
- * - fill: the brush used to draw the fill content of the rectangle, you can set null to draw nothing (but you will have to set a border brush), default is a SolidColorBrush of plain white. can also be a string value (see Canvas2D.GetBrushFromString)
- * - border: the brush used to draw the border of the rectangle, you can set null to draw nothing (but you will have to set a fill brush), default is null. can also be a string value (see Canvas2D.GetBrushFromString)
- * - borderThickness: the thickness of the drawn border, default is 1.
- * - isVisible: true if the primitive must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- */
- constructor(settings ?: {
- parent ?: Prim2DBase,
- children ?: Array<Prim2DBase>,
- id ?: string,
- position ?: Vector2,
- x ?: number,
- y ?: number,
- rotation ?: number,
- scale ?: number,
- scaleX ?: number,
- scaleY ?: number,
- dontInheritParentScale?: boolean,
- opacity ?: number,
- zOrder ?: number,
- origin ?: Vector2,
- size ?: Size,
- width ?: number,
- height ?: number,
- roundRadius ?: number,
- fill ?: IBrush2D | string,
- border ?: IBrush2D | string,
- borderThickness ?: number,
- isVisible ?: boolean,
- isPickable ?: boolean,
- isContainer ?: boolean,
- childrenFlatZOrder ?: boolean,
- marginTop ?: number | string,
- marginLeft ?: number | string,
- marginRight ?: number | string,
- marginBottom ?: number | string,
- margin ?: number | string,
- marginHAlignment ?: number,
- marginVAlignment ?: number,
- marginAlignment ?: string,
- paddingTop ?: number | string,
- paddingLeft ?: number | string,
- paddingRight ?: number | string,
- paddingBottom ?: number | string,
- padding ?: string,
- }) {
-
- // Avoid checking every time if the object exists
- if (settings == null) {
- settings = {};
- }
-
- super(settings);
-
- if (settings.size != null) {
- this.size = settings.size;
- }
- else if (settings.width || settings.height) {
- let size = new Size(settings.width, settings.height);
- // We override this method because if there's a roundRadius set, we will reduce the initial Content Area to make sure the computed area won't intersect with the shape contour. The formula is simple: we shrink the incoming size by the amount of the roundRadius
- // At this stage we have everything correctly initialized, ModelRenderCache is setup, Model Instance data are good too, they have allocated elements in the Instanced DynamicFloatArray.
- // The last thing to do is check if the instanced related data must be updated because a InstanceLevel property had changed or the primitive visibility changed.
- var pd = new BABYLON.ModelRenderCachePartData();
- this._modelRenderCache._partData.push(pd);
- var cat = this.getUsedShaderCategories(dataPart);
- var cti = dataPart.getClassTreeInfo();
- // Make sure the instance is visible other the properties won't be set and their size/offset wont be computed
- var curVisible = this.isVisible;
- this.isVisible = true;
- // We manually trigger refreshInstanceData for the only sake of evaluating each instance property size and offset in the instance data, this can only be made at runtime. Once it's done we have all the information to create the instance data buffer.
- //console.log("Build Prop Layout for " + Tools.getClassName(this._instanceDataParts[0]));
- var joinCat = ";" + cat.join(";") + ";";
- pd._partJoinedUsedCategories = joinCat;
- InstanceClassInfo._CurCategories = joinCat;
- var obj = this.beforeRefreshForLayoutConstruction(dataPart);
- if (!this.refreshInstanceDataPart(dataPart)) {
- console.log("Layout construction for " + BABYLON.Tools.getClassName(this._instanceDataParts[0]) + " failed because refresh returned false");
- console.log("ERROR: Couldn't detect the size of the Property " + v.attributeName + " from type " + BABYLON.Tools.getClassName(cti.type) + ". Property is ignored.");
- * Transform a given point using the Primitive's origin setting.
- * This method requires the Primitive's actualSize to be accurate
- * @param p the point to transform
- * @param originOffset an offset applied on the current origin before performing the transformation. Depending on which frame of reference your data is expressed you may have to apply a offset. (if you data is expressed from the bottom/left, no offset is required. If it's expressed from the center the a [-0.5;-0.5] offset has to be applied.
- * @param res an allocated Vector2 that will receive the transformed content
- */
- RenderablePrim2D.prototype.transformPointWithOriginByRef = function (p, originOffset, res) {
- * Get the info for a given effect based on the dataPart metadata
- * @param dataPartId partId in part list to get the info
- * @param vertexBufferAttributes vertex buffer attributes to manually add
- * @param uniforms uniforms to manually add
- * @param useInstanced specified if Instanced Array should be used, if null the engine caps will be used (so true if WebGL supports it, false otherwise), but you have the possibility to override the engine capability. However, if you manually set true but the engine does not support Instanced Array, this method will return null
- */
- RenderablePrim2D.prototype.getDataPartEffectInfo = function (dataPartId, vertexBufferAttributes, uniforms, useInstanced) {
- RenderablePrim2D.prototype.createModelRenderCache = function (modelKey) {
- return null;
- };
- RenderablePrim2D.prototype.setupModelRenderCache = function (modelRenderCache) {
- };
- RenderablePrim2D.prototype.createInstanceDataParts = function () {
- return null;
- };
- RenderablePrim2D.prototype.getUsedShaderCategories = function (dataPart) {
- return [];
- };
- RenderablePrim2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
- };
- RenderablePrim2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
- };
- RenderablePrim2D.prototype.applyActualScaleOnTransform = function () {
- return true;
- };
- RenderablePrim2D.prototype.refreshInstanceDataPart = function (part) {
- if (!this.isVisible) {
- return false;
- }
- part.isVisible = this.isVisible;
- // Which means, if there's only one data element, we're update it from this method, otherwise it is the responsibility of the derived class to call updateInstanceDataPart as many times as needed, properly (look at Text2D's implementation for more information)
- if (part.dataElementCount === 1) {
- part.curElement = 0;
- this.updateInstanceDataPart(part);
- }
- return true;
- };
- /**
- * Update the instanceDataBase level properties of a part
- * @param part the part to update
- * @param positionOffset to use in multi part per primitive (e.g. the Text2D has N parts for N letter to display), this give the offset to apply (e.g. the position of the letter from the bottom/left corner of the text).
- */
- RenderablePrim2D.prototype.updateInstanceDataPart = function (part, positionOffset) {
- var t = this._globalTransform.multiply(this.renderGroup.invGlobalTransform); // Compute the transformation into the renderGroup's space
- var rgScale = this._areSomeFlagsSet(BABYLON.SmartPropertyPrim.flagDontInheritParentScale) ? RenderablePrim2D._uV : this.renderGroup.actualScale; // We still need to apply the scale of the renderGroup to our rendering, so get it.
- var size = this.renderGroup.viewportSize;
- var zBias = this.actualZOffset;
- var offX = 0;
- var offY = 0;
- // If there's an offset, apply the global transformation matrix on it to get a global offset
- // Have to convert the coordinates to clip space which is ranged between [-1;1] on X and Y axis, with 0,0 being the left/bottom corner
- // Current coordinates are expressed in renderGroup coordinates ([0, renderGroup.actualSize.width|height]) with 0,0 being at the left/top corner
- // So for X:
- // - tx.x = value * 2 / width: is to switch from [0, renderGroup.width] to [0, 2]
- // - tx.w = (value * 2 / width) - 1: w stores the translation in renderGroup coordinates so (value * 2 / width) to switch to a clip space translation value. - 1 is to offset the overall [0;2] to [-1;1].
- // At last we don't forget to apply the actualScale of the Render Group to tx[0] and ty[1] to propagate scaling correctly
- // At this stage we have everything correctly initialized, ModelRenderCache is setup, Model Instance data are good too, they have allocated elements in the Instanced DynamicFloatArray.
-
- // The last thing to do is check if the instanced related data must be updated because a InstanceLevel property had changed or the primitive visibility changed.
- let ctiArray = new Array<ClassTreeInfo<InstanceClassInfo, InstancePropInfo>>();
- this._modelRenderCache._partData = new Array<ModelRenderCachePartData>();
- for (let dataPart of parts) {
- var pd = new ModelRenderCachePartData();
- this._modelRenderCache._partData.push(pd)
- var cat = this.getUsedShaderCategories(dataPart);
- var cti = dataPart.getClassTreeInfo();
- // Make sure the instance is visible other the properties won't be set and their size/offset wont be computed
- let curVisible = this.isVisible;
- this.isVisible = true;
- // We manually trigger refreshInstanceData for the only sake of evaluating each instance property size and offset in the instance data, this can only be made at runtime. Once it's done we have all the information to create the instance data buffer.
- //console.log("Build Prop Layout for " + Tools.getClassName(this._instanceDataParts[0]));
- var joinCat = ";" + cat.join(";") + ";";
- pd._partJoinedUsedCategories = joinCat;
- InstanceClassInfo._CurCategories = joinCat;
- let obj = this.beforeRefreshForLayoutConstruction(dataPart);
- if (!this.refreshInstanceDataPart(dataPart)) {
- console.log(`Layout construction for ${Tools.getClassName(this._instanceDataParts[0])} failed because refresh returned false`);
- * Transform a given point using the Primitive's origin setting.
- * This method requires the Primitive's actualSize to be accurate
- * @param p the point to transform
- * @param originOffset an offset applied on the current origin before performing the transformation. Depending on which frame of reference your data is expressed you may have to apply a offset. (if you data is expressed from the bottom/left, no offset is required. If it's expressed from the center the a [-0.5;-0.5] offset has to be applied.
- * @param res an allocated Vector2 that will receive the transformed content
- * Get the info for a given effect based on the dataPart metadata
- * @param dataPartId partId in part list to get the info
- * @param vertexBufferAttributes vertex buffer attributes to manually add
- * @param uniforms uniforms to manually add
- * @param useInstanced specified if Instanced Array should be used, if null the engine caps will be used (so true if WebGL supports it, false otherwise), but you have the possibility to override the engine capability. However, if you manually set true but the engine does not support Instanced Array, this method will return null
- // Which means, if there's only one data element, we're update it from this method, otherwise it is the responsibility of the derived class to call updateInstanceDataPart as many times as needed, properly (look at Text2D's implementation for more information)
- if (part.dataElementCount === 1) {
- part.curElement = 0;
- this.updateInstanceDataPart(part);
- }
- return true;
- }
-
- private static _uV = new Vector2(1, 1);
-
- /**
- * Update the instanceDataBase level properties of a part
- * @param part the part to update
- * @param positionOffset to use in multi part per primitive (e.g. the Text2D has N parts for N letter to display), this give the offset to apply (e.g. the position of the letter from the bottom/left corner of the text).
- let t = this._globalTransform.multiply(this.renderGroup.invGlobalTransform); // Compute the transformation into the renderGroup's space
- let rgScale = this._areSomeFlagsSet(SmartPropertyPrim.flagDontInheritParentScale) ? RenderablePrim2D._uV : this.renderGroup.actualScale; // We still need to apply the scale of the renderGroup to our rendering, so get it.
- let size = (<Size>this.renderGroup.viewportSize);
- let zBias = this.actualZOffset;
-
- let offX = 0;
- let offY = 0;
- // If there's an offset, apply the global transformation matrix on it to get a global offset
- // Have to convert the coordinates to clip space which is ranged between [-1;1] on X and Y axis, with 0,0 being the left/bottom corner
- // Current coordinates are expressed in renderGroup coordinates ([0, renderGroup.actualSize.width|height]) with 0,0 being at the left/top corner
- // So for X:
- // - tx.x = value * 2 / width: is to switch from [0, renderGroup.width] to [0, 2]
- // - tx.w = (value * 2 / width) - 1: w stores the translation in renderGroup coordinates so (value * 2 / width) to switch to a clip space translation value. - 1 is to offset the overall [0;2] to [-1;1].
- // At last we don't forget to apply the actualScale of the Render Group to tx[0] and ty[1] to propagate scaling correctly
- * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
- * @returns false if the object is already dispose, true otherwise. Your implementation must call super.dispose() and check for a false return and return immediately if it's the case.
- */
- SmartPropertyPrim.prototype.dispose = function () {
- * Base class of the primitives, implementing core crosscutting features
- */
- export abstract class SmartPropertyPrim implements IPropertyChanged {
-
- constructor() {
- this._flags = 0;
- this._modelKey = null;
- this._instanceDirtyFlags = 0;
- this._levelBoundingInfo = new BoundingInfo2D();
- this.animations = new Array<Animation>();
- }
-
- /**
- * An observable that is triggered when a property (using of the XXXXLevelProperty decorator) has its value changing.
- * You can add an observer that will be triggered only for a given set of Properties using the Mask feature of the Observable and the corresponding Prim2DPropInfo.flagid value (e.g. Prim2DBase.positionProperty.flagid|Prim2DBase.rotationProperty.flagid to be notified only about position or rotation change)
- */
- public propertyChanged: Observable<PropertyChangedInfo>;
-
- /**
- * Check if the object is disposed or not.
- * @returns true if the object is dispose, false otherwise.
- * Disposable pattern, this method must be overloaded by derived types in order to clean up hardware related resources.
- * @returns false if the object is already dispose, true otherwise. Your implementation must call super.dispose() and check for a false return and return immediately if it's the case.
- * @param texture the texture that stores the sprite to render
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - spriteSize: the size of the sprite (in pixels), if null the size of the given texture will be used, default is null.
- * - spriteLocation: the location (in pixels) in the texture of the top/left corner of the Sprite to display, default is null (0,0)
- * - spriteScaleFactor: say you want to display a sprite twice as big as its bitmap which is 64,64, you set the spriteSize to 128,128 and have to set the spriteScaleFactory to 0.5,0.5 in order to address only the 64,64 pixels of the bitmaps. Default is 1,1.
- * - invertY: if true the texture Y will be inverted, default is false.
- * - alignToPixel: if true the sprite's texels will be aligned to the rendering viewport pixels, ensuring the best rendering quality but slow animations won't be done as smooth as if you set false. If false a texel could lies between two pixels, being blended by the texture sampling mode you choose, the rendering result won't be as good, but very slow animation will be overall better looking. Default is true: content will be aligned.
- * - isVisible: true if the sprite must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- if (settings.spriteSize == null || !texture.isReady()) {
- if (texture.isReady()) {
- this.size = texture.getBaseSize();
- }
- else {
- texture.onLoadObservable.add(function () {
- if (settings.spriteSize == null) {
- _this.size = texture.getBaseSize();
- }
- _this._positioningDirty();
- _this._instanceDirtyFlags |= BABYLON.Prim2DBase.originProperty.flagId | Sprite2D.textureProperty.flagId; // To make sure the sprite is issued again for render
- @dynamicLevelProperty(RenderablePrim2D.RENDERABLEPRIM2D_PROPCOUNT + 2, pi => Sprite2D.useAlphaFromTextureProperty = pi)
- /**
- * If true and the texture has an Alpha Channel which is used (BaseTexture.hasAlpha = true) the Sprite2d will be rendered as a Transparent Primitive, if false and the texture has an Alpha Channel which is used (BaseTexture.hasAlpha = true) the Sprite2d will be rendered as Alpha Test. If false or if the Texture has no alpha or it's not used (BaseTexture.hasAlpha = false) the Sprite2d will be rendered as an Opaque Primitive
- */
- public get useAlphaFromTexture(): boolean {
- return this._useAlphaFromTexture;
- }
-
- public set useAlphaFromTexture(value: boolean) {
- // If we've made it so far it means the boundingInfo intersection test succeed, the Sprite2D is shaped the same, so we always return true
- return true;
- }
-
- /**
- * Create an 2D Sprite primitive
- * @param texture the texture that stores the sprite to render
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - spriteSize: the size of the sprite (in pixels), if null the size of the given texture will be used, default is null.
- * - spriteLocation: the location (in pixels) in the texture of the top/left corner of the Sprite to display, default is null (0,0)
- * - spriteScaleFactor: say you want to display a sprite twice as big as its bitmap which is 64,64, you set the spriteSize to 128,128 and have to set the spriteScaleFactory to 0.5,0.5 in order to address only the 64,64 pixels of the bitmaps. Default is 1,1.
- * - invertY: if true the texture Y will be inverted, default is false.
- * - alignToPixel: if true the sprite's texels will be aligned to the rendering viewport pixels, ensuring the best rendering quality but slow animations won't be done as smooth as if you set false. If false a texel could lies between two pixels, being blended by the texture sampling mode you choose, the rendering result won't be as good, but very slow animation will be overall better looking. Default is true: content will be aligned.
- * - isVisible: true if the sprite must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- */
- constructor(texture: Texture, settings?: {
-
- parent ?: Prim2DBase,
- children ?: Array<Prim2DBase>,
- id ?: string,
- position ?: Vector2,
- x ?: number,
- y ?: number,
- rotation ?: number,
- scale ?: number,
- scaleX ?: number,
- scaleY ?: number,
- dontInheritParentScale?: boolean,
- opacity ?: number,
- zOrder ?: number,
- origin ?: Vector2,
- spriteSize ?: Size,
- spriteLocation ?: Vector2,
- spriteScaleFactor ?: Vector2,
- invertY ?: boolean,
- alignToPixel ?: boolean,
- isVisible ?: boolean,
- isPickable ?: boolean,
- isContainer ?: boolean,
- childrenFlatZOrder ?: boolean,
- marginTop ?: number | string,
- marginLeft ?: number | string,
- marginRight ?: number | string,
- marginBottom ?: number | string,
- margin ?: number | string,
- marginHAlignment ?: number,
- marginVAlignment ?: number,
- marginAlignment ?: string,
- paddingTop ?: number | string,
- paddingLeft ?: number | string,
- paddingRight ?: number | string,
- paddingBottom ?: number | string,
- padding ?: string,
- }) {
-
- if (!settings) {
- settings = {};
- }
-
- super(settings);
-
- this.texture = texture;
- this.texture.wrapU = Texture.CLAMP_ADDRESSMODE;
- this.texture.wrapV = Texture.CLAMP_ADDRESSMODE;
- this.size = settings.spriteSize;
- this.spriteLocation = settings.spriteLocation || new Vector2(0, 0);
- this.spriteScaleFactor = settings.spriteScaleFactor || new Vector2(1, 1);
- if (settings.spriteSize == null || !texture.isReady()) {
- if (texture.isReady()) {
- this.size = <Size>texture.getBaseSize();
- } else {
- texture.onLoadObservable.add(() => {
- if (settings.spriteSize == null) {
- this.size = <Size>texture.getBaseSize();
- }
- this._positioningDirty();
- this._instanceDirtyFlags |= Prim2DBase.originProperty.flagId | Sprite2D.textureProperty.flagId; // To make sure the sprite is issued again for render
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - fontName: the name/size/style of the font to use, following the CSS notation. Default is "12pt Arial".
- * - fontSuperSample: if true the text will be rendered with a superSampled font (the font is twice the given size). Use this settings if the text lies in world space or if it's scaled in.
- * - defaultFontColor: the color by default to apply on each letter of the text to display, default is plain white.
- * - areaSize: the size of the area in which to display the text, default is auto-fit from text content.
- * - tabulationSize: number of space character to insert when a tabulation is encountered, default is 4
- * - isVisible: true if the text must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- Text2D.prototype.levelIntersect = function (intersectInfo) {
- // For now I can't do something better that boundingInfo is a hit, detecting an intersection on a particular letter would be possible, but do we really need it? Not for now...
- return true;
- };
- Text2D.prototype.createModelRenderCache = function (modelKey) {
- var renderCache = new Text2DRenderCache(this.owner.engine, modelKey);
- return renderCache;
- };
- Text2D.prototype.setupModelRenderCache = function (modelRenderCache) {
- // Looks like a hack!? Yes! Because that's what it is!
- // For the InstanceData layer to compute correctly we need to set all the properties involved, which won't be the case if there's no text
- // This method is called before the layout construction for us to detect this case, set some text and return the initial one to restore it after (there can be some text without char to display, say "\t\n" for instance)
- Text2D.prototype.beforeRefreshForLayoutConstruction = function (part) {
- if (!this._charCount) {
- var curText = this._text;
- this.text = "A";
- return curText;
- }
- };
- // if obj contains something, we restore the _text property
- Text2D.prototype.afterRefreshForLayoutConstruction = function (part, obj) {
- if (obj !== undefined) {
- this.text = obj;
- }
- };
- Text2D.prototype.refreshInstanceDataPart = function (part) {
- if (!_super.prototype.refreshInstanceDataPart.call(this, part)) {
- return false;
- }
- if (part.id === Text2D.TEXT2D_MAINPARTID) {
- var d = part;
- var texture = this.fontTexture;
- var superSampleFactor = texture.isSuperSampled ? 0.5 : 1;
- var ts = texture.getSize();
- var offset = BABYLON.Vector2.Zero();
- var lh = this.fontTexture.lineHeight;
- offset.y = ((this.textSize.height / lh) - 1) * lh; // Origin is bottom, not top, so the offset is starting with a y that is the top location of the text
- * @param settings a combination of settings, possible ones are
- * - parent: the parent primitive/canvas, must be specified if the primitive is not constructed as a child of another one (i.e. as part of the children array setting)
- * - children: an array of direct children
- * - id a text identifier, for information purpose
- * - position: the X & Y positions relative to its parent. Alternatively the x and y properties can be set. Default is [0;0]
- * - rotation: the initial rotation (in radian) of the primitive. default is 0
- * - scale: the initial scale of the primitive. default is 1. You can alternatively use scaleX &| scaleY to apply non uniform scale
- * - dontInheritParentScale: if set the parent's scale won't be taken into consideration to compute the actualScale property
- * - opacity: set the overall opacity of the primitive, 1 to be opaque (default), less than 1 to be transparent.
- * - zOrder: override the zOrder with the specified value
- * - origin: define the normalized origin point location, default [0.5;0.5]
- * - fontName: the name/size/style of the font to use, following the CSS notation. Default is "12pt Arial".
- * - fontSuperSample: if true the text will be rendered with a superSampled font (the font is twice the given size). Use this settings if the text lies in world space or if it's scaled in.
- * - defaultFontColor: the color by default to apply on each letter of the text to display, default is plain white.
- * - areaSize: the size of the area in which to display the text, default is auto-fit from text content.
- * - tabulationSize: number of space character to insert when a tabulation is encountered, default is 4
- * - isVisible: true if the text must be visible, false for hidden. Default is true.
- * - isPickable: if true the Primitive can be used with interaction mode and will issue Pointer Event. If false it will be ignored for interaction/intersection test. Default value is true.
- * - isContainer: if true the Primitive acts as a container for interaction, if the primitive is not pickable or doesn't intersection, no further test will be perform on its children. If set to false, children will always be considered for intersection/interaction. Default value is true.
- * - childrenFlatZOrder: if true all the children (direct and indirect) will share the same Z-Order. Use this when there's a lot of children which don't overlap. The drawing order IS NOT GUARANTED!
- * - marginTop: top margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginLeft: left margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginRight: right margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - marginBottom: bottom margin, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - margin: top, left, right and bottom margin formatted as a single string (see PrimitiveThickness.fromString)
- * - marginHAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginVAlignment: one value of the PrimitiveAlignment type's static properties
- * - marginAlignment: a string defining the alignment, see PrimitiveAlignment.fromString
- * - paddingTop: top padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingLeft: left padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingRight: right padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - paddingBottom: bottom padding, can be a number (will be pixels) or a string (see PrimitiveThickness.fromString)
- * - padding: top, left, right and bottom padding formatted as a single string (see PrimitiveThickness.fromString)
- // For now I can't do something better that boundingInfo is a hit, detecting an intersection on a particular letter would be possible, but do we really need it? Not for now...
- // Looks like a hack!? Yes! Because that's what it is!
- // For the InstanceData layer to compute correctly we need to set all the properties involved, which won't be the case if there's no text
- // This method is called before the layout construction for us to detect this case, set some text and return the initial one to restore it after (there can be some text without char to display, say "\t\n" for instance)
- protected beforeRefreshForLayoutConstruction(part: InstanceDataBase): any {
- if (!this._charCount) {
- let curText = this._text;
- this.text = "A";
- return curText;
- }
- }
-
- // if obj contains something, we restore the _text property