فهرست منبع

fixing APIs and module separation

Raanan Weber 7 سال پیش
والد
کامیت
95b12bbc0c

+ 1 - 1
Viewer/src/index.ts

@@ -19,7 +19,7 @@ import * as BABYLON from 'babylonjs';
 
 
 // load needed modules.
 // load needed modules.
 import 'babylonjs-loaders';
 import 'babylonjs-loaders';
-import 'pep';
+import 'pepjs';
 
 
 import { initListeners, InitTags } from './initializer';
 import { initListeners, InitTags } from './initializer';
 
 

+ 19 - 18
Viewer/src/managers/sceneManager.ts

@@ -6,6 +6,7 @@ import { CameraBehavior } from '../interfaces';
 import { ViewerLabs } from '../labs/viewerLabs';
 import { ViewerLabs } from '../labs/viewerLabs';
 import { getCustomOptimizerByName } from '../optimizer/custom/';
 import { getCustomOptimizerByName } from '../optimizer/custom/';
 import { ObservablesManager } from '../managers/observablesManager';
 import { ObservablesManager } from '../managers/observablesManager';
+import { ConfigurationContainer } from 'configuration/configurationContainer';
 
 
 /**
 /**
  * This interface describes the structure of the variable sent with the configuration observables of the scene manager.
  * This interface describes the structure of the variable sent with the configuration observables of the scene manager.
@@ -89,8 +90,6 @@ export class SceneManager {
      */
      */
     private _hdrSupport: boolean;
     private _hdrSupport: boolean;
 
 
-    private _mainColor: Color3 = Color3.White();
-    private _reflectionColor = Color3.White();
     private readonly _white = Color3.White();
     private readonly _white = Color3.White();
 
 
     private _forceShadowUpdate: boolean = false;
     private _forceShadowUpdate: boolean = false;
@@ -107,7 +106,7 @@ export class SceneManager {
         return this._defaultRenderingPipeline;
         return this._defaultRenderingPipeline;
     }
     }
 
 
