|
@@ -1,29 +1,153 @@
|
|
module BABYLON {
|
|
module BABYLON {
|
|
|
|
+ /**
|
|
|
|
+ * Set of assets to keep when moving a scene into an asset container.
|
|
|
|
+ */
|
|
|
|
+ export class KeepAssets {
|
|
|
|
+ /**
|
|
|
|
+ * Cameras to keep.
|
|
|
|
+ */
|
|
|
|
+ public cameras = new Array<Camera>();
|
|
|
|
+ /**
|
|
|
|
+ * Lights to keep.
|
|
|
|
+ */
|
|
|
|
+ public lights = new Array<Light>();
|
|
|
|
+ /**
|
|
|
|
+ * Meshes to keep.
|
|
|
|
+ */
|
|
|
|
+ public meshes = new Array<AbstractMesh>();
|
|
|
|
+ /**
|
|
|
|
+ * Skeletons to keep.
|
|
|
|
+ */
|
|
|
|
+ public skeletons = new Array<Skeleton>();
|
|
|
|
+ /**
|
|
|
|
+ * ParticleSystems to keep.
|
|
|
|
+ */
|
|
|
|
+ public particleSystems = new Array<ParticleSystem>();
|
|
|
|
+ /**
|
|
|
|
+ * Animations to keep.
|
|
|
|
+ */
|
|
|
|
+ public animations = new Array<Animation>();
|
|
|
|
+ /**
|
|
|
|
+ * MultiMaterials to keep.
|
|
|
|
+ */
|
|
|
|
+ public multiMaterials = new Array<MultiMaterial>();
|
|
|
|
+ /**
|
|
|
|
+ * Materials to keep.
|
|
|
|
+ */
|
|
|
|
+ public materials = new Array<Material>();
|
|
|
|
+ /**
|
|
|
|
+ * MorphTargetManagers to keep.
|
|
|
|
+ */
|
|
|
|
+ public morphTargetManagers = new Array<MorphTargetManager>();
|
|
|
|
+ /**
|
|
|
|
+ * Geometries to keep.
|
|
|
|
+ */
|
|
|
|
+ public geometries = new Array<Geometry>();
|
|
|
|
+ /**
|
|
|
|
+ * TransformNodes to keep.
|
|
|
|
+ */
|
|
|
|
+ public transformNodes = new Array<TransformNode>();
|
|
|
|
+ /**
|
|
|
|
+ * LensFlareSystems to keep.
|
|
|
|
+ */
|
|
|
|
+ public lensFlareSystems = new Array<LensFlareSystem>();
|
|
|
|
+ /**
|
|
|
|
+ * ShadowGenerators to keep.
|
|
|
|
+ */
|
|
|
|
+ public shadowGenerators = new Array<ShadowGenerator>();
|
|
|
|
+ /**
|
|
|
|
+ * ActionManagers to keep.
|
|
|
|
+ */
|
|
|
|
+ public actionManagers = new Array<ActionManager>();
|
|
|
|
+ /**
|
|
|
|
+ * Sounds to keep.
|
|
|
|
+ */
|
|
|
|
+ public sounds = new Array<Sound>();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Container with a set of assets that can be added or removed from a scene.
|
|
|
|
+ */
|
|
export class AssetContainer {
|
|
export class AssetContainer {
|
|
|
|
+ /**
|
|
|
|
+ * The scene the AssetContainer belongs to.
|
|
|
|
+ */
|
|
public scene: Scene;
|
|
public scene: Scene;
|
|
|
|
|
|
// Objects
|
|
// Objects
|
|
|
|
+ /**
|
|
|
|
+ * Cameras populated in the container.
|
|
|
|
+ */
|
|
public cameras = new Array<Camera>();
|
|
public cameras = new Array<Camera>();
|
|
|
|
+ /**
|
|
|
|
+ * Lights populated in the container.
|
|
|
|
+ */
|
|
public lights = new Array<Light>();
|
|
public lights = new Array<Light>();
|
|
|
|
+ /**
|
|
|
|
+ * Meshes populated in the container.
|
|
|
|
+ */
|
|
public meshes = new Array<AbstractMesh>();
|
|
public meshes = new Array<AbstractMesh>();
|
|
|
|
+ /**
|
|
|
|
+ * Skeletons populated in the container.
|
|
|
|
+ */
|
|
public skeletons = new Array<Skeleton>();
|
|
public skeletons = new Array<Skeleton>();
|
|
|
|
+ /**
|
|
|
|
+ * ParticleSystems populated in the container.
|
|
|
|
+ */
|
|
public particleSystems = new Array<ParticleSystem>();
|
|
public particleSystems = new Array<ParticleSystem>();
|
|
|
|
+ /**
|
|
|
|
+ * Animations populated in the container.
|
|
|
|
+ */
|
|
public animations = new Array<Animation>();
|
|
public animations = new Array<Animation>();
|
|
|
|
+ /**
|
|
|
|
+ * MultiMaterials populated in the container.
|
|
|
|
+ */
|
|
public multiMaterials = new Array<MultiMaterial>();
|
|
public multiMaterials = new Array<MultiMaterial>();
|
|
|
|
+ /**
|
|
|
|
+ * Materials populated in the container.
|
|
|
|
+ */
|
|
public materials = new Array<Material>();
|
|
public materials = new Array<Material>();
|
|
|
|
+ /**
|
|
|
|
+ * MorphTargetManagers populated in the container.
|
|
|
|
+ */
|
|
public morphTargetManagers = new Array<MorphTargetManager>();
|
|
public morphTargetManagers = new Array<MorphTargetManager>();
|
|
|
|
+ /**
|
|
|
|
+ * Geometries populated in the container.
|
|
|
|
+ */
|
|
public geometries = new Array<Geometry>();
|
|
public geometries = new Array<Geometry>();
|
|
|
|
+ /**
|
|
|
|
+ * TransformNodes populated in the container.
|
|
|
|
+ */
|
|
public transformNodes = new Array<TransformNode>();
|
|
public transformNodes = new Array<TransformNode>();
|
|
|
|
+ /**
|
|
|
|
+ * LensFlareSystems populated in the container.
|
|
|
|
+ */
|
|
public lensFlareSystems = new Array<LensFlareSystem>();
|
|
public lensFlareSystems = new Array<LensFlareSystem>();
|
|
|
|
+ /**
|
|
|
|
+ * ShadowGenerators populated in the container.
|
|
|
|
+ */
|
|
public shadowGenerators = new Array<ShadowGenerator>();
|
|
public shadowGenerators = new Array<ShadowGenerator>();
|
|
|
|
+ /**
|
|
|
|
+ * ActionManagers populated in the container.
|
|
|
|
+ */
|
|
public actionManagers = new Array<ActionManager>();
|
|
public actionManagers = new Array<ActionManager>();
|
|
|
|
+ /**
|
|
|
|
+ * Sounds populated in the container.
|
|
|
|
+ */
|
|
public sounds = new Array<Sound>();
|
|
public sounds = new Array<Sound>();
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Instantiates an AssetContainer.
|
|
|
|
+ * @param scene The scene the AssetContainer belongs to.
|
|
|
|
+ */
|
|
constructor(scene:Scene){
|
|
constructor(scene:Scene){
|
|
this.scene = scene;
|
|
this.scene = scene;
|
|
}
|
|
}
|
|
|
|
|
|
- addAllToScene(){
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Adds all the assets from the container to the scene.
|
|
|
|
+ */
|
|
|
|
+ public addAllToScene(){
|
|
this.cameras.forEach((o)=>{
|
|
this.cameras.forEach((o)=>{
|
|
this.scene.addCamera(o);
|
|
this.scene.addCamera(o);
|
|
});
|
|
});
|
|
@@ -69,7 +193,11 @@ module BABYLON {
|
|
this.scene.mainSoundTrack.AddSound(o);
|
|
this.scene.mainSoundTrack.AddSound(o);
|
|
})
|
|
})
|
|
}
|
|
}
|
|
- removeAllFromScene(){
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Removes all the assets in the container from the scene
|
|
|
|
+ */
|
|
|
|
+ public removeAllFromScene(){
|
|
this.cameras.forEach((o)=>{
|
|
this.cameras.forEach((o)=>{
|
|
this.scene.removeCamera(o);
|
|
this.scene.removeCamera(o);
|
|
});
|
|
});
|
|
@@ -115,5 +243,50 @@ module BABYLON {
|
|
this.scene.mainSoundTrack.RemoveSound(o);
|
|
this.scene.mainSoundTrack.RemoveSound(o);
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private _moveAssets<T>(sourceAssets: T[], targetAssets: T[], keepAssets: T[]): void {
|
|
|
|
+ for (let asset of sourceAssets) {
|
|
|
|
+ let move = true;
|
|
|
|
+ for (let keepAsset of keepAssets) {
|
|
|
|
+ if (asset === keepAsset) {
|
|
|
|
+ move = false;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (move) {
|
|
|
|
+ targetAssets.push(asset);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Removes all the assets contained in the scene and adds them to the container.
|
|
|
|
+ * @param keepAssets Set of assets to keep in the scene. (default: empty)
|
|
|
|
+ */
|
|
|
|
+ public moveAllFromScene(keepAssets?: KeepAssets): void {
|
|
|
|
+
|
|
|
|
+ if (keepAssets === undefined) {
|
|
|
|
+ keepAssets = new KeepAssets();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this._moveAssets(this.scene.cameras, this.cameras, keepAssets.cameras);
|
|
|
|
+ this._moveAssets(this.scene.meshes, this.meshes, keepAssets.meshes);
|
|
|
|
+ this._moveAssets(this.scene.getGeometries(), this.geometries, keepAssets.geometries);
|
|
|
|
+ this._moveAssets(this.scene.materials, this.materials, keepAssets.materials);
|
|
|
|
+
|
|
|
|
+ Array.prototype.push.apply(this.actionManagers, this.scene._actionManagers);
|
|
|
|
+ Array.prototype.push.apply(this.animations, this.scene.animations);
|
|
|
|
+ Array.prototype.push.apply(this.lensFlareSystems, this.scene.lensFlareSystems);
|
|
|
|
+ Array.prototype.push.apply(this.lights, this.scene.lights);
|
|
|
|
+ Array.prototype.push.apply(this.morphTargetManagers, this.scene.morphTargetManagers);
|
|
|
|
+ Array.prototype.push.apply(this.multiMaterials, this.scene.multiMaterials);
|
|
|
|
+ Array.prototype.push.apply(this.skeletons, this.scene.skeletons);
|
|
|
|
+ Array.prototype.push.apply(this.particleSystems, this.scene.particleSystems);
|
|
|
|
+ Array.prototype.push.apply(this.sounds, this.scene.mainSoundTrack.soundCollection);
|
|
|
|
+ Array.prototype.push.apply(this.transformNodes, this.scene.transformNodes);
|
|
|
|
+
|
|
|
|
+ this.removeAllFromScene();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|