@shapediver/viewer.rendering-engine.animation-engine 3.3.4 → 3.3.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapediver/viewer.rendering-engine.animation-engine",
3
- "version": "3.3.4",
3
+ "version": "3.3.6",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "Michael Oppitz <michael@shapediver.com>",
@@ -10,11 +10,10 @@
10
10
  "test": "__tests__"
11
11
  },
12
12
  "files": [
13
- "dist",
14
- "src",
15
13
  "package.json",
14
+ "dist/",
16
15
  "README.md",
17
- "tsconfig.json"
16
+ "LICENSE"
18
17
  ],
19
18
  "publishConfig": {
20
19
  "access": "public"
@@ -39,12 +38,12 @@
39
38
  "testEnvironment": "node"
40
39
  },
41
40
  "dependencies": {
42
- "@shapediver/viewer.rendering-engine.rendering-engine": "3.3.4",
43
- "@shapediver/viewer.shared.node-tree": "3.3.4",
44
- "@shapediver/viewer.shared.services": "3.3.4",
45
- "@shapediver/viewer.shared.types": "3.3.4",
41
+ "@shapediver/viewer.rendering-engine.rendering-engine": "3.3.6",
42
+ "@shapediver/viewer.shared.node-tree": "3.3.6",
43
+ "@shapediver/viewer.shared.services": "3.3.6",
44
+ "@shapediver/viewer.shared.types": "3.3.6",
46
45
  "@tweenjs/tween.js": "^18.6.4",
47
46
  "gl-matrix": "3.3.0"
48
47
  },
49
- "gitHead": "8193da527b4e3fc4d90181018bd60d6ac70be3e8"
48
+ "gitHead": "13aea937b128a001e6e93be300674c4a04624c29"
50
49
  }
