Browse Source

dist-update

Raanan Weber 7 năm trước cách đây
mục cha
commit
7437f8f5a6
2 tập tin đã thay đổi với 238 bổ sung66 xóa
  1. BIN
      Viewer/dist/environment.dds
  2. 238 66
      Viewer/dist/viewer.js

BIN
Viewer/dist/environment.dds


+ 238 - 66
Viewer/dist/viewer.js

@@ -74005,19 +74005,9 @@ var AbstractViewer = (function () {
     AbstractViewer.prototype.getBaseId = function () {
         return this.baseId;
     };
-    AbstractViewer.prototype.prepareContainerElement = function () {
-    };
     AbstractViewer.prototype.onTemplatesLoaded = function () {
         var _this = this;
         return this.initEngine().then(function () {
-            return _this.initScene();
-        }).then(function () {
-            return _this.initCameras();
-        }).then(function () {
-            return _this.initLights();
-        }).then(function () {
-            return _this.initEnvironment();
-        }).then(function () {
             return _this.loadModel();
         }).then(function () {
             return _this;
@@ -74031,18 +74021,47 @@ var AbstractViewer = (function () {
         window.addEventListener('resize', function () {
             _this.engine.resize();
         });
+        this.engine.runRenderLoop(function () {
+            _this.scene && _this.scene.render();
+        });
         var scale = Math.max(0.5, 1 / (window.devicePixelRatio || 2));
         this.engine.setHardwareScalingLevel(scale);
         return Promise.resolve(this.engine);
     };
     AbstractViewer.prototype.initScene = function () {
-        var _this = this;
+        if (this.scene) {
+            this.scene.dispose();
+        }
         this.scene = new babylonjs_1.Scene(this.engine);
-        this.engine.runRenderLoop(function () {
-            _this.scene.render();
-        });
+        this.scene.createDefaultCameraOrLight(true, true, true);
         return Promise.resolve(this.scene);
     };
+    AbstractViewer.prototype.loadModel = function (model, clearScene) {
+        var _this = this;
+        if (model === void 0) { model = this.configuration.model; }
+        if (clearScene === void 0) { clearScene = true; }
+        var modelUrl = (typeof model === 'string') ? model : model.url;
+        var parts = modelUrl.split('/');
+        var filename = parts.pop();
+        var base = parts.join('/') + '/';
+        return Promise.resolve().then(function () {
+            if (!_this.scene || clearScene)
+                return _this.initScene();
+            else
+                return _this.scene;
+        }).then(function () {
+            return new Promise(function (resolve, reject) {
+                babylonjs_1.SceneLoader.ImportMesh(undefined, base, filename, _this.scene, function (meshes) {
+                    resolve(meshes);
+                }, undefined, function (e, m, exception) {
+                    console.log(m, exception);
+                    reject(m);
+                });
+            });
+        }).then(function (meshes) {
+            return _this.onModelLoaded(meshes);
+        });
+    };
     AbstractViewer.prototype.onModelLoaded = function (meshes) {
         console.log("model loaded");
         return Promise.resolve(this.scene);
@@ -100692,6 +100711,7 @@ exports.default = exports.configurationLoader;
 
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.defaultConfiguration = {
+    version: "0.1",
     eventPrefix: 'babylonviewer-',
     events: true,
     defaultViewer: true,
@@ -100715,10 +100735,69 @@ exports.defaultConfiguration = {
             }
         }
     },
+    camera: {
+        behaviors: [
+            0,
+            {
+                type: 2,
+                zoomOnBoundingInfo: true,
+                zoomStopsAnimation: false
+            }
+        ]
+    },
+    lights: [
+        {
+            type: 1,
+            shadowEnabled: true,
+            direction: { x: -0.2, y: -1, z: 0 },
+            position: { x: 0.017, y: 0.5, z: 0 },
+            intensity: 4.5,
+            shadowConfig: {
+                useBlurExponentialShadowMap: true,
+                useKernelBlur: true,
+                blurKernel: 64,
+                blurScale: 4
+            }
+        }
+    ],
+    skybox: {
+        cubeTexture: {
+            url: 'http://localhost:9000/environment.dds',
+            gammaSpace: false
+        },
+        pbr: true,
+        blur: 0.7,
+        scale: 32,
+        infiniteDIstance: false,
+        material: {
+            imageProcessingConfiguration: {
+                colorCurves: {
+                    globalDensity: 89,
+                    globalHue: 58.88,
+                    globalSaturation: 94
+                },
+                colorCurvesEnabled: true,
+                exposure: 1.5,
+                contrast: 1.66,
+                toneMappingEnabled: true,
+                vignetteEnabled: true,
+                vignetteWeight: 5,
+                vignetteColor: { r: 0.8, g: 0.6, b: 0.4 },
+                vignetteM: true
+            }
+        }
+    },
+    ground: true,
     engine: {
         antialiasing: true
     },
-    scene: {}
+    scene: {
+        imageProcessingConfiguration: {
+            exposure: 1.4,
+            contrast: 1.66,
+            toneMappingEnabled: true
+        }
+    }
 };
 
 
@@ -103068,7 +103147,7 @@ var DefaultViewer = (function (_super) {
     DefaultViewer.prototype.initScene = function () {
         var _this = this;
         return _super.prototype.initScene.call(this).then(function () {
-            _this.scene.createDefaultCameraOrLight(true, true, true);
+            _this.extendClassWithConfig(_this.scene, _this.configuration.scene);
             return _this.scene;
         });
     };
@@ -103088,65 +103167,56 @@ var DefaultViewer = (function (_super) {
         this.containerElement.style.position = 'relative';
         this.containerElement.style.display = 'flex';
     };
-    DefaultViewer.prototype.initCameras = function () {
-        return Promise.resolve(this.scene);
-    };
-    DefaultViewer.prototype.initLights = function () {
-        var light = new babylonjs_1.HemisphericLight("light1", new babylonjs_1.Vector3(0, 1, 0), this.scene);
-        return Promise.resolve(this.scene);
-    };
     DefaultViewer.prototype.loadModel = function (model) {
-        var _this = this;
         if (model === void 0) { model = this.configuration.model; }
         this.showLoadingScreen();
-        var modelUrl = (typeof model === 'string') ? model : model.url;
-        var parts = modelUrl.split('/');
-        var filename = parts.pop();
-        var base = parts.join('/') + '/';
-        return new Promise(function (resolve, reject) {
-            babylonjs_1.SceneLoader.ImportMesh(undefined, base, filename, _this.scene, function (meshes) {
-                console.log("model loaded");
-                _this.onModelLoaded(meshes).then(function () {
-                    resolve(_this.scene);
-                });
-            }, undefined, function (e, m, exception) {
-                console.log(m, exception);
-                reject(m);
-            });
-        });
+        return _super.prototype.loadModel.call(this, model, true);
     };
     DefaultViewer.prototype.onModelLoaded = function (meshes) {
+        this.hideLoadingScreen();
         this.scene.createDefaultCameraOrLight(true, true, true);
-        var camera = this.scene.activeCamera;
-        camera.useFramingBehavior = true;
-        camera.useAutoRotationBehavior = true;
+        this.camera = this.scene.activeCamera;
         meshes[0].rotation.y += Math.PI;
-        var bounding = meshes[0].getHierarchyBoundingVectors();
-        camera.framingBehavior.zoomOnBoundingInfo(bounding.min, bounding.max);
-        this.scene.lights[0].dispose();
-        var light = new BABYLON.DirectionalLight('light', new BABYLON.Vector3(-0.2, -1, 0), this.scene);
-        light.position = new BABYLON.Vector3(bounding.max.x * 0.2, bounding.max.y * 2, 0);
-        light.intensity = 4.5;
-        var ground = babylonjs_1.Mesh.CreatePlane('ground', 100, this.scene);
-        ground.rotation.x = Math.PI / 2;
-        ground.receiveShadows = true;
-        ground.material = new babylonjs_1.ShadowOnlyMaterial('shadow-only-mat', this.scene);
-        ground.material.alpha = 0.4;
-        var shadowGenerator = new BABYLON.ShadowGenerator(512, light);
-        shadowGenerator.useBlurExponentialShadowMap = true;
-        shadowGenerator.useKernelBlur = true;
-        shadowGenerator.blurKernel = 64;
-        shadowGenerator.blurScale = 4;
-        for (var index = 0; index < meshes.length; index++) {
-            shadowGenerator.getShadowMap().renderList.push(meshes[index]);
-        }
-        this.hideLoadingScreen();
-        return Promise.resolve(this.scene);
+        this.setupCamera(meshes);
+        this.setupLights(meshes);
+        return this.initEnvironment();
     };
     DefaultViewer.prototype.initEnvironment = function () {
-        this.scene.imageProcessingConfiguration.exposure = 1.4;
-        this.scene.imageProcessingConfiguration.contrast = 1.66;
-        this.scene.imageProcessingConfiguration.toneMappingEnabled = true;
+        if (this.configuration.skybox) {
+            var texture = void 0;
+            if (this.configuration.skybox.cubeTexture) {
+                if (typeof this.configuration.skybox.cubeTexture.url === 'string') {
+                    texture = babylonjs_1.CubeTexture.CreateFromPrefilteredData(this.configuration.skybox.cubeTexture.url, this.scene);
+                }
+                else {
+                    texture = babylonjs_1.CubeTexture.CreateFromImages(this.configuration.skybox.cubeTexture.url, this.scene, this.configuration.skybox.cubeTexture.noMipMap);
+                }
+            }
+            if (texture) {
+                this.extendClassWithConfig(texture, this.configuration.skybox.cubeTexture);
+                var scale = this.configuration.skybox.scale || (this.scene.activeCamera.maxZ - this.scene.activeCamera.minZ) / 2;
+                var box = this.scene.createDefaultSkybox(texture, this.configuration.skybox.pbr, scale, this.configuration.skybox.blur);
+                if (this.configuration.skybox.material && this.configuration.skybox.material.imageProcessingConfiguration) {
+                    box.material.imageProcessingConfiguration = new babylonjs_1.ImageProcessingConfiguration();
+                }
+                this.extendClassWithConfig(box, this.configuration.skybox);
+            }
+        }
+        if (this.configuration.ground) {
+            var groundConfig = (typeof this.configuration.ground === 'boolean') ? {} : this.configuration.ground;
+            var ground = babylonjs_1.Mesh.CreateGround('ground', groundConfig.size || 100, groundConfig.size || 100, 8, this.scene);
+            if (this.configuration.ground === true || groundConfig.shadowOnly) {
+                ground.material = new BABYLON.ShadowOnlyMaterial('groundmat', this.scene);
+            }
+            else {
+                ground.material = new babylonjs_1.StandardMaterial('groundmat', this.scene);
+            }
+            if (this.configuration.ground === true) {
+                ground.receiveShadows = true;
+                ground.material.alpha = 0.4;
+            }
+            this.extendClassWithConfig(ground, groundConfig);
+        }
         return Promise.resolve(this.scene);
     };
     DefaultViewer.prototype.showLoadingScreen = function () {
@@ -103173,6 +103243,108 @@ var DefaultViewer = (function (_super) {
             return Promise.resolve(template);
         }));
     };
+    DefaultViewer.prototype.setupLights = function (focusMeshes) {
+        var _this = this;
+        if (focusMeshes === void 0) { focusMeshes = []; }
+        if (!this.configuration.scene.defaultLight && (this.configuration.lights && this.configuration.lights.length)) {
+            this.scene.lights.forEach(function (l) {
+                l.dispose();
+            });
+            this.configuration.lights.forEach(function (lightConfig, idx) {
+                lightConfig.name = lightConfig.name || 'light-' + idx;
+                var constructor = babylonjs_1.Light.GetConstructorFromName(lightConfig.type, lightConfig.name, _this.scene);
+                var light = constructor();
+                if (light.isEnabled() !== !lightConfig.disabled) {
+                    light.setEnabled(!lightConfig.disabled);
+                }
+                _this.extendClassWithConfig(light, lightConfig);
+                if (light instanceof babylonjs_1.ShadowLight) {
+                    if (lightConfig.shadowEnabled) {
+                        var shadowGenerator = new BABYLON.ShadowGenerator(512, light);
+                        _this.extendClassWithConfig(shadowGenerator, lightConfig.shadowConfig || {});
+                        for (var index = 0; index < focusMeshes.length; index++) {
+                            shadowGenerator.getShadowMap().renderList.push(focusMeshes[index]);
+                        }
+                    }
+                }
+            });
+        }
+    };
+    DefaultViewer.prototype.setupCamera = function (focusMeshes) {
+        var _this = this;
+        if (focusMeshes === void 0) { focusMeshes = []; }
+        if (this.configuration.scene.defaultCamera) {
+            return;
+        }
+        var cameraConfig = this.configuration.camera || {};
+        if (cameraConfig.position) {
+            this.camera.position.copyFromFloats(cameraConfig.position.x || 0, cameraConfig.position.y || 0, cameraConfig.position.z || 0);
+        }
+        if (cameraConfig.rotation) {
+            this.camera.rotationQuaternion = new babylonjs_1.Quaternion(cameraConfig.rotation.x || 0, cameraConfig.rotation.y || 0, cameraConfig.rotation.z || 0, cameraConfig.rotation.w || 0);
+        }
+        this.camera.minZ = cameraConfig.minZ || this.camera.minZ;
+        this.camera.maxZ = cameraConfig.maxZ || this.camera.maxZ;
+        if (cameraConfig.behaviors) {
+            cameraConfig.behaviors.forEach(function (behaviorConfig) {
+                _this.setCameraBehavior(behaviorConfig, focusMeshes);
+            });
+        }
+        ;
+        if (this.configuration.scene.autoRotate) {
+            this.camera.useAutoRotationBehavior = true;
+        }
+    };
+    DefaultViewer.prototype.setCameraBehavior = function (behaviorConfig, payload) {
+        var behavior;
+        var type = (typeof behaviorConfig !== "object") ? behaviorConfig : behaviorConfig.type;
+        var config = (typeof behaviorConfig === "object") ? behaviorConfig : {};
+        switch (type) {
+            case 0:
+                behavior = new babylonjs_1.AutoRotationBehavior();
+                break;
+            case 1:
+                behavior = new babylonjs_1.BouncingBehavior();
+                break;
+            case 2:
+                behavior = new babylonjs_1.FramingBehavior();
+                break;
+        }
+        if (behavior) {
+            if (typeof behaviorConfig === "object") {
+                this.extendClassWithConfig(behavior, behaviorConfig);
+            }
+            this.camera.addBehavior(behavior);
+        }
+        switch (type) {
+            case 0:
+                break;
+            case 1:
+                break;
+            case 2:
+                if (config.zoomOnBoundingInfo) {
+                    var meshes = payload;
+                    var bounding = meshes[0].getHierarchyBoundingVectors();
+                    behavior.zoomOnBoundingInfo(bounding.min, bounding.max);
+                }
+                break;
+        }
+    };
+    DefaultViewer.prototype.extendClassWithConfig = function (object, config) {
+        var _this = this;
+        Object.keys(config).forEach(function (key) {
+            if (key in object && typeof object[key] !== 'function') {
+                if (typeof object[key] === 'function')
+                    return;
+                if (typeof object[key] === 'object') {
+                    _this.extendClassWithConfig(object[key], config[key]);
+                }
+                else {
+                    object[key] = config[key];
+                }
+            }
+        });
+    };
     return DefaultViewer;
 }(viewer_1.AbstractViewer));
 exports.DefaultViewer = DefaultViewer;