Bläddra i källkod

protected and private methods with _

Raanan Weber 7 år sedan
förälder
incheckning
bed0b45dc7

+ 0 - 0
Viewer/src/configuration/index.ts


+ 14 - 14
Viewer/src/configuration/loader.ts

@@ -7,13 +7,13 @@ import { Tools, IFileRequest } from 'babylonjs';
 
 export class ConfigurationLoader {
 
-    private configurationCache: { [url: string]: any };
+    private _configurationCache: { [url: string]: any };
 
-    private loadRequests: Array<IFileRequest>;
+    private _loadRequests: Array<IFileRequest>;
 
     constructor(private _enableCache: boolean = false) {
-        this.configurationCache = {};
-        this.loadRequests = [];
+        this._configurationCache = {};
+        this._loadRequests = [];
     }
 
     public loadConfiguration(initConfig: ViewerConfiguration = {}, callback?: (config: ViewerConfiguration) => void): Promise<ViewerConfiguration> {
@@ -47,7 +47,7 @@ export class ConfigurationLoader {
                         }
                         mapperType = type || mapperType;
                     }
-                    return this.loadFile(url);
+                    return this._loadFile(url);
                 } else {
                     if (typeof loadedConfig.configuration === "object") {
                         mapperType = loadedConfig.configuration.mapper || mapperType;
@@ -70,32 +70,32 @@ export class ConfigurationLoader {
     }
 
     public dispose() {
-        this.loadRequests.forEach(request => {
+        this._loadRequests.forEach(request => {
             request.abort();
         });
-        this.loadRequests.length = 0;
+        this._loadRequests.length = 0;
     }
 
-    private loadFile(url: string): Promise<any> {
-        let cacheReference = this.configurationCache;
+    private _loadFile(url: string): Promise<any> {
+        let cacheReference = this._configurationCache;
         if (this._enableCache && cacheReference[url]) {
             return Promise.resolve(cacheReference[url]);
         }
 
         return new Promise((resolve, reject) => {
             let fileRequest = Tools.LoadFile(url, (result) => {
-                let idx = this.loadRequests.indexOf(fileRequest);
+                let idx = this._loadRequests.indexOf(fileRequest);
                 if (idx !== -1)
-                    this.loadRequests.splice(idx, 1);
+                    this._loadRequests.splice(idx, 1);
                 if (this._enableCache) cacheReference[url] = result;
                 resolve(result);
             }, undefined, undefined, false, (request, error: any) => {
-                let idx = this.loadRequests.indexOf(fileRequest);
+                let idx = this._loadRequests.indexOf(fileRequest);
                 if (idx !== -1)
-                    this.loadRequests.splice(idx, 1);
+                    this._loadRequests.splice(idx, 1);
                 reject(error);
             });
-            this.loadRequests.push(fileRequest);
+            this._loadRequests.push(fileRequest);
         });
     }
 

+ 6 - 6
Viewer/src/configuration/mappers.ts

@@ -96,11 +96,11 @@ class DOMMapper implements IMapper {
 
 export class MapperManager {
 
-    private mappers: { [key: string]: IMapper };
+    private _mappers: { [key: string]: IMapper };
     public static DefaultMapper = 'json';
 
     constructor() {
-        this.mappers = {
+        this._mappers = {
             "html": new HTMLMapper(),
             "json": new JSONMapper(),
             "dom": new DOMMapper()
@@ -108,18 +108,18 @@ export class MapperManager {
     }
 
     public getMapper(type: string) {
-        if (!this.mappers[type]) {
+        if (!this._mappers[type]) {
             Tools.Error("No mapper defined for " + type);
         }
-        return this.mappers[type] || this.mappers[MapperManager.DefaultMapper];
+        return this._mappers[type] || this._mappers[MapperManager.DefaultMapper];
     }
 
     public registerMapper(type: string, mapper: IMapper) {
-        this.mappers[type] = mapper;
+        this._mappers[type] = mapper;
     }
 
     public dispose() {
-        this.mappers = {};
+        this._mappers = {};
     }
 
 }

+ 13 - 13
Viewer/src/eventManager.ts

@@ -3,42 +3,42 @@ import { EventCallback, TemplateManager } from "./templateManager";
 
 export class EventManager {
 
-    private callbacksContainer: { [key: string]: Array<{ eventType?: string, selector?: string, callback: (eventData: EventCallback) => void }> }
+    private _callbacksContainer: { [key: string]: Array<{ eventType?: string, selector?: string, callback: (eventData: EventCallback) => void }> }
 
-    constructor(private templateManager: TemplateManager) {
-        this.callbacksContainer = {};
-        this.templateManager.onEventTriggered.add(eventData => {
-            this.eventTriggered(eventData);
+    constructor(private _templateManager: TemplateManager) {
+        this._callbacksContainer = {};
+        this._templateManager.onEventTriggered.add(eventData => {
+            this._eventTriggered(eventData);
         })
     }
 
     public registerCallback(templateName: string, callback: (eventData: EventCallback) => void, eventType?: string, selector?: string) {
-        if (!this.callbacksContainer[templateName]) {
-            this.callbacksContainer[templateName] = [];
+        if (!this._callbacksContainer[templateName]) {
+            this._callbacksContainer[templateName] = [];
         }
-        this.callbacksContainer[templateName].push({
+        this._callbacksContainer[templateName].push({
             eventType: eventType,
             callback: callback
         });
     }
 
     public unregisterCallback(templateName: string, callback?: (eventData: EventCallback) => void, eventType?: string, selector?: string) {
-        let callbackDefs = this.callbacksContainer[templateName] || [];
-        this.callbacksContainer[templateName] = callbackDefs.filter(callbackDef => (!callbackDef.eventType || callbackDef.eventType === eventType) && (!callbackDef.selector || callbackDef.selector === selector));
+        let callbackDefs = this._callbacksContainer[templateName] || [];
+        this._callbacksContainer[templateName] = callbackDefs.filter(callbackDef => (!callbackDef.eventType || callbackDef.eventType === eventType) && (!callbackDef.selector || callbackDef.selector === selector));
     }
 
-    private eventTriggered(data: EventCallback) {
+    private _eventTriggered(data: EventCallback) {
         let templateName = data.template.name;
         let eventType = data.event.type;
         let selector = data.selector;
 
-        let callbackDefs = this.callbacksContainer[templateName] || [];
+        let callbackDefs = this._callbacksContainer[templateName] || [];
         callbackDefs.filter(callbackDef => (!callbackDef.eventType || callbackDef.eventType === eventType) && (!callbackDef.selector || callbackDef.selector === selector)).forEach(callbackDef => {
             callbackDef.callback(data);
         });
     }
 
     public dispose() {
-        this.callbacksContainer = {};
+        this._callbacksContainer = {};
     }
 }

+ 38 - 41
Viewer/src/templateManager.ts

@@ -73,7 +73,7 @@ export class TemplateManager {
             let addToParent = () => {
                 let containingElement = parentTemplate && parentTemplate.parent.querySelector(camelToKebab(name)) || this.containerElement;
                 template.appendTo(containingElement);
-                this.checkLoadedState();
+                this._checkLoadedState();
             }
 
             if (parentTemplate && !parentTemplate.parent) {
@@ -89,11 +89,11 @@ export class TemplateManager {
         }
 
         //build the html tree
-        return this.buildHTMLTree(templates).then(htmlTree => {
+        return this._buildHTMLTree(templates).then(htmlTree => {
             if (this.templates['main']) {
                 internalInit(htmlTree, 'main');
             } else {
-                this.checkLoadedState();
+                this._checkLoadedState();
             }
             return;
         });
@@ -105,11 +105,9 @@ export class TemplateManager {
      * It will compile each template, check if its children exist in the configuration and will add them if they do.
      * It is expected that the main template will be called main!
      * 
-     * @private
-     * @param {{ [key: string]: ITemplateConfiguration }} templates 
-     * @memberof TemplateManager
+     * @param templates
      */
-    private buildHTMLTree(templates: { [key: string]: ITemplateConfiguration }): Promise<object> {
+    private _buildHTMLTree(templates: { [key: string]: ITemplateConfiguration }): Promise<object> {
         let promises: Array<Promise<Template | boolean>> = Object.keys(templates).map(name => {
             // if the template was overridden
             if (!templates[name]) return Promise.resolve(false);
@@ -148,7 +146,7 @@ export class TemplateManager {
         return this.templates[name];
     }
 
-    private checkLoadedState() {
+    private _checkLoadedState() {
         let done = Object.keys(this.templates).length === 0 || Object.keys(this.templates).every((key) => {
             return (this.templates[key].isLoaded && !!this.templates[key].parent) || !this.templates[key].isInHtmlTree;
         });
@@ -214,8 +212,8 @@ export class Template {
 
     public initPromise: Promise<Template>;
 
-    private fragment: DocumentFragment;
-    private htmlTemplate: string;
+    private _fragment: DocumentFragment;
+    private _htmlTemplate: string;
 
     private loadRequests: Array<IFileRequest>;
 
@@ -238,15 +236,15 @@ export class Template {
         */
         this.onInit.notifyObservers(this);
 
-        let htmlContentPromise = this.getTemplateAsHtml(_configuration);
+        let htmlContentPromise = this._getTemplateAsHtml(_configuration);
 
         this.initPromise = htmlContentPromise.then(htmlTemplate => {
             if (htmlTemplate) {
-                this.htmlTemplate = htmlTemplate;
+                this._htmlTemplate = htmlTemplate;
                 let compiledTemplate = Handlebars.compile(htmlTemplate);
                 let config = this._configuration.params || {};
                 let rawHtml = compiledTemplate(config);
-                this.fragment = document.createRange().createContextualFragment(rawHtml);
+                this._fragment = document.createRange().createContextualFragment(rawHtml);
                 this.isLoaded = true;
                 this.isShown = true;
                 this.onLoaded.notifyObservers(this);
@@ -261,10 +259,10 @@ export class Template {
         if (this.isLoaded) {
             this.dispose();
         }
-        let compiledTemplate = Handlebars.compile(this.htmlTemplate);
+        let compiledTemplate = Handlebars.compile(this._htmlTemplate);
         let config = this._configuration.params || {};
         let rawHtml = compiledTemplate(config);
-        this.fragment = document.createRange().createContextualFragment(rawHtml);
+        this._fragment = document.createRange().createContextualFragment(rawHtml);
         if (this.parent) {
             this.appendTo(this.parent, true);
         }
@@ -277,10 +275,10 @@ export class Template {
     public getChildElements(): Array<string> {
         let childrenArray: string[] = [];
         //Edge and IE don't support frage,ent.children
-        let children = this.fragment.children;
+        let children = this._fragment.children;
         if (!children) {
             // casting to HTMLCollection, as both NodeListOf and HTMLCollection have 'item()' and 'length'.
-            children = <HTMLCollection>this.fragment.querySelectorAll('*');
+            children = <HTMLCollection>this._fragment.querySelectorAll('*');
         }
         for (let i = 0; i < children.length; ++i) {
             childrenArray.push(kebabToCamel(children.item(i).nodeName.toLowerCase()));
@@ -291,7 +289,7 @@ export class Template {
     public appendTo(parent: HTMLElement, forceRemove?: boolean) {
         if (this.parent) {
             if (forceRemove) {
-                this.parent.removeChild(this.fragment);
+                this.parent.removeChild(this._fragment);
             } else {
                 return;
             }
@@ -301,20 +299,20 @@ export class Template {
         if (this._configuration.id) {
             this.parent.id = this._configuration.id;
         }
-        this.fragment = this.parent.appendChild(this.fragment);
+        this._fragment = this.parent.appendChild(this._fragment);
         // appended only one frame after.
         setTimeout(() => {
-            this.registerEvents();
+            this._registerEvents();
             this.onAppended.notifyObservers(this);
         });
     }
 
-    private isShowing: boolean;
-    private isHiding: boolean;
+    private _isShowing: boolean;
+    private _isHiding: boolean;
     public show(visibilityFunction?: (template: Template) => Promise<Template>): Promise<Template> {
-        if (this.isHiding) return Promise.resolve(this);
+        if (this._isHiding) return Promise.resolve(this);
         return Promise.resolve().then(() => {
-            this.isShowing = true;
+            this._isShowing = true;
             if (visibilityFunction) {
                 return visibilityFunction(this);
             } else {
@@ -324,16 +322,16 @@ export class Template {
             }
         }).then(() => {
             this.isShown = true;
-            this.isShowing = false;
+            this._isShowing = false;
             this.onStateChange.notifyObservers(this);
             return this;
         });
     }
 
     public hide(visibilityFunction?: (template: Template) => Promise<Template>): Promise<Template> {
-        if (this.isShowing) return Promise.resolve(this);
+        if (this._isShowing) return Promise.resolve(this);
         return Promise.resolve().then(() => {
-            this.isHiding = true;
+            this._isHiding = true;
             if (visibilityFunction) {
                 return visibilityFunction(this);
             } else {
@@ -343,7 +341,7 @@ export class Template {
             }
         }).then(() => {
             this.isShown = false;
-            this.isHiding = false;
+            this._isHiding = false;
             this.onStateChange.notifyObservers(this);
             return this;
         });
@@ -358,7 +356,7 @@ export class Template {
         this.isLoaded = false;
         // remove from parent
         try {
-            this.parent.removeChild(this.fragment);
+            this.parent.removeChild(this._fragment);
         } catch (e) {
             //noop
         }
@@ -367,16 +365,16 @@ export class Template {
             request.abort();
         });
 
-        if (this.registeredEvents) {
-            this.registeredEvents.forEach(evt => {
+        if (this._registeredEvents) {
+            this._registeredEvents.forEach(evt => {
                 evt.htmlElement.removeEventListener(evt.eventName, evt.function);
             });
         }
 
-        delete this.fragment;
+        delete this._fragment;
     }
 
-    private getTemplateAsHtml(templateConfig: ITemplateConfiguration): Promise<string> {
+    private _getTemplateAsHtml(templateConfig: ITemplateConfiguration): Promise<string> {
         if (!templateConfig) {
             return Promise.reject('No templateConfig provided');
         } else if (templateConfig.html !== undefined) {
@@ -404,14 +402,13 @@ export class Template {
         }
     }
 
-    private registeredEvents: Array<{ htmlElement: HTMLElement, eventName: string, function: EventListenerOrEventListenerObject }>;
+    private _registeredEvents: Array<{ htmlElement: HTMLElement, eventName: string, function: EventListenerOrEventListenerObject }>;
 
-    // TODO - Should events be removed as well? when are templates disposed?
-    private registerEvents() {
-        this.registeredEvents = this.registeredEvents || [];
-        if (this.registeredEvents.length) {
+    private _registerEvents() {
+        this._registeredEvents = this._registeredEvents || [];
+        if (this._registeredEvents.length) {
             // first remove the registered events
-            this.registeredEvents.forEach(evt => {
+            this._registeredEvents.forEach(evt => {
                 evt.htmlElement.removeEventListener(evt.eventName, evt.function);
             });
         }
@@ -426,7 +423,7 @@ export class Template {
                     if (typeof this._configuration.events[eventName] === 'boolean') {
                         let binding = functionToFire.bind(this, '#' + this.parent.id);
                         this.parent.addEventListener(eventName, functionToFire.bind(this, '#' + this.parent.id), false);
-                        this.registeredEvents.push({
+                        this._registeredEvents.push({
                             htmlElement: this.parent,
                             eventName: eventName,
                             function: binding
@@ -443,7 +440,7 @@ export class Template {
                             if (htmlElement) {
                                 let binding = functionToFire.bind(this, selector);
                                 htmlElement.addEventListener(eventName, binding, false);
-                                this.registeredEvents.push({
+                                this._registeredEvents.push({
                                     htmlElement: htmlElement,
                                     eventName: eventName,
                                     function: binding

+ 32 - 32
Viewer/src/viewer/defaultViewer.ts

@@ -11,22 +11,22 @@ export class DefaultViewer extends AbstractViewer {
 
     constructor(public containerElement: HTMLElement, initialConfiguration: ViewerConfiguration = { extends: 'default' }) {
         super(containerElement, initialConfiguration);
-        this.onModelLoadedObservable.add(this.onModelLoaded);
+        this.onModelLoadedObservable.add(this._onModelLoaded);
     }
 
-    public initScene(): Promise<Scene> {
-        return super.initScene().then(() => {
-            this.extendClassWithConfig(this.scene, this.configuration.scene);
+    public _initScene(): Promise<Scene> {
+        return super._initScene().then(() => {
+            this._extendClassWithConfig(this.scene, this._configuration.scene);
             return this.scene;
         })
     }
 
-    protected onTemplatesLoaded() {
+    protected _onTemplatesLoaded() {
 
         this.showLoadingScreen();
 
         // navbar
-        this.initNavbar();
+        this._initNavbar();
 
         // close overlay button
         let closeButton = document.getElementById('close-button');
@@ -36,10 +36,10 @@ export class DefaultViewer extends AbstractViewer {
             })
         }
 
-        return super.onTemplatesLoaded();
+        return super._onTemplatesLoaded();
     }
 
-    private initNavbar() {
+    private _initNavbar() {
         let navbar = this.templateManager.getTemplate('navBar');
         if (navbar) {
             let navbarHeight = navbar.parent.clientHeight + 'px';
@@ -99,12 +99,12 @@ export class DefaultViewer extends AbstractViewer {
         }
     }
 
-    protected prepareContainerElement() {
+    protected _prepareContainerElement() {
         this.containerElement.style.position = 'relative';
         this.containerElement.style.display = 'flex';
     }
 
-    protected configureTemplate(model: ViewerModel) {
+    protected _configureTemplate(model: ViewerModel) {
         let navbar = this.templateManager.getTemplate('navBar');
         if (!navbar) return;
 
@@ -132,7 +132,7 @@ export class DefaultViewer extends AbstractViewer {
         }
     }
 
-    public loadModel(model: any = this.configuration.model): Promise<ViewerModel> {
+    public loadModel(model: any = this._configuration.model): Promise<ViewerModel> {
         this.showLoadingScreen();
         return super.loadModel(model, true).catch((error) => {
             console.log(error);
@@ -142,12 +142,12 @@ export class DefaultViewer extends AbstractViewer {
         });
     }
 
-    private onModelLoaded = (model: ViewerModel) => {
-        this.configureTemplate(model);
+    private _onModelLoaded = (model: ViewerModel) => {
+        this._configureTemplate(model);
         // with a short timeout, making sure everything is there already.
         let hideLoadingDelay = 500;
-        if (this.configuration.lab && this.configuration.lab.hideLoadingDelay !== undefined) {
-            hideLoadingDelay = this.configuration.lab.hideLoadingDelay;
+        if (this._configuration.lab && this._configuration.lab.hideLoadingDelay !== undefined) {
+            hideLoadingDelay = this._configuration.lab.hideLoadingDelay;
         }
         setTimeout(() => {
             this.hideLoadingScreen();
@@ -243,31 +243,31 @@ export class DefaultViewer extends AbstractViewer {
         }));
     }
 
-    protected configureLights(lightsConfiguration: { [name: string]: ILightConfiguration | boolean } = {}, model: ViewerModel) {
-        super.configureLights(lightsConfiguration, model);
+    protected _configureLights(lightsConfiguration: { [name: string]: ILightConfiguration | boolean } = {}, model: ViewerModel) {
+        super._configureLights(lightsConfiguration, model);
         // labs feature - flashlight
-        if (this.configuration.lab && this.configuration.lab.flashlight) {
+        if (this._configuration.lab && this._configuration.lab.flashlight) {
             let pointerPosition = Vector3.Zero();
             let lightTarget;
             let angle = 0.5;
             let exponent = Math.PI / 2;
-            if (typeof this.configuration.lab.flashlight === "object") {
-                exponent = this.configuration.lab.flashlight.exponent || exponent;
-                angle = this.configuration.lab.flashlight.angle || angle;
+            if (typeof this._configuration.lab.flashlight === "object") {
+                exponent = this._configuration.lab.flashlight.exponent || exponent;
+                angle = this._configuration.lab.flashlight.angle || angle;
             }
             var flashlight = new SpotLight("flashlight", Vector3.Zero(),
                 Vector3.Zero(), exponent, angle, this.scene);
-            if (typeof this.configuration.lab.flashlight === "object") {
-                flashlight.intensity = this.configuration.lab.flashlight.intensity || flashlight.intensity;
-                if (this.configuration.lab.flashlight.diffuse) {
-                    flashlight.diffuse.r = this.configuration.lab.flashlight.diffuse.r;
-                    flashlight.diffuse.g = this.configuration.lab.flashlight.diffuse.g;
-                    flashlight.diffuse.b = this.configuration.lab.flashlight.diffuse.b;
+            if (typeof this._configuration.lab.flashlight === "object") {
+                flashlight.intensity = this._configuration.lab.flashlight.intensity || flashlight.intensity;
+                if (this._configuration.lab.flashlight.diffuse) {
+                    flashlight.diffuse.r = this._configuration.lab.flashlight.diffuse.r;
+                    flashlight.diffuse.g = this._configuration.lab.flashlight.diffuse.g;
+                    flashlight.diffuse.b = this._configuration.lab.flashlight.diffuse.b;
                 }
-                if (this.configuration.lab.flashlight.specular) {
-                    flashlight.specular.r = this.configuration.lab.flashlight.specular.r;
-                    flashlight.specular.g = this.configuration.lab.flashlight.specular.g;
-                    flashlight.specular.b = this.configuration.lab.flashlight.specular.b;
+                if (this._configuration.lab.flashlight.specular) {
+                    flashlight.specular.r = this._configuration.lab.flashlight.specular.r;
+                    flashlight.specular.g = this._configuration.lab.flashlight.specular.g;
+                    flashlight.specular.b = this._configuration.lab.flashlight.specular.b;
                 }
 
             }
@@ -288,7 +288,7 @@ export class DefaultViewer extends AbstractViewer {
                 }
             }
             this.scene.registerBeforeRender(updateFlashlightFunction);
-            this.registeredOnBeforerenderFunctions.push(updateFlashlightFunction);
+            this._registeredOnBeforerenderFunctions.push(updateFlashlightFunction);
         }
     }
 }

+ 100 - 100
Viewer/src/viewer/viewer.ts

@@ -27,13 +27,13 @@ export abstract class AbstractViewer {
     public lastUsedLoader: ISceneLoaderPlugin | ISceneLoaderPluginAsync;
     public modelLoader: ModelLoader;
 
-    protected configuration: ViewerConfiguration;
+    protected _configuration: ViewerConfiguration;
     public environmentHelper: EnvironmentHelper;
 
-    protected defaultHighpTextureType: number;
-    protected shadowGeneratorBias: number;
-    protected defaultPipelineTextureType: number;
-    protected maxShadows: number;
+    protected _defaultHighpTextureType: number;
+    protected _shadowGeneratorBias: number;
+    protected _defaultPipelineTextureType: number;
+    protected _maxShadows: number;
     private _hdrSupport: boolean;
 
     protected _isDisposed: boolean = false;
@@ -54,7 +54,7 @@ export abstract class AbstractViewer {
 
     public canvas: HTMLCanvasElement;
 
-    protected registeredOnBeforerenderFunctions: Array<() => void>;
+    protected _registeredOnBeforerenderFunctions: Array<() => void>;
     protected _configurationLoader: ConfigurationLoader;
 
     constructor(public containerElement: HTMLElement, initialConfiguration: ViewerConfiguration = {}) {
@@ -73,7 +73,7 @@ export abstract class AbstractViewer {
         this.onInitDoneObservable = new Observable();
         this.onLoaderInitObservable = new Observable();
 
-        this.registeredOnBeforerenderFunctions = [];
+        this._registeredOnBeforerenderFunctions = [];
         this.models = [];
         this.modelLoader = new ModelLoader(this);
 
@@ -83,19 +83,19 @@ export abstract class AbstractViewer {
         // create a new template manager. TODO - singleton?
         this.templateManager = new TemplateManager(containerElement);
 
-        this.prepareContainerElement();
+        this._prepareContainerElement();
 
         // extend the configuration
         this._configurationLoader = new ConfigurationLoader();
         this._configurationLoader.loadConfiguration(initialConfiguration, (configuration) => {
-            this.configuration = deepmerge(this.configuration || {}, configuration);
-            if (this.configuration.observers) {
-                this.configureObservers(this.configuration.observers);
+            this._configuration = deepmerge(this._configuration || {}, configuration);
+            if (this._configuration.observers) {
+                this._configureObservers(this._configuration.observers);
             }
             //this.updateConfiguration(configuration);
 
             // initialize the templates
-            let templateConfiguration = this.configuration.templates || {};
+            let templateConfiguration = this._configuration.templates || {};
             this.templateManager.initTemplate(templateConfiguration);
             // when done, execute onTemplatesLoaded()
             this.templateManager.onAllLoaded.add(() => {
@@ -119,7 +119,7 @@ export abstract class AbstractViewer {
         return !!this.canvas && !!this.canvas.parentElement;
     }
 
-    protected resize = (): void => {
+    protected _resize = (): void => {
         // Only resize if Canvas is in the DOM
         if (!this.isCanvasInDOM()) {
             return;
@@ -132,7 +132,7 @@ export abstract class AbstractViewer {
         this.engine.resize();
     }
 
-    protected render = (): void => {
+    protected _render = (): void => {
         this.scene && this.scene.activeCamera && this.scene.render();
     }
 
@@ -143,46 +143,46 @@ export abstract class AbstractViewer {
      * and the entire configuration will be updated. 
      * @param newConfiguration 
      */
-    public updateConfiguration(newConfiguration: Partial<ViewerConfiguration> = this.configuration) {
+    public updateConfiguration(newConfiguration: Partial<ViewerConfiguration> = this._configuration) {
         // update this.configuration with the new data
-        this.configuration = deepmerge(this.configuration || {}, newConfiguration);
+        this._configuration = deepmerge(this._configuration || {}, newConfiguration);
 
         // update scene configuration
         if (newConfiguration.scene) {
-            this.configureScene(newConfiguration.scene);
+            this._configureScene(newConfiguration.scene);
         }
         // optimizer
         if (newConfiguration.optimizer) {
-            this.configureOptimizer(newConfiguration.optimizer);
+            this._configureOptimizer(newConfiguration.optimizer);
         }
 
         // observers in configuration
         if (newConfiguration.observers) {
-            this.configureObservers(newConfiguration.observers);
+            this._configureObservers(newConfiguration.observers);
         }
 
         // configure model
         if (newConfiguration.model && typeof newConfiguration.model === 'object') {
-            this.configureModel(newConfiguration.model);
+            this._configureModel(newConfiguration.model);
         }
 
         // lights
         if (newConfiguration.lights) {
-            this.configureLights(newConfiguration.lights);
+            this._configureLights(newConfiguration.lights);
         }
 
         // environment
         if (newConfiguration.skybox !== undefined || newConfiguration.ground !== undefined) {
-            this.configureEnvironment(newConfiguration.skybox, newConfiguration.ground);
+            this._configureEnvironment(newConfiguration.skybox, newConfiguration.ground);
         }
 
         // camera
         if (newConfiguration.camera) {
-            this.configureCamera(newConfiguration.camera);
+            this._configureCamera(newConfiguration.camera);
         }
     }
 
-    protected configureEnvironment(skyboxConifguration?: ISkyboxConfiguration | boolean, groundConfiguration?: IGroundConfiguration | boolean) {
+    protected _configureEnvironment(skyboxConifguration?: ISkyboxConfiguration | boolean, groundConfiguration?: IGroundConfiguration | boolean) {
         if (!skyboxConifguration && !groundConfiguration) {
             if (this.environmentHelper) {
                 this.environmentHelper.dispose();
@@ -235,8 +235,8 @@ export abstract class AbstractViewer {
                         options.groundMirrorFresnelWeight = groundConfig.mirror.fresnelWeight;
                     if (groundConfig.mirror.fallOffDistance !== undefined)
                         options.groundMirrorFallOffDistance = groundConfig.mirror.fallOffDistance;
-                    if (this.defaultPipelineTextureType !== undefined)
-                        options.groundMirrorTextureType = this.defaultPipelineTextureType;
+                    if (this._defaultPipelineTextureType !== undefined)
+                        options.groundMirrorTextureType = this._defaultPipelineTextureType;
                 }
             }
 
@@ -292,13 +292,13 @@ export abstract class AbstractViewer {
             let skyboxMaterial = this.environmentHelper.skyboxMaterial;
             if (skyboxMaterial) {
                 if (typeof skyboxConifguration === 'object' && skyboxConifguration.material && skyboxConifguration.material.imageProcessingConfiguration) {
-                    this.extendClassWithConfig(skyboxMaterial.imageProcessingConfiguration, skyboxConifguration.material.imageProcessingConfiguration);
+                    this._extendClassWithConfig(skyboxMaterial.imageProcessingConfiguration, skyboxConifguration.material.imageProcessingConfiguration);
                 }
             }
         }
     }
 
-    protected configureScene(sceneConfig: ISceneConfiguration, optimizerConfig?: ISceneOptimizerConfiguration) {
+    protected _configureScene(sceneConfig: ISceneConfiguration, optimizerConfig?: ISceneOptimizerConfiguration) {
         // sanity check!
         if (!this.scene) {
             return;
@@ -330,7 +330,7 @@ export abstract class AbstractViewer {
 
         // image processing configuration - optional.
         if (sceneConfig.imageProcessingConfiguration) {
-            this.extendClassWithConfig(this.scene.imageProcessingConfiguration, sceneConfig.imageProcessingConfiguration);
+            this._extendClassWithConfig(this.scene.imageProcessingConfiguration, sceneConfig.imageProcessingConfiguration);
         }
         if (sceneConfig.environmentTexture) {
             if (this.scene.environmentTexture) {
@@ -345,7 +345,7 @@ export abstract class AbstractViewer {
         }
     }
 
-    protected configureOptimizer(optimizerConfig: ISceneOptimizerConfiguration | boolean) {
+    protected _configureOptimizer(optimizerConfig: ISceneOptimizerConfiguration | boolean) {
         if (typeof optimizerConfig === 'boolean') {
             if (this.sceneOptimizer) {
                 this.sceneOptimizer.stop();
@@ -381,31 +381,31 @@ export abstract class AbstractViewer {
         }
     }
 
-    protected configureObservers(observersConfiguration: IObserversConfiguration) {
+    protected _configureObservers(observersConfiguration: IObserversConfiguration) {
         if (observersConfiguration.onEngineInit) {
             this.onEngineInitObservable.add(window[observersConfiguration.onEngineInit]);
         } else {
-            if (observersConfiguration.onEngineInit === '' && this.configuration.observers && this.configuration.observers!.onEngineInit) {
-                this.onEngineInitObservable.removeCallback(window[this.configuration.observers!.onEngineInit!]);
+            if (observersConfiguration.onEngineInit === '' && this._configuration.observers && this._configuration.observers!.onEngineInit) {
+                this.onEngineInitObservable.removeCallback(window[this._configuration.observers!.onEngineInit!]);
             }
         }
         if (observersConfiguration.onSceneInit) {
             this.onSceneInitObservable.add(window[observersConfiguration.onSceneInit]);
         } else {
-            if (observersConfiguration.onSceneInit === '' && this.configuration.observers && this.configuration.observers!.onSceneInit) {
-                this.onSceneInitObservable.removeCallback(window[this.configuration.observers!.onSceneInit!]);
+            if (observersConfiguration.onSceneInit === '' && this._configuration.observers && this._configuration.observers!.onSceneInit) {
+                this.onSceneInitObservable.removeCallback(window[this._configuration.observers!.onSceneInit!]);
             }
         }
         if (observersConfiguration.onModelLoaded) {
             this.onModelLoadedObservable.add(window[observersConfiguration.onModelLoaded]);
         } else {
-            if (observersConfiguration.onModelLoaded === '' && this.configuration.observers && this.configuration.observers!.onModelLoaded) {
-                this.onModelLoadedObservable.removeCallback(window[this.configuration.observers!.onModelLoaded!]);
+            if (observersConfiguration.onModelLoaded === '' && this._configuration.observers && this._configuration.observers!.onModelLoaded) {
+                this.onModelLoadedObservable.removeCallback(window[this._configuration.observers!.onModelLoaded!]);
             }
         }
     }
 
-    protected configureCamera(cameraConfig: ICameraConfiguration, model?: ViewerModel) {
+    protected _configureCamera(cameraConfig: ICameraConfiguration, model?: ViewerModel) {
         let focusMeshes = model ? model.meshes : this.scene.meshes;
 
         if (!this.scene.activeCamera) {
@@ -420,14 +420,14 @@ export abstract class AbstractViewer {
             this.camera.rotationQuaternion = new Quaternion(cameraConfig.rotation.x || 0, cameraConfig.rotation.y || 0, cameraConfig.rotation.z || 0, cameraConfig.rotation.w || 0)
         }
 
-        this.extendClassWithConfig(this.camera, cameraConfig);
+        this._extendClassWithConfig(this.camera, cameraConfig);
 
         this.camera.minZ = cameraConfig.minZ || this.camera.minZ;
         this.camera.maxZ = cameraConfig.maxZ || this.camera.maxZ;
 
         if (cameraConfig.behaviors) {
             for (let name in cameraConfig.behaviors) {
-                this.setCameraBehavior(cameraConfig.behaviors[name], focusMeshes);
+                this._setCameraBehavior(cameraConfig.behaviors[name], focusMeshes);
             }
         };
 
@@ -440,14 +440,14 @@ export abstract class AbstractViewer {
             this.camera.upperRadiusLimit = sceneDiagonalLenght * 3;
     }
 
-    protected configureLights(lightsConfiguration: { [name: string]: ILightConfiguration | boolean } = {}, model?: ViewerModel) {
+    protected _configureLights(lightsConfiguration: { [name: string]: ILightConfiguration | boolean } = {}, model?: ViewerModel) {
         let focusMeshes = model ? model.meshes : this.scene.meshes;
         // sanity check!
         if (!Object.keys(lightsConfiguration).length) return;
 
         let lightsAvailable: Array<string> = this.scene.lights.map(light => light.name);
         // compare to the global (!) configuration object and dispose unneeded:
-        let lightsToConfigure = Object.keys(this.configuration.lights || []);
+        let lightsToConfigure = Object.keys(this._configuration.lights || []);
         if (Object.keys(lightsToConfigure).length !== lightsAvailable.length) {
             lightsAvailable.forEach(lName => {
                 if (lightsToConfigure.indexOf(lName) === -1) {
@@ -493,7 +493,7 @@ export abstract class AbstractViewer {
             light.setEnabled(enabled);
 
 
-            this.extendClassWithConfig(light, lightConfig);
+            this._extendClassWithConfig(light, lightConfig);
 
             //position. Some lights don't support shadows
             if (light instanceof ShadowLight) {
@@ -507,12 +507,12 @@ export abstract class AbstractViewer {
                     light.direction = direction;
                 }
                 let shadowGenerator = light.getShadowGenerator();
-                if (lightConfig.shadowEnabled && this.maxShadows) {
+                if (lightConfig.shadowEnabled && this._maxShadows) {
                     if (!shadowGenerator) {
                         shadowGenerator = new ShadowGenerator(512, light);
                         // TODO blur kernel definition
                     }
-                    this.extendClassWithConfig(shadowGenerator, lightConfig.shadowConfig || {});
+                    this._extendClassWithConfig(shadowGenerator, lightConfig.shadowConfig || {});
                     // add the focues meshes to the shadow list
                     let shadownMap = shadowGenerator.getShadowMap();
                     if (!shadownMap) return;
@@ -529,7 +529,7 @@ export abstract class AbstractViewer {
         });
     }
 
-    protected configureModel(modelConfiguration: Partial<IModelConfiguration>, model?: ViewerModel) {
+    protected _configureModel(modelConfiguration: Partial<IModelConfiguration>, model?: ViewerModel) {
         this.models.forEach(model => {
             model.configuration = modelConfiguration;
         })
@@ -539,7 +539,7 @@ export abstract class AbstractViewer {
         if (this._isDisposed) {
             return;
         }
-        window.removeEventListener('resize', this.resize);
+        window.removeEventListener('resize', this._resize);
         if (this.sceneOptimizer) {
             this.sceneOptimizer.stop();
             this.sceneOptimizer.dispose();
@@ -589,7 +589,7 @@ export abstract class AbstractViewer {
         this._isDisposed = true;
     }
 
-    protected abstract prepareContainerElement();
+    protected abstract _prepareContainerElement();
 
     /**
      * This function will execute when the HTML templates finished initializing.
@@ -599,7 +599,7 @@ export abstract class AbstractViewer {
      * @returns {Promise<AbstractViewer>} The viewer object will be returned after the object was loaded.
      * @memberof AbstractViewer
      */
-    protected onTemplatesLoaded(): Promise<AbstractViewer> {
+    protected _onTemplatesLoaded(): Promise<AbstractViewer> {
         return Promise.resolve(this);
     }
 
@@ -609,15 +609,15 @@ export abstract class AbstractViewer {
      * But first - it will load the extendible onTemplateLoaded()!
      */
     private _onTemplateLoaded(): Promise<AbstractViewer> {
-        return this.onTemplatesLoaded().then(() => {
-            let autoLoadModel = this.configuration.model;
-            return this.initEngine().then((engine) => {
+        return this._onTemplatesLoaded().then(() => {
+            let autoLoadModel = this._configuration.model;
+            return this._initEngine().then((engine) => {
                 return this.onEngineInitObservable.notifyObserversWithPromise(engine);
             }).then(() => {
                 if (autoLoadModel) {
                     return this.loadModel().catch(e => { }).then(() => { return this.scene });
                 } else {
-                    return this.scene || this.initScene();
+                    return this.scene || this._initScene();
                 }
             }).then((scene) => {
                 return this.onSceneInitObservable.notifyObserversWithPromise(scene);
@@ -637,16 +637,16 @@ export abstract class AbstractViewer {
      * @returns {Promise<Engine>} 
      * @memberof Viewer
      */
-    protected initEngine(): Promise<Engine> {
+    protected _initEngine(): Promise<Engine> {
 
         // init custom shaders
-        this.injectCustomShaders();
+        this._injectCustomShaders();
 
         let canvasElement = this.templateManager.getCanvas();
         if (!canvasElement) {
             return Promise.reject('Canvas element not found!');
         }
-        let config = this.configuration.engine || {};
+        let config = this._configuration.engine || {};
         // TDO enable further configuration
         this.engine = new Engine(canvasElement, !!config.antialiasing, config.engineOptions);
 
@@ -654,24 +654,24 @@ export abstract class AbstractViewer {
         Database.IDBStorageEnabled = false;
 
         if (!config.disableResize) {
-            window.addEventListener('resize', this.resize);
+            window.addEventListener('resize', this._resize);
         }
 
 
-        this.engine.runRenderLoop(this.render);
+        this.engine.runRenderLoop(this._render);
 
-        if (this.configuration.engine && this.configuration.engine.adaptiveQuality) {
+        if (this._configuration.engine && this._configuration.engine.adaptiveQuality) {
             var scale = Math.max(0.5, 1 / (window.devicePixelRatio || 2));
             this.engine.setHardwareScalingLevel(scale);
         }
 
         // set hardware limitations for scene initialization
-        this.handleHardwareLimitations();
+        this._handleHardwareLimitations();
 
         return Promise.resolve(this.engine);
     }
 
-    protected initScene(): Promise<Scene> {
+    protected _initScene(): Promise<Scene> {
 
         // if the scen exists, dispose it.
         if (this.scene) {
@@ -683,22 +683,22 @@ export abstract class AbstractViewer {
         // make sure there is a default camera and light.
         this.scene.createDefaultLight(true);
 
-        if (this.configuration.scene) {
-            this.configureScene(this.configuration.scene);
+        if (this._configuration.scene) {
+            this._configureScene(this._configuration.scene);
 
             // Scene optimizer
-            if (this.configuration.optimizer) {
-                this.configureOptimizer(this.configuration.optimizer);
+            if (this._configuration.optimizer) {
+                this._configureOptimizer(this._configuration.optimizer);
             }
         }
 
         return Promise.resolve(this.scene);
     }
 
-    private isLoading: boolean;
-    private nextLoading: Function;
+    private _isLoading: boolean;
+    private _nextLoading: Function;
 
-    public initModel(modelConfig: any = this.configuration.model, clearScene: boolean = true): ViewerModel {
+    public initModel(modelConfig: any = this._configuration.model, clearScene: boolean = true): ViewerModel {
         let model = this.modelLoader.load(modelConfig);
 
         if (clearScene) {
@@ -719,14 +719,14 @@ export abstract class AbstractViewer {
         model.onLoadedObservable.add(() => {
             this.onModelLoadedObservable.notifyObserversWithPromise(model)
                 .then(() => {
-                    this.configureLights(this.configuration.lights);
+                    this._configureLights(this._configuration.lights);
 
-                    if (this.configuration.camera) {
-                        this.configureCamera(this.configuration.camera, model);
+                    if (this._configuration.camera) {
+                        this._configureCamera(this._configuration.camera, model);
                     }
-                    return this.initEnvironment(model);
+                    return this._initEnvironment(model);
                 }).then(() => {
-                    this.isLoading = false;
+                    this._isLoading = false;
                     return model;
                 });
         });
@@ -735,31 +735,31 @@ export abstract class AbstractViewer {
         return model;
     }
 
-    public loadModel(modelConfig: any = this.configuration.model, clearScene: boolean = true): Promise<ViewerModel> {
+    public loadModel(modelConfig: any = this._configuration.model, clearScene: boolean = true): Promise<ViewerModel> {
         // no model was provided? Do nothing!
         let modelUrl = (typeof modelConfig === 'string') ? modelConfig : modelConfig.url;
         if (!modelUrl) {
             return Promise.reject("no model configuration found");
         }
-        if (this.isLoading) {
+        if (this._isLoading) {
             // We can decide here whether or not to cancel the lst load, but the developer can do that.
             return Promise.reject("another model is curently being loaded.");
         }
-        this.isLoading = true;
+        this._isLoading = true;
         if ((typeof modelConfig === 'string')) {
-            if (this.configuration.model && typeof this.configuration.model === 'object') {
-                this.configuration.model.url = modelConfig;
+            if (this._configuration.model && typeof this._configuration.model === 'object') {
+                this._configuration.model.url = modelConfig;
             }
         } else {
-            if (this.configuration.model) {
-                deepmerge(this.configuration.model, modelConfig)
+            if (this._configuration.model) {
+                deepmerge(this._configuration.model, modelConfig)
             } else {
-                this.configuration.model = modelConfig;
+                this._configuration.model = modelConfig;
             }
         }
 
         return Promise.resolve(this.scene).then((scene) => {
-            if (!scene) return this.initScene();
+            if (!scene) return this._initScene();
             return scene;
         }).then(() => {
             return new Promise<ViewerModel>((resolve, reject) => {
@@ -769,8 +769,8 @@ export abstract class AbstractViewer {
         })
     }
 
-    protected initEnvironment(model?: ViewerModel): Promise<Scene> {
-        this.configureEnvironment(this.configuration.skybox, this.configuration.ground);
+    protected _initEnvironment(model?: ViewerModel): Promise<Scene> {
+        this._configureEnvironment(this._configuration.skybox, this._configuration.ground);
 
         return Promise.resolve(this.scene);
     }
@@ -779,16 +779,16 @@ export abstract class AbstractViewer {
 		 * Alters render settings to reduce features based on hardware feature limitations
 		 * @param options Viewer options to modify
 		 */
-    protected handleHardwareLimitations() {
+    protected _handleHardwareLimitations() {
         //flip rendering settings switches based on hardware support
         let maxVaryingRows = this.engine.getCaps().maxVaryingVectors;
         let maxFragmentSamplers = this.engine.getCaps().maxTexturesImageUnits;
 
         //shadows are disabled if there's not enough varyings for a single shadow
         if ((maxVaryingRows < 8) || (maxFragmentSamplers < 8)) {
-            this.maxShadows = 0;
+            this._maxShadows = 0;
         } else {
-            this.maxShadows = 3;
+            this._maxShadows = 3;
         }
 
         //can we render to any >= 16-bit targets (required for HDR)
@@ -799,24 +799,24 @@ export abstract class AbstractViewer {
         this._hdrSupport = !!(linearFloatTargets || linearHalfFloatTargets);
 
         if (linearHalfFloatTargets) {
-            this.defaultHighpTextureType = Engine.TEXTURETYPE_HALF_FLOAT;
-            this.shadowGeneratorBias = 0.002;
+            this._defaultHighpTextureType = Engine.TEXTURETYPE_HALF_FLOAT;
+            this._shadowGeneratorBias = 0.002;
         } else if (linearFloatTargets) {
-            this.defaultHighpTextureType = Engine.TEXTURETYPE_FLOAT;
-            this.shadowGeneratorBias = 0.001;
+            this._defaultHighpTextureType = Engine.TEXTURETYPE_FLOAT;
+            this._shadowGeneratorBias = 0.001;
         } else {
-            this.defaultHighpTextureType = Engine.TEXTURETYPE_UNSIGNED_INT;
-            this.shadowGeneratorBias = 0.001;
+            this._defaultHighpTextureType = Engine.TEXTURETYPE_UNSIGNED_INT;
+            this._shadowGeneratorBias = 0.001;
         }
 
-        this.defaultPipelineTextureType = this._hdrSupport ? this.defaultHighpTextureType : Engine.TEXTURETYPE_UNSIGNED_INT;
+        this._defaultPipelineTextureType = this._hdrSupport ? this._defaultHighpTextureType : Engine.TEXTURETYPE_UNSIGNED_INT;
     }
 
     /**
      * Injects all the spectre shader in the babylon shader store
      */
-    protected injectCustomShaders(): void {
-        let customShaders = this.configuration.customShaders;
+    protected _injectCustomShaders(): void {
+        let customShaders = this._configuration.customShaders;
         // Inject all the spectre shader in the babylon shader store.
         if (!customShaders) {
             return;
@@ -835,14 +835,14 @@ export abstract class AbstractViewer {
         }
     }
 
-    protected extendClassWithConfig(object: any, config: any) {
+    protected _extendClassWithConfig(object: any, config: any) {
         if (!config) return;
         Object.keys(config).forEach(key => {
             if (key in object && typeof object[key] !== 'function') {
                 // if (typeof object[key] === 'function') return;
                 // if it is an object, iterate internally until reaching basic types
                 if (typeof object[key] === 'object') {
-                    this.extendClassWithConfig(object[key], config[key]);
+                    this._extendClassWithConfig(object[key], config[key]);
                 } else {
                     if (config[key] !== undefined) {
                         object[key] = config[key];
@@ -852,7 +852,7 @@ export abstract class AbstractViewer {
         });
     }
 
-    private setCameraBehavior(behaviorConfig: number | {
+    private _setCameraBehavior(behaviorConfig: number | {
         type: number;
         [propName: string]: any;
     }, payload: any) {
@@ -883,7 +883,7 @@ export abstract class AbstractViewer {
 
         if (behavior) {
             if (typeof behaviorConfig === "object") {
-                this.extendClassWithConfig(behavior, behaviorConfig);
+                this._extendClassWithConfig(behavior, behaviorConfig);
             }
         }
 

+ 9 - 9
Viewer/src/viewer/viewerManager.ts

@@ -3,36 +3,36 @@ import { AbstractViewer } from './viewer';
 
 export class ViewerManager {
 
-    private viewers: { [key: string]: AbstractViewer };
+    private _viewers: { [key: string]: AbstractViewer };
 
     public onViewerAdded: (viewer: AbstractViewer) => void;
     public onViewerAddedObservable: Observable<AbstractViewer>;
     public onViewerRemovedObservable: Observable<string>;
 
     constructor() {
-        this.viewers = {};
+        this._viewers = {};
         this.onViewerAddedObservable = new Observable();
         this.onViewerRemovedObservable = new Observable();
     }
 
     public addViewer(viewer: AbstractViewer) {
-        this.viewers[viewer.getBaseId()] = viewer;
+        this._viewers[viewer.getBaseId()] = viewer;
         this._onViewerAdded(viewer);
     }
 
     public removeViewer(viewer: AbstractViewer) {
         let id = viewer.getBaseId();
-        delete this.viewers[id];
+        delete this._viewers[id];
         this.onViewerRemovedObservable.notifyObservers(id);
     }
 
     public getViewerById(id: string): AbstractViewer {
-        return this.viewers[id];
+        return this._viewers[id];
     }
 
     public getViewerByHTMLElement(element: HTMLElement) {
-        for (let id in this.viewers) {
-            if (this.viewers[id].containerElement === element) {
+        for (let id in this._viewers) {
+            if (this._viewers[id].containerElement === element) {
                 return this.getViewerById(id);
             }
         }
@@ -60,8 +60,8 @@ export class ViewerManager {
     }
 
     public dispose() {
-        for (let id in this.viewers) {
-            this.viewers[id].dispose();
+        for (let id in this._viewers) {
+            this._viewers[id].dispose();
         }
     }
 }