|
@@ -3,6 +3,10 @@
|
|
|
dispose(): void;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Represents a scene to be rendered by the engine.
|
|
|
+ * @see http://doc.babylonjs.com/page.php?p=21911
|
|
|
+ */
|
|
|
export class Scene {
|
|
|
// Statics
|
|
|
public static FOGMODE_NONE = 0;
|
|
@@ -17,8 +21,20 @@
|
|
|
public autoClear = true;
|
|
|
public clearColor: any = new Color3(0.2, 0.2, 0.3);
|
|
|
public ambientColor = new Color3(0, 0, 0);
|
|
|
+ /**
|
|
|
+ * A function to be executed before rendering this scene
|
|
|
+ * @type {Function}
|
|
|
+ */
|
|
|
public beforeRender: () => void;
|
|
|
+ /**
|
|
|
+ * A function to be executed after rendering this scene
|
|
|
+ * @type {Function}
|
|
|
+ */
|
|
|
public afterRender: () => void;
|
|
|
+ /**
|
|
|
+ * A function to be executed when this scene is disposed.
|
|
|
+ * @type {Function}
|
|
|
+ */
|
|
|
public onDispose: () => void;
|
|
|
public beforeCameraRender: (camera: Camera) => void;
|
|
|
public afterCameraRender: (camera: Camera) => void;
|
|
@@ -42,6 +58,10 @@
|
|
|
private _onKeyUp: (evt: Event) => void;
|
|
|
|
|
|
// Fog
|
|
|
+ /**
|
|
|
+ * is fog enabled on this scene.
|
|
|
+ * @type {boolean}
|
|
|
+ */
|
|
|
public fogEnabled = true;
|
|
|
public fogMode = Scene.FOGMODE_NONE;
|
|
|
public fogColor = new Color3(0.2, 0.2, 0.3);
|
|
@@ -50,16 +70,39 @@
|
|
|
public fogEnd = 1000.0;
|
|
|
|
|
|
// Lights
|
|
|
+ /**
|
|
|
+ * is shadow enabled on this scene.
|
|
|
+ * @type {boolean}
|
|
|
+ */
|
|
|
public shadowsEnabled = true;
|
|
|
+ /**
|
|
|
+ * is light enabled on this scene.
|
|
|
+ * @type {boolean}
|
|
|
+ */
|
|
|
public lightsEnabled = true;
|
|
|
+ /**
|
|
|
+ * All of the lights added to this scene.
|
|
|
+ * @see BABYLON.Light
|
|
|
+ * @type {BABYLON.Light[]}
|
|
|
+ */
|
|
|
public lights = new Array<Light>();
|
|
|
|
|
|
// Cameras
|
|
|
+ /**
|
|
|
+ * All of the cameras added to this scene.
|
|
|
+ * @see BABYLON.Camera
|
|
|
+ * @type {BABYLON.Camera[]}
|
|
|
+ */
|
|
|
public cameras = new Array<Camera>();
|
|
|
public activeCameras = new Array<Camera>();
|
|
|
public activeCamera: Camera;
|
|
|
|
|
|
// Meshes
|
|
|
+ /**
|
|
|
+ * All of the (abstract) meshes added to this scene.
|
|
|
+ * @see BABYLON.AbstractMesh
|
|
|
+ * @type {BABYLON.AbstractMesh[]}
|
|
|
+ */
|
|
|
public meshes = new Array<AbstractMesh>();
|
|
|
|
|
|
// Geometries
|
|
@@ -114,6 +157,10 @@
|
|
|
public database; //ANY
|
|
|
|
|
|
// Actions
|
|
|
+ /**
|
|
|
+ * This scene's action manager
|
|
|
+ * @type {BABYLON.ActionManager}
|
|
|
+ */
|
|
|
public actionManager: ActionManager;
|
|
|
public _actionManagers = new Array<ActionManager>();
|
|
|
private _meshesForIntersections = new SmartArray<AbstractMesh>(256);
|
|
@@ -183,7 +230,10 @@
|
|
|
|
|
|
private _debugLayer: DebugLayer;
|
|
|
|
|
|
- // Constructor
|
|
|
+ /**
|
|
|
+ * @constructor
|
|
|
+ * @param {BABYLON.Engine} engine - the engine to be used to render this scene.
|
|
|
+ */
|
|
|
constructor(engine: Engine) {
|
|
|
this._engine = engine;
|
|
|
|
|
@@ -209,14 +259,26 @@
|
|
|
return this._debugLayer;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * The mesh that is currently under the pointer.
|
|
|
+ * @return {BABYLON.AbstractMesh} mesh under the pointer/mouse cursor or null if none.
|
|
|
+ */
|
|
|
public get meshUnderPointer(): AbstractMesh {
|
|
|
return this._meshUnderPointer;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Current on-screen X position of the pointer
|
|
|
+ * @return {number} X position of the pointer
|
|
|
+ */
|
|
|
public get pointerX(): number {
|
|
|
return this._pointerX;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Current on-screen Y position of the pointer
|
|
|
+ * @return {number} Y position of the pointer
|
|
|
+ */
|
|
|
public get pointerY(): number {
|
|
|
return this._pointerY;
|
|
|
}
|
|
@@ -469,6 +531,10 @@
|
|
|
return this._pendingData.length;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Registers a function to be executed when the scene is ready.
|
|
|
+ * @param {Function} func - the function to be executed.
|
|
|
+ */
|
|
|
public executeWhenReady(func: () => void): void {
|
|
|
this._onReadyCallbacks.push(func);
|
|
|
|
|
@@ -498,6 +564,19 @@
|
|
|
}
|
|
|
|
|
|
// Animations
|
|
|
+ /**
|
|
|
+ * Will start the animation sequence of a given target
|
|
|
+ * @param target - the target
|
|
|
+ * @param {number} from - from which frame should animation start
|
|
|
+ * @param {number} to - till which frame should animation run.
|
|
|
+ * @param {boolean} [loop] - should the animation loop
|
|
|
+ * @param {number} [speedRatio] - the speed in which to run the animation
|
|
|
+ * @param {Function} [onAnimationEnd] function to be executed when the animation ended.
|
|
|
+ * @param {BABYLON.Animatable} [animatable] an animatable object. If not provided a new one will be created from the given params.
|
|
|
+ * @return {BABYLON.Animatable} the animatable object created for this animation
|
|
|
+ * @see BABYLON.Animatable
|
|
|
+ * @see http://doc.babylonjs.com/page.php?p=22081
|
|
|
+ */
|
|
|
public beginAnimation(target: any, from: number, to: number, loop?: boolean, speedRatio?: number, onAnimationEnd?: () => void, animatable?: Animatable): Animatable {
|
|
|
if (speedRatio === undefined) {
|
|
|
speedRatio = 1.0;
|
|
@@ -545,6 +624,11 @@
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Will stop the animation of the given target
|
|
|
+ * @param target - the target
|
|
|
+ * @see beginAnimation
|
|
|
+ */
|
|
|
public stopAnimation(target: any): void {
|
|
|
var animatable = this.getAnimatableByTarget(target);
|
|
|
|
|
@@ -594,6 +678,13 @@
|
|
|
}
|
|
|
|
|
|
// Methods
|
|
|
+
|
|
|
+ /**
|
|
|
+ * sets the active camera of the scene using its ID
|
|
|
+ * @param {string} id - the camera's ID
|
|
|
+ * @return {BABYLON.Camera|null} the new active camera or null if none found.
|
|
|
+ * @see activeCamera
|
|
|
+ */
|
|
|
public setActiveCameraByID(id: string): Camera {
|
|
|
var camera = this.getCameraByID(id);
|
|
|
|
|
@@ -605,6 +696,12 @@
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * sets the active camera of the scene using its name
|
|
|
+ * @param {string} name - the camera's name
|
|
|
+ * @return {BABYLON.Camera|null} the new active camera or null if none found.
|
|
|
+ * @see activeCamera
|
|
|
+ */
|
|
|
public setActiveCameraByName(name: string): Camera {
|
|
|
var camera = this.getCameraByName(name);
|
|
|
|
|
@@ -616,6 +713,11 @@
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * get a material using its id
|
|
|
+ * @param {string} the material's ID
|
|
|
+ * @return {BABYLON.Material|null} the material or null if none found.
|
|
|
+ */
|
|
|
public getMaterialByID(id: string): Material {
|
|
|
for (var index = 0; index < this.materials.length; index++) {
|
|
|
if (this.materials[index].id === id) {
|
|
@@ -626,6 +728,11 @@
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * get a material using its name
|
|
|
+ * @param {string} the material's name
|
|
|
+ * @return {BABYLON.Material|null} the material or null if none found.
|
|
|
+ */
|
|
|
public getMaterialByName(name: string): Material {
|
|
|
for (var index = 0; index < this.materials.length; index++) {
|
|
|
if (this.materials[index].name === name) {
|
|
@@ -646,6 +753,11 @@
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * get a camera using its name
|
|
|
+ * @param {string} the camera's name
|
|
|
+ * @return {BABYLON.Camera|null} the camera or null if none found.
|
|
|
+ */
|
|
|
public getCameraByName(name: string): Camera {
|
|
|
for (var index = 0; index < this.cameras.length; index++) {
|
|
|
if (this.cameras[index].name === name) {
|
|
@@ -656,6 +768,11 @@
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * get a light node using its name
|
|
|
+ * @param {string} the light's name
|
|
|
+ * @return {BABYLON.Light|null} the light or null if none found.
|
|
|
+ */
|
|
|
public getLightByName(name: string): Light {
|
|
|
for (var index = 0; index < this.lights.length; index++) {
|
|
|
if (this.lights[index].name === name) {
|
|
@@ -666,6 +783,11 @@
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * get a light node using its ID
|
|
|
+ * @param {string} the light's id
|
|
|
+ * @return {BABYLON.Light|null} the light or null if none found.
|
|
|
+ */
|
|
|
public getLightByID(id: string): Light {
|
|
|
for (var index = 0; index < this.lights.length; index++) {
|
|
|
if (this.lights[index].id === id) {
|
|
@@ -676,6 +798,11 @@
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * get a geometry using its ID
|
|
|
+ * @param {string} the geometry's id
|
|
|
+ * @return {BABYLON.Geometry|null} the geometry or null if none found.
|
|
|
+ */
|
|
|
public getGeometryByID(id: string): Geometry {
|
|
|
for (var index = 0; index < this._geometries.length; index++) {
|
|
|
if (this._geometries[index].id === id) {
|
|
@@ -686,6 +813,12 @@
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * add a new geometry to this scene.
|
|
|
+ * @param {BABYLON.Geometry} geometry - the geometry to be added to the scene.
|
|
|
+ * @param {boolean} [force] - force addition, even if a geometry with this ID already exists
|
|
|
+ * @return {boolean} was the geometry added or not
|
|
|
+ */
|
|
|
public pushGeometry(geometry: Geometry, force?: boolean): boolean {
|
|
|
if (!force && this.getGeometryByID(geometry.id)) {
|
|
|
return false;
|
|
@@ -700,6 +833,11 @@
|
|
|
return this._geometries;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Get a the first added mesh found of a given ID
|
|
|
+ * @param {string} id - the id to search for
|
|
|
+ * @return {BABYLON.AbstractMesh|null} the mesh found or null if not found at all.
|
|
|
+ */
|
|
|
public getMeshByID(id: string): AbstractMesh {
|
|
|
for (var index = 0; index < this.meshes.length; index++) {
|
|
|
if (this.meshes[index].id === id) {
|
|
@@ -710,6 +848,11 @@
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Get a the last added mesh found of a given ID
|
|
|
+ * @param {string} id - the id to search for
|
|
|
+ * @return {BABYLON.AbstractMesh|null} the mesh found or null if not found at all.
|
|
|
+ */
|
|
|
public getLastMeshByID(id: string): AbstractMesh {
|
|
|
for (var index = this.meshes.length - 1; index >= 0; index--) {
|
|
|
if (this.meshes[index].id === id) {
|
|
@@ -720,6 +863,11 @@
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Get a the last added node (Mesh, Camera, Light) found of a given ID
|
|
|
+ * @param {string} id - the id to search for
|
|
|
+ * @return {BABYLON.Node|null} the node found or null if not found at all.
|
|
|
+ */
|
|
|
public getLastEntryByID(id: string): Node {
|
|
|
for (var index = this.meshes.length - 1; index >= 0; index--) {
|
|
|
if (this.meshes[index].id === id) {
|