123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- import { Helper } from "../../../commons/helper";
- import { assert, expect, should } from "../viewerReference";
- export let name = "configuration update";
- describe(name + " scene", () => {
- it("should be used as a template for the following tests", (done) => {
- let viewer = Helper.getNewViewerInstance(undefined, { extends: "none" });
- viewer.onInitDoneObservable.add(() => {
- viewer.dispose();
- done();
- });
- });
- it("should enable and disable the debug layer", (done) => {
- let viewer = Helper.getNewViewerInstance(undefined, { extends: "none" });
- let showCalled = 0;
- let hideCalled = 0;
- let isVisible = false;
- viewer.onSceneInitObservable.add((scene) => {
- scene.debugLayer.show = () => {
- showCalled++;
- isVisible = true;
- }
- scene.debugLayer.hide = () => {
- hideCalled++;
- isVisible = false;
- }
- scene.debugLayer.isVisible = () => {
- return isVisible;
- }
- })
- viewer.onInitDoneObservable.add(() => {
- // assert.isUndefined(viewer.configuration.scene);
- assert.equal(showCalled, 0);
- assert.equal(hideCalled, 0);
- viewer.updateConfiguration({
- scene: {
- debug: true
- }
- });
- assert.equal(showCalled, 1);
- viewer.updateConfiguration({
- scene: {
- debug: false
- }
- });
- assert.equal(showCalled, 1);
- assert.equal(hideCalled, 1);
- viewer.dispose();
- done();
- });
- });
- it("should update the image processing configuration values", (done) => {
- let viewer = Helper.getNewViewerInstance(undefined, { extends: "none" });
- viewer.onInitDoneObservable.add(() => {
- // check babylon defaults
- assert.isFalse(viewer.sceneManager.scene.imageProcessingConfiguration.applyByPostProcess);
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.exposure, 1);
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.contrast, 1);
- assert.isFalse(viewer.sceneManager.scene.imageProcessingConfiguration.colorGradingEnabled);
- if (viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves) {
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves.globalDensity, 0);
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves.globalHue, 30);
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves.globalSaturation, 0);
- } else {
- assert.fail(viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves, {}, "color curves was not initialized");
- }
- // update with fixed values
- viewer.updateConfiguration({
- scene: {
- imageProcessingConfiguration: {
- applyByPostProcess: true,
- exposure: 0,
- contrast: 0,
- colorGradingEnabled: true,
- colorCurves: {
- globalDensity: 1,
- globalHue: 0.2,
- globalSaturation: 0.5
- }
- }
- }
- });
- assert.isTrue(viewer.sceneManager.scene.imageProcessingConfiguration.applyByPostProcess, "apply by post process should be true");
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.exposure, 0);
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.contrast, 0);
- assert.isTrue(viewer.sceneManager.scene.imageProcessingConfiguration.colorGradingEnabled);
- if (viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves) {
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves.globalDensity, 1);
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves.globalHue, 0.2);
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves.globalSaturation, 0.5);
- } else {
- assert.fail(viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves, {}, "color curves was not initialized");
- }
- let randoms = [0, 1, 2, 3, 4].map(n => Math.random());
- viewer.updateConfiguration({
- scene: {
- imageProcessingConfiguration: {
- exposure: randoms[0],
- contrast: randoms[1],
- colorCurves: {
- highlightsDensity: randoms[2],
- highlightsHue: randoms[3],
- highlightsSaturation: randoms[4]
- }
- }
- }
- });
- assert.isTrue(viewer.sceneManager.scene.imageProcessingConfiguration.applyByPostProcess, "apply by post process should be true");
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.exposure, randoms[0]);
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.contrast, randoms[1]);
- assert.isTrue(viewer.sceneManager.scene.imageProcessingConfiguration.colorGradingEnabled);
- if (viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves) {
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves.highlightsDensity, randoms[2]);
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves.highlightsHue, randoms[3]);
- assert.equal(viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves.highlightsSaturation, randoms[4]);
- } else {
- assert.fail(viewer.sceneManager.scene.imageProcessingConfiguration.colorCurves, {}, "color curves was not initialized");
- }
- viewer.dispose();
- done();
- });
- });
- it("should update main color and reflection color", (done) => {
- let viewer = Helper.getNewViewerInstance(undefined, { extends: "none" });
- viewer.onInitDoneObservable.add(() => {
- assert.equal(viewer.sceneManager.mainColor.r, 1);
- assert.equal(viewer.sceneManager.mainColor.g, 1);
- assert.equal(viewer.sceneManager.mainColor.b, 1);
- assert.equal(viewer.sceneManager.reflectionColor.r, 1);
- assert.equal(viewer.sceneManager.reflectionColor.g, 1);
- assert.equal(viewer.sceneManager.reflectionColor.b, 1);
- viewer.updateConfiguration({
- environmentMap: {
- tintLevel: 1,
- texture: "",
- rotationY: 0,
- mainColor: {
- r: 0.5,
- g: 0.5,
- b: 0.5
- }
- }
- });
- assert.equal(viewer.sceneManager.mainColor.r, 0.5);
- assert.equal(viewer.sceneManager.mainColor.g, 0.5);
- assert.equal(viewer.sceneManager.mainColor.b, 0.5);
- // to black
- viewer.updateConfiguration({
- scene: {
- mainColor: {
- r: 0,
- g: 0,
- b: 0
- }
- }
- });
- assert.equal(viewer.sceneManager.mainColor.r, 0);
- assert.equal(viewer.sceneManager.mainColor.g, 0);
- assert.equal(viewer.sceneManager.mainColor.b, 0);
- assert.equal(viewer.sceneManager.reflectionColor.r, 0);
- assert.equal(viewer.sceneManager.reflectionColor.g, 0);
- assert.equal(viewer.sceneManager.reflectionColor.b, 0);
- let randomColor = Math.random();
- //only update red
- viewer.updateConfiguration({
- scene: {
- mainColor: {
- r: randomColor
- }
- }
- });
- assert.equal(viewer.sceneManager.mainColor.r, randomColor);
- assert.equal(viewer.sceneManager.mainColor.g, 0);
- assert.equal(viewer.sceneManager.mainColor.b, 0);
- viewer.dispose();
- done();
- });
- });
- it("should update the flags correctly", (done) => {
- let viewer = Helper.getNewViewerInstance(undefined, { extends: "none" });
- viewer.onInitDoneObservable.add(() => {
- viewer.updateConfiguration({
- scene: {
- flags: {
- audioEnabled: false
- }
- }
- });
- assert.isFalse(viewer.sceneManager.scene.audioEnabled);
- viewer.updateConfiguration({
- scene: {
- flags: {
- audioEnabled: true,
- lightsEnabled: false
- }
- }
- });
- assert.isTrue(viewer.sceneManager.scene.audioEnabled);
- assert.isFalse(viewer.sceneManager.scene.lightsEnabled);
- viewer.updateConfiguration({
- scene: {
- flags: {
- lightsEnabled: true,
- shadowsEnabled: false
- }
- }
- });
- assert.isTrue(viewer.sceneManager.scene.audioEnabled);
- assert.isTrue(viewer.sceneManager.scene.lightsEnabled);
- assert.isFalse(viewer.sceneManager.scene.shadowsEnabled);
- viewer.dispose();
- done();
- });
- });
- });
- describe(name + " scene optimizer", () => {
- it("should be enabled and disabled with booleans", (done) => {
- let viewer = Helper.getNewViewerInstance(undefined, { extends: "none" });
- let started = false;
- let constructed = false;
- let optimizerFunction = BABYLON.SceneOptimizer;
- //mock!
- (<any>BABYLON.SceneOptimizer) = function () {
- constructed = true;
- }
- BABYLON.SceneOptimizer.prototype.start = function () {
- started = true;
- }
- BABYLON.SceneOptimizer.prototype.stop = function () {
- started = false;
- }
- BABYLON.SceneOptimizer.prototype.dispose = function () {
- }
- viewer.onInitDoneObservable.add(() => {
- assert.isUndefined(viewer.sceneManager.sceneOptimizer);
- viewer.updateConfiguration({
- optimizer: true
- });
- assert.isDefined(viewer.sceneManager.sceneOptimizer);
- assert.isTrue(started);
- assert.isTrue(constructed);
- viewer.updateConfiguration({
- optimizer: false
- });
- assert.isUndefined(viewer.sceneManager.sceneOptimizer);
- assert.isFalse(started);
- BABYLON.SceneOptimizer = optimizerFunction;
- viewer.dispose();
- done();
- });
- });
- });
- describe(name + " camera", () => {
- it("should enable and disable camera behaviors", (done) => {
- let viewer = Helper.getNewViewerInstance(undefined, { extends: "none" });
- viewer.onInitDoneObservable.add(() => {
- assert.isFalse(viewer.sceneManager.camera.useAutoRotationBehavior);
- viewer.updateConfiguration({
- camera: {
- behaviors: {
- autoRotate: {
- type: 0
- }
- }
- }
- });
- assert.isTrue(viewer.sceneManager.camera.useAutoRotationBehavior);
- viewer.updateConfiguration({
- camera: {
- behaviors: {
- autoRotate: false
- }
- }
- });
- assert.isFalse(viewer.sceneManager.camera.useAutoRotationBehavior);
- viewer.dispose();
- done();
- });
- })
- })
|