solidsplugin
Models made of low-poly solids, and their meshes for the plugins that draw them.
Putting it in a scene
List it before render3d, and after terrain3d when models stand on its ground (see Mods). It has no row, no prefab and no server half. A scene that only lists it for another plugin that draws such models leaves world.solids out.
"plugins": ["loader", "scenemanager", "player", "terrain3d", "solids", "render3d"],
"world": {
"loader": { "assets": { "hut": { "type": "json", "url": "/games/mygame/assets/hut.json", "preload": true } } },
"solids": { "kinds": { "hut": "hut" }, "mods": { "land": "terrain3d" } }
}
Properties
Read from world.solids.
.kinds : { [kind]: model }
Each row of a named kind is drawn from the model, the name of a json entry of the loader catalogue. The row is read for its pos [x, y, z] and its yaw in radians, and nothing else. When the model's file changes, as it does in the editor, every row of that kind is made again.
.mods : { land }
The ground models stand on (see Mods). With none named, or until the land has a height, a model stands at its row's own y.
The model file
{
"paints": {
"wood": { "colour": "#8a5a32", "roughness": 0.9 },
"lamp": { "colour": "#ffd27a", "glow": 2, "blink": [0.5, 0.8] },
"glass": { "colour": "#a8c8e0", "opacity": 0.3 }
},
"nodes": {
"body": { "at": [0, 0, 0] },
"door": { "parent": "body", "at": [0.6, 0, 1.5], "turn": [0, 0.4] }
},
"parts": [
{ "node": "body", "paint": "wood", "loft": { "axis": "y", "from": 0, "to": 2.4, "a": [0, 0, 1.5, 1.5], "b": [0, 0, 1.2, 1.2] } },
{ "node": "body", "paint": "wood", "prism": { "axis": "y", "from": 2.4, "to": 3.4, "at": [0, 0], "r": [1.6, 0], "sides": 4 } },
{ "node": "door", "paint": "glass", "loft": { "axis": "z", "from": -0.02, "to": 0.02, "a": [-0.6, 1, 0.6, 1] } }
],
"lights": [
{ "node": "body", "colour": "#ffd27a", "intensity": 20, "at": [0, 2.8, 1.6], "distance": 12, "paint": "lamp" }
]
}
nodes
The frames the parts hang in, each listed after its parent. A node is at metres from its parent's origin, or from the row's pos when it has no parent. turn [rx, ry] turns it in radians about x and then about y in its parent's frame, and mirror: true flips its x.
parts
Each part is one convex solid in its node, drawn in one paint. Every facet is flat-shaded, and a face's winding in the file does not matter.
| Key | Meaning |
|---|---|
node, paint | The node it hangs in and the paint it is drawn in. |
loft | { axis, from, to, a, b? }: a box along axis (x, y or z) from from to to metres, between rectangle a at the start and b at the end (a when left out). A rectangle is [centre j, centre k, half j, half k] on the other two axes in order: y and z for x, x and z for y, x and y for z. |
prism | { axis, from, to, at, r, sides }: a prism of sides sides along axis, radius r[0] at from and r[1] at to, centred on at [j, k]. A flat side faces the j axis. A radius of 0 makes a point, as a roof's. |
frame | { at?, turn? }: turns the solid about x, then about y, in radians, then moves it to at, before the node's own frame. |
paints
A paint is a standard material that the sky's light, wetness and snow reach. Every part casts and takes shadows except see-through ones.
| Key | Meaning |
|---|---|
colour | An sRGB colour string. |
roughness, metalness | 0 to 1. Left out, three.js's own defaults. |
glow | How strongly the paint gives off light in its own colour. |
blink | [hz, on]: the paint glows only for the first on share of each of hz cycles a second, at glow, or 1 when it gives none. |
opacity | Below 1 the paint is glass: it lets that share of what is behind it through and casts no shadow. |
lights
Real lights that light whatever is round them, each hung in a node as a part is.
| Key | Meaning |
|---|---|
node, at | The node, and the light's place in its frame, in metres. |
colour, intensity | An sRGB colour string, and the strength in candela. |
distance, decay | How far the light reaches in metres, 0 or left out for no limit, and how it falls off, 2 when left out. |
spot | { aim, angle, penumbra }: makes it a spot light pointed at aim, a point in the same frame. angle is radians from its axis to the cone's edge, and penumbra the share of the cone softened. |
shadow | A whole number of pixels: the light casts shadows through a map that many pixels across. |
paint | The paint the light is the glow of. A plugin that lights and darkens a model's paints as it draws turns this light up and down with it. |
Methods
On the page, through plugins.solids, for plugins that draw machines of solids or hang a model on a node of one.
meshes( THREE, dress, paints, parts, whose ) : { meshes, owned, blinks, materials }
Makes every part: one mesh for each node and paint, keyed by the node. dress is render3d's. whose names the model in the error thrown for a paint paints does not hold. materials is each paint's material by name, owned every geometry and material made, for the caller to dispose, and blinks the blinking paints for blink.
lights( THREE, lights ) : { lights, owned }
Makes a model's lights, keyed by node as meshes keys its meshes. A spot light's aim comes as a child of the same node, so it moves with it.
blink( blinks, now )
Lights or darkens each blinking paint for the page's clock now, in milliseconds.
solid( part ) : { v, faces }
A part's corners as [x, y, z] in its node's frame, and its faces, each { ix, n }: the indices of its corners and its outward unit normal.
group( id ) : THREE.Group | undefined
The three.js group a row is drawn in, its world matrix this frame's. Undefined while the row is not drawn.
Mods
Name them in world.solids.mods.
- terrain3d
land: each model stands on the ground's height under its row's x and z. List terrain3d before solids.