@zephyr3d/scene 0.3.1 → 0.5.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 (174) hide show
  1. package/dist/animation/animation.js +25 -117
  2. package/dist/animation/animation.js.map +1 -1
  3. package/dist/animation/animationset.js +164 -24
  4. package/dist/animation/animationset.js.map +1 -1
  5. package/dist/animation/animationtrack.js +6 -18
  6. package/dist/animation/animationtrack.js.map +1 -1
  7. package/dist/animation/eulerrotationtrack.js +16 -6
  8. package/dist/animation/eulerrotationtrack.js.map +1 -1
  9. package/dist/animation/morphtarget.js +104 -0
  10. package/dist/animation/morphtarget.js.map +1 -0
  11. package/dist/animation/morphtrack.js +68 -0
  12. package/dist/animation/morphtrack.js.map +1 -0
  13. package/dist/animation/rotationtrack.js +15 -7
  14. package/dist/animation/rotationtrack.js.map +1 -1
  15. package/dist/animation/scaletrack.js +15 -7
  16. package/dist/animation/scaletrack.js.map +1 -1
  17. package/dist/animation/skeleton.js +101 -1
  18. package/dist/animation/skeleton.js.map +1 -1
  19. package/dist/animation/translationtrack.js +15 -7
  20. package/dist/animation/translationtrack.js.map +1 -1
  21. package/dist/animation/usertrack.js +2 -2
  22. package/dist/app.js +4 -26
  23. package/dist/app.js.map +1 -1
  24. package/dist/asset/assetmanager.js +58 -107
  25. package/dist/asset/assetmanager.js.map +1 -1
  26. package/dist/asset/loaders/dds/dds.js +77 -3
  27. package/dist/asset/loaders/dds/dds.js.map +1 -1
  28. package/dist/asset/loaders/dds/dds_loader.js +1 -1
  29. package/dist/asset/loaders/gltf/gltf_loader.js +284 -45
  30. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  31. package/dist/asset/loaders/image/tga_Loader.js +1 -1
  32. package/dist/asset/model.js +13 -0
  33. package/dist/asset/model.js.map +1 -1
  34. package/dist/blitter/blitter.js +2 -2
  35. package/dist/camera/camera.js +83 -5
  36. package/dist/camera/camera.js.map +1 -1
  37. package/dist/index.d.ts +5212 -4785
  38. package/dist/index.js +6 -7
  39. package/dist/index.js.map +1 -1
  40. package/dist/material/blinn.js +9 -4
  41. package/dist/material/blinn.js.map +1 -1
  42. package/dist/material/grassmat.js +127 -0
  43. package/dist/material/grassmat.js.map +1 -0
  44. package/dist/material/grassmaterial.js +15 -0
  45. package/dist/material/grassmaterial.js.map +1 -1
  46. package/dist/material/lambert.js +22 -17
  47. package/dist/material/lambert.js.map +1 -1
  48. package/dist/material/lightmodel.js +7 -6
  49. package/dist/material/lightmodel.js.map +1 -1
  50. package/dist/material/lit.js +99 -5
  51. package/dist/material/lit.js.map +1 -1
  52. package/dist/material/material.js +88 -347
  53. package/dist/material/material.js.map +1 -1
  54. package/dist/material/meshmaterial.js +122 -102
  55. package/dist/material/meshmaterial.js.map +1 -1
  56. package/dist/material/mixins/albedocolor.js +11 -3
  57. package/dist/material/mixins/albedocolor.js.map +1 -1
  58. package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
  59. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +3 -3
  60. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +3 -3
  61. package/dist/material/mixins/lit.js +2 -2
  62. package/dist/material/mixins/pbr/common.js +433 -10
  63. package/dist/material/mixins/pbr/common.js.map +1 -1
  64. package/dist/material/pbrmr.js +17 -6
  65. package/dist/material/pbrmr.js.map +1 -1
  66. package/dist/material/pbrsg.js +16 -9
  67. package/dist/material/pbrsg.js.map +1 -1
  68. package/dist/material/shader/helper.js +186 -117
  69. package/dist/material/shader/helper.js.map +1 -1
  70. package/dist/material/terrainlightmodel.js +3 -1
  71. package/dist/material/terrainlightmodel.js.map +1 -1
  72. package/dist/material/terrainmat.js +357 -0
  73. package/dist/material/terrainmat.js.map +1 -0
  74. package/dist/material/terrainmaterial.js +16 -0
  75. package/dist/material/terrainmaterial.js.map +1 -1
  76. package/dist/material/unlit.js +8 -4
  77. package/dist/material/unlit.js.map +1 -1
  78. package/dist/posteffect/bloom.js +34 -45
  79. package/dist/posteffect/bloom.js.map +1 -1
  80. package/dist/posteffect/compositor.js +11 -41
  81. package/dist/posteffect/compositor.js.map +1 -1
  82. package/dist/posteffect/fxaa.js +1 -2
  83. package/dist/posteffect/fxaa.js.map +1 -1
  84. package/dist/posteffect/grayscale.js +1 -2
  85. package/dist/posteffect/grayscale.js.map +1 -1
  86. package/dist/posteffect/posteffect.js +0 -74
  87. package/dist/posteffect/posteffect.js.map +1 -1
  88. package/dist/posteffect/sao.js +13 -29
  89. package/dist/posteffect/sao.js.map +1 -1
  90. package/dist/posteffect/tonemap.js +1 -2
  91. package/dist/posteffect/tonemap.js.map +1 -1
  92. package/dist/posteffect/water.js +20 -18
  93. package/dist/posteffect/water.js.map +1 -1
  94. package/dist/render/abuffer_oit.js +352 -0
  95. package/dist/render/abuffer_oit.js.map +1 -0
  96. package/dist/render/cull_visitor.js +3 -3
  97. package/dist/render/depth_pass.js +3 -2
  98. package/dist/render/depth_pass.js.map +1 -1
  99. package/dist/render/depthpass.js +16 -19
  100. package/dist/render/depthpass.js.map +1 -1
  101. package/dist/render/drawable_mixin.js +152 -0
  102. package/dist/render/drawable_mixin.js.map +1 -0
  103. package/dist/render/envlight.js +165 -31
  104. package/dist/render/envlight.js.map +1 -1
  105. package/dist/render/forward.js +3 -6
  106. package/dist/render/forward.js.map +1 -1
  107. package/dist/render/forward_pass.js +6 -5
  108. package/dist/render/forward_pass.js.map +1 -1
  109. package/dist/render/globalbindgroup_allocator.js +58 -0
  110. package/dist/render/globalbindgroup_allocator.js.map +1 -0
  111. package/dist/render/lightpass.js +83 -49
  112. package/dist/render/lightpass.js.map +1 -1
  113. package/dist/render/objectcolorpass.js +50 -0
  114. package/dist/render/objectcolorpass.js.map +1 -0
  115. package/dist/render/objectpool.js +295 -0
  116. package/dist/render/objectpool.js.map +1 -0
  117. package/dist/render/oit.js +16 -0
  118. package/dist/render/oit.js.map +1 -0
  119. package/dist/render/render_queue.js +294 -107
  120. package/dist/render/render_queue.js.map +1 -1
  121. package/dist/render/renderbundle_wrapper.js +20 -0
  122. package/dist/render/renderbundle_wrapper.js.map +1 -0
  123. package/dist/render/renderer.js +108 -28
  124. package/dist/render/renderer.js.map +1 -1
  125. package/dist/render/renderpass.js +96 -34
  126. package/dist/render/renderpass.js.map +1 -1
  127. package/dist/render/shadowmap_pass.js +18 -37
  128. package/dist/render/shadowmap_pass.js.map +1 -1
  129. package/dist/render/sky.js +2 -2
  130. package/dist/render/watermesh.js +140 -48
  131. package/dist/render/watermesh.js.map +1 -1
  132. package/dist/render/weightedblended_oit.js +171 -0
  133. package/dist/render/weightedblended_oit.js.map +1 -0
  134. package/dist/scene/batchgroup.js +8 -35
  135. package/dist/scene/batchgroup.js.map +1 -1
  136. package/dist/scene/environment.js +24 -4
  137. package/dist/scene/environment.js.map +1 -1
  138. package/dist/scene/graph_node.js +1 -10
  139. package/dist/scene/graph_node.js.map +1 -1
  140. package/dist/scene/mesh.js +42 -32
  141. package/dist/scene/mesh.js.map +1 -1
  142. package/dist/scene/scene.js +7 -37
  143. package/dist/scene/scene.js.map +1 -1
  144. package/dist/scene/scene_node.js +6 -2
  145. package/dist/scene/scene_node.js.map +1 -1
  146. package/dist/scene/terrain/grass.js +26 -11
  147. package/dist/scene/terrain/grass.js.map +1 -1
  148. package/dist/scene/terrain/patch.js +27 -15
  149. package/dist/scene/terrain/patch.js.map +1 -1
  150. package/dist/scene/terrain/quadtree.js +3 -3
  151. package/dist/scene/terrain/terrain.js +0 -8
  152. package/dist/scene/terrain/terrain.js.map +1 -1
  153. package/dist/shaders/lighting.js +14 -10
  154. package/dist/shaders/lighting.js.map +1 -1
  155. package/dist/shaders/water.js +4 -4
  156. package/dist/shadow/esm.js +4 -23
  157. package/dist/shadow/esm.js.map +1 -1
  158. package/dist/shadow/shadowmapper.js +45 -21
  159. package/dist/shadow/shadowmapper.js.map +1 -1
  160. package/dist/shadow/vsm.js +4 -25
  161. package/dist/shadow/vsm.js.map +1 -1
  162. package/dist/utility/draco/decoder.js +116 -0
  163. package/dist/utility/draco/decoder.js.map +1 -0
  164. package/dist/utility/sheenlut.js +196 -0
  165. package/dist/utility/sheenlut.js.map +1 -0
  166. package/dist/values.js +18 -1
  167. package/dist/values.js.map +1 -1
  168. package/package.json +7 -6
  169. package/dist/utility/noisetexture.js +0 -66
  170. package/dist/utility/noisetexture.js.map +0 -1
  171. package/dist/utility/textures/gradientnoise.js +0 -66
  172. package/dist/utility/textures/gradientnoise.js.map +0 -1
  173. package/dist/utility/textures/randomnoise.js +0 -41
  174. package/dist/utility/textures/randomnoise.js.map +0 -1
