Bläddra i källkod

Merge pull request #5177 from sebavan/master

Doc
sebavan 7 år sedan
förälder
incheckning
80d73863f6
2 ändrade filer med 75 tillägg och 8 borttagningar
  1. 32 4
      src/Debug/babylon.debugLayer.ts
  2. 43 4
      src/Debug/babylon.rayHelper.ts

+ 32 - 4
src/Debug/babylon.debugLayer.ts

@@ -29,16 +29,37 @@ module BABYLON {
         configurable: true
     });
 
+    /**
+     * The debug layer (aka Inspector) is the go to tool in order to better understand
+     * what is happening in your scene
+     * @see http://doc.babylonjs.com/features/playground_debuglayer
+     */
     export class DebugLayer {
-        private _scene: Scene;
+        /**
+         * Define the url to get the inspector script from.
+         * By default it uses the babylonjs CDN.
+         * @ignoreNaming
+         */
         public static InspectorURL = 'https://preview.babylonjs.com/inspector/babylon.inspector.bundle.js';
+
+        private _scene: Scene;
         // The inspector instance
         private _inspector: any;
 
         private BJSINSPECTOR = typeof INSPECTOR !== 'undefined' ? INSPECTOR : undefined;
 
+        /**
+         * Observable triggered when a property is changed through the inspector.
+         */
         public onPropertyChangedObservable = new BABYLON.Observable<{ object: any, property: string, value: any, initialValue: any }>();
 
+        /**
+         * Instantiates a new debug layer.
+         * The debug layer (aka Inspector) is the go to tool in order to better understand
+         * what is happening in your scene
+         * @see http://doc.babylonjs.com/features/playground_debuglayer
+         * @param scene Defines the scene to inspect
+         */
         constructor(scene: Scene) {
             this._scene = scene;
             this._scene.onDisposeObservable.add(() => {
@@ -74,6 +95,10 @@ module BABYLON {
             } // else nothing to do as instance is already created
         }
 
+        /**
+         * Get if the inspector is visible or not.
+         * @returns true if visible otherwise, false
+         */
         public isVisible(): boolean {
             if (!this._inspector) {
                 return false;
@@ -81,6 +106,9 @@ module BABYLON {
             return true;
         }
 
+        /**
+         * Hide the inspector and close its window.
+         */
         public hide() {
             if (this._inspector) {
                 try {
@@ -112,9 +140,9 @@ module BABYLON {
         * | 9 | Physics |
         * | 10 | Camera |
         * | 11 | Audio |
-        *
+        * 
+        * @param config Define the configuration of the inspector
         */
-
         public show(config: {
             popup?: boolean,
             initialTab?: number | string,
@@ -128,7 +156,7 @@ module BABYLON {
                 colorTop?: string,
                 colorBot?: string
             }
-        } = {}) {
+        } = {}): void {
             if (typeof this.BJSINSPECTOR == 'undefined') {
                 // Load inspector and add it to the DOM
                 Tools.LoadScript(DebugLayer.InspectorURL, this._createInspector.bind(this, config));

+ 43 - 4
src/Debug/babylon.rayHelper.ts

@@ -1,6 +1,14 @@
 module BABYLON {
+    /**
+     * As raycast might be hard to debug, the RayHelper can help rendering the different rays
+     * in order to better appreciate the issue one might have.
+     * @see http://doc.babylonjs.com/babylon101/raycasts#debugging
+     */
     export class RayHelper {
 
+        /**
+         * Defines the ray we are currently tryin to visualize.
+         */
         public ray: Nullable<Ray>;
 
         private _renderPoints: Vector3[];
@@ -13,6 +21,13 @@ module BABYLON {
         private _meshSpaceDirection: Vector3;
         private _meshSpaceOrigin: Vector3;
 
+        /**
+         * Helper function to create a colored helper in a scene in one line.
+         * @param ray Defines the ray we are currently tryin to visualize
+         * @param scene Defines the scene the ray is used in
+         * @param color Defines the color we want to see the ray in
+         * @returns The newly created ray helper.
+         */
         public static CreateAndShow(ray: Ray, scene: Scene, color: Color3): RayHelper {
             var helper = new RayHelper(ray);
 
@@ -21,10 +36,22 @@ module BABYLON {
             return helper;
         }
 
+        /**
+         * Instantiate a new ray helper.
+         * As raycast might be hard to debug, the RayHelper can help rendering the different rays
+         * in order to better appreciate the issue one might have.
+         * @see http://doc.babylonjs.com/babylon101/raycasts#debugging
+         * @param ray Defines the ray we are currently tryin to visualize
+         */
         constructor(ray: Ray) {
             this.ray = ray;
         }
 
+        /**
+         * Shows the ray we are willing to debug.
+         * @param scene Defines the scene the ray needs to be rendered in
+         * @param color Defines the color the ray needs to be rendered in
+         */
         public show(scene: Scene, color?: Color3): void {
 
             if (!this._renderFunction && this.ray) {
@@ -47,6 +74,9 @@ module BABYLON {
 
         }
 
+        /**
+         * Hides the ray we are debugging.
+         */
         public hide(): void {
 
             if (this._renderFunction && this._scene) {
@@ -82,6 +112,13 @@ module BABYLON {
 
         }
 
+        /**
+         * Attach a ray helper to a mesh so that we can easily see its orientation for instance or information like its normals.
+         * @param mesh Defines the mesh we want the helper attached to
+         * @param meshSpaceDirection Defines the direction of the Ray in mesh space (local space of the mesh node)
+         * @param meshSpaceOrigin Defines the origin of the Ray in mesh space (local space of the mesh node)
+         * @param length Defines the length of the ray
+         */
         public attachToMesh(mesh: AbstractMesh, meshSpaceDirection?: Vector3, meshSpaceOrigin?: Vector3, length?: number): void {
 
             this._attachedToMesh = mesh;
@@ -127,9 +164,11 @@ module BABYLON {
             }
 
             this._updateToMesh();
-
         }
 
+        /**
+         * Detach the ray helper from the mesh it has previously been attached to.
+         */
         public detachFromMesh(): void {
 
             if (this._attachedToMesh) {
@@ -157,16 +196,16 @@ module BABYLON {
 
             this._attachedToMesh.getDirectionToRef(this._meshSpaceDirection, ray.direction);
             Vector3.TransformCoordinatesToRef(this._meshSpaceOrigin, this._attachedToMesh.getWorldMatrix(), ray.origin);
-
         }
 
+        /**
+         * Dispose the helper and release its associated resources.
+         */
         public dispose(): void {
 
             this.hide();
             this.detachFromMesh();
             this.ray = null;
-
         }
-
     }
 }