@zephyr3d/scene 0.1.0

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 (236) hide show
  1. package/dist/animation/animation.js +173 -0
  2. package/dist/animation/animation.js.map +1 -0
  3. package/dist/animation/animationset.js +95 -0
  4. package/dist/animation/animationset.js.map +1 -0
  5. package/dist/animation/animationtrack.js +38 -0
  6. package/dist/animation/animationtrack.js.map +1 -0
  7. package/dist/animation/eulerrotationtrack.js +33 -0
  8. package/dist/animation/eulerrotationtrack.js.map +1 -0
  9. package/dist/animation/rotationtrack.js +37 -0
  10. package/dist/animation/rotationtrack.js.map +1 -0
  11. package/dist/animation/scaletrack.js +36 -0
  12. package/dist/animation/scaletrack.js.map +1 -0
  13. package/dist/animation/skeleton.js +97 -0
  14. package/dist/animation/skeleton.js.map +1 -0
  15. package/dist/animation/translationtrack.js +36 -0
  16. package/dist/animation/translationtrack.js.map +1 -0
  17. package/dist/animation/usertrack.js +47 -0
  18. package/dist/animation/usertrack.js.map +1 -0
  19. package/dist/app.js +173 -0
  20. package/dist/app.js.map +1 -0
  21. package/dist/asset/assetmanager.js +476 -0
  22. package/dist/asset/assetmanager.js.map +1 -0
  23. package/dist/asset/builtin.js +373 -0
  24. package/dist/asset/builtin.js.map +1 -0
  25. package/dist/asset/loaders/dds/dds.js +472 -0
  26. package/dist/asset/loaders/dds/dds.js.map +1 -0
  27. package/dist/asset/loaders/dds/dds_loader.js +38 -0
  28. package/dist/asset/loaders/dds/dds_loader.js.map +1 -0
  29. package/dist/asset/loaders/gltf/gltf_loader.js +981 -0
  30. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -0
  31. package/dist/asset/loaders/gltf/helpers.js +314 -0
  32. package/dist/asset/loaders/gltf/helpers.js.map +1 -0
  33. package/dist/asset/loaders/hdr/hdr.js +175 -0
  34. package/dist/asset/loaders/hdr/hdr.js.map +1 -0
  35. package/dist/asset/loaders/image/tga_Loader.js +117 -0
  36. package/dist/asset/loaders/image/tga_Loader.js.map +1 -0
  37. package/dist/asset/loaders/image/webimage_loader.js +50 -0
  38. package/dist/asset/loaders/image/webimage_loader.js.map +1 -0
  39. package/dist/asset/loaders/loader.js +45 -0
  40. package/dist/asset/loaders/loader.js.map +1 -0
  41. package/dist/asset/model.js +264 -0
  42. package/dist/asset/model.js.map +1 -0
  43. package/dist/blitter/blitter.js +389 -0
  44. package/dist/blitter/blitter.js.map +1 -0
  45. package/dist/blitter/box.js +118 -0
  46. package/dist/blitter/box.js.map +1 -0
  47. package/dist/blitter/copy.js +22 -0
  48. package/dist/blitter/copy.js.map +1 -0
  49. package/dist/blitter/depthlimitedgaussion.js +166 -0
  50. package/dist/blitter/depthlimitedgaussion.js.map +1 -0
  51. package/dist/blitter/gaussianblur.js +229 -0
  52. package/dist/blitter/gaussianblur.js.map +1 -0
  53. package/dist/camera/base.js +90 -0
  54. package/dist/camera/base.js.map +1 -0
  55. package/dist/camera/camera.js +358 -0
  56. package/dist/camera/camera.js.map +1 -0
  57. package/dist/camera/fps.js +246 -0
  58. package/dist/camera/fps.js.map +1 -0
  59. package/dist/camera/orbit.js +157 -0
  60. package/dist/camera/orbit.js.map +1 -0
  61. package/dist/camera/orthocamera.js +126 -0
  62. package/dist/camera/orthocamera.js.map +1 -0
  63. package/dist/camera/perspectivecamera.js +133 -0
  64. package/dist/camera/perspectivecamera.js.map +1 -0
  65. package/dist/index.d.ts +8402 -0
  66. package/dist/index.js +87 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/input/inputmgr.js +242 -0
  69. package/dist/input/inputmgr.js.map +1 -0
  70. package/dist/material/blinn.js +75 -0
  71. package/dist/material/blinn.js.map +1 -0
  72. package/dist/material/grassmaterial.js +221 -0
  73. package/dist/material/grassmaterial.js.map +1 -0
  74. package/dist/material/lambert.js +52 -0
  75. package/dist/material/lambert.js.map +1 -0
  76. package/dist/material/lightmodel.js +2074 -0
  77. package/dist/material/lightmodel.js.map +1 -0
  78. package/dist/material/lit.js +578 -0
  79. package/dist/material/lit.js.map +1 -0
  80. package/dist/material/material.js +458 -0
  81. package/dist/material/material.js.map +1 -0
  82. package/dist/material/meshmaterial.js +311 -0
  83. package/dist/material/meshmaterial.js.map +1 -0
  84. package/dist/material/mixins/albedocolor.js +130 -0
  85. package/dist/material/mixins/albedocolor.js.map +1 -0
  86. package/dist/material/mixins/texture.js +110 -0
  87. package/dist/material/mixins/texture.js.map +1 -0
  88. package/dist/material/mixins/vertexcolor.js +45 -0
  89. package/dist/material/mixins/vertexcolor.js.map +1 -0
  90. package/dist/material/pbr.js +27 -0
  91. package/dist/material/pbr.js.map +1 -0
  92. package/dist/material/standard.js +282 -0
  93. package/dist/material/standard.js.map +1 -0
  94. package/dist/material/terrainlightmodel.js +259 -0
  95. package/dist/material/terrainlightmodel.js.map +1 -0
  96. package/dist/material/terrainmaterial.js +139 -0
  97. package/dist/material/terrainmaterial.js.map +1 -0
  98. package/dist/material/unlit.js +29 -0
  99. package/dist/material/unlit.js.map +1 -0
  100. package/dist/posteffect/bloom.js +398 -0
  101. package/dist/posteffect/bloom.js.map +1 -0
  102. package/dist/posteffect/compositor.js +264 -0
  103. package/dist/posteffect/compositor.js.map +1 -0
  104. package/dist/posteffect/fxaa.js +291 -0
  105. package/dist/posteffect/fxaa.js.map +1 -0
  106. package/dist/posteffect/grayscale.js +87 -0
  107. package/dist/posteffect/grayscale.js.map +1 -0
  108. package/dist/posteffect/posteffect.js +165 -0
  109. package/dist/posteffect/posteffect.js.map +1 -0
  110. package/dist/posteffect/sao.js +327 -0
  111. package/dist/posteffect/sao.js.map +1 -0
  112. package/dist/posteffect/tonemap.js +112 -0
  113. package/dist/posteffect/tonemap.js.map +1 -0
  114. package/dist/posteffect/water.js +535 -0
  115. package/dist/posteffect/water.js.map +1 -0
  116. package/dist/render/clipmap.js +462 -0
  117. package/dist/render/clipmap.js.map +1 -0
  118. package/dist/render/cluster_light.js +329 -0
  119. package/dist/render/cluster_light.js.map +1 -0
  120. package/dist/render/cull_visitor.js +124 -0
  121. package/dist/render/cull_visitor.js.map +1 -0
  122. package/dist/render/depth_pass.js +47 -0
  123. package/dist/render/depth_pass.js.map +1 -0
  124. package/dist/render/envlight.js +282 -0
  125. package/dist/render/envlight.js.map +1 -0
  126. package/dist/render/forward.js +186 -0
  127. package/dist/render/forward.js.map +1 -0
  128. package/dist/render/forward_pass.js +137 -0
  129. package/dist/render/forward_pass.js.map +1 -0
  130. package/dist/render/helper.js +38 -0
  131. package/dist/render/helper.js.map +1 -0
  132. package/dist/render/primitive.js +246 -0
  133. package/dist/render/primitive.js.map +1 -0
  134. package/dist/render/render_queue.js +163 -0
  135. package/dist/render/render_queue.js.map +1 -0
  136. package/dist/render/renderpass.js +151 -0
  137. package/dist/render/renderpass.js.map +1 -0
  138. package/dist/render/renderscheme.js +61 -0
  139. package/dist/render/renderscheme.js.map +1 -0
  140. package/dist/render/scatteringlut.js +634 -0
  141. package/dist/render/scatteringlut.js.map +1 -0
  142. package/dist/render/shadowmap_pass.js +70 -0
  143. package/dist/render/shadowmap_pass.js.map +1 -0
  144. package/dist/render/sky.js +881 -0
  145. package/dist/render/sky.js.map +1 -0
  146. package/dist/render/temporalcache.js +222 -0
  147. package/dist/render/temporalcache.js.map +1 -0
  148. package/dist/render/watermesh.js +835 -0
  149. package/dist/render/watermesh.js.map +1 -0
  150. package/dist/scene/environment.js +146 -0
  151. package/dist/scene/environment.js.map +1 -0
  152. package/dist/scene/graph_node.js +69 -0
  153. package/dist/scene/graph_node.js.map +1 -0
  154. package/dist/scene/light.js +436 -0
  155. package/dist/scene/light.js.map +1 -0
  156. package/dist/scene/mesh.js +215 -0
  157. package/dist/scene/mesh.js.map +1 -0
  158. package/dist/scene/model.js +111 -0
  159. package/dist/scene/model.js.map +1 -0
  160. package/dist/scene/octree.js +651 -0
  161. package/dist/scene/octree.js.map +1 -0
  162. package/dist/scene/octree_update_visitor.js +16 -0
  163. package/dist/scene/octree_update_visitor.js.map +1 -0
  164. package/dist/scene/raycast_visitor.js +72 -0
  165. package/dist/scene/raycast_visitor.js.map +1 -0
  166. package/dist/scene/scene.js +225 -0
  167. package/dist/scene/scene.js.map +1 -0
  168. package/dist/scene/scene_node.js +299 -0
  169. package/dist/scene/scene_node.js.map +1 -0
  170. package/dist/scene/terrain/grass.js +277 -0
  171. package/dist/scene/terrain/grass.js.map +1 -0
  172. package/dist/scene/terrain/heightfield.js +391 -0
  173. package/dist/scene/terrain/heightfield.js.map +1 -0
  174. package/dist/scene/terrain/patch.js +530 -0
  175. package/dist/scene/terrain/patch.js.map +1 -0
  176. package/dist/scene/terrain/quadtree.js +430 -0
  177. package/dist/scene/terrain/quadtree.js.map +1 -0
  178. package/dist/scene/terrain/terrain.js +258 -0
  179. package/dist/scene/terrain/terrain.js.map +1 -0
  180. package/dist/scene/xform.js +224 -0
  181. package/dist/scene/xform.js.map +1 -0
  182. package/dist/shaders/builtins.js +110 -0
  183. package/dist/shaders/builtins.js.map +1 -0
  184. package/dist/shaders/framework.js +709 -0
  185. package/dist/shaders/framework.js.map +1 -0
  186. package/dist/shaders/lighting.js +335 -0
  187. package/dist/shaders/lighting.js.map +1 -0
  188. package/dist/shaders/misc.js +405 -0
  189. package/dist/shaders/misc.js.map +1 -0
  190. package/dist/shaders/noise.js +157 -0
  191. package/dist/shaders/noise.js.map +1 -0
  192. package/dist/shaders/pbr.js +132 -0
  193. package/dist/shaders/pbr.js.map +1 -0
  194. package/dist/shaders/shadow.js +642 -0
  195. package/dist/shaders/shadow.js.map +1 -0
  196. package/dist/shaders/water.js +630 -0
  197. package/dist/shaders/water.js.map +1 -0
  198. package/dist/shadow/esm.js +235 -0
  199. package/dist/shadow/esm.js.map +1 -0
  200. package/dist/shadow/pcf_opt.js +182 -0
  201. package/dist/shadow/pcf_opt.js.map +1 -0
  202. package/dist/shadow/pcf_pd.js +190 -0
  203. package/dist/shadow/pcf_pd.js.map +1 -0
  204. package/dist/shadow/shadow_impl.js +15 -0
  205. package/dist/shadow/shadow_impl.js.map +1 -0
  206. package/dist/shadow/shadowmapper.js +709 -0
  207. package/dist/shadow/shadowmapper.js.map +1 -0
  208. package/dist/shadow/ssm.js +194 -0
  209. package/dist/shadow/ssm.js.map +1 -0
  210. package/dist/shadow/vsm.js +298 -0
  211. package/dist/shadow/vsm.js.map +1 -0
  212. package/dist/shapes/box.js +313 -0
  213. package/dist/shapes/box.js.map +1 -0
  214. package/dist/shapes/cylinder.js +74 -0
  215. package/dist/shapes/cylinder.js.map +1 -0
  216. package/dist/shapes/plane.js +48 -0
  217. package/dist/shapes/plane.js.map +1 -0
  218. package/dist/shapes/shape.js +33 -0
  219. package/dist/shapes/shape.js.map +1 -0
  220. package/dist/shapes/sphere.js +91 -0
  221. package/dist/shapes/sphere.js.map +1 -0
  222. package/dist/shapes/torus.js +100 -0
  223. package/dist/shapes/torus.js.map +1 -0
  224. package/dist/utility/aabbtree.js +390 -0
  225. package/dist/utility/aabbtree.js.map +1 -0
  226. package/dist/utility/bounding_volume.js +78 -0
  227. package/dist/utility/bounding_volume.js.map +1 -0
  228. package/dist/utility/panorama.js +163 -0
  229. package/dist/utility/panorama.js.map +1 -0
  230. package/dist/utility/pmrem.js +345 -0
  231. package/dist/utility/pmrem.js.map +1 -0
  232. package/dist/utility/shprojection.js +448 -0
  233. package/dist/utility/shprojection.js.map +1 -0
  234. package/dist/values.js +48 -0
  235. package/dist/values.js.map +1 -0
  236. package/package.json +70 -0
