Browse Source

Merge remote-tracking branch 'upstream/master' into animations-disconnect

sebavan 6 years ago
parent
commit
70b62158e9

+ 4 - 0
.travis.yml

@@ -35,7 +35,11 @@ jobs:
     - gulp tests-babylon-unit
     - travis_retry gulp tests-validation-virtualscreen
     - travis_retry gulp tests-validation-browserstack
+  - env: JOB=ModuleTests
+    script:
+    - gulp typescript-all
     - gulp tests-modules
+    - gulp deployAndTests-es6Modules
   - env: JOB=ViewerTests
     script:
     - export DISPLAY=:99.0

+ 2 - 1
Tools/Gulp/gulpfile.js

@@ -18,6 +18,7 @@ require("./tasks/gulpTasks-tests");
 require("./tasks/gulpTasks-remapPaths");
 require("./tasks/gulpTasks-npmPackages");
 require("./tasks/gulpTasks-dependencies");
+require("./tasks/gulpTasks-testsES6");
 
 /**
  * Temp cleanup after upgrade.
@@ -79,7 +80,7 @@ gulp.task("typescript-all", gulp.series("typescript-libraries", "typescript-es6"
 /**
  * Do it all (tests).
  */
-gulp.task("tests-all", gulp.series("tests-unit", "tests-modules", "tests-validation-virtualscreen", "tests-validation-browserstack"));
+gulp.task("tests-all", gulp.series("tests-unit", "tests-modules", "deployAndTests-es6Modules", "tests-validation-virtualscreen", "tests-validation-browserstack"));
 
 /**
  * Get Ready to test Npm Packages.

+ 73 - 18
Tools/Gulp/helpers/gulp-validateImports.js

@@ -8,51 +8,64 @@ var colorConsole = require("../../NodeHelpers/colorConsole");
 var config = require("../../Config/config");
 
 const indexExlclusion = ["States", "EmitterTypes"];
-const forbiddenImports = ["Meshes/meshBuilder"];
+const forbiddenImports = ["meshBuilder"];
 
 const mapping = { };
 config.modules.forEach(moduleName => {
     mapping[config[moduleName].build.umd.packageName] = moduleName;
 });
 
-var validatePath = function(fileLocation, directory, module, lineNumber, errors) {
+var validatePath = function(fileLocation, directory, module, lineNumber, errors, isExport) {
+    let expressionType = isExport ? "Export" : "Import";
     let internalModulePath = path.join(directory, module + ".ts");
+
     // Check .ts path.
     if (!fs.existsSync(internalModulePath)) {
-        let internalModulePath = path.join(directory, module + ".tsx");
+        internalModulePath = path.join(directory, module + ".tsx");
         // Check .tsx path.
         if (!fs.existsSync(internalModulePath)) {
             // If not found, check index.ts for legacy and index files.
             if (fileLocation.indexOf("legacy") > -1 || fileLocation.indexOf("index") > -1) {
-                let internalModulePath = path.join(directory, module, "index.ts");
+                internalModulePath = path.join(directory, module, "index.ts");
                 if (!fs.existsSync(internalModulePath)) {
-                    errors.push(`Line ${lineNumber} Export from folder only allowes if index is present. ${module}`);
+                    errors.push(`Line ${lineNumber} ${expressionType} from folder only allows if index is present. ${module}`);
                 }
             }
             else {
-                errors.push(`Line ${lineNumber} Imports ${module} needs to be full path (not from directory) for tree shaking.`);
+                errors.push(`Line ${lineNumber} ${expressionType}s ${module} needs to be full path (not from directory) for tree shaking.`);
             }
         }
     }
 
     if (internalModulePath.indexOf("index.") > -1) {
         if (fileLocation.indexOf("legacy") === -1) {
-            let excluded = false;
-            for (let exclusion of indexExlclusion) {
-                if (internalModulePath.indexOf(exclusion) > -1) {
-                    excluded = true;
-                    break;
+            if (isExport) {
+                internalModulePath = path.join(directory, module + ".ts");
+                // Check .ts path.
+                if (!fs.existsSync(internalModulePath)) {
+                    errors.push(`Line ${lineNumber} Exports ${module} should be from the full path including index.`);
                 }
             }
-            if (!excluded) {
-                errors.push(`Line ${lineNumber} Imports ${module} should not be from index for tree shaking.`);
+            else {
+                let excluded = false;
+                for (let exclusion of indexExlclusion) {
+                    if (internalModulePath.indexOf(exclusion) > -1) {
+                        excluded = true;
+                        break;
+                    }
+                }
+                if (!excluded && fileLocation.indexOf("index.ts") === -1) {
+                    errors.push(`Line ${lineNumber} Imports ${module} should not be from index for tree shaking.`);
+                }
             }
         }
     }
 
-    for (let forbiddenImport of forbiddenImports) {
-        if (module.endsWith(forbiddenImport)) {
-            errors.push(`Line ${lineNumber} Imports ${module} is forbidden for tree shaking.`);
+    if (!isExport) {
+        for (let forbiddenImport of forbiddenImports) {
+            if (module.endsWith(forbiddenImport)) {
+                errors.push(`Line ${lineNumber} ${expressionType}s ${module} is forbidden for tree shaking.`);
+            }
         }
     }
 }
@@ -107,7 +120,7 @@ var validateImports = function(data, fileLocation, options) {
 
                     const directory = config[configName].computed.srcDirectory;
                     module = module.substring(splitter);
-                    validatePath(fileLocation, directory, module, index + 1, errors);
+                    validatePath(fileLocation, directory, module, index + 1, errors, false);
                 }
             }
             else {
@@ -117,7 +130,49 @@ var validateImports = function(data, fileLocation, options) {
                 }
                 else {
                     const directory = path.dirname(fileLocation);
-                    validatePath(fileLocation, directory, module, index + 1, errors);
+                    validatePath(fileLocation, directory, module, index + 1, errors, false);
+                }
+            }
+        }
+
+        // Find Exports.
+        if (options.isCore && line.indexOf("export") > -1) {
+            let regexTypeExport = new RegExp(`export .* from ['"](.*)['"];`, "g");
+            let match = regexTypeExport.exec(line);
+            if (match) {
+                module = match[1];
+
+                // Checks if line is about external module
+                if (options.externals) {
+                    for (let ext in options.externals) {
+                        if (line.indexOf(ext) > -1) {
+                            externalModule = ext;
+                            break;
+                        }
+                    }
+                }
+
+                // Check if path is correct internal.
+                if (externalModule) {
+                    const splitter = module.indexOf("/");
+                    const baseModule = module.substring(0, splitter);
+                    if (mapping[baseModule]) {
+                        const configName = mapping[baseModule];
+
+                        const directory = config[configName].computed.srcDirectory;
+                        module = module.substring(splitter);
+                        validatePath(fileLocation, directory, module, index + 1, errors, true);
+                    }
+                }
+                else {
+                    // Check Relative.
+                    if (!module.startsWith(".")) {
+                        errors.push(`Line ${index + 1} Export ${module} needs to be relative.`);
+                    }
+                    else {
+                        const directory = path.dirname(fileLocation);
+                        validatePath(fileLocation, directory, module, index + 1, errors, true);
+                    }
                 }
             }
         }

+ 2 - 1
Tools/Gulp/tasks/gulpTasks-importLint.js

@@ -27,7 +27,8 @@ var importLintLibrary = function(settings) {
     return gulp.src(settings.computed.tsGlob)
         .pipe(fxFilter)
         .pipe(validateImports({
-            externals: settings.build.umd.processDeclaration.classMap
+            externals: settings.build.umd.processDeclaration.classMap,
+            isCore: settings.isCore
         }));
 }
 

+ 14 - 4
Tools/Gulp/tasks/gulpTasks-npmPackages.js

@@ -7,22 +7,32 @@ var publish = require("../../Publisher/tasks/main");
 /**
  * Get Ready to test Npm Packages.
  */
