@zephyr3d/scene 0.1.0 → 0.1.2

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.
Files changed (60) hide show
  1. package/README.md +46 -0
  2. package/dist/animation/animation.js +28 -28
  3. package/dist/animation/skeleton.js +14 -14
  4. package/dist/animation/usertrack.js +9 -9
  5. package/dist/app.js +31 -31
  6. package/dist/asset/assetmanager.js +50 -50
  7. package/dist/asset/builtin.js +157 -157
  8. package/dist/asset/loaders/dds/dds_loader.js +11 -11
  9. package/dist/asset/loaders/gltf/gltf_loader.js +10 -10
  10. package/dist/asset/loaders/hdr/hdr.js +5 -5
  11. package/dist/asset/loaders/image/tga_Loader.js +3 -3
  12. package/dist/asset/loaders/image/webimage_loader.js +3 -3
  13. package/dist/asset/loaders/loader.js +19 -19
  14. package/dist/asset/model.js +57 -57
  15. package/dist/blitter/blitter.js +35 -35
  16. package/dist/blitter/box.js +24 -24
  17. package/dist/blitter/depthlimitedgaussion.js +3 -3
  18. package/dist/blitter/gaussianblur.js +21 -21
  19. package/dist/camera/camera.js +68 -68
  20. package/dist/index.d.ts +2 -0
  21. package/dist/material/grassmaterial.js +17 -17
  22. package/dist/material/lambert.js +3 -3
  23. package/dist/material/lightmodel.js +362 -362
  24. package/dist/material/material.js +50 -50
  25. package/dist/material/meshmaterial.js +48 -48
  26. package/dist/material/unlit.js +3 -3
  27. package/dist/posteffect/bloom.js +5 -5
  28. package/dist/posteffect/compositor.js +16 -16
  29. package/dist/posteffect/fxaa.js +5 -5
  30. package/dist/posteffect/grayscale.js +5 -5
  31. package/dist/posteffect/posteffect.js +42 -42
  32. package/dist/posteffect/sao.js +5 -5
  33. package/dist/posteffect/tonemap.js +5 -5
  34. package/dist/posteffect/water.js +6 -6
  35. package/dist/render/cull_visitor.js +12 -12
  36. package/dist/render/depth_pass.js +8 -8
  37. package/dist/render/envlight.js +104 -104
  38. package/dist/render/render_queue.js +33 -33
  39. package/dist/render/renderpass.js +18 -18
  40. package/dist/render/renderscheme.js +14 -14
  41. package/dist/render/scatteringlut.js +3 -3
  42. package/dist/render/sky.js +38 -38
  43. package/dist/render/temporalcache.js +4 -4
  44. package/dist/render/watermesh.js +5 -5
  45. package/dist/scene/graph_node.js +25 -25
  46. package/dist/scene/octree.js +191 -191
  47. package/dist/scene/scene.js +37 -37
  48. package/dist/scene/terrain/grass.js +27 -27
  49. package/dist/scene/terrain/quadtree.js +45 -45
  50. package/dist/shaders/framework.js +161 -161
  51. package/dist/shaders/lighting.js +7 -7
  52. package/dist/shaders/noise.js +43 -43
  53. package/dist/shadow/shadowmapper.js +76 -76
  54. package/dist/shadow/ssm.js +34 -34
  55. package/dist/utility/bounding_volume.js +30 -27
  56. package/dist/utility/bounding_volume.js.map +1 -1
  57. package/dist/utility/shprojection.js +14 -14
  58. package/package.json +70 -70
  59. package/dist/material/mixins/texture.js +0 -110
  60. package/dist/material/mixins/texture.js.map +0 -1
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # @zephyr3d
2
+
3
+ Zephyr3d is a set of API for 3D rendering within the browser.
4
+
5
+ Zephyr3d is released as ES6 modules and requires npm for installation. It is designed to be used in conjunction with front-end build tools such as Webpack or Vite for development.
6
+
7
+ ## Installation
8
+
9
+ - @zephyr3d/base
10
+
11
+ The basic module includes a math library and content commonly used in other modules.
12
+
13
+ ```npm install --save @zephyr3d/base```
14
+
15
+ - @zephyr3d/device
16
+
17
+ Includes the basic definitions and abstract interfaces of the rendering API.
18
+
19
+ ```npm install --save @zephyr3d/device```
20
+
21
+ - @zephyr3d/backend-webgl
22
+
23
+ WebGL backend, WebGL/WebGL2 rendering.
24
+
25
+ ```npm install --save @zephyr3d/backend-webgl```
26
+
27
+ - @zephyr3d/backend-webgpu
28
+
29
+ WebGPU backend.
30
+
31
+ ```npm install --save @zephyr3d/backend-webgpu```
32
+
33
+ - @zephyr3d/scene
34
+
35
+ The SceneAPI module, built on top of the DeviceAPI module, facilitates rapid development of rendering projects.
36
+
37
+ ```npm install --save @zephyr3d/scene```
38
+
39
+ - @zephyr3d/imgui
40
+
41
+ To render a GUI, you can install the ImGui binding module.
42
+
43
+ ```npm install --save @zephyr3d/imgui```
44
+
45
+
46
+
@@ -2,9 +2,9 @@ import { Quaternion, Vector3, Matrix4x4 } from '@zephyr3d/base';
2
2
  import { BoundingBox } from '../utility/bounding_volume.js';
