Procházet zdrojové kódy

Merge remote-tracking branch 'upstream/master'

sebastien před 7 roky
rodič
revize
ea436583ac

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 10021 - 9473
Playground/babylon.d.txt


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 8461 - 7913
dist/preview release/babylon.d.ts


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 1
dist/preview release/babylon.js


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 584 - 146
dist/preview release/babylon.max.js


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 584 - 146
dist/preview release/babylon.no-module.max.js


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 1
dist/preview release/babylon.worker.js


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 584 - 146
dist/preview release/es6.js


+ 1 - 1
dist/preview release/gui/babylon.gui.d.ts

@@ -1,6 +1,6 @@
 /*BabylonJS GUI*/
 // Dependencies for this module:
-//   ../../../../Tools/Gulp/babylonjs
+//   ../../../../Tools/gulp/babylonjs
 declare module BABYLON.GUI {
 }
 declare module BABYLON.GUI {

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 1
dist/preview release/gui/babylon.gui.min.js.map


+ 2 - 2
dist/preview release/gui/babylon.gui.module.d.ts

@@ -1,6 +1,6 @@
 /*BabylonJS GUI*/
 // Dependencies for this module:
-//   ../../../../Tools/Gulp/babylonjs
+//   ../../../../Tools/gulp/babylonjs
 
 declare module 'babylonjs-gui' {
     export * from "babylonjs-gui/2D";
@@ -2826,7 +2826,7 @@ declare module 'babylonjs-gui/3D/materials/fluentMaterial' {
 
 /*BabylonJS GUI*/
 // Dependencies for this module:
-//   ../../../../Tools/Gulp/babylonjs
+//   ../../../../Tools/gulp/babylonjs
 declare module BABYLON.GUI {
 }
 declare module BABYLON.GUI {

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 1
dist/preview release/inspector/babylon.inspector.bundle.js.map


+ 1 - 1
dist/preview release/inspector/babylon.inspector.d.ts

@@ -1,6 +1,6 @@
 /*BabylonJS Inspector*/
 // Dependencies for this module:
-//   ../../../../Tools/Gulp/babylonjs
+//   ../../../../Tools/gulp/babylonjs
 declare module INSPECTOR {
 }
 declare module INSPECTOR {

+ 2 - 2
dist/preview release/inspector/babylon.inspector.module.d.ts

@@ -1,6 +1,6 @@
 /*BabylonJS Inspector*/
 // Dependencies for this module:
-//   ../../../../Tools/Gulp/babylonjs
+//   ../../../../Tools/gulp/babylonjs
 
 declare module 'babylonjs-inspector' {
     export * from 'babylonjs-inspector/adapters';
@@ -1343,7 +1343,7 @@ declare module 'babylonjs-inspector/treetools/SoundInteractions' {
 
 /*BabylonJS Inspector*/
 // Dependencies for this module:
-//   ../../../../Tools/Gulp/babylonjs
+//   ../../../../Tools/gulp/babylonjs
 declare module INSPECTOR {
 }
 declare module INSPECTOR {

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 272 - 1488
dist/preview release/typedocValidationBaseline.json


+ 3 - 24
dist/preview release/viewer/babylon.viewer.d.ts

@@ -4,8 +4,8 @@
 declare module "babylonjs-loaders"{ export=BABYLON;}
 // Generated by dts-bundle v0.7.3
 // Dependencies for this module:
-//   ../../../../../Tools/Gulp/babylonjs
-//   ../../../../../Tools/Gulp/babylonjs-loaders
+//   ../../../../../Tools/gulp/babylonjs
+//   ../../../../../Tools/gulp/babylonjs-loaders
 declare module BabylonViewer {
     /**
         * BabylonJS Viewer
@@ -924,7 +924,7 @@ declare module BabylonViewer {
       * @param name the name of the custom optimizer configuration
       * @param upgrade set to true if you want to upgrade optimizer and false if you want to degrade
       */
-    export function getCustomOptimizerByName(name: string, upgrade?: boolean): typeof extendedUpgrade;
+    export function getCustomOptimizerByName(name: string, upgrade?: boolean): (sceneManager: SceneManager) => boolean;
     export function registerCustomOptimizer(name: string, optimizer: (sceneManager: SceneManager) => boolean): void;
 }
 declare module BabylonViewer {
@@ -1558,20 +1558,6 @@ declare module BabylonViewer {
     export function addLoaderPlugin(name: string, plugin: ILoaderPlugin): void;
 }
 declare module BabylonViewer {
-    /**
-        * A custom upgrade-oriented function configuration for the scene optimizer.
-        *
-        * @param viewer the viewer to optimize
-        */
-    export function extendedUpgrade(sceneManager: SceneManager): boolean;
-    /**
-        * A custom degrade-oriented function configuration for the scene optimizer.
-        *
-        * @param viewer the viewer to optimize
-        */
-    export function extendedDegrade(sceneManager: SceneManager): boolean;
-}
-declare module BabylonViewer {
 }
 declare module BabylonViewer {
     export interface IEnvironmentMapConfiguration {
@@ -1733,13 +1719,6 @@ declare module BabylonViewer {
     }
 }
 declare module BabylonViewer {
-    /**
-      * A (PBR) material will be extended using this function.
-      * This function will hold extra default configuration for the viewer, if not implemented in Babylon itself.
-      */
-    export class ExtendedMaterialLoaderPlugin implements ILoaderPlugin {
-        onMaterialLoaded(baseMaterial: BABYLON.Material): void;
-    }
 }
 declare module BabylonViewer {
     export interface ICameraConfiguration {

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1 - 1
dist/preview release/viewer/babylon.viewer.js


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 4 - 4
dist/preview release/viewer/babylon.viewer.max.js


+ 4 - 29
dist/preview release/viewer/babylon.viewer.module.d.ts

@@ -5,8 +5,8 @@ declare module "babylonjs-loaders"{ export=BABYLON;}
 
 // Generated by dts-bundle v0.7.3
 // Dependencies for this module:
-//   ../../../../../Tools/Gulp/babylonjs
-//   ../../../../../Tools/Gulp/babylonjs-loaders
+//   ../../../../../Tools/gulp/babylonjs
+//   ../../../../../Tools/gulp/babylonjs-loaders
 
 declare module 'babylonjs-viewer' {
     import { mapperManager } from 'babylonjs-viewer/configuration/mappers';
@@ -985,14 +985,13 @@ declare module 'babylonjs-viewer/templating/viewerTemplatePlugin' {
 }
 
 declare module 'babylonjs-viewer/optimizer/custom' {
-    import { extendedUpgrade } from "babylonjs-viewer/optimizer/custom/extended";
     import { SceneManager } from "babylonjs-viewer/managers/sceneManager";
     /**
       *
       * @param name the name of the custom optimizer configuration
       * @param upgrade set to true if you want to upgrade optimizer and false if you want to degrade
       */
-    export function getCustomOptimizerByName(name: string, upgrade?: boolean): typeof extendedUpgrade;
+    export function getCustomOptimizerByName(name: string, upgrade?: boolean): (sceneManager: SceneManager) => boolean;
     export function registerCustomOptimizer(name: string, optimizer: (sceneManager: SceneManager) => boolean): void;
 }
 
@@ -1663,22 +1662,6 @@ declare module 'babylonjs-viewer/loader/plugins' {
     export function addLoaderPlugin(name: string, plugin: ILoaderPlugin): void;
 }
 
-declare module 'babylonjs-viewer/optimizer/custom/extended' {
-    import { SceneManager } from 'babylonjs-viewer/managers/sceneManager';
-    /**
-        * A custom upgrade-oriented function configuration for the scene optimizer.
-        *
-        * @param viewer the viewer to optimize
-        */
-    export function extendedUpgrade(sceneManager: SceneManager): boolean;
-    /**
-        * A custom degrade-oriented function configuration for the scene optimizer.
-        *
-        * @param viewer the viewer to optimize
-        */
-    export function extendedDegrade(sceneManager: SceneManager): boolean;
-}
-
 declare module 'babylonjs-viewer/configuration/interfaces' {
     export * from 'babylonjs-viewer/configuration/interfaces/cameraConfiguration';
     export * from 'babylonjs-viewer/configuration/interfaces/colorGradingConfiguration';
@@ -1877,15 +1860,7 @@ declare module 'babylonjs-viewer/loader/plugins/applyMaterialConfig' {
 }
 
 declare module 'babylonjs-viewer/loader/plugins/extendedMaterialLoaderPlugin' {
-    import { Material } from 'babylonjs';
-    import { ILoaderPlugin } from 'babylonjs-viewer/loader/plugins/loaderPlugin';
-    /**
-      * A (PBR) material will be extended using this function.
-      * This function will hold extra default configuration for the viewer, if not implemented in Babylon itself.
-      */
-    export class ExtendedMaterialLoaderPlugin implements ILoaderPlugin {
-        onMaterialLoaded(baseMaterial: Material): void;
-    }
+    
 }
 
 declare module 'babylonjs-viewer/configuration/interfaces/cameraConfiguration' {

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

@@ -128,6 +128,8 @@
 - Added FXAA and MSAA support to the StandardRenderingPipeline ([julien-moreau](https://github.com/julien-moreau))
 - Make teleportCamera public in VR experience helper ([TrevorDev](https://github.com/TrevorDev))
 - Added optional alphaFilter parameter to ```CreateGroundFromHeightMap``` to allow for heightmaps to be created that ignore any transparent data ([Postman-nz](https://github.com/Postman-nz))
+- Fixed renormalization of mesh weights to in cleanMatrixWeights function. ([Bolloxim](https://github.com/Bolloxim))
+- Added a validationSkin function to report out any errors on skinned meshes. ([Bolloxim](https://github.com/Bolloxim))
 
 
 ### glTF Loader
@@ -140,6 +142,7 @@
 - Added support for MSFT_audio_emitter ([najadojo](http://www.github.com/najadojo))
 - Added support for custom loader extensions ([bghgary](http://www.github.com/bghgary))
 - Added support for validating assets using [glTF-Validator](https://github.com/KhronosGroup/glTF-Validator) ([bghgary](http://www.github.com/bghgary))
+- Added automatically renormalizes skinweights when loading geometry. Calls core mesh functions to do this ([Bolloxim](https://github.com/Bolloxim))
 
 ### glTF Serializer
 - Added support for exporting the scale, rotation and offset texture properties ([kcoley](http://www.github.com/kcoley))

+ 4 - 0
readme.md

@@ -124,3 +124,7 @@ If you want to contribute, please read our [contribution guidelines](https://git
 ## Features
 
 To get a complete list of supported features, please visit our [website](https://www.babylonjs.com/#specifications).
+
+## Build
+
+Babylon.js is automatically built using [Gulp](https://gulpjs.com/). For further instructions see the readme at [/Tools/Gulp](https://github.com/BabylonJS/Babylon.js/tree/master/Tools/Gulp).

+ 1 - 1
src/Cameras/babylon.camera.ts

@@ -780,7 +780,7 @@
             if (!origin) {
                 origin = this.position;
             }
-            var forward = new Vector3(0, 0, 1);
+            var forward = this._scene.useRightHandedSystem ? new Vector3(0, 0, -1) : new Vector3(0, 0, 1);
             var forwardWorld = Vector3.TransformNormal(forward, transform);
 
             var direction = Vector3.Normalize(forwardWorld);

+ 6 - 2
src/Cameras/babylon.targetCamera.ts

@@ -350,6 +350,7 @@
         }
 
         private _cachedRotationZ = 0;
+        private _cachedQuaternionRotationZ = 0;
         /** @hidden */
         public _getViewMatrix(): Matrix {
             if (this.lockedTarget) {
@@ -359,8 +360,11 @@
             // Compute
             this._updateCameraRotationMatrix();
 
-            // Apply the changed rotation to the upVector.
-            if (this._cachedRotationZ != this.rotation.z) {
+            // Apply the changed rotation to the upVector
+            if (this.rotationQuaternion && this._cachedQuaternionRotationZ != this.rotationQuaternion.z) {
+                this._rotateUpVectorWithCameraRotationMatrix();
+                this._cachedQuaternionRotationZ = this.rotationQuaternion.z;
+            } else if (this._cachedRotationZ != this.rotation.z) {
                 this._rotateUpVectorWithCameraRotationMatrix();
                 this._cachedRotationZ = this.rotation.z;
             }

+ 1 - 1
src/Materials/babylon.shaderMaterial.ts

@@ -111,7 +111,7 @@
          * @returns a boolean specifying if alpha blending is needed
          */
         public needAlphaBlending(): boolean {
-            return (this.alpha < 1.0);
+            return (this.alpha < 1.0) || this._options.needAlphaBlending;
         }
 
         /**

+ 143 - 59
src/Mesh/babylon.mesh.ts

@@ -1621,80 +1621,164 @@
         }
 
         /**
-         * Normalize matrix weights so that all vertices have a total weight set to 1
+         *   Renormalize the mesh and patch it up if there are no weights
+         *   Similar to normalization by adding the weights compute the reciprocal and multiply all elements, this wil ensure that everything adds to 1. 
+         *   However in the case of zero weights then we set just a single influence to 1. 
+         *   We check in the function for extra's present and if so we use the normalizeSkinWeightsWithExtras rather than the FourWeights version. 
          */
         public cleanMatrixWeights(): void {
-            const epsilon: number = 1e-3;
 
-            let noInfluenceBoneIndex = 0.0;
-            if (this.skeleton) {
-                noInfluenceBoneIndex = this.skeleton.bones.length;
-            } else {
-                return;
-            }
+            if (this.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {
+                if (this.isVerticesDataPresent(VertexBuffer.MatricesWeightsExtraKind)) {
+                    this.normalizeSkinWeightsAndExtra();
+                }
+                else {
+                    this.normalizeSkinFourWeights();
+                }
+            }    
+        }
+
+        // faster 4 weight version. 
+        private normalizeSkinFourWeights(): void {
 
-            let matricesIndices = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesIndicesKind));
-            let matricesIndicesExtra = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesIndicesExtraKind));
             let matricesWeights = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesWeightsKind));
-            let matricesWeightsExtra = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind));
-            let influencers = this.numBoneInfluencers;
-            let size = matricesWeights.length;
-
-            for (var i = 0; i < size; i += 4) {
-                let weight = 0.0;
-                let firstZeroWeight = -1;
-                for (var j = 0; j < 4; j++) {
-                    let w = matricesWeights[i + j];
-                    weight += w;
-                    if (w < epsilon && firstZeroWeight < 0) {
-                        firstZeroWeight = j;
-                    }
+            let numWeights = matricesWeights.length;
+
+            for (var a = 0; a < numWeights; a += 4) {
+                // accumulate weights
+                var t = matricesWeights[a] + matricesWeights[a+1] +matricesWeights[a+2] +matricesWeights[a+3];
+                // check for invalid weight and just set it to 1.
+                if (t === 0) matricesWeights[a] = 1;
+                else{
+                    // renormalize so everything adds to 1 use reciprical
+                    let recip = 1 / t;
+                    matricesWeights[a] *= recip;
+                    matricesWeights[a+1] *= recip;
+                    matricesWeights[a+2] *= recip;
+                    matricesWeights[a+3] *= recip;
                 }
-                if (matricesWeightsExtra) {
-                    for (var j = 0; j < 4; j++) {
-                        let w = matricesWeightsExtra[i + j];
-                        weight += w;
-                        if (w < epsilon && firstZeroWeight < 0) {
-                            firstZeroWeight = j + 4;
-                        }
-                    }
+                
+            }
+            this.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeights);
+        }
+        // handle special case of extra verts.  (in theory gltf can handle 12 influences)
+        private normalizeSkinWeightsAndExtra(): void {
+            
+            let matricesWeightsExtra = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind));
+            let matricesWeights = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesWeightsKind));
+            let numWeights = matricesWeights.length;
+
+            for (var a = 0; a  < numWeights; a += 4){
+                // accumulate weights
+                var t = matricesWeights[a] + matricesWeights[a+1] +matricesWeights[a+2] +matricesWeights[a+3];
+                t += matricesWeightsExtra[a] + matricesWeightsExtra[a+1] +matricesWeightsExtra[a+2] +matricesWeightsExtra[a+3];
+                // check for invalid weight and just set it to 1.
+                if (t === 0) matricesWeights[a] = 1;
+                else {
+                    // renormalize so everything adds to 1 use reciprical 
+                    let recip = 1 / t;
+                    matricesWeights[a] *= recip;
+                    matricesWeights[a+1] *= recip;
+                    matricesWeights[a+2] *= recip;
+                    matricesWeights[a+3] *= recip;
+                    // same goes for extras
+                    matricesWeightsExtra[a] *= recip;
+                    matricesWeightsExtra[a+1] *= recip;
+                    matricesWeightsExtra[a+2] *= recip;
+                    matricesWeightsExtra[a+3] *= recip;
                 }
-                if (firstZeroWeight < 0 || firstZeroWeight > (influencers - 1)) {
-                    firstZeroWeight = influencers - 1;
+                
+            }
+            this.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeights);
+            this.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeightsExtra);
+        }
+
+        /**
+         * ValidateSkinning is used to determine that a mesh has valid skinning data along with skin metrics, if missing weights, 
+         * or not normalized it is returned as invalid mesh the string can be used for console logs, or on screen messages to let
+         * the user know there was an issue with importing the mesh
+         * @returns a validation object with skinned, valid and report string
+         */
+        public validateSkinning() : {skinned:boolean, valid:boolean, report:string} {
+
+            let matricesWeightsExtra = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind));
+            let matricesWeights = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesWeightsKind));
+            if (matricesWeights === null || this.skeleton == null) {
+                return {skinned:false, valid: true, report:"not skinned"}
+            }
+
+            let numWeights = matricesWeights.length;
+            let numberNotSorted : number = 0;
+            let missingWeights : number  = 0;
+            let maxUsedWeights : number  = 0;
+            let numberNotNormalized :number  = 0;
+            let numInfluences : number  = matricesWeightsExtra === null ? 4 : 8;
+            var usedWeightCounts = new Array<number>();
+            for (var a = 0; a <= numInfluences; a++) { 
+                usedWeightCounts[a] = 0;
+            }
+            const toleranceEpsilon : number = 0.001;
+
+            for (var a = 0; a < numWeights; a += 4) {
+
+                let lastWeight : number = matricesWeights[a];
+                var t = lastWeight;
+                let usedWeights : number = t===0 ? 0 : 1;
+
+                for (var b = 1; b < numInfluences; b++) {
+                    var d = b < 4 ? matricesWeights[a + b] : matricesWeightsExtra[a + b-4];
+                    if (d > lastWeight) numberNotSorted++;
+                    if (d !== 0) usedWeights++;
+                    t += d;
+                    lastWeight = d;
                 }
-                if (weight > epsilon) {
-                    let mweight = 1.0 / weight;
-                    for (var j = 0; j < 4; j++) {
-                        matricesWeights[i + j] *= mweight;
-                    }
-                    if (matricesWeightsExtra) {
-                        for (var j = 0; j < 4; j++) {
-                            matricesWeightsExtra[i + j] *= mweight;
-                        }
-                    }
-                } else {
-                    if (firstZeroWeight >= 4) {
-                        matricesWeightsExtra[i + firstZeroWeight - 4] = 1.0 - weight;
-                        matricesIndicesExtra[i + firstZeroWeight - 4] = noInfluenceBoneIndex;
-                    } else {
-                        matricesWeights[i + firstZeroWeight] = 1.0 - weight;
-                        matricesIndices[i + firstZeroWeight] = noInfluenceBoneIndex;
+                // count the buffer weights usage
+                usedWeightCounts[usedWeights]++;
+
+                // max influences
+                if (usedWeights > maxUsedWeights) maxUsedWeights = usedWeights;
+
+                // check for invalid weight and just set it to 1.
+                if (t === 0) {
+                    missingWeights++;
+                } 
+                else {
+                    // renormalize so everything adds to 1 use reciprical 
+                    let recip = 1 / t;
+                    let tolerance = 0;
+                    for (b = 0; b < numInfluences; b++) {
+                        if (b < 4)
+                            tolerance += Math.abs(matricesWeights[a + b] - (matricesWeights[a + b] * recip));
+                        else
+                            tolerance += Math.abs(matricesWeightsExtra[a + b-4] - (matricesWeightsExtra[a + b-4] * recip));
                     }
-                }
+                    // arbitary epsilon value for dicdating not normalized
+                    if (tolerance > toleranceEpsilon) numberNotNormalized++;
+                }   
             }
 
-            this.setVerticesData(VertexBuffer.MatricesIndicesKind, matricesIndices);
-            if (matricesIndicesExtra) {
-                this.setVerticesData(VertexBuffer.MatricesIndicesExtraKind, matricesIndicesExtra);
+            // validate bone indices are in range of the skeleton
+            let numBones:number = this.skeleton.bones.length;
+            let matricesIndices = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesIndicesKind));
+            let matricesIndicesExtra = (<FloatArray>this.getVerticesData(VertexBuffer.MatricesIndicesExtraKind));
+            let numBadBoneIndices : number = 0;
+            for (var a = 0; a < numWeights; a++) {
+                for (var b = 0; b < numInfluences; b++) {
+                    let index = b < 4 ? matricesIndices[b] : matricesIndicesExtra[b-4];
+                    if (index >= numBones || index < 0) numBadBoneIndices++;
+                }
             }
 
-            this.setVerticesData(VertexBuffer.MatricesWeightsKind, matricesWeights);
-            if (matricesWeightsExtra) {
-                this.setVerticesData(VertexBuffer.MatricesWeightsExtraKind, matricesWeightsExtra);
-            }
+            
+            // log mesh stats
+            var output = "Number of Weights = " + numWeights/4 + "\nMaximum influences = " + maxUsedWeights + 
+                         "\nMissing Weights = " + missingWeights + "\nNot Sorted = " + numberNotSorted +
+                         "\nNot Normalized = " + numberNotNormalized + "\nWeightCounts = [" + usedWeightCounts + "]" +
+                         "\nNumber of bones = " + numBones + "\nBad Bone Indices = " + numBadBoneIndices ;
+            
+            return {skinned:true, valid: missingWeights===0 && numberNotNormalized===0 && numBadBoneIndices===0, report: output};
         }
 
-
         /** @hidden */
         public _checkDelayState(): Mesh {
             var scene = this.getScene();

+ 144 - 54
src/Physics/babylon.physicsHelper.ts

@@ -1,10 +1,18 @@
 module BABYLON {
 
+    /**
+     * A helper for physics simulations
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export class PhysicsHelper {
 
         private _scene: Scene;
         private _physicsEngine: Nullable<IPhysicsEngine>;
 
+        /**
+         * Initializes the Physics helper
+         * @param scene Babylon.js scene
+         */
         constructor(scene: Scene) {
             this._scene = scene;
             this._physicsEngine = this._scene.getPhysicsEngine();
@@ -15,10 +23,12 @@ module BABYLON {
         }
 
         /**
-         * @param {Vector3} origin the origin of the explosion
-         * @param {number} radius the explosion radius
-         * @param {number} strength the explosion strength
-         * @param {PhysicsRadialImpulseFalloff} falloff possible options: Constant & Linear. Defaults to Constant
+         * Applies a radial explosion impulse
+         * @param origin the origin of the explosion
+         * @param radius the explosion radius
+         * @param strength the explosion strength
+         * @param falloff possible options: Constant & Linear. Defaults to Constant
+         * @returns A physics radial explosion event, or null
          */
         public applyRadialExplosionImpulse(origin: Vector3, radius: number, strength: number, falloff: PhysicsRadialImpulseFalloff = PhysicsRadialImpulseFalloff.Constant): Nullable<PhysicsRadialExplosionEvent> {
             if (!this._physicsEngine) {
@@ -48,10 +58,12 @@ module BABYLON {
         }
 
         /**
-         * @param {Vector3} origin the origin of the explosion
-         * @param {number} radius the explosion radius
-         * @param {number} strength the explosion strength
-         * @param {PhysicsRadialImpulseFalloff} falloff possible options: Constant & Linear. Defaults to Constant
+         * Applies a radial explosion force
+         * @param origin the origin of the explosion
+         * @param radius the explosion radius
+         * @param strength the explosion strength
+         * @param falloff possible options: Constant & Linear. Defaults to Constant
+         * @returns A physics radial explosion event, or null
          */
         public applyRadialExplosionForce(origin: Vector3, radius: number, strength: number, falloff: PhysicsRadialImpulseFalloff = PhysicsRadialImpulseFalloff.Constant): Nullable<PhysicsRadialExplosionEvent> {
             if (!this._physicsEngine) {
@@ -81,10 +93,12 @@ module BABYLON {
         }
 
         /**
-         * @param {Vector3} origin the origin of the explosion
-         * @param {number} radius the explosion radius
-         * @param {number} strength the explosion strength
-         * @param {PhysicsRadialImpulseFalloff} falloff possible options: Constant & Linear. Defaults to Constant
+         * Creates a gravitational field
+         * @param origin the origin of the explosion
+         * @param radius the explosion radius
+         * @param strength the explosion strength
+         * @param falloff possible options: Constant & Linear. Defaults to Constant
+         * @returns A physics gravitational field event, or null
          */
         public gravitationalField(origin: Vector3, radius: number, strength: number, falloff: PhysicsRadialImpulseFalloff = PhysicsRadialImpulseFalloff.Constant): Nullable<PhysicsGravitationalFieldEvent> {
             if (!this._physicsEngine) {
@@ -105,11 +119,13 @@ module BABYLON {
         }
 
         /**
-         * @param {Vector3} origin the origin of the updraft
-         * @param {number} radius the radius of the updraft
-         * @param {number} strength the strength of the updraft
-         * @param {number} height the height of the updraft
-         * @param {PhysicsUpdraftMode} updraftMode possible options: Center & Perpendicular. Defaults to Center
+         * Creates a physics updraft event
+         * @param origin the origin of the updraft
+         * @param radius the radius of the updraft
+         * @param strength the strength of the updraft
+         * @param height the height of the updraft
+         * @param updraftMode possible options: Center & Perpendicular. Defaults to Center
+         * @returns A physics updraft event, or null
          */
         public updraft(origin: Vector3, radius: number, strength: number, height: number, updraftMode: PhysicsUpdraftMode = PhysicsUpdraftMode.Center): Nullable<PhysicsUpdraftEvent> {
             if (!this._physicsEngine) {
@@ -129,10 +145,13 @@ module BABYLON {
         }
 
         /**
-         * @param {Vector3} origin the of the vortex
-         * @param {number} radius the radius of the vortex
-         * @param {number} strength the strength of the vortex
-         * @param {number} height   the height of the vortex
+         * Creates a physics vortex event
+         * @param origin the of the vortex
+         * @param radius the radius of the vortex
+         * @param strength the strength of the vortex
+         * @param height   the height of the vortex
+         * @returns a Physics vortex event, or null
+         * A physics vortex event or null
          */
         public vortex(origin: Vector3, radius: number, strength: number, height: number): Nullable<PhysicsVortexEvent> {
             if (!this._physicsEngine) {
@@ -152,9 +171,10 @@ module BABYLON {
         }
     }
 
-
-    /***** Radial explosion *****/
-
+    /**
+     * Represents a physics radial explosion event
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export class PhysicsRadialExplosionEvent {
 
         private _scene: Scene;
@@ -163,13 +183,17 @@ module BABYLON {
         private _rays: Array<Ray> = [];
         private _dataFetched: boolean = false; // check if the data has been fetched. If not, do cleanup
 
+        /**
+         * Initializes a radial explosioin event
+         * @param scene BabylonJS scene
+         */
         constructor(scene: Scene) {
             this._scene = scene;
         }
 
         /**
          * Returns the data related to the radial explosion event (sphere & rays).
-         * @returns {PhysicsRadialExplosionEventData}
+         * @returns The radial explosion event data
          */
         public getData(): PhysicsRadialExplosionEventData {
             this._dataFetched = true;
@@ -182,12 +206,12 @@ module BABYLON {
 
         /**
          * Returns the force and contact point of the impostor or false, if the impostor is not affected by the force/impulse.
-         * @param impostor 
-         * @param {Vector3} origin the origin of the explosion
-         * @param {number} radius the explosion radius
-         * @param {number} strength the explosion strength
-         * @param {PhysicsRadialImpulseFalloff} falloff possible options: Constant & Linear
-         * @returns {Nullable<PhysicsForceAndContactPoint>}
+         * @param impostor A physics imposter
+         * @param origin the origin of the explosion
+         * @param radius the explosion radius
+         * @param strength the explosion strength
+         * @param falloff possible options: Constant & Linear
+         * @returns {Nullable<PhysicsForceAndContactPoint>} A physics force and contact point, or null
          */
         public getImpostorForceAndContactPoint(impostor: PhysicsImpostor, origin: Vector3, radius: number, strength: number, falloff: PhysicsRadialImpulseFalloff): Nullable<PhysicsForceAndContactPoint> {
             if (impostor.mass === 0) {
@@ -230,7 +254,7 @@ module BABYLON {
 
         /**
          * Disposes the sphere.
-         * @param {bolean} force
+         * @param force Specifies if the sphere should be disposed by force
          */
         public dispose(force: boolean = true) {
             if (force) {
@@ -268,9 +292,10 @@ module BABYLON {
 
     }
 
-
-    /***** Gravitational Field *****/
-
+    /**
+     * Represents a gravitational field event
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export class PhysicsGravitationalFieldEvent {
 
         private _physicsHelper: PhysicsHelper;
@@ -283,6 +308,15 @@ module BABYLON {
         private _sphere: Mesh;
         private _dataFetched: boolean = false; // check if the has been fetched the data. If not, do cleanup
 
+        /**
+         * Initializes the physics gravitational field event
+         * @param physicsHelper A physics helper
+         * @param scene BabylonJS scene
+         * @param origin The origin position of the gravitational field event
+         * @param radius The radius of the gravitational field event
+         * @param strength The strength of the gravitational field event
+         * @param falloff The falloff for the gravitational field event
+         */
         constructor(physicsHelper: PhysicsHelper, scene: Scene, origin: Vector3, radius: number, strength: number, falloff: PhysicsRadialImpulseFalloff = PhysicsRadialImpulseFalloff.Constant) {
             this._physicsHelper = physicsHelper;
             this._scene = scene;
@@ -295,7 +329,7 @@ module BABYLON {
 
         /**
          * Returns the data related to the gravitational field event (sphere).
-         * @returns {PhysicsGravitationalFieldEventData}
+         * @returns A gravitational field event
          */
         public getData(): PhysicsGravitationalFieldEventData {
             this._dataFetched = true;
@@ -322,7 +356,7 @@ module BABYLON {
 
         /**
          * Disposes the sphere.
-         * @param {bolean} force
+         * @param force The force to dispose from the gravitational field event
          */
         public dispose(force: boolean = true) {
             if (force) {
@@ -350,9 +384,10 @@ module BABYLON {
 
     }
 
-
-    /***** Updraft *****/
-
+    /**
+     * Represents a physics updraft event
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export class PhysicsUpdraftEvent {
 
         private _physicsEngine: PhysicsEngine;
@@ -363,6 +398,15 @@ module BABYLON {
         private _cylinderPosition: Vector3 = Vector3.Zero(); // to keep the cylinders position, because normally the origin is in the center and not on the bottom
         private _dataFetched: boolean = false; // check if the has been fetched the data. If not, do cleanup
  
+        /**
+         * Initializes the physics updraft event
+         * @param _scene BabylonJS scene
+         * @param _origin The origin position of the updraft
+         * @param _radius The radius of the updraft
+         * @param _strength The strength of the updraft
+         * @param _height The height of the updraft
+         * @param _updraftMode The mode of the updraft
+         */
         constructor(private _scene: Scene, private _origin: Vector3, private _radius: number, private _strength: number, private _height: number, private _updraftMode: PhysicsUpdraftMode) {
             this._physicsEngine = <PhysicsEngine>this._scene.getPhysicsEngine();
 
@@ -378,7 +422,7 @@ module BABYLON {
 
         /**
          * Returns the data related to the updraft event (cylinder).
-         * @returns {PhysicsUpdraftEventData}
+         * @returns A physics updraft event
          */
         public getData(): PhysicsUpdraftEventData {
             this._dataFetched = true;
@@ -405,7 +449,7 @@ module BABYLON {
 
         /**
          * Disposes the sphere.
-         * @param {bolean} force
+         * @param force Specifies if the updraft should be disposed by force
          */
         public dispose(force: boolean = true) {
             if (force) {
@@ -478,9 +522,10 @@ module BABYLON {
 
     }
 
-
-    /***** Vortex *****/
-
+    /**
+     * Represents a physics vortex event
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export class PhysicsVortexEvent {
 
         private _physicsEngine: PhysicsEngine;
@@ -492,6 +537,14 @@ module BABYLON {
         private _cylinderPosition: Vector3 = Vector3.Zero(); // to keep the cylinders position, because normally the origin is in the center and not on the bottom
         private _dataFetched: boolean = false; // check if the has been fetched the data. If not, do cleanup
 
+        /**
+         * Initializes the physics vortex event
+         * @param _scene The BabylonJS scene
+         * @param _origin The origin position of the vortex
+         * @param _radius The radius of the vortex
+         * @param _strength The strength of the vortex
+         * @param _height The height of the vortex
+         */
         constructor(private _scene: Scene, private _origin: Vector3, private _radius: number, private _strength: number, private _height: number) {
             this._physicsEngine = <PhysicsEngine>this._scene.getPhysicsEngine();
 
@@ -503,7 +556,7 @@ module BABYLON {
 
         /**
          * Returns the data related to the vortex event (cylinder).
-         * @returns {PhysicsVortexEventData}
+         * @returns The physics vortex event data
          */
         public getData(): PhysicsVortexEventData {
             this._dataFetched = true;
@@ -530,7 +583,7 @@ module BABYLON {
 
         /**
          * Disposes the sphere.
-         * @param {bolean} force
+         * @param force
          */
         public dispose(force: boolean = true) {
             if (force) {
@@ -627,11 +680,9 @@ module BABYLON {
 
     }
 
-
-    /***** Enums *****/
-
     /**
     * The strenght of the force in correspondence to the distance of the affected object
+    * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
     */
     export enum PhysicsRadialImpulseFalloff {
         /** Defines that impulse is constant in strength across it's whole radius */
@@ -641,7 +692,8 @@ module BABYLON {
     }
 
     /**
-     * The strenght of the force in correspondence to the distance of the affected object
+     * The strength of the force in correspondence to the distance of the affected object
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
      */
     export enum PhysicsUpdraftMode {
         /** Defines that the upstream forces will pull towards the top center of the cylinder */
@@ -650,28 +702,66 @@ module BABYLON {
         Perpendicular
     }
 
-
-    /***** Data interfaces *****/
-
+    /**
+     * Interface for a physics force and contact point
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export interface PhysicsForceAndContactPoint {
+        /**
+         * The force applied at the contact point
+         */
         force: Vector3;
+        /**
+         * The contact point
+         */
         contactPoint: Vector3;
     }
 
+    /**
+     * Interface for radial explosion event data
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export interface PhysicsRadialExplosionEventData {
+        /**
+         * A sphere used for the radial explosion event
+         */
         sphere: Mesh;
+        /**
+         * An array of rays for the radial explosion event
+         */
         rays: Array<Ray>;
     }
 
+    /**
+     * Interface for gravitational field event data
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export interface PhysicsGravitationalFieldEventData {
+        /**
+         * A sphere mesh used for the gravitational field event
+         */
         sphere: Mesh;
     }
 
+    /**
+     * Interface for updraft event data
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export interface PhysicsUpdraftEventData {
+        /**
+         * A cylinder used for the updraft event
+         */
         cylinder: Mesh;
     }
 
+    /**
+     * Interface for vortex event data
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export interface PhysicsVortexEventData {
+        /**
+         * A cylinder used for the vortex event
+         */
         cylinder: Mesh;
     }
 

+ 295 - 13
src/Physics/babylon.physicsImpostor.ts

@@ -1,39 +1,152 @@
 module BABYLON {
 
+    /**
+     * The interface for the physics imposter parameters
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export interface PhysicsImpostorParameters {
+        /**
+         * The mass of the physics imposter
+         */
         mass: number;
+        /**
+         * The friction of the physics imposter
+         */
         friction?: number;
+        /**
+         * The coefficient of restitution of the physics imposter
+         */
         restitution?: number;
+        /**
+         * The native options of the physics imposter
+         */
         nativeOptions?: any;
+        /**
+         * Specifies if the parent should be ignored
+         */
         ignoreParent?: boolean;
+        /**
+         * Specifies if bi-directional transformations should be disabled
+         */
         disableBidirectionalTransformation?: boolean;
     }
 
+    /**
+     * Interface for a physics-enabled object
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export interface IPhysicsEnabledObject {
+        /**
+         * The position of the physics-enabled object
+         */
         position: Vector3;
+        /**
+         * The rotation of the physics-enabled object
+         */
         rotationQuaternion: Nullable<Quaternion>;
+        /**
+         * The scale of the physics-enabled object
+         */
         scaling: Vector3;
+        /**
+         * The rotation of the physics-enabled object
+         */
         rotation?: Vector3;
+        /**
+         * The parent of the physics-enabled object
+         */
         parent?: any;
+        /**
+         * The bounding info of the physics-enabled object
+         * @returns The bounding info of the physics-enabled object
+         */
         getBoundingInfo(): BoundingInfo;
+        /**
+         * Computes the world matrix
+         * @param force Specifies if the world matrix should be computed by force
+         * @returns A world matrix
+         */
         computeWorldMatrix(force: boolean): Matrix;
+        /**
+         * Gets the world matrix
+         * @returns A world matrix
+         */
         getWorldMatrix?(): Matrix;
+        /**
+         * Gets the child meshes
+         * @param directDescendantsOnly Specifies if only direct-descendants should be obtained
+         * @returns An array of abstract meshes
+         */
         getChildMeshes?(directDescendantsOnly?: boolean): Array<AbstractMesh>;
+        /**
+         * Gets the vertex data
+         * @param kind The type of vertex data
+         * @returns A nullable array of numbers, or a float32 array
+         */
         getVerticesData(kind: string): Nullable<Array<number> | Float32Array>;
+        /**
+         * Gets the indices from the mesh
+         * @returns A nullable array of index arrays
+         */
         getIndices?(): Nullable<IndicesArray>;
+        /**
+         * Gets the scene from the mesh
+         * @returns the indices array or null
+         */
         getScene?(): Scene;
+        /**
+         * Gets the absolute position from the mesh
+         * @returns the absolute position
+         */
         getAbsolutePosition(): Vector3;
+        /**
+         * Gets the absolute pivot point from the mesh
+         * @returns the absolute pivot point
+         */
         getAbsolutePivotPoint(): Vector3;
+        /**
+         * Rotates the mesh
+         * @param axis The axis of rotation
+         * @param amount The amount of rotation
+         * @param space The space of the rotation
+         * @returns The rotation transform node
+         */
         rotate(axis: Vector3, amount: number, space?: Space): TransformNode;
+        /**
+         * Translates the mesh
+         * @param axis The axis of translation
+         * @param distance The distance of translation
+         * @param space The space of the translation
+         * @returns The transform node
+         */
         translate(axis: Vector3, distance: number, space?: Space): TransformNode;
+        /**
+         * Sets the absolute position of the mesh
+         * @param absolutePosition The absolute position of the mesh
+         * @returns The transform node
+         */
         setAbsolutePosition(absolutePosition: Vector3): TransformNode;
+        /**
+         * Gets the class name of the mesh
+         * @returns The class name
+         */
         getClassName(): string;
     }
 
+    /**
+     * Represents a physics imposter
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export class PhysicsImpostor {
 
+        /**
+         * The default object size of the imposter
+         */
         public static DEFAULT_OBJECT_SIZE: Vector3 = new Vector3(1, 1, 1);
 
+        /**
+         * The identity quaternion of the imposter
+         */
         public static IDENTITY_QUATERNION = Quaternion.Identity();
 
         private _physicsEngine: Nullable<IPhysicsEngine>;
@@ -57,10 +170,16 @@ module BABYLON {
         private static _tmpVecs: Vector3[] = [Vector3.Zero(), Vector3.Zero(), Vector3.Zero()];
         private static _tmpQuat: Quaternion = Quaternion.Identity();
 
+        /**
+         * Specifies if the physics imposter is disposed
+         */
         get isDisposed(): boolean {
             return this._isDisposed;
         }
 
+        /**
+         * Gets the mass of the physics imposter
+         */
         get mass(): number {
             return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getBodyMass(this) : 0;
         }
@@ -69,10 +188,16 @@ module BABYLON {
             this.setMass(value);
         }
 
+        /**
+         * Gets the coefficient of friction
+         */
         get friction(): number {
             return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getBodyFriction(this) : 0;
         }
 
+        /**
+         * Sets the coefficient of friction
+         */
         set friction(value: number) {
             if (!this._physicsEngine) {
                 return;
@@ -80,10 +205,16 @@ module BABYLON {
             this._physicsEngine.getPhysicsPlugin().setBodyFriction(this, value);
         }
 
+        /**
+         * Gets the coefficient of restitution
+         */
         get restitution(): number {
             return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getBodyRestitution(this) : 0;
         }
 
+        /**
+         * Sets the coefficient of restitution
+         */
         set restitution(value: number) {
             if (!this._physicsEngine) {
                 return;
@@ -91,7 +222,10 @@ module BABYLON {
             this._physicsEngine.getPhysicsPlugin().setBodyRestitution(this, value);
         }
 
-        //set by the physics engine when adding this impostor to the array.
+        /**
+         * The unique id of the physics imposter
+         * set by the physics engine when adding this impostor to the array
+         */
         public uniqueId: number;
 
         private _joints: Array<{
@@ -99,7 +233,22 @@ module BABYLON {
             otherImpostor: PhysicsImpostor
         }>;
 
-        constructor(public object: IPhysicsEnabledObject, public type: number, private _options: PhysicsImpostorParameters = { mass: 0 }, private _scene?: Scene) {
+        /**
+         * Initializes the physics imposter
+         * @param object The physics-enabled object used as the physics imposter
+         * @param type The type of the physics imposter
+         * @param _options The options for the physics imposter
+         * @param _scene The Babylon scene
+         */
+        constructor(
+            /**
+             * The physics-enabled object used as the physics imposter
+             */
+            public object: IPhysicsEnabledObject, 
+            /**
+             * The type of the physics imposter
+             */
+            public type: number, private _options: PhysicsImpostorParameters = { mass: 0 }, private _scene?: Scene) {
 
             //sanity check!
             if (!this.object) {
@@ -174,11 +323,16 @@ module BABYLON {
 
         /**
          * Should a new body be generated.
+         * @returns boolean specifying if body initialization is required
          */
         public isBodyInitRequired(): boolean {
             return this._bodyUpdateRequired || (!this._physicsBody && !this._parent);
         }
 
+        /**
+         * Sets the updated scaling
+         * @param updated Specifies if the scaling is updated
+         */
         public setScalingUpdated(updated: boolean) {
             this.forceUpdate();
         }
@@ -205,10 +359,17 @@ module BABYLON {
             return (this._parent && !this._options.ignoreParent) ? this._parent.physicsBody : this._physicsBody;
         }
 
+        /**
+         * Get the parent of the physics imposter
+         * @returns Physics imposter or null
+         */
         public get parent(): Nullable<PhysicsImpostor> {
             return !this._options.ignoreParent && this._parent ? this._parent : null;
         }
 
+        /**
+         * Sets the parent of the physics imposter
+         */
         public set parent(value: Nullable<PhysicsImpostor>) {
             this._parent = value;
         }
@@ -224,10 +385,17 @@ module BABYLON {
             this.resetUpdateFlags();
         }
 
+        /**
+         * Resets the update flags
+         */
         public resetUpdateFlags() {
             this._bodyUpdateRequired = false;
         }
 
+        /**
+         * Gets the object extend size
+         * @returns the object extend size
+         */
         public getObjectExtendSize(): Vector3 {
             if (this.object.getBoundingInfo) {
                 let q = this.object.rotationQuaternion;
@@ -249,6 +417,10 @@ module BABYLON {
             }
         }
 
+        /**
+         * Gets the object center
+         * @returns The object center
+         */
         public getObjectCenter(): Vector3 {
             if (this.object.getBoundingInfo) {
                 let boundingInfo = this.object.getBoundingInfo();
@@ -259,14 +431,18 @@ module BABYLON {
         }
 
         /**
-         * Get a specific parametes from the options parameter.
+         * Get a specific parametes from the options parameter
+         * @param paramName The object parameter name
+         * @returns The object parameter
          */
-        public getParam(paramName: string) {
+        public getParam(paramName: string): any {
             return (<any>this._options)[paramName];
         }
 
         /**
          * Sets a specific parameter in the options given to the physics plugin
+         * @param paramName The parameter name
+         * @param value The value of the parameter
          */
         public setParam(paramName: string, value: number) {
             (<any>this._options)[paramName] = value;
@@ -275,6 +451,7 @@ module BABYLON {
 
         /**
          * Specifically change the body's mass option. Won't recreate the physics body object
+         * @param mass The mass of the physics imposter
          */
         public setMass(mass: number) {
             if (this.getParam("mass") !== mass) {
@@ -285,20 +462,36 @@ module BABYLON {
             }
         }
 
+        /**
+         * Gets the linear velocity
+         * @returns  linear velocity or null
+         */
         public getLinearVelocity(): Nullable<Vector3> {
             return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getLinearVelocity(this) : Vector3.Zero();
         }
 
+        /**
+         * Sets the linear velocity
+         * @param velocity  linear velocity or null
+         */
         public setLinearVelocity(velocity: Nullable<Vector3>) {
             if (this._physicsEngine) {
                 this._physicsEngine.getPhysicsPlugin().setLinearVelocity(this, velocity);
             }
         }
 
+        /**
+         * Gets the angular velocity
+         * @returns angular velocity or null 
+         */
         public getAngularVelocity(): Nullable<Vector3> {
             return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getAngularVelocity(this) : Vector3.Zero();
         }
 
+        /**
+         * Sets the angular velocity
+         * @param velocity The velocity or null
+         */
         public setAngularVelocity(velocity: Nullable<Vector3>) {
             if (this._physicsEngine) {
                 this._physicsEngine.getPhysicsPlugin().setAngularVelocity(this, velocity);
@@ -306,9 +499,11 @@ module BABYLON {
         }
 
         /**
-         * Execute a function with the physics plugin native code.
-         * Provide a function the will have two variables - the world object and the physics body object.
+         * Execute a function with the physics plugin native code
+         * Provide a function the will have two variables - the world object and the physics body object
+         * @param func The function to execute with the physics plugin native code
          */
+
         public executeNativeFunction(func: (world: any, physicsBody: any) => void) {
             if (this._physicsEngine) {
                 func(this._physicsEngine.getPhysicsPlugin().world, this.physicsBody);
@@ -316,12 +511,17 @@ module BABYLON {
         }
 
         /**
-         * Register a function that will be executed before the physics world is stepping forward.
+         * Register a function that will be executed before the physics world is stepping forward
+         * @param func The function to execute before the physics world is stepped forward
          */
         public registerBeforePhysicsStep(func: (impostor: PhysicsImpostor) => void): void {
             this._onBeforePhysicsStepCallbacks.push(func);
         }
 
+        /**
+         * Unregister a function that will be executed before the physics world is stepping forward
+         * @param func The function to execute before the physics world is stepped forward
+         */
         public unregisterBeforePhysicsStep(func: (impostor: PhysicsImpostor) => void): void {
             var index = this._onBeforePhysicsStepCallbacks.indexOf(func);
 
@@ -334,11 +534,16 @@ module BABYLON {
 
         /**
          * Register a function that will be executed after the physics step
+         * @param func The function to execute after physics step
          */
         public registerAfterPhysicsStep(func: (impostor: PhysicsImpostor) => void): void {
             this._onAfterPhysicsStepCallbacks.push(func);
         }
 
+        /**
+         * Unregisters a function that will be executed after the physics step
+         * @param func The function to execute after physics step
+         */
         public unregisterAfterPhysicsStep(func: (impostor: PhysicsImpostor) => void): void {
             var index = this._onAfterPhysicsStepCallbacks.indexOf(func);
 
@@ -350,13 +555,20 @@ module BABYLON {
         }
 
         /**
-         * register a function that will be executed when this impostor collides against a different body.
+         * register a function that will be executed when this impostor collides against a different body
+         * @param collideAgainst Physics imposter, or array of physics imposters to collide against
+         * @param func Callback that is executed on collision
          */
         public registerOnPhysicsCollide(collideAgainst: PhysicsImpostor | Array<PhysicsImpostor>, func: (collider: PhysicsImpostor, collidedAgainst: PhysicsImpostor) => void): void {
             var collidedAgainstList: Array<PhysicsImpostor> = collideAgainst instanceof Array ? <Array<PhysicsImpostor>>collideAgainst : [<PhysicsImpostor>collideAgainst]
             this._onPhysicsCollideCallbacks.push({ callback: func, otherImpostors: collidedAgainstList });
         }
 
+        /**
+         * Unregisters the physics imposter on contact
+         * @param collideAgainst The physics object to collide against
+         * @param func Callback to execute on collision
+         */
         public unregisterOnPhysicsCollide(collideAgainst: PhysicsImpostor | Array<PhysicsImpostor>, func: (collider: PhysicsImpostor, collidedAgainst: PhysicsImpostor | Array<PhysicsImpostor>) => void): void {
             var collidedAgainstList: Array<PhysicsImpostor> = collideAgainst instanceof Array ? <Array<PhysicsImpostor>>collideAgainst : [<PhysicsImpostor>collideAgainst]
             var index = -1;
@@ -386,7 +598,11 @@ module BABYLON {
         private _tmpQuat: Quaternion = new Quaternion();
         private _tmpQuat2: Quaternion = new Quaternion();
 
-        public getParentsRotation() {
+        /**
+         * Get the parent rotation
+         * @returns The parent rotation
+         */
+        public getParentsRotation(): Quaternion {
             let parent = this.object.parent;
             this._tmpQuat.copyFromFloats(0, 0, 0, 1);
             while (parent) {
@@ -428,7 +644,7 @@ module BABYLON {
         }
 
         /**
-         * this function is executed by the physics engine.
+         * this function is executed by the physics engine
          */
         public afterStep = () => {
             if (!this._physicsEngine) {
@@ -457,7 +673,9 @@ module BABYLON {
          */
         public onCollideEvent: Nullable<(collider: PhysicsImpostor, collidedWith: PhysicsImpostor) => void> = null;
 
-        //event and body object due to cannon's event-based architecture.
+        /**
+         * event and body object due to cannon's event-based architecture.
+         */
         public onCollide = (e: { body: any }) => {
             if (!this._onPhysicsCollideCallbacks.length && !this.onCollideEvent) {
                 return;
@@ -483,6 +701,9 @@ module BABYLON {
 
         /**
          * Apply a force 
+         * @param force The force to apply
+         * @param contactPoint The contact point for the force
+         * @returns The physics imposter
          */
         public applyForce(force: Vector3, contactPoint: Vector3): PhysicsImpostor {
             if (this._physicsEngine) {
@@ -493,6 +714,9 @@ module BABYLON {
 
         /**
          * Apply an impulse
+         * @param force The impulse force
+         * @param contactPoint The contact point for the impulse force
+         * @returns The physics imposter
          */
         public applyImpulse(force: Vector3, contactPoint: Vector3): PhysicsImpostor {
             if (this._physicsEngine) {
@@ -503,7 +727,11 @@ module BABYLON {
         }
 
         /**
-         * A help function to create a joint.
+         * A help function to create a joint
+         * @param otherImpostor A physics imposter used to create a joint
+         * @param jointType The type of joint
+         * @param jointData The data for the joint
+         * @returns The physics imposter
          */
         public createJoint(otherImpostor: PhysicsImpostor, jointType: number, jointData: PhysicsJointData): PhysicsImpostor {
             var joint = new PhysicsJoint(jointType, jointData);
@@ -513,7 +741,10 @@ module BABYLON {
         }
 
         /**
-         * Add a joint to this impostor with a different impostor.
+         * Add a joint to this impostor with a different impostor
+         * @param otherImpostor A physics imposter used to add a joint
+         * @param joint The joint to add
+         * @returns The physics imposter
          */
         public addJoint(otherImpostor: PhysicsImpostor, joint: PhysicsJoint): PhysicsImpostor {
             this._joints.push({
@@ -530,6 +761,7 @@ module BABYLON {
 
         /**
          * Will keep this body still, in a sleep mode.
+         * @returns the physics imposter
          */
         public sleep(): PhysicsImpostor {
             if (this._physicsEngine) {
@@ -541,6 +773,7 @@ module BABYLON {
 
         /**
          * Wake the body up.
+         * @returns The physics imposter
          */
         public wakeUp(): PhysicsImpostor {
             if (this._physicsEngine) {
@@ -550,11 +783,19 @@ module BABYLON {
             return this;
         }
 
+        /**
+         * Clones the physics imposter
+         * @param newObject The physics imposter clones to this physics-enabled object
+         * @returns A nullable physics imposter
+         */
         public clone(newObject: IPhysicsEnabledObject): Nullable<PhysicsImpostor> {
             if (!newObject) return null;
             return new PhysicsImpostor(newObject, this.type, this._options, this._scene);
         }
 
+        /**
+         * Disposes the physics imposter
+         */
         public dispose(/*disposeChildren: boolean = true*/) {
             //no dispose if no physics engine is available.
             if (!this._physicsEngine) {
@@ -584,10 +825,18 @@ module BABYLON {
             this._isDisposed = true;
         }
 
+        /**
+         * Sets the delta position
+         * @param position The delta position amount
+         */
         public setDeltaPosition(position: Vector3) {
             this._deltaPosition.copyFrom(position);
         }
 
+        /**
+         * Sets the delta rotation
+         * @param rotation The delta rotation amount
+         */
         public setDeltaRotation(rotation: Quaternion) {
             if (!this._deltaRotation) {
                 this._deltaRotation = new Quaternion();
@@ -596,6 +845,11 @@ module BABYLON {
             this._deltaRotationConjugated = this._deltaRotation.conjugate();
         }
 
+        /**
+         * Gets the box size of the physics imposter and stores the result in the input parameter
+         * @param result Stores the box size
+         * @returns The physics imposter
+         */
         public getBoxSizeToRef(result: Vector3): PhysicsImpostor {
             if (this._physicsEngine) {
                 this._physicsEngine.getPhysicsPlugin().getBoxSizeToRef(this, result);
@@ -604,6 +858,10 @@ module BABYLON {
             return this;
         }
 
+        /**
+         * Gets the radius of the physics imposter
+         * @returns Radius of the physics imposter
+         */
         public getRadius(): number {
             return this._physicsEngine ? this._physicsEngine.getPhysicsPlugin().getRadius(this) : 0;
         }
@@ -714,13 +972,37 @@ module BABYLON {
         }
 
         //Impostor types
+        /**
+         * No-Imposter type
+         */
         public static NoImpostor = 0;
+        /**
+         * Sphere-Imposter type
+         */
         public static SphereImpostor = 1;
+        /**
+         * Box-Imposter type
+         */
         public static BoxImpostor = 2;
+        /**
+         * Plane-Imposter type
+         */
         public static PlaneImpostor = 3;
+        /**
+         * Mesh-imposter type
+         */
         public static MeshImpostor = 4;
+        /**
+         * Cylinder-Imposter type
+         */
         public static CylinderImpostor = 7;
+        /**
+         * Particle-Imposter type
+         */
         public static ParticleImpostor = 8;
+        /**
+         * Heightmap-Imposter type
+         */
         public static HeightmapImpostor = 9;
     }
 }

+ 140 - 12
src/Physics/babylon.physicsJoint.ts

@@ -1,33 +1,74 @@
 module BABYLON {
 
+    /**
+     * Interface for Physics-Joint data
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export interface PhysicsJointData {
         //Important for some engines, optional!
+        /**
+         * The main pivot of the joint
+         */
         mainPivot?: Vector3;
+        /**
+         * The connected pivot of the joint
+         */
         connectedPivot?: Vector3;
+        /**
+         * The main axis of the joint
+         */
         mainAxis?: Vector3,
+        /**
+         * The connected axis of the joint
+         */
         connectedAxis?: Vector3,
+        /**
+         * The collision of the joint
+         */
         collision?: boolean
-        //Native Oimo/Cannon/Energy data
+        /**
+         * Native Oimo/Cannon/Energy data
+         */
         nativeParams?: any;
     }
 
     /**
-     * This is a holder class for the physics joint created by the physics plugin.
-     * It holds a set of functions to control the underlying joint.
+     * This is a holder class for the physics joint created by the physics plugin
+     * It holds a set of functions to control the underlying joint
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
      */
     export class PhysicsJoint {
 
         private _physicsJoint: any;
         protected _physicsPlugin: IPhysicsEnginePlugin;
 
-        constructor(public type: number, public jointData: PhysicsJointData) {
+        /**
+         * Initializes the physics joint
+         * @param type The type of the physics joint
+         * @param jointData The data for the physics joint
+         */
+        constructor(
+            /**
+             * The type of the physics joint
+             */
+            public type: number,
+            /**
+             * The data for the physics joint
+             */
+            public jointData: PhysicsJointData) {
             jointData.nativeParams = jointData.nativeParams || {};
         }
 
+        /**
+         * Gets the physics joint
+         */
         public get physicsJoint(): any {
             return this._physicsJoint;
         }
 
+        /**
+         * Sets the physics joint
+         */
         public set physicsJoint(newJoint: any) {
 
             if (this._physicsJoint) {
@@ -37,6 +78,9 @@ module BABYLON {
             this._physicsJoint = newJoint;
         }
 
+        /**
+         * Sets the physics plugin
+         */
         public set physicsPlugin(physicsPlugin: IPhysicsEnginePlugin) {
             this._physicsPlugin = physicsPlugin;
         }
@@ -44,7 +88,7 @@ module BABYLON {
         /**
          * Execute a function that is physics-plugin specific.
          * @param {Function} func the function that will be executed. 
-         *                        It accepts two parameters: the physics world and the physics joint.
+         *                        It accepts two parameters: the physics world and the physics joint
          */
         public executeNativeFunction(func: (world: any, physicsJoint: any) => void) {
             func(this._physicsPlugin.world, this._physicsJoint)
@@ -54,42 +98,91 @@ module BABYLON {
         //TODO check if the native joints are the same
 
         //Joint Types
+        /**
+         * Distance-Joint type
+         */
         public static DistanceJoint = 0;
+        /**
+         * Hinge-Joint type
+         */
         public static HingeJoint = 1;
+        /**
+         * Ball-and-Socket joint type
+         */
         public static BallAndSocketJoint = 2;
+        /**
+         * Wheel-Joint type
+         */
         public static WheelJoint = 3;
+        /**
+         * Slider-Joint type
+         */
         public static SliderJoint = 4;
         //OIMO
+        /**
+         * Prismatic-Joint type
+         */
         public static PrismaticJoint = 5;
-        //ENERGY FTW! (compare with this - http://ode-wiki.org/wiki/index.php?title=Manual:_Joint_Types_and_Functions)
+        //
+        /**
+         * Universal-Joint type
+         * ENERGY FTW! (compare with this - @see http://ode-wiki.org/wiki/index.php?title=Manual:_Joint_Types_and_Functions)
+         */
         public static UniversalJoint = 6;
+        /**
+         * Hinge-Joint 2 type
+         */
         public static Hinge2Joint = PhysicsJoint.WheelJoint;
         //Cannon
-        //Similar to a Ball-Joint. Different in params
+        /**
+         * Point to Point Joint type.  Similar to a Ball-Joint.  Different in parameters
+         */
         public static PointToPointJoint = 8;
         //Cannon only at the moment
+        /**
+         * Spring-Joint type
+         */
         public static SpringJoint = 9;
+        /**
+         * Lock-Joint type
+         */
         public static LockJoint = 10;
     }
 
     /**
-     * A class representing a physics distance joint.
+     * A class representing a physics distance joint
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
      */
     export class DistanceJoint extends PhysicsJoint {
+        /**
+         * 
+         * @param jointData The data for the Distance-Joint
+         */
         constructor(jointData: DistanceJointData) {
             super(PhysicsJoint.DistanceJoint, jointData);
         }
 
         /**
          * Update the predefined distance.
+         * @param maxDistance The maximum preferred distance
+         * @param minDistance The minimum preferred distance
          */
         public updateDistance(maxDistance: number, minDistance?: number) {
             this._physicsPlugin.updateDistanceJoint(this, maxDistance, minDistance);
         }
     }
 
+    /**
+     * Represents a Motor-Enabled Joint
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export class MotorEnabledJoint extends PhysicsJoint implements IMotorEnabledJoint {
 
+        /**
+         * Initializes the Motor-Enabled Joint
+         * @param type The type of the joint
+         * @param jointData The physica joint data for the joint
+         */
         constructor(type: number, jointData: PhysicsJointData) {
             super(type, jointData);
         }
@@ -97,8 +190,8 @@ module BABYLON {
         /**
          * Set the motor values.
          * Attention, this function is plugin specific. Engines won't react 100% the same.
-         * @param {number} force the force to apply
-         * @param {number} maxForce max force for this motor.
+         * @param force the force to apply
+         * @param maxForce max force for this motor.
          */
         public setMotor(force?: number, maxForce?: number) {
             this._physicsPlugin.setMotor(this, force || 0, maxForce);
@@ -107,6 +200,8 @@ module BABYLON {
         /**
          * Set the motor's limits.
          * Attention, this function is plugin specific. Engines won't react 100% the same.
+         * @param upperLimit The upper limit of the motor
+         * @param lowerLimit The lower limit of the motor
          */
         public setLimit(upperLimit: number, lowerLimit?: number) {
             this._physicsPlugin.setLimit(this, upperLimit, lowerLimit);
@@ -114,10 +209,15 @@ module BABYLON {
     }
 
     /**
-     * This class represents a single hinge physics joint
+     * This class represents a single physics Hinge-Joint
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
      */
     export class HingeJoint extends MotorEnabledJoint {
 
+        /**
+         * Initializes the Hinge-Joint
+         * @param jointData The joint data for the Hinge-Joint
+         */
         constructor(jointData: PhysicsJointData) {
             super(PhysicsJoint.HingeJoint, jointData);
         }
@@ -135,6 +235,8 @@ module BABYLON {
         /**
          * Set the motor's limits.
          * Attention, this function is plugin specific. Engines won't react 100% the same.
+         * @param upperLimit The upper limit of the motor
+         * @param lowerLimit The lower limit of the motor
          */
         public setLimit(upperLimit: number, lowerLimit?: number) {
             this._physicsPlugin.setLimit(this, upperLimit, lowerLimit);
@@ -143,9 +245,14 @@ module BABYLON {
 
     /**
      * This class represents a dual hinge physics joint (same as wheel joint)
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
      */
     export class Hinge2Joint extends MotorEnabledJoint {
 
+        /**
+         * Initializes the Hinge2-Joint
+         * @param jointData The joint data for the Hinge2-Joint
+         */
         constructor(jointData: PhysicsJointData) {
             super(PhysicsJoint.Hinge2Joint, jointData);
         }
@@ -173,14 +280,34 @@ module BABYLON {
         }
     }
 
+    /**
+     * Interface for a motor enabled joint
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
+     */
     export interface IMotorEnabledJoint {
+        /**
+         * Physics joint
+         */
         physicsJoint: any;
+        /**
+         * Sets the motor of the motor-enabled joint
+         * @param force The force of the motor
+         * @param maxForce The maximum force of the motor
+         * @param motorIndex The index of the motor
+         */
         setMotor(force?: number, maxForce?: number, motorIndex?: number): void;
+        /**
+         * Sets the limit of the motor
+         * @param upperLimit The upper limit of the motor
+         * @param lowerLimit The lower limit of the motor
+         * @param motorIndex The index of the motor
+         */
         setLimit(upperLimit: number, lowerLimit?: number, motorIndex?: number): void;
     }
 
     /**
-     * Joint data for a distance joint
+     * Joint data for a Distance-Joint
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
      */
     export interface DistanceJointData extends PhysicsJointData {
         /**
@@ -193,6 +320,7 @@ module BABYLON {
 
     /**
      * Joint data from a spring joint
+     * @see https://doc.babylonjs.com/how_to/using_the_physics_engine
      */
     export interface SpringJointData extends PhysicsJointData {
         /**