@@ -1,244 +0,0 @@
1
- import { mat4, quat, vec3, vec4 } from 'gl-matrix'
2
- import { ITree, ITreeNode, Tree } from '@shapediver/viewer.shared.node-tree'
3
- import { AnimationData, GeometryData, IAnimationData } from '@shapediver/viewer.shared.types'
4
- import { IManager } from '@shapediver/viewer.rendering-engine.rendering-engine';
5
- import { IAnimationEngine } from '../interfaces/IAnimationEngine';
6
-
7
- export class AnimationEngine implements IManager, IAnimationEngine {
8
- // #region Properties (3)
9
-
10
- private readonly _tree: ITree = Tree.instance;
11
-
12
- private static _instance: AnimationEngine;
13
-
14
- private _animations: {
15
- [key: string]: IAnimationData
16
- } = {};
17
-
18
- // #endregion Properties (3)
19
-
20
- // #region Public Static Accessors (1)
21
-
22
- public static get instance() {
23
- return this._instance || (this._instance = new this());
24
- }
25
-
26
- // #endregion Public Static Accessors (1)
27
-
28
- // #region Public Accessors (1)
29
-
30
- public get animations(): {
31
- [key: string]: IAnimationData
32
- }
33
- {
34
- return this._animations;
35
- }
36
-
37
- // #endregion Public Accessors (1)
38
-
39
- // #region Public Methods (3)
40
-
41
- public init(): void { }
42
-
43
- public update(deltaTime: number): boolean {
44
- const animations = Object.values(this._animations);
45
- let running = false;
46
-
47
- for (let i = 0; i < animations.length; i++) {
48
- const animation = animations[i];
49
- if (animation.animationTime === -1) {
50
- // if we just stopped we need to render one more time
51
- running = true;
52
- animation.animationTime = 0;
53
- }
54
- if (!animation.animate) continue;
55
- running = true;
56
-
57
- animation.animationTime += deltaTime;
58
- if (animation.animationTime / 1000.0 > animation.duration) {
59
- if (animation.repeat) {
60
- animation.startAnimation();
61
- } else {
62
- animation.stopAnimation();
63
- }
64
- }
65
-
66
- const animationDuration = animation.duration!;
67
- const currentAnimationDeltaTime = (animation.animationTime / 1000.0) % animationDuration;
68
-
69
- for (let j = 0; j < animation.tracks.length; j++) {
70
- const track = animation.tracks[j];
71
- const id = animation.id + '_' + j;
72
- if (currentAnimationDeltaTime < track.times[0] || currentAnimationDeltaTime > track.times[track.times.length - 1]) continue;
73
-
74
- for (let k = 1; k < track.times.length; k++) {
75
- if (currentAnimationDeltaTime < track.times[k] && currentAnimationDeltaTime > track.times[k - 1]) {
76
- const prevAnimation = track.node.transformations.filter(t => t.id === id);
77
- track.node.transformations = track.node.transformations.filter((el) => {
78
- return !prevAnimation.includes(el);
79
- });
80
-
81
- const factor = (currentAnimationDeltaTime - track.times[k - 1]) / (track.times[k] - track.times[k - 1]);
82
-
83
- let translationTransformation = track.node.transformations.find(t => t.id === 'gltf_matrix_translation');
84
- if (!translationTransformation) {
85
- translationTransformation = {
86
- id: 'gltf_matrix_translation',
87
- matrix: mat4.create()
88
- }
89
- track.node.transformations.push(translationTransformation)
90
- }
91
-
92
- let rotationTransformation = track.node.transformations.find(t => t.id === 'gltf_matrix_rotation');
93
- if (!rotationTransformation) {
94
- rotationTransformation = {
95
- id: 'gltf_matrix_rotation',
96
- matrix: mat4.create()
97
- }
98
- track.node.transformations.push(rotationTransformation)
99
- }
100
-
101
- let scaleTransformation = track.node.transformations.find(t => t.id === 'gltf_matrix_scale');
102
- if (!scaleTransformation) {
103
- scaleTransformation = {
104
- id: 'gltf_matrix_scale',
105
- matrix: mat4.create()
106
- }
107
- track.node.transformations.push(scaleTransformation)
108
- }
109
-
110
- if (track.path === 'rotation') {
111
- let pivotMatrix: mat4 | undefined, pivotMatrixInverse: mat4 | undefined;
112
- if (track.pivot) {
113
- pivotMatrix = mat4.fromTranslation(mat4.create(), vec3.fromValues(track.pivot[0], track.pivot[1], track.pivot[2]));
114
- pivotMatrixInverse = mat4.fromTranslation(mat4.create(), vec3.fromValues(-track.pivot[0], -track.pivot[1], -track.pivot[2]));
115
- }
116
-
117
- let quaternion: quat;
118
- if (track.interpolation === 'step') {
119
- quaternion = quat.fromValues(track.values[(k - 1) * 4 + 0], track.values[(k - 1) * 4 + 1], track.values[(k - 1) * 4 + 2], track.values[(k - 1) * 4 + 3]);
120
- } else {
121
- quaternion = quat.slerp(
122
- vec4.create(),
123
- vec4.fromValues(track.values[(k - 1) * 4 + 0], track.values[(k - 1) * 4 + 1], track.values[(k - 1) * 4 + 2], track.values[(k - 1) * 4 + 3]),
124
- vec4.fromValues(track.values[(k) * 4 + 0], track.values[(k) * 4 + 1], track.values[(k) * 4 + 2], track.values[(k) * 4 + 3]),
125
- factor)
126
- }
127
-
128
- const rotationMatrix = mat4.fromQuat(mat4.create(), quaternion);
129
- if (pivotMatrix && pivotMatrixInverse) {
130
- rotationTransformation.matrix = mat4.multiply(mat4.create(), mat4.multiply(mat4.create(), pivotMatrix, rotationMatrix), pivotMatrixInverse);
131
- } else {
132
- rotationTransformation.matrix = rotationMatrix;
133
- }
134
- } else if (track.path === 'translation') {
135
- let vector: vec3;
136
- if (track.interpolation === 'step') {
137
- vector = vec3.fromValues(track.values[(k - 1) * 3 + 0], track.values[(k - 1) * 3 + 1], track.values[(k - 1) * 3 + 2]);
138
- } else {
139
- vector = vec3.lerp(
140
- vec3.create(),
141
- vec3.fromValues(track.values[(k - 1) * 3 + 0], track.values[(k - 1) * 3 + 1], track.values[(k - 1) * 3 + 2]),
142
- vec3.fromValues(track.values[(k) * 3 + 0], track.values[(k) * 3 + 1], track.values[(k) * 3 + 2]),
143
- factor)
144
- }
145
- translationTransformation.matrix = mat4.fromTranslation(mat4.create(), vector);
146
- } else if (track.path === 'scale') {
147
- let pivotMatrix: mat4 | undefined, pivotMatrixInverse: mat4 | undefined;
148
- if (track.pivot) {
149
- pivotMatrix = mat4.fromTranslation(mat4.create(), vec3.fromValues(track.pivot[0], track.pivot[1], track.pivot[2]));
150
- pivotMatrixInverse = mat4.fromTranslation(mat4.create(), vec3.fromValues(-track.pivot[0], -track.pivot[1], -track.pivot[2]));
151
- }
152
-
153
- let vector: vec3;
154
- if (track.interpolation === 'step') {
155
- vector = vec3.fromValues(track.values[(k - 1) * 3 + 0], track.values[(k - 1) * 3 + 1], track.values[(k - 1) * 3 + 2]);
156
- } else {
157
- vector = vec3.lerp(
158
- vec3.create(),
159
- vec3.fromValues(track.values[(k - 1) * 3 + 0], track.values[(k - 1) * 3 + 1], track.values[(k - 1) * 3 + 2]),
160
- vec3.fromValues(track.values[(k) * 3 + 0], track.values[(k) * 3 + 1], track.values[(k) * 3 + 2]),
161
- factor)
162
- }
163
-
164
- const scalingMatrix = mat4.fromScaling(mat4.create(), vector);
165
- if (pivotMatrix && pivotMatrixInverse) {
166
- scaleTransformation.matrix = mat4.multiply(mat4.create(), mat4.multiply(mat4.create(), pivotMatrix, scalingMatrix), pivotMatrixInverse);
167
- } else {
168
- scaleTransformation.matrix = scalingMatrix;
169
- }
170
- } else if (track.path === 'weights') {
171
- let weights: number[] = [];
172
- const weightCount = track.values.length / track.times.length;
173
-
174
- if (track.interpolation === 'step') {
175
- for (let l = 0; l < weightCount; l++)
176
- weights.push(track.values[(k - 1) * weightCount + l])
177
- } else {
178
- for (let l = 0; l < weightCount; l++)
179
- weights.push(track.values[(k - 1) * weightCount + l] * (1.0 - factor) + (factor) * track.values[(k - 1) * weightCount + l]);
180
- }
181
-
182
- const applyWeights = (node: ITreeNode) => {
183
- for (let l = 0; l < node.data.length; l++)
184
- if (node.data[l] instanceof GeometryData && (<GeometryData>node.data[l]).morphWeights.length === weightCount)
185
- (<GeometryData>node.data[l]).morphWeights = weights;
186
-
187
- for (let l = 0; l < node.children.length; l++)
188
- applyWeights(node.children[l])
189
- }
190
- applyWeights(track.node);
191
- }
192
- break;
193
- }
194
- }
195
- }
196
- }
197
- return running;
198
- }
199
-
200
- public updateAnimationData(): void {
201
- this._animations = {};
202
-
203
- const animationArray = this.gatherAnimations();
204
- const names = animationArray.map(a => a.name);
205
-
206
- for (let i = 0; i < animationArray.length; i++) {
207
- const animationName = animationArray[i].name;
208
-
209
- const nameIndices = [];
210
- for (let j = 0; j < names.length; j++)
211
- if (animationName === names[j])
212
- nameIndices.push(j);
213
-
214
- let animationNameAdjusted = animationName;
215
- // name adjustement if the name occurs multiple times
216
- if (nameIndices.length > 1) {
217
- animationNameAdjusted = animationName + '_' + nameIndices.indexOf(i);
218
- // even further name adjustement if the name is even then the same after adjustements (probably will never happen)
219
- while (names.includes(animationNameAdjusted))
220
- animationNameAdjusted += "_0";
221
- }
222
-
223
- this._animations[animationNameAdjusted] = animationArray[i];
224
- }
225
- }
226
-
227
- // #endregion Public Methods (3)
228
-
229
- // #region Private Methods (1)
230
-
231
- private gatherAnimations(node: ITreeNode = this._tree.root): AnimationData[] {
232
- let out: AnimationData[] = [];
233
- for (let i = 0, len = node.data.length; i < len; i++)
234
- if (node.data[i] instanceof AnimationData)
235
- out.push(<AnimationData>node.data[i])
236
-
237
- for (let i = 0, len = node.children.length; i < len; i++)
238
- out = out.concat(this.gatherAnimations(node.children[i]))
239
-
240
- return out;
241
- }
242
-
243
- // #endregion Private Methods (1)
244
- }
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- import { AnimationEngine } from "./implementation/AnimationEngine";
2
- import { IAnimationEngine } from "./interfaces/IAnimationEngine";
3
-
4
- export {
5
- IAnimationEngine,
6
- AnimationEngine
7
- }
@@ -1,28 +0,0 @@
1
- import { IAnimationData } from "@shapediver/viewer.shared.types";
2
-
3
- export interface IAnimationEngine {
4
- // #region Properties (1)
5
-
6
- animations: {
7
- [key: string]: IAnimationData
8
- }
9
-
10
- // #endregion Properties (1)
11
-
12
- // #region Public Methods (2)
13
-
14
- /**
15
- * Update all animations and progress them according to the specified delta time.
16
- *
17
- * returns true, if at least one animation is running
18
- *
19
- * @param deltaTime
20
- */
21
- update(deltaTime: number): boolean;
22
- /**
23
- * Traverse the scene tree and gather all the animation data present in it.
24
- */
25
- updateAnimationData(): void;
26
-
27
- // #endregion Public Methods (2)
28
- }
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "include": [
4
- "./**/*.ts"
5
- ],
6
- "compilerOptions": {
7
- "rootDir": "src",
8
- "outDir": "dist"
9
- },
10
- "exclude": [
11
- "__tests__",
12
- "node_modules",
13
- "dist",
14
- "dist-dev",
15
- "dist-prod"
16
- ]
17
- }