lythreeframe 1.0.32 → 1.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1664,26 +1664,31 @@ class Viewport {
1664
1664
  }
1665
1665
  this.isRenderStateDirty = false;
1666
1666
  }
1667
- renderAsImage(width = 1024, height = 1024) {
1668
- if (this.postProcessing) {
1669
- this.postProcessing.render();
1670
- }
1671
- else { //console.log("render renderer");
1672
- this.renderer.render(this.app.world.scene, this.app.camera);
1673
- }
1674
- const offscreenCanvas = document.createElement('canvas');
1675
- offscreenCanvas.width = width;
1676
- offscreenCanvas.height = height;
1677
- const context = offscreenCanvas.getContext('2d');
1678
- if (context) {
1679
- context.drawImage(this.renderer.domElement, 0, 0, width, height);
1680
- }
1681
- if (!context) {
1682
- throw Error("Can not create context");
1683
- }
1684
- const ret = offscreenCanvas.toDataURL('image/jpeg');
1685
- offscreenCanvas.remove();
1686
- return ret;
1667
+ async renderAsImage(width = 1024, height = 1024) {
1668
+ return new Promise((resolve, reject) => {
1669
+ try {
1670
+ if (this.postProcessing) {
1671
+ this.postProcessing.render();
1672
+ }
1673
+ else {
1674
+ this.renderer.render(this.app.world.scene, this.app.camera);
1675
+ }
1676
+ const offscreenCanvas = document.createElement('canvas');
1677
+ offscreenCanvas.width = width;
1678
+ offscreenCanvas.height = height;
1679
+ const context = offscreenCanvas.getContext('2d');
1680
+ if (!context) {
1681
+ throw Error("Can not create context");
1682
+ }
1683
+ context.drawImage(this.renderer.domElement, 0, 0, width, height);
1684
+ const ret = offscreenCanvas.toDataURL('image/jpeg');
1685
+ offscreenCanvas.remove();
1686
+ resolve(ret);
1687
+ }
1688
+ catch (error) {
1689
+ reject(error);
1690
+ }
1691
+ });
1687
1692
  }
1688
1693
  destroy() {
1689
1694
  var _a;
@@ -2172,8 +2177,8 @@ class ThreeJsApp {
2172
2177
  // }
2173
2178
  this.camera.updateProjectionMatrix();
2174
2179
  }
2175
- renderAsImage(width = 1024, height = 1024) {
2176
- return this.viewport.renderAsImage(width, height);
2180
+ async renderAsImage(width = 1024, height = 1024) {
2181
+ return await this.viewport.renderAsImage(width, height);
2177
2182
  }
2178
2183
  }
2179
2184
 
@@ -1662,26 +1662,31 @@ class Viewport {
1662
1662
  }
1663
1663
  this.isRenderStateDirty = false;
1664
1664
  }
1665
- renderAsImage(width = 1024, height = 1024) {
1666
- if (this.postProcessing) {
1667
- this.postProcessing.render();
1668
- }
1669
- else { //console.log("render renderer");
1670
- this.renderer.render(this.app.world.scene, this.app.camera);
1671
- }
1672
- const offscreenCanvas = document.createElement('canvas');
1673
- offscreenCanvas.width = width;
1674
- offscreenCanvas.height = height;
1675
- const context = offscreenCanvas.getContext('2d');
1676
- if (context) {
1677
- context.drawImage(this.renderer.domElement, 0, 0, width, height);
1678
- }
1679
- if (!context) {
1680
- throw Error("Can not create context");
1681
- }
1682
- const ret = offscreenCanvas.toDataURL('image/jpeg');
1683
- offscreenCanvas.remove();
1684
- return ret;
1665
+ async renderAsImage(width = 1024, height = 1024) {
1666
+ return new Promise((resolve, reject) => {
1667
+ try {
1668
+ if (this.postProcessing) {
1669
+ this.postProcessing.render();
1670
+ }
1671
+ else {
1672
+ this.renderer.render(this.app.world.scene, this.app.camera);
1673
+ }
1674
+ const offscreenCanvas = document.createElement('canvas');
1675
+ offscreenCanvas.width = width;
1676
+ offscreenCanvas.height = height;
1677
+ const context = offscreenCanvas.getContext('2d');
1678
+ if (!context) {
1679
+ throw Error("Can not create context");
1680
+ }
1681
+ context.drawImage(this.renderer.domElement, 0, 0, width, height);
1682
+ const ret = offscreenCanvas.toDataURL('image/jpeg');
1683
+ offscreenCanvas.remove();
1684
+ resolve(ret);
1685
+ }
1686
+ catch (error) {
1687
+ reject(error);
1688
+ }
1689
+ });
1685
1690
  }
1686
1691
  destroy() {
1687
1692
  var _a;
@@ -2170,8 +2175,8 @@ class ThreeJsApp {
2170
2175
  // }
2171
2176
  this.camera.updateProjectionMatrix();
2172
2177
  }
2173
- renderAsImage(width = 1024, height = 1024) {
2174
- return this.viewport.renderAsImage(width, height);
2178
+ async renderAsImage(width = 1024, height = 1024) {
2179
+ return await this.viewport.renderAsImage(width, height);
2175
2180
  }
2176
2181
  }
2177
2182
 
@@ -46,6 +46,6 @@ export declare class Viewport {
46
46
  onWindowResize(): void;
47
47
  markRenderStateDirty(): void;
48
48
  render(): void;
49
- renderAsImage(width?: number, height?: number): string;
49
+ renderAsImage(width?: number, height?: number): Promise<string>;
50
50
  destroy(): void;
51
51
  }
@@ -29,5 +29,5 @@ export declare class ThreeJsApp {
29
29
  destroy(): void;
30
30
  updateCamera(param: CameraParam): void;
31
31
  onWindowResize(width: number, height: number): void;
32
- renderAsImage(width?: number, height?: number): string;
32
+ renderAsImage(width?: number, height?: number): Promise<string>;
33
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lythreeframe",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "description": "Three.js 封装",
5
5
  "main": "dist/bundle.cjs.js",
6
6
  "module": "dist/bundle.esm.js",