3
3
  import { Application } from '../app.js';
4
4
 
5
- /**
6
- * Animation that contains multiple tracks
7
- * @public
5
+ /**
6
+ * Animation that contains multiple tracks
7
+ * @public
8
8
  */ class AnimationClip {
9
9
  /** @internal */ _name;
10
10
  /** @internal */ _model;
@@ -20,10 +20,10 @@ import { Application } from '../app.js';
20
20
  /** @internal */ _tmpPosition;
21
21
  /** @internal */ _tmpRotation;
22
22
  /** @internal */ _tmpScale;
23
- /**
24
- * Creates an animation instance
25
- * @param name - Name of the animation
26
- * @param model - Parent node if this is a skeleton animation
23
+ /**
24
+ * Creates an animation instance
25
+ * @param name - Name of the animation
26
+ * @param model - Parent node if this is a skeleton animation
27
27
  */ constructor(name, model){
28
28
  this._name = name;
29
29
  this._model = model ?? null;
@@ -55,11 +55,11 @@ import { Application } from '../app.js';
55
55
  /** The duration of the animation */ get timeDuration() {
56
56
  return this._duration;
57
57
  }
58
- /**
59
- * Adds a skeleton to the animation
60
- * @param skeleton - The skeleton to be added
61
- * @param meshList - The meshes controlled by the skeleton
62
- * @param boundingBoxInfo - Bounding box information for the skeleton
58
+ /**
59
+ * Adds a skeleton to the animation
60
+ * @param skeleton - The skeleton to be added
61
+ * @param meshList - The meshes controlled by the skeleton
62
+ * @param boundingBoxInfo - Bounding box information for the skeleton
63
63
  */ addSkeleton(skeleton, meshList, boundingBoxInfo) {
64
64
  let meshes = this._skeletons.get(skeleton);
65
65
  if (!meshes) {
@@ -74,11 +74,11 @@ import { Application } from '../app.js';
74
74
  });
75
75
  }
76
76
  }
77
- /**
78
- * Adds an animation track to the animation
79
- * @param node - The node that will be controlled by the track
80
- * @param track - The track to be added
81
- * @returns self
77
+ /**
78
+ * Adds an animation track to the animation
79
+ * @param node - The node that will be controlled by the track
80
+ * @param track - The track to be added
81
+ * @returns self
82
82
  */ addTrack(node, track) {
83
83
  if (!track) {
84
84
  return;
@@ -97,14 +97,14 @@ import { Application } from '../app.js';
97
97
  this._duration = Math.max(this._duration, track.interpolator.maxTime);
98
98
  return this;
99
99
  }
100
- /**
101
- * Check if the animation is playing
102
- * @returns true if the animation is playing, otherwise false
100
+ /**
101
+ * Check if the animation is playing
102
+ * @returns true if the animation is playing, otherwise false
103
103
  */ isPlaying() {
104
104
  return this._isPlaying;
105
105
  }
106
- /**
107
- * Updates the animation state
106
+ /**
107
+ * Updates the animation state
108
108
  */ update() {
109
109
  const device = Application.instance.device;
110
110
  if (!this._isPlaying || this._lastUpdateFrame === device.frameInfo.frameCounter) {
@@ -138,8 +138,8 @@ import { Application } from '../app.js';
138
138
  this.stop();
139
139
  }
140
140
  }
141
- /**
142
- * Starts playing the animation
141
+ /**
142
+ * Starts playing the animation
143
143
  */ play(repeat, speedRatio) {
144
144
  this._isPlaying = true;
145
145
  this._repeat = repeat;
@@ -147,8 +147,8 @@ import { Application } from '../app.js';
147
147
  this._currentPlayTime = speedRatio < 0 ? this._duration : 0;
148
148
  this.update();
149
149
  }
150
- /**
151
- * Stops the animation
150
+ /**
151
+ * Stops the animation
152
152
  */ stop() {
153
153
  this._isPlaying = false;
154
154
  this._skeletons.forEach((meshes, skeleton)=>{
@@ -162,8 +162,8 @@ import { Application } from '../app.js';
162
162
  }
163
163
  });
164
164
  }
