Browse Source

Merge pull request #3547 from RaananW/modules-extra-work

Modules extra work
David Catuhe 7 years ago
parent
commit
0555034c68

+ 9 - 91
Tools/Gulp/config.json

@@ -252,7 +252,6 @@
                 "imageProcessingFunctions",
                 "bumpFragmentFunctions",
                 "clipPlaneFragmentDeclaration",
-                "logDepthDeclaration",
                 "fogFragmentDeclaration",
                 "clipPlaneFragment",
                 "bumpFragment",
@@ -444,45 +443,12 @@
                 "pbr.fragment"
             ],
             "shaderIncludes": [
-                "bonesDeclaration",
-                "instancesDeclaration",
-                "bumpVertexDeclaration",
-                "clipPlaneVertexDeclaration",
-                "fogVertexDeclaration",
-                "morphTargetsVertexGlobalDeclaration",
-                "morphTargetsVertexDeclaration",
-                "logDepthDeclaration",
-                "morphTargetsVertex",
-                "instancesVertex",
-                "bonesVertex",
-                "bumpVertex",
-                "clipPlaneVertex",
-                "fogVertex",
-                "shadowsVertex",
-                "logDepthVertex",
-                "lightFragmentDeclaration",
-                "lightUboDeclaration",
                 "pbrVertexDeclaration",
                 "pbrFragmentDeclaration",
                 "pbrUboDeclaration",
-                "fresnelFunction",
-                "reflectionFunction",
-                "shadowsFragmentFunctions",
                 "pbrFunctions",
-                "imageProcessingDeclaration",
-                "imageProcessingFunctions",
                 "harmonicsFunctions",
-                "pbrLightFunctions",
-                "helperFunctions",
-                "bumpFragmentFunctions",
-                "clipPlaneFragmentDeclaration",
-                "logDepthDeclaration",
-                "fogFragmentDeclaration",
-                "clipPlaneFragment",
-                "bumpFragment",
-                "lightFragment",
-                "logDepthFragment",
-                "fogFragment"
+                "pbrLightFunctions"
             ]
         },
         "targetCamera": {
@@ -616,7 +582,6 @@
                 "../../src/Tools/babylon.andOrNotEvaluator.js"
             ],
             "dependUpon": [
-                "core",
                 "stringDictionary"
             ]
         },
@@ -705,12 +670,7 @@
                 "depth.vertex",
                 "depth.fragment"
             ],
