diff --git a/surfaces/blender/docs/kitbash.md b/surfaces/blender/docs/kitbash.md index 4096be7..f82d7c3 100644 --- a/surfaces/blender/docs/kitbash.md +++ b/surfaces/blender/docs/kitbash.md @@ -25,8 +25,10 @@ Who owns what: included: a part's size is its params, and a socket's frame is a rotation and an origin. Set scale to 1 and resize with `set_params`. - A connection between two parts belongs to the child: its parent pointer and its `kit_socket`, - `kit_parent_socket` and `kit_roll` properties. Where the child stands is derived from them - ("Assembling parts"). + `kit_parent_socket` and `kit_roll` properties, and its joint record (`kit_slide`, `kit_min`, `kit_max`, + `kit_mechanism`, `kit_compliance`). Where the child stands is derived from them ("Assembling parts"). The + joint's kind belongs to the kit's socket type and its axis to the parent socket's frame: neither is stored on + the connection. - A closure, the joint that closes a loop, belongs to the closing part: its `kit_close_socket`, `kit_close_to` and `kit_close_to_socket` properties. Only `close` writes them and only `detach` clears them. A closure places nothing: whether it holds is derived at each report. @@ -149,7 +151,8 @@ well under the part's thinnest feature at its smallest params. **Sockets** are frames. `at` is the origin; `z` is the outward normal (a mating socket faces it), `y` is up (the roll reference), and x is y cross z; each is one of `+x -x +y -y +z -z` in the part's frame, on different axes. `size` is a diameter in metres. `type` names one of the kit's `socketTypes`, whose `match` says how sizes are to -be compared when sockets are mated: `equal` (within 1 percent) or `fits` (the child at most the parent). A socket +be compared when sockets are mated: `equal` (within 1 percent) or `fits` (the child at most the parent), and +whose optional `dof` (`revolute` or `prismatic`; absent is rigid) says how a child seated on such a socket moves. A socket sits on a flat face of the part whose normal is its `z`; `test_kitbash` checks this for every part of a shipped kit at its default, smallest and largest params and at seeded draws between. @@ -162,20 +165,75 @@ angle: at 0 the two parts line up, side by side. A pin carries a socket on each **A connection** seats one socket of a child part on one socket of a parent part: the two origins together, the two normals opposed, and the child turned `roll` degrees about the parent socket's normal (right-handed; at 0 the -two sockets' up axes line up). The child owns it. It is the child's parent pointer, under an identity parent -inverse, and three ID properties on the child: `kit_socket` (its own socket), `kit_parent_socket` and `kit_roll`. -Nothing else stores it: no parent name, no world matrix, no empties. The child's `matrix_basis` is derived, +two sockets' up axes line up). On a prismatic socket the child also stands `slide` metres along that normal. The +child owns it. It is the child's parent pointer, under an identity parent inverse, and three ID properties on the +child: `kit_socket` (its own socket), `kit_parent_socket` and `kit_roll`, with its joint record ("Joint records", +below). Nothing else stores it: no parent name, no world matrix, no empties. The child's `matrix_basis` is +derived, ```text -matrix_basis = S_parent @ Rz(roll) @ FLIP @ inverse(S_child) FLIP = half a turn about y +matrix_basis = S_parent @ T(0, 0, slide) @ Rz(roll) @ FLIP @ inverse(S_child) FLIP = half a turn about y ``` -with `S` each socket's frame in its own part at that part's stored params (`core.mate`). `attach`, `set_params`, -`roll`, `aim` and `reach` write it; nothing else should. +with `S` each socket's frame in its own part at that part's stored params (`core.mate`); a turn about z and a move +along it commute, so one connection carries both. `attach`, `set_params`, `roll`, `aim`, `reach`, `slide` and +`joint` write it; nothing else should. + +**Joint records.** A connection's degree of freedom is its parent socket's type's: a socket type states +`"dof": "revolute"` (the child turns about the socket's z: `pivot`), `"dof": "prismatic"` (it slides along it: +`slide`) or nothing, and is then rigid (`flange`, `mount`, `hose`). No part, socket or object name decides it. A +revolute joint's value is its `kit_roll`, in degrees; a prismatic joint's is its `kit_slide`, in metres, and its +roll is a build angle. Beside the value the child's connection carries a record: + +| Property | States | Stated by | +| --- | --- | --- | +| `kit_slide` | metres along the parent socket's z; prismatic only, 0 where the two origins meet | `slide` | +| `kit_min`, `kit_max` | the limits of the value, both or neither: degrees on a revolute joint (a span of at most 360, each end within 360 of 0), metres on a prismatic one (each end within 10 m of 0) | `joint` | +| `kit_mechanism` | a label of 1 to 32 `a-z`, `0-9` and `_`: which mechanism the joint is (`knee`, `shock`) | `joint` | +| `kit_compliance` | `{"hertz", "damping_ratio"}` (hertz over 0 to 30, damping ratio 0 to 2): a slide in the load path that settles and rebounds under load. Prismatic only, and it needs limits, the travel it settles within | `joint` | + +Every one of them is written by one function, `write_connection`, which `attach`, `roll`, `aim`, `reach`, `slide` +and `joint` all seat through; `detach` clears them with the connection. So the limits have one check: a value with +no representative inside them is refused before anything is written, naming value and limits, and a roll a turn +away from its limits is written as the roll inside them (limits 150 to 210 and a roll of -170: 190). `aim` inside +limits takes the free roll when the limits hold it and otherwise the end that points the axis nearer; `reach` +takes only a root inside them. A new connection states no record. A value written by hand outside its limits +reads `within: false` in every report and the next pose of that part is refused. + +Limits and springs follow Box2D v3's `b2PrismaticJointDef` and Jolt's `SliderConstraintSettings`: the slide's +limits and a spring as a frequency in hertz and a damping ratio sit on the joint itself. Frequency and damping +ratio describe how the strut feels whatever mass it carries; a stiffness in N/m would need the mass the kit does +not know. `kit_compliance` is a record for a runtime: nothing in Brokkr solves it. + +Two things a rig needs are not stored, because each is already stated once. The axis is the parent socket's z in +the kit at the parent's stored params: a copy on the connection would go stale at the next `set_params`. The order +is the parent tree. `brokkr_kitbash.joints` derives both at each call and emits them, so a consumer derives +nothing: + +```json +{"schema": "brokkr.joints", "version": 1, "root": "Tank", "frame": "the root object's: Blender axes (+Z up), metres", + "rigid": 2, "joints": [ + {"id": "Strut", "parent": null, "part": "strut", "socket": "Mount:pivot", "kind": "revolute", + "axis": [0.0, 1.0, 0.0], "origin": [0.436, 0.0, 0.85368], "value": -113.019997, "limits": [-116.02, -40.02], + "min": -3.000003, "max": 72.999997, "mechanism": "knee", "compliance": null}, + {"id": "Rod", "parent": "Barrel", "part": "ram_rod", "socket": "Barrel:bore", "kind": "prismatic", + "axis": [0.97429, 0.0, 0.225296], "origin": [1.072572, 0.124, 1.312762], "value": 0.12, "limits": [0.0, 0.3], + "min": -0.12, "max": 0.18, "mechanism": "shock", "compliance": {"damping_ratio": 0.7, "hertz": 4.0}}]} +``` + +A row per revolute or prismatic connection under the root, depth first with children by name, so a row's parent +comes before it. `parent` is the nearest joint above, not the object the part hangs from: rigid connections fold +into it and are counted in `rigid`. `axis` and `origin` are the parent socket's z and origin in the root object's +frame. `min` and `max` are the limits less the value, the travel either way from the pose the report was taken at, +which is the shape of Aetheria's `ShipJoint` (`Min` and `Max` about rest). What the report gives up: it is the +pose at the call, so rest is whatever the assembly stood at; it carries no meshes or bone names, so a consumer +joins rows to the exported objects by `id`; and `ShipJoint` has no slide and no spring yet +(aetheria-release:question:shipjoint-prismatic-dof), so a prismatic row has no Aetheria reader today. **What may mate** (`core.mate_refusal`): two sockets of one type whose sizes agree as the type's `match` says: `equal` within 1 percent of the larger, `fits` with the child at most the parent. Socket types are a -vocabulary kits share: parts of two kits mate when both kits declare the socket's type with the same `match` +vocabulary kits share: parts of two kits mate when both kits declare the socket's type with the same `match` and +the same `dof` (`cutters` declares `mount` as `mechanical` does, so a vent seats on a recess floor), and are refused, naming both kits and the type, when one does not declare it or declares it otherwise. KSP's attach nodes and LDraw's snap types are connector vocabularies of this kind: global, matched by type and size. `attach` also @@ -666,7 +724,7 @@ evaluation once for every `ribs` call; iterate planes on the cage before it is c ```json {"action": "brokkr_kitbash.hose", "object_name": "Feed", "start": "ThighRam:port_cap", "end": "ShinRam:port_cap", "count": 3, "radius": 0.006, "clearance": 0.005, - "joint": "{\"socket\": \"Shin:end_a_back\", \"standoff\": 0.08, \"range\": [-120, 20]}"} + "joint": "{\"socket\": \"Shin:end_a_back\", \"standoff\": 0.08}"} ``` **Ends.** `start` and `end` are `Object:socket` on a kit part, a `hose` socket (an actuator's `port_cap` and @@ -751,9 +809,12 @@ radius above the face, for 2 outside diameters each side, and gets a pad on the bundle lies flat on the first clamp; its ups are rotation minimising (Wang et al. 2008), so it does not twist between clamps, and a later clamp's strap follows the bundle as it arrives. -**A pin.** A hose may cross one pin: a pivot connection between its ends' parts, found from their parent chains. -`joint` names a socket on that pin's axis whose z runs along it (the free end face of the pin: a strut's -`end_a_back`), a `standoff` and the pin's roll `range`. The hose passes through the point `standoff` beyond that +**A pin.** A hose may cross one pin: a revolute connection between its ends' parts, found from their parent +chains. `joint` names a socket on that pin's axis whose z runs along it (the free end face of the pin: a strut's +`end_a_back`) and a `standoff`. The roll range the hose is proven over is the pin's own: its connection's limits, +stated once with `brokkr_kitbash.joint` (`{"limits": [-120, 20]}`) and read by every hose across it. A pin with no +limits is refused, naming that action, and so is a prismatic connection between the ends: a hose across a slide +is not routed. The hose passes through the point `standoff` beyond that socket, on the axis, as a robot's dress pack does: the straights on each side then move with their own part and only the bend at that point changes with the roll. The whole range is measured without posing anything, not a list of rolls in it. Each roll from `lo` to `hi` in steps of 5 degrees answers for the rolls nearer it than any @@ -792,7 +853,8 @@ skin weights are `brokkr_rig`'s. **Refusals**, each before anything is written: a name taken by an object that is no hose; an end or clamp that names no object, no such socket, or a socket of the wrong type; a bundle wider than a port, naming both sizes; a part that is scaled or that Blender does not evaluate; a pin crossed with no `joint`, a `joint` with no pin, two -pins, a `joint` socket off the pin's axis, the current roll outside `range`; a search box over 524288 voxels, +pins, a `joint` socket off the pin's axis, a pin with no limits or standing outside them, a slide between the +ends; a search box over 524288 voxels, naming a step that fits; an end nearer an obstacle than the bundle needs; a bundle proven too stiff to leave a port; and, once every seed has been tried, no route found, with the first seed's refusal: no way through, a corner under the floor by what its polyline lacked, a curve not proven to keep the clearance at a named point, or a roll @@ -993,6 +1055,9 @@ Python loop of BVH queries with three rays a sample, and the 13,824-candidate se | `brokkr_kitbash.roll` | `object_name`, `roll` (degrees, -360 to 360) | Turns an attached part to that roll where it hangs. Refuses a part that is not attached. Reports the part and `closures` as `set_params` does. | | `brokkr_kitbash.aim` | `object_name`, `axis` (`+x`, `-x`, `+y`, `-y`, `+z` or `-z`, the part's own), `direction_x`, `direction_y`, `direction_z` (world, any length) | Solves the roll that turns the axis as far toward the direction as the pin lets it, and turns the part to it. Refuses an axis or direction along the pin. Reports the part, `aimed: {roll, dot}` and `closures`. | | `brokkr_kitbash.reach` | `object_name`, `socket` (one of the part's), `height` (metres, -1000 to 1000), `direction_x`, `direction_y`, `direction_z` (world; default 0, 0, 1) | Solves the roll that brings the socket's origin to `height` along the direction, the nearer of the two, and turns the part to it. Refuses a height out of reach, naming the range. Reports the part, `reached: {roll, residual}` and `closures`. | +| `brokkr_kitbash.joint` | `object_name`, `record` (a JSON object of any of `limits`: `[lo, hi]` or null; `mechanism`: a label or null; `compliance`: `{hertz, damping_ratio}` or null) | States the joint record of an attached part's connection; a key left out keeps what is stated and null clears it. Refuses a rigid connection naming its socket type, limits that do not hold the value the joint has, revolute limits over a turn or past 360, prismatic limits past 10 m, and compliance on a revolute joint or without limits. Reports the part and `closures` as `roll` does | +| `brokkr_kitbash.slide` | `object_name`, `slide` (metres, -10 to 10) | Slides an attached part along its parent socket's normal on a prismatic connection, where it hangs. Refuses a revolute or rigid connection naming its socket type, and a slide outside the joint's limits. Reports the part and `closures` as `roll` does | +| `brokkr_kitbash.joints` | `object_name` (the root, a kit part) | Reports the joints of the tree attached under the root as `brokkr.joints` version 1: a row per revolute or prismatic connection, parents first, with `id`, `parent`, `part`, `socket`, `kind`, `axis`, `origin`, `value`, `limits`, `min`, `max`, `mechanism` and `compliance`, in the root's frame ("Joint records"). Changes nothing | | `brokkr_kitbash.close` | `object_name` (the closing part), `socket`, `other_name`, `other_socket` | States that the closing part's socket meets the other part's, closing a loop. Accepted only when they already meet; moves nothing. Reports the closing part. | | `brokkr_kitbash.boolean` | `object_name` (any mesh), `cutter`, `operation` (`DIFFERENCE`, `UNION` or `INTERSECT`; default `DIFFERENCE`) | Adds the cutter to the collection of the target's one live Exact Boolean for the operation, above the Bevel. Refuses a cutter that is the target, is not a mesh, or already cuts it, and a scaled target. Reports the part (or `object` for a mesh that is not one), `booleans: [{cutter, operation}]` (difference, union, intersect; each in the order added; `booleansOmitted` counts rows a receipt had no room for) and `evaluated`. | | `brokkr_kitbash.cut` | `object_name` (any mesh), `cutter_name`, `part` (`box`, `cyl`, `slot`, `slab`), `params`, `origin_x/y/z`, `direction_x/y/z`, `up_x/y/z` (default 0, 0, 1), `roll` (degrees, default 0), `axis_x/y/z` (default 0, 0, 0: the surface normal) | Places a `cutters` part where the ray meets the target, parented to it, and adds it to the target's difference Boolean. Refuses a ray that misses or has no direction, a name an object has, an `up` along the cutter's axis, an `axis` into the surface and a scaled target. Reports `object`, the `cutter` with its floor sockets, and `booleans` (with `booleansOmitted`, as `boolean`). | @@ -1001,7 +1066,7 @@ Python loop of BVH queries with three rays a sample, and the 13,824-candidate se | `brokkr_kitbash.thaw` | `object_name` | Puts the live mesh back, turns every modifier on and removes the frozen mesh; evaluates nothing. Refuses an object that is not frozen or whose held mesh is gone. Reports `object`, `frozen`, `modifiers` and the live mesh's `faces`. | | `brokkr_kitbash.ribs` | `object_name` (the cage), `ribs_name`, `planes` (a JSON array of 1 to 64 `{origin, normal}`, up to 16000 characters), `standoff`, `depth`, `thickness`, `step`, `holes`, `posts`, `post_r`, `bridge`, `clearance`, `longerons` (a JSON array of 0 to 16 `{origin, axis, toward}`, up to 8000 characters), `longeron`, `longeron_w`, `longeron_h`, `longeron_t` | Derives ribs, lightening holes, posts and longerons from the cage as it is cut, as one mesh object under it. Refuses before it writes anything, naming the plane or longeron. Reports `object`, `ribs`, `thickness`, `sections: [{plane, chains, pieces, length, open}]`, `posts`, `holes`, `longerons: [{index, stations}]` (trimmed to a receipt, with `longeronsOmitted`), `faces`, `volume` and `nonManifoldEdges`. | | `brokkr_kitbash.shell` | `object_name`, `sheet` (a JSON object `{rings, closed, mirror, creases, rim, flip}`, up to 32000 characters), `thickness`, `offset`, `levels`, `bevel`, `count_folds` | Makes a faceted, hollow armor shell from a loft of rings with crease runs, or rebuilds a shell's cage in place under its cutters and ribs. Refuses before it writes anything, naming the field and index. Reports `object`, `rebuilt`, `rings`, `points`, `cageFaces`, `creases`, `folded` (with `count_folds`, the number of the evaluated wall's inner faces that fold; else null), `corners`, `subdividedFaces`, `facing`, `thickness`, `offset`, `levels` and `children`. | -| `brokkr_kitbash.hose` | `object_name`, `start`, `end`, `count`, `radius`, `spread`, `clearance`, `bend`, `step`, `sag`, `clamps` (a JSON array of up to 8 `{socket}`), `joint` (empty, or a JSON object `{socket, standoff, range}`) | Routes a bundle of hoses between two sockets around every other mesh, over clamps and through a pin's axis across its roll range; on a hose's name, rebuilds it in place. Reports `length`, `lengthChange`, `clearance`, `radii`, `sag`, `voxels`, `seed`, `rolls`, `worstRoll`, `faces`, `nonManifoldEdges`. | +| `brokkr_kitbash.hose` | `object_name`, `start`, `end`, `count`, `radius`, `spread`, `clearance`, `bend`, `step`, `sag`, `clamps` (a JSON array of up to 8 `{socket}`), `joint` (empty, or a JSON object `{socket, standoff}`) | Routes a bundle of hoses between two sockets around every other mesh, over clamps and through a pin's axis across its roll range; on a hose's name, rebuilds it in place. Reports `length`, `lengthChange`, `clearance`, `radii`, `sag`, `voxels`, `seed`, `rolls`, `worstRoll`, `faces`, `nonManifoldEdges`. | `params` is `name=value; name=value`; a param left out takes the part's default (`place_part`) or keeps its stored value (`set_params`). A value outside its bounds is refused with the bounds in the message. @@ -1047,8 +1112,9 @@ file holds each report in `hostResult`. `tools/turntable_recipe.py` renders the ## The mechanical kit -`kits/mechanical.v0.json`: eleven parts, each along +z, with socket types `flange` (equal), `mount` (fits), -`pivot` (equal) and `hose` (fits: a port takes a bundle no wider than its size). +`kits/mechanical.v0.json`: thirteen parts, each along +z, with socket types `flange` (equal), `mount` (fits), +`pivot` (equal, revolute), `slide` (equal, prismatic: a telescoping bore, sized by its diameter) and `hose` (fits: +a port takes a bundle no wider than its size). | part | params | sockets | | --- | --- | --- | @@ -1057,6 +1123,8 @@ file holds each report in `hostResult`. `tools/turntable_recipe.py` renders the | `ribbed_cylinder` | `radius`, `length`, `ribs`, `rib_depth`, `rib_width`, `segments` | `end_a`, `end_b` (flange) | | `strut` | `length`, `width`, `thickness`, `segments` | `end_a`, `end_a_back`, `end_b`, `end_b_back` (pivot): the two end faces of the pin at each end | | `actuator` | `body_r`, `body_len`, `rod_r`, `extension`, `segments` | `base`, `base_back`, `rod_end`, `rod_end_back` (pivot); the rod end's two move with `extension`; `port_cap`, `port_rod` (hose, `0.4*body_r` wide) on the end faces of its two port bosses | +| `ram_barrel` | `body_r`, `body_len`, `rod_r`, `segments` | the actuator up to its gland: `base`, `base_back` (pivot); `bore` (slide, `2*rod_r`) at the closed piston face, its z along the barrel; `port_cap`, `port_rod` (hose) | +| `ram_rod` | `body_r`, `rod_r`, `length`, `segments` | the actuator from its gland: `piston` (slide, `2*rod_r`); `rod_end`, `rod_end_back` (pivot). In a barrel's bore slide 0 is closed and the slide is the extension; a rod of `length` `body_len + 1.1*body_r` stands as the actuator does | | `pipe_fitting` | `pipe_r`, `run`, `branch`, `flange_r`, `flange_t`, `segments` | `a`, `b`, `c` (flange) | | `radiator_stack` | `fins`, `fin_w`, `fin_h`, `fin_t`, `pitch`, `segments` | `base` (mount) | | `vent` | `width`, `height`, `depth`, `slats`, `slat_t`, `tilt` | `back` (mount) | @@ -1088,7 +1156,7 @@ on the other then lie in one plane and can meet at a pin: a braced leg. ## The frame kit `kits/frame.v0.json`: nine parts of chassis structure, every shell an extrude. Its socket types are `mount` (fits) -and `pivot` (equal), the same two lines as `mechanical`'s, so a frame part seats on a mechanical one and the other +and `pivot` (equal, revolute), the same two lines as `mechanical`'s, so a frame part seats on a mechanical one and the other way round (`place_part` and `describe` take `kit: "frame"`). | part | params | what it is | sockets | @@ -1117,7 +1185,7 @@ python -m unittest discover -s surfaces/blender/tests -p "test_kitbash.py" -v 16 seeded draws, and checks that every shell is closed and wound outward, every socket frame is right-handed and seated on a face that faces its `z`, and no build passes 20000 faces. Choose param ranges so every combination builds: a `min` or `max` in an expression keeps a derived length positive where two params could cross. A new -part of `mechanical` also joins the part and socket list in `test_the_kit_is_the_eleven_parts_and_three_socket_types`. +part of `mechanical` also joins the part and socket list in `test_the_kit_is_the_thirteen_parts_and_five_socket_types`. `FrameKitTests` holds `frame` to the same (the seat check reads a cap that is not convex, an I section's, as it reads a convex one), with the truss's shells and chords, the portal's mitres, its web in the frame's plane and its feet apart, each beam's `w` across x and `h` along y, and a beam seated on a mechanical diff --git a/surfaces/blender/tests/live/kitbash_assembly.result.json b/surfaces/blender/tests/live/kitbash_assembly.result.json index 7cc08bf..8448f5d 100644 --- a/surfaces/blender/tests/live/kitbash_assembly.result.json +++ b/surfaces/blender/tests/live/kitbash_assembly.result.json @@ -612,7 +612,17 @@ "detail": null }, { - "name": "refused, scene unchanged: set_params on a dirty frozen part", + "name": "refused, scene unchanged: set_params on a dirty frozen part, named dirty as its report names it", + "ok": true, + "detail": null + }, + { + "name": "a frozen part with a modifier shown in renders only reports dirty", + "ok": true, + "detail": null + }, + { + "name": "refused, scene unchanged: exportGltf applying modifiers over a frozen part dirty in renders only", "ok": true, "detail": null }, @@ -651,6 +661,56 @@ "ok": true, "detail": null }, + { + "name": "thaw after an export that applied modifiers leaves no frozen mesh behind", + "ok": true, + "detail": null + }, + { + "name": "freeze gives the live mesh a fake user and kit_kept, a pointer to the frozen mesh; a save writes both", + "ok": true, + "detail": null + }, + { + "name": "deleteObject on a frozen object releases its live mesh: a purge takes it and the frozen mesh", + "ok": true, + "detail": null + }, + { + "name": "importGltf drops the kit_* properties a file's extras carry, and says so: the imported object is not frozen and not a part", + "ok": true, + "detail": null + }, + { + "name": "refused, scene unchanged: thaw on the imported object", + "ok": true, + "detail": null + }, + { + "name": "a frozen object deleted in Blender, by no action: a save writes neither mesh, and a purge takes both", + "ok": true, + "detail": null + }, + { + "name": "a kept mesh whose kit_kept was cleared by hand still gives its fake user back at thaw", + "ok": true, + "detail": null + }, + { + "name": "a live mesh whose kit_frozen was deleted by hand stays kept through a purge and a save", + "ok": true, + "detail": null + }, + { + "name": "refused, scene unchanged: thaw on a frozen part whose kit_frozen was deleted names the kept mesh", + "ok": true, + "detail": null + }, + { + "name": "and with kit_frozen pointed back it thaws and the mesh is released", + "ok": true, + "detail": null + }, { "name": "two cutters share one Boolean modifier above the Bevel, in its collection in the order they came", "ok": true,