@algorisys/tinyfly 0.82.0 → 0.86.2
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/README.md +11 -4
- package/lib/addons/adapters.js +363 -248
- package/lib/addons/characters.js +1652 -1470
- package/lib/addons/dom-adapter-Cphr2HZn.js +372 -0
- package/lib/addons/gsap-compat.js +197 -187
- package/lib/addons/load-scene-vp14_Jj-.js +324 -0
- package/lib/addons/scene-3d-webgl.js +237 -0
- package/lib/addons/scene-3d.js +306 -0
- package/lib/addons/shading-ByG9UXd0.js +85 -0
- package/lib/browser/tinyfly-scene-3d-webgl.iife.js +114 -0
- package/lib/browser/tinyfly-scene-3d.iife.js +3 -0
- package/lib/browser/tinyfly.iife.js +4 -4
- package/lib/browser/tinyfly.js +3028 -2480
- package/lib/browser/tinyfly.umd.js +4 -4
- package/lib/cli/tools.js +137 -22
- package/lib/embed/tinyfly-embed.iife.js +4 -4
- package/lib/embed/tinyfly-embed.js +921 -833
- package/lib/engine/tinyfly-engine.js +1022 -776
- package/lib/engine/tinyfly-engine.umd.cjs +2 -2
- package/lib/headless/headless.js +264 -7
- package/lib/player/tinyfly-player.es.js +459 -371
- package/lib/player/tinyfly-player.iife.js +2 -2
- package/lib/player/tinyfly-player.umd.js +2 -2
- package/lib/types/adapters/canvas/canvas-adapter.d.ts +36 -0
- package/lib/types/adapters/transform-3d.d.ts +99 -0
- package/lib/types/adapters/webgl/webgl-adapter.d.ts +17 -0
- package/lib/types/characters/character.d.ts +20 -1
- package/lib/types/characters/index.d.ts +2 -0
- package/lib/types/characters/rig/body-plan.d.ts +3 -1
- package/lib/types/characters/rig/skeleton.d.ts +57 -0
- package/lib/types/characters/scene-objects.d.ts +2 -0
- package/lib/types/compat/gsap/vars.d.ts +8 -0
- package/lib/types/engine/core/bake.d.ts +3 -1
- package/lib/types/engine/index.d.ts +1 -0
- package/lib/types/engine/interpolation/interpolators.d.ts +10 -3
- package/lib/types/engine/math/index.d.ts +11 -0
- package/lib/types/engine/math/mat4.d.ts +37 -0
- package/lib/types/engine/math/quat.d.ts +39 -0
- package/lib/types/engine/math/vec3.d.ts +16 -0
- package/lib/types/engine/types.d.ts +23 -2
- package/lib/types/scene-3d/camera.d.ts +27 -0
- package/lib/types/scene-3d/canvas-2d-renderer.d.ts +21 -0
- package/lib/types/scene-3d/geometry/extrude.d.ts +17 -0
- package/lib/types/scene-3d/geometry/mesh.d.ts +36 -0
- package/lib/types/scene-3d/geometry/primitives.d.ts +16 -0
- package/lib/types/scene-3d/geometry/triangulate.d.ts +24 -0
- package/lib/types/scene-3d/index.d.ts +20 -0
- package/lib/types/scene-3d/load-scene.d.ts +31 -0
- package/lib/types/scene-3d/object-kind.d.ts +54 -0
- package/lib/types/scene-3d/resolve-scene.d.ts +122 -0
- package/lib/types/scene-3d/scene-3d-adapter.d.ts +46 -0
- package/lib/types/scene-3d/scene-types.d.ts +191 -0
- package/lib/types/scene-3d/shading.d.ts +20 -0
- package/lib/types/scene-3d/validate-scene.d.ts +11 -0
- package/lib/types/scene-3d/webgl/gl-data.d.ts +28 -0
- package/lib/types/scene-3d/webgl/index.d.ts +16 -0
- package/lib/types/scene-3d/webgl/shaders.d.ts +29 -0
- package/lib/types/scene-3d/webgl/webgl2-renderer.d.ts +33 -0
- package/package.json +10 -2
- package/lib/addons/dom-adapter-CrNwoomd.js +0 -243
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A 3D scene as plain JSON: objects in world space (metres, right-handed,
|
|
3
|
+
* +y up, +z toward the default camera), a camera to look through, lights and
|
|
4
|
+
* materials. Its animation is ordinary tracks addressed to
|
|
5
|
+
* `<sceneId>/<objectId>` (see `resolve-scene.ts`), so it plays on any
|
|
6
|
+
* timeline and in any renderer.
|
|
7
|
+
*
|
|
8
|
+
* Angles are degrees; Euler rotations apply in YXZ order (yaw, pitch, roll),
|
|
9
|
+
* as `quat.fromEuler`; quaternions are `[x, y, z, w]`.
|
|
10
|
+
*/
|
|
11
|
+
export type Vec3Tuple = [number, number, number];
|
|
12
|
+
export type QuatTuple = [number, number, number, number];
|
|
13
|
+
export interface Scene3D {
|
|
14
|
+
/** The format of this scene (1) */
|
|
15
|
+
formatVersion?: number;
|
|
16
|
+
id: string;
|
|
17
|
+
/** The camera at time 0; a film cuts between cameras with an `activeCamera` track on the scene */
|
|
18
|
+
camera: string;
|
|
19
|
+
/** In order: parents before children; array order breaks depth ties */
|
|
20
|
+
objects: Object3D[];
|
|
21
|
+
materials?: Record<string, Material3D>;
|
|
22
|
+
/** Background colour, or 'transparent' (default) */
|
|
23
|
+
background?: string;
|
|
24
|
+
/** Fog from `near` to `far` metres from the camera, toward `color` */
|
|
25
|
+
fog?: {
|
|
26
|
+
color: string;
|
|
27
|
+
near: number;
|
|
28
|
+
far: number;
|
|
29
|
+
};
|
|
30
|
+
/** Realistic mode: an equirectangular HDR asset for light and reflections (stylized ignores it) */
|
|
31
|
+
environment?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface Transform3D {
|
|
34
|
+
/** Metres; default [0, 0, 0] */
|
|
35
|
+
position?: Vec3Tuple;
|
|
36
|
+
/** Euler degrees, YXZ order (use `quaternion` instead for tumbling) */
|
|
37
|
+
rotation?: Vec3Tuple;
|
|
38
|
+
quaternion?: QuatTuple;
|
|
39
|
+
/** One number for all three axes, or per axis; default 1 */
|
|
40
|
+
scale?: Vec3Tuple | number;
|
|
41
|
+
}
|
|
42
|
+
export interface ObjectBase extends Transform3D {
|
|
43
|
+
/** Unique in the scene; tracks address it as `<sceneId>/<id>` */
|
|
44
|
+
id: string;
|
|
45
|
+
name?: string;
|
|
46
|
+
/** Id of an earlier object this one moves with */
|
|
47
|
+
parent?: string;
|
|
48
|
+
/** Default true */
|
|
49
|
+
visible?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Draw-order group (default 0): lower layers draw first, whatever their
|
|
52
|
+
* depth, then far to near within a layer. A floor at -1 never covers what
|
|
53
|
+
* stands on it.
|
|
54
|
+
*/
|
|
55
|
+
layer?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface GroupObject extends ObjectBase {
|
|
58
|
+
kind: 'group';
|
|
59
|
+
}
|
|
60
|
+
export interface MeshObject extends ObjectBase {
|
|
61
|
+
kind: 'mesh';
|
|
62
|
+
geometry: Geometry3D;
|
|
63
|
+
/** A key of `materials` */
|
|
64
|
+
material: string;
|
|
65
|
+
}
|
|
66
|
+
export interface PerspectiveCamera extends ObjectBase {
|
|
67
|
+
kind: 'camera';
|
|
68
|
+
projection: 'perspective';
|
|
69
|
+
/** Vertical field of view, degrees */
|
|
70
|
+
fov: number;
|
|
71
|
+
/** Nearest and furthest distances drawn, metres */
|
|
72
|
+
near: number;
|
|
73
|
+
far: number;
|
|
74
|
+
/** A point to look at, overriding the camera's rotation */
|
|
75
|
+
lookAt?: Vec3Tuple;
|
|
76
|
+
}
|
|
77
|
+
export interface OrthographicCamera extends ObjectBase {
|
|
78
|
+
kind: 'camera';
|
|
79
|
+
projection: 'orthographic';
|
|
80
|
+
/** Height of the view, metres */
|
|
81
|
+
height: number;
|
|
82
|
+
near: number;
|
|
83
|
+
far: number;
|
|
84
|
+
lookAt?: Vec3Tuple;
|
|
85
|
+
}
|
|
86
|
+
export type CameraObject = PerspectiveCamera | OrthographicCamera;
|
|
87
|
+
export interface LightObject extends ObjectBase {
|
|
88
|
+
kind: 'light';
|
|
89
|
+
light: 'ambient' | 'directional' | 'point' | 'spot';
|
|
90
|
+
color: string;
|
|
91
|
+
/**
|
|
92
|
+
* Strength. Stylized renderers read it as a multiplier (1 is full light);
|
|
93
|
+
* the realistic renderer maps it to physical units.
|
|
94
|
+
*/
|
|
95
|
+
intensity: number;
|
|
96
|
+
/** Directional and spot: they shine from their position toward this point (default the origin) */
|
|
97
|
+
target?: Vec3Tuple;
|
|
98
|
+
/** Point and spot: the light fades to nothing at this distance, metres (default: no fade) */
|
|
99
|
+
range?: number;
|
|
100
|
+
/** Spot: the cone's half-angle, degrees (default 30) */
|
|
101
|
+
angle?: number;
|
|
102
|
+
/** Realistic mode: casts shadow maps */
|
|
103
|
+
castShadow?: boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A character (tinyfly's v2 human) standing in the scene. Drawing it needs the
|
|
107
|
+
* characters add-on: `loadScene3D(scene, { kinds: [characterObjects] })` with
|
|
108
|
+
* `characterObjects` from `@algorisys/tinyfly/characters`.
|
|
109
|
+
*/
|
|
110
|
+
export interface CharacterObject3D extends ObjectBase {
|
|
111
|
+
kind: 'character';
|
|
112
|
+
/** How it looks: `character()` options (figure, look, ink, skin, hands, …) */
|
|
113
|
+
character?: Record<string, unknown>;
|
|
114
|
+
/** Height, metres (default 1.7) */
|
|
115
|
+
height?: number;
|
|
116
|
+
/** Its pose: character pose fields (`arm.right.spread`, `turn`, …); tracks animate them */
|
|
117
|
+
pose?: Record<string, number>;
|
|
118
|
+
/** A soft shadow on the ground under it (default true) */
|
|
119
|
+
shadow?: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* `pen` (default): drawn by its pens, in its 2D look (clean, pencil,
|
|
122
|
+
* silhouette) seen in perspective. `solid`: built of shaded capsules and an
|
|
123
|
+
* ellipsoid head, lit and outlined like the scene's meshes.
|
|
124
|
+
*/
|
|
125
|
+
look?: 'pen' | 'solid';
|
|
126
|
+
/** The solid look's colours and shading (default: a slate body, skin, toon with ink) */
|
|
127
|
+
solid?: {
|
|
128
|
+
color?: string;
|
|
129
|
+
skin?: string;
|
|
130
|
+
shading?: 'unlit' | 'flat' | 'lambert' | 'toon';
|
|
131
|
+
outline?: {
|
|
132
|
+
width: number;
|
|
133
|
+
color: string;
|
|
134
|
+
} | false;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export type Object3D = GroupObject | MeshObject | CameraObject | LightObject | CharacterObject3D;
|
|
138
|
+
export type Geometry3D = {
|
|
139
|
+
type: 'box';
|
|
140
|
+
size: Vec3Tuple;
|
|
141
|
+
} | {
|
|
142
|
+
type: 'sphere';
|
|
143
|
+
radius: number;
|
|
144
|
+
segments?: number;
|
|
145
|
+
} | {
|
|
146
|
+
type: 'cylinder';
|
|
147
|
+
radius: number;
|
|
148
|
+
height: number;
|
|
149
|
+
segments?: number;
|
|
150
|
+
} | {
|
|
151
|
+
type: 'cone';
|
|
152
|
+
radius: number;
|
|
153
|
+
height: number;
|
|
154
|
+
segments?: number;
|
|
155
|
+
} | {
|
|
156
|
+
type: 'plane';
|
|
157
|
+
size: [number, number];
|
|
158
|
+
segments?: number;
|
|
159
|
+
} | {
|
|
160
|
+
type: 'torus';
|
|
161
|
+
radius: number;
|
|
162
|
+
tube: number;
|
|
163
|
+
segments?: number;
|
|
164
|
+
}
|
|
165
|
+
/** An SVG path made solid, `depth` thick, scaled to `width` metres wide (default 1); subpaths inside others are holes */
|
|
166
|
+
| {
|
|
167
|
+
type: 'extrude';
|
|
168
|
+
path: string;
|
|
169
|
+
depth: number;
|
|
170
|
+
width?: number;
|
|
171
|
+
curveSegments?: number;
|
|
172
|
+
};
|
|
173
|
+
export interface Material3D {
|
|
174
|
+
color: string;
|
|
175
|
+
/** 0..1, default 1 */
|
|
176
|
+
opacity?: number;
|
|
177
|
+
/** Draw both sides (default: only the front, the side the outward normal faces) */
|
|
178
|
+
doubleSided?: boolean;
|
|
179
|
+
/** unlit: the colour as is; flat: lit per face; lambert: lit, smoothed; toon: lit in bands */
|
|
180
|
+
shading?: 'unlit' | 'flat' | 'lambert' | 'toon';
|
|
181
|
+
/** Toon: number of light bands (default 3) */
|
|
182
|
+
bands?: number;
|
|
183
|
+
/** Ink outline along silhouettes and creases, px */
|
|
184
|
+
outline?: {
|
|
185
|
+
width: number;
|
|
186
|
+
color: string;
|
|
187
|
+
};
|
|
188
|
+
roughness?: number;
|
|
189
|
+
metalness?: number;
|
|
190
|
+
emissive?: string;
|
|
191
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Vec3 } from '../engine/math';
|
|
2
|
+
import type { DrawTriangle, ResolvedCamera, ResolvedLight, ResolvedScene3D } from './resolve-scene';
|
|
3
|
+
/**
|
|
4
|
+
* Stylized shading, pure: the colour of one triangle under the scene's
|
|
5
|
+
* lights, as flat, smooth (lambert) or banded (toon) light, then fog. Light
|
|
6
|
+
* intensity is a multiplier here (1 is full light); a point or spot light
|
|
7
|
+
* fades to nothing at its `range`.
|
|
8
|
+
*/
|
|
9
|
+
export type Rgb = [number, number, number];
|
|
10
|
+
/** `#rgb`, `#rrggbb`, `rgb()` / `rgba()` as 0..1 channels; anything else is white. */
|
|
11
|
+
export declare function parseColor(color: string): Rgb;
|
|
12
|
+
/** The light reaching point `p` with normal `n`, as RGB (can exceed 1). */
|
|
13
|
+
export declare function lightAt(p: Vec3, n: Vec3, lights: ResolvedLight[]): Rgb;
|
|
14
|
+
/** How much fog covers a point `distance` metres from the camera, 0..1. */
|
|
15
|
+
export declare function fogAmount(fog: ResolvedScene3D['fog'], distance: number): number;
|
|
16
|
+
/** The fill of one triangle: a CSS colour and its opacity. */
|
|
17
|
+
export declare function shadeTriangle(triangle: DrawTriangle, lights: ResolvedLight[], camera: ResolvedCamera, fog?: ResolvedScene3D['fog']): {
|
|
18
|
+
color: string;
|
|
19
|
+
alpha: number;
|
|
20
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Scene3D } from './scene-types';
|
|
2
|
+
/**
|
|
3
|
+
* Problems with a scene, as plain sentences (empty when it is fine): ids,
|
|
4
|
+
* parents, the camera, materials, sizes. With `tracks`, also a channel
|
|
5
|
+
* animated two ways at once (x and position, rotateY and quaternion), which
|
|
6
|
+
* would otherwise need a hidden rule to pick a winner.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateScene3D(scene: Scene3D, tracks?: ReadonlyArray<{
|
|
9
|
+
target: string;
|
|
10
|
+
property: string;
|
|
11
|
+
}>): string[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ResolvedLight } from '../resolve-scene';
|
|
2
|
+
import type { Material3D } from '../scene-types';
|
|
3
|
+
/**
|
|
4
|
+
* Pure packing for the WebGL2 renderer: lights into uniform arrays, materials
|
|
5
|
+
* into shader numbers, normal matrices. No GL here, so it is tested in Node.
|
|
6
|
+
*/
|
|
7
|
+
export interface LightUniforms {
|
|
8
|
+
count: number;
|
|
9
|
+
kind: Int32Array;
|
|
10
|
+
color: Float32Array;
|
|
11
|
+
intensity: Float32Array;
|
|
12
|
+
position: Float32Array;
|
|
13
|
+
direction: Float32Array;
|
|
14
|
+
range: Float32Array;
|
|
15
|
+
/** Spot cone: cos(outer angle), cos(inner angle) */
|
|
16
|
+
cone: Float32Array;
|
|
17
|
+
}
|
|
18
|
+
/** The scene's lights as uniform arrays (the first {@link MAX_LIGHTS}; the default pair when there are none). */
|
|
19
|
+
export declare function packLights(lights: ResolvedLight[]): LightUniforms;
|
|
20
|
+
/** A material's numbers for the surface shader, with an object's own colour and opacity over it. */
|
|
21
|
+
export declare function surfaceUniforms(material: Material3D, color: string | undefined, opacity: number): {
|
|
22
|
+
color: import("../shading").Rgb;
|
|
23
|
+
opacity: number;
|
|
24
|
+
shading: 0 | 2 | 1 | 3;
|
|
25
|
+
bands: number;
|
|
26
|
+
};
|
|
27
|
+
/** The 3×3 normal matrix (inverse transpose of the upper 3×3), column-major, from a column-major 4×4. */
|
|
28
|
+
export declare function normalMatrix3(m: number[]): Float32Array;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@algorisys/tinyfly/scene-3d/webgl`: the WebGL2 renderer for 3D scenes. A
|
|
3
|
+
* depth buffer, light per pixel and inverted-hull outlines, for scenes too
|
|
4
|
+
* big or too tangled for the Canvas 2D renderer. Its own entry, so pages
|
|
5
|
+
* without it never download it.
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* import { loadScene3D, resolveScene3D } from '@algorisys/tinyfly/scene-3d'
|
|
9
|
+
* import { WebGL2Renderer } from '@algorisys/tinyfly/scene-3d/webgl'
|
|
10
|
+
* const renderer = new WebGL2Renderer(canvas.getContext('webgl2'), { overlay })
|
|
11
|
+
* renderer.render(resolveScene3D(scene, values, { width, height }))
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export { WebGL2Renderer } from './webgl2-renderer';
|
|
15
|
+
export { packLights, surfaceUniforms, normalMatrix3, type LightUniforms } from './gl-data';
|
|
16
|
+
export { MAX_LIGHTS, SHADING_CODE, LIGHT_CODE } from './shaders';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The WebGL2 renderer's shaders (GLSL ES 3.0). The light is the stylized
|
|
3
|
+
* light of `shading.ts`, per pixel: ambient, directional, point and spot
|
|
4
|
+
* lights fading at their range, unlit / flat / smooth / toon, then fog.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MAX_LIGHTS = 8;
|
|
7
|
+
/** Shading modes as the fragment shader numbers them. */
|
|
8
|
+
export declare const SHADING_CODE: {
|
|
9
|
+
readonly unlit: 0;
|
|
10
|
+
readonly flat: 1;
|
|
11
|
+
readonly lambert: 2;
|
|
12
|
+
readonly toon: 3;
|
|
13
|
+
};
|
|
14
|
+
/** Light kinds as the fragment shader numbers them. */
|
|
15
|
+
export declare const LIGHT_CODE: {
|
|
16
|
+
readonly ambient: 0;
|
|
17
|
+
readonly directional: 1;
|
|
18
|
+
readonly point: 2;
|
|
19
|
+
readonly spot: 3;
|
|
20
|
+
};
|
|
21
|
+
export declare const SURFACE_VERTEX = "#version 300 es\nin vec3 a_position;\nin vec3 a_normal;\nuniform mat4 u_model;\nuniform mat4 u_view;\nuniform mat4 u_projection;\nuniform mat3 u_normalMatrix;\nout vec3 v_world;\nout vec3 v_normal;\nvoid main() {\n vec4 world = u_model * vec4(a_position, 1.0);\n v_world = world.xyz;\n v_normal = u_normalMatrix * a_normal;\n gl_Position = u_projection * u_view * world;\n}\n";
|
|
22
|
+
export declare const SURFACE_FRAGMENT = "#version 300 es\nprecision highp float;\n#define MAX_LIGHTS 8\nuniform int u_lightCount;\nuniform int u_lightKind[MAX_LIGHTS];\nuniform vec3 u_lightColor[MAX_LIGHTS];\nuniform float u_lightIntensity[MAX_LIGHTS];\nuniform vec3 u_lightPosition[MAX_LIGHTS];\nuniform vec3 u_lightDirection[MAX_LIGHTS];\nuniform float u_lightRange[MAX_LIGHTS];\nuniform vec2 u_lightCone[MAX_LIGHTS];\nuniform vec3 u_color;\nuniform float u_opacity;\nuniform int u_shading;\nuniform float u_bands;\nuniform vec3 u_eye;\nuniform vec3 u_forward;\nuniform bool u_orthographic;\nuniform bool u_fog;\nuniform vec3 u_fogColor;\nuniform vec2 u_fogRange;\nin vec3 v_world;\nin vec3 v_normal;\nout vec4 outColor;\n\nvec3 lightAt(vec3 p, vec3 n) {\n vec3 total = vec3(0.0);\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= u_lightCount) break;\n float amount;\n int kind = u_lightKind[i];\n if (kind == 0) {\n amount = u_lightIntensity[i];\n } else if (kind == 1) {\n amount = u_lightIntensity[i] * max(0.0, -dot(n, u_lightDirection[i]));\n } else {\n vec3 toLight = u_lightPosition[i] - p;\n float distance = length(toLight);\n vec3 l = distance > 0.0 ? toLight / distance : n;\n float fade = u_lightRange[i] > 0.0 ? pow(max(0.0, 1.0 - distance / u_lightRange[i]), 2.0) : 1.0;\n amount = u_lightIntensity[i] * max(0.0, dot(n, l)) * fade;\n if (kind == 3) amount *= smoothstep(u_lightCone[i].x, u_lightCone[i].y, -dot(l, u_lightDirection[i]));\n }\n total += u_lightColor[i] * amount;\n }\n return total;\n}\n\nvoid main() {\n vec3 rgb = u_color;\n if (u_shading != 0) {\n // Flat: the face's own normal, from the surface's slope; otherwise the smooth one.\n vec3 n = u_shading == 1 ? normalize(cross(dFdx(v_world), dFdy(v_world))) : normalize(v_normal);\n vec3 toEye = u_orthographic ? -u_forward : normalize(u_eye - v_world);\n if (dot(n, toEye) < 0.0) n = -n;\n vec3 light = lightAt(v_world, n);\n if (u_shading == 3) {\n // Band the brightness, not each channel, so coloured lights keep their hue.\n float level = max(light.r, max(light.g, light.b));\n float steps = max(2.0, floor(u_bands + 0.5));\n float banded = min(1.2, ceil(min(1.0, level) * steps - 1e-6) / steps);\n light = level > 0.0 ? light * (banded / level) : vec3(0.0);\n }\n rgb *= light;\n }\n if (u_fog) {\n float amount = clamp((distance(v_world, u_eye) - u_fogRange.x) / (u_fogRange.y - u_fogRange.x), 0.0, 1.0);\n rgb = mix(rgb, u_fogColor, amount);\n }\n outColor = vec4(clamp(rgb, 0.0, 1.0), u_opacity);\n}\n";
|
|
23
|
+
/**
|
|
24
|
+
* Ink outlines by the inverted hull: each mesh again, its back faces only,
|
|
25
|
+
* pushed out along their normals by the outline's width in pixels, in the
|
|
26
|
+
* ink colour. Behind the surface, only the rim shows: a silhouette.
|
|
27
|
+
*/
|
|
28
|
+
export declare const OUTLINE_VERTEX = "#version 300 es\nin vec3 a_position;\nin vec3 a_normal;\nuniform mat4 u_model;\nuniform mat4 u_view;\nuniform mat4 u_projection;\nuniform mat3 u_normalMatrix;\nuniform vec2 u_viewport;\nuniform float u_width;\nvoid main() {\n mat4 viewProjection = u_projection * u_view;\n vec4 clip = viewProjection * u_model * vec4(a_position, 1.0);\n vec3 worldNormal = normalize(u_normalMatrix * a_normal);\n vec4 tip = viewProjection * (u_model * vec4(a_position, 1.0) + vec4(worldNormal * 0.01, 0.0));\n vec2 direction = tip.xy / tip.w - clip.xy / clip.w;\n float length2 = dot(direction, direction);\n vec2 push = length2 > 0.0 ? direction * inversesqrt(length2) : vec2(0.0);\n clip.xy += push * u_width * 2.0 / u_viewport * clip.w;\n gl_Position = clip;\n}\n";
|
|
29
|
+
export declare const OUTLINE_FRAGMENT = "#version 300 es\nprecision highp float;\nuniform vec4 u_ink;\nout vec4 outColor;\nvoid main() {\n outColor = u_ink;\n}\n";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ResolvedScene3D } from '../resolve-scene';
|
|
2
|
+
/**
|
|
3
|
+
* Draws a resolved 3D scene with WebGL2: the same frame the Canvas 2D
|
|
4
|
+
* renderer paints, but with a depth buffer (shapes that cut through each
|
|
5
|
+
* other are drawn right), light per pixel (smooth curves, toon bands, fog per
|
|
6
|
+
* pixel) and ink outlines by the inverted hull. Opaque meshes first, then
|
|
7
|
+
* see-through ones far to near.
|
|
8
|
+
*
|
|
9
|
+
* Added objects drawn whole (a character in its pen look, its shadow) are not
|
|
10
|
+
* meshes: they go on `overlay`, a 2D canvas laid over this one, after the
|
|
11
|
+
* meshes (so in front of them). Characters in the solid look are meshes and
|
|
12
|
+
* sort properly.
|
|
13
|
+
*
|
|
14
|
+
* Works on a page canvas or an OffscreenCanvas in a Worker. Not in Node
|
|
15
|
+
* (there is no WebGL2 there): headless video uses the Canvas 2D renderer.
|
|
16
|
+
*/
|
|
17
|
+
export declare class WebGL2Renderer {
|
|
18
|
+
private readonly gl;
|
|
19
|
+
private readonly surface;
|
|
20
|
+
private readonly outline;
|
|
21
|
+
private readonly buffers;
|
|
22
|
+
private readonly overlay?;
|
|
23
|
+
constructor(gl: WebGL2RenderingContext, options?: {
|
|
24
|
+
overlay?: CanvasRenderingContext2D;
|
|
25
|
+
});
|
|
26
|
+
render(frame: ResolvedScene3D): void;
|
|
27
|
+
private drawSurface;
|
|
28
|
+
private drawOutline;
|
|
29
|
+
/** Upload a mesh once; bind its buffers to the program's attributes. */
|
|
30
|
+
private bindMesh;
|
|
31
|
+
/** Release the programs (mesh buffers go with their meshes). */
|
|
32
|
+
destroy(): void;
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algorisys/tinyfly",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.86.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Lightweight, API-driven animation engine and editor. The engine is framework-agnostic and runs in browsers, Web Workers, and Node.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -105,6 +105,14 @@
|
|
|
105
105
|
"types": "./lib/types/maps/index.d.ts",
|
|
106
106
|
"import": "./lib/addons/maps.js"
|
|
107
107
|
},
|
|
108
|
+
"./scene-3d": {
|
|
109
|
+
"types": "./lib/types/scene-3d/index.d.ts",
|
|
110
|
+
"import": "./lib/addons/scene-3d.js"
|
|
111
|
+
},
|
|
112
|
+
"./scene-3d/webgl": {
|
|
113
|
+
"types": "./lib/types/scene-3d/webgl/index.d.ts",
|
|
114
|
+
"import": "./lib/addons/scene-3d-webgl.js"
|
|
115
|
+
},
|
|
108
116
|
"./headless": {
|
|
109
117
|
"types": "./lib/types/headless/index.d.ts",
|
|
110
118
|
"import": "./lib/headless/headless.js"
|
|
@@ -137,7 +145,7 @@
|
|
|
137
145
|
"test": "vitest",
|
|
138
146
|
"test:run": "vitest run",
|
|
139
147
|
"build:addons": "vite build --config vite.config.addons.ts",
|
|
140
|
-
"build:browser": "vite build --config vite.config.browser.ts && vite build --config vite.config.browser-maps.ts",
|
|
148
|
+
"build:browser": "vite build --config vite.config.browser.ts && vite build --config vite.config.browser-maps.ts && vite build --config vite.config.browser-scene-3d.ts && vite build --config vite.config.browser-scene-3d-webgl.ts",
|
|
141
149
|
"prepublishOnly": "npm run test:run && npm run build:libs",
|
|
142
150
|
"e2e": "node e2e/run.mjs",
|
|
143
151
|
"release:oss": "./scripts/publish-oss.sh --push",
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
const w = /* @__PURE__ */ new Set([
|
|
2
|
-
"blur",
|
|
3
|
-
"brightness",
|
|
4
|
-
"glow",
|
|
5
|
-
"glowColor",
|
|
6
|
-
"shadowX",
|
|
7
|
-
"shadowY",
|
|
8
|
-
"shadowBlur",
|
|
9
|
-
"shadowColor"
|
|
10
|
-
]), b = "#ffffff", R = "rgba(0, 0, 0, 0.5)";
|
|
11
|
-
function x(r) {
|
|
12
|
-
const t = [];
|
|
13
|
-
if (r.blur !== void 0 && t.push(`blur(${Math.max(0, r.blur)}px)`), r.brightness !== void 0 && t.push(`brightness(${Math.max(0, r.brightness)})`), r.glow !== void 0 && t.push(`drop-shadow(0 0 ${Math.max(0, r.glow)}px ${r.glowColor ?? b})`), r.shadowX !== void 0 || r.shadowY !== void 0 || r.shadowBlur !== void 0) {
|
|
14
|
-
const o = r.shadowX ?? 0, e = r.shadowY ?? 0, a = Math.max(0, r.shadowBlur ?? 0);
|
|
15
|
-
t.push(`drop-shadow(${o}px ${e}px ${a}px ${r.shadowColor ?? R})`);
|
|
16
|
-
}
|
|
17
|
-
return t.length > 0 ? t.join(" ") : null;
|
|
18
|
-
}
|
|
19
|
-
function S(r, t) {
|
|
20
|
-
const o = r.childNodes.length === 1 ? r.firstChild : null;
|
|
21
|
-
if (o && o.nodeType === 3) {
|
|
22
|
-
const e = o;
|
|
23
|
-
e.data !== t && (e.data = t);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
r.textContent !== t && (r.textContent = t);
|
|
27
|
-
}
|
|
28
|
-
function $(r) {
|
|
29
|
-
if (!("ownerSVGElement" in r)) return;
|
|
30
|
-
const t = r.style;
|
|
31
|
-
!t || t.transformBox || (t.transformBox = "fill-box", t.transformOrigin || (t.transformOrigin = "50% 50%"));
|
|
32
|
-
}
|
|
33
|
-
const d = /* @__PURE__ */ new Set([
|
|
34
|
-
"width",
|
|
35
|
-
"height",
|
|
36
|
-
"top",
|
|
37
|
-
"right",
|
|
38
|
-
"bottom",
|
|
39
|
-
"left",
|
|
40
|
-
"margin",
|
|
41
|
-
"marginTop",
|
|
42
|
-
"marginRight",
|
|
43
|
-
"marginBottom",
|
|
44
|
-
"marginLeft",
|
|
45
|
-
"padding",
|
|
46
|
-
"paddingTop",
|
|
47
|
-
"paddingRight",
|
|
48
|
-
"paddingBottom",
|
|
49
|
-
"paddingLeft",
|
|
50
|
-
"borderRadius",
|
|
51
|
-
"borderWidth",
|
|
52
|
-
"fontSize",
|
|
53
|
-
"lineHeight",
|
|
54
|
-
"letterSpacing",
|
|
55
|
-
"outlineWidth",
|
|
56
|
-
"gap",
|
|
57
|
-
"rowGap",
|
|
58
|
-
"columnGap"
|
|
59
|
-
]), m = /* @__PURE__ */ new Set([
|
|
60
|
-
"x",
|
|
61
|
-
"y",
|
|
62
|
-
"z",
|
|
63
|
-
"rotate",
|
|
64
|
-
"rotateX",
|
|
65
|
-
"rotateY",
|
|
66
|
-
"rotateZ",
|
|
67
|
-
"scale",
|
|
68
|
-
"scaleX",
|
|
69
|
-
"scaleY",
|
|
70
|
-
"scaleZ",
|
|
71
|
-
"skewX",
|
|
72
|
-
"skewY",
|
|
73
|
-
// Motion path properties
|
|
74
|
-
"motionPathX",
|
|
75
|
-
"motionPathY",
|
|
76
|
-
"motionPathRotate"
|
|
77
|
-
]), k = /* @__PURE__ */ new Set(["originX", "originY"]), O = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]), T = /* @__PURE__ */ new Set(["drawOn"]), C = {
|
|
78
|
-
fill: "backgroundColor",
|
|
79
|
-
stroke: "borderColor",
|
|
80
|
-
strokeWidth: "borderWidth",
|
|
81
|
-
color: "color",
|
|
82
|
-
backgroundColor: "backgroundColor",
|
|
83
|
-
borderColor: "borderColor"
|
|
84
|
-
}, u = {
|
|
85
|
-
fill: "fill",
|
|
86
|
-
stroke: "stroke",
|
|
87
|
-
strokeWidth: "strokeWidth",
|
|
88
|
-
strokeDasharray: "strokeDasharray",
|
|
89
|
-
strokeDashoffset: "strokeDashoffset",
|
|
90
|
-
fillOpacity: "fillOpacity",
|
|
91
|
-
strokeOpacity: "strokeOpacity"
|
|
92
|
-
}, Y = "http://www.w3.org/2000/svg";
|
|
93
|
-
class E {
|
|
94
|
-
targets = /* @__PURE__ */ new Map();
|
|
95
|
-
/**
|
|
96
|
-
* Register an HTML element as an animation target.
|
|
97
|
-
*/
|
|
98
|
-
registerTarget(t, o) {
|
|
99
|
-
this.targets.set(t, o);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Unregister a target by its ID.
|
|
103
|
-
*/
|
|
104
|
-
unregisterTarget(t) {
|
|
105
|
-
this.targets.delete(t);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Get a registered target element.
|
|
109
|
-
*/
|
|
110
|
-
getTarget(t) {
|
|
111
|
-
return this.targets.get(t);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Clear all registered targets.
|
|
115
|
-
*/
|
|
116
|
-
clearTargets() {
|
|
117
|
-
this.targets.clear();
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Apply animation state to all registered targets.
|
|
121
|
-
*/
|
|
122
|
-
applyState(t) {
|
|
123
|
-
for (const [o, e] of t.values) {
|
|
124
|
-
const a = this.targets.get(o);
|
|
125
|
-
a && this.applyProperties(a, e);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Apply properties to a single element.
|
|
130
|
-
*/
|
|
131
|
-
applyProperties(t, o) {
|
|
132
|
-
const e = [];
|
|
133
|
-
let a = null, n = null, c = null;
|
|
134
|
-
const h = o.has("motionPathX"), y = o.has("motionPathY"), P = o.has("motionPathRotate");
|
|
135
|
-
for (const [s, i] of o)
|
|
136
|
-
if (!(s === "x" && h) && !(s === "y" && y) && !((s === "rotate" || s === "rotateZ") && P) && !T.has(s)) {
|
|
137
|
-
if (m.has(s)) {
|
|
138
|
-
const l = this.buildTransformPart(s, i);
|
|
139
|
-
l && e.push(l);
|
|
140
|
-
} else if (k.has(s))
|
|
141
|
-
typeof i == "number" && ((a ??= {})[s] = i);
|
|
142
|
-
else if (O.has(s))
|
|
143
|
-
typeof i == "number" && ((n ??= {})[s] = i);
|
|
144
|
-
else if (w.has(s))
|
|
145
|
-
(c ??= {})[s] = i;
|
|
146
|
-
else if (s !== "perspective") {
|
|
147
|
-
if (s !== "shine") if (s === "text" && typeof i == "string")
|
|
148
|
-
S(t, i);
|
|
149
|
-
else if (s === "d" && typeof i == "string") {
|
|
150
|
-
const l = t;
|
|
151
|
-
(l.tagName?.toLowerCase() === "path" ? l : l.querySelector?.("path"))?.setAttribute?.("d", i);
|
|
152
|
-
} else
|
|
153
|
-
this.applyStyleProperty(t, s, i);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
const f = o.get("shine");
|
|
157
|
-
typeof f == "number" && this.applyShine(t, f);
|
|
158
|
-
const g = o.get("perspective");
|
|
159
|
-
if (typeof g == "number" && e.unshift(`perspective(${g}px)`), e.length > 0 && (t.style.transform = e.join(" "), $(t)), a) {
|
|
160
|
-
const s = a.originX ?? 50, i = a.originY ?? 50;
|
|
161
|
-
t.style.transformOrigin = `${s}% ${i}%`;
|
|
162
|
-
}
|
|
163
|
-
if (n) {
|
|
164
|
-
const s = n.clipTop ?? 0, i = n.clipRight ?? 0, l = n.clipBottom ?? 0, p = n.clipLeft ?? 0;
|
|
165
|
-
t.style.clipPath = `inset(${s}% ${i}% ${l}% ${p}%)`;
|
|
166
|
-
}
|
|
167
|
-
if (c) {
|
|
168
|
-
const s = x(c);
|
|
169
|
-
s && (t.style.filter = s);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Build a transform function string for a property.
|
|
174
|
-
*/
|
|
175
|
-
buildTransformPart(t, o) {
|
|
176
|
-
if (typeof o != "number") return null;
|
|
177
|
-
switch (t) {
|
|
178
|
-
case "x":
|
|
179
|
-
case "motionPathX":
|
|
180
|
-
return `translateX(${o}px)`;
|
|
181
|
-
case "y":
|
|
182
|
-
case "motionPathY":
|
|
183
|
-
return `translateY(${o}px)`;
|
|
184
|
-
case "z":
|
|
185
|
-
return `translateZ(${o}px)`;
|
|
186
|
-
case "rotate":
|
|
187
|
-
case "rotateZ":
|
|
188
|
-
case "motionPathRotate":
|
|
189
|
-
return `rotate(${o}deg)`;
|
|
190
|
-
case "rotateX":
|
|
191
|
-
return `rotateX(${o}deg)`;
|
|
192
|
-
case "rotateY":
|
|
193
|
-
return `rotateY(${o}deg)`;
|
|
194
|
-
case "scale":
|
|
195
|
-
return `scale(${o})`;
|
|
196
|
-
case "scaleX":
|
|
197
|
-
return `scaleX(${o})`;
|
|
198
|
-
case "scaleY":
|
|
199
|
-
return `scaleY(${o})`;
|
|
200
|
-
case "scaleZ":
|
|
201
|
-
return `scaleZ(${o})`;
|
|
202
|
-
case "skewX":
|
|
203
|
-
return `skewX(${o}deg)`;
|
|
204
|
-
case "skewY":
|
|
205
|
-
return `skewY(${o}deg)`;
|
|
206
|
-
default:
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Apply a shine sweep to a (text) element.
|
|
212
|
-
*
|
|
213
|
-
* `progress` runs 0..1 as the highlight travels from just off the left edge to
|
|
214
|
-
* just off the right. Two layered, text-clipped gradients are used: a moving
|
|
215
|
-
* white highlight band on top of a solid layer of the element's base colour,
|
|
216
|
-
* so the text stays visible while the sheen passes over the glyphs.
|
|
217
|
-
*/
|
|
218
|
-
applyShine(t, o) {
|
|
219
|
-
t.dataset.shineBase || (t.dataset.shineBase = t.style.color || "currentColor");
|
|
220
|
-
const e = t.dataset.shineBase, a = -20 + o * 140, n = t.style;
|
|
221
|
-
n.color = "transparent", n.backgroundImage = `linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.9) 50%, transparent 60%), linear-gradient(${e}, ${e})`, n.backgroundSize = "250% 100%, 100% 100%", n.backgroundPosition = `${a}% 0, 0 0`, n.backgroundRepeat = "no-repeat", n.webkitBackgroundClip = "text", n.backgroundClip = "text";
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Apply a single style property to an element.
|
|
225
|
-
*/
|
|
226
|
-
applyStyleProperty(t, o, e) {
|
|
227
|
-
let a;
|
|
228
|
-
if (t.namespaceURI === Y && o in u) {
|
|
229
|
-
const h = Array.isArray(e) ? e.join(", ") : String(e);
|
|
230
|
-
t.style[u[o]] = h;
|
|
231
|
-
return;
|
|
232
|
-
} else o === "fill" && t.dataset?.elementType === "text" ? a = "color" : a = C[o] ?? o;
|
|
233
|
-
let c;
|
|
234
|
-
typeof e == "number" ? d.has(o) || d.has(a) ? c = `${e}px` : c = String(e) : Array.isArray(e) ? c = e.join(", ") : c = e, t.style[a] = c;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
export {
|
|
238
|
-
E as D,
|
|
239
|
-
w as F,
|
|
240
|
-
x as c,
|
|
241
|
-
$ as e,
|
|
242
|
-
S as s
|
|
243
|
-
};
|