瀏覽代碼

Merge pull request #6155 from BabylonJS/perf2

Perf2
David Catuhe 6 年之前
父節點
當前提交
b715706223

+ 2 - 2
src/Animations/animatable.ts

@@ -20,7 +20,7 @@ export class Animatable {
     private _scene: Scene;
     private _speedRatio = 1;
     private _weight = -1.0;
-    private _syncRoot: Animatable;
+    private _syncRoot: Nullable<Animatable> = null;
 
     /**
      * Gets or sets a boolean indicating if the animatable must be disposed and removed at the end of the animation.
@@ -46,7 +46,7 @@ export class Animatable {
     /**
      * Gets the root Animatable used to synchronize and normalize animations
      */
-    public get syncRoot(): Animatable {
+    public get syncRoot(): Nullable<Animatable> {
         return this._syncRoot;
     }
 

+ 5 - 5
src/Animations/runtimeAnimation.ts

@@ -1,4 +1,4 @@
-import { DeepImmutable } from "../types";
+import { DeepImmutable, Nullable } from "../types";
 import { Quaternion, Vector3, Vector2, Size, Color3, Matrix } from "../Maths/math";
 import { Animation, _IAnimationState } from "./animation";
 import { AnimationEvent } from "./animationEvent";
@@ -59,7 +59,7 @@ export class RuntimeAnimation {
     /**
      * The original blend value of the runtime animation
      */
-    private _originalBlendValue: any;
+    private _originalBlendValue: Nullable<any> = null;
 
     /**
      * The offsets cache of the runtime animation
@@ -89,7 +89,7 @@ export class RuntimeAnimation {
     /**
      * The current value of the runtime animation
      */
-    private _currentValue: any;
+    private _currentValue: Nullable<any> = null;
 
     /** @hidden */
     public _animationState: _IAnimationState;
@@ -98,8 +98,8 @@ export class RuntimeAnimation {
      * The active target of the runtime animation
      */
     private _activeTargets: any[];
-    private _currentActiveTarget: any;
-    private _directTarget: any;
+    private _currentActiveTarget: Nullable<any> = null;
+    private _directTarget: Nullable<any> = null;
 
     /**
      * The target path of the runtime animation

+ 4 - 2
src/Culling/boundingBox.ts

@@ -54,7 +54,7 @@ export class BoundingBox implements ICullable {
      */
     public readonly maximum: Vector3 = Vector3.Zero();
 
-    private _worldMatrix: DeepImmutable<Matrix>;
+    private _worldMatrix: DeepImmutable<Matrix>; 
     private static readonly TmpVector3 = ArrayTools.BuildArray(3, Vector3.Zero);
 
     /**
@@ -98,8 +98,10 @@ export class BoundingBox implements ICullable {
         // OBB
         max.addToRef(min, this.center).scaleInPlace(0.5);
         max.subtractToRef(min, this.extendSize).scaleInPlace(0.5);
+        
+        this._worldMatrix = worldMatrix || Matrix.IdentityReadOnly;
 
-        this._update(worldMatrix || Matrix.IdentityReadOnly);
+        this._update(this._worldMatrix);
     }
 
     /**

+ 1 - 1
src/Engines/engine.ts

@@ -4841,7 +4841,7 @@ export class Engine {
                     texture._workingCanvas.height = texture.height;
                 }
 
-                texture._workingContext.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, texture.width, texture.height);
+                texture._workingContext!.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, texture.width, texture.height);
 
                 this._gl.texImage2D(this._gl.TEXTURE_2D, 0, this._gl.RGBA, this._gl.RGBA, this._gl.UNSIGNED_BYTE, texture._workingCanvas);
             } else {

+ 16 - 16
src/Materials/PBR/pbrBaseMaterial.ts

@@ -333,12 +333,12 @@ export abstract class PBRBaseMaterial extends PushMaterial {
     /**
      * AKA Diffuse Texture in standard nomenclature.
      */
-    protected _albedoTexture: BaseTexture;
+    protected _albedoTexture: Nullable<BaseTexture> = null;
 
     /**
      * AKA Occlusion Texture in other nomenclature.
      */
-    protected _ambientTexture: BaseTexture;
+    protected _ambientTexture: Nullable<BaseTexture> = null;
 
     /**
      * AKA Occlusion Texture Intensity in other nomenclature.
@@ -355,55 +355,55 @@ export abstract class PBRBaseMaterial extends PushMaterial {
     /**
      * Stores the alpha values in a texture.
      */
-    protected _opacityTexture: BaseTexture;
+    protected _opacityTexture: Nullable<BaseTexture> = null;
 
     /**
      * Stores the reflection values in a texture.
      */
-    protected _reflectionTexture: BaseTexture;
+    protected _reflectionTexture: Nullable<BaseTexture> = null;
 
     /**
      * Stores the emissive values in a texture.
      */
-    protected _emissiveTexture: BaseTexture;
+    protected _emissiveTexture: Nullable<BaseTexture> = null;
 
     /**
      * AKA Specular texture in other nomenclature.
      */
-    protected _reflectivityTexture: BaseTexture;
+    protected _reflectivityTexture: Nullable<BaseTexture> = null;
 
     /**
      * Used to switch from specular/glossiness to metallic/roughness workflow.
      */
-    protected _metallicTexture: BaseTexture;
+    protected _metallicTexture: Nullable<BaseTexture> = null;
 
     /**
      * Specifies the metallic scalar of the metallic/roughness workflow.
      * Can also be used to scale the metalness values of the metallic texture.
      */
-    protected _metallic: Nullable<number>;
+    protected _metallic: Nullable<number> = null;
 
     /**
      * Specifies the roughness scalar of the metallic/roughness workflow.
      * Can also be used to scale the roughness values of the metallic texture.
      */
-    protected _roughness: Nullable<number>;
+    protected _roughness: Nullable<number> = null;
 
     /**
      * Used to enable roughness/glossiness fetch from a separate channel depending on the current mode.
      * Gray Scale represents roughness in metallic mode and glossiness in specular mode.
      */
-    protected _microSurfaceTexture: BaseTexture;
+    protected _microSurfaceTexture: Nullable<BaseTexture> = null;
 
     /**
      * Stores surface normal data used to displace a mesh in a texture.
      */
-    protected _bumpTexture: BaseTexture;
+    protected _bumpTexture: Nullable<BaseTexture> = null;
 
     /**
      * Stores the pre-calculated light information of a mesh in a texture.
      */
-    protected _lightmapTexture: BaseTexture;
+    protected _lightmapTexture: Nullable<BaseTexture> = null;
 
     /**
      * The color of a material in ambient lighting.
@@ -616,7 +616,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
     /**
      * Keep track of the image processing observer to allow dispose and replace.
      */
-    private _imageProcessingObserver: Nullable<Observer<ImageProcessingConfiguration>>;
+    private _imageProcessingObserver: Nullable<Observer<ImageProcessingConfiguration>> = null;
 
     /**
      * Attaches a new image processing configuration to the PBR Material.
@@ -661,7 +661,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
     /**
      * Enables the use of logarithmic depth buffers, which is good for wide depth buffers.
      */
-    private _useLogarithmicDepth: boolean;
+    private _useLogarithmicDepth: boolean = false;
 
     /**
      * If set to true, no lighting calculations will be applied.
@@ -874,7 +874,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
     /**
      * Gets the texture used for the alpha test.
      */
-    public getAlphaTestTexture(): BaseTexture {
+    public getAlphaTestTexture(): Nullable<BaseTexture> {
         return this._albedoTexture;
     }
 
@@ -1857,7 +1857,7 @@ export abstract class PBRBaseMaterial extends PushMaterial {
             }
 
             // image processing
-            this._imageProcessingConfiguration.bind(this._activeEffect);
+            this._imageProcessingConfiguration!.bind(this._activeEffect);
 
             // Log. depth
             MaterialHelper.BindLogDepth(defines, this._activeEffect, scene);

+ 4 - 4
src/Materials/Textures/baseTexture.ts

@@ -300,7 +300,7 @@ export class BaseTexture implements IAnimatable {
     */
     public onDisposeObservable = new Observable<BaseTexture>();
 
-    private _onDisposeObserver: Nullable<Observer<BaseTexture>>;
+    private _onDisposeObserver: Nullable<Observer<BaseTexture>> = null;
     /**
      * Callback triggered when the texture has been disposed.
      * Kept for back compatibility, you can use the onDisposeObservable instead.
@@ -317,11 +317,11 @@ export class BaseTexture implements IAnimatable {
      */
     public delayLoadState = Constants.DELAYLOADSTATE_NONE;
 
-    private _scene: Nullable<Scene>;
+    private _scene: Nullable<Scene> = null;
 
     /** @hidden */
-    public _texture: Nullable<InternalTexture>;
-    private _uid: Nullable<string>;
+    public _texture: Nullable<InternalTexture> = null;
+    private _uid: Nullable<string> = null;
 
     /**
      * Define if the texture is preventinga material to render or not.

+ 46 - 46
src/Materials/Textures/internalTexture.ts

@@ -77,43 +77,43 @@ export class InternalTexture {
     /**
      * Defines if the texture is ready
      */
-    public isReady: boolean;
+    public isReady: boolean = false;
     /**
      * Defines if the texture is a cube texture
      */
-    public isCube: boolean;
+    public isCube: boolean = false;
     /**
      * Defines if the texture contains 3D data
      */
-    public is3D: boolean;
+    public is3D: boolean = false;
     /**
      * Defines if the texture contains multiview data
      */
-    public isMultiview: boolean;
+    public isMultiview: boolean = false;
     /**
      * Gets the URL used to load this texture
      */
-    public url: string;
+    public url: string = "";
     /**
      * Gets the sampling mode of the texture
      */
-    public samplingMode: number;
+    public samplingMode: number = -1;
     /**
      * Gets a boolean indicating if the texture needs mipmaps generation
      */
-    public generateMipMaps: boolean;
+    public generateMipMaps: boolean = false;
     /**
      * Gets the number of samples used by the texture (WebGL2+ only)
      */
-    public samples: number;
+    public samples: number = 0;
     /**
      * Gets the type of the texture (int, float...)
      */
-    public type: number;
+    public type: number = -1;
     /**
      * Gets the format of the texture (RGB, RGBA...)
      */
-    public format: number;
+    public format: number = -1;
     /**
      * Observable called when the texture is loaded
      */
@@ -121,31 +121,31 @@ export class InternalTexture {
     /**
      * Gets the width of the texture
      */
-    public width: number;
+    public width: number = 0;
     /**
      * Gets the height of the texture
      */
-    public height: number;
+    public height: number = 0;
     /**
      * Gets the depth of the texture
      */
-    public depth: number;
+    public depth: number = 0;
     /**
      * Gets the initial width of the texture (It could be rescaled if the current system does not support non power of two textures)
      */
-    public baseWidth: number;
+    public baseWidth: number = 0;
     /**
      * Gets the initial height of the texture (It could be rescaled if the current system does not support non power of two textures)
      */
-    public baseHeight: number;
+    public baseHeight: number = 0;
     /**
      * Gets the initial depth of the texture (It could be rescaled if the current system does not support non power of two textures)
      */
-    public baseDepth: number;
+    public baseDepth: number = 0;
     /**
      * Gets a boolean indicating if the texture is inverted on Y axis
      */
-    public invertY: boolean;
+    public invertY: boolean = false;
 
     // Private
     /** @hidden */
@@ -155,51 +155,51 @@ export class InternalTexture {
     /** @hidden */
     public _dataSource = InternalTexture.DATASOURCE_UNKNOWN;
     /** @hidden */
-    public _buffer: Nullable<string | ArrayBuffer | HTMLImageElement | Blob>;
+    public _buffer: Nullable<string | ArrayBuffer | HTMLImageElement | Blob> = null;
     /** @hidden */
-    public _bufferView: Nullable<ArrayBufferView>;
+    public _bufferView: Nullable<ArrayBufferView> = null;
     /** @hidden */
-    public _bufferViewArray: Nullable<ArrayBufferView[]>;
+    public _bufferViewArray: Nullable<ArrayBufferView[]> = null;
     /** @hidden */
-    public _bufferViewArrayArray: Nullable<ArrayBufferView[][]>;
+    public _bufferViewArrayArray: Nullable<ArrayBufferView[][]> = null;
     /** @hidden */
-    public _size: number;
+    public _size: number = 0;
     /** @hidden */
-    public _extension: string;
+    public _extension: string = "";
     /** @hidden */
-    public _files: Nullable<string[]>;
+    public _files: Nullable<string[]> = null;
     /** @hidden */
-    public _workingCanvas: HTMLCanvasElement;
+    public _workingCanvas: Nullable<HTMLCanvasElement> = null;
     /** @hidden */
-    public _workingContext: CanvasRenderingContext2D;
+    public _workingContext: Nullable<CanvasRenderingContext2D> = null;
     /** @hidden */
-    public _framebuffer: Nullable<WebGLFramebuffer>;
+    public _framebuffer: Nullable<WebGLFramebuffer> = null;
     /** @hidden */
-    public _depthStencilBuffer: Nullable<WebGLRenderbuffer>;
+    public _depthStencilBuffer: Nullable<WebGLRenderbuffer> = null;
     /** @hidden */
-    public _MSAAFramebuffer: Nullable<WebGLFramebuffer>;
+    public _MSAAFramebuffer: Nullable<WebGLFramebuffer> = null;
     /** @hidden */
-    public _MSAARenderBuffer: Nullable<WebGLRenderbuffer>;
+    public _MSAARenderBuffer: Nullable<WebGLRenderbuffer> = null;
     /** @hidden */
-    public _attachments: Nullable<number[]>;
+    public _attachments: Nullable<number[]> = null;
     /** @hidden */
-    public _cachedCoordinatesMode: Nullable<number>;
+    public _cachedCoordinatesMode: Nullable<number> = null;
     /** @hidden */
-    public _cachedWrapU: Nullable<number>;
+    public _cachedWrapU: Nullable<number> = null;
     /** @hidden */
-    public _cachedWrapV: Nullable<number>;
+    public _cachedWrapV: Nullable<number> = null;
     /** @hidden */
-    public _cachedWrapR: Nullable<number>;
+    public _cachedWrapR: Nullable<number> = null;
     /** @hidden */
-    public _cachedAnisotropicFilteringLevel: Nullable<number>;
+    public _cachedAnisotropicFilteringLevel: Nullable<number> = null;
     /** @hidden */
-    public _isDisabled: boolean;
+    public _isDisabled: boolean = false;
     /** @hidden */
-    public _compression: Nullable<string>;
+    public _compression: Nullable<string> = null;
     /** @hidden */
-    public _generateStencilBuffer: boolean;
+    public _generateStencilBuffer: boolean = false;
     /** @hidden */
-    public _generateDepthBuffer: boolean;
+    public _generateDepthBuffer: boolean = false;
     /** @hidden */
     public _comparisonFunction: number = 0;
     /** @hidden */
@@ -211,24 +211,24 @@ export class InternalTexture {
 
     // Multiview
     /** @hidden */
-    public _colorTextureArray: Nullable<WebGLTexture>;
+    public _colorTextureArray: Nullable<WebGLTexture> = null;
     /** @hidden */
-    public _depthStencilTextureArray: Nullable<WebGLTexture>;
+    public _depthStencilTextureArray: Nullable<WebGLTexture> = null;
 
     // The following three fields helps sharing generated fixed LODs for texture filtering
     // In environment not supporting the textureLOD extension like EDGE. They are for internal use only.
     // They are at the level of the gl texture to benefit from the cache.
     /** @hidden */
-    public _lodTextureHigh: BaseTexture;
+    public _lodTextureHigh: Nullable<BaseTexture> = null;
     /** @hidden */
-    public _lodTextureMid: BaseTexture;
+    public _lodTextureMid: Nullable<BaseTexture> = null;
     /** @hidden */
-    public _lodTextureLow: BaseTexture;
+    public _lodTextureLow: Nullable<BaseTexture> = null;
     /** @hidden */
     public _isRGBD: boolean = false;
 
     /** @hidden */
-    public _webGLTexture: Nullable<WebGLTexture>;
+    public _webGLTexture: Nullable<WebGLTexture> = null;
     /** @hidden */
     public _references: number = 1;
 

+ 39 - 39
src/Materials/Textures/texture.ts

@@ -104,7 +104,7 @@ export class Texture extends BaseTexture {
      * Define the url of the texture.
      */
     @serialize()
-    public url: Nullable<string>;
+    public url: Nullable<string> = null;
 
     /**
      * Define an offset on the texture to offset the u coordinates of the UVs
@@ -184,37 +184,37 @@ export class Texture extends BaseTexture {
      * List of inspectable custom properties (used by the Inspector)
      * @see https://doc.babylonjs.com/how_to/debug_layer#extensibility
      */
-    public inspectableCustomProperties: IInspectable[];
+    public inspectableCustomProperties: Nullable<IInspectable[]> = null;
 
-    private _noMipmap: boolean;
+    private _noMipmap: boolean = false;
     /** @hidden */
-    public _invertY: boolean;
-    private _rowGenerationMatrix: Matrix;
-    private _cachedTextureMatrix: Matrix;
-    private _projectionModeMatrix: Matrix;
-    private _t0: Vector3;
-    private _t1: Vector3;
-    private _t2: Vector3;
-
-    private _cachedUOffset: number;
-    private _cachedVOffset: number;
-    private _cachedUScale: number;
-    private _cachedVScale: number;
-    private _cachedUAng: number;
-    private _cachedVAng: number;
-    private _cachedWAng: number;
-    private _cachedProjectionMatrixId: number;
-    private _cachedCoordinatesMode: number;
+    public _invertY: boolean = false;
+    private _rowGenerationMatrix: Nullable<Matrix> = null;
+    private _cachedTextureMatrix: Nullable<Matrix> = null;
+    private _projectionModeMatrix: Nullable<Matrix> = null;
+    private _t0: Nullable<Vector3> = null;
+    private _t1: Nullable<Vector3> = null;
+    private _t2: Nullable<Vector3> = null;
+
+    private _cachedUOffset: number = -1;
+    private _cachedVOffset: number = -1;
+    private _cachedUScale: number = 0;
+    private _cachedVScale: number = 0;
+    private _cachedUAng: number = -1;
+    private _cachedVAng: number = -1;
+    private _cachedWAng: number = -1;
+    private _cachedProjectionMatrixId: number = -1;
+    private _cachedCoordinatesMode: number = -1;
 
     /** @hidden */
     protected _initialSamplingMode = Texture.BILINEAR_SAMPLINGMODE;
 
     /** @hidden */
-    public _buffer: Nullable<string | ArrayBuffer | HTMLImageElement | Blob>;
-    private _deleteBuffer: boolean;
-    protected _format: Nullable<number>;
-    private _delayedOnLoad: Nullable<() => void>;
-    private _delayedOnError: Nullable<() => void>;
+    public _buffer: Nullable<string | ArrayBuffer | HTMLImageElement | Blob> = null;
+    private _deleteBuffer: boolean = false;
+    protected _format: Nullable<number> = null;
+    private _delayedOnLoad: Nullable<() => void> = null;
+    private _delayedOnError: Nullable<() => void> = null;
 
     /**
      * Observable triggered once the texture has been loaded.
@@ -400,7 +400,7 @@ export class Texture extends BaseTexture {
         y -= this.vRotationCenter * this.vScale;
         z -= this.wRotationCenter;
 
-        Vector3.TransformCoordinatesFromFloatsToRef(x, y, z, this._rowGenerationMatrix, t);
+        Vector3.TransformCoordinatesFromFloatsToRef(x, y, z, this._rowGenerationMatrix!, t);
 
         t.x += this.uRotationCenter * this.uScale + this.uOffset;
         t.y += this.vRotationCenter * this.vScale + this.vOffset;
@@ -420,7 +420,7 @@ export class Texture extends BaseTexture {
             this.uAng === this._cachedUAng &&
             this.vAng === this._cachedVAng &&
             this.wAng === this._cachedWAng) {
-            return this._cachedTextureMatrix;
+            return this._cachedTextureMatrix!;
         }
 
         this._cachedUOffset = this.uOffset;
@@ -439,19 +439,19 @@ export class Texture extends BaseTexture {
             this._t2 = Vector3.Zero();
         }
 
-        Matrix.RotationYawPitchRollToRef(this.vAng, this.uAng, this.wAng, this._rowGenerationMatrix);
+        Matrix.RotationYawPitchRollToRef(this.vAng, this.uAng, this.wAng, this._rowGenerationMatrix!);
 
-        this._prepareRowForTextureGeneration(0, 0, 0, this._t0);
-        this._prepareRowForTextureGeneration(1.0, 0, 0, this._t1);
-        this._prepareRowForTextureGeneration(0, 1.0, 0, this._t2);
+        this._prepareRowForTextureGeneration(0, 0, 0, this._t0!);
+        this._prepareRowForTextureGeneration(1.0, 0, 0, this._t1!);
+        this._prepareRowForTextureGeneration(0, 1.0, 0, this._t2!);
 
-        this._t1.subtractInPlace(this._t0);
-        this._t2.subtractInPlace(this._t0);
+        this._t1!.subtractInPlace(this._t0!);
+        this._t2!.subtractInPlace(this._t0!);
 
         Matrix.FromValuesToRef(
-            this._t1.x, this._t1.y, this._t1.z, 0.0,
-            this._t2.x, this._t2.y, this._t2.z, 0.0,
-            this._t0.x, this._t0.y, this._t0.z, 0.0,
+            this._t1!.x, this._t1!.y, this._t1!.z, 0.0,
+            this._t2!.x, this._t2!.y, this._t2!.z, 0.0,
+            this._t0!.x, this._t0!.y, this._t0!.z, 0.0,
             0.0, 0.0, 0.0, 1.0,
             this._cachedTextureMatrix
         );
@@ -477,7 +477,7 @@ export class Texture extends BaseTexture {
         let scene = this.getScene();
 
         if (!scene) {
-            return this._cachedTextureMatrix;
+            return this._cachedTextureMatrix!;
         }
 
         if (
@@ -488,10 +488,10 @@ export class Texture extends BaseTexture {
             this.coordinatesMode === this._cachedCoordinatesMode) {
             if (this.coordinatesMode === Texture.PROJECTION_MODE) {
                 if (this._cachedProjectionMatrixId === scene.getProjectionMatrix().updateFlag) {
-                    return this._cachedTextureMatrix;
+                    return this._cachedTextureMatrix!;
                 }
             } else {
-                return this._cachedTextureMatrix;
+                return this._cachedTextureMatrix!;
             }
         }
 

+ 11 - 11
src/Materials/material.ts

@@ -213,17 +213,17 @@ export class Material implements IAnimatable {
     /**
      * Callback triggered when the material is compiled
      */
-    public onCompiled: (effect: Effect) => void;
+    public onCompiled: Nullable<(effect: Effect) => void> = null;
 
     /**
      * Callback triggered when an error occurs
      */
-    public onError: (effect: Effect, errors: string) => void;
+    public onError: Nullable<(effect: Effect, errors: string) => void> = null;
 
     /**
      * Callback triggered to get the render target textures
      */
-    public getRenderTargetTextures: () => SmartArray<RenderTargetTexture>;
+    public getRenderTargetTextures: Nullable<() => SmartArray<RenderTargetTexture>> = null;
 
     /**
      * Gets a boolean indicating that current material needs to register RTT
@@ -245,7 +245,7 @@ export class Material implements IAnimatable {
     /**
      * Stores the animations for the material
      */
-    public animations: Array<Animation>;
+    public animations: Nullable<Array<Animation>> = null;
 
     /**
     * An event triggered when the material is disposed
@@ -255,8 +255,8 @@ export class Material implements IAnimatable {
     /**
      * An observer which watches for dispose events
      */
-    private _onDisposeObserver: Nullable<Observer<Material>>;
-    private _onUnBindObservable: Nullable<Observable<Material>>;
+    private _onDisposeObserver: Nullable<Observer<Material>> = null;
+    private _onUnBindObservable: Nullable<Observable<Material>> = null;
 
     /**
      * Called during a dispose event
@@ -284,7 +284,7 @@ export class Material implements IAnimatable {
     /**
      * An observer which watches for bind events
      */
-    private _onBindObserver: Nullable<Observer<AbstractMesh>>;
+    private _onBindObserver: Nullable<Observer<AbstractMesh>> = null;
 
     /**
      * Called during a bind event
@@ -494,7 +494,7 @@ export class Material implements IAnimatable {
      * @hidden
      * Stores the effects for the material
      */
-    public _effect: Nullable<Effect>;
+    public _effect: Nullable<Effect> = null;
 
     /**
      * @hidden
@@ -505,7 +505,7 @@ export class Material implements IAnimatable {
     /**
      * Specifies if uniform buffers should be used
      */
-    private _useUBO: boolean;
+    private _useUBO: boolean = false;
 
     /**
      * Stores a reference to the scene
@@ -520,7 +520,7 @@ export class Material implements IAnimatable {
     /**
      * Specifies if the depth write state should be cached
      */
-    private _cachedDepthWriteState: boolean;
+    private _cachedDepthWriteState: boolean = false;
 
     /**
      * Stores the uniform buffer
@@ -531,7 +531,7 @@ export class Material implements IAnimatable {
     public _indexInSceneMaterialArray = -1;
 
     /** @hidden */
-    public meshMap: Nullable<{ [id: string]: AbstractMesh | undefined }>;
+    public meshMap: Nullable<{ [id: string]: AbstractMesh | undefined }> = null;
 
     /**
      * Creates a material instance

+ 2 - 2
src/Maths/math.ts

@@ -371,7 +371,7 @@ export class Color3 {
     }
 
     /**
-     * Creates a new Vector3 from the starting index of the given array
+     * Creates a new Color3 from the starting index of the given array
      * @param array defines the source array
      * @param offset defines an offset in the source array
      * @returns a new Color3 object
@@ -4386,7 +4386,7 @@ export class Matrix {
      * It will be incremented every time the matrix data change.
      * You can use it to speed the comparison between two versions of the same matrix.
      */
-    public updateFlag: number;
+    public updateFlag: number = -1;
 
     private readonly _m: Float32Array = new Float32Array(16);
 

+ 13 - 13
src/Meshes/abstractMesh.ts

@@ -264,14 +264,14 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
     public definedFacingForward = true;
 
     /** @hidden */
-    public _occlusionQuery: Nullable<WebGLQuery>;
+    public _occlusionQuery: Nullable<WebGLQuery> = null;
 
     private _visibility = 1.0;
 
     /** @hidden */
     public _isActive = false;
     /** @hidden */
-    public _renderingGroup: RenderingGroup;
+    public _renderingGroup: Nullable<RenderingGroup> = null;
 
     /**
      * Gets or sets mesh visibility between 0 and 1 (default is 1)
@@ -325,7 +325,7 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
      * @see http://doc.babylonjs.com/resources/transparency_and_how_meshes_are_rendered#rendering-groups
      */
     public renderingGroupId = 0;
-    private _material: Nullable<Material>;
+    private _material: Nullable<Material> = null;
 
     /** Gets or sets current material */
     public get material(): Nullable<Material> {
@@ -518,7 +518,7 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
      * @see http://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity
      */
     public ellipsoidOffset = new Vector3(0, 0, 0);
-    private _collider: Collider;
+    private _collider: Nullable<Collider> = null;
     private _oldPositionForCollisions = new Vector3(0, 0, 0);
     private _diffPositionForCollisions = new Vector3(0, 0, 0);
 
@@ -558,12 +558,12 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
      */
     public edgesColor = new Color4(1, 0, 0, 1);
     /** @hidden */
-    public _edgesRenderer: Nullable<IEdgesRenderer>;
+    public _edgesRenderer: Nullable<IEdgesRenderer> = null;
 
     /** @hidden */
-    public _masterMesh: Nullable<AbstractMesh>;
+    public _masterMesh: Nullable<AbstractMesh> = null;
     /** @hidden */
-    public _boundingInfo: Nullable<BoundingInfo>;
+    public _boundingInfo: Nullable<BoundingInfo> = null;
     /** @hidden */
     public _renderId = 0;
 
@@ -589,14 +589,14 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
 
     // Loading properties
     /** @hidden */
-    public _waitingActions: any;
+    public _waitingActions: Nullable<any> = null;
     /** @hidden */
-    public _waitingFreezeWorldMatrix: Nullable<boolean>;
+    public _waitingFreezeWorldMatrix: Nullable<boolean> = null;
 
     // Skeleton
-    private _skeleton: Nullable<Skeleton>;
+    private _skeleton: Nullable<Skeleton> = null;
     /** @hidden */
-    public _bonesTransformMatrices: Nullable<Float32Array>;
+    public _bonesTransformMatrices: Nullable<Float32Array> = null;
 
     /**
      * Gets or sets a skeleton to apply skining transformations
@@ -1338,7 +1338,7 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
      * Gets Collider object used to compute collisions (not physics)
      * @see http://doc.babylonjs.com/babylon101/cameras,_mesh_collisions_and_gravity
      */
-    public get collider(): Collider {
+    public get collider(): Nullable<Collider> {
         return this._collider;
     }
 
@@ -1388,7 +1388,7 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
         }
 
         // Transformation
-        if (!subMesh._lastColliderWorldVertices || !subMesh._lastColliderTransformMatrix.equals(transformMatrix)) {
+        if (!subMesh._lastColliderWorldVertices || !subMesh._lastColliderTransformMatrix!.equals(transformMatrix)) {
             subMesh._lastColliderTransformMatrix = transformMatrix.clone();
             subMesh._lastColliderWorldVertices = [];
             subMesh._trianglePlanes = [];

+ 7 - 7
src/Meshes/mesh.ts

@@ -242,7 +242,7 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
     public onLODLevelSelection: (distance: number, mesh: Mesh, selectedLevel: Nullable<Mesh>) => void;
 
     // Morph
-    private _morphTargetManager: Nullable<MorphTargetManager>;
+    private _morphTargetManager: Nullable<MorphTargetManager> = null;
 
     /**
      * Gets or sets the morph target manager
@@ -262,10 +262,10 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
 
     // Private
     /** @hidden */
-    public _creationDataStorage: Nullable<_CreationDataStorage>;
+    public _creationDataStorage: Nullable<_CreationDataStorage> = null;
 
     /** @hidden */
-    public _geometry: Nullable<Geometry>;
+    public _geometry: Nullable<Geometry> = null;
     /** @hidden */
     public _delayInfo: Array<string>;
     /** @hidden */
@@ -274,11 +274,11 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
     /** @hidden */
     public _instanceDataStorage = new _InstanceDataStorage();
 
-    private _effectiveMaterial: Material;
+    private _effectiveMaterial: Nullable<Material> = null;
 
     /** @hidden */
-    public _shouldGenerateFlatShading: boolean;
-    private _preActivateId: number;
+    public _shouldGenerateFlatShading: boolean = false;
+    private _preActivateId: number = -1;
 
     // Use by builder only to know what orientation were the mesh build in.
     /** @hidden */
@@ -297,7 +297,7 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
     // Will be used to save a source mesh reference, If any
     private _source: Nullable<Mesh> = null;
     // Will be used to for fast cloned mesh lookup
-    private meshMap: Nullable<{ [id: string]: Mesh | undefined }>;
+    private meshMap: Nullable<{ [id: string]: Mesh | undefined }> = null;
 
     /**
      * Gets the source mesh (the one used to clone this one from)

+ 9 - 9
src/Meshes/subMesh.ts

@@ -22,9 +22,9 @@ declare type TrianglePickingPredicate = import("../Culling/ray").TrianglePicking
  */
 export class BaseSubMesh {
     /** @hidden */
-    public _materialDefines: Nullable<MaterialDefines>;
+    public _materialDefines: Nullable<MaterialDefines> = null;
     /** @hidden */
-    public _materialEffect: Nullable<Effect>;
+    public _materialEffect: Nullable<Effect> = null;
 
     /**
      * Gets associated effect
@@ -55,28 +55,28 @@ export class BaseSubMesh {
  */
 export class SubMesh extends BaseSubMesh implements ICullable {
     /** @hidden */
-    public _linesIndexCount: number;
+    public _linesIndexCount: number = 0;
     private _mesh: AbstractMesh;
     private _renderingMesh: Mesh;
     private _boundingInfo: BoundingInfo;
-    private _linesIndexBuffer: Nullable<WebGLBuffer>;
+    private _linesIndexBuffer: Nullable<WebGLBuffer> = null;
     /** @hidden */
-    public _lastColliderWorldVertices: Nullable<Vector3[]>;
+    public _lastColliderWorldVertices: Nullable<Vector3[]> = null;
     /** @hidden */
     public _trianglePlanes: Plane[];
     /** @hidden */
-    public _lastColliderTransformMatrix: Matrix;
+    public _lastColliderTransformMatrix: Nullable<Matrix> = null;
 
     /** @hidden */
     public _renderId = 0;
     /** @hidden */
-    public _alphaIndex: number;
+    public _alphaIndex: number = 0;
     /** @hidden */
-    public _distanceToCamera: number;
+    public _distanceToCamera: number = 0;
     /** @hidden */
     public _id: number;
 
-    private _currentMaterial: Nullable<Material>;
+    private _currentMaterial: Nullable<Material> = null;
 
     /**
      * Add a new submesh to a mesh

+ 10 - 3
src/Meshes/transformNode.ts

@@ -49,12 +49,12 @@ export class TransformNode extends Node {
     private _rotation = Vector3.Zero();
 
     @serializeAsQuaternion("rotationQuaternion")
-    private _rotationQuaternion: Nullable<Quaternion>;
+    private _rotationQuaternion: Nullable<Quaternion> = null;
 
     @serializeAsVector3("scaling")
     protected _scaling = Vector3.One();
     protected _isDirty = false;
-    private _transformToBoneReferal: Nullable<TransformNode>;
+    private _transformToBoneReferal: Nullable<TransformNode> = null;
 
     @serialize("billboardMode")
     private _billboardMode = TransformNode.BILLBOARDMODE_NONE;
@@ -137,7 +137,7 @@ export class TransformNode extends Node {
 
     // Cache
     /** @hidden */
-    public _poseMatrix: Matrix;
+    public _poseMatrix: Nullable<Matrix> = null;
     /** @hidden */
     public _localMatrix = Matrix.Zero();
 
@@ -264,6 +264,10 @@ export class TransformNode extends Node {
      * @returns this TransformNode.
      */
     public updatePoseMatrix(matrix: Matrix): TransformNode {
+        if (!this._poseMatrix) {
+            this._poseMatrix = matrix.clone();
+            return this;
+        }
         this._poseMatrix.copyFrom(matrix);
         return this;
     }
@@ -273,6 +277,9 @@ export class TransformNode extends Node {
      * @returns the pose matrix
      */
     public getPoseMatrix(): Matrix {
+        if (!this._poseMatrix) {
+            this._poseMatrix = Matrix.Identity();
+        }
         return this._poseMatrix;
     }
 

+ 1 - 1
src/Misc/tools.ts

@@ -44,7 +44,7 @@ export interface IAnimatable {
     /**
      * Array of animations
      */
-    animations: Array<Animation>;
+    animations: Nullable<Array<Animation>>;
 }
 
 /** Interface used by value gradients (color, factor, ...) */

+ 6 - 6
src/node.ts

@@ -118,7 +118,7 @@ export class Node implements IBehaviorAware<Node> {
     /**
      * Callback raised when the node is ready to be used
      */
-    public onReady: (node: Node) => void;
+    public onReady: Nullable<(node: Node) => void> = null;
 
     private _isEnabled = true;
     private _isParentEnabled = true;
@@ -130,14 +130,14 @@ export class Node implements IBehaviorAware<Node> {
     public _childUpdateId = -1;
 
     /** @hidden */
-    public _waitingParentId: Nullable<string>;
+    public _waitingParentId: Nullable<string> = null;
     /** @hidden */
     public _scene: Scene;
     /** @hidden */
-    public _cache: any;
+    public _cache: any = {};
 
-    private _parentNode: Nullable<Node>;
-    private _children: Node[];
+    private _parentNode: Nullable<Node> = null;
+    private _children: Nullable<Node[]> = null;
 
     /** @hidden */
     public _worldMatrix = Matrix.Identity();
@@ -253,7 +253,7 @@ export class Node implements IBehaviorAware<Node> {
     */
     public onDisposeObservable = new Observable<Node>();
 
-    private _onDisposeObserver: Nullable<Observer<Node>>;
+    private _onDisposeObserver: Nullable<Observer<Node>> = null;
     /**
      * Sets a callback that will be raised when the node will be disposed
      */

+ 2 - 2
src/scene.ts

@@ -3736,7 +3736,7 @@ export class Scene extends AbstractScene implements IAnimatable {
                     if (this._processedMaterials.indexOf(material) === -1) {
                         this._processedMaterials.push(material);
 
-                        this._renderTargets.concatWithNoDuplicate(material.getRenderTargetTextures());
+                        this._renderTargets.concatWithNoDuplicate(material.getRenderTargetTextures!());
                     }
                 }
 
@@ -3926,7 +3926,7 @@ export class Scene extends AbstractScene implements IAnimatable {
 
             this._totalVertices.addCount(mesh.getTotalVertices(), false);
 
-            if (!mesh.isReady() || !mesh.isEnabled()) {
+            if (!mesh.isReady() || !mesh.isEnabled() || mesh.scaling.lengthSquared() === 0) {
                 continue;
             }