The asset type "vector art" exists as a model, which is stage 1 of #129 and shows nothing in the browser yet on purpose: a vectorart asset is not placeable, sits in the + menu and in the asset panel with its own icon (a curve between two points) and has no tab, so it behaves like a font - selectable, its rows in the inspector, a double click leading nowhere - because the tab is stage 3 and half an asset would only be in the way; the data model in Asset.ts is a shape built from rings (even-odd, so a shape may have holes, answer 6 in the issue), a ring being points with optional bezier handles in/out stored as an offset from the point and a closed flag (an open path is stroke only, answer 4), plus fill colour, opacity and an optional stroke (answer 5) - the two handles are kept apart instead of mirrored, because what "smooth" means is the editor's business and not the model's; canvas width, height and the filter are properties, so they get an inspector row and undo like any other, while the shapes are intrinsic data like the frames of a texture; the revision that #185 hands to the picture path is a fingerprint of what is drawn, not a counter, which is exactly why that key took a string token - no command can forget to bump it - and the name of a shape is deliberately left out of it, renaming changing no pixel; six undo commands in the new vectorArtCommands.ts (add a shape numbered in order, remove one which comes back to its old place - unlike a tilemap layer the last one may go too -, rename, move, write the rings as one step per gesture with the list copied, and set the style where stroke: null takes it away) and the pure function shapeOrderTarget for the four buttons of the planned inspector list (one forward, to front, one back, to back), which also serves dragging in that list; loading from a project file is strict - a point without numbers falls away, a broken handle leaves a corner behind, duplicate shape ids fall away like duplicate layer ids, a stroke of width 0 is no stroke - while a ring with a single point, which is what someone is drawing right now, stays; three findings on the way: JSON.stringify as the fingerprint was wrong because the same drawing came back from a project file as {points, closed} and was built as {closed, points}, so a reload would have rasterized the same picture under a new key (the fingerprint writes its fields in a fixed order now and a test measures that case), toNumber in serialize.ts turns any nonsense into 0 so the Number.isFinite checks ran into nothing and {x: 'far'} became the left edge instead of vanishing (shapes read numbers strictly via asFinite, 0 being a place on the canvas here), and "Vector art" would have been both a menu entry and the panel heading, which an existing test catches because a click by text would hit the heading - the group is called "Vector drawings" now while the menu entry stays "Vector art"; 20 new unit tests in tests/core/vectorart.test.ts and three counter-checks hold: the fingerprint back on JSON.stringify fails 2, reading the numbers loosely again fails 4, and not copying the ring list fails 1; no e2e check and the check sum stays 1157, only module 04 counting 19 asset types instead of 18 (#129)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb1804dcf2
commit
bdb3f066cf
13 files changed
+975
-3
No files matched your search
@@ -235,6 +235,60 @@ export interface TilemapAsset extends AssetBase {
|
||||
layers: TilemapLayer[];
|
||||
}
|
||||
|
||||
/**
|
||||
* A point of a ring. `in` and `out` are the Bezier handles, as an offset from the point itself, so
|
||||
* a point may be dragged without touching them; absent is a corner, and the edge to that side is
|
||||
* straight. They are kept apart rather than mirrored, because a point may bend differently on each
|
||||
* side – what "smooth" means is the editor's business, not the model's (#129).
|
||||
*/
|
||||
export interface VectorPoint {
|
||||
x: number;
|
||||
y: number;
|
||||
in?: Vec2;
|
||||
out?: Vec2;
|
||||
}
|
||||
|
||||
/**
|
||||
* One outline of a shape, in canvas pixels from the canvas's top-left corner. A shape holds several
|
||||
* of them so it can have holes: the rings are filled even-odd, so a ring inside another cuts it out
|
||||
* (#129, answer 6). `closed` false is an open path – it is stroked and not filled.
|
||||
*/
|
||||
export interface VectorRing {
|
||||
points: VectorPoint[];
|
||||
closed: boolean;
|
||||
}
|
||||
|
||||
/** The outline drawn along a ring; `width` is in canvas pixels. Absent on a shape is no outline. */
|
||||
export interface VectorStroke {
|
||||
color: number;
|
||||
width: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* One filled figure. `fill` is a solid colour and `opacity` scales it – gradients and a texture
|
||||
* fill are #186, boolean operations between shapes are #187. The list order is the drawing order:
|
||||
* the last shape of the asset lies on top, as the last layer of a tilemap does.
|
||||
*/
|
||||
export interface VectorShape {
|
||||
id: string;
|
||||
name: string;
|
||||
rings: VectorRing[];
|
||||
fill: number;
|
||||
opacity: number;
|
||||
stroke?: VectorStroke;
|
||||
}
|
||||
|
||||
/**
|
||||
* A picture drawn from curves instead of uploaded (#129). It is rasterised onto a canvas whose size
|
||||
* is a property, and handed to the picture path through the generated-picture key of #185 – so a
|
||||
* sprite, a tile, a tilemap and a particle source wear it exactly as they wear a texture, and the
|
||||
* shapes never leave this asset. The shapes are intrinsic data, as a texture's frames are.
|
||||
*/
|
||||
export interface VectorArtAsset extends AssetBase {
|
||||
type: 'vectorart';
|
||||
shapes: VectorShape[];
|
||||
}
|
||||
|
||||
/**
|
||||
* The graph is the motion of one particle: every output of its `Output` node is a function of the
|
||||
* particle's age and its own random number (see `core/particles/compile.ts`). A placed object is
|
||||
@@ -256,6 +310,7 @@ export type Asset =
|
||||
| RigidbodyAsset
|
||||
| ContainerAsset
|
||||
| TextureAsset
|
||||
| VectorArtAsset
|
||||
| AnimationAsset
|
||||
| TileAsset
|
||||
| TilemapAsset
|
||||
|
||||
Reference in new issue
Block a user