@margoengine/toon 0.1.0 → 1.0.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/LICENSE CHANGED
@@ -1,201 +1,201 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright 2026 Scott Campbell
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Scott Campbell
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE CHANGED
@@ -1,4 +1,4 @@
1
- Margo Engine
2
- Copyright 2026 Scott Campbell
3
-
4
- This product includes Margo Engine (https://margoengine.com) by Scott Campbell.
1
+ Margo Engine
2
+ Copyright 2026 Scott Campbell
3
+
4
+ This product includes Margo Engine (https://margoengine.com) by Scott Campbell.
package/README.md CHANGED
@@ -1,94 +1,94 @@
1
- # @margoengine/toon
2
-
3
- Stepped diffuse shading and inverted-hull outlines.
4
-
5
- Import `margoengine/toon` from the `margoengine` package, or `@margoengine/toon` from this package alone; the two are the same module. Neither is on npm yet: the [Install](../../README.md#install) section lists the two routes that work today (run in a clone, or install local tarballs).
6
-
7
- Stepped diffuse ramps reuse creative/ToonShading. A second front-culled pass expands vertex normals into an inverted hull for silhouette outlines.
8
-
9
- ```ts
10
- import {Toon} from 'margoengine/toon';
11
- import {Engine} from 'margoengine/core';
12
- const engine = await Engine.create(document.querySelector('canvas')!);
13
- const toon = Toon.attach(engine, {bands: 4, rim: 0.15, outline: 0.025});
14
- ```
15
-
16
- Outline thickness is world units. color is linear RGB in 0..1. The hull replays visible core geometry with the existing reversed-Z depth buffer. Geometry should have coherent smooth normals for a continuous silhouette; hard-normal seams can separate hull corners. `Toon` is a core-mesh pipeline; outline loaded and animated models with `ModelOutlines` (below). dispose removes both passes.
17
-
18
- ## Outlines on loaded and skinned models
19
-
20
- `@margoengine/toon/models` draws the same inverted hull around loaded glTF PBR models and `@margoengine/materials` meshes: skinned and morphed characters keep their outline in every pose (the hull is drawn from the vertices their deformer wrote this frame), and instanced primitives get one hull per instance.
21
-
22
- ```ts
23
- import {ModelOutlines} from 'margoengine/toon/models';
24
- import {Engine} from 'margoengine/core';
25
- import {loadGLTF} from 'margoengine/gltf/pbr';
26
- import {Animation} from 'margoengine/animation';
27
- const engine = await Engine.create(document.querySelector('canvas')!);
28
- const character = await loadGLTF(engine, '/hero.glb');
29
- Animation.attach(character).play(0);
30
- const outlines = ModelOutlines.attach(engine, {outline: 0.02, color: [0.02, 0.01, 0.01]});
31
- outlines.outline = 0.03; // live, as are the other options
32
- outlines.materials = {Hair: {outline: 0.05, color: [0.2, 0.05, 0]}, Eyes: {outline: 0}}; // per material, 0: no line
33
- outlines.vertexColors = true; // painted COLOR_0 tints the line and its alpha scales the width
34
- outlines.nodes = [character.nodes[0]]; // only that node's primitives and its children's (undefined: all)
35
- ```
36
-
37
- Options: `outline`, thickness in world units 0 to 10 (default 0.025, 0 hides it); `color`, linear RGB 0 to 1 (default `[0.015, 0.015, 0.015]`); `smooth`, seam-free outlines (default true, live); `materials`, width and colour by glTF material name over those two (default none, live); `vertexColors`, the line's colour times the vertex colour (COLOR_0) RGB and its width times its alpha (default false, live); `models`, the models to outline (default every model on the engine); `nodes`, only the primitives under these nodes (a model's `root` or entries of `model.nodes`, each with its descendants; default every primitive, live), as drei's `Outlines` inside one `skinnedMesh`. Hidden nodes and nodes outside a view's layers get no outline; point and line primitives never do. With `smooth`, every copy of a vertex at one position (split by a hard edge or a UV seam) pushes out along the average of their normals, read each frame from the vertices drawn, so hard-edged meshes get an unbroken outline, posed ones too; it is thinner at sharp corners (a cube's corner moves the width over the square root of 3 each way). `positionRings(vertices)` returns the links it bakes, each vertex's next copy at the same position. Positions must match bit for bit; at most 64 copies a position are averaged; a vertex buffer without STORAGE usage draws as `smooth: false`. With `smooth: false` the line follows each vertex's own normal and parts at creases. WebGPU only; `dispose()` removes the pass. For a screen-space line of fixed pixel width, use `@margoengine/post` `Outline`.
38
-
39
- ## One mesh's outline
40
-
41
- `@margoengine/toon/outline` outlines a single core mesh (drei's `Outlines`; React: `@margoengine/react/outlines`): its triangles are drawn again with front faces culled and every vertex pushed out along a hull normal, after the opaque scene.
42
-
43
- ```ts
44
- import {MeshOutline} from 'margoengine/toon/outline';
45
- import {Engine, box} from 'margoengine/core';
46
- const engine = await Engine.create(document.querySelector('canvas')!);
47
- const mesh = engine.createMesh().setGeometry(box(1, 1, 1));
48
- const outline = MeshOutline.attach(engine, {mesh, thickness: 3, screenspace: true, color: [0.02, 0.05, 0.3]});
49
- outline.angle = 0; // live: let the hull part at every crease
50
- outline.transparent = true;
51
- outline.opacity = 0.5;
52
- ```
53
-
54
- Options (every one but `renderOrder` live as a property): `mesh` (required); `geometry`, the triangles when another package draws the mesh (default the mesh's own); `color`, linear RGB 0 or more (default black); `opacity` 0..1, blended only when `transparent` (default 1, false; a transparent line leaves depth unwritten); `thickness`, world units or, with `screenspace`, drawing-buffer pixels, 0..1024 (default 0.05, false); `toneMapped`, the colour goes through Khronos PBR Neutral like a lit surface, else it is clamped like unlit output, then sRGB encoded either way (default true); `polygonOffset` and `polygonOffsetFactor`, depth pushed back by the factor times the depth slope (default false, 0); `renderOrder` -1000..1000, draw order among outlines (default 0); `angle`, the crease angle 0..pi: copies of a vertex at one position whose normals lie within it of each other push out along their averaged normal (default pi, a closed hull; 0 keeps each face's normal, so the line parts at creases). A mirrored matrix culls back faces instead. `creasedNormals(vertices, angle)` and `outlineColor(color, toneMapped)` return what is uploaded. WebGPU or the WebGL2 compatibility layer; `dispose()` removes the pass. Sources: Raskar and Cohen, "Image Precision Silhouette Edges" (I3D 1999); Gooch, Sloan, Gooch, Shirley and Riesenfeld, "Interactive Technical Illustration" (I3D 1999); Thurmer and Wuthrich, "Computing Vertex Normals from Polygonal Facets" (JGT 1998); not re-read for this entry.
55
-
56
- ## Hatching and halftone
57
-
58
- Hatching composes with `Shadows` and `Clustered`. The ink is applied after both have contributed to the lit paper
59
- colour. This follows the separation of tone and ink coverage described by [Winkenbach and Salesin,
60
- *Computer-Generated Pen-and-Ink Illustration* (1994)](https://grail.cs.washington.edu/projects/cg-illus/) and
61
- [Praun, Hoppe, Webb and Finkelstein, *Real-Time Hatching* (2001)](https://gfx.cs.princeton.edu/pubs/Praun_2001_RH/).
62
-
63
- `@margoengine/toon/hatch` draws pen hatching or print dots in place of flat bands on core meshes: the surface takes its full lit colour (the paper) and the diffuse light level decides how much of each pixel is ink, in a pattern fixed to the screen.
64
-
65
- ```ts
66
- import {Hatching} from 'margoengine/toon/hatch';
67
- import {Engine} from 'margoengine/core';
68
- const engine = await Engine.create(document.querySelector('canvas')!);
69
- const hatching = Hatching.attach(engine, {style: 'hatch', spacing: 8, layers: 3});
70
- hatching.style = 'halftone'; // live, as are the other options; hatching.set({...}) changes several at once
71
- ```
72
-
73
- Options (each live): `style`, `'hatch'` (default) or `'halftone'`; `spacing`, line or dot spacing in screen pixels, 2 to 64 (default 8); `width`, stroke width in pixels for `'hatch'`, 0.5 up to `spacing` (default 1.5); `layers`, stroke layers for `'hatch'`, 1 to 4 (default 3), layer k drawn where the light is below (layers - k) / (layers + 1), each turned 180 / layers degrees from the last; `angle`, the first strokes' or the dot grid's angle in degrees (default 45); `ink`, linear RGB 0 to 1 drawn unlit (default black). Halftone dots cover 1 - light of each cell. With `Toon` attached too, hatching replaces its bands and keeps its rim and outlines. Core meshes only; it uses group 0 binding 146. WebGPU only.
74
-
75
- For toon shading per material, on materials meshes (plain, instanced, skinned) and loaded glTF PBR models (skinned and morphed too), use `@margoengine/materials`: `new ToonMaterial({gradientMap})` or `{steps: 3}`, and `toonModel(model)` for a loaded model or some of its primitives. Both band the sun, clustered lights and their shadows through the ramp.
76
-
77
- ```ts
78
- import {ToonMaterial, createMesh, toonModel} from 'margoengine/materials';
79
- import {Engine} from 'margoengine/core';
80
- import {sphereGeometry} from 'margoengine/geometry';
81
- import {loadGLTF} from 'margoengine/gltf/pbr';
82
- const engine = await Engine.create(document.querySelector('canvas')!);
83
- const geometry = sphereGeometry(1, 32, 16), character = await loadGLTF(engine, '/hero.glb');
84
- createMesh(engine, geometry, new ToonMaterial({color: '#e07040', steps: 3}));
85
- toonModel(character, {steps: 4});
86
- ```
87
-
88
- Apache-2.0. Optional, tree-shakable package; core peer: ^0.1.0 || ^1.0.0.
89
-
90
- Build and unit tests: npm test --workspace @margoengine/toon
91
-
92
- ## Preview tier contract
93
-
94
- GPU-only attachments refuse the small WebGL2 preview during setup with `MargoError` code `unsupported` and a help link. Native WebGPU and the full WebGL2 compatibility layer expose the WebGPU-shaped device these passes need. Use [automatic escalation](../webgl2-compat/README.md#automatic-escalation) with awaited setup to load the full layer when required. Existing real preview routes remain available.
1
+ # @margoengine/toon
2
+
3
+ Stepped diffuse shading and inverted-hull outlines.
4
+
5
+ Import `margoengine/toon` from the `margoengine` package, or `@margoengine/toon` from this package alone; the two are the same module. Neither is on npm yet: the [Install](../../README.md#install) section lists the two routes that work today (run in a clone, or install local tarballs).
6
+
7
+ Stepped diffuse ramps reuse creative/ToonShading. A second front-culled pass expands vertex normals into an inverted hull for silhouette outlines.
8
+
9
+ ```ts
10
+ import {Toon} from 'margoengine/toon';
11
+ import {Engine} from 'margoengine/core';
12
+ const engine = await Engine.create(document.querySelector('canvas')!);
13
+ const toon = Toon.attach(engine, {bands: 4, rim: 0.15, outline: 0.025});
14
+ ```
15
+
16
+ Outline thickness is world units. color is linear RGB in 0..1. The hull replays visible core geometry with the existing reversed-Z depth buffer. Geometry should have coherent smooth normals for a continuous silhouette; hard-normal seams can separate hull corners. `Toon` is a core-mesh pipeline; outline loaded and animated models with `ModelOutlines` (below). dispose removes both passes.
17
+
18
+ ## Outlines on loaded and skinned models
19
+
20
+ `@margoengine/toon/models` draws the same inverted hull around loaded glTF PBR models and `@margoengine/materials` meshes: skinned and morphed characters keep their outline in every pose (the hull is drawn from the vertices their deformer wrote this frame), and instanced primitives get one hull per instance.
21
+
22
+ ```ts
23
+ import {ModelOutlines} from 'margoengine/toon/models';
24
+ import {Engine} from 'margoengine/core';
25
+ import {loadGLTF} from 'margoengine/gltf/pbr';
26
+ import {Animation} from 'margoengine/animation';
27
+ const engine = await Engine.create(document.querySelector('canvas')!);
28
+ const character = await loadGLTF(engine, '/hero.glb');
29
+ Animation.attach(character).play(0);
30
+ const outlines = ModelOutlines.attach(engine, {outline: 0.02, color: [0.02, 0.01, 0.01]});
31
+ outlines.outline = 0.03; // live, as are the other options
32
+ outlines.materials = {Hair: {outline: 0.05, color: [0.2, 0.05, 0]}, Eyes: {outline: 0}}; // per material, 0: no line
33
+ outlines.vertexColors = true; // painted COLOR_0 tints the line and its alpha scales the width
34
+ outlines.nodes = [character.nodes[0]]; // only that node's primitives and its children's (undefined: all)
35
+ ```
36
+
37
+ Options: `outline`, thickness in world units 0 to 10 (default 0.025, 0 hides it); `color`, linear RGB 0 to 1 (default `[0.015, 0.015, 0.015]`); `smooth`, seam-free outlines (default true, live); `materials`, width and colour by glTF material name over those two (default none, live); `vertexColors`, the line's colour times the vertex colour (COLOR_0) RGB and its width times its alpha (default false, live); `models`, the models to outline (default every model on the engine); `nodes`, only the primitives under these nodes (a model's `root` or entries of `model.nodes`, each with its descendants; default every primitive, live), as drei's `Outlines` inside one `skinnedMesh`. Hidden nodes and nodes outside a view's layers get no outline; point and line primitives never do. With `smooth`, every copy of a vertex at one position (split by a hard edge or a UV seam) pushes out along the average of their normals, read each frame from the vertices drawn, so hard-edged meshes get an unbroken outline, posed ones too; it is thinner at sharp corners (a cube's corner moves the width over the square root of 3 each way). `positionRings(vertices)` returns the links it bakes, each vertex's next copy at the same position. Positions must match bit for bit; at most 64 copies a position are averaged; a vertex buffer without STORAGE usage draws as `smooth: false`. With `smooth: false` the line follows each vertex's own normal and parts at creases. WebGPU only; `dispose()` removes the pass. For a screen-space line of fixed pixel width, use `@margoengine/post` `Outline`.
38
+
39
+ ## One mesh's outline
40
+
41
+ `@margoengine/toon/outline` outlines a single core mesh (drei's `Outlines`; React: `@margoengine/react/outlines`): its triangles are drawn again with front faces culled and every vertex pushed out along a hull normal, after the opaque scene.
42
+
43
+ ```ts
44
+ import {MeshOutline} from 'margoengine/toon/outline';
45
+ import {Engine, box} from 'margoengine/core';
46
+ const engine = await Engine.create(document.querySelector('canvas')!);
47
+ const mesh = engine.createMesh().setGeometry(box(1, 1, 1));
48
+ const outline = MeshOutline.attach(engine, {mesh, thickness: 3, screenspace: true, color: [0.02, 0.05, 0.3]});
49
+ outline.angle = 0; // live: let the hull part at every crease
50
+ outline.transparent = true;
51
+ outline.opacity = 0.5;
52
+ ```
53
+
54
+ Options (every one but `renderOrder` live as a property): `mesh` (required); `geometry`, the triangles when another package draws the mesh (default the mesh's own); `color`, linear RGB 0 or more (default black); `opacity` 0..1, blended only when `transparent` (default 1, false; a transparent line leaves depth unwritten); `thickness`, world units or, with `screenspace`, drawing-buffer pixels, 0..1024 (default 0.05, false); `toneMapped`, the colour goes through Khronos PBR Neutral like a lit surface, else it is clamped like unlit output, then sRGB encoded either way (default true); `polygonOffset` and `polygonOffsetFactor`, depth pushed back by the factor times the depth slope (default false, 0); `renderOrder` -1000..1000, draw order among outlines (default 0); `angle`, the crease angle 0..pi: copies of a vertex at one position whose normals lie within it of each other push out along their averaged normal (default pi, a closed hull; 0 keeps each face's normal, so the line parts at creases). A mirrored matrix culls back faces instead. `creasedNormals(vertices, angle)` and `outlineColor(color, toneMapped)` return what is uploaded. WebGPU or the WebGL2 compatibility layer; `dispose()` removes the pass. Sources: Raskar and Cohen, "Image Precision Silhouette Edges" (I3D 1999); Gooch, Sloan, Gooch, Shirley and Riesenfeld, "Interactive Technical Illustration" (I3D 1999); Thurmer and Wuthrich, "Computing Vertex Normals from Polygonal Facets" (JGT 1998); not re-read for this entry.
55
+
56
+ ## Hatching and halftone
57
+
58
+ Hatching composes with `Shadows` and `Clustered`. The ink is applied after both have contributed to the lit paper
59
+ colour. This follows the separation of tone and ink coverage described by [Winkenbach and Salesin,
60
+ *Computer-Generated Pen-and-Ink Illustration* (1994)](https://grail.cs.washington.edu/projects/cg-illus/) and
61
+ [Praun, Hoppe, Webb and Finkelstein, *Real-Time Hatching* (2001)](https://gfx.cs.princeton.edu/pubs/Praun_2001_RH/).
62
+
63
+ `@margoengine/toon/hatch` draws pen hatching or print dots in place of flat bands on core meshes: the surface takes its full lit colour (the paper) and the diffuse light level decides how much of each pixel is ink, in a pattern fixed to the screen.
64
+
65
+ ```ts
66
+ import {Hatching} from 'margoengine/toon/hatch';
67
+ import {Engine} from 'margoengine/core';
68
+ const engine = await Engine.create(document.querySelector('canvas')!);
69
+ const hatching = Hatching.attach(engine, {style: 'hatch', spacing: 8, layers: 3});
70
+ hatching.style = 'halftone'; // live, as are the other options; hatching.set({...}) changes several at once
71
+ ```
72
+
73
+ Options (each live): `style`, `'hatch'` (default) or `'halftone'`; `spacing`, line or dot spacing in screen pixels, 2 to 64 (default 8); `width`, stroke width in pixels for `'hatch'`, 0.5 up to `spacing` (default 1.5); `layers`, stroke layers for `'hatch'`, 1 to 4 (default 3), layer k drawn where the light is below (layers - k) / (layers + 1), each turned 180 / layers degrees from the last; `angle`, the first strokes' or the dot grid's angle in degrees (default 45); `ink`, linear RGB 0 to 1 drawn unlit (default black). Halftone dots cover 1 - light of each cell. With `Toon` attached too, hatching replaces its bands and keeps its rim and outlines. Core meshes only; it uses group 0 binding 146. WebGPU only.
74
+
75
+ For toon shading per material, on materials meshes (plain, instanced, skinned) and loaded glTF PBR models (skinned and morphed too), use `@margoengine/materials`: `new ToonMaterial({gradientMap})` or `{steps: 3}`, and `toonModel(model)` for a loaded model or some of its primitives. Both band the sun, clustered lights and their shadows through the ramp.
76
+
77
+ ```ts
78
+ import {ToonMaterial, createMesh, toonModel} from 'margoengine/materials';
79
+ import {Engine} from 'margoengine/core';
80
+ import {sphereGeometry} from 'margoengine/geometry';
81
+ import {loadGLTF} from 'margoengine/gltf/pbr';
82
+ const engine = await Engine.create(document.querySelector('canvas')!);
83
+ const geometry = sphereGeometry(1, 32, 16), character = await loadGLTF(engine, '/hero.glb');
84
+ createMesh(engine, geometry, new ToonMaterial({color: '#e07040', steps: 3}));
85
+ toonModel(character, {steps: 4});
86
+ ```
87
+
88
+ Apache-2.0. Optional, tree-shakable package; core peer: ^0.1.0 || ^1.0.0.
89
+
90
+ Build and unit tests: npm test --workspace @margoengine/toon
91
+
92
+ ## Preview tier contract
93
+
94
+ GPU-only attachments refuse the small WebGL2 preview during setup with `MargoError` code `unsupported` and a help link. Native WebGPU and the full WebGL2 compatibility layer expose the WebGPU-shaped device these passes need. Use [automatic escalation](../webgl2-compat/README.md#automatic-escalation) with awaited setup to load the full layer when required. Existing real preview routes remain available.
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const o=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const o=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { n as e, t } from "./errors-XvcwUnU4.js";
5
5
  import { i as n, n as r } from "./frame-resources-CRA1ZB6K.js";
6
6
  import { n as i, t as a } from "./hatch-style-DlyIqk6B.js";
@@ -86,7 +86,7 @@ var v = class e extends a {
86
86
  if (!o(e.root.engine).gpu) throw t("unsupported", "ModelHatching needs WebGPU or the full WebGL2 compatibility device");
87
87
  this.removeDraw = s(e, (e) => this.draw(e)), this.unsubscribe = e.onDispose(() => this.dispose());
88
88
  }
89
- static attach(t, n = {}) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
89
+ static attach(t, n = {}) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
90
90
  return new e(t, n);
91
91
  }
92
92
  draw(e) {
package/dist/hatch.js CHANGED
@@ -1,15 +1,15 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const n=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const n=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { n as e, t } from "./hatch-style-DlyIqk6B.js";
5
5
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
6
6
  import { MargoError as r } from "@margoengine/math/errors";
7
7
  //#region src/hatch.ts
8
- var i = 146, a = class i extends t {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
8
+ var i = 146, a = class i extends t {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
9
9
  constructor(...e) {
10
10
  super(...e), this.name = "toon:hatch", this.shaders = /* @__PURE__ */ new Map(), this.disposed = !1;
11
11
  }
12
- static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
12
+ static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
13
13
  let r = new i(t);
14
14
  return n(e).use(r), r;
15
15
  }
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const l=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const l=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { a as e, i as t, n, r, t as i } from "./rings-BmbstqyP.js";
5
5
  import { i as a, n as o, r as s, t as c } from "./frame-resources-CRA1ZB6K.js";
6
6
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
@@ -32,7 +32,7 @@ function _(e, t, n) {
32
32
  for (let r = t; r >= 0; r = e.parents?.[r] ?? -1) if (n.has(r)) return !0;
33
33
  return !1;
34
34
  }
35
- var v = (e) => e[0] * (e[5] * e[10] - e[6] * e[9]) - e[4] * (e[1] * e[10] - e[2] * e[9]) + e[8] * (e[1] * e[6] - e[2] * e[5]), y = class p {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
35
+ var v = (e) => e[0] * (e[5] * e[10] - e[6] * e[9]) - e[4] * (e[1] * e[10] - e[2] * e[9]) + e[8] * (e[1] * e[6] - e[2] * e[5]), y = class p {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
36
36
  get maxOutline() {
37
37
  return 10;
38
38
  }
@@ -56,7 +56,7 @@ var v = (e) => e[0] * (e[5] * e[10] - e[6] * e[9]) - e[4] * (e[1] * e[10] - e[2]
56
56
  t[2]
57
57
  ], this.only = a && [...a], this.smooth = !!n, this.vertexColors = !!i, this.materials = r, this.nodes = o;
58
58
  }
59
- static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
59
+ static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
60
60
  let n = new p(t);
61
61
  return l(e).use(n), n;
62
62
  }
package/dist/outline.js CHANGED
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const f=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const f=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { r as e, t } from "./errors-XvcwUnU4.js";
5
5
  import { a as n, i as r, n as i, o as a, r as o, t as s } from "./rings-BmbstqyP.js";
6
6
  import { i as c, n as l, r as u } from "./frame-resources-CRA1ZB6K.js";
@@ -70,7 +70,7 @@ function _(e, t) {
70
70
  return t < .0031308 ? t * 12.92 : 1.055 * t ** (1 / 2.4) - .055;
71
71
  });
72
72
  }
73
- var v = 0, y = (e, t, n) => typeof e == "number" && Number.isFinite(e) && e >= t && e <= n, b = class s {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
73
+ var v = 0, y = (e, t, n) => typeof e == "number" && Number.isFinite(e) && e >= t && e <= n, b = class s {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
74
74
  constructor(t) {
75
75
  if (this.name = "toon:outline:" + v++, this.groups = /* @__PURE__ */ new Map(), this.pipelines = /* @__PURE__ */ new Map(), this.values = /* @__PURE__ */ new Float32Array(40), this.colorAttachment = {
76
76
  view: void 0,
@@ -83,7 +83,7 @@ var v = 0, y = (e, t, n) => typeof e == "number" && Number.isFinite(e) && e >= t
83
83
  0
84
84
  ], this.opacity = t.opacity ?? 1, this.transparent = t.transparent ?? !1, this.thickness = t.thickness ?? .05, this.screenspace = t.screenspace ?? !1, this.toneMapped = t.toneMapped ?? !0, this.polygonOffset = t.polygonOffset ?? !1, this.polygonOffsetFactor = t.polygonOffsetFactor ?? 0, this.renderOrder = t.renderOrder ?? 0, this.angle = t.angle ?? Math.PI, this.validate();
85
85
  }
86
- static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
86
+ static attach(e, t) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
87
87
  let n = new s(t);
88
88
  return f(e).use(n), n;
89
89
  }
@@ -1,6 +1,6 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const i=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const i=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { o as e } from "./rings-BmbstqyP.js";
5
5
  import { t } from "./src-npYQWEC-.js";
6
6
  import { t as n } from "./models-CyFG_IC3.js";
@@ -17,7 +17,7 @@ var a = class n extends t {
17
17
  ...e
18
18
  }), this.pixelValues = /* @__PURE__ */ new Float32Array(8);
19
19
  }
20
- static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
20
+ static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
21
21
  let r = new n(t);
22
22
  return i(e).use(r), r;
23
23
  }
@@ -37,7 +37,7 @@ var a = class n extends t {
37
37
  ...e
38
38
  });
39
39
  }
40
- static attach(e, n = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
40
+ static attach(e, n = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
41
41
  let r = new t(n);
42
42
  return i(e).use(r), r;
43
43
  }
@@ -1,39 +1,39 @@
1
- import type { Mesh } from '@margoengine/core/extension';
2
-
3
- /**
4
- * Structural view of a gltf/pbr `PBRModel` primitive (also what @margoengine/materials meshes are): node-space
5
- * vertices, 20 floats each (position at 0, normal at 4, TEXCOORD_0 at 12), triangle indices and the material's
6
- * settings. `buffers` exist while its model is set up on a device; `deformed` replaces the vertices when skinned.
7
- */
8
- export interface ModelPrimitiveLike {
9
- readonly node: Mesh;
10
- readonly vertices: Float32Array;
11
- readonly indices: Uint32Array;
12
- readonly material: { readonly settings: ArrayLike<number>; readonly side?: 'front' | 'back' | 'double' };
13
- readonly nodeIndex?: number;
14
- /** gltf\/pbr `PBRInstances`: drawn once per instance (24 floats each, node-space matrix first). */
15
- readonly instances?: { readonly count: number; readonly data: Float32Array };
16
- readonly buffers?: { vertex: GPUBuffer; index: GPUBuffer };
17
- readonly deformed?: GPUBuffer;
18
- /** Byte offset of the primitive's vertices in `deformed`. Default 0. */
19
- readonly deformedOffset?: number;
20
- }
21
- /** Structural view of a gltf/pbr `PBRModel`: its `root` node and `primitives`. */
22
- export interface ModelLike {
23
- readonly root: Mesh;
24
- readonly primitives: readonly ModelPrimitiveLike[];
25
- readonly disposed?: boolean;
26
- }
27
- /**
28
- * Structural view of a pick proxy: an object drawn without triangles (an @margoengine/lod imposter level), hit through
29
- * its local bounding sphere `sphere` (x, y, z, radius) under `anchor`'s world matrix. `model` is reported with the hit.
30
- */
31
- export interface PickProxy {
32
- readonly anchor: Mesh;
33
- readonly sphere: ArrayLike<number>;
34
- readonly model?: object | null;
35
- }
36
- /** gltf/pbr shape: a `root` node and `primitives` with 20-float CPU vertices (the first one is checked). */
37
- export function isModel(value: unknown): value is ModelLike;
38
- /** Proxies from every engine plugin with a `pickProxies()` method (an @margoengine/lod `LODSystem`), in a new array. */
39
- export function engineProxies(engine: object): PickProxy[];
1
+ import type { Mesh } from '@margoengine/core/extension';
2
+
3
+ /**
4
+ * Structural view of a gltf/pbr `PBRModel` primitive (also what @margoengine/materials meshes are): node-space
5
+ * vertices, 20 floats each (position at 0, normal at 4, TEXCOORD_0 at 12), triangle indices and the material's
6
+ * settings. `buffers` exist while its model is set up on a device; `deformed` replaces the vertices when skinned.
7
+ */
8
+ export interface ModelPrimitiveLike {
9
+ readonly node: Mesh;
10
+ readonly vertices: Float32Array;
11
+ readonly indices: Uint32Array;
12
+ readonly material: { readonly settings: ArrayLike<number>; readonly side?: 'front' | 'back' | 'double' };
13
+ readonly nodeIndex?: number;
14
+ /** gltf\/pbr `PBRInstances`: drawn once per instance (24 floats each, node-space matrix first). */
15
+ readonly instances?: { readonly count: number; readonly data: Float32Array };
16
+ readonly buffers?: { vertex: GPUBuffer; index: GPUBuffer };
17
+ readonly deformed?: GPUBuffer;
18
+ /** Byte offset of the primitive's vertices in `deformed`. Default 0. */
19
+ readonly deformedOffset?: number;
20
+ }
21
+ /** Structural view of a gltf/pbr `PBRModel`: its `root` node and `primitives`. */
22
+ export interface ModelLike {
23
+ readonly root: Mesh;
24
+ readonly primitives: readonly ModelPrimitiveLike[];
25
+ readonly disposed?: boolean;
26
+ }
27
+ /**
28
+ * Structural view of a pick proxy: an object drawn without triangles (an @margoengine/lod imposter level), hit through
29
+ * its local bounding sphere `sphere` (x, y, z, radius) under `anchor`'s world matrix. `model` is reported with the hit.
30
+ */
31
+ export interface PickProxy {
32
+ readonly anchor: Mesh;
33
+ readonly sphere: ArrayLike<number>;
34
+ readonly model?: object | null;
35
+ }
36
+ /** gltf/pbr shape: a `root` node and `primitives` with 20-float CPU vertices (the first one is checked). */
37
+ export function isModel(value: unknown): value is ModelLike;
38
+ /** Proxies from every engine plugin with a `pickProxies()` method (an @margoengine/lod `LODSystem`), in a new array. */
39
+ export function engineProxies(engine: object): PickProxy[];
@@ -1,13 +1,13 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
- const n=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
3
+ const n=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { i as e, n as t } from "./frame-resources-CRA1ZB6K.js";
5
5
  import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
6
6
  import { ToonShading as r } from "@margoengine/creative/toon";
7
7
  import { MargoError as i } from "@margoengine/math/errors";
8
8
  //#endregion
9
9
  //#region ../shared/gpu.js
10
- var a = "\nstruct Frame {camera:mat4x4f,eye:vec4f,light:vec4f,radiance:vec4f,ambient:vec4f}\n@group(0) @binding(0) var<uniform> frame:Frame;\nstruct Input {@location(0) position:vec3f,@location(1) normal:vec3f,@location(2) m0:vec4f,@location(3) m1:vec4f,@location(4) m2:vec4f,@location(5) m3:vec4f,@location(6) color:vec4f,@location(7) factors:vec4f}\nstruct Output {@builtin(position) @invariant clip:vec4f,@location(0) @interpolate(flat) id:u32}\n@vertex fn vertex(i:Input)->Output {let model=mat4x4f(i.m0,i.m1,i.m2,i.m3);let p=model*vec4f(i.position,1);return Output(frame.camera*p,u32(i.factors.w));}\n", o = class o {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
10
+ var a = "\nstruct Frame {camera:mat4x4f,eye:vec4f,light:vec4f,radiance:vec4f,ambient:vec4f}\n@group(0) @binding(0) var<uniform> frame:Frame;\nstruct Input {@location(0) position:vec3f,@location(1) normal:vec3f,@location(2) m0:vec4f,@location(3) m1:vec4f,@location(4) m2:vec4f,@location(5) m3:vec4f,@location(6) color:vec4f,@location(7) factors:vec4f}\nstruct Output {@builtin(position) @invariant clip:vec4f,@location(0) @interpolate(flat) id:u32}\n@vertex fn vertex(i:Input)->Output {let model=mat4x4f(i.m0,i.m1,i.m2,i.m3);let p=model*vec4f(i.position,1);return Output(frame.camera*p,u32(i.factors.w));}\n", o = class o {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
11
11
  get maxOutline() {
12
12
  return 10;
13
13
  }
@@ -25,7 +25,7 @@ var a = "\nstruct Frame {camera:mat4x4f,eye:vec4f,light:vec4f,radiance:vec4f,amb
25
25
  if (this.name = "toon", this.format = "", this.disposed = !1, !Number.isFinite(e) || e < 0 || e > this.maxOutline || t.length !== 3 || t.some((e) => !Number.isFinite(e) || e < 0 || e > 1)) throw RangeError(`Toon outline must be between 0 and ${this.maxOutline} and color three channels between 0 and 1; pass finite values in range.`);
26
26
  this.shading = new r(n), this.values = new Float32Array([...t, e]);
27
27
  }
28
- static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
28
+ static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
29
29
  let r = new o(t);
30
30
  return n(e).use(r), r;
31
31
  }
package/package.json CHANGED
@@ -1,77 +1,77 @@
1
- {
2
- "name": "@margoengine/toon",
3
- "version": "0.1.0",
4
- "description": "Stepped diffuse shading and inverted-hull outlines.",
5
- "keywords": [
6
- "margoengine",
7
- "webgpu",
8
- "3d",
9
- "toon"
10
- ],
11
- "homepage": "https://margoengine.com",
12
- "bugs": {
13
- "url": "https://github.com/scottcampbelldata/margoengine/issues"
14
- },
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/scottcampbelldata/margoengine.git",
18
- "directory": "packages/toon"
19
- },
20
- "license": "Apache-2.0",
21
- "author": "Scott Campbell",
22
- "type": "module",
23
- "sideEffects": false,
24
- "exports": {
25
- ".": {
26
- "types": "./dist/index.d.ts",
27
- "import": "./dist/index.js"
28
- },
29
- "./models": {
30
- "types": "./dist/models.d.ts",
31
- "import": "./dist/models.js"
32
- },
33
- "./screen-outline": {
34
- "types": "./dist/screen-outline.d.ts",
35
- "import": "./dist/screen-outline.js"
36
- },
37
- "./hatch-models": {
38
- "types": "./dist/hatch-models.d.ts",
39
- "import": "./dist/hatch-models.js"
40
- },
41
- "./hatch": {
42
- "types": "./dist/hatch.d.ts",
43
- "import": "./dist/hatch.js"
44
- },
45
- "./outline": {
46
- "types": "./dist/outline.d.ts",
47
- "import": "./dist/outline.js"
48
- }
49
- },
50
- "files": [
51
- "dist",
52
- "LICENSE",
53
- "NOTICE"
54
- ],
55
- "publishConfig": {
56
- "access": "public"
57
- },
58
- "dependencies": {
59
- "@margoengine/creative": "^0.1.0",
60
- "@margoengine/math": "^0.1.0"
61
- },
62
- "peerDependencies": {
63
- "@margoengine/core": "^0.1.0",
64
- "@margoengine/gltf": "^0.1.0"
65
- },
66
- "peerDependenciesMeta": {
67
- "@margoengine/gltf": {
68
- "optional": true
69
- }
70
- },
71
- "scripts": {
72
- "build": "node ../../scripts/build-optional.js toon",
73
- "test": "npm run build && node --test test/*.test.js",
74
- "prepack": "npm run build",
75
- "test:gpu": "cd ../.. && node packages/toon/test/models-check.mjs && node packages/toon/test/hatch-check.mjs && node packages/toon/test/screen-outline.browser.mjs && node packages/toon/test/hatch-models.browser.mjs && node packages/toon/test/outline.browser.mjs"
76
- }
77
- }
1
+ {
2
+ "name": "@margoengine/toon",
3
+ "version": "1.0.0",
4
+ "description": "Stepped diffuse shading and inverted-hull outlines.",
5
+ "keywords": [
6
+ "margoengine",
7
+ "webgpu",
8
+ "3d",
9
+ "toon"
10
+ ],
11
+ "homepage": "https://margoengine.com",
12
+ "bugs": {
13
+ "url": "https://github.com/scottcampbelldata/margoengine/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/scottcampbelldata/margoengine.git",
18
+ "directory": "packages/toon"
19
+ },
20
+ "license": "Apache-2.0",
21
+ "author": "Scott Campbell",
22
+ "type": "module",
23
+ "sideEffects": false,
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./models": {
30
+ "types": "./dist/models.d.ts",
31
+ "import": "./dist/models.js"
32
+ },
33
+ "./screen-outline": {
34
+ "types": "./dist/screen-outline.d.ts",
35
+ "import": "./dist/screen-outline.js"
36
+ },
37
+ "./hatch-models": {
38
+ "types": "./dist/hatch-models.d.ts",
39
+ "import": "./dist/hatch-models.js"
40
+ },
41
+ "./hatch": {
42
+ "types": "./dist/hatch.d.ts",
43
+ "import": "./dist/hatch.js"
44
+ },
45
+ "./outline": {
46
+ "types": "./dist/outline.d.ts",
47
+ "import": "./dist/outline.js"
48
+ }
49
+ },
50
+ "files": [
51
+ "dist",
52
+ "LICENSE",
53
+ "NOTICE"
54
+ ],
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "dependencies": {
59
+ "@margoengine/creative": "^1.0.0",
60
+ "@margoengine/math": "^1.0.0"
61
+ },
62
+ "peerDependencies": {
63
+ "@margoengine/core": "^1.0.0",
64
+ "@margoengine/gltf": "^1.0.0"
65
+ },
66
+ "peerDependenciesMeta": {
67
+ "@margoengine/gltf": {
68
+ "optional": true
69
+ }
70
+ },
71
+ "scripts": {
72
+ "build": "node ../../scripts/build-optional.js toon",
73
+ "test": "npm run build && node --test test/*.test.js",
74
+ "prepack": "npm run build",
75
+ "test:gpu": "cd ../.. && node packages/toon/test/models-check.mjs && node packages/toon/test/hatch-check.mjs && node packages/toon/test/screen-outline.browser.mjs && node packages/toon/test/hatch-models.browser.mjs && node packages/toon/test/outline.browser.mjs"
76
+ }
77
+ }