Browse Source

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 6 years ago
parent
commit
f338eb0fa9

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

@@ -50,6 +50,7 @@
 - Added support for inspectable strings ([Deltakosh](https://github.com/deltakosh/))
 
 ### Tools
+- Added `Tools.CreateScreenshotAsync` and `Tools.CreateScreenshotUsingRenderTargetAsync` ([mehmetoguzderin](https://github.com/mehmetoguzderin/))
 - Added `Color3.toHSV()`, `Color3.toHSVToRef()` and `Color3.HSVtoRGBToRef()` ([Deltakosh](https://github.com/deltakosh/))
 - Added `ShadowGenerator.onAfterShadowMapRenderObservable` and `ShadowGenerator.onAfterShadowMapMeshRenderObservable` ([Deltakosh](https://github.com/deltakosh/))
 - Added support for side by side and top bottom images in the `PhotoDome` ([Deltakosh](https://github.com/deltakosh/))
@@ -105,6 +106,7 @@
 - Make planeDragGizmo usable on its own ([TrevorDev](https://github.com/TrevorDev))
 - Fix useObjectOrienationForDragging for pointerDragBehavior when using a single axis drag ([TrevorDev](https://github.com/TrevorDev))
 - Fix VR button not positioning correctly in canvas ([haroldma](https://github.com/haroldma))
+- Fix check for material needing alpha blending in OutlineRenderer ([mkmc](https://github.com/mkmc))
 
 ## Breaking changes
 - Setting mesh.scaling to a new vector will no longer automatically call forceUpdate (this should be done manually when needed) ([TrevorDev](https://github.com/TrevorDev))

+ 60 - 1
src/Misc/screenshotTools.ts

@@ -92,6 +92,33 @@ export class ScreenshotTools {
     }
 
     /**
+     * Captures a screenshot of the current rendering
+     * @see http://doc.babylonjs.com/how_to/render_scene_on_a_png
+     * @param engine defines the rendering engine
+     * @param camera defines the source camera
+     * @param size This parameter can be set to a single number or to an object with the
+     * following (optional) properties: precision, width, height. If a single number is passed,
+     * it will be used for both width and height. If an object is passed, the screenshot size
+     * will be derived from the parameters. The precision property is a multiplier allowing
+     * rendering at a higher or lower resolution
+     * @param mimeType defines the MIME type of the screenshot image (default: image/png).
+     * Check your browser for supported MIME types
+     * @returns screenshot as a string of base64-encoded characters. This string can be assigned
+     * to the src parameter of an <img> to display it
+     */
+    public static CreateScreenshotAsync(engine: Engine, camera: Camera, size: any, mimeType: string = "image/png"): Promise<string> {
+        return new Promise((resolve, reject) => {
+            ScreenshotTools.CreateScreenshot(engine, camera, size, (data) => {
+                if (typeof(data) !== "undefined") {
+                    resolve(data);
+                } else {
+                    reject(new Error("Data is undefined"));
+                }
+            }, mimeType);
+        });
+    }
+
+    /**
      * Generates an image screenshot from the specified camera.
      * @see http://doc.babylonjs.com/how_to/render_scene_on_a_png
      * @param engine The engine to use for rendering
@@ -186,7 +213,39 @@ export class ScreenshotTools {
         engine.setSize(originalSize.width, originalSize.height);
         camera.getProjectionMatrix(true); // Force cache refresh;
     }
+
+    /**
+     * Generates an image screenshot from the specified camera.
+     * @see http://doc.babylonjs.com/how_to/render_scene_on_a_png
+     * @param engine The engine to use for rendering
+     * @param camera The camera to use for rendering
+     * @param size This parameter can be set to a single number or to an object with the
+     * following (optional) properties: precision, width, height. If a single number is passed,
+     * it will be used for both width and height. If an object is passed, the screenshot size
+     * will be derived from the parameters. The precision property is a multiplier allowing
+     * rendering at a higher or lower resolution
+     * @param mimeType The MIME type of the screenshot image (default: image/png).
+     * Check your browser for supported MIME types
+     * @param samples Texture samples (default: 1)
+     * @param antialiasing Whether antialiasing should be turned on or not (default: false)
+     * @param fileName A name for for the downloaded file.
+     * @returns screenshot as a string of base64-encoded characters. This string can be assigned
+     * to the src parameter of an <img> to display it
+     */
+    public static CreateScreenshotUsingRenderTargetAsync(engine: Engine, camera: Camera, size: any, mimeType: string = "image/png", samples: number = 1, antialiasing: boolean = false, fileName?: string): Promise<string> {
+        return new Promise((resolve, reject) => {
+            ScreenshotTools.CreateScreenshotUsingRenderTarget(engine, camera, size, (data) => {
+                if (typeof(data) !== "undefined") {
+                    resolve(data);
+                } else {
+                    reject(new Error("Data is undefined"));
+                }
+            }, mimeType, samples, antialiasing, fileName);
+        });
+    }
 }
 
 Tools.CreateScreenshot = ScreenshotTools.CreateScreenshot;
-Tools.CreateScreenshotUsingRenderTarget = ScreenshotTools.CreateScreenshotUsingRenderTarget;
+Tools.CreateScreenshotAsync = ScreenshotTools.CreateScreenshotAsync;
+Tools.CreateScreenshotUsingRenderTarget = ScreenshotTools.CreateScreenshotUsingRenderTarget;
+Tools.CreateScreenshotUsingRenderTargetAsync = ScreenshotTools.CreateScreenshotUsingRenderTargetAsync;

+ 41 - 0
src/Misc/tools.ts

@@ -759,6 +759,25 @@ export class Tools {
     }
 
     /**
+     * Captures a screenshot of the current rendering
+     * @see http://doc.babylonjs.com/how_to/render_scene_on_a_png
+     * @param engine defines the rendering engine
+     * @param camera defines the source camera
+     * @param size This parameter can be set to a single number or to an object with the
+     * following (optional) properties: precision, width, height. If a single number is passed,
+     * it will be used for both width and height. If an object is passed, the screenshot size
+     * will be derived from the parameters. The precision property is a multiplier allowing
+     * rendering at a higher or lower resolution
+     * @param mimeType defines the MIME type of the screenshot image (default: image/png).
+     * Check your browser for supported MIME types
+     * @returns screenshot as a string of base64-encoded characters. This string can be assigned
+     * to the src parameter of an <img> to display it
+     */
+    public static CreateScreenshotAsync(engine: Engine, camera: Camera, size: any, mimeType: string = "image/png"): Promise<string> {
+        throw _DevTools.WarnImport("ScreenshotTools");
+    }
+
+    /**
      * Generates an image screenshot from the specified camera.
      * @see http://doc.babylonjs.com/how_to/render_scene_on_a_png
      * @param engine The engine to use for rendering
@@ -782,6 +801,28 @@ export class Tools {
     }
 
     /**
+     * Generates an image screenshot from the specified camera.
+     * @see http://doc.babylonjs.com/how_to/render_scene_on_a_png
+     * @param engine The engine to use for rendering
+     * @param camera The camera to use for rendering
+     * @param size This parameter can be set to a single number or to an object with the
+     * following (optional) properties: precision, width, height. If a single number is passed,
+     * it will be used for both width and height. If an object is passed, the screenshot size
+     * will be derived from the parameters. The precision property is a multiplier allowing
+     * rendering at a higher or lower resolution
+     * @param mimeType The MIME type of the screenshot image (default: image/png).
+     * Check your browser for supported MIME types
+     * @param samples Texture samples (default: 1)
+     * @param antialiasing Whether antialiasing should be turned on or not (default: false)
+     * @param fileName A name for for the downloaded file.
+     * @returns screenshot as a string of base64-encoded characters. This string can be assigned
+     * to the src parameter of an <img> to display it
+     */
+    public static CreateScreenshotUsingRenderTargetAsync(engine: Engine, camera: Camera, size: any, mimeType: string = "image/png", samples: number = 1, antialiasing: boolean = false, fileName?: string): Promise<string> {
+        throw _DevTools.WarnImport("ScreenshotTools");
+    }
+
+    /**
      * Implementation from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#answer-2117523
      * Be aware Math.random() could cause collisions, but:
      * "All but 6 of the 128 bits of the ID are randomly generated, which means that for any two ids, there's a 1 in 2^^122 (or 5.3x10^^36) chance they'll collide"

+ 14 - 14
src/Particles/solidParticleSystem.ts

@@ -21,7 +21,7 @@ const depthSortFunction = (p1: DepthSortedParticle, p2: DepthSortedParticle) =>
  * The SPS is also a particle system. It provides some methods to manage the particles.
  * However it is behavior agnostic. This means it has no emitter, no particle physics, no particle recycler. You have to implement your own behavior.
  *
- * Full documentation here : http://doc.babylonjs.com/overviews/Solid_Particle_System
+ * Full documentation here : http://doc.babylonjs.com/how_to/Solid_Particle_System
  */
 export class SolidParticleSystem implements IDisposable {
     /**
@@ -55,7 +55,7 @@ export class SolidParticleSystem implements IDisposable {
     public mesh: Mesh;
     /**
      * This empty object is intended to store some SPS specific or temporary values in order to lower the Garbage Collector activity.
-     * Please read : http://doc.babylonjs.com/overviews/Solid_Particle_System#garbage-collector-concerns
+     * Please read : http://doc.babylonjs.com/how_to/Solid_Particle_System#garbage-collector-concerns
      */
     public vars: any = {};
     /**
@@ -64,7 +64,7 @@ export class SolidParticleSystem implements IDisposable {
      * Each element of this array is an object `{idx: int, faceId: int}`.
      * `idx` is the picked particle index in the `SPS.particles` array
      * `faceId` is the picked face index counted within this particle.
-     * Please read : http://doc.babylonjs.com/overviews/Solid_Particle_System#pickable-particles
+     * Please read : http://doc.babylonjs.com/how_to/Solid_Particle_System#pickable-particles
      */
     public pickedParticles: { idx: number; faceId: number }[];
     /**
@@ -481,7 +481,7 @@ export class SolidParticleSystem implements IDisposable {
 
     /**
      * Adds some particles to the SPS from the model shape. Returns the shape id.
-     * Please read the doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#create-an-immutable-sps
+     * Please read the doc : http://doc.babylonjs.com/how_to/Solid_Particle_System#create-an-immutable-sps
      * @param mesh is any Mesh object that will be used as a model for the solid particles.
      * @param nb (positive integer) the number of particles to be created from this model
      * @param options {positionFunction} is an optional javascript function to called for each particle on SPS creation.
@@ -998,7 +998,7 @@ export class SolidParticleSystem implements IDisposable {
 
     /**
      * Visibilty helper : Recomputes the visible size according to the mesh bounding box
-     * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#sps-visibility
+     * doc : http://doc.babylonjs.com/how_to/Solid_Particle_System#sps-visibility
      * @returns the SPS.
      */
     public refreshVisibleSize(): SolidParticleSystem {
@@ -1012,7 +1012,7 @@ export class SolidParticleSystem implements IDisposable {
      * Visibility helper : Sets the size of a visibility box, this sets the underlying mesh bounding box.
      * @param size the size (float) of the visibility box
      * note : this doesn't lock the SPS mesh bounding box.
-     * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#sps-visibility
+     * doc : http://doc.babylonjs.com/how_to/Solid_Particle_System#sps-visibility
      */
     public setVisibilityBox(size: number): void {
         var vis = size / 2;
@@ -1021,7 +1021,7 @@ export class SolidParticleSystem implements IDisposable {
 
     /**
      * Gets whether the SPS as always visible or not
-     * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#sps-visibility
+     * doc : http://doc.babylonjs.com/how_to/Solid_Particle_System#sps-visibility
      */
     public get isAlwaysVisible(): boolean {
         return this._alwaysVisible;
@@ -1029,7 +1029,7 @@ export class SolidParticleSystem implements IDisposable {
 
     /**
      * Sets the SPS as always visible or not
-     * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#sps-visibility
+     * doc : http://doc.babylonjs.com/how_to/Solid_Particle_System#sps-visibility
      */
     public set isAlwaysVisible(val: boolean) {
         this._alwaysVisible = val;
@@ -1038,7 +1038,7 @@ export class SolidParticleSystem implements IDisposable {
 
     /**
      * Sets the SPS visibility box as locked or not. This enables/disables the underlying mesh bounding box updates.
-     * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#sps-visibility
+     * doc : http://doc.babylonjs.com/how_to/Solid_Particle_System#sps-visibility
      */
     public set isVisibilityBoxLocked(val: boolean) {
         this._isVisibilityBoxLocked = val;
@@ -1050,7 +1050,7 @@ export class SolidParticleSystem implements IDisposable {
 
     /**
      * Gets if the SPS visibility box as locked or not. This enables/disables the underlying mesh bounding box updates.
-     * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#sps-visibility
+     * doc : http://doc.babylonjs.com/how_to/Solid_Particle_System#sps-visibility
      */
     public get isVisibilityBoxLocked(): boolean {
         return this._isVisibilityBoxLocked;
@@ -1153,7 +1153,7 @@ export class SolidParticleSystem implements IDisposable {
     /**
      * This function does nothing. It may be overwritten to set all the particle first values.
      * The SPS doesn't call this function, you may have to call it by your own.
-     * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#particle-management
+     * doc : http://doc.babylonjs.com/how_to/Solid_Particle_System#particle-management
      */
     public initParticles(): void {
     }
@@ -1161,7 +1161,7 @@ export class SolidParticleSystem implements IDisposable {
     /**
      * This function does nothing. It may be overwritten to recycle a particle.
      * The SPS doesn't call this function, you may have to call it by your own.
-     * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#particle-management
+     * doc : http://doc.babylonjs.com/how_to/Solid_Particle_System#particle-management
      * @param particle The particle to recycle
      * @returns the recycled particle
      */
@@ -1172,7 +1172,7 @@ export class SolidParticleSystem implements IDisposable {
     /**
      * Updates a particle : this function should  be overwritten by the user.
      * It is called on each particle by `setParticles()`. This is the place to code each particle behavior.
-     * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#particle-management
+     * doc : http://doc.babylonjs.com/how_to/Solid_Particle_System#particle-management
      * @example : just set a particle position or velocity and recycle conditions
      * @param particle The particle to update
      * @returns the updated particle
@@ -1187,7 +1187,7 @@ export class SolidParticleSystem implements IDisposable {
      * @param particle the current particle
      * @param vertex the current index of the current particle
      * @param pt the index of the current vertex in the particle shape
-     * doc : http://doc.babylonjs.com/overviews/Solid_Particle_System#update-each-particle-shape
+     * doc : http://doc.babylonjs.com/how_to/Solid_Particle_System#update-each-particle-shape
      * @example : just set a vertex particle position
      * @returns the updated vertex
      */

+ 2 - 2
src/Rendering/outlineRenderer.ts

@@ -296,7 +296,7 @@ export class OutlineRenderer implements ISceneComponent {
         this._savedDepthWrite = this._engine.getDepthWrite();
         if (mesh.renderOutline) {
             var material = subMesh.getMaterial();
-            if (material && material.needAlphaBlending) {
+            if (material && material.needAlphaBlending()) {
                 this._engine.cacheStencilState();
                 // Draw only to stencil buffer for the original mesh
                 // The resulting stencil buffer will be used so the outline is not visible inside the mesh when the mesh is transparent
@@ -318,7 +318,7 @@ export class OutlineRenderer implements ISceneComponent {
             this.render(subMesh, batch);
             this._engine.setDepthWrite(this._savedDepthWrite);
 
-            if (material && material.needAlphaBlending) {
+            if (material && material.needAlphaBlending()) {
                 this._engine.restoreStencilState();
             }
         }