-            "shaderIncludes": [
-                "bonesDeclaration",
-                "instancesDeclaration",
-                "instancesVertex",
-                "bonesVertex"
-            ]
+            "shaderIncludes": []
         },
         "geometryBufferRenderer": {
             "files": [
@@ -726,9 +686,7 @@
             "shaderIncludes": [
                 "mrtFragmentDeclaration",
                 "bones300Declaration",
-                "instances300Declaration",
-                "instancesVertex",
-                "bonesVertex"
+                "instances300Declaration"
             ]
         },
         "postProcesses": {
@@ -795,10 +753,7 @@
             "shaders": [
                 "imageProcessing.fragment"
             ],
-            "shaderIncludes": [
-                "imageProcessingDeclaration",
-                "imageProcessingFunctions"
-            ]
+            "shaderIncludes": []
         },
         "additionalPostProcesses": {
             "files": [
@@ -964,10 +919,7 @@
                 "stringDictionary",
                 "actions"
             ],
-            "shaders": [
-                "color.vertex",
-                "color.fragment"
-            ]
+            "shaders": []
         },
         "morphTargets": {
             "files": [
@@ -1002,7 +954,9 @@
                 "../../src/Cameras/VR/babylon.vrExperienceHelper.js"
             ],
             "dependUpon": [
-                "core"
+                "core",
+                "postProcesses",
+                "freeCamera"
             ],
             "shaders": [
                 "anaglyph.fragment",
@@ -1099,45 +1053,9 @@
                 "background.fragment"
             ],
             "shaderIncludes": [
-                "bonesDeclaration",
-                "instancesDeclaration",
-                "pointCloudVertexDeclaration",
-                "bumpVertexDeclaration",
-                "clipPlaneVertexDeclaration",
-                "fogVertexDeclaration",
-                "morphTargetsVertexGlobalDeclaration",
-                "morphTargetsVertexDeclaration",
-                "logDepthDeclaration",
-                "morphTargetsVertex",
-                "instancesVertex",
-                "bonesVertex",
-                "bumpVertex",
-                "clipPlaneVertex",
-                "fogVertex",
-                "shadowsVertex",
-                "pointCloudVertex",
-                "logDepthVertex",
-                "helperFunctions",
-                "lightFragmentDeclaration",
-                "lightsFragmentFunctions",
-                "lightUboDeclaration",
                 "backgroundVertexDeclaration",
                 "backgroundFragmentDeclaration",
-                "backgroundUboDeclaration",
-                "shadowsFragmentFunctions",
-                "fresnelFunction",
-                "reflectionFunction",
-                "imageProcessingDeclaration",
-                "imageProcessingFunctions",
-                "bumpFragmentFunctions",
-                "clipPlaneFragmentDeclaration",
-                "logDepthDeclaration",
-                "fogFragmentDeclaration",
-                "clipPlaneFragment",
-                "bumpFragment",
-                "lightFragment",
-                "logDepthFragment",
-                "fogFragment"
+                "backgroundUboDeclaration"
             ]
         },
         "environmentHelper": {

+ 79 - 0
Tools/Gulp/gulp-addES6Exports.js

@@ -0,0 +1,79 @@
+var gutil = require('gulp-util');
+var through = require('through2');
+
+/**
+ * The parameters for this function has grown during development.
+ * Eventually, this function will need to be reorganized. 
+ */
+module.exports = function (baseModule, subModule, extendsRoot, externalUsingBabylon) {
+    return through.obj(function (file, enc, cb) {
+
+        var optionalRequire = `var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
+var babylonDependency = (globalObject && globalObject.BABYLON) || BABYLON || (typeof require !== 'undefined' && require("babylonjs"));
+var BABYLON = babylonDependency;
+`;
+        let fileContent = file.contents.toString();
+        function moduleExportAddition(varName) {
+
+            let base = subModule ? 'BABYLON' : baseModule;
+
+            let sadGlobalPolution = (!subModule) ? `var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
+globalObject["${base}"] = ${base}${(subModule && !extendsRoot) ? '.' + varName : ''};` : '';
+            /*if (extendsRoot) {
+                basicInit = `__extends(root["BABYLON"], factory()); `
+            }*/
+
+            let listOfExports = [];
+            // find the exported members. es6 exports can NOT be generated dynamically.
+            let matcher = new RegExp(base + "\\.(\\w*) = (\\w*);", "g");
+            let match = matcher.exec(fileContent);
+            while (match != null) {
+                if (match[1] && match[2] && match[1] === match[2]) {
+                    listOfExports.push(match[1]);
+                }
+                match = matcher.exec(fileContent);
+            }
+
+            let exportsText = '';
+            listOfExports.forEach(cls => {
+                exportsText += `var ${cls} = ${base}.${cls};`;
+            });
+            exportsText += `
+export { ${listOfExports.join(",")} };`
+
+            return `${sadGlobalPolution}
+${exportsText}
+`;
+        }
+
+        var extendsAddition = `var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var n in o)o.hasOwnProperty(n)&&(t[n]=o[n])};return function(o,n){function r(){this.constructor=o}t(o,n),o.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();
+`;
+
+        var decorateAddition = 'var __decorate=this&&this.__decorate||function(e,t,r,c){var o,f=arguments.length,n=f<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,r):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,c);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(n=(f<3?o(n):f>3?o(t,r,n):o(t,r))||n);return f>3&&n&&Object.defineProperty(t,r,n),n};\n';
+
+
+        if (file.isNull()) {
+            cb(null, file);
+            return;
+        }
+
+        if (file.isStream()) {
+            //streams not supported, no need for now.
+            return;
+        }
+
+        try {
+            if (externalUsingBabylon) {
+                //file.contents = new Buffer(optionalRequire.concat(String(file.contents)));
+                file.contents = new Buffer(optionalRequire.concat(new Buffer(String(file.contents).concat(moduleExportAddition(baseModule)))));
+            } else {
+                let pretext = subModule ? optionalRequire : '';
+                file.contents = new Buffer(pretext.concat(decorateAddition).concat(new Buffer(extendsAddition.concat(String(file.contents)).concat(moduleExportAddition(baseModule)))));
+            }
+            this.push(file);
+        } catch (err) {
+            this.emit('error', new gutil.PluginError('gulp-add-module-exports', err, { fileName: file.path }));
+        }
+        cb();
+    });
+};

+ 36 - 6
Tools/Gulp/gulp-appendSrcToVariable.js

@@ -7,7 +7,7 @@ var File = gutil.File;
 // Consts
 const PLUGIN_NAME = 'gulp-appendSrcToVariable';
 
-var appendSrcToVariable = function appendSrcToVariable(varName, namingCallback, output, lastFile) {
+var appendSrcToVariable = function appendSrcToVariable(varName, namingCallback, output, moduleType) {
 
     var content;
     var firstFile;
@@ -28,17 +28,47 @@ var appendSrcToVariable = function appendSrcToVariable(varName, namingCallback,
             return;
         }
 
+        // construct concat instance
+        if (!content) {
+            content = "";
+        }
+
         // set first file if not already set
         if (!firstFile) {
+            if (moduleType === "es6") {
+                content += `
+// import * as BABYLON from 'babylonjs/core/es6';
+`;
+            }
             firstFile = file;
         }
 
-        // construct concat instance
-        if (!content) {
-            content = "";
-        }
+
         var name = namingCallback(file.relative);
-        content += varName + "['" + name + "'] = " + JSON.stringify(file.contents.toString()) + ";\r\n";
+        if (moduleType) {
+            let vars = varName.split(".");
+            // shader support when using modules
+            if (moduleType === "es6") {
+                content += `
+let ${name} = ${JSON.stringify(file.contents.toString())};
+// ${varName}["${name}"] = ${varName}["${name}"] || ${name};
+export { ${name}  };
+`;
+            } else {
+                // commonjs
+                content += `
+if(typeof require !== 'undefined'){
+var BABYLON = require("babylonjs/core");
+let data = ${JSON.stringify(file.contents.toString())};
+${varName}["${name}"] = ${varName}["${name}"] || data;
+module.exports = module.exports || {};
+module.exports["${name}"] = data;
+}
+`;
+            }
+        } else {
+            content += varName + "['" + name + "'] = " + JSON.stringify(file.contents.toString()) + ";\r\n";
+        }
         cb();
     }
 

+ 66 - 46
Tools/Gulp/gulp-babylonModule.js

@@ -1,34 +1,23 @@
 var gutil = require('gulp-util');
 var through = require('through2');
+var path = require('path');
 
-module.exports = function (moduleName, dependencies) {
+module.exports = function (moduleName, dependencyTree, generateIndex, perFile, shaders, shaderIncludes) {
     return through.obj(function (file, enc, cb) {
 
-        console.log("Compiling module: " + moduleName);
+        let basename = (path.basename(file.path, ".js"));
+
+        //console.log("Compiling module: " + moduleName + "/" + basename.replace("babylon.", ""));
 
         var extendsAddition =
-            `var __extends = (this && this.__extends) || (function () {
-var extendStatics = Object.setPrototypeOf ||
-    ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
-    function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
-return function (d, b) {
-    extendStatics(d, b);
-    function __() { this.constructor = d; }
-    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
-};
-})();
+            `var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var n in o)o.hasOwnProperty(n)&&(t[n]=o[n])};return function(o,n){function r(){this.constructor=o}t(o,n),o.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();
 `;
 
         var decorateAddition =
-            'var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n' +
-            'var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n' +
-            'if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);\n' +
-            'else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n' +
-            'return c > 3 && r && Object.defineProperty(target, key, r), r;\n' +
-            '};\n';
+            'var __decorate=this&&this.__decorate||function(e,t,r,c){var o,f=arguments.length,n=f<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,r):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,c);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(n=(f<3?o(n):f>3?o(t,r,n):o(t,r))||n);return f>3&&n&&Object.defineProperty(t,r,n),n};\n';
 
         let content = file.contents.toString();
-        if (content.indexOf('__extends') === -1 && dependencies.length < 2) {
+        if (content.indexOf('__extends') === -1 && !dependencyTree.length) {
             extendsAddition = '';
         }
 
@@ -41,23 +30,68 @@ ${decorateAddition}
 if(typeof require !== 'undefined'){
     var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
     var BABYLON = globalObject["BABYLON"] || {}; 
+    var EXPORTS = {};
+`;
+        let exportsText = '';
+        if (!generateIndex) {
+            let loadedFiles = [];
+            dependencyTree[basename].forEach(function (d, idx) {
+                if (d.module.indexOf("core") !== -1) return;
+                let name = d.file.split(".").pop();
+
+                if (loadedFiles.indexOf(name) === -1) {
+                    if (d.main)
+                        dependenciesText += `var ${name}Module = require('babylonjs/${d.module[0]}/${name}');
 `;
-        if (dependencies) {
-            /*if (dependencies.length > 1) {
-                dependenciesText += 'function nse(ns1, ns2) { Object.keys(ns2).forEach(function(c) {if(!ns1[c]) {ns1[c] = ns2[c]}}) };\n';
-            }*/
+                    else
+                        exportsText += `var ${name}Module = require('babylonjs/${d.module[0]}/${name}');
+`;
+                    loadedFiles.push(name);
+                }
 
-            dependencies.forEach(function (d, idx) {
-                dependenciesText += `var BABYLON${idx} = require('babylonjs/${d}');
+                dependenciesText += `BABYLON["${d.name}"] = ${name}Module["${d.name}"];
 `;
-                dependenciesText += `if(BABYLON !== BABYLON${idx}) __extends(BABYLON, BABYLON${idx});
+                //dependenciesText += `if(BABYLON !== BABYLON${idx}) __extends(BABYLON, BABYLON${idx});
+            });
+            perFile[basename].declarations.forEach(dec => {
+                exportsText += `EXPORTS['${dec}'] = BABYLON["${dec}"];
 `;
             });
+            if (shaders) {
+                dependenciesText += `require("babylonjs/${moduleName}/shaders");
+`;
+            }
+            if (shaderIncludes) {
+                dependenciesText += `require("babylonjs/${moduleName}/shaderIncludes");
+`;
+            }
+        } else {
+            content = '';
+            let basenames = Object.keys(perFile).filter(basefilename => {
+                return perFile[basefilename].module.indexOf(moduleName) !== -1;
+            });
+
+            basenames.forEach(bname => {
+                let name = bname.split(".").pop();
+                dependenciesText += `var ${name} = require("babylonjs/${moduleName}/${name}");
+`;
+                // now add the internal dependencies to EXPORTS
+                perFile[bname].declarations.forEach(dec => {
+                    dependenciesText += `EXPORTS['${dec}'] = BABYLON["${dec}"] = ${name}["${dec}"];
+`;
+                });
+            })
         }
 
+        exportsText += `(function() {
+    globalObject["BABYLON"] = globalObject["BABYLON"] || BABYLON;
+    module.exports = EXPORTS;
+    })();
+}`;
+
 
 
-        let exportRegex = /BABYLON.([0-9A-Za-z-_]*) = .*;\n/g
+        /*let exportRegex = /BABYLON.([0-9A-Za-z-_]*) = .*;\n/g
 
         var match = exportRegex.exec(content);
 
@@ -67,30 +101,16 @@ if(typeof require !== 'undefined'){
                 exportsArray.push(match[1])
             }
             match = exportRegex.exec(content);
-        }
+        }*/
 
-        let exportsText = '';
-        if (moduleName === "core") {
+
+        /*if (moduleName === "core") {
             exportsText = `(function() {
     globalObject["BABYLON"] = globalObject["BABYLON"] || BABYLON;
     module.exports = BABYLON; 
 })();
 }`
-        }
-        else {
-            exportsText = `(function() {
-var EXPORTS = {};`
-            exportsArray.forEach(e => {
-                if (e.indexOf('.') === -1)
-                    exportsText += `EXPORTS['${e}'] = BABYLON['${e}'];`
-            });
-
-            exportsText += `
-    globalObject["BABYLON"] = globalObject["BABYLON"] || BABYLON;
-    module.exports = EXPORTS;
-    })();
-}`
-        }
+        }*/
 
         if (file.isNull()) {
             cb(null, file);
@@ -103,7 +123,7 @@ var EXPORTS = {};`
         }
 
         try {
-            file.contents = new Buffer(dependenciesText.concat(new Buffer(String(file.contents).concat(exportsText))));
+            file.contents = new Buffer(dependenciesText.concat(new Buffer(String(content).concat(exportsText))));
             this.push(file);
         } catch (err) {
             this.emit('error', new gutil.PluginError('gulp-add-babylon-module', err, { fileName: file.path }));

+ 80 - 0
Tools/Gulp/gulp-calculateDependencies.js

@@ -0,0 +1,80 @@
+var gutil = require('gulp-util');
+var through = require('through2');
+var path = require('path');
+
+module.exports = function (moduleName, perFile, declared, depTree) {
+    return through.obj(function (file, enc, cb) {
+        let basename = (path.basename(file.path, ".ts"));
+        depTree[basename] = depTree[basename] || [];
+        // detect dependencies
+        let depReg1 = /[:,][ ]{0,1}([A-Z]\w*)/g;
+        let depReg2 = /<([A-Z]\w*)(\[\]){0,1}>/g;
+        let depReg3 = /[\s(]([A-Z]\w*)\./g;
+        let depReg4 = /[extends|implements] ([A-Z]\w*)/g;
+        let depReg5 = /new ([A-Z]\w*)/g;
+
+        let dependencies = [];
+        fileContent = file.contents.toString().replace(/(\/\*([\s\S]*?)\*\/)|(\/\/(.*)$)/gm, "");
+        function findWhereDeclared(objectName) {
+            let fileLocator;
+            Object.keys(perFile).some((filename => {
+                filedec = perFile[filename];
+                if (filedec.declarations.indexOf(objectName) !== -1) {
+                    fileLocator = filename;
+                    return true;
+                }
+                return false;
+            }))
+            return fileLocator;
+        }
+
+        //if (basename === "babylon.webVRCamera") {
+        [depReg4, depReg1, depReg5, depReg3, depReg2].forEach((reg, idx) => {
+            var match = reg.exec(fileContent);
+            while (match != null) {
+                if (match[1]) {
+                    let dep = match[1];
+                    if (basename === "babylon.poseEnabledController") {
+                        console.log(dep, idx);
+                    }
+                    //find if it is declared internally
+                    if (perFile[basename].declarations.indexOf(dep) === -1) {
+                        // not internally? maybe it is in core?
+                        //if (declared.core.indexOf(dep) === -1) {
+                        // seems like a legit dependency! was it already added?
+                        if (perFile[basename].dependencies.indexOf(dep) === -1) {
+                            //no! add it.
+                            let whereDeclared = (findWhereDeclared(dep));
+                            if (whereDeclared) {
+                                perFile[basename].dependencies.push(dep);
+                                if (basename === "babylon.poseEnabledController") {
+                                    console.log("adding ", dep, idx === 2);
+                                }
+                                depTree[basename].push({
+                                    name: dep,
+                                    file: whereDeclared,
+                                    module: perFile[whereDeclared].module,
+                                    main: idx === 0, // is it a main import
+                                    newDec: idx === 2 // is it "new"
+                                });
+                            }
+                        }
+                        //}
+                    }
+                }
+                match = reg.exec(fileContent);
+            }
+        });
+        //}
+
+
+        try {
+            this.push(file);
+
+        } catch (err) {
+            this.emit('error', new gutil.PluginError('gulp-calculateDependencies', err, { fileName: file.path }));
+        }
+        cb();
+    });
+};
+

+ 38 - 4
Tools/Gulp/gulp-dtsModuleSupport.js

@@ -1,14 +1,23 @@
 var gutil = require('gulp-util');
 var through = require('through2');
+var path = require('path');
 
 // inject - if set to true, it will add all declarations as imports.
-module.exports = function (moduleName, inject, declarations) {
+module.exports = function (moduleName, inject, declarations, perFile, dependencyTree) {
     return through.obj(function (file, enc, cb) {
-
+        let basename = (path.basename(file.path, ".d.ts"));
         let fileContent = file.contents.toString();
         let importsString = '';
 
         if (!inject) {
+            perFile[basename] = perFile[basename] || {
+                module: [moduleName],
+                dependencies: [],
+                declarations: []
+            };
+            if (perFile[basename].module.indexOf(moduleName) === -1) {
+                perFile[basename].module.push(moduleName);
+            }
             declarations[moduleName] = declarations[moduleName] || [];
             let regexp = /    (abstract class|function|class|interface|type|const|enum|var) ([\w]*)/g;
 
@@ -17,13 +26,15 @@ module.exports = function (moduleName, inject, declarations) {
                 if (match[2]) {
                     // check it is not SIMD:
                     let simdMatch = /    interface (\w*\dx\d{1,2}\w*)/.exec(match[0]);
-                    if (!simdMatch && match[2] !== 'earcut' && match[2] !== 'deviation' && match[2] !== 'flatten')
+                    if (!simdMatch && match[2] !== 'earcut' && match[2] !== 'deviation' && match[2] !== 'flatten') {
                         declarations[moduleName].push(match[2]);
+                        perFile[basename].declarations.push(match[2]);
+                    }
                 }
                 match = regexp.exec(fileContent);
             }
         } else {
-            let declared = [];
+            /*let declared = [];
             Object.keys(declarations).forEach(name => {
                 if (name === moduleName) return;
                 let imports = declarations[name].filter(obj => {
@@ -36,6 +47,29 @@ module.exports = function (moduleName, inject, declarations) {
                 if (imports.length)
                     importsString += `import {${imports.join(',')}} from 'babylonjs/${name}';
 `;
+            });*/
+
+            // find all of the related files for the dependency tree integration
+            let basenames = Object.keys(perFile).filter(basefilename => {
+                return perFile[basefilename].module.indexOf(moduleName) !== -1;
+            });
+
+            let classesForImports = {} // key : module name, content - array of objects
+            basenames.forEach(bname => {
+                dependencyTree[bname].forEach(dep => {
+                    if (dep.module.indexOf(moduleName) !== -1) return;
+                    let depModule = dep.module.indexOf("core") === -1 ? dep.module[0] : "core";
+                    classesForImports[depModule] = classesForImports[depModule] || [];
+                    if (classesForImports[depModule].indexOf(dep.name) === -1) {
+                        //babylon.imageProcessingPostProcess
+                        classesForImports[depModule].push(dep.name);
+                    }
+                });
+            });
+
+            Object.keys(classesForImports).forEach(modName => {
+                importsString += `import {${classesForImports[modName].join(',')}} from 'babylonjs/${modName}';
+`;
             });
         }
 

+ 139 - 36
Tools/Gulp/gulp-es6ModuleExports.js

@@ -1,34 +1,23 @@
 var gutil = require('gulp-util');
 var through = require('through2');
+var path = require('path');
 
-module.exports = function (moduleName, dependencies, es6) {
+module.exports = function (moduleName, dependencyTree, generateIndex, perFile, shaders, shaderIncludes) {
     return through.obj(function (file, enc, cb) {
 
-        console.log("Compiling es6 module: " + moduleName);
+        let basename = (path.basename(file.path, ".js"));
+
+        //console.log("Compiling es6 module: " + moduleName + "/" + basename.replace("babylon.", ""));
 
         var extendsAddition =
-            `var __extends = (this && this.__extends) || (function () {
-var extendStatics = Object.setPrototypeOf ||
-    ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
-    function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
-return function (d, b) {
-    extendStatics(d, b);
-    function __() { this.constructor = d; }
-    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
-};
-})();
+            `var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var n in o)o.hasOwnProperty(n)&&(t[n]=o[n])};return function(o,n){function r(){this.constructor=o}t(o,n),o.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();
 `;
 
         var decorateAddition =
-            'var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n' +
-            'var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n' +
-            'if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);\n' +
-            'else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n' +
-            'return c > 3 && r && Object.defineProperty(target, key, r), r;\n' +
-            '};\n';
+            'var __decorate=this&&this.__decorate||function(e,t,r,c){var o,f=arguments.length,n=f<3?t:null===c?c=Object.getOwnPropertyDescriptor(t,r):c;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,r,c);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(n=(f<3?o(n):f>3?o(t,r,n):o(t,r))||n);return f>3&&n&&Object.defineProperty(t,r,n),n};\n';
 
         let content = file.contents.toString();
-        if (content.indexOf('__extends') === -1 && dependencies.length < 2) {
+        if (content.indexOf('__extends') === -1 && !dependencyTree.length) {
             extendsAddition = '';
         }
 
@@ -39,28 +28,135 @@ return function (d, b) {
         let dependenciesText = `${extendsAddition}
 ${decorateAddition}
 `;
-        if (dependencies) {
-            /*if (dependencies.length > 1) {
-                dependenciesText += 'function nse(ns1, ns2) { Object.keys(ns2).forEach(function(c) {if(!ns1[c]) {ns1[c] = ns2[c]}}) };\n';
-            }*/
+        //if (moduleName !== 'core') {
+        dependenciesText += `var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
+            var BABYLON = globalObject["BABYLON"] || {};
+`;
+        /*} else {
+            dependenciesText += `var BABYLON;
+`;
+        }*/
 
-            dependencies.forEach(function (d, idx) {
-                let name = d === 'core' ? 'BABYLON' : d;
-                dependenciesText += `import * as ${name} from 'babylonjs/${d}/es6';
+        let exportsText = '';
+        if (!generateIndex) {
+
+            // process parenting!
+            let parentRegex = /__extends\(([A-Z]\w*), _super\)/g;
+            var match = parentRegex.exec(content);
+            while (match != null) {
+                let extendingClass = match[1];
+                // find the first row
+                let extendedMatcher = new RegExp("}\\([BABYLON\\.]*([A-Z]\\w*)\\)\\);\\n\\s*BABYLON." + extendingClass + " = " + extendingClass + ";");
+
+                let extendedArray = extendedMatcher.exec(content);
+                if (extendedArray) {
+                    let firstRowReg = new RegExp("var " + extendingClass + " = .* \\(function");
+                    content = content.replace(firstRowReg, "var " + extendingClass + " = function");
+
+                    extended = extendedArray[1];
+                    content = content.replace(extendedMatcher, `};
+    var CLS${extendingClass};
+    BABYLON.__${extendingClass} = function() {
+        CLS${extendingClass} = CLS${extendingClass} || ${extendingClass}.call(null, BABYLON.__${extended} && BABYLON.__${extended}() || BABYLON.${extended});
+    }
+    Object.defineProperty(BABYLON, "${extendingClass}", {
+        get: function () {
+            BABYLON.__${extendingClass}();
+            return CLS${extendingClass};
+        },
+        enumerable: true,
+        configurable: true
+    });`);
+                    console.log(extendingClass, extended);
+                } else {
+                    console.log(extendingClass + " is not exported");
+                }
+
+                match = parentRegex.exec(content);
+            }
+
+            let loadedFiles = [];
+            dependencyTree[basename].forEach(function (d, idx) {
+                //if (d.module.indexOf("core") !== -1) return;
+                let name = d.file.split(".").pop();
+
+                if (loadedFiles.indexOf(name) === -1/* && !d.newDec*/) {
+                    let regexp = new RegExp("BABYLON." + d.name);
+                    let match = regexp.exec(content);
+                    if (!match) return;
+                    if (d.main)
+                        dependenciesText += `import {${d.name}} from 'babylonjs/${d.module[0]}/es6/${name}';
 `;
-                if (idx > 0) {
-                    dependenciesText += `__extends(BABYLON, ${d});
+                    else
+                        exportsText += `import {${d.name}} from 'babylonjs/${d.module[0]}/es6/${name}';
 `;
+                    loadedFiles.push(name);
                 }
+                //dependenciesText += `if(BABYLON !== BABYLON${idx}) __extends(BABYLON, BABYLON${idx});
             });
+            let exported = [];
+            perFile[basename].declarations.forEach(dec => {
+                if (exported.indexOf(dec) !== -1) return;
+                exported.push(dec);
+                exportsText += `var ${dec} = BABYLON.${dec}; export {${dec}};
+`;
+            });
+            if (shaders) {
+                dependenciesText += `import * as Shaders from "babylonjs/${moduleName}/es6/shaders";
+if(BABYLON.Effect) Object.keys(Shaders).forEach(function(shaderName) {BABYLON.Effect.ShadersStore[shaderName] = Shaders[shaderName]})
+`;
+            }
+            if (shaderIncludes) {
+                dependenciesText += `import * as ShaderIncludes from "babylonjs/${moduleName}/es6/shaderIncludes";
+if(BABYLON.Effect) Object.keys(ShaderIncludes).forEach(function(shaderName) {BABYLON.Effect.IncludesShadersStore[shaderName] = ShaderIncludes[shaderName]})
+`;
+            }
+
+            //if (moduleName === "core") {
+            exportsText += `(function() {
+    //var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
+    globalObject["BABYLON"] = globalObject["BABYLON"] || BABYLON;
+})();
+`;
+            //}
+        } else {
+            content = '';
+            let basenames = Object.keys(perFile).filter(basefilename => {
+                return perFile[basefilename].module.indexOf(moduleName) !== -1;
+            });
+
+            basenames.forEach(bname => {
+                let name = bname.split(".").pop();
+                dependenciesText += `export * from "babylonjs/${moduleName}/es6/${name}";
+`;
+            })
         }
 
 
 
-        let exportRegex = /BABYLON.([0-9A-Za-z-_]*) = .*;\n/g
+        /*exportsText += `(function() {
+    globalObject["BABYLON"] = globalObject["BABYLON"] || BABYLON;
+    })();
+`;*/
 
+        /*if (dependencies) {
+            dependencies.forEach(function (d, idx) {
+                if (d === 'core') return;
+                dependenciesText += `import * as ${d} from 'babylonjs/${d}/es6';
+`;
+                //if (idx > 0) {
+                dependenciesText += `__extends(BABYLON, ${d});
+`;
+                //}
+            });
+        }
+ 
+ 
+ 
+        let exportRegex = /BABYLON.([0-9A-Za-z-_]*) = .*;\n/g
+ 
         var match = exportRegex.exec(content);
-
+ 
         let exportsArray = [];
         while (match != null) {
             if (match[1]) {
@@ -68,16 +164,16 @@ ${decorateAddition}
             }
             match = exportRegex.exec(content);
         }
-
+ 
         let exportsText = '';
         if (moduleName === "core") {
             exportsText = `(function() {
     var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
     globalObject["BABYLON"] = BABYLON;
-})();;
+})();
 `
         }
-
+ 
         let exportedItems = '';
         exportsArray.forEach((e, idx) => {
             if (e.indexOf('.') === -1) {
@@ -86,9 +182,16 @@ ${decorateAddition}
 `
             }
         });
-
+ 
         exportsText += `
-export { ${exportedItems} };`
+export { ${exportedItems} };`*/
+
+        /*if (moduleName === "core") {
+            exportsText = `(function() {
+var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : this);
+globalObject["BABYLON"] = BABYLON;
+})();
+`*/
 
         if (file.isNull()) {
             cb(null, file);
@@ -101,7 +204,7 @@ export { ${exportedItems} };`
         }
 
         try {
-            file.contents = new Buffer(dependenciesText.concat(new Buffer(String(file.contents).concat(exportsText))));
+            file.contents = new Buffer(dependenciesText.concat(new Buffer(String(content).concat(exportsText))));
             this.push(file);
         } catch (err) {
             this.emit('error', new gutil.PluginError('gulp-es6-module-exports', err, { fileName: file.path }));

+ 122 - 28
Tools/Gulp/gulpfile.js

@@ -6,9 +6,11 @@ var srcToVariable = require("gulp-content-to-variable");
 var appendSrcToVariable = require("./gulp-appendSrcToVariable");
 var addDtsExport = require("./gulp-addDtsExport");
 var addModuleExports = require("./gulp-addModuleExports");
+var addES6Exports = require("./gulp-addES6Exports");
 var babylonModuleExports = require("./gulp-babylonModule");
 var babylonES6ModuleExports = require("./gulp-es6ModuleExports");
 var dtsModuleSupport = require("./gulp-dtsModuleSupport");
+let calculateDependencies = require("./gulp-calculateDependencies");
 var merge2 = require("merge2");
 var concat = require("gulp-concat");
 var rename = require("gulp-rename");
@@ -81,8 +83,8 @@ var commandLineOptions = minimist(process.argv.slice(2), {
     boolean: "public"
 });
 
-function processDependency(kind, dependency, filesToLoad) {
-    if (dependency.dependUpon) {
+function processDependency(kind, dependency, filesToLoad, firstLevelOnly) {
+    if (!firstLevelOnly && dependency.dependUpon) {
         for (var i = 0; i < dependency.dependUpon.length; i++) {
             var dependencyName = dependency.dependUpon[i];
             var parent = config.workloads[dependencyName];
@@ -211,23 +213,33 @@ gulp.task("buildWorker", ["workers", "shaders"], function () {
 gulp.task("build", ["shaders"], function () {
     var filesToProcess = determineFilesToProcess("files");
     var directFilesToProcess = determineFilesToProcess("directFiles");
-    return merge2(
+    let mergedStreams = merge2(
         gulp.src(filesToProcess).
             pipe(expect.real({ errorOnFailure: true }, filesToProcess)),
         shadersStream,
         includeShadersStream,
         gulp.src(directFilesToProcess)
     )
-        .pipe(concat(config.build.filename))
-        .pipe(cleants())
-        .pipe(replace(extendsSearchRegex, ""))
-        .pipe(replace(decorateSearchRegex, ""))
-        .pipe(addModuleExports("BABYLON"))
-        .pipe(gulp.dest(config.build.outputDirectory))
-        .pipe(rename(config.build.minFilename))
-        .pipe(uglify())
-        .pipe(optimisejs())
-        .pipe(gulp.dest(config.build.outputDirectory));
+    return merge2(
+        mergedStreams
+            .pipe(concat(config.build.filename))
+            .pipe(cleants())
+            .pipe(replace(extendsSearchRegex, ""))
+            .pipe(replace(decorateSearchRegex, ""))
+            .pipe(addModuleExports("BABYLON"))
+            .pipe(gulp.dest(config.build.outputDirectory))
+            .pipe(rename(config.build.minFilename))
+            .pipe(uglify())
+            .pipe(optimisejs())
+            .pipe(gulp.dest(config.build.outputDirectory)),
+        mergedStreams
+            .pipe(concat("es6.js"))
+            .pipe(cleants())
+            .pipe(replace(extendsSearchRegex, ""))
+            .pipe(replace(decorateSearchRegex, ""))
+            .pipe(addES6Exports("BABYLON"))
+            .pipe(gulp.dest(config.build.outputDirectory))
+    );
 });
 
 /*
@@ -610,48 +622,128 @@ gulp.task("modules-compile", function () {
 
 // this holds the declared objects in each module
 let declared = {}
+let perFile = {};
+let dependencyTree = {};
 
-gulp.task('prepare-for-modules', ["modules-compile"], function () {
+gulp.task('prepare-for-modules', /*["modules-compile"],*/ function () {
     let tasks = [];
     Object.keys(config.workloads).forEach((moduleName) => {
         let dtsFiles = config.workloads[moduleName].files.map(f => f.replace(".js", ".d.ts"))
         let dtsTask = gulp.src(dtsFiles)
-            .pipe(dtsModuleSupport(moduleName, false, declared));
+            .pipe(dtsModuleSupport(moduleName, false, declared, perFile));
 
         tasks.push(dtsTask);
     });
 
+    // now calculate internal dependencies in the .ts files!
+    /*Object.keys(config.workloads).forEach((moduleName) => {
+        let tsFiles = config.workloads[moduleName].files.map(f => f.replace(".js", ".ts"))
+        let depTask = gulp.src(tsFiles)
+            .pipe(calculateDependencies(moduleName, perFile, dependencyTree));
+
+        tasks.push(depTask);
+    });*/
+
+    return merge2(tasks);
+});
+
+gulp.task('prepare-dependency-tree', ["prepare-for-modules"], function () {
+    let tasks = [];
+
+    // now calculate internal dependencies in the .ts files!
+    Object.keys(config.workloads).forEach((moduleName) => {
+        let tsFiles = config.workloads[moduleName].files.map(f => f.replace(".js", ".ts"))
+        let depTask = gulp.src(tsFiles)
+            .pipe(calculateDependencies(moduleName, perFile, declared, dependencyTree));
+
+        tasks.push(depTask);
+    });
+
     return merge2(tasks);
 });
 
 // generate the modules directory, along with commonjs modules and es6 modules
 // Note - the generated modules are UNMINIFIED! The user will choose whether they want to minify or not.
-gulp.task("modules", ["prepare-for-modules"], function () {
+gulp.task("modules", ["prepare-dependency-tree"], function () {
     let tasks = [];
 
     Object.keys(config.workloads)
         .forEach((moduleName) => {
             let shadersFiles = [];
-            processDependency("shaders", config.workloads[moduleName], shadersFiles);
+            processDependency("shaders", config.workloads[moduleName], shadersFiles, true);
             for (var index = 0; index < shadersFiles.length; index++) {
                 shadersFiles[index] = "../../src/Shaders/" + shadersFiles[index] + ".fx";
             }
 
             let shaderIncludeFiles = [];
-            processDependency("shaderIncludes", config.workloads[moduleName], shaderIncludeFiles);
+            processDependency("shaderIncludes", config.workloads[moduleName], shaderIncludeFiles, true);
             for (var index = 0; index < shaderIncludeFiles.length; index++) {
                 shaderIncludeFiles[index] = "../../src/Shaders/ShadersInclude/" + shaderIncludeFiles[index] + ".fx";
             }
 
+            let commonJsTask = merge2([
+                gulp.src(config.workloads[moduleName].files)
+                    .pipe(replace(extendsSearchRegex, ""))
+                    .pipe(replace(decorateSearchRegex, ""))
+                    .pipe(replace(referenceSearchRegex, ""))
+                    .pipe(replace(/var BABYLON;\n/g, ""))
+                    .pipe(babylonModuleExports(moduleName, dependencyTree, false, perFile, shadersFiles.length, shaderIncludeFiles.length))
+                    .pipe(rename(function (path) {
+                        path.basename = path.basename.split(".").pop()
+                        path.extname = ".js"
+                    })),
+                gulp.src(shadersFiles)
+                    .pipe(expect.real({ errorOnFailure: true }, shadersFiles))
+                    .pipe(uncommentShader())
+                    .pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".fx", "commonjs"))
+                    .pipe(rename("shaders.js")),
+                gulp.src(shaderIncludeFiles)
+                    .pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles))
+                    .pipe(uncommentShader())
+                    .pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".include.fx", "commonjs"))
+                    .pipe(rename("shaderIncludes.js")),
+                gulp.src(config.workloads[moduleName].files)
+                    .pipe(concat('index.js'))
+                    .pipe(babylonModuleExports(moduleName, dependencyTree, true, perFile))
+
+            ]).pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'))
+
+            let es6Tasks = merge2([
+                gulp.src(config.workloads[moduleName].files)
+                    .pipe(replace(extendsSearchRegex, ""))
+                    .pipe(replace(decorateSearchRegex, ""))
+                    .pipe(replace(referenceSearchRegex, ""))
+                    .pipe(replace(/var BABYLON;\n/g, ""))
+                    .pipe(babylonES6ModuleExports(moduleName, dependencyTree, false, perFile, shadersFiles.length, shaderIncludeFiles.length))
+                    .pipe(rename(function (path) {
+                        path.basename = path.basename.split(".").pop()
+                        path.extname = ".js"
+                    })),
+                gulp.src(shadersFiles)
+                    .pipe(expect.real({ errorOnFailure: true }, shadersFiles))
+                    .pipe(uncommentShader())
+                    .pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, config.build.outputDirectory + '/es6/' + moduleName + ".fx", "es6"))
+                    .pipe(rename("shaders.js")),
+                gulp.src(shaderIncludeFiles)
+                    .pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles))
+                    .pipe(uncommentShader())
+                    .pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, config.build.outputDirectory + '/es6/' + moduleName + ".include.fx", "es6"))
+                    .pipe(rename("shaderIncludes.js")),
+                gulp.src(config.workloads[moduleName].files)
+                    .pipe(concat('index.js'))
+                    .pipe(babylonES6ModuleExports(moduleName, dependencyTree, true, perFile))
+
+            ]).pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/es6/'))
+
             //commonjs js generation task
-            let jsTask = merge2([
+            /*let jsTask = merge2([
                 gulp.src(config.workloads[moduleName].files),
                 gulp.src(shadersFiles).
-                    pipe(expect.real({ errorOnFailure: true }, shadersFiles)).
+                    //pipe(expect.real({ errorOnFailure: true }, shadersFiles)).
                     pipe(uncommentShader()).
                     pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".fx", true)),
                 gulp.src(shaderIncludeFiles).
-                    pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles)).
+                    //pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles)).
                     pipe(uncommentShader()).
                     pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".include.fx", true))
             ]).pipe(concat('index.js'))
@@ -659,23 +751,25 @@ gulp.task("modules", ["prepare-for-modules"], function () {
                 .pipe(replace(decorateSearchRegex, ""))
                 .pipe(replace(referenceSearchRegex, ""))
                 .pipe(babylonModuleExports(moduleName, config.workloads[moduleName].dependUpon))
-                .pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'));
+                .pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'));*/
+
 
             // es6 modules generation task
-            let es6Task = merge2([
+            /*let es6Task = merge2([
                 gulp.src(config.workloads[moduleName].files),
                 gulp.src(shadersFiles).
-                    pipe(expect.real({ errorOnFailure: true }, shadersFiles)).
+                    //pipe(expect.real({ errorOnFailure: true }, shadersFiles)).
                     pipe(uncommentShader()).
                     pipe(appendSrcToVariable("BABYLON.Effect.ShadersStore", shadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".fx", true)),
                 gulp.src(shaderIncludeFiles).
-                    pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles)).
+                    //pipe(expect.real({ errorOnFailure: true }, shaderIncludeFiles)).
                     pipe(uncommentShader()).
                     pipe(appendSrcToVariable("BABYLON.Effect.IncludesShadersStore", includeShadersName, config.build.outputDirectory + '/commonjs/' + moduleName + ".include.fx", true))
             ]).pipe(concat('es6.js'))
                 .pipe(replace(extendsSearchRegex, ""))
                 .pipe(replace(decorateSearchRegex, ""))
                 .pipe(replace(referenceSearchRegex, ""))
+                .pipe(replace(/var BABYLON;/g, ""))
                 .pipe(babylonES6ModuleExports(moduleName, config.workloads[moduleName].dependUpon))
                 .pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'));
 
@@ -685,10 +779,10 @@ gulp.task("modules", ["prepare-for-modules"], function () {
                 .pipe(concat("index.d.ts"))
                 .pipe(replace(/declare module BABYLON {/g, `declare module 'babylonjs/${moduleName}' {`))
                 .pipe(replace(/\ninterface /g, `\nexport interface `))
-                .pipe(dtsModuleSupport(moduleName, true, declared))
+                .pipe(dtsModuleSupport(moduleName, true, declared, perFile, dependencyTree))
                 .pipe(gulp.dest(config.build.outputDirectory + '/modules/' + moduleName + '/'));
-
-            tasks.push(jsTask, es6Task, dtsTask);
+*/
+            tasks.push(commonJsTask, es6Tasks);
         });
 
     // run da tasks man!

+ 7 - 2
Tools/Publisher/index.js

@@ -87,6 +87,10 @@ function processCore(package, version) {
             objectName: "babylon.d.ts"
         },
         {
+            path: basePath + "/es6.js",
+            objectName: "es6.js"
+        },
+        {
             path: basePath + "/babylon.js",
             objectName: "babylon.js"
         },
@@ -108,7 +112,8 @@ function processCore(package, version) {
         }
     ];
 
-    fs.readdirSync(basePath + '/modules/').forEach(object => {
+    // remove the modules for now
+    /*fs.readdirSync(basePath + '/modules/').forEach(object => {
         console.log(object);
         if (fs.statSync(basePath + '/modules/' + object).isDirectory) {
             files.push({
@@ -117,7 +122,7 @@ function processCore(package, version) {
                 isDir: true
             });
         }
-    })
+    })*/
 
     //copy them to the package path
     files.forEach(file => {

+ 3 - 3
src/Lights/babylon.shadowLight.ts

@@ -117,15 +117,15 @@
         }
 
         /**
-         * Returns the DirectionalLight absolute position in the World.
+         * Returns the ShadowLight absolute position in the World.
          */
         public getAbsolutePosition(): Vector3 {
             return this.transformedPosition ? this.transformedPosition : this.position;
         }
 
         /**
-         * Sets the DirectionalLight direction toward the passed target (Vector3).
-         * Returns the updated DirectionalLight direction (Vector3).
+         * Sets the ShadowLight direction toward the passed target (Vector3).
+         * Returns the updated ShadowLight direction (Vector3).
          */
         public setDirectionToTarget(target: Vector3): Vector3 {
             this.direction = Vector3.Normalize(target.subtract(this.position));

+ 1 - 1
src/Tools/babylon.textureTools.ts

@@ -63,7 +63,7 @@
             return rtt;
         }
 
-        public static GetEnvironmentBRDFTexture(scene: Scene) {
+        public static GetEnvironmentBRDFTexture(scene: Scene): BaseTexture {
             if (!scene._environmentBRDFTexture) {
                 var texture = Texture.CreateFromBase64String(this._environmentBRDFBase64Texture, "EnvironmentBRDFTexture", scene, true, false, Texture.BILINEAR_SAMPLINGMODE);