@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,173 @@
1
+ import { Quaternion, Vector3, Matrix4x4 } from '@zephyr3d/base';
2
+ import { BoundingBox } from '../utility/bounding_volume.js';
3
+ import { Application } from '../app.js';
4
+
5
+ /**
6
+ * Animation that contains multiple tracks
7
+ * @public
8
+ */ class AnimationClip {
9
+ /** @internal */ _name;
10
+ /** @internal */ _model;
11
+ /** @internal */ _repeat;
12
+ /** @internal */ _speedRatio;
13
+ /** @internal */ _repeatCounter;
14
+ /** @internal */ _duration;
15
+ /** @internal */ _isPlaying;
16
+ /** @internal */ _lastUpdateFrame;
17
+ /** @internal */ _currentPlayTime;
18
+ /** @internal */ _tracks;
19
+ /** @internal */ _skeletons;
20
+ /** @internal */ _tmpPosition;
21
+ /** @internal */ _tmpRotation;
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
27
+ */ constructor(name, model){
28
+ this._name = name;
29
+ this._model = model ?? null;
30
+ this._tracks = new Map();
31
+ this._duration = 0;
32
+ this._repeat = 0;
33
+ this._repeatCounter = 0;
34
+ this._speedRatio = 1;
35
+ this._isPlaying = false;
36
+ this._currentPlayTime = 0;
37
+ this._lastUpdateFrame = 0;
38
+ this._skeletons = new Map();
39
+ this._tmpRotation = new Quaternion();
40
+ this._tmpPosition = new Vector3();
41
+ this._tmpScale = new Vector3();
42
+ }
43
+ /** Disposes self */ dispose() {
44
+ this._model = null;
45
+ this._tracks = null;
46
+ this._skeletons?.forEach((val, key)=>key.dispose());
47
+ this._skeletons = null;
48
+ }
49
+ /** Gets the name of the animation */ get name() {
50
+ return this._name;
51
+ }
52
+ /** Gets all the tracks of this animation */ get tracks() {
53
+ return this._tracks;
54
+ }
55
+ /** The duration of the animation */ get timeDuration() {
56
+ return this._duration;
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
63
+ */ addSkeleton(skeleton, meshList, boundingBoxInfo) {
64
+ let meshes = this._skeletons.get(skeleton);
65
+ if (!meshes) {
66
+ meshes = [];
67
+ this._skeletons.set(skeleton, meshes);
68
+ }
69
+ for(let i = 0; i < meshList.length; i++){
70
+ meshes.push({
71
+ mesh: meshList[i],
72
+ bounding: boundingBoxInfo[i],
73
+ box: new BoundingBox()
74
+ });
75
+ }
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
82
+ */ addTrack(node, track) {
83
+ if (!track) {
84
+ return;
85
+ }
86
+ let trackInfo = this._tracks.get(node);
87
+ if (!trackInfo) {
88
+ trackInfo = {
89
+ poseTranslation: new Vector3(node.position),
90
+ poseRotation: new Quaternion(node.rotation),
91
+ poseScaling: new Vector3(node.scale),
92
+ tracks: []
93
+ };
94
+ this._tracks.set(node, trackInfo);
95
+ }
96
+ trackInfo.tracks.push(track);
97
+ this._duration = Math.max(this._duration, track.interpolator.maxTime);
98
+ return this;
99
+ }
100
+ /**
101
+ * Check if the animation is playing
102
+ * @returns true if the animation is playing, otherwise false
103
+ */ isPlaying() {
104
+ return this._isPlaying;
105
+ }
106
+ /**
107
+ * Updates the animation state
108
+ */ update() {
109
+ const device = Application.instance.device;
110
+ if (!this._isPlaying || this._lastUpdateFrame === device.frameInfo.frameCounter) {
111
+ return;
112
+ }
113
+ this._lastUpdateFrame = device.frameInfo.frameCounter;
114
+ this._tracks.forEach((trackInfo, node)=>{
115
+ for (const track of trackInfo.tracks){
116
+ track.apply(node, this._currentPlayTime, this._duration);
117
+ }
118
+ });
119
+ this._skeletons.forEach((meshes, skeleton)=>{
120
+ skeleton.computeJoints();
121
+ for (const mesh of meshes){
122
+ skeleton.computeBoundingBox(mesh.bounding, mesh.mesh.invWorldMatrix);
123
+ mesh.mesh.setBoneMatrices(skeleton.jointTexture);
124
+ mesh.mesh.setInvBindMatrix(mesh.mesh.invWorldMatrix);
125
+ mesh.mesh.setAnimatedBoundingBox(mesh.bounding.boundingBox);
126
+ }
127
+ });
128
+ const timeAdvance = device.frameInfo.elapsedFrame * 0.001 * this._speedRatio;
129
+ this._currentPlayTime += timeAdvance;
130
+ if (this._currentPlayTime > this._duration) {
131
+ this._repeatCounter++;
132
+ this._currentPlayTime = 0;
133
+ } else if (this._currentPlayTime < 0) {
134
+ this._repeatCounter++;
135
+ this._currentPlayTime = this._duration;
136
+ }
137
+ if (this._repeat !== 0 && this._repeatCounter >= this._repeat) {
138
+ this.stop();
139
+ }
140
+ }
141
+ /**
142
+ * Starts playing the animation
143
+ */ play(repeat, speedRatio) {
144
+ this._isPlaying = true;
145
+ this._repeat = repeat;
146
+ this._speedRatio = speedRatio;
147
+ this._currentPlayTime = speedRatio < 0 ? this._duration : 0;
148
+ this.update();
149
+ }
150
+ /**
151
+ * Stops the animation
152
+ */ stop() {
153
+ this._isPlaying = false;
154
+ this._skeletons.forEach((meshes, skeleton)=>{
155
+ skeleton.computeBindPose();
156
+ for (const mesh of meshes){
157
+ const invWorldMatrix = Matrix4x4.multiply(mesh.mesh.invWorldMatrix, this._model.worldMatrix);
158
+ skeleton.computeBoundingBox(mesh.bounding, invWorldMatrix);
159
+ mesh.mesh.setBoneMatrices(skeleton.jointTexture);
160
+ mesh.mesh.setInvBindMatrix(invWorldMatrix);
161
+ mesh.mesh.setAnimatedBoundingBox(mesh.bounding.boundingBox);
162
+ }
163
+ });
164
+ }
165
+ /**
166
+ * Rewind the animation to the first frame
167
+ */ rewind() {
168
+ this._currentPlayTime = 0;
169
+ }
170
+ }
171
+
172
+ export { AnimationClip };
173
+ //# sourceMappingURL=animation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animation.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Animation set
3
+ * @public
4
+ */ class AnimationSet {
5
+ /** @internal */ _animations;
6
+ /** @internal */ _scene;
7
+ /**
8
+ * Creates an instance of AnimationSet
9
+ * @param scene - The scene to which the animation set belongs
10
+ */ constructor(scene){
11
+ this._scene = scene;
12
+ this._scene.animationSet.push(this);
13
+ this._animations = {};
14
+ }
15
+ /**
16
+ * How many animations in this set
17
+ */ get numAnimations() {
18
+ return Object.getOwnPropertyNames(this._animations).length;
19
+ }
20
+ /**
21
+ * Gets an animation clip by name
22
+ * @param name - name of the animation to get
23
+ */ get(name) {
24
+ return this._animations[name] ?? null;
25
+ }
26
+ /**
27
+ * Adds an animation
28
+ */ add(animation) {
29
+ this._animations[animation.name] = animation;
30
+ }
31
+ /**
32
+ * Gets names of all the animations of the model
33
+ * @returns An array of string that contains the animation names
34
+ */ getAnimationNames() {
35
+ return Object.keys(this._animations);
36
+ }
37
+ /**
38
+ * Updates all animations of the model
39
+ */ update() {
40
+ for(const k in this._animations){
41
+ this._animations[k].update();
42
+ }
43
+ }
44
+ /**
45
+ * Checks whether an animation is playing
46
+ * @param name - Name of the animation to be checked
47
+ * @returns true if the animation is playing, otherwise false
48
+ */ isPlayingAnimation(name) {
49
+ if (name) {
50
+ return this._animations[name]?.isPlaying();
51
+ } else {
52
+ for(const k in this._animations){
53
+ if (this._animations[k].isPlaying()) {
54
+ return true;
55
+ }
56
+ }
57
+ return false;
58
+ }
59
+ }
60
+ /**
61
+ * Starts playing an animation of the model
62
+ * @param name - Name of the animation to play
63
+ * @param repeat - The repeat times, 0 for always repeating, default is 1
64
+ * @param ratio - The speed ratio, default is 1. Use negative value to play backwards
65
+ */ playAnimation(name, repeat = 0, speedRatio = 1) {
66
+ const ani = this._animations[name];
67
+ if (ani && !ani.isPlaying()) {
68
+ for (const name of this.getAnimationNames()){
69
+ if (this.isPlayingAnimation(name)) {
70
+ this.stopAnimation(name);
71
+ }
72
+ }
73
+ ani.play(repeat, speedRatio);
74
+ }
75
+ }
76
+ /**
77
+ * Stops playing an animation of the model
78
+ * @param name - Name of the animation to stop playing
79
+ */ stopAnimation(name) {
80
+ this._animations[name]?.stop();
81
+ }
82
+ dispose() {
83
+ const index = this._scene.animationSet.indexOf(this);
84
+ if (index >= 0) {
85
+ this._scene.animationSet.splice(index, 1);
86
+ }
87
+ for(const k in this._animations){
88
+ this._animations[k].dispose();
89
+ }
90
+ this._animations = {};
91
+ }
92
+ }
93
+
94
+ export { AnimationSet };
95
+ //# sourceMappingURL=animationset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animationset.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Base class for any kind of animation track
3
+ * @public
4
+ */ class AnimationTrack {
5
+ /** @internal */ _interpolator;
6
+ /** @internal */ _currentPlayTime;
7
+ /** @internal */ _playing;
8
+ /**
9
+ * Creates a new animation track
10
+ * @param interpolator - Interpolator for the track
11
+ */ constructor(interpolator){
12
+ this._currentPlayTime = 0;
13
+ this._playing = false;
14
+ this._interpolator = interpolator;
15
+ }
16
+ /** Gets the interpolator of the track */ get interpolator() {
17
+ return this._interpolator;
18
+ }
19
+ /** Return true if the track is playing, otherwise false */ get playing() {
20
+ return this._playing;
21
+ }
22
+ /** Starts playing the track */ start() {
23
+ this._playing = true;
24
+ }
25
+ /** Stops playing the track */ stop() {
26
+ this._playing = false;
27
+ }
28
+ /** Rewinds the track to the first frame */ rewind() {
29
+ this._currentPlayTime = 0;
30
+ }
31
+ /** Stops playing the track and rewind to the first frame */ reset() {
32
+ this.stop();
33
+ this._currentPlayTime = 0;
34
+ }
35
+ }
36
+
37
+ export { AnimationTrack };
38
+ //# sourceMappingURL=animationtrack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animationtrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,33 @@
1
+ import { Vector3, Quaternion, Interpolator } from '@zephyr3d/base';
2
+ import { AnimationTrack } from './animationtrack.js';
3
+
4
+ const tmpVec3 = new Vector3();
5
+ const tmpQuat = new Quaternion();
6
+ /**
7
+ * Euler angle rotation animation track
8
+ * @public
9
+ */ class EulerRotationTrack extends AnimationTrack {
10
+ /**
11
+ * Create an instance of EulerRotationTrack from keyframe values
12
+ * @param mode - The interpolation mode of keyframes
13
+ * @param keyFrames - Keyframe values
14
+ */ constructor(mode, keyFrames){
15
+ const inputs = new Float32Array(keyFrames.map((val)=>val.time));
16
+ const outputs = new Float32Array(keyFrames.length * 3);
17
+ for(let i = 0; i < keyFrames.length; i++){
18
+ outputs[i * 3 + 0] = keyFrames[i].value.x;
19
+ outputs[i * 3 + 1] = keyFrames[i].value.y;
20
+ outputs[i * 3 + 2] = keyFrames[i].value.z;
21
+ }
22
+ const interpolator = new Interpolator(mode, 'vec3', inputs, outputs);
23
+ super(interpolator);
24
+ }
25
+ /** {@inheritDoc AnimationTrack.apply} */ apply(node, currentTime, duration) {
26
+ this._interpolator.interpolate(currentTime, duration, tmpVec3);
27
+ node.rotation.set(tmpQuat.fromEulerAngle(tmpVec3.x, tmpVec3.y, tmpVec3.z, 'ZYX'));
28
+ return true;
29
+ }
30
+ }
31
+
32
+ export { EulerRotationTrack };
33
+ //# sourceMappingURL=eulerrotationtrack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eulerrotationtrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,37 @@
1
+ import { Quaternion, Interpolator } from '@zephyr3d/base';
2
+ import { AnimationTrack } from './animationtrack.js';
3
+
4
+ // Reduce gc
5
+ const tmpQuat = new Quaternion();
6
+ /**
7
+ * Rotation animation track
8
+ * @public
9
+ */ class RotationTrack extends AnimationTrack {
10
+ constructor(modeOrInterpolator, keyFrames){
11
+ if (modeOrInterpolator instanceof Interpolator) {
12
+ if (modeOrInterpolator.target !== 'quat') {
13
+ throw new Error(`RotationTrack(): interpolator target must be 'quat'`);
14
+ }
15
+ super(modeOrInterpolator);
16
+ } else {
17
+ const inputs = new Float32Array(keyFrames.map((val)=>val.time));
18
+ const outputs = new Float32Array(keyFrames.length * 4);
19
+ for(let i = 0; i < keyFrames.length; i++){
20
+ outputs[i * 4 + 0] = keyFrames[i].value.x;
21
+ outputs[i * 4 + 1] = keyFrames[i].value.y;
22
+ outputs[i * 4 + 2] = keyFrames[i].value.z;
23
+ outputs[i * 4 + 3] = keyFrames[i].value.w;
24
+ }
25
+ const interpolator = new Interpolator(modeOrInterpolator, 'quat', inputs, outputs);
26
+ super(interpolator);
27
+ }
28
+ }
29
+ /** {@inheritDoc AnimationTrack.apply} */ apply(node, currentTime, duration) {
30
+ this._interpolator.interpolate(currentTime, duration, tmpQuat);
31
+ node.rotation.set(tmpQuat);
32
+ return true;
33
+ }
34
+ }
35
+
36
+ export { RotationTrack };
37
+ //# sourceMappingURL=rotationtrack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rotationtrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,36 @@
1
+ import { Vector3, Interpolator } from '@zephyr3d/base';
2
+ import { AnimationTrack } from './animationtrack.js';
3
+
4
+ // Reduce gc
5
+ const tmpVec3 = new Vector3();
6
+ /**
7
+ * Scale animation track
8
+ * @public
9
+ */ class ScaleTrack extends AnimationTrack {
10
+ constructor(modeOrInterpolator, keyFrames){
11
+ if (modeOrInterpolator instanceof Interpolator) {
12
+ if (modeOrInterpolator.target !== 'vec3') {
13
+ throw new Error(`ScaleTrack(): interpolator target must be 'vec3'`);
14
+ }
15
+ super(modeOrInterpolator);
16
+ } else {
17
+ const inputs = new Float32Array(keyFrames.map((val)=>val.time));
18
+ const outputs = new Float32Array(keyFrames.length * 3);
19
+ for(let i = 0; i < keyFrames.length; i++){
20
+ outputs[i * 3 + 0] = keyFrames[i].value.x;
21
+ outputs[i * 3 + 1] = keyFrames[i].value.y;
22
+ outputs[i * 3 + 2] = keyFrames[i].value.z;
23
+ }
24
+ const interpolator = new Interpolator(modeOrInterpolator, 'vec3', inputs, outputs);
25
+ super(interpolator);
26
+ }
27
+ }
28
+ /** {@inheritDoc AnimationTrack.apply} */ apply(node, currentTime, duration) {
29
+ this._interpolator.interpolate(currentTime, duration, tmpVec3);
30
+ node.scale.set(tmpVec3);
31
+ return true;
32
+ }
33
+ }
34
+
35
+ export { ScaleTrack };
36
+ //# sourceMappingURL=scaletrack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaletrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,97 @@
1
+ import { Vector3, Matrix4x4, nextPowerOf2 } from '@zephyr3d/base';
2
+ import { Application } from '../app.js';
3
+
4
+ const tmpV0 = new Vector3();
5
+ const tmpV1 = new Vector3();
6
+ const tmpV2 = new Vector3();
7
+ const tmpV3 = new Vector3();
8
+ /**
9
+ * Skeleton for skinned animation
10
+ * @public
11
+ */ class Skeleton {
12
+ /** @internal */ _joints;
13
+ /** @internal */ _inverseBindMatrices;
14
+ /** @internal */ _bindPoseMatrices;
15
+ /** @internal */ _jointMatrices;
16
+ /** @internal */ _jointMatrixArray;
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
23
+ */ constructor(joints, inverseBindMatrices, bindPoseMatrices){
24
+ this._joints = joints;
25
+ this._inverseBindMatrices = inverseBindMatrices;
26
+ this._bindPoseMatrices = bindPoseMatrices;
27
+ this._jointMatrixArray = null;
28
+ this._jointMatrices = null;
29
+ this._jointTexture = null;
30
+ }
31
+ /**
32
+ * Disposes self
33
+ */ dispose() {
34
+ this._jointTexture?.dispose();
35
+ this._jointTexture = null;
36
+ this._joints = null;
37
+ this._inverseBindMatrices = null;
38
+ this._bindPoseMatrices = null;
39
+ this._jointMatrices = null;
40
+ this._jointMatrixArray = null;
41
+ }
42
+ /**
43
+ * The joint transform matrices
44
+ */ get jointMatrices() {
45
+ return this._jointMatrices;
46
+ }
47
+ /**
48
+ * The texture that contains the transform matrices of all the joints
49
+ */ get jointTexture() {
50
+ return this._jointTexture;
51
+ }
52
+ /** @internal */ updateJointMatrices(jointTransforms) {
53
+ if (!this._jointTexture) {
54
+ this._createJointTexture();
55
+ }
56
+ for(let i = 0; i < this._joints.length; i++){
57
+ const mat = this._jointMatrices[i];
58
+ Matrix4x4.multiply(jointTransforms ? jointTransforms[i] : this._joints[i].worldMatrix, this._inverseBindMatrices[i], mat);
59
+ }
60
+ }
61
+ /** @internal */ computeBindPose() {
62
+ this.updateJointMatrices(this._bindPoseMatrices);
63
+ this._jointTexture.update(this._jointMatrixArray, 0, 0, this._jointTexture.width, this._jointTexture.height);
64
+ }
65
+ /** @internal */ computeJoints() {
66
+ this.updateJointMatrices();
67
+ this._jointTexture.update(this._jointMatrixArray, 0, 0, this._jointTexture.width, this._jointTexture.height);
68
+ }
69
+ /** @internal */ computeBoundingBox(info, invWorldMatrix) {
70
+ info.boundingBox.beginExtend();
71
+ for(let i = 0; i < info.boundingVertices.length; i++){
72
+ this._jointMatrices[info.boundingVertexBlendIndices[i * 4 + 0]].transformPointAffine(info.boundingVertices[i], tmpV0).scaleBy(info.boundingVertexJointWeights[i * 4 + 0]);
73
+ this._jointMatrices[info.boundingVertexBlendIndices[i * 4 + 1]].transformPointAffine(info.boundingVertices[i], tmpV1).scaleBy(info.boundingVertexJointWeights[i * 4 + 1]);
74
+ this._jointMatrices[info.boundingVertexBlendIndices[i * 4 + 2]].transformPointAffine(info.boundingVertices[i], tmpV2).scaleBy(info.boundingVertexJointWeights[i * 4 + 2]);
75
+ this._jointMatrices[info.boundingVertexBlendIndices[i * 4 + 3]].transformPointAffine(info.boundingVertices[i], tmpV3).scaleBy(info.boundingVertexJointWeights[i * 4 + 3]);
76
+ tmpV0.addBy(tmpV1).addBy(tmpV2).addBy(tmpV3);
77
+ invWorldMatrix.transformPointAffine(tmpV0, tmpV0);
78
+ info.boundingBox.extend(tmpV0);
79
+ }
80
+ }
81
+ /** @internal */ _createJointTexture() {
82
+ const textureWidth = nextPowerOf2(Math.max(4, Math.ceil(Math.sqrt(this._joints.length * 4))));
83
+ this._jointTexture = Application.instance.device.createTexture2D('rgba32f', textureWidth, textureWidth, {
84
+ samplerOptions: {
85
+ magFilter: 'nearest',
86
+ minFilter: 'nearest',
87
+ mipFilter: 'none'
88
+ }
89
+ });
90
+ this._jointMatrixArray = new Float32Array(textureWidth * textureWidth * 4);
91
+ const buffer = this._jointMatrixArray.buffer;
92
+ this._jointMatrices = this._joints.map((val, index)=>new Matrix4x4(buffer, index * 16 * Float32Array.BYTES_PER_ELEMENT));
93
+ }
94
+ }
95
+
96
+ export { Skeleton };
97
+ //# sourceMappingURL=skeleton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skeleton.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,36 @@
1
+ import { Vector3, Interpolator } from '@zephyr3d/base';
2
+ import { AnimationTrack } from './animationtrack.js';
3
+
4
+ // Reduce gc
5
+ const tmpVec3 = new Vector3();
6
+ /**
7
+ * Translate animation track
8
+ * @public
9
+ */ class TranslationTrack extends AnimationTrack {
10
+ constructor(modeOrInterpolator, keyFrames){
11
+ if (modeOrInterpolator instanceof Interpolator) {
12
+ if (modeOrInterpolator.target !== 'vec3') {
13
+ throw new Error(`TranslationTrack(): interpolator target must be 'vec3'`);
14
+ }
15
+ super(modeOrInterpolator);
16
+ } else {
17
+ const inputs = new Float32Array(keyFrames.map((val)=>val.time));
18
+ const outputs = new Float32Array(keyFrames.length * 3);
19
+ for(let i = 0; i < keyFrames.length; i++){
20
+ outputs[i * 3 + 0] = keyFrames[i].value.x;
21
+ outputs[i * 3 + 1] = keyFrames[i].value.y;
22
+ outputs[i * 3 + 2] = keyFrames[i].value.z;
23
+ }
24
+ const interpolator = new Interpolator(modeOrInterpolator, 'vec3', inputs, outputs);
25
+ super(interpolator);
26
+ }
27
+ }
28
+ /** {@inheritDoc AnimationTrack.apply} */ apply(node, currentTime, duration) {
29
+ this._interpolator.interpolate(currentTime, duration, tmpVec3);
30
+ node.position.set(tmpVec3);
31
+ return true;
32
+ }
33
+ }
34
+
35
+ export { TranslationTrack };
36
+ //# sourceMappingURL=translationtrack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"translationtrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,47 @@
1
+ import { Interpolator } from '@zephyr3d/base';
2
+ import { AnimationTrack } from './animationtrack.js';
3
+
4
+ const tmpValue = new Float32Array(4);
5
+ /**
6
+ * User-defined animation track
7
+ * @public
8
+ */ class UserTrack extends AnimationTrack {
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
16
+ */ constructor(mode, target, keyFrames, handler){
17
+ const stride = Interpolator.getTargetStride(target);
18
+ if (!stride) {
19
+ throw new Error(`UserTrack(): invalid target: ${target}`);
20
+ }
21
+ const inputs = new Float32Array(keyFrames.map((val)=>val.time));
22
+ const outputs = new Float32Array(keyFrames.length * stride);
23
+ for(let i = 0; i < keyFrames.length; i++){
24
+ for(let j = 0; j < stride; j++){
25
+ const value = keyFrames[i].value;
26
+ if (typeof value === 'number') {
27
+ outputs[i * stride + j] = value;
28
+ } else if (value instanceof Float32Array) {
29
+ outputs[i * stride + j] = value[j] ?? 0;
30
+ } else {
31
+ throw new Error(`UserTrack(): invalid keyframe value: ${value}`);
32
+ }
33
+ }
34
+ }
35
+ const interpolator = new Interpolator(mode, target, inputs, outputs);
36
+ super(interpolator);
37
+ this._handler = handler;
38
+ }
39
+ /** {@inheritDoc AnimationTrack.apply} */ apply(node, currentTime, duration) {
40
+ this._interpolator.interpolate(currentTime, duration, tmpValue);
41
+ this._handler && this._handler(node, tmpValue);
42
+ return true;
43
+ }
44
+ }
45
+
46
+ export { UserTrack };
47
+ //# sourceMappingURL=usertrack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usertrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}