-    constructor(private _engine: Engine, private _observablesManager?: ObservablesManager) {
+    constructor(private _engine: Engine, private _configurationContainer: ConfigurationContainer, private _observablesManager?: ObservablesManager) {
         this.models = [];
         this.models = [];
 
 
         this.onCameraConfiguredObservable = new Observable();
         this.onCameraConfiguredObservable = new Observable();
@@ -193,11 +192,11 @@ export class SceneManager {
      * Return the main color defined in the configuration.
      * Return the main color defined in the configuration.
      */
      */
     public get mainColor(): Color3 {
     public get mainColor(): Color3 {
-        return this._mainColor;
+        return this._configurationContainer.mainColor;
     }
     }
 
 
     public get reflectionColor(): Color3 {
     public get reflectionColor(): Color3 {
-        return this._reflectionColor;
+        return this._configurationContainer.reflectionColor;
     }
     }
 
 
     public get animationBlendingEnabled() {
     public get animationBlendingEnabled() {
@@ -356,8 +355,6 @@ export class SceneManager {
 
 
         Animation.AllowMatricesInterpolation = true;
         Animation.AllowMatricesInterpolation = true;
 
 
-        this._mainColor = Color3.White();
-
         /*if (sceneConfiguration.glow) {
         /*if (sceneConfiguration.glow) {
             let options: Partial<IGlowLayerOptions> = {
             let options: Partial<IGlowLayerOptions> = {
                 mainTextureFixedSize: 512
                 mainTextureFixedSize: 512
@@ -388,9 +385,13 @@ export class SceneManager {
      * @param newConfiguration the delta that should be configured. This includes only the changes
      * @param newConfiguration the delta that should be configured. This includes only the changes
      * @param globalConfiguration The global configuration object, after the new configuration was merged into it
      * @param globalConfiguration The global configuration object, after the new configuration was merged into it
      */
      */
-    public updateConfiguration(newConfiguration: Partial<ViewerConfiguration>, globalConfiguration: ViewerConfiguration) {
+    public updateConfiguration(newConfiguration: Partial<ViewerConfiguration>) {
 
 
-        this._globalConfiguration = globalConfiguration;
+        if (this._configurationContainer) {
+            this._globalConfiguration = this._configurationContainer.configuration;
+        } else {
+            this._globalConfiguration = newConfiguration;
+        }
 
 
         if (newConfiguration.lab) {
         if (newConfiguration.lab) {
             if (newConfiguration.lab.assetsRootURL) {
             if (newConfiguration.lab.assetsRootURL) {
@@ -632,28 +633,28 @@ export class SceneManager {
 
 
         // process mainColor changes:
         // process mainColor changes:
         if (sceneConfig.mainColor) {
         if (sceneConfig.mainColor) {
-            this._mainColor = this._mainColor || Color3.White();
+            this._configurationContainer.mainColor = this.mainColor || Color3.White();
             let mc = sceneConfig.mainColor;
             let mc = sceneConfig.mainColor;
             if (mc.r !== undefined) {
             if (mc.r !== undefined) {
-                this._mainColor.r = mc.r;
+                this.mainColor.r = mc.r;
             }
             }
             if (mc.g !== undefined) {
             if (mc.g !== undefined) {
-                this._mainColor.g = mc.g
+                this.mainColor.g = mc.g
             }
             }
             if (mc.b !== undefined) {
             if (mc.b !== undefined) {
-                this._mainColor.b = mc.b
+                this.mainColor.b = mc.b
             }
             }
 
 
-            this._reflectionColor.copyFrom(this.mainColor);
+            this.reflectionColor.copyFrom(this.mainColor);
 
 
 
 
             let environmentTint = getConfigurationKey("lab.environmentMap.tintLevel", this._globalConfiguration) || 0;
             let environmentTint = getConfigurationKey("lab.environmentMap.tintLevel", this._globalConfiguration) || 0;
 
 
             // reflection color
             // reflection color
-            this._reflectionColor.toLinearSpaceToRef(this._reflectionColor);
-            this._reflectionColor.scaleToRef(1 / this.scene.imageProcessingConfiguration.exposure, this._reflectionColor);
-            let tmpColor3 = Color3.Lerp(this._white, this._reflectionColor, environmentTint);
-            this._reflectionColor.copyFrom(tmpColor3);
+            this.reflectionColor.toLinearSpaceToRef(this.reflectionColor);
+            this.reflectionColor.scaleToRef(1 / this.scene.imageProcessingConfiguration.exposure, this.reflectionColor);
+            let tmpColor3 = Color3.Lerp(this._white, this.reflectionColor, environmentTint);
+            this.reflectionColor.copyFrom(tmpColor3);
 
 
             //update the environment, if exists
             //update the environment, if exists
             if (this.environmentHelper) {
             if (this.environmentHelper) {

+ 343 - 0
Viewer/src/templating/handlebars.d.ts

@@ -0,0 +1,343 @@
+// Type definitions for Handlebars v4.0.11
+// Project: http://handlebarsjs.com/
+// Definitions by: Boris Yankov <https://github.com/borisyankov>, Sergei Dorogin <https://github.com/evil-shrike>
+// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
+// TypeScript Version: 2.3
+
+declare namespace Handlebars {
+    export interface TemplateDelegate<T = any> {
+        (context: T, options?: RuntimeOptions): string;
+    }
+
+    export type Template<T = any> = TemplateDelegate<T> | string;
+
+    export interface RuntimeOptions {
+        partial?: boolean;
+        depths?: any[];
+        helpers?: { [name: string]: Function };
+        partials?: { [name: string]: HandlebarsTemplateDelegate };
+        decorators?: { [name: string]: Function };
+        data?: any;
+        blockParams?: any[];
+    }
+
+    export interface HelperOptions {
+        fn: TemplateDelegate;
+        inverse: TemplateDelegate;
+        hash: any;
+        data?: any;
+    }
+
+    export interface HelperDelegate {
+        (context?: any, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, options?: HelperOptions): any;
+    }
+    export interface HelperDeclareSpec {
+        [key: string]: HelperDelegate;
+    }
+
+    export function registerHelper(name: string, fn: HelperDelegate): void;
+    export function registerHelper(name: HelperDeclareSpec): void;
+    export function unregisterHelper(name: string): void;
+
+    export function registerPartial(name: string, fn: Template): void;
+    export function unregisterPartial(name: string): void;
+
+    // TODO: replace Function with actual signature
+    export function registerDecorator(name: string, fn: Function): void;
+    export function unregisterDecorator(name: string): void;
+
+    export function K(): void;
+    export function createFrame(object: any): any;
+    export function blockParams(obj: any[], ids: any[]): any[];
+    export function Exception(message: string): void;
+    export function log(level: number, obj: any): void;
+    export function parse(input: string): hbs.AST.Program;
+    export function compile<T = any>(input: any, options?: CompileOptions): HandlebarsTemplateDelegate<T>;
+    export function precompile(input: any, options?: PrecompileOptions): TemplateSpecification;
+    export function template<T = any>(precompilation: TemplateSpecification): HandlebarsTemplateDelegate<T>;
+
+    export function create(): typeof Handlebars;
+
+    export const escapeExpression: typeof Utils.escapeExpression;
+    //export const Utils: typeof hbs.Utils;
+    export const logger: Logger;
+    export const templates: HandlebarsTemplates;
+    export const helpers: { [name: string]: HelperDelegate };
+    export const partials: { [name: string]: any };
+    // TODO: replace Function with actual signature
+    export const decorators: { [name: string]: Function };
+
+    export function noConflict(): typeof Handlebars;
+
+    export class SafeString {
+        constructor(str: string);
+        toString(): string;
+        toHTML(): string;
+    }
+
+    export namespace Utils {
+        export function escapeExpression(str: string): string;
+        export function createFrame(object: any): any;
+        export function blockParams(obj: any[], ids: any[]): any[];
+        export function isEmpty(obj: any): boolean;
+        export function extend(obj: any, ...source: any[]): any;
+        export function toString(obj: any): string;
+        export function isArray(obj: any): boolean;
+        export function isFunction(obj: any): boolean;
+    }
+
+    export namespace AST {
+        export const helpers: hbs.AST.helpers;
+    }
+
+    interface ICompiler {
+        accept(node: hbs.AST.Node): void;
+        Program(program: hbs.AST.Program): void;
+        BlockStatement(block: hbs.AST.BlockStatement): void;
+        PartialStatement(partial: hbs.AST.PartialStatement): void;
+        PartialBlockStatement(partial: hbs.AST.PartialBlockStatement): void;
+        DecoratorBlock(decorator: hbs.AST.DecoratorBlock): void;
+        Decorator(decorator: hbs.AST.Decorator): void;
+        MustacheStatement(mustache: hbs.AST.MustacheStatement): void;
+        ContentStatement(content: hbs.AST.ContentStatement): void;
+        CommentStatement(comment?: hbs.AST.CommentStatement): void;
+        SubExpression(sexpr: hbs.AST.SubExpression): void;
+        PathExpression(path: hbs.AST.PathExpression): void;
+        StringLiteral(str: hbs.AST.StringLiteral): void;
+        NumberLiteral(num: hbs.AST.NumberLiteral): void;
+        BooleanLiteral(bool: hbs.AST.BooleanLiteral): void;
+        UndefinedLiteral(): void;
+        NullLiteral(): void;
+        Hash(hash: hbs.AST.Hash): void;
+    }
+
+    export class Visitor implements ICompiler {
+        accept(node: hbs.AST.Node): void;
+        acceptKey(node: hbs.AST.Node, name: string): void;
+        acceptArray(arr: hbs.AST.Expression[]): void;
+        Program(program: hbs.AST.Program): void;
+        BlockStatement(block: hbs.AST.BlockStatement): void;
+        PartialStatement(partial: hbs.AST.PartialStatement): void;
+        PartialBlockStatement(partial: hbs.AST.PartialBlockStatement): void;
+        DecoratorBlock(decorator: hbs.AST.DecoratorBlock): void;
+        Decorator(decorator: hbs.AST.Decorator): void;
+        MustacheStatement(mustache: hbs.AST.MustacheStatement): void;
+        ContentStatement(content: hbs.AST.ContentStatement): void;
+        CommentStatement(comment?: hbs.AST.CommentStatement): void;
+        SubExpression(sexpr: hbs.AST.SubExpression): void;
+        PathExpression(path: hbs.AST.PathExpression): void;
+        StringLiteral(str: hbs.AST.StringLiteral): void;
+        NumberLiteral(num: hbs.AST.NumberLiteral): void;
+        BooleanLiteral(bool: hbs.AST.BooleanLiteral): void;
+        UndefinedLiteral(): void;
+        NullLiteral(): void;
+        Hash(hash: hbs.AST.Hash): void;
+    }
+}
+
+/**
+* Implement this interface on your MVW/MVVM/MVC views such as Backbone.View
+**/
+interface HandlebarsTemplatable {
+    template: HandlebarsTemplateDelegate;
+}
+
+// NOTE: for backward compatibility of this typing
+type HandlebarsTemplateDelegate<T = any> = Handlebars.TemplateDelegate<T>;
+
+interface HandlebarsTemplates {
+    [index: string]: HandlebarsTemplateDelegate;
+}
+
+interface TemplateSpecification {
+
+}
+
+// for backward compatibility of this typing
+type RuntimeOptions = Handlebars.RuntimeOptions;
+
+interface CompileOptions {
+    data?: boolean;
+    compat?: boolean;
+    knownHelpers?: {
+        helperMissing?: boolean;
+        blockHelperMissing?: boolean;
+        each?: boolean;
+        if?: boolean;
+        unless?: boolean;
+        with?: boolean;
+        log?: boolean;
+        lookup?: boolean;
+    };
+    knownHelpersOnly?: boolean;
+    noEscape?: boolean;
+    strict?: boolean;
+    assumeObjects?: boolean;
+    preventIndent?: boolean;
+    ignoreStandalone?: boolean;
+    explicitPartialContext?: boolean;
+}
+
+interface PrecompileOptions extends CompileOptions {
+    srcName?: string;
+    destName?: string;
+}
+
+declare namespace hbs {
+    // for backward compatibility of this typing
+    type SafeString = Handlebars.SafeString;
+
+    type Utils = typeof Handlebars.Utils;
+}
+
+interface Logger {
+    DEBUG: number;
+    INFO: number;
+    WARN: number;
+    ERROR: number;
+    level: number;
+
+    methodMap: { [level: number]: string };
+
+    log(level: number, obj: string): void;
+}
+
+declare namespace hbs {
+    namespace AST {
+        interface Node {
+            type: string;
+            loc: SourceLocation;
+        }
+
+        interface SourceLocation {
+            source: string;
+            start: Position;
+            end: Position;
+        }
+
+        interface Position {
+            line: number;
+            column: number;
+        }
+
+        interface Program extends Node {
+            body: Statement[];
+            blockParams: string[];
+        }
+
+        interface Statement extends Node { }
+
+        interface MustacheStatement extends Statement {
+            path: PathExpression | Literal;
+            params: Expression[];
+            hash: Hash;
+            escaped: boolean;
+            strip: StripFlags;
+        }
+
+        interface Decorator extends MustacheStatement { }
+
+        interface BlockStatement extends Statement {
+            path: PathExpression;
+            params: Expression[];
+            hash: Hash;
+            program: Program;
+            inverse: Program;
+            openStrip: StripFlags;
+            inverseStrip: StripFlags;
+            closeStrip: StripFlags;
+        }
+
+        interface DecoratorBlock extends BlockStatement { }
+
+        interface PartialStatement extends Statement {
+            name: PathExpression | SubExpression;
+            params: Expression[];
+            hash: Hash;
+            indent: string;
+            strip: StripFlags;
+        }
+
+        interface PartialBlockStatement extends Statement {
+            name: PathExpression | SubExpression;
+            params: Expression[];
+            hash: Hash;
+            program: Program;
+            openStrip: StripFlags;
+            closeStrip: StripFlags;
+        }
+
+        interface ContentStatement extends Statement {
+            value: string;
+            original: StripFlags;
+        }
+
+        interface CommentStatement extends Statement {
+            value: string;
+            strip: StripFlags;
+        }
+
+        interface Expression extends Node { }
+
+        interface SubExpression extends Expression {
+            path: PathExpression;
+            params: Expression[];
+            hash: Hash;
+        }
+
+        interface PathExpression extends Expression {
+            data: boolean;
+            depth: number;
+            parts: string[];
+            original: string;
+        }
+
+        interface Literal extends Expression { }
+        interface StringLiteral extends Literal {
+            value: string;
+            original: string;
+        }
+
+        interface BooleanLiteral extends Literal {
+            value: boolean;
+            original: boolean;
+        }
+
+        interface NumberLiteral extends Literal {
+            value: number;
+            original: number;
+        }
+
+        interface UndefinedLiteral extends Literal { }
+
+        interface NullLiteral extends Literal { }
+
+        interface Hash extends Node {
+            pairs: HashPair[];
+        }
+
+        interface HashPair extends Node {
+            key: string;
+            value: Expression;
+        }
+
+        interface StripFlags {
+            open: boolean;
+            close: boolean;
+        }
+
+        interface helpers {
+            helperExpression(node: Node): boolean;
+            scopeId(path: PathExpression): boolean;
+            simpleId(path: PathExpression): boolean;
+        }
+    }
+}
+
+declare module "handlebars" {
+    export = Handlebars;
+}
+
+declare module "handlebars/runtime" {
+    export = Handlebars;
+}

+ 1 - 1
Viewer/src/templating/templateManager.ts

@@ -2,7 +2,7 @@
 import { Observable, IFileRequest, Tools } from 'babylonjs';
 import { Observable, IFileRequest, Tools } from 'babylonjs';
 import { isUrl, camelToKebab, kebabToCamel } from '../helper';
 import { isUrl, camelToKebab, kebabToCamel } from '../helper';
 
 
-import * as Handlebars from 'handlebars';
+import * as Handlebars from 'handlebars/runtime';
 import { EventManager } from './eventManager';
 import { EventManager } from './eventManager';
 import { ITemplateConfiguration } from '../configuration/interfaces';
 import { ITemplateConfiguration } from '../configuration/interfaces';
 import { deepmerge } from '../helper/';
 import { deepmerge } from '../helper/';

+ 6 - 3
Viewer/src/viewer/viewer.ts

@@ -160,6 +160,10 @@ export abstract class AbstractViewer {
 
 
     protected _configurationContainer: ConfigurationContainer;
     protected _configurationContainer: ConfigurationContainer;
 
 
+    public get configurationContainer() {
+        return this._configurationContainer;
+    }
+
     constructor(public containerElement: HTMLElement, initialConfiguration: ViewerConfiguration = {}) {
     constructor(public containerElement: HTMLElement, initialConfiguration: ViewerConfiguration = {}) {
         // if exists, use the container id. otherwise, generate a random string.
         // if exists, use the container id. otherwise, generate a random string.
         if (containerElement.id) {
         if (containerElement.id) {
@@ -347,7 +351,7 @@ export abstract class AbstractViewer {
         // update this.configuration with the new data
         // update this.configuration with the new data
         this._configurationContainer.configuration = deepmerge(this.configuration || {}, newConfiguration);
         this._configurationContainer.configuration = deepmerge(this.configuration || {}, newConfiguration);
 
 
-        this.sceneManager.updateConfiguration(newConfiguration, this.configuration);
+        this.sceneManager.updateConfiguration(newConfiguration);
 
 
         // observers in configuration
         // observers in configuration
         if (newConfiguration.observers) {
         if (newConfiguration.observers) {
@@ -508,9 +512,8 @@ export abstract class AbstractViewer {
             this.engine.setHardwareScalingLevel(scale);
             this.engine.setHardwareScalingLevel(scale);
         }
         }
 
 
-
         // create a new template manager for this viewer
         // create a new template manager for this viewer
-        this.sceneManager = new SceneManager(this.engine, this.observablesManager);
+        this.sceneManager = new SceneManager(this.engine, this._configurationContainer, this.observablesManager);
 
 
         return Promise.resolve(this.engine);
         return Promise.resolve(this.engine);
     }
     }

+ 2 - 2
Viewer/tests/commons/helper.ts

@@ -136,7 +136,7 @@ export class NullEngineAbstractViewer extends AbstractViewer {
             return this.canvas;
             return this.canvas;
         }
         }
 
 
-        this.sceneManager = new SceneManager(this.engine, this.observablesManager);
+        this.sceneManager = new SceneManager(this.engine, this.configurationContainer, this.observablesManager);
 
 
         // Disable manifest checking
         // Disable manifest checking
         BABYLON.Database.IDBStorageEnabled = false;
         BABYLON.Database.IDBStorageEnabled = false;
@@ -178,7 +178,7 @@ export class NullEngineDefaultViewer extends DefaultViewer {
             return this.canvas;
             return this.canvas;
         }
         }
 
 
-        this.sceneManager = new SceneManager(this.engine, this.observablesManager);
+        this.sceneManager = new SceneManager(this.engine, this.configurationContainer, this.observablesManager);
 
 
         // Disable manifest checking
         // Disable manifest checking
         BABYLON.Database.IDBStorageEnabled = false;
         BABYLON.Database.IDBStorageEnabled = false;