Browse Source

Merge pull request #7328 from bghgary/perf-fix

Use maps by default in scene options
David Catuhe 5 years ago
parent
commit
9ae2cd2873
2 changed files with 17 additions and 8 deletions
  1. 2 2
      src/Meshes/mesh.ts
  2. 15 6
      src/scene.ts

+ 2 - 2
src/Meshes/mesh.ts

@@ -417,7 +417,7 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
 
 
             // Source mesh
             // Source mesh
             this._internalMeshDataInfo._source = source;
             this._internalMeshDataInfo._source = source;
-            if (scene.useClonedMeshhMap) {
+            if (scene.useClonedMeshMap) {
                 if (!source._internalMeshDataInfo.meshMap) {
                 if (!source._internalMeshDataInfo.meshMap) {
                     source._internalMeshDataInfo.meshMap = {};
                     source._internalMeshDataInfo.meshMap = {};
                 }
                 }
@@ -2236,7 +2236,7 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
         }
         }
 
 
         // Sources
         // Sources
-        if (this._scene.useClonedMeshhMap) {
+        if (this._scene.useClonedMeshMap) {
             if (internalDataInfo.meshMap) {
             if (internalDataInfo.meshMap) {
                 for (const uniqueId in internalDataInfo.meshMap) {
                 for (const uniqueId in internalDataInfo.meshMap) {
                     const mesh = internalDataInfo.meshMap[uniqueId];
                     const mesh = internalDataInfo.meshMap[uniqueId];

+ 15 - 6
src/scene.ts

@@ -92,7 +92,7 @@ export interface SceneOptions {
      * Defines that each mesh of the scene should keep up-to-date a map of referencing cloned meshes for fast diposing
      * Defines that each mesh of the scene should keep up-to-date a map of referencing cloned meshes for fast diposing
      * It will improve performance when the number of mesh becomes important, but might consume a bit more memory
      * It will improve performance when the number of mesh becomes important, but might consume a bit more memory
      */
      */
-    useClonedMeshhMap?: boolean;
+    useClonedMeshMap?: boolean;
 
 
     /** Defines if the creation of the scene should impact the engine (Eg. UtilityLayer's scene) */
     /** Defines if the creation of the scene should impact the engine (Eg. UtilityLayer's scene) */
     virtual?: boolean;
     virtual?: boolean;
@@ -1186,7 +1186,7 @@ export class Scene extends AbstractScene implements IAnimatable {
     /** @hidden */
     /** @hidden */
     public readonly useMaterialMeshMap: boolean;
     public readonly useMaterialMeshMap: boolean;
     /** @hidden */
     /** @hidden */
-    public readonly useClonedMeshhMap: boolean;
+    public readonly useClonedMeshMap: boolean;
 
 
     private _externalData: StringDictionary<Object>;
     private _externalData: StringDictionary<Object>;
     private _uid: Nullable<string>;
     private _uid: Nullable<string>;
@@ -1371,8 +1371,17 @@ export class Scene extends AbstractScene implements IAnimatable {
      */
      */
     constructor(engine: Engine, options?: SceneOptions) {
     constructor(engine: Engine, options?: SceneOptions) {
         super();
         super();
+
+        const fullOptions = {
+            useGeometryUniqueIdsMap: true,
+            useMaterialMeshMap: true,
+            useClonedMeshMap: true,
+            virtual: false,
+            ...options
+        };
+
         this._engine = engine || EngineStore.LastCreatedEngine;
         this._engine = engine || EngineStore.LastCreatedEngine;
-        if (!options || !options.virtual) {
+        if (!fullOptions.virtual) {
             EngineStore._LastCreatedScene = this;
             EngineStore._LastCreatedScene = this;
             this._engine.scenes.push(this);
             this._engine.scenes.push(this);
         }
         }
@@ -1399,12 +1408,12 @@ export class Scene extends AbstractScene implements IAnimatable {
 
 
         this.setDefaultCandidateProviders();
         this.setDefaultCandidateProviders();
 
 
-        if (options && options.useGeometryUniqueIdsMap === true) {
+        if (fullOptions.useGeometryUniqueIdsMap) {
             this.geometriesByUniqueId = {};
             this.geometriesByUniqueId = {};
         }
         }
 
 
-        this.useMaterialMeshMap = options && options.useGeometryUniqueIdsMap || false;
-        this.useClonedMeshhMap = options && options.useClonedMeshhMap || false;
+        this.useMaterialMeshMap = fullOptions.useMaterialMeshMap;
+        this.useClonedMeshMap = fullOptions.useClonedMeshMap;
 
 
         if (!options || !options.virtual) {
         if (!options || !options.virtual) {
             this._engine.onNewSceneAddedObservable.notifyObservers(this);
             this._engine.onNewSceneAddedObservable.notifyObservers(this);