@@ -0,0 +1,68 @@
1
+ import { AnimationTrack } from './animationtrack.js';
2
+ import '../utility/pmrem.js';
3
+ import '../utility/panorama.js';
4
+ import '../utility/shprojection.js';
5
+ import { Vector3 } from '@zephyr3d/base';
6
+ import { BoundingBox } from '../utility/bounding_volume.js';
7
+ import { MAX_MORPH_TARGETS } from '../values.js';
8
+ import { calculateMorphBoundingBox } from './morphtarget.js';
9
+
10
+ /**
11
+ * Morph target track
12
+ * @public
13
+ */ class MorphTargetTrack extends AnimationTrack {
14
+ _state;
15
+ _boundingBox;
16
+ _defaultWeights;
17
+ /**
18
+ * Create an instance of MorphTargetTrack
19
+ */ constructor(assetTrack, subMesh){
20
+ super(assetTrack.interpolator);
21
+ this._state = {
22
+ numTargets: assetTrack.interpolator.stride,
23
+ boundingBox: new BoundingBox(),
24
+ weights: new Float32Array(MAX_MORPH_TARGETS)
25
+ };
26
+ this._boundingBox = subMesh.targetBox;
27
+ this._defaultWeights = assetTrack.defaultMorphWeights ?? Array.from({
28
+ length: this._state.numTargets
29
+ }).map(()=>0);
30
+ }
31
+ calculateState(currentTime) {
32
+ this._interpolator.interpolate(currentTime, this._state.weights);
33
+ calculateMorphBoundingBox(this._state.boundingBox, this._boundingBox, this._state.weights, this._state.numTargets);
34
+ return this._state;
35
+ }
36
+ applyState(node, state) {
37
+ node.getMorphInfo().bufferSubData(4 * 4, state.weights);
38
+ const animatedBoundingBox = new BoundingBox();
39
+ const originBoundingBox = node.getBoundingVolume().toAABB();
40
+ animatedBoundingBox.minPoint = Vector3.add(originBoundingBox.minPoint, state.boundingBox.minPoint);
41
+ animatedBoundingBox.maxPoint = Vector3.add(originBoundingBox.maxPoint, state.boundingBox.maxPoint);
42
+ node.setAnimatedBoundingBox(animatedBoundingBox);
43
+ }
44
+ mixState(a, b, t) {
45
+ const state = {
46
+ weights: new Float32Array(a.numTargets),
47
+ boundingBox: new BoundingBox(),
48
+ numTargets: a.numTargets
49
+ };
50
+ for(let i = 0; i < a.numTargets; i++){
51
+ state.weights[i] = a.weights[i] + (b.weights[i] - a.weights[i]) * t;
52
+ state.boundingBox.minPoint = Vector3.min(a.boundingBox.minPoint, b.boundingBox.minPoint);
53
+ state.boundingBox.maxPoint = Vector3.max(a.boundingBox.maxPoint, b.boundingBox.maxPoint);
54
+ }
55
+ return state;
56
+ }
57
+ getBlendId() {
58
+ return 'node-morph';
59
+ }
60
+ reset(node) {
61
+ // apply default weights
62
+ this._state.weights.set(this._defaultWeights);
63
+ this.applyState(node, this._state);
64
+ }
65
+ }
66
+
67
+ export { MorphTargetTrack };
68
+ //# sourceMappingURL=morphtrack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"morphtrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,12 +1,11 @@
1
- import { Quaternion, Interpolator } from '@zephyr3d/base';
1
+ import { Interpolator, Quaternion } from '@zephyr3d/base';
2
2
  import { AnimationTrack } from './animationtrack.js';