@@ -0,0 +1,215 @@
1
+ import { Vector4 } from '@zephyr3d/base';
2
+ import { GraphNode } from './graph_node.js';
3
+ import { Application } from '../app.js';
4
+ import { BoxFrameShape } from '../shapes/box.js';
5
+ import { StandardMaterial } from '../material/standard.js';
6
+ import '../material/lambert.js';
7
+ import '../material/blinn.js';
8
+ import '../material/unlit.js';
9
+ import { LambertLightModel } from '../material/lightmodel.js';
10
+ import '../material/material.js';
11
+ import '@zephyr3d/device';
12
+ import '../shaders/framework.js';
13
+ import '../render/scatteringlut.js';
14
+
15
+ /**
16
+ * Mesh node
17
+ * @public
18
+ */ class Mesh extends GraphNode {
19
+ /** @internal */ _primitive;
20
+ /** @internal */ _material;
21
+ /** @internal */ _castShadow;
22
+ /** @internal */ _bboxChangeCallback;
23
+ /** @internal */ _animatedBoundingBox;
24
+ /** @internal */ _boneMatrices;
25
+ /** @internal */ _invBindMatrix;
26
+ /** @internal */ _instanceHash;
27
+ /** @internal */ _batchable;
28
+ /** @internal */ _boundingBoxNode;
29
+ /** @internal */ _instanceColor;
30
+ /**
31
+ * Creates an instance of mesh node
32
+ * @param scene - The scene to which the mesh node belongs
33
+ */ constructor(scene, primitive, material){
34
+ super(scene);
35
+ this._primitive = null;
36
+ this._material = null;
37
+ this._castShadow = true;
38
+ this._animatedBoundingBox = null;
39
+ this._boneMatrices = null;
40
+ this._invBindMatrix = null;
41
+ this._instanceHash = null;
42
+ this._boundingBoxNode = null;
43
+ this._instanceColor = Vector4.zero();
44
+ this._batchable = Application.instance.deviceType !== 'webgl';
45
+ this._bboxChangeCallback = this._onBoundingboxChange.bind(this);
46
+ // use setter
47
+ this.primitive = primitive ?? null;
48
+ this.material = material ?? Mesh._getDefaultMaterial();
49
+ }
50
+ /**
51
+ * {@inheritDoc Drawable.getName}
52
+ */ getName() {
53
+ return this._name;
54
+ }
55
+ /**
56
+ * {@inheritDoc BatchDrawable.getInstanceId}
57
+ */ getInstanceId(renderPass) {
58
+ return `${this._instanceHash}:${this.worldMatrixDet >= 0}`;
59
+ }
60
+ /**
61
+ * {@inheritDoc Drawable.getInstanceColor}
62
+ */ getInstanceColor() {
63
+ return this._instanceColor;
64
+ }
65
+ /**
66
+ * {@inheritDoc Drawable.getPickTarget }
67
+ */ getPickTarget() {
68
+ return this;
69
+ }
70
+ /** Wether the mesh node casts shadows */ get castShadow() {
71
+ return this._castShadow;
72
+ }
73
+ set castShadow(b) {
74
+ this._castShadow = b;
75
+ }
76
+ /** Primitive of the mesh */ get primitive() {
77
+ return this._primitive;
78
+ }
79
+ set primitive(prim) {
80
+ if (prim !== this._primitive) {
81
+ if (this._primitive) {
82
+ this._primitive.removeBoundingboxChangeCallback(this._bboxChangeCallback);
83
+ }
84
+ this._primitive = prim || null;
85
+ if (this._primitive) {
86
+ this._primitive.addBoundingboxChangeCallback(this._bboxChangeCallback);
87
+ }
88
+ this._instanceHash = this._primitive && this._material ? `${this.constructor.name}:${this._scene.id}:${this._primitive.id}:${this._material.id}` : null;
89
+ this.invalidateBoundingVolume();
90
+ }
91
+ }
92
+ /** Material of the mesh */ get material() {
93
+ return this._material;
94
+ }
95
+ set material(m) {
96
+ if (this._material !== m) {
97
+ this._material = m;
98
+ this._instanceHash = this._primitive && this._material ? `${this.constructor.name}:${this._scene.id}:${this._primitive.id}:${this._material.id}` : null;
99
+ }
100
+ }
101
+ /** Wether to draw the bounding box of the mesh node */ get drawBoundingBox() {
102
+ return !!this._boundingBoxNode;
103
+ }
104
+ set drawBoundingBox(val) {
105
+ if (!!this._boundingBoxNode !== !!val) {
106
+ if (!val) {
107
+ this._boundingBoxNode.remove();
108
+ this._boundingBoxNode = null;
109
+ } else {
110
+ if (!Mesh._defaultBoxFrame) {
111
+ Mesh._defaultBoxFrame = new BoxFrameShape({
112
+ size: 1
113
+ });
114
+ }
115
+ this._boundingBoxNode = new Mesh(this._scene, Mesh._defaultBoxFrame).reparent(this);
116
+ this._boundingBoxNode.scale.set(this.getBoundingVolume().toAABB().size);
117
+ this._boundingBoxNode.position.set(this.getBoundingVolume().toAABB().minPoint);
118
+ }
119
+ }
120
+ }
121
+ /**
122
+ * {@inheritDoc SceneNode.isMesh}
123
+ */ isMesh() {
124
+ return true;
125
+ }
126
+ /**
127
+ * Sets the bounding box for animation
128
+ * @param bbox - The bounding box for animation
129
+ */ setAnimatedBoundingBox(bbox) {
130
+ this._animatedBoundingBox = bbox;
131
+ this.invalidateBoundingVolume();
132
+ }
133
+ /**
134
+ * Sets the texture that contains the bone matrices for skeletal animation
135
+ * @param matrices - The texture that contains the bone matrices
136
+ */ setBoneMatrices(matrices) {
137
+ this._boneMatrices = matrices;
138
+ }
139
+ /**
140
+ * Sets the inverse bind matrix for skeletal animation
141
+ * @param matrix - The matrix to set
142
+ */ setInvBindMatrix(matrix) {
143
+ this._invBindMatrix = matrix;
144
+ }
145
+ /**
146
+ * {@inheritDoc Drawable.isBatchable}
147
+ */ isBatchable() {
148
+ return this._batchable && !this._boneMatrices;
149
+ }
150
+ /** Disposes the mesh node */ dispose() {
151
+ this._primitive = null;
152
+ this._material = null;
153
+ super.dispose();
154
+ }
155
+ /**
156
+ * {@inheritDoc Drawable.isTransparency}
157
+ */ isTransparency() {
158
+ return !!this.material?.isTransparent();
159
+ }
160
+ /**
161
+ * {@inheritDoc Drawable.isUnlit}
162
+ */ isUnlit() {
163
+ return !this.material?.supportLighting();
164
+ }
165
+ /**
166
+ * {@inheritDoc Drawable.draw}
167
+ */ draw(ctx) {
168
+ this.material.draw(this.primitive, ctx);
169
+ }
170
+ /**
171
+ * {@inheritDoc Drawable.getBoneMatrices}
172
+ */ getBoneMatrices() {
173
+ return this._boneMatrices;
174
+ }
175
+ /**
176
+ * {@inheritDoc Drawable.getInvBindMatrix}
177
+ */ getInvBindMatrix() {
178
+ return this._invBindMatrix;
179
+ }
180
+ /**
181
+ * {@inheritDoc Drawable.getXForm}
182
+ */ getXForm() {
183
+ // mesh transform should be ignored when skinned
184
+ return this;
185
+ }
186
+ /** @internal */ computeBoundingVolume(bv) {
187
+ let bbox;
188
+ if (this._animatedBoundingBox) {
189
+ bbox = this._animatedBoundingBox;
190
+ } else {
191
+ const primitive = this.primitive;
192
+ bbox = primitive ? primitive.getBoundingVolume() : null;
193
+ }
194
+ if (bbox && this._boundingBoxNode) {
195
+ this._boundingBoxNode.scale.set(bbox.toAABB().size);
196
+ this._boundingBoxNode.position.set(bbox.toAABB().minPoint);
197
+ }
198
+ return bbox;
199
+ }
200
+ /** @internal */ _onBoundingboxChange() {
201
+ this.invalidateBoundingVolume();
202
+ }
203
+ /** @internal */ static _defaultMaterial = null;
204
+ /** @internal */ static _defaultBoxFrame = null;
205
+ /** @internal */ static _getDefaultMaterial() {
206
+ if (!this._defaultMaterial) {
207
+ this._defaultMaterial = new StandardMaterial();
208
+ this._defaultMaterial.lightModel = new LambertLightModel();
209
+ }
210
+ return this._defaultMaterial;
211
+ }
212
+ }
213
+
214
+ export { Mesh };
215
+ //# sourceMappingURL=mesh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mesh.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,111 @@
1
+ import { AnimationClip } from '../animation/animation.js';
2
+ import { GraphNode } from './graph_node.js';
3
+
4
+ /**
5
+ * Model node
6
+ * @public
7
+ */ class Model extends GraphNode {
8
+ /** @internal */ _animations;
9
+ /** @internal */ _animationIndex;
10
+ /** @internal */ _updateCallback;
11
+ /**
12
+ * Creates an instance of model node
13
+ * @param scene - The scene to which the model belongs
14
+ */ constructor(scene){
15
+ super(scene);
16
+ this._animations = {};
17
+ this._animationIndex = 0;
18
+ this._updateCallback = (evt)=>{
19
+ if (this.attached) {
20
+ this.update();
21
+ }
22
+ };
23
+ }
24
+ /**
25
+ * Creates a new animation for the model
26
+ * @param name - Name of the animation to be created
27
+ * @returns The created animation
28
+ */ createAnimation(name) {
29
+ if (!name) {
30
+ for(;;){
31
+ name = `animation${this._animationIndex++}`;
32
+ if (!this._animationIndex[name]) {
33
+ break;
34
+ }
35
+ }
36
+ }
37
+ if (this._animations[name]) {
38
+ console.error(`Model.createAnimation() failed: animation '${name}' already exists`);
39
+ return null;
40
+ } else {
41
+ const ani = new AnimationClip(name, this);
42
+ this._animations[name] = ani;
43
+ return ani;
44
+ }
45
+ }
46
+ /**
47
+ * Deletes an animation of this model
48
+ * @param name - Name of the animation to be deleted
49
+ */ deleteAnimation(name) {
50
+ this.stopAnimation(name);
51
+ delete this._animations[name];
52
+ }
53
+ /**
54
+ * Gets names of all the animations of the model
55
+ * @returns An array of string that contains the animation names
56
+ */ getAnimationNames() {
57
+ return Object.keys(this._animations);
58
+ }
59
+ /**
60
+ * Updates all animations of the model
61
+ */ update() {
62
+ for(const k in this._animations){
63
+ this._animations[k].update();
64
+ }
65
+ }
66
+ /**
67
+ * Checks whether an animation is playing
68
+ * @param name - Name of the animation to be checked
69
+ * @returns true if the animation is playing, otherwise false
70
+ */ isPlayingAnimation(name) {
71
+ if (name) {
72
+ return this._animations[name]?.isPlaying();
73
+ } else {
74
+ for(const k in this._animations){
75
+ if (this._animations[k].isPlaying()) {
76
+ return true;
77
+ }
78
+ }
79
+ return false;
80
+ }
81
+ }
82
+ /**
83
+ * Starts playing an animation of the model
84
+ * @param name - Name of the animation to play
85
+ * @param repeat - The repeat times, 0 for always repeating
86
+ */ playAnimation(name, repeat = 1) {
87
+ const ani = this._animations[name];
88
+ if (ani && !ani.isPlaying()) {
89
+ for (const name of this.getAnimationNames()){
90
+ if (this.isPlayingAnimation(name)) {
91
+ this.stopAnimation(name);
92
+ }
93
+ }
94
+ ani.play(repeat, 1);
95
+ this.scene.on('sceneupdate', this._updateCallback);
96
+ }
97
+ }
98
+ /**
99
+ * Stops playing an animation of the model
100
+ * @param name - Name of the animation to stop playing
101
+ */ stopAnimation(name) {
102
+ const isPlaying = this.isPlayingAnimation();
103
+ this._animations[name]?.stop();
104
+ if (isPlaying && !this.isPlayingAnimation()) {
105
+ this.scene.off('sceneupdate', this._updateCallback);
106
+ }
107
+ }
108
+ }
109
+
110
+ export { Model };
111
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}