lecodes-sdk 1.0.0 → 1.1.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.
- package/dist/global.d.ts +18 -4
- package/dist/types/animate/tween/Animation.d.ts +69 -0
- package/dist/types/animate/tween/Timeline.d.ts +55 -0
- package/dist/types/animate/tween/animateValue.d.ts +27 -0
- package/dist/types/animate/tween/easing.d.ts +29 -0
- package/dist/types/animate/tween/spec.d.ts +178 -0
- package/dist/types/g2/Node2D.d.ts +16 -0
- package/dist/types/g2/Sprite.d.ts +11 -1
- package/dist/types/gl/Camera.d.ts +15 -1
- package/dist/types/gl/Foliage.d.ts +47 -0
- package/dist/types/gl/Geometry.d.ts +24 -0
- package/dist/types/gl/Light.d.ts +25 -7
- package/dist/types/gl/Lightmap.d.ts +90 -60
- package/dist/types/gl/Material.d.ts +28 -20
- package/dist/types/gl/Model.d.ts +7 -5
- package/dist/types/gl/Node.d.ts +18 -0
- package/dist/types/gl/Particles.d.ts +40 -1
- package/dist/types/gl/Scene.d.ts +20 -0
- package/dist/types/gl/animation/AnimationClip.d.ts +19 -0
- package/dist/types/gl/animation/Animator.d.ts +27 -0
- package/dist/types/gl/animation/DynamicBone.d.ts +19 -8
- package/dist/types/gl/animation/IK.d.ts +86 -30
- package/dist/types/gl/animation/Warp.d.ts +2 -1
- package/dist/types/gl/animation/core.d.ts +35 -4
- package/dist/types/gl/physics/Ragdoll.d.ts +87 -12
- package/dist/types/gl/terrain/Terrain.d.ts +4 -2
- package/dist/types/inject.d.ts +8 -2
- package/dist/types/scene/defineScene.d.ts +44 -32
- package/dist/types/ui/UIButton.d.ts +3 -1
- package/dist/types/ui/UIInput.d.ts +5 -1
- package/dist/types/ui/UINode.d.ts +24 -24
- package/dist/types.json +1 -1
- package/package.json +1 -1
- package/prompts/core-design.md +27 -4
- package/prompts/core.md +35 -6
- package/prompts/select.ts +19 -4
- package/src/animate/tween/Animation.ts +378 -0
- package/src/animate/tween/Timeline.ts +175 -0
- package/src/animate/tween/animateValue.ts +100 -0
- package/src/animate/tween/easing.ts +172 -0
- package/src/animate/tween/spec.ts +479 -0
- package/src/bridges.d.ts +226 -65
- package/src/compile/__tests__/assetMacro.test.ts +26 -0
- package/src/compile/__tests__/detectEntry.test.ts +19 -0
- package/src/compile/__tests__/serverSplit.test.ts +27 -0
- package/src/compile/bundler.ts +34 -4
- package/src/compile/compileProject.ts +31 -1
- package/src/compile/detectEntry.ts +8 -3
- package/src/compile/index.ts +2 -0
- package/src/compile/serverSplit.ts +9 -3
- package/src/g2/Node2D.ts +38 -0
- package/src/g2/Sprite.ts +20 -1
- package/src/gl/Camera.ts +34 -1
- package/src/gl/Foliage.ts +102 -0
- package/src/gl/Geometry.ts +393 -348
- package/src/gl/Light.ts +46 -16
- package/src/gl/Lightmap.ts +439 -275
- package/src/gl/Material.ts +59 -47
- package/src/gl/Model.ts +167 -156
- package/src/gl/Node.ts +39 -0
- package/src/gl/Particles.ts +61 -2
- package/src/gl/Scene.ts +34 -1
- package/src/gl/animation/AnimationClip.ts +52 -0
- package/src/gl/animation/Animator.ts +42 -2
- package/src/gl/animation/DynamicBone.ts +482 -459
- package/src/gl/animation/IK.ts +173 -152
- package/src/gl/animation/Playback.ts +5 -4
- package/src/gl/animation/Warp.ts +5 -2
- package/src/gl/animation/core.ts +65 -4
- package/src/gl/physics/Ragdoll.ts +451 -272
- package/src/gl/terrain/Terrain.ts +4 -2
- package/src/inject.ts +12 -2
- package/src/scene/defineScene.ts +72 -62
- package/src/ui/UIButton.ts +2 -2
- package/src/ui/UIInput.ts +3 -3
- package/src/ui/UINode.ts +61 -36
- package/dist/types/animate/animate.d.ts +0 -20
- package/src/animate/animate.ts +0 -238
package/src/animate/animate.ts
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
// animate self-implements its matrix decompose/recompose; these are just the numeric-array shapes.
|
|
2
|
-
type mat4 = Float32Array | number[]
|
|
3
|
-
type quat = Float32Array | number[]
|
|
4
|
-
type vec2 = Float32Array | number[]
|
|
5
|
-
type vec3 = Float32Array | number[]
|
|
6
|
-
import type { Easing } from "./easings"
|
|
7
|
-
|
|
8
|
-
type AnimateProps = number | string | vec2 | vec3 | quat
|
|
9
|
-
|
|
10
|
-
export type AnimateOptions<T> = {
|
|
11
|
-
from: T,
|
|
12
|
-
to: T,
|
|
13
|
-
duration: number,
|
|
14
|
-
onUpdate(val: T): void,
|
|
15
|
-
onComplete?(): void,
|
|
16
|
-
easing?: Easing,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const animate = <T extends AnimateProps>(options: AnimateOptions<T>): number => {
|
|
20
|
-
|
|
21
|
-
let onRawUpdate
|
|
22
|
-
if (typeof options.to === "number") {
|
|
23
|
-
const { onUpdate, from, to } = options as AnimateOptions<number>
|
|
24
|
-
onRawUpdate = (t: number) => onUpdate(from + (to - from) * t)
|
|
25
|
-
} else if (options.to === "string") {
|
|
26
|
-
// TODO: Make color animate here
|
|
27
|
-
const { onUpdate, from, to } = options as AnimateOptions<string>
|
|
28
|
-
onRawUpdate = (t: number) => onUpdate(from)
|
|
29
|
-
|
|
30
|
-
// onRawUpdate = (val: number) => onUpdate(from + (to - from) * val)
|
|
31
|
-
} else if (options.to.length === 2) {
|
|
32
|
-
const { onUpdate, from, to } = options as AnimateOptions<vec2>
|
|
33
|
-
const tempVec = new Float32Array(3)
|
|
34
|
-
onRawUpdate = (t: number) => onUpdate(lerp2(tempVec, from, to, t))
|
|
35
|
-
|
|
36
|
-
} else if (options.to.length === 3) {
|
|
37
|
-
const { onUpdate, from, to } = options as AnimateOptions<vec3>
|
|
38
|
-
const tempVec = new Float32Array(3)
|
|
39
|
-
|
|
40
|
-
onRawUpdate = (t: number) => onUpdate(lerp(tempVec, from, to, t))
|
|
41
|
-
} else if (options.to.length === 4) {
|
|
42
|
-
const { onUpdate, from, to } = options as AnimateOptions<quat>
|
|
43
|
-
|
|
44
|
-
const tempQuat = new Float32Array(4)
|
|
45
|
-
onRawUpdate = (t: number) => onUpdate(slerp(tempQuat, from, to, t))
|
|
46
|
-
} else {
|
|
47
|
-
onRawUpdate = () => {}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const animationId = _creatorUtils.animate(val => {
|
|
51
|
-
const _val = options.easing? options.easing(val): val
|
|
52
|
-
onRawUpdate(_val)
|
|
53
|
-
if (val === 1 && options.onComplete) {
|
|
54
|
-
options.onComplete()
|
|
55
|
-
}
|
|
56
|
-
}, options.duration)
|
|
57
|
-
|
|
58
|
-
return animationId
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const stopAnimation = (id: number): void => _creatorUtils.stopAnimation(id)
|
|
62
|
-
export const pauseAnimation = (id: number): void => _creatorUtils.pauseAnimation(id)
|
|
63
|
-
export const resumeAnimation = (id: number): void => _creatorUtils.resumeAnimation(id)
|
|
64
|
-
|
|
65
|
-
export const animateMat4 = (options: AnimateOptions<mat4>): number => {
|
|
66
|
-
const fromPosition = new Float32Array(3)
|
|
67
|
-
const fromQuaternion = new Float32Array(4)
|
|
68
|
-
const fromScale = new Float32Array(3)
|
|
69
|
-
const toPosition = new Float32Array(3)
|
|
70
|
-
const toQuaternion = new Float32Array(4)
|
|
71
|
-
const toScale = new Float32Array(3)
|
|
72
|
-
decompose(fromQuaternion, fromPosition, fromScale, (options as AnimateOptions<mat4>).from)
|
|
73
|
-
decompose(toQuaternion, toPosition, toScale, (options as AnimateOptions<mat4>).to)
|
|
74
|
-
|
|
75
|
-
const tempPosition = new Float32Array(3)
|
|
76
|
-
const tempQuat = new Float32Array(4)
|
|
77
|
-
const tempScale = new Float32Array(3)
|
|
78
|
-
const tempMat = new Float32Array(16)
|
|
79
|
-
|
|
80
|
-
const onUpdate = (options as AnimateOptions<mat4>).onUpdate
|
|
81
|
-
const onRawUpdate = (t: number) => {
|
|
82
|
-
lerp(tempPosition, fromPosition, toPosition, t)
|
|
83
|
-
slerp(tempQuat, fromQuaternion, toQuaternion, t)
|
|
84
|
-
lerp(tempScale, fromScale, toScale, t)
|
|
85
|
-
|
|
86
|
-
onUpdate(fromRotationTranslationScale(tempMat, tempQuat, tempPosition, tempScale))
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const animationId = _creatorUtils.animate(val => {
|
|
90
|
-
const _val = options.easing? options.easing(val): val
|
|
91
|
-
onRawUpdate(_val)
|
|
92
|
-
if (val === 1 && options.onComplete) {
|
|
93
|
-
options.onComplete()
|
|
94
|
-
}
|
|
95
|
-
}, options.duration)
|
|
96
|
-
|
|
97
|
-
return animationId
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const EPSILON = 1e-6;
|
|
101
|
-
function slerp(out: quat, a: quat, b: quat, t: number) {
|
|
102
|
-
const ax = a[0], ay = a[1], az = a[2], aw = a[3];
|
|
103
|
-
let bx = b[0], by = b[1], bz = b[2], bw = b[3];
|
|
104
|
-
let omega, cosom, sinom, scale0, scale1;
|
|
105
|
-
cosom = ax * bx + ay * by + az * bz + aw * bw;
|
|
106
|
-
if (cosom < 0) {
|
|
107
|
-
cosom = -cosom;
|
|
108
|
-
bx = -bx;
|
|
109
|
-
by = -by;
|
|
110
|
-
bz = -bz;
|
|
111
|
-
bw = -bw;
|
|
112
|
-
}
|
|
113
|
-
if (1 - cosom > EPSILON) {
|
|
114
|
-
omega = Math.acos(cosom);
|
|
115
|
-
sinom = Math.sin(omega);
|
|
116
|
-
scale0 = Math.sin((1 - t) * omega) / sinom;
|
|
117
|
-
scale1 = Math.sin(t * omega) / sinom;
|
|
118
|
-
} else {
|
|
119
|
-
scale0 = 1 - t;
|
|
120
|
-
scale1 = t;
|
|
121
|
-
}
|
|
122
|
-
out[0] = scale0 * ax + scale1 * bx;
|
|
123
|
-
out[1] = scale0 * ay + scale1 * by;
|
|
124
|
-
out[2] = scale0 * az + scale1 * bz;
|
|
125
|
-
out[3] = scale0 * aw + scale1 * bw;
|
|
126
|
-
return out;
|
|
127
|
-
}
|
|
128
|
-
function lerp(out: vec3, a: vec3, b: vec3, t: number) {
|
|
129
|
-
const ax = a[0];
|
|
130
|
-
const ay = a[1];
|
|
131
|
-
const az = a[2];
|
|
132
|
-
out[0] = ax + t * (b[0] - ax);
|
|
133
|
-
out[1] = ay + t * (b[1] - ay);
|
|
134
|
-
out[2] = az + t * (b[2] - az);
|
|
135
|
-
return out;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function lerp2(out: vec2, a: vec2, b: vec2, t: number) {
|
|
139
|
-
const ax = a[0];
|
|
140
|
-
const ay = a[1];
|
|
141
|
-
const az = a[2];
|
|
142
|
-
out[0] = ax + t * (b[0] - ax);
|
|
143
|
-
out[1] = ay + t * (b[1] - ay);
|
|
144
|
-
return out;
|
|
145
|
-
}
|
|
146
|
-
function fromRotationTranslationScale(out: mat4, q: quat, v: vec3, s: vec3) {
|
|
147
|
-
const x = q[0], y = q[1], z = q[2], w = q[3];
|
|
148
|
-
const x2 = x + x;
|
|
149
|
-
const y2 = y + y;
|
|
150
|
-
const z2 = z + z;
|
|
151
|
-
const xx = x * x2;
|
|
152
|
-
const xy = x * y2;
|
|
153
|
-
const xz = x * z2;
|
|
154
|
-
const yy = y * y2;
|
|
155
|
-
const yz = y * z2;
|
|
156
|
-
const zz = z * z2;
|
|
157
|
-
const wx = w * x2;
|
|
158
|
-
const wy = w * y2;
|
|
159
|
-
const wz = w * z2;
|
|
160
|
-
const sx = s[0];
|
|
161
|
-
const sy = s[1];
|
|
162
|
-
const sz = s[2];
|
|
163
|
-
out[0] = (1 - (yy + zz)) * sx;
|
|
164
|
-
out[1] = (xy + wz) * sx;
|
|
165
|
-
out[2] = (xz - wy) * sx;
|
|
166
|
-
out[3] = 0;
|
|
167
|
-
out[4] = (xy - wz) * sy;
|
|
168
|
-
out[5] = (1 - (xx + zz)) * sy;
|
|
169
|
-
out[6] = (yz + wx) * sy;
|
|
170
|
-
out[7] = 0;
|
|
171
|
-
out[8] = (xz + wy) * sz;
|
|
172
|
-
out[9] = (yz - wx) * sz;
|
|
173
|
-
out[10] = (1 - (xx + yy)) * sz;
|
|
174
|
-
out[11] = 0;
|
|
175
|
-
out[12] = v[0];
|
|
176
|
-
out[13] = v[1];
|
|
177
|
-
out[14] = v[2];
|
|
178
|
-
out[15] = 1;
|
|
179
|
-
return out;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function decompose(out_r: mat4, out_t: vec3, out_s: vec3, mat: mat4) {
|
|
183
|
-
out_t[0] = mat[12];
|
|
184
|
-
out_t[1] = mat[13];
|
|
185
|
-
out_t[2] = mat[14];
|
|
186
|
-
const m11 = mat[0];
|
|
187
|
-
const m12 = mat[1];
|
|
188
|
-
const m13 = mat[2];
|
|
189
|
-
const m21 = mat[4];
|
|
190
|
-
const m22 = mat[5];
|
|
191
|
-
const m23 = mat[6];
|
|
192
|
-
const m31 = mat[8];
|
|
193
|
-
const m32 = mat[9];
|
|
194
|
-
const m33 = mat[10];
|
|
195
|
-
out_s[0] = Math.hypot(m11, m12, m13);
|
|
196
|
-
out_s[1] = Math.hypot(m21, m22, m23);
|
|
197
|
-
out_s[2] = Math.hypot(m31, m32, m33);
|
|
198
|
-
const is1 = 1 / out_s[0];
|
|
199
|
-
const is2 = 1 / out_s[1];
|
|
200
|
-
const is3 = 1 / out_s[2];
|
|
201
|
-
const sm11 = m11 * is1;
|
|
202
|
-
const sm12 = m12 * is2;
|
|
203
|
-
const sm13 = m13 * is3;
|
|
204
|
-
const sm21 = m21 * is1;
|
|
205
|
-
const sm22 = m22 * is2;
|
|
206
|
-
const sm23 = m23 * is3;
|
|
207
|
-
const sm31 = m31 * is1;
|
|
208
|
-
const sm32 = m32 * is2;
|
|
209
|
-
const sm33 = m33 * is3;
|
|
210
|
-
const trace = sm11 + sm22 + sm33;
|
|
211
|
-
let S = 0;
|
|
212
|
-
if (trace > 0) {
|
|
213
|
-
S = Math.sqrt(trace + 1) * 2;
|
|
214
|
-
out_r[3] = 0.25 * S;
|
|
215
|
-
out_r[0] = (sm23 - sm32) / S;
|
|
216
|
-
out_r[1] = (sm31 - sm13) / S;
|
|
217
|
-
out_r[2] = (sm12 - sm21) / S;
|
|
218
|
-
} else if (sm11 > sm22 && sm11 > sm33) {
|
|
219
|
-
S = Math.sqrt(1 + sm11 - sm22 - sm33) * 2;
|
|
220
|
-
out_r[3] = (sm23 - sm32) / S;
|
|
221
|
-
out_r[0] = 0.25 * S;
|
|
222
|
-
out_r[1] = (sm12 + sm21) / S;
|
|
223
|
-
out_r[2] = (sm31 + sm13) / S;
|
|
224
|
-
} else if (sm22 > sm33) {
|
|
225
|
-
S = Math.sqrt(1 + sm22 - sm11 - sm33) * 2;
|
|
226
|
-
out_r[3] = (sm31 - sm13) / S;
|
|
227
|
-
out_r[0] = (sm12 + sm21) / S;
|
|
228
|
-
out_r[1] = 0.25 * S;
|
|
229
|
-
out_r[2] = (sm23 + sm32) / S;
|
|
230
|
-
} else {
|
|
231
|
-
S = Math.sqrt(1 + sm33 - sm11 - sm22) * 2;
|
|
232
|
-
out_r[3] = (sm12 - sm21) / S;
|
|
233
|
-
out_r[0] = (sm31 + sm13) / S;
|
|
234
|
-
out_r[1] = (sm23 + sm32) / S;
|
|
235
|
-
out_r[2] = 0.25 * S;
|
|
236
|
-
}
|
|
237
|
-
return out_r;
|
|
238
|
-
}
|