figureone 1.9.0 → 1.9.1
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/figureone.min.js +1 -1
- package/index.js +21 -3
- package/llms-full.txt +37 -0
- package/llms.txt +10 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -66649,13 +66649,31 @@ function composeFragShader() {
|
|
|
66649
66649
|
// alpha controls how strongly that region is recolored (0 = leave the base
|
|
66650
66650
|
// color unchanged). With one mask this is exactly four mixes and one extra
|
|
66651
66651
|
// texture fetch; each additional mask adds one fetch and four mixes.
|
|
66652
|
+
//
|
|
66653
|
+
// Masks are uploaded with premultiplied alpha, so a region only carries full
|
|
66654
|
+
// weight where the mask pixel is opaque. Author each mask pixel as one of:
|
|
66655
|
+
// keep base : [0, 0, 0, 0] (transparent)
|
|
66656
|
+
// region 0 : [1, 0, 0, 1] -> u_tint0 (r channel)
|
|
66657
|
+
// region 1 : [0, 1, 0, 1] -> u_tint1 (g channel)
|
|
66658
|
+
// region 2 : [0, 0, 1, 1] -> u_tint2 (b channel)
|
|
66659
|
+
// region 3 : [0, 0, 0, 1] -> u_tint3 (a channel, opaque black)
|
|
66660
|
+
// With every painted region opaque, the alpha channel is 1 across all of them,
|
|
66661
|
+
// so it can't act as an independent region on its own. The a-channel mix below
|
|
66662
|
+
// gates on (1 - r - g - b) so region 3 is exactly the opaque-black pixels - the
|
|
66663
|
+
// ones not already claimed by an r/g/b region. Regions 0-2 support partial
|
|
66664
|
+
// weight by lowering their channel value (e.g. [0.5, 0, 0, 1]); region 3 is
|
|
66665
|
+
// full-weight only, with slight antialiasing softness at its borders.
|
|
66652
66666
|
src += ' vec4 base = texture2D(u_texture, v_texcoord);\n';
|
|
66653
66667
|
src += ' vec3 col = base.rgb;\n';
|
|
66654
66668
|
for (var _m = 0; _m < numMasks; _m += 1) {
|
|
66655
66669
|
src += " vec4 mask".concat(_m, " = texture2D(u_mask").concat(_m, ", v_texcoord);\n");
|
|
66656
66670
|
for (var c = 0; c < CHANNELS_PER_MASK; c += 1) {
|
|
66657
66671
|
var _t = _m * CHANNELS_PER_MASK + c;
|
|
66658
|
-
|
|
66672
|
+
if (channels[c] === 'a') {
|
|
66673
|
+
src += " col = mix(col, u_tint".concat(_t, ".rgb, mask").concat(_m, ".a * (1.0 - clamp(mask").concat(_m, ".r + mask").concat(_m, ".g + mask").concat(_m, ".b, 0.0, 1.0)) * u_tint").concat(_t, ".a);\n");
|
|
66674
|
+
} else {
|
|
66675
|
+
src += " col = mix(col, u_tint".concat(_t, ".rgb, mask").concat(_m, ".").concat(channels[c], " * u_tint").concat(_t, ".a);\n");
|
|
66676
|
+
}
|
|
66659
66677
|
}
|
|
66660
66678
|
}
|
|
66661
66679
|
src += ' gl_FragColor = vec4(col, base.a * u_color.a);\n';
|
|
@@ -82283,8 +82301,8 @@ var tools = {
|
|
|
82283
82301
|
*/
|
|
82284
82302
|
|
|
82285
82303
|
var Fig = {
|
|
82286
|
-
version: "1.9.
|
|
82287
|
-
gitHash: "
|
|
82304
|
+
version: "1.9.1",
|
|
82305
|
+
gitHash: "0adca1678",
|
|
82288
82306
|
tools: tools,
|
|
82289
82307
|
Figure: _js_figure_Figure__WEBPACK_IMPORTED_MODULE_5__["default"],
|
|
82290
82308
|
Recorder: _js_figure_Recorder_Recorder__WEBPACK_IMPORTED_MODULE_7__.Recorder,
|
package/llms-full.txt
CHANGED
|
@@ -115,6 +115,8 @@ Path to figure element(s) within a collection. Supports multiple formats:
|
|
|
115
115
|
| loadColor | TypeColor | `[0, 0, 1, 0.5]` | Color while loading |
|
|
116
116
|
| onLoad | () => void | | Callback after load |
|
|
117
117
|
|
|
118
|
+
A `texture` on the `gl` primitive can be recolored by region with one or more masks — see OBJ_TextureMask under OBJ_GenericGL.
|
|
119
|
+
|
|
118
120
|
### OBJ_FigurePrimitive (base for all primitives)
|
|
119
121
|
|
|
120
122
|
| Property | Type | Default | Description |
|
|
@@ -365,12 +367,47 @@ Extends OBJ_Generic (without drawType).
|
|
|
365
367
|
| attributes | OBJ_GLAttribute[] | | Shader attributes |
|
|
366
368
|
| uniforms | OBJ_GLUniform[] | | Shader uniforms |
|
|
367
369
|
| texture | OBJ_Texture | | Texture |
|
|
370
|
+
| mask | OBJ_TextureMask | | Single mask to recolor regions of `texture` |
|
|
371
|
+
| masks | OBJ_TextureMask[] | | Multiple masks (each adds 4 recolorable regions) |
|
|
372
|
+
| tints | (TypeColor \| null)[] | | Recolor per region; mask `m` uses `tints[4m]`…`tints[4m+3]` for its r,g,b,a channels (`null` = leave region unchanged) |
|
|
368
373
|
| dimension | `2` \| `3` | `2` | Coordinate dimensions |
|
|
369
374
|
| light | `'directional'` \| `'point'` \| null | null | Lighting |
|
|
370
375
|
| vertices | number[] \| object | | Vertex data |
|
|
371
376
|
| colors | number[] \| object | | Per-vertex colors |
|
|
372
377
|
| normals | number[] \| object | | Normal vectors |
|
|
373
378
|
|
|
379
|
+
A texture can be recolored by region using one or more masks. A mask shares the base texture's coordinates (same dimensions, aligned to the base image); each of its r, g, b, a channels marks a region. Mask `m` is recolored by `tints[4m]` (r), `tints[4m + 1]` (g), `tints[4m + 2]` (b), `tints[4m + 3]` (a); unmasked pixels keep the base texture's color. A single mask costs one extra texture fetch and four mixes; each additional mask adds one fetch and four mixes.
|
|
380
|
+
|
|
381
|
+
### OBJ_TextureMask
|
|
382
|
+
|
|
383
|
+
| Property | Type | Default | Description |
|
|
384
|
+
|---|---|---|---|
|
|
385
|
+
| src | string | | URL of the mask image |
|
|
386
|
+
| loadColor | TypeColor | `[0, 0, 0, 0]` | Color shown while the mask loads (transparent = nothing recolored until loaded) |
|
|
387
|
+
|
|
388
|
+
```js
|
|
389
|
+
// Recolor three regions of a texture with one mask. The mask image's red,
|
|
390
|
+
// green and blue channels mark the regions tinted by tints 0, 1 and 2.
|
|
391
|
+
figure.add({
|
|
392
|
+
make: 'gl',
|
|
393
|
+
vertices: [-0.8, -0.8, 0.8, -0.8, -0.8, 0.8, 0.8, -0.8, 0.8, 0.8, -0.8, 0.8],
|
|
394
|
+
texture: { src: './image.png', coords: [0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1] },
|
|
395
|
+
mask: { src: './mask.png' },
|
|
396
|
+
tints: [[1, 0, 0, 1], [0, 0.6, 0, 1], [0, 0, 1, 1]],
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
// Two masks: mask 0 uses tints 0-3, mask 1 uses tints 4-7.
|
|
400
|
+
figure.add({
|
|
401
|
+
make: 'gl',
|
|
402
|
+
// ...vertices, texture...
|
|
403
|
+
masks: [{ src: './mask.png' }, { src: './mask1.png' }],
|
|
404
|
+
tints: [
|
|
405
|
+
[1, 0, 0, 1], [0, 0.6, 0, 1], [0, 0, 1, 1], null, // mask 0
|
|
406
|
+
[0.6, 0, 0.8, 1], // mask 1
|
|
407
|
+
],
|
|
408
|
+
});
|
|
409
|
+
```
|
|
410
|
+
|
|
374
411
|
### OBJ_Morph (`make: 'morph'`)
|
|
375
412
|
|
|
376
413
|
Morphable shape with multiple point arrays that can be animated between.
|
package/llms.txt
CHANGED
|
@@ -97,6 +97,16 @@ figure.add({
|
|
|
97
97
|
make: 'rectangle', width: 1.8, height: 1.2,
|
|
98
98
|
texture: { src: 'image.jpg', mapTo: [-0.9, -0.6, 1.8, 1.2] },
|
|
99
99
|
});
|
|
100
|
+
|
|
101
|
+
// Recolor regions of a texture with masks (gl primitive). Each mask's r,g,b,a
|
|
102
|
+
// channels mark regions; mask m is tinted by tints[4m]..tints[4m+3].
|
|
103
|
+
figure.add({
|
|
104
|
+
make: 'gl',
|
|
105
|
+
vertices: [-0.8, -0.8, 0.8, -0.8, -0.8, 0.8, 0.8, -0.8, 0.8, 0.8, -0.8, 0.8],
|
|
106
|
+
texture: { src: 'image.png', coords: [0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1] },
|
|
107
|
+
masks: [{ src: 'mask.png' }, { src: 'mask1.png' }],
|
|
108
|
+
tints: [[1, 0, 0, 1], [0, 0.6, 0, 1], [0, 0, 1, 1], null, [0.6, 0, 0.8, 1]],
|
|
109
|
+
});
|
|
100
110
|
```
|
|
101
111
|
|
|
102
112
|
### Element Properties
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "figureone",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"description": "Draw, animate and interact with shapes, text, plots and equations in Javascript. Create interactive slide shows, and interactive videos.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|