Builtin Library
- ..
- README.md3.2 KB
- from_elements.module
- init.luau1.9 KB
README.md
instances.from_elements (procNode)
Turn elements into a piece set, ready for instances.to_points to place. The elements are the entities io.import answers, or any points that carry parent and a pose.
local piece = asset.resolve("@builtin::bundles.lamp_post", "bundle")
local set = g.instances.from_elements({ elements = g.io.import({ source = piece }) })
local copies = g.instances.to_points({ points = slots, pieces = set.pieces })
How it works
- Which elements become pieces. Every element that carries a
Meshbecomes one piece point. The point holds thatMeshand the element'sMaterial, or the default material when the element names none.io.importgives an entity drawn by aModelitsMeshandMaterial(seeio.import).- The mesh stays a reference to the mesh asset. Nothing is read onto the device until the copies are drawn.
- Pose. A piece stands at the pose its element stands at once every parent's pose is applied, root first: position, then rotation, then per-axis scale.
- An element that draws nothing still contributes its pose to its children, so a root entity and the offsets its children carry are applied.
instances.to_pointsapplies each piece's own pose after the target point's, so the whole set stands at every target point.
- Names. Each piece carries its element's
name, and the same text undergroup, whichinstances.to_pointsmatches target points on whenmatchis on. The pieces are named by the entity names, not by the mesh assets they hold. - Bounds. The detail
boundsis{ min, max, center, size }: the box the pieces' meshes span, each mesh's own box carried through its piece's pose. It is the piece set's extent in its own space, read without spawning it. A mesh asset's box is the onerenderer.mesh.boundsanswers, and a geometry's is the box of its points. - What is left out. An element that carries no
Mesh(a root, an empty) is not a piece.reportlists, one{ element, note }row each:- an element left out for carrying another component (a
Light, aSkinnedModel, a script component); - a component a piece leaves behind on an element that does draw;
- a pose that turns under a parent scaled unevenly between its axes, where the composed pose keeps the rotation and the per-axis scale and drops the shear between them;
- a mesh whose box is unknown;
- every row the elements' own
reporteddetail carries (whatio.importcould not put on an element).
- an element left out for carrying another component (a
- No mesh at all. Elements of which none carries a
Meshare refused, naming how many were given.
Inputs
elements(Points). The elements:io.importof an asset, or points carryingparent(the number of the element they hang under, -1 for none),P,orient,scaleand, on the ones that draw,MeshandMaterial.group(String). Default"variant". The attribute each piece's element name is written under. Empty writes none.
Outputs
pieces: the piece set, one point per drawn element:Mesh,Material,P,orient,scale,name,idand thegroupattribute; the detailbounds.report: the{ element, note }rows described above.