Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

README.md

prefab.place (procNode)

Place one prefab inside another: put a whole prefab, a geometry's prefab among them, under a named entity of a host prefab at a local position, rotation and scale. Builds a hierarchy out of parts: a wheel under an axle, a lamp on a post, a door in a wall, each part its own entity. The placed records are renumbered and re-parented, so the same prefab can be placed any number of times.

Every placed record takes the id place<n>_<its id>, n being the number of records the host held before it (raised past any id the host already holds). A placed record's parent_id, and every string in its components' data that names a placed record's id (what prefab.link writes), take the new ids, so links inside the placed prefab keep pointing at their own entities. Each placed root keeps its own pose inside the frame position, rotation and scale pose: a root at (0, 1, 0) placed at (2, 0, 0) stands at (2, 1, 0) under parent. Built from prefab.edit (what = "place").

Inputs

  • prefab (Prefab). The host prefab the placed one goes into. It comes out as a new value; the prefab wired in keeps the shape it had.
  • placed (Prefab). The prefab placed: every record of it is appended, its root (each record with no parent) hung under parent. prefab.from_geometry makes one of a single mesh.
  • parent (String, optional). The name of the host entity the placed prefab hangs under: the first record carrying it. Left out, it hangs on the host's root; a name the host does not carry is an error.
  • position (List<Float>, default { 0, 0, 0 }). Where the placed prefab's root stands, local to parent.
  • rotation (List<Float>, default { 0, 0, 0, 1 }). The placed prefab's root rotation local to parent, a quaternion (x, y, z, w).
  • scale (List<Float>, default { 1, 1, 1 }). The placed prefab's root scale local to parent.

Outputs

  • prefab (Prefab). A new prefab value, { records = { ... } }: the host's records, then the placed ones.
local cart = g.prefab.empty({ name = "cart" })
cart = g.prefab.entity({ prefab = cart, name = "axle" })
local wheel = g.prefab.from_geometry({ geometry = g.mesh.cylinder({}), name = "wheel" })
cart = g.prefab.place({ prefab = cart, placed = wheel, parent = "axle", position = { 1, 0, 0 } })
cart = g.prefab.place({ prefab = cart, placed = wheel, parent = "axle", position = { -1, 0, 0 } })