UNPKG

@aidinabedi/playcanvas

Version:

PlayCanvas WebGL game engine

1,052 lines 1.19 MB
/** * @name pc * @namespace * @description Root namespace for the PlayCanvas Engine. */ declare namespace pc { /** * @constant * @type {number} * @name pc.INTERPOLATION_STEP * @description A stepped interpolation scheme. */ const INTERPOLATION_STEP: number; /** * @constant * @type {number} * @name pc.INTERPOLATION_LINEAR * @description A linear interpolation scheme. */ const INTERPOLATION_LINEAR: number; /** * @constant * @type {number} * @name pc.INTERPOLATION_CUBIC * @description A cubic spline interpolation scheme. */ const INTERPOLATION_CUBIC: number; /** * @class * @name pc.AnimData * @classdesc Wraps a set of data used in animation. * @description Create a new animation data container. * @param {number} dimension - Specifies the number of components which make up an element * of data. For example, specify 3 for a set of 3-dimensional vectors. The number of elements * in data must be a multiple of dimension. * @param {Float32Array|number[]} data - The set of data */ class AnimData { constructor(dimension: number, data: Float32Array | number[]); } /** * @class * @name pc.AnimCache * @classdesc Internal cache data for the evaluation of a single curve timeline. * @description Create a new animation cache. */ class AnimCache { } /** * @class * @name pc.AnimCurve * @classdesc Animation curve links an input data set to an output data set * and defines the interpolation method to use. * @description Create a new animation curve * @param {number} input - index of the curve which specifies the key data. * @param {number} output - index of the curve which specifies the value data. * @param {number} interpolation - the interpolation method to use. One of the following: * * * {@link pc.INTERPOLATION_STEP} * * {@link pc.INTERPOLATION_LINEAR} * * {@link pc.INTERPOLATION_CUBIC} * */ class AnimCurve { constructor(input: number, output: number, interpolation: number); } /** * @class * @name pc.AnimTarget * @classdesc AnimTarget names a target graph node and specifies the curves which drive translation, rotation and scale. * @description Create a new animation target. * @param {string} name - the target node to control. * @param {number} translation - the curve index controlling the translation of the target node or -1 for none. * @param {number} rotation - the curve index controlling the rotation of the target node or -1 for none. * @param {number} scale - the curve index controlling the scale of the target node or -1 for none. */ class AnimTarget { constructor(name: string, translation: number, rotation: number, scale: number); } /** * @class * @name pc.AnimTrack * @classdesc AnimTrack contains a set of curve data which can be used to animate a set of target nodes. * @description Create a new animation track. * @param {string} name - the track name * @param {number} duration - the duration of the track in seconds. * @param {pc.AnimData[]} inputs - list of curve key data. * @param {pc.AnimData[]} outputs - list of curve value data. * @param {pc.AnimCurve[]} curves - the list of curves. * @param {pc.AnimTarget[]} targets - the list of targets. */ class AnimTrack { constructor(name: string, duration: number, inputs: pc.AnimData[], outputs: pc.AnimData[], curves: pc.AnimCurve[], targets: pc.AnimTarget[]); } /** * @class * @name pc.AnimSnapshot * @classdesc AnimSnapshot stores the state of an animation track at a particular time. * @description Create a new animation snapshot. * @param {pc.AnimTrack} animTrack - the source track. */ class AnimSnapshot { constructor(animTrack: pc.AnimTrack); } /** * @class * @name pc.AnimClip * @classdesc AnimClip wraps the running state of an animation track. It contains and update * the animation 'cursor' and performs looping logic. * @description Create a new animation clip. * @param {pc.AnimTrack} track - the animation data. * @param {number} time - the initial time of the clip. * @param {number} speed - speed of the animation playback. * @param {boolean} playing - true if the clip is playing and false otherwise. * @param {boolean} loop - whether the clip should loop. */ class AnimClip { constructor(track: pc.AnimTrack, time: number, speed: number, playing: boolean, loop: boolean); } /** * @class * @name pc.AnimController * @classdesc AnimContoller stores a set of animation clips and performs blending * between them. It then applies the resulting transforms to the target nodes. * @description Create a new animation controller. * @param {pc.GraphNode} graph - root of the scene graph to control. */ class AnimController { constructor(graph: pc.GraphNode); } /** * @class * @name pc.Node * @classdesc A animation node has a name and contains an array of keyframes. * @description Create a new animation node. */ class Node { } /** * @class * @name pc.Animation * @classdesc An animation is a sequence of keyframe arrays which map to the nodes of a skeletal hierarchy. * It controls how the nodes of the hierarchy are transformed over time. * @property {string} name Human-readable name of the animation. * @property {number} duration Duration of the animation in seconds. */ class Animation { /** * @function * @name pc.Animation#getNode * @description Gets a {@link pc.Node} by name. * @param {string} name - The name of the pc.Node. * @returns {pc.Node} The pc.Node with the specified name. */ getNode(name: string): pc.Node; /** * @readonly * @name pc.Animation#nodes * @type {pc.Node[]} * @description A read-only property to get array of animation nodes. */ readonly nodes: pc.Node[]; /** * @function * @name pc.Animation#addNode * @description Adds a node to the internal nodes array. * @param {pc.Node} node - The node to add. */ addNode(node: pc.Node): void; /** * Human-readable name of the animation. */ name: string; /** * Duration of the animation in seconds. */ duration: number; } /** * @class * @name pc.Skeleton * @classdesc Represents a skeleton used to play animations. * @param {pc.GraphNode} graph - The root pc.GraphNode of the skeleton. * @property {boolean} looping Determines whether skeleton is looping its animation. */ class Skeleton { constructor(graph: pc.GraphNode); /** * @function * @name pc.Skeleton#addTime * @description Progresses The animation assigned to The specified skeleton by The * supplied time delta. If the delta takes the animation passed its end point, if * the skeleton is set to loop, the animation will continue from the beginning. * Otherwise, the animation's current time will remain at its duration (i.e. the * end). * @param {number} delta - The time in seconds to progress the skeleton's animation. */ addTime(delta: number): void; /** * @function * @name pc.Skeleton#blend * @description Blends two skeletons together. * @param {pc.Skeleton} skel1 - Skeleton holding the first pose to be blended. * @param {pc.Skeleton} skel2 - Skeleton holding the second pose to be blended. * @param {number} alpha - The value controlling the interpolation in relation to the two input * skeletons. The value is in the range 0 to 1, 0 generating skel1, 1 generating skel2 and anything * in between generating a spherical interpolation between the two. */ blend(skel1: pc.Skeleton, skel2: pc.Skeleton, alpha: number): void; /** * @name pc.Skeleton#animation * @type {pc.Animation} * @description Animation currently assigned to skeleton. */ animation: pc.Animation; /** * @name pc.Skeleton#currentTime * @type {number} * @description Current time of currently active animation in seconds. * This value is between zero and the duration of the animation. */ currentTime: number; /** * @readonly * @name pc.Skeleton#numNodes * @type {number} * @description Read-only property that returns number of nodes of a skeleton. */ readonly numNodes: number; /** * @function * @name pc.Skeleton#setGraph * @description Links a skeleton to a node hierarchy. The nodes animated skeleton are * then subsequently used to drive the local transformation matrices of the node * hierarchy. * @param {pc.GraphNode} graph - The root node of the graph that the skeleton is to drive. */ setGraph(graph: pc.GraphNode): void; /** * @function * @name pc.Skeleton#updateGraph * @description Synchronizes the currently linked node hierarchy with the current state of the * skeleton. Internally, this function converts the interpolated keyframe at each node in the * skeleton into the local transformation matrix at each corresponding node in the linked node * hierarchy. */ updateGraph(): void; /** * Determines whether skeleton is looping its animation. */ looping: boolean; } /** * @class * @name pc.AssetReference * @description An object that manages the case where an object holds a reference to an asset and needs to be notified when * changes occur in the asset. e.g. notifications include load, add and remove events. * @param {string} propertyName - The name of the property that the asset is stored under, passed into callbacks to enable updating. * @param {pc.Asset|object} parent - The parent object that contains the asset reference, passed into callbacks to enable updating. Currently an asset, but could be component or other. * @param {pc.AssetRegistry} registry - The asset registry that stores all assets. * @param {object} callbacks - A set of functions called when the asset state changes: load, add, remove. * @param {object} [callbacks.load] - The function called when the asset loads load(propertyName, parent, asset). * @param {object} [callbacks.add] - The function called when the asset is added to the registry add(propertyName, parent, asset). * @param {object} [callbacks.remove] - The function called when the asset is remove from the registry remove(propertyName, parent, asset). * @param {object} [scope] - The scope to call the callbacks in * @property {number} id Get or set the asset id which this references. One of either id or url must be set to initialize an asset reference. * @property {string} url Get or set the asset url which this references. One of either id or url must be called to initialize an asset reference. * @example * * var reference = new pc.AssetReference('textureAsset', this, this.app.assets, { * load: this.onTextureAssetLoad, * add: this.onTextureAssetAdd, * remove: this.onTextureAssetRemove * }, this); * reference.id = this.textureAsset.id; */ class AssetReference { constructor(propertyName: string, parent: pc.Asset | any, registry: pc.AssetRegistry, callbacks: { load?: any; add?: any; remove?: any; }, scope?: any); /** * Get or set the asset id which this references. One of either id or url must be set to initialize an asset reference. */ id: number; /** * Get or set the asset url which this references. One of either id or url must be called to initialize an asset reference. */ url: string; } /** * @class * @name pc.AssetRegistry * @augments pc.EventHandler * @classdesc Container for all assets that are available to this application. * @description Create an instance of an AssetRegistry. * Note: PlayCanvas scripts are provided with an AssetRegistry instance as 'app.assets'. * @param {pc.ResourceLoader} loader - The ResourceLoader used to load the asset files. * @property {string} prefix A URL prefix that will be added to all asset loading requests. */ class AssetRegistry extends pc.EventHandler { constructor(loader: pc.ResourceLoader); /** * @function * @name pc.AssetRegistry#list * @description Create a filtered list of assets from the registry. * @param {object} filters - Properties to filter on, currently supports: 'preload: true|false'. * @returns {pc.Asset[]} The filtered list of assets. */ list(filters: any): pc.Asset[]; /** * @function * @name pc.AssetRegistry#add * @description Add an asset to the registry. * @param {pc.Asset} asset - The asset to add. * @example * var asset = new pc.Asset("My Asset", "texture", { * url: "../path/to/image.jpg" * }); * app.assets.add(asset); */ add(asset: pc.Asset): void; /** * @function * @name pc.AssetRegistry#remove * @description Remove an asset from the registry. * @param {pc.Asset} asset - The asset to remove. * @returns {boolean} True if the asset was successfully removed and false otherwise. * @example * var asset = app.assets.get(100); * app.assets.remove(asset); */ remove(asset: pc.Asset): boolean; /** * @function * @name pc.AssetRegistry#get * @description Retrieve an asset from the registry by its id field. * @param {number} id - The id of the asset to get. * @returns {pc.Asset} The asset. * @example * var asset = app.assets.get(100); */ get(id: number): pc.Asset; /** * @function * @name pc.AssetRegistry#getByUrl * @description Retrieve an asset from the registry by it's file's URL field. * @param {string} url - The url of the asset to get. * @returns {pc.Asset} The asset. * @example * var asset = app.assets.getByUrl("../path/to/image.jpg"); */ getByUrl(url: string): pc.Asset; /** * @function * @name pc.AssetRegistry#load * @description Load the asset's file from a remote source. Listen for "load" events on the asset to find out when it is loaded. * @param {pc.Asset} asset - The asset to load. * @example * // load some assets * var assetsToLoad = [ * app.assets.find("My Asset"), * app.assets.find("Another Asset") * ]; * var count = 0; * assetsToLoad.forEach(function (assetToLoad) { * assetToLoad.ready(function (asset) { * count++; * if (count === assetsToLoad.length) { * // done * } * }); * app.assets.load(assetToLoad); * }); */ load(asset: pc.Asset): void; /** * @function * @name pc.AssetRegistry#loadFromUrl * @description Use this to load and create an asset if you don't have assets created. Usually you would only use this * if you are not integrated with the PlayCanvas Editor. * @param {string} url - The url to load. * @param {string} type - The type of asset to load. * @param {pc.callbacks.LoadAsset} callback - Function called when asset is loaded, passed (err, asset), where err is null if no errors were encountered. * @param {string} [filename] - Optional asset filename. * @example * app.assets.loadFromUrl("../path/to/texture.jpg", "texture", function (err, asset) { * var texture = asset.resource; * }); */ loadFromUrl(url: string, type: string, callback: pc.callbacks.LoadAsset, filename?: string): void; /** * @function * @name pc.AssetRegistry#findAll * @description Return all Assets with the specified name and type found in the registry. * @param {string} name - The name of the Assets to find. * @param {string} [type] - The type of the Assets to find. * @returns {pc.Asset[]} A list of all Assets found. * @example * var assets = app.assets.findAll("myTextureAsset", "texture"); * console.log("Found " + assets.length + " assets called " + name); */ findAll(name: string, type?: string): pc.Asset[]; /** * @function * @name pc.AssetRegistry#findByTag * @description Return all Assets that satisfy the search query. * Query can be simply a string, or comma separated strings, * to have inclusive results of assets that match at least one query. * A query that consists of an array of tags can be used to match assets that have each tag of array. * @param {...*} query - Name of a tag or array of tags. * @returns {pc.Asset[]} A list of all Assets matched query. * @example * var assets = app.assets.findByTag("level-1"); * // returns all assets that tagged by `level-1` * @example * var assets = app.assets.findByTag("level-1", "level-2"); * // returns all assets that tagged by `level-1` OR `level-2` * @example * var assets = app.assets.findByTag(["level-1", "monster"]); * // returns all assets that tagged by `level-1` AND `monster` * @example * var assets = app.assets.findByTag(["level-1", "monster"], ["level-2", "monster"]); * // returns all assets that tagged by (`level-1` AND `monster`) OR (`level-2` AND `monster`) */ findByTag(...query: any[]): pc.Asset[]; /** * @function * @name pc.AssetRegistry#filter * @description Return all Assets that satisfy filter callback. * @param {pc.callbacks.FilterAsset} callback - The callback function that is used to filter assets, return `true` to include asset to result list. * @returns {pc.Asset[]} A list of all Assets found. * @example * var assets = app.assets.filter(function (asset) { * return asset.name.indexOf('monster') !== -1; * }); * console.log("Found " + assets.length + " assets, where names contains 'monster'"); */ filter(callback: pc.callbacks.FilterAsset): pc.Asset[]; /** * @function * @name pc.AssetRegistry#find * @description Return the first Asset with the specified name and type found in the registry. * @param {string} name - The name of the Asset to find. * @param {string} [type] - The type of the Asset to find. * @returns {pc.Asset} A single Asset or null if no Asset is found. * @example * var asset = app.assets.find("myTextureAsset", "texture"); */ find(name: string, type?: string): pc.Asset; /** * @function * @name pc.EventHandler#on * @description Attach an event handler to an event. * @param {string} name - Name of the event to bind the callback to. * @param {pc.callbacks.HandleEvent} callback - Function that is called when event is fired. Note the callback is limited to 8 arguments. * @param {object} [scope] - Object to use as 'this' when the event is fired, defaults to current this. * @returns {pc.EventHandler} Self for chaining. * @example * obj.on('test', function (a, b) { * console.log(a + b); * }); * obj.fire('test', 1, 2); // prints 3 to the console */ on(name: string, callback: pc.callbacks.HandleEvent, scope?: any): pc.EventHandler; /** * @function * @name pc.EventHandler#off * @description Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, * if scope is not provided then all events with the callback will be unbound. * @param {string} [name] - Name of the event to unbind. * @param {pc.callbacks.HandleEvent} [callback] - Function to be unbound. * @param {object} [scope] - Scope that was used as the this when the event is fired. * @returns {pc.EventHandler} Self for chaining. * @example * var handler = function () { * }; * obj.on('test', handler); * * obj.off(); // Removes all events * obj.off('test'); // Removes all events called 'test' * obj.off('test', handler); // Removes all handler functions, called 'test' * obj.off('test', handler, this); // Removes all hander functions, called 'test' with scope this */ off(name?: string, callback?: pc.callbacks.HandleEvent, scope?: any): pc.EventHandler; /** * @function * @name pc.EventHandler#fire * @description Fire an event, all additional arguments are passed on to the event listener. * @param {object} name - Name of event to fire. * @param {*} [arg1] - First argument that is passed to the event handler. * @param {*} [arg2] - Second argument that is passed to the event handler. * @param {*} [arg3] - Third argument that is passed to the event handler. * @param {*} [arg4] - Fourth argument that is passed to the event handler. * @param {*} [arg5] - Fifth argument that is passed to the event handler. * @param {*} [arg6] - Sixth argument that is passed to the event handler. * @param {*} [arg7] - Seventh argument that is passed to the event handler. * @param {*} [arg8] - Eighth argument that is passed to the event handler. * @returns {pc.EventHandler} Self for chaining. * @example * obj.fire('test', 'This is the message'); */ fire(name: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, arg6?: any, arg7?: any, arg8?: any): pc.EventHandler; /** * @function * @name pc.EventHandler#once * @description Attach an event handler to an event. This handler will be removed after being fired once. * @param {string} name - Name of the event to bind the callback to. * @param {pc.callbacks.HandleEvent} callback - Function that is called when event is fired. Note the callback is limited to 8 arguments. * @param {object} [scope] - Object to use as 'this' when the event is fired, defaults to current this. * @returns {pc.EventHandler} Self for chaining. * @example * obj.once('test', function (a, b) { * console.log(a + b); * }); * obj.fire('test', 1, 2); // prints 3 to the console * obj.fire('test', 1, 2); // not going to get handled */ once(name: string, callback: pc.callbacks.HandleEvent, scope?: any): pc.EventHandler; /** * @function * @name pc.EventHandler#hasEvent * @description Test if there are any handlers bound to an event name. * @param {string} name - The name of the event to test. * @returns {boolean} True if the object has handlers bound to the specified event name. * @example * obj.on('test', function () { }); // bind an event to 'test' * obj.hasEvent('test'); // returns true * obj.hasEvent('hello'); // returns false */ hasEvent(name: string): boolean; /** * A URL prefix that will be added to all asset loading requests. */ prefix: string; } /** * @class * @name pc.Asset * @augments pc.EventHandler * @classdesc An asset record of a file or data resource that can be loaded by the engine. * The asset contains three important fields: * * * `file`: contains the details of a file (filename, url) which contains the resource data, e.g. an image file for a texture asset. * * `data`: contains a JSON blob which contains either the resource data for the asset (e.g. material data) or additional data for the file (e.g. material mappings for a model). * * `resource`: contains the final resource when it is loaded. (e.g. a {@link pc.StandardMaterial} or a {@link pc.Texture}). * * See the {@link pc.AssetRegistry} for details on loading resources from assets. * @description Create a new Asset record. Generally, Assets are created in the loading process and you won't need to create them by hand. * @param {string} name - A non-unique but human-readable name which can be later used to retrieve the asset. * @param {string} type - Type of asset. One of ["animation", "audio", "binary", "cubemap", "css", "font", "json", "html", "material", "model", "script", "shader", "text", "texture"] * @param {object} [file] - Details about the file the asset is made from. At the least must contain the 'url' field. For assets that don't contain file data use null. * @example * var file = { * filename: "filename.txt", * url: "/example/filename.txt" * }; * @param {object} [data] - JSON object with additional data about the asset (e.g. for texture and model assets) or contains the asset data itself (e.g. in the case of materials) * @example * var asset = new pc.Asset("a texture", "texture", { * url: "http://example.com/my/assets/here/texture.png" * }); * @property {string} name The name of the asset * @property {number} id The asset id * @property {string} type The type of the asset. One of ["animation", "audio", "binary", "cubemap", "css", "font", "json", "html", "material", "model", "script", "shader", "text", "texture"] * @property {pc.Tags} tags Interface for tagging. Allows to find assets by tags using {@link pc.AssetRegistry#findByTag} method. * @property {object} file The file details or null if no file * @property {string} [file.url] The URL of the resource file that contains the asset data * @property {string} [file.filename] The filename of the resource file * @property {number} [file.size] The size of the resource file * @property {string} [file.hash] The MD5 hash of the resource file data and the Asset data field * @property {object} data JSON data that contains either the complete resource data (e.g. in the case of a material) or additional data (e.g. in the case of a model it contains mappings from mesh to material) * @property {object} resource A reference to the resource when the asset is loaded. e.g. a {@link pc.Texture} or a {@link pc.Model} * @property {Array} resources A reference to the resources of the asset when it's loaded. An asset can hold more runtime resources than one e.g. cubemaps * @property {boolean} preload If true the asset will be loaded during the preload phase of application set up. * @property {boolean} loaded True if the resource is loaded. e.g. if asset.resource is not null * @property {boolean} loading True if the resource is currently being loaded * @property {pc.AssetRegistry} registry The asset registry that this Asset belongs to */ class Asset extends pc.EventHandler { constructor(name: string, type: string, file?: any, data?: any); /** * @name pc.Asset#getFileUrl * @function * @description Return the URL required to fetch the file for this asset. * @returns {string} The URL. * @example * var assets = app.assets.find("My Image", "texture"); * var img = "<img src='" + assets[0].getFileUrl() + "'>"; */ getFileUrl(): string; /** * @function * @name pc.Asset#ready * @description Take a callback which is called as soon as the asset is loaded. If the asset is already loaded the callback is called straight away. * @param {pc.callbacks.AssetReady} callback - The function called when the asset is ready. Passed the (asset) arguments. * @param {object} [scope] - Scope object to use when calling the callback. * @example * var asset = app.assets.find("My Asset"); * asset.ready(function (asset) { * // asset loaded * }); * app.assets.load(asset); */ ready(callback: pc.callbacks.AssetReady, scope?: any): void; /** * @function * @name pc.Asset#unload * @description Destroys the associated resource and marks asset as unloaded. * @example * var asset = app.assets.find("My Asset"); * asset.unload(); * // asset.resource is null */ unload(): void; /** * @function * @name pc.EventHandler#on * @description Attach an event handler to an event. * @param {string} name - Name of the event to bind the callback to. * @param {pc.callbacks.HandleEvent} callback - Function that is called when event is fired. Note the callback is limited to 8 arguments. * @param {object} [scope] - Object to use as 'this' when the event is fired, defaults to current this. * @returns {pc.EventHandler} Self for chaining. * @example * obj.on('test', function (a, b) { * console.log(a + b); * }); * obj.fire('test', 1, 2); // prints 3 to the console */ on(name: string, callback: pc.callbacks.HandleEvent, scope?: any): pc.EventHandler; /** * @function * @name pc.EventHandler#off * @description Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, * if scope is not provided then all events with the callback will be unbound. * @param {string} [name] - Name of the event to unbind. * @param {pc.callbacks.HandleEvent} [callback] - Function to be unbound. * @param {object} [scope] - Scope that was used as the this when the event is fired. * @returns {pc.EventHandler} Self for chaining. * @example * var handler = function () { * }; * obj.on('test', handler); * * obj.off(); // Removes all events * obj.off('test'); // Removes all events called 'test' * obj.off('test', handler); // Removes all handler functions, called 'test' * obj.off('test', handler, this); // Removes all hander functions, called 'test' with scope this */ off(name?: string, callback?: pc.callbacks.HandleEvent, scope?: any): pc.EventHandler; /** * @function * @name pc.EventHandler#fire * @description Fire an event, all additional arguments are passed on to the event listener. * @param {object} name - Name of event to fire. * @param {*} [arg1] - First argument that is passed to the event handler. * @param {*} [arg2] - Second argument that is passed to the event handler. * @param {*} [arg3] - Third argument that is passed to the event handler. * @param {*} [arg4] - Fourth argument that is passed to the event handler. * @param {*} [arg5] - Fifth argument that is passed to the event handler. * @param {*} [arg6] - Sixth argument that is passed to the event handler. * @param {*} [arg7] - Seventh argument that is passed to the event handler. * @param {*} [arg8] - Eighth argument that is passed to the event handler. * @returns {pc.EventHandler} Self for chaining. * @example * obj.fire('test', 'This is the message'); */ fire(name: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, arg6?: any, arg7?: any, arg8?: any): pc.EventHandler; /** * @function * @name pc.EventHandler#once * @description Attach an event handler to an event. This handler will be removed after being fired once. * @param {string} name - Name of the event to bind the callback to. * @param {pc.callbacks.HandleEvent} callback - Function that is called when event is fired. Note the callback is limited to 8 arguments. * @param {object} [scope] - Object to use as 'this' when the event is fired, defaults to current this. * @returns {pc.EventHandler} Self for chaining. * @example * obj.once('test', function (a, b) { * console.log(a + b); * }); * obj.fire('test', 1, 2); // prints 3 to the console * obj.fire('test', 1, 2); // not going to get handled */ once(name: string, callback: pc.callbacks.HandleEvent, scope?: any): pc.EventHandler; /** * @function * @name pc.EventHandler#hasEvent * @description Test if there are any handlers bound to an event name. * @param {string} name - The name of the event to test. * @returns {boolean} True if the object has handlers bound to the specified event name. * @example * obj.on('test', function () { }); // bind an event to 'test' * obj.hasEvent('test'); // returns true * obj.hasEvent('hello'); // returns false */ hasEvent(name: string): boolean; /** * The name of the asset */ name: string; /** * The asset id */ id: number; /** * The type of the asset. One of ["animation", "audio", "binary", "cubemap", "css", "font", "json", "html", "material", "model", "script", "shader", "text", "texture"] */ type: string; /** * Interface for tagging. Allows to find assets by tags using {@link pc.AssetRegistry#findByTag} method. */ tags: pc.Tags; /** * The file details or null if no file */ file: { url?: string; filename?: string; size?: number; hash?: string; }; /** * JSON data that contains either the complete resource data (e.g. in the case of a material) or additional data (e.g. in the case of a model it contains mappings from mesh to material) */ data: any; /** * A reference to the resource when the asset is loaded. e.g. a {@link pc.Texture} or a {@link pc.Model} */ resource: any; /** * A reference to the resources of the asset when it's loaded. An asset can hold more runtime resources than one e.g. cubemaps */ resources: any[]; /** * If true the asset will be loaded during the preload phase of application set up. */ preload: boolean; /** * True if the resource is loaded. e.g. if asset.resource is not null */ loaded: boolean; /** * True if the resource is currently being loaded */ loading: boolean; /** * The asset registry that this Asset belongs to */ registry: pc.AssetRegistry; } /** * @constant * @type {string} * @name pc.ASSET_ANIMATION * @description Asset type name for animation. */ const ASSET_ANIMATION: string; /** * @constant * @type {string} * @name pc.ASSET_AUDIO * @description Asset type name for audio. */ const ASSET_AUDIO: string; /** * @constant * @type {string} * @name pc.ASSET_IMAGE * @description Asset type name for image. */ const ASSET_IMAGE: string; /** * @constant * @type {string} * @name pc.ASSET_JSON * @description Asset type name for json. */ const ASSET_JSON: string; /** * @constant * @type {string} * @name pc.ASSET_MODEL * @description Asset type name for model. */ const ASSET_MODEL: string; /** * @constant * @type {string} * @name pc.ASSET_MATERIAL * @description Asset type name for material. */ const ASSET_MATERIAL: string; /** * @constant * @type {string} * @name pc.ASSET_TEXT * @description Asset type name for text. */ const ASSET_TEXT: string; /** * @constant * @type {string} * @name pc.ASSET_TEXTURE * @description Asset type name for texture. */ const ASSET_TEXTURE: string; /** * @constant * @type {string} * @name pc.ASSET_CUBEMAP * @description Asset type name for cubemap. */ const ASSET_CUBEMAP: string; /** * @constant * @type {string} * @name pc.ASSET_SHADER * @description Asset type name for shader. */ const ASSET_SHADER: string; /** * @constant * @type {string} * @name pc.ASSET_CSS * @description Asset type name for CSS. */ const ASSET_CSS: string; /** * @constant * @type {string} * @name pc.ASSET_HTML * @description Asset type name for HTML. */ const ASSET_HTML: string; /** * @constant * @type {string} * @name pc.ASSET_SCRIPT * @description Asset type name for script. */ const ASSET_SCRIPT: string; /** * @name pc.callbacks * @namespace * @description Namespace for callback definitions. */ namespace callbacks { /** * @callback pc.callbacks.HandleEvent * @description Callback used by {@link pc.events} functions. Note the callback is limited to 8 arguments. * @param {*} [arg1] - First argument that is passed from caller. * @param {*} [arg2] - Second argument that is passed from caller. * @param {*} [arg3] - Third argument that is passed from caller. * @param {*} [arg4] - Fourth argument that is passed from caller. * @param {*} [arg5] - Fifth argument that is passed from caller. * @param {*} [arg6] - Sixth argument that is passed from caller. * @param {*} [arg7] - Seventh argument that is passed from caller. * @param {*} [arg8] - Eighth argument that is passed from caller. */ type HandleEvent = (arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, arg6?: any, arg7?: any, arg8?: any) => void; /** * @callback pc.callbacks.LoadAsset * @description Callback used by {@link pc.AssetRegistry#loadFromUrl} and called when an asset is loaded (or an error occurs). * @param {string|null} err - The error message is null if no errors were encountered. * @param {pc.Asset} [asset] - The loaded asset if no errors were encountered. */ type LoadAsset = (err: string | null, asset?: pc.Asset) => void; /** * @callback pc.callbacks.FilterAsset * @description Callback used by {@link pc.AssetRegistry#filter} to filter assets. * @param {pc.Asset} asset - The current asset to filter. * @returns {boolean} Return `true` to include asset to result list. */ type FilterAsset = (asset: pc.Asset) => boolean; /** * @callback pc.callbacks.AssetReady * @description Callback used by {@link pc.Asset#ready} and called when an asset is ready. * @param {pc.Asset} asset - The ready asset. */ type AssetReady = (asset: pc.Asset) => void; /** * @callback pc.callbacks.ConfigureApp * @description Callback used by {@link pc.Application#configure} when configuration file is loaded and parsed (or an error occurs). * @param {string|null} err - The error message in the case where the loading or parsing fails. */ type ConfigureApp = (err: string | null) => void; /** * @callback pc.callbacks.PreloadApp * @description Callback used by {@link pc.Application#preload} when all assets (marked as 'preload') are loaded. */ type PreloadApp = () => void; /** * @callback pc.callbacks.LoadHierarchy * @description Callback used by {@link pc.Application#loadSceneHierarchy}. * @param {string|null} err - The error message in the case where the loading or parsing fails. * @param {pc.Entity} [entity] - The loaded root entity if no errors were encountered. */ type LoadHierarchy = (err: string | null, entity?: pc.Entity) => void; /** * @callback pc.callbacks.LoadSettings * @description Callback used by {@link pc.Application#loadSceneSettings}. * @param {string|null} err - The error message in the case where the loading or parsing fails. */ type LoadSettings = (err: string | null) => void; /** * @callback pc.callbacks.CalculateMatrix * @description Callback used by {@link pc.CameraComponent#calculateTransform} and {@link pc.CameraComponent#calculateProjection}. * @param {pc.Mat4} transformMatrix - Output of the function. * @param {number} view - Type of view. Can be pc.VIEW_CENTER, pc.VIEW_LEFT or pc.VIEW_RIGHT. Left and right are only used in stereo rendering. */ type CalculateMatrix = (transformMatrix: pc.Mat4, view: number) => void; /** * @callback pc.callbacks.CalculateSortDistance * @description Callback used by {@link pc.Layer} to calculate the "sort distance" for a {@link pc.MeshInstance}, which determines its place in the render order. * @param {pc.MeshInstance} meshInstance - The mesh instance. * @param {pc.Vec3} cameraPosition - The position of the camera. * @param {pc.Vec3} cameraForward - The forward vector of the camera. */ type CalculateSortDistance = (meshInstance: pc.MeshInstance, cameraPosition: pc.Vec3, cameraForward: pc.Vec3) => void; /** * @callback pc.callbacks.VrCamera * @description Callback used by {@link pc.CameraComponent#enterVr} and {@link pc.CameraComponent#exitVr}. * @param {string|null} err - On success it is null on failure it is the error message. */ type VrCamera = (err: string | null) => void; /** * @callback pc.callbacks.CreateScreen * @description Callback used by {@link pc.script.createLoadingScreen}. * @param {pc.Application} app - The application. */ type CreateScreen = (app: pc.Application) => void; /** * @callback pc.callbacks.LockMouse * @description Callback used by {@link pc.Mouse#enablePointerLock} and {@link pc.Application#disablePointerLock}. */ type LockMouse = () => void; /** * @callback pc.callbacks.HttpResponse * @description Callback used by {@link pc.Http#get}, {@link pc.Http#post}, {@link pc.Http#put}, {@link pc.Http#del}, and {@link pc.Http#request}. * @param {number|string|Error|null} err - The error code, message, or exception in the case where the request fails. * @param {*} [response] - The response data if no errors were encountered. (format depends on response type: text, Object, ArrayBuffer, XML). */ type HttpResponse = (err: number | string | Error | null, response?: any) => void; /** * @callback pc.callbacks.ResourceHandler * @description Callback used by {@link pc.ResourceHandler#load} when a resource is loaded (or an error occurs). * @param {string|null} err - The error message in the case where the load fails. * @param {*} [response] - The raw data that has been successfully loaded. */ type ResourceHandler = (err: string | null, response?: any) => void; /** * @callback pc.callbacks.ResourceLoader * @description Callback used by {@link pc.ResourceLoader#load} when a resource is loaded (or an error occurs). * @param {string|null} err - The error message in the case where the load fails. * @param {*} [resource] - The resource that has been successfully loaded. */ type ResourceLoader = (err: string | null, resource?: any) => void; /** * @callback pc.callbacks.AddParser * @description Callback used by {@link pc.ModelHandler#addParser} to decide on which parser to use. * @param {string} url - The resource url. * @param {object} data - The raw model data. * @returns {boolean} Return true if this parser should be used to parse the data into a {@link pc.Model}. */ type AddParser = (url: string, data: any) => boolean; /** * @callback pc.callbacks.FindNode * @description Callback used by {@link pc.GraphNode#find} and {@link pc.GraphNode#findOne} to search through a graph node and all of its descendants. * @param {pc.GraphNode} node - The current graph node. * @returns {boolean} Returning `true` will result in that node being returned from {@link pc.GraphNode#find} or {@link pc.GraphNode#findOne}. */ type FindNode = (node: pc.GraphNode) => boolean; /** * @callback pc.callbacks.ForEach * @description Callback used by {@link pc.GraphNode#forEach} to iterate through a graph node and all of its descendants. * @param {pc.GraphNode} node - The current graph node. */ type ForEach = (node: pc.GraphNode) => void; /** * @callback pc.callbacks.UpdateShader * @description Callback used by {@link pc.StandardMaterial#onUpdateShader}. * @param {object} options - An object with shader generator settings (based on current material and scene properties), that you can change and then return. * Properties of the object passed into this function are documented in {@link pc.StandardMaterial#onUpdateShader}. * @returns {object} Returned settings will be used by the shader. */ type UpdateShader = (options: any) => any; /** * @callback pc.callbacks.VrDisplay * @description Callback used by {@link pc.VrDisplay#requestPresent} and {@link pc.VrDisplay#exitPresent}. * @param {string|null} err - The error message if presenting fails, or null if the call succeeds. */ type VrDisplay = (err: string | null) => void; /** * @callback pc.callbacks.VrFrame * @description Callback used by {@link pc.VrDisplay#requestAnimationFrame}. */ type VrFrame = () => void; /** * @callback pc.callbacks.XrError * @description Callback used by {@link pc.XrManager#endXr} and {@link pc.XrManager#startXr}. * @param {Error|null} err - The Error object or null if operation was successfull. */ type XrError = (err: Error | null) => void; } /** * @class * @name pc.Color * @classdesc Representation of an RGBA color. * @description Create a new Color object. * @param {number|number[]} [r] - The value of the red component (0-1). If r is an array of length 3 or 4, the array will be used to populate all components. * @param {number} [g] - The value of the green component (0-1). * @param {number} [b] - The value of the blue component (0-1). * @param {number} [a] - The value of the alpha component (0-1). * @property {number} r The red component of the color. * @property {number} g The green component of the color. * @property {number} b The blue component of the color. * @property {number} a The alpha component of the color. */ class Color { constructor(r?: number | number[], g?: number, b?: number, a?: number); /** * @function * @name pc.Color#clone * @description Returns a clone of the specified color. * @returns {pc.Color} A duplicate color object. */ clone(): pc.Color; /** * @function * @name pc.Color#copy * @description Copies the contents of a source color to a destination color. * @param {pc.Color} rhs - A color to copy to the specified color. * @returns {pc.Color} Self for chaining. * @example * var src = new pc.Color(1, 0, 0, 1); * var dst = new pc.Color(); * * dst.copy(src); * * console.log("The two colors are " + (dst.equals(src) ? "equal" : "different")); */ copy(rhs: pc.Color): pc.Color; /** * @function * @name pc.Color#set * @description Assign values to the color components, including alpha. * @param {number} r - The value for red (0-1). * @param {number} g - The value for blue (0-1). * @param {number} b - The value for green (0-1). * @param {number} [a] - The value for the alpha (0-1), defaults to 1. * @returns {pc.Color} Self f