Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: modernize & tree-shake #241

Merged
merged 20 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@
"module": "./dist/index.mjs",
"sideEffects": false,
"devDependencies": {
"@types/three": "^0.139.0",
"@types/three": "^0.128.0",
"copyfiles": "^2.4.1",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"three": "^0.139.2",
"typescript": "^4.2.4",
"three": "^0.128.0",
"typescript": "^4.7.4",
"vite": "^4.3.8"
},
"dependencies": {
"@types/draco3d": "^1.4.0",
"@types/offscreencanvas": "^2019.6.4",
"@types/webxr": "^0.5.2",
"@webgpu/glslang": "^0.0.15",
"chevrotain": "^10.1.2",
"draco3d": "^1.4.1",
"fflate": "^0.6.9",
Expand All @@ -49,7 +48,7 @@
"zstddec": "^0.0.2"
},
"peerDependencies": {
"three": ">=0.122.0"
"three": ">=0.128.0"
},
"scripts": {
"build": "rimraf dist && vite build && tsc --emitDeclarationOnly && copyfiles -u 1 \"src/**/*.d.ts\" dist",
Expand Down
126 changes: 63 additions & 63 deletions src/animation/AnimationClipCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,98 +7,98 @@ import {
VectorKeyframeTrack,
} from 'three'

const AnimationClipCreator = () => {}
class AnimationClipCreator {
static CreateRotationAnimation(period, axis = 'x') {
const times = [0, period],
values = [0, 360]

AnimationClipCreator.CreateRotationAnimation = (period, axis) => {
const times = [0, period],
values = [0, 360]
const trackName = '.rotation[' + axis + ']'

axis = axis || 'x'
const trackName = `.rotation[${axis}]`
const track = new NumberKeyframeTrack(trackName, times, values)

const track = new NumberKeyframeTrack(trackName, times, values)
return new AnimationClip(null, period, [track])
}

return new AnimationClip(null, period, [track])
}
static CreateScaleAxisAnimation(period, axis = 'x') {
const times = [0, period],
values = [0, 1]

AnimationClipCreator.CreateScaleAxisAnimation = (period, axis) => {
const times = [0, period],
values = [0, 1]
const trackName = '.scale[' + axis + ']'

axis = axis || 'x'
const trackName = `.scale[${axis}]`
const track = new NumberKeyframeTrack(trackName, times, values)

const track = new NumberKeyframeTrack(trackName, times, values)
return new AnimationClip(null, period, [track])
}

return new AnimationClip(null, period, [track])
}
static CreateShakeAnimation(duration, shakeScale) {
const times = [],
values = [],
tmp = new Vector3()

AnimationClipCreator.CreateShakeAnimation = (duration, shakeScale) => {
const times = [],
values = [],
tmp = new Vector3()
for (let i = 0; i < duration * 10; i++) {
times.push(i / 10)

for (let i = 0; i < duration * 10; i++) {
times.push(i / 10)
tmp
.set(Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0)
.multiply(shakeScale)
.toArray(values, values.length)
}

tmp
.set(Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0)
.multiply(shakeScale)
.toArray(values, values.length)
}
const trackName = '.position'

const trackName = '.position'
const track = new VectorKeyframeTrack(trackName, times, values)

const track = new VectorKeyframeTrack(trackName, times, values)
return new AnimationClip(null, duration, [track])
}

return new AnimationClip(null, duration, [track])
}
static CreatePulsationAnimation(duration, pulseScale) {
const times = [],
values = [],
tmp = new Vector3()

AnimationClipCreator.CreatePulsationAnimation = (duration, pulseScale) => {
const times = [],
values = [],
tmp = new Vector3()
for (let i = 0; i < duration * 10; i++) {
times.push(i / 10)

for (let i = 0; i < duration * 10; i++) {
times.push(i / 10)
const scaleFactor = Math.random() * pulseScale
tmp.set(scaleFactor, scaleFactor, scaleFactor).toArray(values, values.length)
}

const scaleFactor = Math.random() * pulseScale
tmp.set(scaleFactor, scaleFactor, scaleFactor).toArray(values, values.length)
}
const trackName = '.scale'

const trackName = '.scale'
const track = new VectorKeyframeTrack(trackName, times, values)

const track = new VectorKeyframeTrack(trackName, times, values)
return new AnimationClip(null, duration, [track])
}

return new AnimationClip(null, duration, [track])
}
static CreateVisibilityAnimation(duration) {
const times = [0, duration / 2, duration],
values = [true, false, true]

AnimationClipCreator.CreateVisibilityAnimation = (duration) => {
const times = [0, duration / 2, duration],
values = [true, false, true]
const trackName = '.visible'

const trackName = '.visible'
const track = new BooleanKeyframeTrack(trackName, times, values)

const track = new BooleanKeyframeTrack(trackName, times, values)
return new AnimationClip(null, duration, [track])
}

return new AnimationClip(null, duration, [track])
}
static CreateMaterialColorAnimation(duration, colors) {
const times = [],
values = [],
timeStep = duration / colors.length

AnimationClipCreator.CreateMaterialColorAnimation = (duration, colors) => {
const times = [],
values = [],
timeStep = duration / colors.length
for (let i = 0; i < colors.length; i++) {
times.push(i * timeStep)

for (let i = 0; i <= colors.length; i++) {
times.push(i * timeStep)
values.push(colors[i % colors.length])
}
const color = colors[i]
values.push(color.r, color.g, color.b)
}

const trackName = '.material[0].color'
const trackName = '.material.color'

const track = new ColorKeyframeTrack(trackName, times, values)
const track = new ColorKeyframeTrack(trackName, times, values)

return new AnimationClip(null, duration, [track])
return new AnimationClip(null, duration, [track])
}
}

export { AnimationClipCreator }
13 changes: 9 additions & 4 deletions src/animation/CCDIKSolver.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { Object3D, SkinnedMesh } from 'three'
import { Object3D, SkinnedMesh, Vector3 } from 'three'

// tslint:disable-next-line:interface-name
export interface IKS {
effector: number
iteration: number
links: {
links: Array<{
enabled: boolean
index: number
}
limitation?: Vector3
rotationMin?: Vector3
rotationMax?: Vector3
}>
minAngle: number
maxAngle: number
target: number
}
Expand All @@ -21,5 +25,6 @@ export class CCDIKSolver {
}

export class CCDIKHelper extends Object3D {
constructor(mesh: SkinnedMesh, iks: IKS[])
constructor(mesh: SkinnedMesh, iks?: IKS[], sphereSize?: number)
dispose(): void
}
Loading