165
- /**
166
- * Rewind the animation to the first frame
165
+ /**
166
+ * Rewind the animation to the first frame
167
167
  */ rewind() {
168
168
  this._currentPlayTime = 0;
169
169
  }
@@ -5,9 +5,9 @@ const tmpV0 = new Vector3();
5
5
  const tmpV1 = new Vector3();
6
6
  const tmpV2 = new Vector3();
7
7
  const tmpV3 = new Vector3();
8
- /**
9
- * Skeleton for skinned animation
10
- * @public
8
+ /**
9
+ * Skeleton for skinned animation
10
+ * @public
11
11
  */ class Skeleton {
12
12
  /** @internal */ _joints;
13
13
  /** @internal */ _inverseBindMatrices;
@@ -15,11 +15,11 @@ const tmpV3 = new Vector3();
15
15
  /** @internal */ _jointMatrices;
16
16
  /** @internal */ _jointMatrixArray;
17
17
  /** @internal */ _jointTexture;
18
- /**
19
- * Creates an instance of skeleton
20
- * @param joints - The joint nodes
21
- * @param inverseBindMatrices - The inverse binding matrices of the joints
22
- * @param bindPoseMatrices - The binding pose matrices of the joints
18
+ /**
19
+ * Creates an instance of skeleton
20
+ * @param joints - The joint nodes
21
+ * @param inverseBindMatrices - The inverse binding matrices of the joints
22
+ * @param bindPoseMatrices - The binding pose matrices of the joints
23
23
  */ constructor(joints, inverseBindMatrices, bindPoseMatrices){
24
24
  this._joints = joints;
25
25
  this._inverseBindMatrices = inverseBindMatrices;
@@ -28,8 +28,8 @@ const tmpV3 = new Vector3();
28
28
  this._jointMatrices = null;
29
29
  this._jointTexture = null;
30
30
  }
31
- /**
32
- * Disposes self
31
+ /**
32
+ * Disposes self
33
33
  */ dispose() {
34
34
  this._jointTexture?.dispose();
35
35
  this._jointTexture = null;
@@ -39,13 +39,13 @@ const tmpV3 = new Vector3();
39
39
  this._jointMatrices = null;
40
40
  this._jointMatrixArray = null;
41
41
  }
42
- /**
43
- * The joint transform matrices
42
+ /**
43
+ * The joint transform matrices
44
44
  */ get jointMatrices() {
45
45
  return this._jointMatrices;
46
46
  }
47
- /**
48
- * The texture that contains the transform matrices of all the joints
47
+ /**
48
+ * The texture that contains the transform matrices of all the joints
49
49
  */ get jointTexture() {
50
50
  return this._jointTexture;
51
51
  }
@@ -2,17 +2,17 @@ import { Interpolator } from '@zephyr3d/base';
2
2
  import { AnimationTrack } from './animationtrack.js';
3
3
 
4
4
  const tmpValue = new Float32Array(4);
5
- /**
6
- * User-defined animation track
7
- * @public
5
+ /**
6
+ * User-defined animation track
7
+ * @public
8
8
  */ class UserTrack extends AnimationTrack {
9
9
  _handler;
10
- /**
11
- * Create an instance of UserTrack
12
- * @param mode - Interpolation mode for keyframe values
13
- * @param target - Type of keyframe values
14
- * @param keyFrames - Keyframe values
15
- * @param handler - Handler to apply the keyframe values
10
+ /**
11
+ * Create an instance of UserTrack
12
+ * @param mode - Interpolation mode for keyframe values
13
+ * @param target - Type of keyframe values
14
+ * @param keyFrames - Keyframe values
15
+ * @param handler - Handler to apply the keyframe values
16
16
  */ constructor(mode, target, keyFrames, handler){
17
17
  const stride = Interpolator.getTargetStride(target);
18
18
  if (!stride) {
package/dist/app.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import { InputManager } from './input/inputmgr.js';
2
2
  import { makeEventTarget } from '@zephyr3d/base';
3
3
 
4
- /**
5
- * Event that will be fired every frame
6
- *
7
- * @remarks
8
- * This is where all the rendering work is done.
9
- *
10
- * @public
4
+ /**
5
+ * Event that will be fired every frame
6
+ *
7
+ * @remarks
8
+ * This is where all the rendering work is done.
9
+ *
10
+ * @public
11
11
  */ class AppTickEvent {
12
12
  type = 'tick';
13
13
  }
14
- /**
15
- * This event will be fired whenever the device size changes
16
- * @public
14
+ /**
15
+ * This event will be fired whenever the device size changes
16
+ * @public
17
17
  */ class AppResizeEvent {
18
18
  width;
19
19
  height;
@@ -24,17 +24,17 @@ import { makeEventTarget } from '@zephyr3d/base';
24
24
  this.height = height;
25
25
  }
26
26
  }
27
- /**
28
- * Application class
29
- *
30
- * @remarks
31
- * This is the entry point of your application.
32
- * The Application is responsible for initializing the rendering device
33
- * and doing the rendering loop.
34
- * The Application can not be created more than once. You can get the
35
- * instance by calling the 'Application.instance' static method.
36
- *
37
- * @public
27
+ /**
28
+ * Application class
29
+ *
30
+ * @remarks
31
+ * This is the entry point of your application.
32
+ * The Application is responsible for initializing the rendering device
33
+ * and doing the rendering loop.
34
+ * The Application can not be created more than once. You can get the
35
+ * instance by calling the 'Application.instance' static method.
36
+ *
37
+ * @public
38
38
  */ class Application extends makeEventTarget(Object)() {
39
39
  _options;
40
40
  _device;
@@ -46,9 +46,9 @@ import { makeEventTarget } from '@zephyr3d/base';
46
46
  _logger;
47
47
  _elapsed;
48
48
  static _instance;
49
- /**
50
- * Creates an instance of Application
51
- * @param opt - The creation options
49
+ /**
50
+ * Creates an instance of Application
51
+ * @param opt - The creation options
52
52
  */ constructor(opt){
53
53
  super();
54
54
  if (Application._instance) {
@@ -89,16 +89,16 @@ import { makeEventTarget } from '@zephyr3d/base';
89
89
  /** The options that was used to create the application */ get options() {
90
90
  return this._options;
91
91
  }
92
- /**
93
- * Query if the device is ok to render objects now.
94
- *
95
- * @remarks
96
- * False will be returned if the device is lost.
92
+ /**
93
+ * Query if the device is ok to render objects now.
94
+ *
95
+ * @remarks
96
+ * False will be returned if the device is lost.
97
97
  */ get canRender() {
98
98
  return this._canRender;
99
99
  }
100
- /**
101
- * Query time elapsed since last frame in seconds
100
+ /**
101
+ * Query time elapsed since last frame in seconds
102
102
  */ get timeElapsedInSeconds() {
103
103
  return this._elapsed;
104
104
  }
@@ -22,9 +22,9 @@ import { GraphNode } from '../scene/graph_node.js';
22
22
  import { BUILTIN_ASSET_TEXTURE_SHEEN_LUT, BUILTIN_ASSET_TEST_CUBEMAP } from '../values.js';
23
23
  import { TGALoader } from './loaders/image/tga_Loader.js';
24
24
 
25
- /**
26
- * The asset manager
27
- * @public
25
+ /**
26
+ * The asset manager
27
+ * @public
28
28
  */ class AssetManager {
29
29
  /** @internal */ static _builtinTextures = {};
30
30
  /** @internal */ static _builtinTextureLoaders = {
@@ -38,8 +38,8 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
38
38
  /** @internal */ _models;
39
39
  /** @internal */ _binaryDatas;
40
40
  /** @internal */ _textDatas;
41
- /**
42
- * Creates an instance of AssetManager
41
+ /**
42
+ * Creates an instance of AssetManager
43
43
  */ constructor(){
44
44
  this._httpRequest = new HttpRequest();
45
45
  this._textureLoaders = [
@@ -56,47 +56,47 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
56
56
  this._binaryDatas = {};
57
57
  this._textDatas = {};
58
58
  }
59
- /**
60
- * HttpRequest instance of the asset manager
59
+ /**
60
+ * HttpRequest instance of the asset manager
61
61
  */ get httpRequest() {
62
62
  return this._httpRequest;
63
63
  }
64
- /**
65
- * Removes all cached assets
64
+ /**
65
+ * Removes all cached assets
66
66
  */ clearCache() {
67
67
  this._textures = {};
68
68
  this._models = {};
69
69
  this._binaryDatas = {};
70
70
  this._textDatas = {};
71
71
  }
72
- /**
73
- * Adds a texture loader to the asset manager
74
- *
75
- * @remarks
76
- * TODO: this should be a static method
77
- *
78
- * @param loader - The texture loader to be added
72
+ /**
73
+ * Adds a texture loader to the asset manager
74
+ *
75
+ * @remarks
76
+ * TODO: this should be a static method
77
+ *
78
+ * @param loader - The texture loader to be added
79
79
  */ addTextureLoader(loader) {
80
80
  if (loader) {
81
81
  this._textureLoaders.unshift(loader);
82
82
  }
83
83
  }
84
- /**
85
- * Adds a model loader to the asset manager
86
- *
87
- * @remarks
88
- * TODO: this should be a static method
89
- *
90
- * @param loader - The model loader to be added
84
+ /**
85
+ * Adds a model loader to the asset manager
86
+ *
87
+ * @remarks
88
+ * TODO: this should be a static method
89
+ *
90
+ * @param loader - The model loader to be added
91
91
  */ addModelLoader(loader) {
92
92
  if (loader) {
93
93
  this._modelLoaders.unshift(loader);
94
94
  }
95
95
  }
96
- /**
97
- * Fetches a text resource from a given URL
98
- * @param url - The URL from where to fetch the resource
99
- * @returns The fetched text
96
+ /**
97
+ * Fetches a text resource from a given URL
98
+ * @param url - The URL from where to fetch the resource
99
+ * @returns The fetched text
100
100
  */ async fetchTextData(url) {
101
101
  let P = this._textDatas[url];
102
102
  if (!P) {
@@ -105,10 +105,10 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
105
105
  }
106
106
  return P;
107
107
  }
108
- /**
109
- * Fetches a binary resource from a given URL
110
- * @param url - The URL from where to fetch the resource
111
- * @returns
108
+ /**
109
+ * Fetches a binary resource from a given URL
110
+ * @param url - The URL from where to fetch the resource
111
+ * @returns
112
112
  */ async fetchBinaryData(url) {
113
113
  let P = this._binaryDatas[url];
114
114
  if (!P) {
@@ -117,11 +117,11 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
117
117
  }
118
118
  return P;
119
119
  }
120
- /**
121
- * Fetches a texture resource from a given URL
122
- * @param url - The URL from where to fetch the resource
123
- * @param options - Options for texture fetching
124
- * @returns The fetched texture
120
+ /**
121
+ * Fetches a texture resource from a given URL
122
+ * @param url - The URL from where to fetch the resource
123
+ * @param options - Options for texture fetching
124
+ * @returns The fetched texture
125
125
  */ async fetchTexture(url, options) {
126
126
  if (options?.texture) {
127
127
  return this.loadTexture(url, options.mimeType ?? null, !options.linearColorSpace, options.samplerOptions, options.texture);
@@ -149,12 +149,12 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
149
149
  }
150
150
  return P;
151
151
  }
152
- /**
153
- * Fetches a model resource from a given URL and adds it to a scene
154
- * @param scene - The scene to which the model node belongs
155
- * @param url - The URL from where to fetch the resource
156
- * @param mimeType - The MIME type of the model resource
157
- * @returns The created model node
152
+ /**
153
+ * Fetches a model resource from a given URL and adds it to a scene
154
+ * @param scene - The scene to which the model node belongs
155
+ * @param url - The URL from where to fetch the resource
156
+ * @param mimeType - The MIME type of the model resource
157
+ * @returns The created model node
158
158
  */ async fetchModel(scene, url, mimeType) {
159
159
  const sharedModel = await this.fetchModelData(scene, url, mimeType);
160
160
  return this.createSceneNode(scene, sharedModel);
@@ -272,10 +272,10 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
272
272
  }
273
273
  throw new Error(`Can not find loader for asset ${url}`);
274
274
  }
275
- /**
276
- * Fetches a built-in texture
277
- * @param name - Name of the built-in texture
278
- * @returns The built-in texture
275
+ /**
276
+ * Fetches a built-in texture
277
+ * @param name - Name of the built-in texture
278
+ * @returns The built-in texture
279
279
  */ async fetchBuiltinTexture(name, texture) {
280
280
  const loader = AssetManager._builtinTextureLoaders[name];
281
281
  if (!loader) {
@@ -346,10 +346,10 @@ import { TGALoader } from './loaders/image/tga_Loader.js';
346
346
  animationSet
347
347
  };
348
348
  }
349
- /**
350
- * Sets the loader for a given builtin-texture
351
- * @param name - Name of the builtin texture
352
- * @param loader - Loader for the builtin texture
349
+ /**
350
+ * Sets the loader for a given builtin-texture
351
+ * @param name - Name of the builtin texture
352
+ * @param loader - Loader for the builtin texture
353
353
  */ static setBuiltinTextureLoader(name, loader) {
354
354
  if (loader) {
355
355
  this._builtinTextureLoaders[name] = loader;