-gulp.task("npmPackages-es6", gulp.series("typescript-es6", function(cb) {
+gulp.task("localdev-es6", function(cb) {
     publish(false, {
         es6: true
     });
     cb();
-}));
+});
 
 /**
  * Get Ready to test Npm Packages.
  */
-gulp.task("npmPackages-UMD", gulp.series("typescript-libraries", function(cb) {
+gulp.task("localdev-UMD", function(cb) {
     publish(false, {
         umd: true
     });
     cb();
-}));
+});
+
+/**
+ * Get Ready to test Npm Packages.
+ */
+gulp.task("npmPackages-es6", gulp.series("typescript-es6", "localdev-es6"));
+
+/**
+ * Get Ready to test Npm Packages.
+ */
+gulp.task("npmPackages-UMD", gulp.series("typescript-libraries", "localdev-UMD"));
 
 /**
  * Get Ready to test Npm Packages.

+ 0 - 1
Tools/Gulp/tasks/gulpTasks-tests.js

@@ -1,7 +1,6 @@
 // Import Dependencies.
 var gulp = require("gulp");
 var typescript = require("gulp-typescript");
-var fs = require("fs");
 var karmaServer = require('karma').Server;
 var webpack = require('webpack');
 var webpackStream = require("webpack-stream");

+ 83 - 0
Tools/Gulp/tasks/gulpTasks-testsES6.js

@@ -0,0 +1,83 @@
+// Import Dependencies.
+const gulp = require("gulp");
+const path = require("path");
+const fs = require("fs-extra");
+const shelljs = require('shelljs');
+
+// Import Helpers.
+const colorConsole = require("../../NodeHelpers/colorConsole");
+
+// Read the full config.
+var config = require("../../Config/config.js");
+
+// Base Line Path.
+var baseLinePath = path.resolve(config.computed.rootFolder, "tests/es6Modules/packagesSizeBaseLine.json");
+var es6TestsFolder = path.resolve(config.computed.rootFolder, "tests/es6Modules");
+var es6TestsWebpackFile = path.resolve(es6TestsFolder, "webpack.config.js");
+
+/**
+ * Launches the ES6 modules tests to evaluate the min package size.
+ */
+gulp.task("tests-es6Modules", function(done) {
+    colorConsole.log("Npm link dependencies");
+    shelljs.exec("npm link @babylonjs/core", {
+        async: false,
+        cwd: es6TestsFolder
+    });
+
+    shelljs.exec("npm link @babylonjs/materials", {
+        async: false,
+        cwd: es6TestsFolder
+    });
+
+    colorConsole.log("Bundle test app");
+    var result = shelljs.exec("webpack", {
+        async: false,
+        cwd: es6TestsFolder
+    });
+
+    if (result.code != 0) {
+        colorConsole.error(result.stdout);
+        colorConsole.error(result.stderr);
+        throw "Can not build es6 dev apps."
+    }
+
+    colorConsole.log("Gather output size");
+
+    var testsBaseLine = fs.readJSONSync(baseLinePath);
+    var webpackConfig = require(es6TestsWebpackFile);
+    for (let entryName in webpackConfig.entry) {
+        let entry = webpackConfig.entry[entryName];
+        entry = entry.replace(".ts", ".js");
+        entry = path.basename(entry);
+        let outputPath = path.resolve(config.computed.tempFolder, 'testsES6Modules', entry);
+        let stats = fs.statSync(outputPath);
+        let size = stats.size;
+
+        if (testsBaseLine && testsBaseLine[entryName] && size > (testsBaseLine[entryName] + 10000)) {
+            colorConsole.error(`New size: ${(""+size).cyan} bytes is bigger than baseline size : ${testsBaseLine[entryName]} bytes on ${entryName}.`);
+            throw "Bigger than baseline";
+        }
+        testsBaseLine[entryName] = size;
+    }
+
+    for (let entryName in testsBaseLine) {
+        colorConsole.success(`Baseline size for ${entryName.yellow} is ${(""+testsBaseLine[entryName]).cyan} bytes.`);
+    }
+
+    colorConsole.log("Save baseline");
+    fs.writeJSONSync(baseLinePath, testsBaseLine);
+
+    done();
+});
+
+/**
+ * Launches the ES6 modules tests to evaluate the min package size.
+ */
+gulp.task("deployAndTests-es6Modules", gulp.series("localdev-es6", "tests-es6Modules"));
+
+
+/**
+ * Launches the ES6 modules tests to evaluate the min package size.
+ */
+gulp.task("buildAndTests-es6Modules", gulp.series("npmPackages-es6", "deployAndTests-es6Modules"));

