Builtin Library
- ..
- .metadata228 B
- README.md3.3 KB
- init.luau5.3 KB
- pack.module
README.md
instances.pack (procNode)
Pack a geometry into a piece: ONE POINT whose Mesh holds the geometry whole ({ mesh = <geometry> }) and whose Material holds its material. With attribute empty the whole geometry is one piece; with attribute set, one piece per distinct value of that attribute, in ascending order, each holding the elements that carry the value. A piece point stands as an entity drawing its geometry, merges with other pieces (geometry.merge) into a piece set, and is placed on target points by instances.to_points. A geometry of points packs the same way, which is how a set of points becomes one placeable piece. The packed geometry keeps every attribute it holds; the report output names the ones a drawn mesh does not read.
Each piece point stands at the origin, carries a numbered id, and carries its value under group: its name for a named whole-geometry piece, the split value with attribute, else 0. instances.to_points with match on matches target points on that value. Packing two geometries separately with no name gives both the value 0; give each a name, or pack them together with geometry.merge and pack, which numbers them.
Inputs
geometry(Geometry). What is packed. It rides on the piece point whole.class(String, default "primitive", one of "primitive", "point"). Withattribute, the class of elements whose attribute value splits the geometry. Withoutattributeit has no effect.attribute(String, default ""). An Int or text attribute ofclassto split by: one piece point per distinct value, in ascending order, each carrying its value ingroupand as itsname. Empty packs the whole geometry as one piece. An attribute the class does not carry, or one holding vectors, is refused.name(String, default ""). The name of a whole-geometry piece: the point'snameand the value written togroup. Empty writes 0 togroupand noname. Giving bothnameandattributeis refused.group(String, default "variant"). The attribute written on each piece point. Empty writes none.material(Points or AssetRef<material>, optional). The pieces' material: what a material node answers, or a reference to a material asset. Unwired, the geometry's own, else the default material.castsShadows(Bool, default true). Whether the copies of the pieces cast shadows when they are drawn as instances. A piece that is smoke, a spark or a glow card is packed with it off; debris and props keep it on.receivesShadows(Bool, default true). Whether the copies of the pieces receive shadows when they are drawn as instances.
Outputs
pieces(Points). The piece set: one point, or one per value ofattribute.report(List). One{ attribute, note }row per point, vertex or primitive attribute the packed geometry holds beyond positions, normals, texture coordinates and the links between them, and one when it has no primitives.
local crate = g.instances.pack({ geometry = g.mesh.box({}), name = "crate" }).pieces
local box = g.mesh.box({})
box.primitive.side_id = g.math.to_int(g.math.mod(g.field.index({ domain = box.primitive }), 3))
local sides = g.instances.pack({ geometry = box, attribute = "side_id", class = "primitive" }).pieces