MCPcopy Create free account
hub / github.com/esengine/esengine / main

Function main

scripts/test-animation-times.mjs:206–307  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

204}
205
206async function main() {
207 const { FBXLoader } = await import('../packages/asset-system/dist/index.js');
208
209 const binaryData = readFileSync(filePath);
210 const loader = new FBXLoader();
211
212 const context = {
213 metadata: {
214 path: filePath,
215 name: filePath.split(/[\\/]/).pop(),
216 type: 'model/fbx',
217 guid: '',
218 size: binaryData.length,
219 hash: '',
220 dependencies: [],
221 lastModified: Date.now(),
222 importerVersion: '1.0.0',
223 labels: [],
224 tags: [],
225 version: 1
226 },
227 loadDependency: async () => null
228 };
229
230 const content = {
231 type: 'binary',
232 binary: binaryData.buffer
233 };
234
235 const asset = await loader.parse(content, context);
236
237 if (!asset.skeleton || !asset.animations?.length) {
238 console.log('No skeleton or animation data!');
239 return;
240 }
241
242 const clip = asset.animations[0];
243 const nodes = asset.nodes;
244 const skeleton = asset.skeleton;
245
246 console.log(`Animation: "${clip.name}", duration: ${clip.duration}s`);
247 console.log(`Joints: ${skeleton.joints.length}`);
248
249 // Test at different times
250 const times = [0, clip.duration * 0.25, clip.duration * 0.5, clip.duration * 0.75, clip.duration];
251
252 let prevMatrices = null;
253 for (const time of times) {
254 const animTransforms = sampleAnimation(clip, time, nodes);
255 const skinMatrices = calculateBoneMatrices(skeleton, nodes, animTransforms);
256
257 if (prevMatrices) {
258 // Count how many bones changed
259 let changedCount = 0;
260 let maxChange = 0;
261 for (let i = 0; i < skinMatrices.length; i++) {
262 const diff = matrixDifference(skinMatrices[i], prevMatrices[i]);
263 if (diff > 0.001) {

Callers 1

Calls 11

parseMethod · 0.95
matrixDifferenceFunction · 0.85
popMethod · 0.80
nowMethod · 0.80
sampleAnimationFunction · 0.70
calculateBoneMatricesFunction · 0.70
getMethod · 0.65
logMethod · 0.45
maxMethod · 0.45
mapMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected