1 line
9.3 KiB
Plaintext
1 line
9.3 KiB
Plaintext
|
|
{"version":3,"file":"MorphBlendMesh.cjs","sources":["../../src/misc/MorphBlendMesh.js"],"sourcesContent":["import { MathUtils, Mesh } from 'three'\n\nclass MorphBlendMesh extends Mesh {\n constructor(geometry, material) {\n super(geometry, material)\n\n this.animationsMap = {}\n this.animationsList = []\n\n // prepare default animation\n // (all frames played together in 1 second)\n\n const numFrames = Object.keys(this.morphTargetDictionary).length\n\n const name = '__default'\n\n const startFrame = 0\n const endFrame = numFrames - 1\n\n const fps = numFrames / 1\n\n this.createAnimation(name, startFrame, endFrame, fps)\n this.setAnimationWeight(name, 1)\n }\n\n createAnimation(name, start, end, fps) {\n const animation = {\n start: start,\n end: end,\n\n length: end - start + 1,\n\n fps: fps,\n duration: (end - start) / fps,\n\n lastFrame: 0,\n currentFrame: 0,\n\n active: false,\n\n time: 0,\n direction: 1,\n weight: 1,\n\n directionBackwards: false,\n mirroredLoop: false,\n }\n\n this.animationsMap[name] = animation\n this.animationsList.push(animation)\n }\n\n autoCreateAnimations(fps) {\n const pattern = /([a-z]+)_?(\\d+)/i\n\n let firstAnimation\n\n const frameRanges = {}\n\n let i = 0\n\n for (const key in this.morphTargetDictionary) {\n const chunks = key.match(pattern)\n\n if (chunks && chunks.length > 1) {\n const name = chunks[1]\n\n if (!frameRanges[name]) frameRanges[name] = { start: Infinity, end: -Infinity }\n\n const range = frameRanges[name]\n\n if (i < range.start) range.start = i\n if (i > range.end) range.end = i\n\n if (!firstAnimation) firstAnimation = name\n }\n\n i++\n }\n\n for (const name in frameRanges) {\n const range = frameRanges[name]\n this.createAnimation(name, range.start, range.end, fps)\n }\n\n this.firstAnimation = firstAnimation\n }\n\n setAnimationDirectionForward(name) {\n const animation = this.animationsMap[name]\n\n if (animation) {\n animation.direction = 1\n animation.directionBackwards = false\n }\n }\n\n setAnimationDirectionBackward(name) {\n const animation = this.animationsMap[name]\n\n if (animation) {\n animation.direction = -1\n animation.directionBackwards = true\n }\n }\n\n setAnimationFPS(name, fps) {\n const animation = this.animationsMap[name]\n\n if (animation) {\n animation.fps = fps\n animation.duration = (animation.end - animation.start) / animation.fps\n }\n }\n\n setAnimationDuration(name, duration) {\n const animation = this.animationsMap[name]\n\n if (animation) {\n animation.duration = duration\n animation.fps = (animation.end - animation.start) / animation.duration\n }\n }\n\n setAnimationWeight(name, weight) {\n const animation = this.animationsMap[name]\n\n if (animation) {\n animation.weight = weight\n }\n }\n\n setAnimationTime(name, time) {\n const animation = this.animationsMap[name]\n\n if (animation) {\n animation.time = time\n }\n }\n\n getAnimationTime(name) {\n let time = 0\n\n const animation = this.animationsMap[name]\n\n if (animation) {\n time = animation.time\n }\n\n return time\n }\n\n getAnimationDuration(name) {\n let duration = -1\n\n const animation = this.animationsMap[name]\n\n if (animation) {\n duration = animation.duration\n }\n\n return duration\n }\n\n playAnimation(name) {\n const animation = this.animationsMap[name]\n\n if (animation) {\n animation.time = 0\n animation.active = true\n } else {\n console.warn('THREE.MorphBlendMesh: animation[' + name + '] undefined in .playAnimation()')\n }\n }\n\n stopAnimation(name) {\n const animation = this.animationsMap[name]\n\n if (animation) {\n animation.active = false\n }\n }\n\n update(delta) {\n for (let i = 0, il = this.animationsList.length; i < il; i++) {\n
|