+ 1 - 0
dist/preview release/what's new.md

@@ -91,6 +91,7 @@
 - Fix typo in FollowCamera InputsManager when limiting rotation to 360 degrees. ([mrdunk](https://github.com))
 - In FollowCamera InputsManager, allow choice of modifier key (Alt, Ctrl and/or Shift) for each camera movement axis. ([mrdunk](https://github.com))
 - Added MouseWheel bindings for FollowCamera. ([mrdunk](https://github.com))
+- Tweak MouseWheel bindings for FollowCamera orientations. ([mrdunk](https://github.com))
 - Added maximum and minimum limits for FollowCamera parameters. ([mrdunk](https://github.com))
 - Added per solid particle culling possibility : `solidParticle.isInFrustum()`  ([jerome](https://github.com/jbousquie))
 - Added transparency support to `GlowLayer` ([Sebavan](https://github.com/Sebavan))

+ 1 - 0
gui/src/2D/controls/index.ts

@@ -21,5 +21,6 @@ export * from "./displayGrid";
 export * from "./sliders/baseSlider";
 export * from "./sliders/slider";
 export * from "./sliders/imageBasedSlider";
+export * from "./sliders/scrollBar";
 
 export * from "./statics";

+ 2 - 2
src/Cameras/Inputs/followCameraMouseWheelInput.ts

@@ -99,9 +99,9 @@ export class FollowCameraMouseWheelInput implements ICameraInput<FollowCamera> {
                 if (this.axisControlRadius) {
                     this.camera.radius += delta;
                 } else if (this.axisControlHeight) {
-                    this.camera.heightOffset += delta;
+                    this.camera.heightOffset -= delta;
                 } else if (this.axisControlRotation) {
-                    this.camera.rotationOffset += delta;
+                    this.camera.rotationOffset -= delta;
                 }
             }
 

+ 4 - 0
tests/es6Modules/engineOnly.ts

@@ -0,0 +1,4 @@
+import { Engine } from "@babylonjs/core/Engines/engine";
+
+const canvas = document.getElementById("renderCanvas") as HTMLCanvasElement;
+new Engine(canvas);

+ 45 - 0
tests/es6Modules/minGridMaterial.ts

@@ -0,0 +1,45 @@
+import { Engine } from "@babylonjs/core/Engines/engine";
+import { Scene } from "@babylonjs/core/scene";
+import { Vector3 } from "@babylonjs/core/Maths/math";
+import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera";
+import { HemisphericLight } from "@babylonjs/core/Lights/hemisphericLight";
+import { Mesh } from "@babylonjs/core/Meshes/mesh";
+
+import { GridMaterial } from "@babylonjs/materials/grid/gridMaterial";
+
+import "@babylonjs/core/Meshes/Builders/boxBuilder";
+import "@babylonjs/core/Meshes/Builders/sphereBuilder";
+
+const canvas = document.getElementById("renderCanvas") as HTMLCanvasElement;
+const engine = new Engine(canvas);
+var scene = new Scene(engine);
+
+// This creates and positions a free camera (non-mesh)
+var camera = new FreeCamera("camera1", new Vector3(0, 5, -10), scene);
+
+// This targets the camera to scene origin
+camera.setTarget(Vector3.Zero());
+
+// This attaches the camera to the canvas
+camera.attachControl(canvas, true);
+
+// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
+var light = new HemisphericLight("light1", new Vector3(0, 1, 0), scene);
+
+// Default intensity is 1. Let's dim the light a small amount
+light.intensity = 0.7;
+
+// Our built-in 'sphere' shape. Params: name, subdivs, size, scene
+var sphere = Mesh.CreateSphere("sphere1", 16, 2, scene);
+
+// Move the sphere upward 1/2 its height
+sphere.position.y = 2;
+
+// Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
+var ground = Mesh.CreateGround("ground1", 6, 6, 2, scene);
+ground.material = new GridMaterial("", scene);
+sphere.material = new GridMaterial("", scene);
+
+engine.runRenderLoop(() => {
+    scene.render();
+});

+ 42 - 0
tests/es6Modules/minStandardMaterial.ts

@@ -0,0 +1,42 @@
+import { Engine } from "@babylonjs/core/Engines/engine";
+import { Scene } from "@babylonjs/core/scene";
+import { Vector3 } from "@babylonjs/core/Maths/math";
+import { FreeCamera } from "@babylonjs/core/Cameras/freeCamera";
+import { HemisphericLight } from "@babylonjs/core/Lights/hemisphericLight";
+import { Mesh } from "@babylonjs/core/Meshes/mesh";
+
+import "@babylonjs/core/Materials/standardMaterial";
+import "@babylonjs/core/Meshes/Builders/boxBuilder";
+import "@babylonjs/core/Meshes/Builders/sphereBuilder";
+
+const canvas = document.getElementById("renderCanvas") as HTMLCanvasElement;
+const engine = new Engine(canvas);
+var scene = new Scene(engine);
+
+// This creates and positions a free camera (non-mesh)
+var camera = new FreeCamera("camera1", new Vector3(0, 5, -10), scene);
+
+// This targets the camera to scene origin
+camera.setTarget(Vector3.Zero());
+
+// This attaches the camera to the canvas
+camera.attachControl(canvas, true);
+
+// This creates a light, aiming 0,1,0 - to the sky (non-mesh)
+var light = new HemisphericLight("light1", new Vector3(0, 1, 0), scene);
+
+// Default intensity is 1. Let's dim the light a small amount
+light.intensity = 0.7;
+
+// Our built-in 'sphere' shape. Params: name, subdivs, size, scene
+var sphere = Mesh.CreateSphere("sphere1", 16, 2, scene);
+
+// Move the sphere upward 1/2 its height
+sphere.position.y = 2;
+
+// Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
+var ground = Mesh.CreateGround("ground1", 6, 6, 2, scene);
+
+engine.runRenderLoop(() => {
+    scene.render();
+});

+ 1 - 0
tests/es6Modules/packagesSizeBaseLine.json

@@ -0,0 +1 @@
+{"engineOnly":303950,"sceneOnly":567058,"minGridMaterial":695590,"minStandardMaterial":791420}

+ 6 - 0
tests/es6Modules/sceneOnly.ts

@@ -0,0 +1,6 @@
+import { Engine } from "@babylonjs/core/Engines/engine";
+import { Scene } from "@babylonjs/core/scene";
+
+const canvas = document.getElementById("renderCanvas") as HTMLCanvasElement;
+const engine = new Engine(canvas);
+new Scene(engine);

+ 7 - 0
tests/es6Modules/tsconfig.json

@@ -0,0 +1,7 @@
+{
+    "compilerOptions": {
+        "module": "esNext",
+        "target": "es5",
+        "moduleResolution": "node",
+    }
+}

+ 27 - 0
tests/es6Modules/webpack.config.js

@@ -0,0 +1,27 @@
+const path = require("path");
+const config = require("../../Tools/Config/config");
+
+module.exports = {
+    context: path.resolve(__dirname),
+    entry: {
+        engineOnly: path.resolve(__dirname, 'engineOnly.ts'),
+        sceneOnly: path.resolve(__dirname, 'sceneOnly.ts'),
+        minGridMaterial: path.resolve(__dirname, 'minGridMaterial.ts'),
+        minStandardMaterial: path.resolve(__dirname, 'minStandardMaterial.ts')
+    },
+    output: {
+        filename: '[name].js',
+        path: config.computed.tempFolder + '/testsES6Modules'
+    },
+    devtool: 'none',
+    resolve: {
+        extensions: ['.ts', '.js']
+    },
+    module: {
+        rules: [{
+            test: /\.tsx?$/,
+            loader: 'ts-loader'
+        }]
+    },
+    mode: "production"
+};