3
3
 
4
- // Reduce gc
5
- const tmpQuat = new Quaternion();
6
4
  /**
7
5
  * Rotation animation track
8
6
  * @public
9
7
  */ class RotationTrack extends AnimationTrack {
8
+ _state;
10
9
  constructor(modeOrInterpolator, keyFrames){
11
10
  if (modeOrInterpolator instanceof Interpolator) {
12
11
  if (modeOrInterpolator.target !== 'quat') {
@@ -25,11 +24,20 @@ const tmpQuat = new Quaternion();
25
24
  const interpolator = new Interpolator(modeOrInterpolator, 'quat', inputs, outputs);
26
25
  super(interpolator);
27
26
  }
27
+ this._state = new Quaternion();
28
28
  }
29
- /** {@inheritDoc AnimationTrack.apply} */ apply(node, currentTime, duration) {
30
- this._interpolator.interpolate(currentTime, duration, tmpQuat);
31
- node.rotation.set(tmpQuat);
32
- return true;
29
+ calculateState(currentTime) {
30
+ this._interpolator.interpolate(currentTime, this._state);
31
+ return this._state;
32
+ }
33
+ applyState(node, state) {
34
+ node.rotation.set(state);
35
+ }
36
+ mixState(a, b, t) {
37
+ return Quaternion.slerp(a, b, t);
38
+ }
39
+ getBlendId() {
40
+ return 'node-rotation';
33
41
  }
34
42
  }
35
43
 
@@ -1 +1 @@
1
- {"version":3,"file":"rotationtrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"rotationtrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,12 +1,11 @@
1
- import { Vector3, Interpolator } from '@zephyr3d/base';
1
+ import { Interpolator, Vector3 } from '@zephyr3d/base';
2
2
  import { AnimationTrack } from './animationtrack.js';
3
3
 
4
- // Reduce gc
5
- const tmpVec3 = new Vector3();
6
4
  /**
7
5
  * Scale animation track
8
6
  * @public
9
7
  */ class ScaleTrack extends AnimationTrack {
8
+ _state;
10
9
  constructor(modeOrInterpolator, keyFrames){
11
10
  if (modeOrInterpolator instanceof Interpolator) {
12
11
  if (modeOrInterpolator.target !== 'vec3') {
@@ -24,11 +23,20 @@ const tmpVec3 = new Vector3();
24
23
  const interpolator = new Interpolator(modeOrInterpolator, 'vec3', inputs, outputs);
25
24
  super(interpolator);
26
25
  }
26
+ this._state = new Vector3();
27
27
  }
28
- /** {@inheritDoc AnimationTrack.apply} */ apply(node, currentTime, duration) {
29
- this._interpolator.interpolate(currentTime, duration, tmpVec3);
30
- node.scale.set(tmpVec3);
31
- return true;
28
+ calculateState(currentTime) {
29
+ this._interpolator.interpolate(currentTime, this._state);
30
+ return this._state;
31
+ }
32
+ applyState(node, state) {
33
+ node.scale.set(state);
34
+ }
35
+ mixState(a, b, t) {
36
+ return new Vector3(a.x + t * (b.x - a.x), a.y + t * (b.y - a.y), a.z + t * (b.z - a.z));
37
+ }
38
+ getBlendId() {
39
+ return 'node-scale';
32
40
  }
33
41
  }
34
42
 
@@ -1 +1 @@
1
- {"version":3,"file":"scaletrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"scaletrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,5 +1,9 @@
1
1
  import { Vector3, Matrix4x4, nextPowerOf2 } from '@zephyr3d/base';
2
2
  import { Application } from '../app.js';
3
+ import '../utility/pmrem.js';
4
+ import '../utility/panorama.js';
5
+ import '../utility/shprojection.js';
6
+ import { BoundingBox } from '../utility/bounding_volume.js';
3
7
 
4
8
  const tmpV0 = new Vector3();
5
9
  const tmpV1 = new Vector3();
@@ -9,6 +13,7 @@ const tmpV3 = new Vector3();
9
13
  * Skeleton for skinned animation
10
14
  * @public
11
15
  */ class Skeleton {
16
+ /** @internal */ _meshes;
12
17
  /** @internal */ _joints;
13
18
  /** @internal */ _inverseBindMatrices;
14
19
  /** @internal */ _bindPoseMatrices;
@@ -20,13 +25,21 @@ const tmpV3 = new Vector3();
20
25
  * @param joints - The joint nodes
21
26
  * @param inverseBindMatrices - The inverse binding matrices of the joints
22
27
  * @param bindPoseMatrices - The binding pose matrices of the joints
23
- */ constructor(joints, inverseBindMatrices, bindPoseMatrices){
28
+ */ constructor(joints, inverseBindMatrices, bindPoseMatrices, meshes, bounding){
24
29
  this._joints = joints;
25
30
  this._inverseBindMatrices = inverseBindMatrices;
26
31
  this._bindPoseMatrices = bindPoseMatrices;
27
32
  this._jointMatrixArray = null;
28
33
  this._jointMatrices = null;
29
34
  this._jointTexture = null;
35
+ this.updateJointMatrices();
36
+ this._meshes = meshes.map((mesh, index)=>{
37
+ return {
38
+ mesh,
39
+ bounding: this.getBoundingInfo(bounding[index]),
40
+ box: new BoundingBox()
41
+ };
42
+ });
30
43
  }
31
44
  /**
32
45
  * Disposes self
@@ -66,6 +79,25 @@ const tmpV3 = new Vector3();
66
79
  this.updateJointMatrices();
67
80
  this._jointTexture.update(this._jointMatrixArray, 0, 0, this._jointTexture.width, this._jointTexture.height);
68
81
  }
82
+ /** @internal */ apply() {
83
+ this.computeJoints();
84
+ for (const mesh of this._meshes){
85
+ this.computeBoundingBox(mesh.bounding, mesh.mesh.invWorldMatrix);
86
+ mesh.mesh.setBoneMatrices(this.jointTexture);
87
+ mesh.mesh.setInvBindMatrix(mesh.mesh.invWorldMatrix);
88
+ mesh.mesh.setAnimatedBoundingBox(mesh.bounding.boundingBox);
89
+ }
90
+ }
91
+ /** @internal */ reset(model) {
92
+ this.computeBindPose();
93
+ for (const mesh of this._meshes){
94
+ const invWorldMatrix = Matrix4x4.multiply(mesh.mesh.invWorldMatrix, model.worldMatrix);
95
+ this.computeBoundingBox(mesh.bounding, invWorldMatrix);
96
+ mesh.mesh.setBoneMatrices(this.jointTexture);
97
+ mesh.mesh.setInvBindMatrix(invWorldMatrix);
98
+ mesh.mesh.setAnimatedBoundingBox(mesh.bounding.boundingBox);
99
+ }
100
+ }
69
101
  /** @internal */ computeBoundingBox(info, invWorldMatrix) {
70
102
  info.boundingBox.beginExtend();
71
103
  for(let i = 0; i < info.boundingVertices.length; i++){
@@ -91,6 +123,74 @@ const tmpV3 = new Vector3();
91
123
  const buffer = this._jointMatrixArray.buffer;
92
124
  this._jointMatrices = this._joints.map((val, index)=>new Matrix4x4(buffer, index * 16 * Float32Array.BYTES_PER_ELEMENT));
93
125
  }
126
+ /** @internal */ getBoundingInfo(meshData) {
127
+ const indices = [
128
+ 0,
129
+ 0,
130
+ 0,
131
+ 0,
132
+ 0,
133
+ 0
134
+ ];
135
+ let minx = Number.MAX_VALUE;
136
+ let maxx = -Number.MAX_VALUE;
137
+ let miny = Number.MAX_VALUE;
138
+ let maxy = -Number.MAX_VALUE;
139
+ let minz = Number.MAX_VALUE;
140
+ let maxz = -Number.MAX_VALUE;
141
+ const v = meshData.rawPositions;
142
+ const vert = new Vector3();
143
+ const tmpV0 = new Vector3();
144
+ const tmpV1 = new Vector3();
145
+ const tmpV2 = new Vector3();
146
+ const tmpV3 = new Vector3();
147
+ const numVertices = Math.floor(v.length / 3);
148
+ for(let i = 0; i < numVertices; i++){
149
+ vert.setXYZ(v[i * 3], v[i * 3 + 1], v[i * 3 + 2]);
150
+ this.jointMatrices[meshData.rawBlendIndices[i * 4 + 0]].transformPointAffine(vert, tmpV0).scaleBy(meshData.rawJointWeights[i * 4 + 0]);
151
+ this.jointMatrices[meshData.rawBlendIndices[i * 4 + 1]].transformPointAffine(vert, tmpV1).scaleBy(meshData.rawJointWeights[i * 4 + 1]);
152
+ this.jointMatrices[meshData.rawBlendIndices[i * 4 + 2]].transformPointAffine(vert, tmpV2).scaleBy(meshData.rawJointWeights[i * 4 + 2]);
153
+ this.jointMatrices[meshData.rawBlendIndices[i * 4 + 3]].transformPointAffine(vert, tmpV3).scaleBy(meshData.rawJointWeights[i * 4 + 3]);
154
+ tmpV0.addBy(tmpV1).addBy(tmpV2).addBy(tmpV3);
155
+ if (tmpV0.x < minx) {
156
+ minx = tmpV0.x;
157
+ indices[0] = i;
158
+ }
159
+ if (tmpV0.x > maxx) {
160
+ maxx = tmpV0.x;
161
+ indices[1] = i;
162
+ }
163
+ if (tmpV0.y < miny) {
164
+ miny = tmpV0.y;
165
+ indices[2] = i;
166
+ }
167
+ if (tmpV0.y > maxy) {
168
+ maxy = tmpV0.y;
169
+ indices[3] = i;
170
+ }
171
+ if (tmpV0.z < minz) {
172
+ minz = tmpV0.z;
173
+ indices[4] = i;
174
+ }
175
+ if (tmpV0.z > maxz) {
176
+ maxz = tmpV0.z;
177
+ indices[5] = i;
178
+ }
179
+ }
180
+ const info = {
181
+ boundingVertexBlendIndices: new Float32Array(Array.from({
182
+ length: 6 * 4
183
+ }).map((val, index)=>meshData.rawBlendIndices[indices[index >> 2] * 4 + index % 4])),
184
+ boundingVertexJointWeights: new Float32Array(Array.from({
185
+ length: 6 * 4
186
+ }).map((val, index)=>meshData.rawJointWeights[indices[index >> 2] * 4 + index % 4])),
187
+ boundingVertices: Array.from({
188
+ length: 6
189
+ }).map((val, index)=>new Vector3(meshData.rawPositions[indices[index] * 3], meshData.rawPositions[indices[index] * 3 + 1], meshData.rawPositions[indices[index] * 3 + 2])),
190
+ boundingBox: new BoundingBox()
191
+ };
192
+ return info;
193
+ }
94
194
  }
95
195
 
96
196
  export { Skeleton };
@@ -1 +1 @@
1
- {"version":3,"file":"skeleton.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"skeleton.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,12 +1,11 @@
1
- import { Vector3, Interpolator } from '@zephyr3d/base';
1
+ import { Interpolator, Vector3 } from '@zephyr3d/base';
2
2
  import { AnimationTrack } from './animationtrack.js';
3
3
 
4
- // Reduce gc
5
- const tmpVec3 = new Vector3();
6
4
  /**
7
5
  * Translate animation track
8
6
  * @public
9
7
  */ class TranslationTrack extends AnimationTrack {
8
+ _state;
10
9
  constructor(modeOrInterpolator, keyFrames){
11
10
  if (modeOrInterpolator instanceof Interpolator) {
12
11
  if (modeOrInterpolator.target !== 'vec3') {
@@ -24,11 +23,20 @@ const tmpVec3 = new Vector3();
24
23
  const interpolator = new Interpolator(modeOrInterpolator, 'vec3', inputs, outputs);
25
24
  super(interpolator);
26
25
  }
26
+ this._state = new Vector3();
27
27
  }
28
- /** {@inheritDoc AnimationTrack.apply} */ apply(node, currentTime, duration) {
29
- this._interpolator.interpolate(currentTime, duration, tmpVec3);
30
- node.position.set(tmpVec3);
31
- return true;
28
+ calculateState(currentTime) {
29
+ this._interpolator.interpolate(currentTime, this._state);
30
+ return this._state;
31
+ }
32
+ applyState(node, state) {
33
+ node.position.set(state);
34
+ }
35
+ mixState(a, b, t) {
36
+ return new Vector3(a.x + t * (b.x - a.x), a.y + t * (b.y - a.y), a.z + t * (b.z - a.z));
37
+ }
38
+ getBlendId() {
39
+ return 'node-translation';
32
40
  }
33
41
  }
34
42
 
@@ -1 +1 @@
1
- {"version":3,"file":"translationtrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"translationtrack.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -36,8 +36,8 @@ const tmpValue = new Float32Array(4);
36
36
  super(interpolator);
37
37
  this._handler = handler;
38
38
  }
39
- /** {@inheritDoc AnimationTrack.apply} */ apply(node, currentTime, duration) {
40
- this._interpolator.interpolate(currentTime, duration, tmpValue);
39
+ /** {@inheritDoc AnimationTrack.apply} */ apply(node, currentTime) {
40
+ this._interpolator.interpolate(currentTime, tmpValue);
41
41
  this._handler && this._handler(node, tmpValue);
42
42
  return true;
43
43
  }
package/dist/app.js CHANGED
@@ -39,9 +39,7 @@ import { makeEventTarget } from '@zephyr3d/base';
39
39
  _options;
40
40
  _device;
41
41
  _inputManager;
42
- _running;
43
42
  _ready;
44
- _canRender;
45
43
  _drawEvent;
46
44
  _logger;
47
45
  _elapsed;
@@ -62,9 +60,7 @@ import { makeEventTarget } from '@zephyr3d/base';
62
60
  canvas: opt.canvas
63
61
  };
64
62
  this._inputManager = new InputManager(this);
65
- this._running = null;
66
63
  this._ready = false;
67
- this._canRender = false;
68
64
  this._elapsed = 0;
69
65
  this._drawEvent = new AppTickEvent();
70
66
  this._logger = {
@@ -90,14 +86,6 @@ import { makeEventTarget } from '@zephyr3d/base';
90
86
  return this._options;
91
87
  }
92
88
  /**
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
- */ get canRender() {
98
- return this._canRender;
99
- }
100
- /**
101
89
  * Query time elapsed since last frame in seconds
102
90
  */ get timeElapsedInSeconds() {
103
91
  return this._elapsed;
@@ -139,30 +127,20 @@ import { makeEventTarget } from '@zephyr3d/base';
139
127
  }
140
128
  /** Render one frame */ frame() {
141
129
  if (this._ready) {
142
- this._canRender = this.device.beginFrame();
143
130
  this._elapsed = this.device.frameInfo.elapsedFrame * 0.001;
144
131
  this.device.setFramebuffer(null);
145
132
  this.device.setViewport(null);
146
133
  this.device.setScissor(null);
147
134
  this.dispatchEvent(this._drawEvent);
148
- this.device.endFrame();
149
135
  }
150
136
  }
151
137
  /** Start running the rendering loop */ run() {
152
- if (this._running) {
153
- return;
154
- }
155
- const that = this;
156
- (function entry() {
157
- that._running = requestAnimationFrame(entry);
158
- that.frame();
159
- })();
138
+ this.device.runLoop(()=>{
139
+ this.frame();
140
+ });
160
141
  }
161
142
  /** Stop running the rendering loop */ stop() {
162
- if (this._running) {
163
- cancelAnimationFrame(this._running);
164
- this._running = null;
165
- }
143
+ this.device.exitLoop();
166
144
  }
167
145
  /** Message log */ log(text, mode) {
168
146
  this._logger?.log(text, mode);
package/dist/app.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"app.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}