spider-paint 26.11.24003 → 26.11.25002
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/MCP.md +8 -7
- package/api/version.mjs +12 -0
- package/bin/workshop.mjs +2 -1
- package/engine/{8fa668821759 → 45789c908f86}/edit.js +11 -6
- package/engine/{8fa668821759 → 45789c908f86}/index.js +1 -1
- package/engine/{8fa668821759 → 45789c908f86}/mesh.js +7 -6
- package/engine/{8fa668821759 → 45789c908f86}/place.js +2 -2
- package/help.md +14 -13
- package/index.html +306 -201
- package/mcp/build-info.js +1 -0
- package/mcp/engine/edit.js +11 -6
- package/mcp/engine/index.js +1 -1
- package/mcp/engine/mesh.js +7 -6
- package/mcp/engine/place.js +2 -2
- package/mcp/http.js +3 -3
- package/mcp/live.js +1 -1
- package/mcp/materials.js +24 -0
- package/mcp/package.json +2 -2
- package/mcp/scene.js +92 -20
- package/mcp/server.js +1 -1
- package/mcp/workshop-browser-model.js +1 -1
- package/mcp/workshop-tools.js +1 -1
- package/models/index.json +143 -23
- package/models/modular-characters/README.md +52 -0
- package/models/modular-characters/bodies.scene.json +1 -0
- package/models/modular-characters/bodies.svg +1015 -0
- package/models/modular-characters/cast.json +1 -0
- package/models/modular-characters/compose.mjs +140 -0
- package/models/modular-characters/designer.mjs +99 -0
- package/models/modular-characters/dockhand-front.svg +74 -0
- package/models/modular-characters/dockhand.scene.json +1 -0
- package/models/modular-characters/dockhand.svg +161 -0
- package/models/modular-characters/fat-resident-front.svg +72 -0
- package/models/modular-characters/fat-resident.scene.json +1 -0
- package/models/modular-characters/fat-resident.svg +152 -0
- package/models/modular-characters/fat-technician-front.svg +55 -0
- package/models/modular-characters/fat-technician.scene.json +1 -0
- package/models/modular-characters/fat-technician.svg +116 -0
- package/models/modular-characters/field-tech-front.svg +72 -0
- package/models/modular-characters/field-tech.scene.json +1 -0
- package/models/modular-characters/field-tech.svg +160 -0
- package/models/modular-characters/heads.scene.json +1 -0
- package/models/modular-characters/heads.svg +463 -0
- package/models/modular-characters/host-front.svg +66 -0
- package/models/modular-characters/host.scene.json +1 -0
- package/models/modular-characters/host.svg +133 -0
- package/models/modular-characters/index.html +88 -0
- package/models/modular-characters/library.json +1 -0
- package/models/modular-characters/lineup.scene.json +1 -0
- package/models/modular-characters/lineup.svg +3405 -0
- package/models/modular-characters/mechanic-front.svg +69 -0
- package/models/modular-characters/mechanic.scene.json +1 -0
- package/models/modular-characters/mechanic.svg +134 -0
- package/models/modular-characters/mission-lead-front.svg +63 -0
- package/models/modular-characters/mission-lead.scene.json +1 -0
- package/models/modular-characters/mission-lead.svg +128 -0
- package/models/modular-characters/navigator-front.svg +70 -0
- package/models/modular-characters/navigator.scene.json +1 -0
- package/models/modular-characters/navigator.svg +148 -0
- package/models/modular-characters/parts.scene.json +1 -0
- package/models/modular-characters/parts.svg +151 -0
- package/models/modular-characters/reference/group-color.png +0 -0
- package/models/modular-characters/reference/group-edges.png +0 -0
- package/models/modular-characters/reference/low-poly-boxy-method.png +0 -0
- package/models/modular-characters/reference/ultra-low-poly-suited-guy-with-glasses-3d-model_899449-177730.avif +0 -0
- package/models/modular-characters/researcher-front.svg +88 -0
- package/models/modular-characters/researcher.scene.json +1 -0
- package/models/modular-characters/researcher.svg +195 -0
- package/models/modular-characters/resident-front.svg +68 -0
- package/models/modular-characters/resident.scene.json +1 -0
- package/models/modular-characters/resident.svg +146 -0
- package/models/modular-characters/robot-loader-front.svg +61 -0
- package/models/modular-characters/robot-loader.scene.json +1 -0
- package/models/modular-characters/robot-loader.svg +154 -0
- package/models/modular-characters/robot-maintenance-front.svg +64 -0
- package/models/modular-characters/robot-maintenance.scene.json +1 -0
- package/models/modular-characters/robot-maintenance.svg +165 -0
- package/models/modular-characters/robot-scout-front.svg +62 -0
- package/models/modular-characters/robot-scout.scene.json +1 -0
- package/models/modular-characters/robot-scout.svg +159 -0
- package/models/modular-characters/robot-service-front.svg +58 -0
- package/models/modular-characters/robot-service.scene.json +1 -0
- package/models/modular-characters/robot-service.svg +147 -0
- package/models/modular-characters/robots.scene.json +1 -0
- package/models/modular-characters/robots.svg +1111 -0
- package/models/modular-characters/thin-resident-front.svg +71 -0
- package/models/modular-characters/thin-resident.scene.json +1 -0
- package/models/modular-characters/thin-resident.svg +150 -0
- package/models/modular-characters/thin-technician-front.svg +54 -0
- package/models/modular-characters/thin-technician.scene.json +1 -0
- package/models/modular-characters/thin-technician.svg +115 -0
- package/models/modular-characters/woman-commander-front.svg +60 -0
- package/models/modular-characters/woman-commander.scene.json +1 -0
- package/models/modular-characters/woman-commander.svg +118 -0
- package/models/modular-characters/woman-engineer-front.svg +77 -0
- package/models/modular-characters/woman-engineer.scene.json +1 -0
- package/models/modular-characters/woman-engineer.svg +172 -0
- package/models/modular-characters/woman-medic-front.svg +89 -0
- package/models/modular-characters/woman-medic.scene.json +1 -0
- package/models/modular-characters/woman-medic.svg +197 -0
- package/models/modular-characters/woman-resident-front.svg +64 -0
- package/models/modular-characters/woman-resident.scene.json +1 -0
- package/models/modular-characters/woman-resident.svg +130 -0
- package/models/modular-characters/women.scene.json +1 -0
- package/models/modular-characters/women.svg +1363 -0
- package/package.json +9 -4
- package/player.html +4 -4
- package/xr-compare.html +1 -1
- /package/engine/{8fa668821759 → 45789c908f86}/bevel.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/camera.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/character.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/check.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/csg.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/galaxy.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/gl.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/gpu.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/instances.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/joints.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/kernel-bytes.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/kernel.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/lathe.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/material.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/order.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/pick.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/planet.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/rig.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/saw.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/sky.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/svg.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/text.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/triangulate.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/types.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/vec.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/version.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/vrtsh.js +0 -0
- /package/engine/{8fa668821759 → 45789c908f86}/wire.js +0 -0
package/MCP.md
CHANGED
|
@@ -57,7 +57,7 @@ Every open viewer gets every change and every command. The viewers do not write
|
|
|
57
57
|
|
|
58
58
|
## How to work (for the AI)
|
|
59
59
|
|
|
60
|
-
1. **Model** with `add_box`, `add_extrusion`, `add_mesh
|
|
60
|
+
1. **Model** with `add_box`, `add_extrusion`, `add_mesh` (surfaces: `mat` names a palette material, so metal, glass and glow come with it; `color` is a plain colour; `material` makes new ones), then shape with `extrude_face`, `move_vertices`, `boolean`, `transform`, `recolor`. Feel the scene like the viewer's cursor with `sense` (through a pixel of a render: the first surface, everything behind it, the distances); leave objects out with `sensing` (or `exclude` for one call) to place behind or into them. Make mechanisms with `group` (objects that move as one) and `connect` (glue, pivot, hinge, rail, spring: the holder carries the held part, which moves only as the joint allows; `move_joint` turns or slides it inside its limits, `joints` reports their state). Put things on each other with `place_on` (the viewer's G G: the foot onto the surface straight down at [x, z], upright or turned to the surface) and figures in with `add_character`. Name objects after what they are (`seat`, `leg_fl`): every later tool finds them by name. Repeat things with `instance`: model one pine (or one needle ring, one rock), group it if it has parts, then place many copies in one step with `copies: [{ at, scale, rotate_y, color }]`; a uniform scale, no rotate_z and no `colors` keeps a copy compact (format v2 `prototypes`, as the viewer's stars).
|
|
61
61
|
2. **Look** after every few changes: `render` (an SVG sheet of four views by default; read it), `inspect` (closed, planar, convex, faces counter-clockwise from outside), `pick` (a pixel of a render -> object, face, 3D point, normal).
|
|
62
62
|
3. **Show** it: `viewer` gives the URL for the person. `view_target` aims the viewer at an object, `view_camera` places the eye, `view_state` tells you what the person sees.
|
|
63
63
|
4. **Keep** it: `export` (JSON text, or a `.json` file inside the server's working directory), `import`.
|
|
@@ -172,11 +172,11 @@ Enter: find a target by name. Tab: next target. W/S, A/D, R/F: speed forward, si
|
|
|
172
172
|
<!-- tools:start -->
|
|
173
173
|
| tool | arguments (bold: required) | what it does |
|
|
174
174
|
|---|---|---|
|
|
175
|
-
| `add_box` | **name**, size, at, color, replace | Add an axis-aligned box. `at` is the CENTER, so its bottom is at at[1] - size[1] / 2. Y is up, the ground is y = 0. Units are arbitrary but keep them consistent. |
|
|
176
|
-
| `add_extrusion` | **name**, **polygon**, **height**, y, color, replace | Add a prism: a CONVEX footprint polygon on the ground plane, given as [[x, z], ...] in any winding, extruded up by `height` from `y`. Use it for triangles, hexagons, wedges, roofs, columns. Concave shapes must be split into several convex extrusions. |
|
|
177
|
-
| `add_mesh` | **name**, **positions**, **faces**, color, replace | Add a raw mesh: `positions` [[x,y,z],...] and `faces` [{ v: [indices], color }]. Each face must be planar, convex and listed COUNTER-CLOCKWISE seen from outside (right-hand rule: the normal points out). Run inspect afterwards. |
|
|
175
|
+
| `add_box` | **name**, size, at, mat, color, replace | Add an axis-aligned box. `at` is the CENTER, so its bottom is at at[1] - size[1] / 2. Y is up, the ground is y = 0. Units are arbitrary but keep them consistent. |
|
|
176
|
+
| `add_extrusion` | **name**, **polygon**, **height**, y, mat, color, replace | Add a prism: a CONVEX footprint polygon on the ground plane, given as [[x, z], ...] in any winding, extruded up by `height` from `y`. Use it for triangles, hexagons, wedges, roofs, columns. Concave shapes must be split into several convex extrusions. |
|
|
177
|
+
| `add_mesh` | **name**, **positions**, **faces**, mat, color, replace | Add a raw mesh: `positions` [[x,y,z],...] and `faces` [{ v: [indices], color }]. Each face must be planar, convex and listed COUNTER-CLOCKWISE seen from outside (right-hand rule: the normal points out). Run inspect afterwards. |
|
|
178
178
|
| `transform` | **name**, scale, rotate_x, rotate_z, rotate_y, pivot, move | Scale, then rotate round X, then round Z, then round Y, then move an object. Scale and rotations are about the center of its bounding box (or about `pivot`). Rotations are degrees, counter-clockwise looking from the + end of the axis towards the origin (right-hand rule): rotate_y 90 turns +x into -z, rotate_x 90 turns +y into +z, rotate_z 90 turns +x into +y. |
|
|
179
|
-
| `instance` | **name**, **source**, at, scale, rotate_x, rotate_y, rotate_z, color, colors, copies, replace | Copies of an object or group (`source`, the prototype as it is now), each placed by its foot at `at`, scaled and turned about the foot (as transform), with `color` (all faces) or `colors` ({ "#old": "#new" }). `copies` places many in one step; unnamed ones are <name>-1, <name>-2…; a group source makes <copy>.<member> objects grouped as <copy>. Copies with a uniform scale, no rotate_z and no `colors` are exported compactly (`export` with compact: true, and every `open_url`): scene format v2 `prototypes` + `{ name, proto, at, scale, rot, color }`, the same records the viewer uses for stars. Editing a copy later makes it a plain mesh again. |
|
|
179
|
+
| `instance` | **name**, **source**, at, scale, rotate_x, rotate_y, rotate_z, mat, mats, color, colors, copies, replace | Copies of an object or group (`source`, the prototype as it is now), each placed by its foot at `at`, scaled and turned about the foot (as transform), with `color` (all faces) or `colors` ({ "#old": "#new" }). `copies` places many in one step; unnamed ones are <name>-1, <name>-2…; a group source makes <copy>.<member> objects grouped as <copy>. Copies with a uniform scale, no rotate_z and no `colors` are exported compactly (`export` with compact: true, and every `open_url`): scene format v2 `prototypes` + `{ name, proto, at, scale, rot, color }`, the same records the viewer uses for stars. Editing a copy later makes it a plain mesh again. |
|
|
180
180
|
| `place_on` | **name**, onto, at, point, normal, from, dir, x, y, view, yaw, pitch, size, exclude, include, align, turn, gap | Put an object down on the surface of others, like the viewer's G G: its foot (the middle of the bottom of its bounding box; for a character the middle of where it stands) goes onto the surface point, and with align "normal" its up turns to the surface normal (a thing on a slope, a ball, a wall). Say where with `at` [x, z] (dropped straight down there: the highest surface under that spot), or a pixel `x`, `y` of a render (the ray from the camera, like the viewer's cursor; view / yaw / pitch / size as render), or `point` (+ `normal`) from sense / pick, or a ray (`from` + `dir`). Default: straight down at the object's own x, z. It lands on the sensing set (see sensing) without itself, or on `onto`; exclude / include change the set for this call (exclude a wall to place behind it). Returns the new bounds and the surface it landed on with its distance along the ray. |
|
|
181
181
|
| `add_character` | **name**, preset, seed, spec, pose, at, yaw, onto, replace | Add a character from the viewer's character builder: a stylized figure (about 1.6-1.9 tall, the units are metres) in a few meshes merged into one object, its feet on y = 0 at `at`, facing `yaw`. Presets: scientist, mechanic, crew (Space 1999 style uniform), astronaut. `seed` makes a random variation of the preset, `spec` overrides any field of the builder's spec (base: "male" \| "female", body: { height, build, shoulders, head }, face: { shape, skin }, hair: { style, mat }, outfit: { kind, main, second, helmet }, prop). Pose: stand, sit (the seat under the hips at about 0.44) or walk (one stride). Give `onto` (and `at`) to stand it on a surface, as place_on. |
|
|
182
182
|
| `sense` | view, yaw, pitch, size, x, y, from, dir, exclude, include, limit | Feel the scene along a ray, as the viewer's cursor does from the camera: through pixel (x, y) of a render (same view and size as render), or from `from` along `dir`. Returns the first surface (object, face, point, normal, distance from the eye or `from`) and `hits`: everything along the ray, nearest first, with `outside` true where the ray enters an object and false where it leaves it, so you can see what is behind and how thick it is. Only the sensing set counts (see sensing); exclude / include change it for this call. Use the point and normal with place_on (point + normal), or give place_on the same pixel. |
|
|
@@ -188,10 +188,11 @@ Enter: find a target by name. Tab: next target. W/S, A/D, R/F: speed forward, si
|
|
|
188
188
|
| `joints` | – | The joints and groups now: each joint's kind, holder (a), held part (b), its limits and its state (a hinge's angle, a pivot's angles, a rail's position, a spring's length) with its geometry in world coordinates. |
|
|
189
189
|
| `move_joint` | **name**, angle, angles, position | Move a held part as its joint allows, kept inside the limits: a hinge to `angle` (degrees from the pose it was connected in), a pivot to `angles` [x, y, z] (degrees round the world axes), a rail to `position` (distance along the rail). What b holds moves along. Returns the state reached (clamped). |
|
|
190
190
|
| `get_mesh` | **name** | Read an object's geometry so you can shape it: the vertices (index = position in the list) and the faces with their vertex indices, color, center and outward normal. Use it to find the face or vertex indices for extrude_face and move_vertices. |
|
|
191
|
-
| `extrude_face` | **name**, **face**, distance, scale, color | Shape an object by pushing one of its faces out, like a modeller. The face is replaced (same index) by a copy moved `distance` along its outward normal and scaled by `scale` about its center, joined to the old edges by new side faces. distance > 0 and scale 1: a prism grows out (a wing, a chimney, a step). distance > 0 and scale < 1: a taper (roof, tower top, frustum). distance 0 and scale < 1: an inset (a panel or window frame; extrude it again, negative, for a recess). distance < 0: a dent into the solid (a niche, a door recess). The result is a closed solid again; chain calls on the returned `cap` face. |
|
|
191
|
+
| `extrude_face` | **name**, **face**, distance, scale, mat, color | Shape an object by pushing one of its faces out, like a modeller. The face is replaced (same index) by a copy moved `distance` along its outward normal and scaled by `scale` about its center, joined to the old edges by new side faces. distance > 0 and scale 1: a prism grows out (a wing, a chimney, a step). distance > 0 and scale < 1: a taper (roof, tower top, frustum). distance 0 and scale < 1: an inset (a panel or window frame; extrude it again, negative, for a recess). distance < 0: a dent into the solid (a niche, a door recess). The result is a closed solid again; chain calls on the returned `cap` face. |
|
|
192
192
|
| `move_vertices` | **name**, **indices**, **by** | Move the vertices with the given indices by [dx, dy, dz] (see get_mesh for the indices): shear, lean, pinch a roof ridge, raise a corner. Faces keep their vertices, so moving only some corners of a face can make it non-planar; the result reports that. Move all the corners of a face together to keep it flat. |
|
|
193
193
|
| `boolean` | **a**, **b**, **op**, name, keep | Boolean of two closed solids: union, subtract (a minus b: a door, a window, a hole) or intersect. Both objects must be closed solids with outward faces (inspect says so). The result is a new closed solid; faces keep their colors and a face cut into a solid takes the color of the cutting face. By default a and b are replaced by the result; `keep: true` keeps them. |
|
|
194
|
-
| `recolor` | **name**,
|
|
194
|
+
| `recolor` | **name**, mat, color, face | Change the material (`mat`) or the plain color of a whole object, or of one face when `face` is given. |
|
|
195
|
+
| `material` | **name**, like, color, metal, rough, alpha, emit, soft | Make or change a palette material (alpha below 1: glass; emit: glow; soft: skin-like light); every face made of it changes. Built in: plaster, sand, wood, dark-wood, concrete, slate, grass, brick, steel, gold, glass, copper, ruby-glass, lacquer-blue, lamp (the viewer's starting palette, mcp/materials.js). With only a name it returns that material. |
|
|
195
196
|
| `set_screen` | **name**, face, image, scene, url, material, color | Make faces of an object a screen in the viewer: give exactly one of `image` (a picture, .png .jpg .jpeg .webp .gif .avif .svg: laid on the face as a texture, cut to the face's shape, depth tested and seen in VR too; its server must allow cross-origin reading (CORS), else the desktop shows it as a page), `scene` (a 3Draft scene file .3draft / .json, played on the face turning round its middle) or `url` (a web page, shown in an iframe over the face on the desktop; not in VR, sites that forbid framing stay blank). Only four-cornered faces show it; seen from the front (the side the face's CCW winding faces). Without `face` every four-cornered face of the object becomes the screen (a box: all six sides), so for one side give its face index (get_mesh). The screen is a material (`material`, default "screen-<object>") kept in the scene's palette (export / import keep it); give none of image / scene / url to make the faces plain again. |
|
|
196
197
|
| `remove` | **name** | Remove one object. |
|
|
197
198
|
| `clear` | – | Remove every object. |
|
package/api/version.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// /api/version on a Vercel deployment (Cloud Run and the local server answer it themselves): the deployed package.json
|
|
2
|
+
// version and the commit, read by the app's header.
|
|
3
|
+
import { buildInfo } from '../mcp/build-info.js';
|
|
4
|
+
|
|
5
|
+
const body = JSON.stringify(buildInfo);
|
|
6
|
+
export default function handler(req, res) {
|
|
7
|
+
res.statusCode = 200;
|
|
8
|
+
res.setHeader('content-type', 'application/json; charset=utf-8');
|
|
9
|
+
res.setHeader('cache-control', 'no-store');
|
|
10
|
+
res.setHeader('access-control-allow-origin', '*');
|
|
11
|
+
res.end(req.method === 'HEAD' ? '' : body);
|
|
12
|
+
}
|
package/bin/workshop.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { readFile } from 'node:fs/promises';
|
|
|
6
6
|
import { extname, resolve, dirname, sep } from 'node:path';
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
import { createScene } from '../mcp/scene.js';
|
|
9
|
+
import { buildInfo } from '../mcp/build-info.js';
|
|
9
10
|
|
|
10
11
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
11
12
|
const scene = createScene();
|
|
@@ -53,7 +54,7 @@ const toolCall = (name, args) => callWorkshop(name, args);
|
|
|
53
54
|
const mcp = (req) => {
|
|
54
55
|
const { id, method, params = {} } = req;
|
|
55
56
|
const wrap = (result) => ({ jsonrpc: '2.0', id, result });
|
|
56
|
-
if (method === 'initialize') return wrap({ protocolVersion:protocol, capabilities:{ tools:{} }, serverInfo:{name:'spider-paint-workshop',version:
|
|
57
|
+
if (method === 'initialize') return wrap({ protocolVersion:protocol, capabilities:{ tools:{} }, serverInfo:{name:'spider-paint-workshop',version:buildInfo.version}, instructions:'Local shared Workshop: MCP and browser edit one scene. Visit /workshop.html.' });
|
|
57
58
|
if (method === 'ping') return wrap({});
|
|
58
59
|
if (method === 'tools/list') return wrap({ tools:[...scene.list(),...taskTools] });
|
|
59
60
|
if (method === 'tools/call') {
|
|
@@ -9,11 +9,11 @@ import { faceNormal, faceCenter } from './mesh.js';
|
|
|
9
9
|
* distance > 0, scale < 1 a taper (roof, spire, frustum)
|
|
10
10
|
* distance 0, scale < 1 an inset (a panel, a window frame)
|
|
11
11
|
* distance < 0 a dent into the solid (a niche, a door recess)
|
|
12
|
-
* The new quads are appended after the existing faces
|
|
13
|
-
*
|
|
12
|
+
* The new quads are appended after the existing faces. Their surface (and the cap's): `mat`, a palette material;
|
|
13
|
+
* else `color`, a plain colour (no material); else the face's own material and colour.
|
|
14
14
|
* Returns { mesh, cap, sides } with the index of the cap face and the new quad indices.
|
|
15
15
|
*/
|
|
16
|
-
export const extrudeFace = (mesh, index, { distance = 0, scale = 1, color } = {}) => {
|
|
16
|
+
export const extrudeFace = (mesh, index, { distance = 0, scale = 1, color, mat } = {}) => {
|
|
17
17
|
const face = mesh.faces[index];
|
|
18
18
|
if (!face)
|
|
19
19
|
throw new Error(`no face ${index}: this mesh has ${mesh.faces.length} faces`);
|
|
@@ -27,12 +27,17 @@ export const extrudeFace = (mesh, index, { distance = 0, scale = 1, color } = {}
|
|
|
27
27
|
const moved = pts.map((p) => add(add(c, mul(sub(p, c), scale)), mul(n, distance)));
|
|
28
28
|
const base = mesh.positions.length;
|
|
29
29
|
const m = pts.length;
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
// the surface of the cap and the new sides: `mat` (a palette material), else a plain `color` (no material), else the
|
|
31
|
+
// pushed face's own: its material and its colour, so an extruded wooden plank stays wood all round
|
|
32
|
+
const surface = mat !== undefined ? { color: color ?? face.color, mat }
|
|
33
|
+
: color !== undefined ? { color }
|
|
34
|
+
: { color: face.color, ...(face.mat !== undefined ? { mat: face.mat } : {}) };
|
|
35
|
+
const clean = (s) => Object.fromEntries(Object.entries(s).filter(([, x]) => x !== undefined));
|
|
36
|
+
const faces = mesh.faces.map((f, i) => (i === index ? { v: moved.map((_, j) => base + j), ...clean(surface) } : f));
|
|
32
37
|
const sides = [];
|
|
33
38
|
for (let i = 0; i < m; i++) {
|
|
34
39
|
sides.push(faces.length);
|
|
35
|
-
faces.push({ v: [face.v[i], face.v[(i + 1) % m], base + ((i + 1) % m), base + i],
|
|
40
|
+
faces.push({ v: [face.v[i], face.v[(i + 1) % m], base + ((i + 1) % m), base + i], ...clean(surface) });
|
|
36
41
|
}
|
|
37
42
|
return { mesh: { positions: [...mesh.positions, ...moved], faces }, cap: index, sides };
|
|
38
43
|
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// a target cross that lies on the surface under the cursor. No textures, no
|
|
5
5
|
// shading yet.
|
|
6
6
|
export const name = '3draft';
|
|
7
|
-
export const version = '26.11.
|
|
7
|
+
export const version = '26.11.24001';
|
|
8
8
|
export { box, extrude, merge, rotate, bounds, faceNormal, faceCenter } from './mesh.js';
|
|
9
9
|
export { validate } from './check.js';
|
|
10
10
|
export { boolean, union, subtract, intersect, health, splitParts } from './csg.js';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Faces are CCW when seen from outside. No normals, UVs or textures yet.
|
|
3
3
|
import { add, len, scale, sub } from './vec.js';
|
|
4
4
|
/** Box: 8 points, 12 edges, 6 quad faces. Axis-aligned unless `axes` turns it. */
|
|
5
|
-
export const box = ({ size = [1, 1, 1], at = [0, 0, 0], color = '#c8c8c8', axes } = {}) => {
|
|
5
|
+
export const box = ({ size = [1, 1, 1], at = [0, 0, 0], color = '#c8c8c8', mat, axes } = {}) => {
|
|
6
6
|
const [hx, hy, hz] = size.map((s) => s / 2);
|
|
7
7
|
// `axes` = [ex, ey, ez], an orthonormal right-handed frame (default: x, y, z)
|
|
8
8
|
const [ex, ey, ez] = axes ?? [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
|
|
@@ -24,7 +24,7 @@ export const box = ({ size = [1, 1, 1], at = [0, 0, 0], color = '#c8c8c8', axes
|
|
|
24
24
|
[0, 4, 7, 3], // -x
|
|
25
25
|
[3, 7, 6, 2], // +y
|
|
26
26
|
[0, 1, 5, 4], // -y
|
|
27
|
-
].map((v) => ({ v, color }));
|
|
27
|
+
].map((v) => ({ v, color, ...(mat !== undefined ? { mat } : {}) }));
|
|
28
28
|
return { positions, faces };
|
|
29
29
|
};
|
|
30
30
|
/** Concatenate meshes into one, re-indexing the faces. */
|
|
@@ -101,7 +101,7 @@ export const faceCenter = (pts) => {
|
|
|
101
101
|
* winding), it is extruded up from `y` by `height`. Faces: top, bottom, then one
|
|
102
102
|
* quad per footprint edge, all CCW from outside.
|
|
103
103
|
*/
|
|
104
|
-
export const extrude = ({ polygon, height = 1, y = 0, color = '#c8c8c8' }) => {
|
|
104
|
+
export const extrude = ({ polygon, height = 1, y = 0, color = '#c8c8c8', mat }) => {
|
|
105
105
|
if (!Array.isArray(polygon) || polygon.length < 3)
|
|
106
106
|
throw new Error('polygon needs at least 3 [x, z] points');
|
|
107
107
|
if (!(height > 0))
|
|
@@ -122,10 +122,11 @@ export const extrude = ({ polygon, height = 1, y = 0, color = '#c8c8c8' }) => {
|
|
|
122
122
|
}
|
|
123
123
|
const positions = [...pts.map(([x, z]) => [x, y, z]), ...pts.map(([x, z]) => [x, y + height, z])];
|
|
124
124
|
const ring = [...Array(n).keys()];
|
|
125
|
+
const surface = { color, ...(mat !== undefined ? { mat } : {}) }; // (a palette material, the colour its fallback)
|
|
125
126
|
const faces = [
|
|
126
|
-
{ v: ring.map((i) => n + i),
|
|
127
|
-
{ v: [...ring].reverse(),
|
|
128
|
-
...ring.map((i) => ({ v: [i, (i + 1) % n, n + ((i + 1) % n), n + i],
|
|
127
|
+
{ v: ring.map((i) => n + i), ...surface },
|
|
128
|
+
{ v: [...ring].reverse(), ...surface },
|
|
129
|
+
...ring.map((i) => ({ v: [i, (i + 1) % n, n + ((i + 1) % n), n + i], ...surface })),
|
|
129
130
|
];
|
|
130
131
|
return { positions, faces };
|
|
131
132
|
};
|
|
@@ -7,11 +7,11 @@ import { box } from './mesh.js';
|
|
|
7
7
|
* line up with the first edge of the face. The height is `3 * base` unless given.
|
|
8
8
|
* Returns a new mesh; merge() it into the scene.
|
|
9
9
|
*/
|
|
10
|
-
export const standOn = (mesh, hit, { base = 0.15, height = 3 * base, color = '#c8c8c8' } = {}) => {
|
|
10
|
+
export const standOn = (mesh, hit, { base = 0.15, height = 3 * base, color = '#c8c8c8', mat } = {}) => {
|
|
11
11
|
const [a, b] = mesh.faces[hit.face].v;
|
|
12
12
|
const ex = norm(minus(mesh.positions[a])(mesh.positions[b]));
|
|
13
13
|
const ey = hit.normal;
|
|
14
14
|
const ez = cross(ex, ey);
|
|
15
15
|
const frame = { size: [base, height, base], at: plus(hit.point)(times(height / 2)(ey)), axes: [ex, ey, ez] };
|
|
16
|
-
return { ...box({ ...frame, color }), frame }; // frame: what an instanced renderer needs
|
|
16
|
+
return { ...box({ ...frame, color, mat }), frame }; // frame: what an instanced renderer needs
|
|
17
17
|
};
|
package/help.md
CHANGED
|
@@ -140,19 +140,20 @@ A game brings scenes together: **Fifth Percent** (the scene list, *games*, or `?
|
|
|
140
140
|
|
|
141
141
|
## Characters (the char button)
|
|
142
142
|
|
|
143
|
-
**char** (scene group) opens the **character
|
|
144
|
-
|
|
145
|
-
- **
|
|
146
|
-
- **
|
|
147
|
-
- **
|
|
148
|
-
-
|
|
149
|
-
- **
|
|
150
|
-
- **
|
|
151
|
-
- **
|
|
152
|
-
- **
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
143
|
+
**char** (scene group) opens the **character panel**: modular low-poly humans and robots, built from interchangeable modules (models/modular-characters/). The figure at the top turns with a drag; every change shows at once.
|
|
144
|
+
|
|
145
|
+
- **The ready ones**: 20 characters (dockhand, navigator, researcher, medic, commander, thin and fat builds… and four robots: scout, dock loader, service unit, repair unit). A click puts one in the panel.
|
|
146
|
+
- **random**: every part and colour at random (a human stays human, a robot robot).
|
|
147
|
+
- **figure**: body (straight, tapered, sturdy, slender, curved, thin, fat, three robot frames), head, face. **hair**: style, colour, an extra (glasses, headset, beard, visor). **clothes**: top, bottom, shoes and the outfit's colours. **skin**.
|
|
148
|
+
- Faces, hair and extras are fitted to every head, clothes to every body, so any combination fits. The materials (mc-…) come into the palette; edit one there and every character made of it changes.
|
|
149
|
+
- **save** keeps the selection under a name in this browser; the list next to it opens it again.
|
|
150
|
+
- **place**: in an empty scene the character stands at the origin (0, 0, 0), facing you. Otherwise it floats under the pointer in place mode (as **G G**): a click stands it on the surface under the pointer, **Enter** keeps it, **Esc** takes it away. One **U** takes it back.
|
|
151
|
+
- **edit selected** takes the character under the cross (or the target) back into the panel; **apply** rebuilds only that one, where it stands (one U step).
|
|
152
|
+
- **designer ↗** opens the designer page: every module side by side, the line-up, the face and exploded views.
|
|
153
|
+
|
|
154
|
+
A placed character can be **posed** like any figure: put the cross on it (or target it, T) and press **J**; **1–5** the ready poses (rest, T, wave, sit, phone), **6** walk, **7** run, **Enter** keeps the pose, **J** or **Esc** leaves it. Its skeleton comes from the library (every body has its own, robots too) and each module follows its bone, so the boxes bend at the joints; a turned character bends the same way. A kept pose makes the moved parts ordinary objects; **apply** in the panel stands it up again.
|
|
155
|
+
|
|
156
|
+
A placed character is a **group of instances**: one object per module (body, head, face, hair, top, bottom, shoes, extra), grouped under the character's name, each an instance of the library's prototype. So a crowd shares a few meshes. It moves with **G**, turns with **R** and sizes with **S** as one, and stays made of instances (a save writes the prototypes once and a short record per module); an edit of its mesh, or a tilt off upright, makes that part an ordinary object.
|
|
156
157
|
|
|
157
158
|
## Two views: build and store
|
|
158
159
|
|