Builtin Library
README.md
io.import (procNode)
Take a scene concept, the entities and components of zero space, or the value an asset states, and turn it into procgen values: the Geometry, elements and piece sets a graph works on. source is an asset, and value is what the node makes of it.
The node makes a value of an asset by the first of these its type offers:
- A
graphconversion its behavior states. The type states one of:import: it answers the record it reads, and the members it names incolumnsare put on the device. A texture is{ width, height, format, texels }, its texels one{ x, y, z, w }each; a landscape (.terrainData) is its ground,{ cols, rows, minX, minZ, sizeX, sizeZ, heights };record, the record kind its assets load as: it answers one element holding the record its kind loads, the way a node that makes such a record answers. A.materialis one element whoseMaterialattribute holds the material record, with the kind on the detail attributerecords;read: it answers that value. A mesh is a Geometry; a population is the copies it places, the forminstances.to_pointsanswers; a.procRecordis the record kind itself ({ kind, name, asset, applies }); a bundle and a scene are their entities as elements.
instantiate. A type that states nographconversion and definesinstantiate(ref:canInstantiate()) is instantiated, and the entities the instantiation produces are answered as elements. The node instantiates the asset under a temporary root, which is internal, hidden and inactive, reads the entities beneath it, and despawns the root and everything under it before the node answers, including when reading raises.
The asset is read when the node cooks, and an edit to it cooks the node again.
Elements
The entities of a bundle, a scene or an instantiated asset answer as one point per entity, numbered from 0, carrying
name, parent (the number of the entity it hangs under, -1 for none), P, orient and scale (the entity's own
pose), and one attribute per script component, named after the component's type as the record states it
(@builtin::components.Light) and holding the component's data.
- A bundle and a scene list their entities in the order the asset holds them. An instantiated asset lists its root first, then each entity's children after it in name order, a parent always before its children.
- An entity drawn through the native
MeshandMaterialcomponents carries them asMeshandMaterialrecords. An instantiated entity's native components are read from the live entity, a field holding an asset written as the asset's guid. - An entity drawn through a
Modelcomponent carriesMesh(the mesh asset, with the Model's shadow settings) andMaterial, and noModelattribute. - A
Modelfield that dresses the draw (tint, outline, light channels, mobility) set away from a freshModel's, and a hiddenModel(whose element then carries noMesh), are listed in the detail attributereported, as is any other native component. - A
SkinnedModelstays an attribute of its own. instances.from_elementsturns the elements into a piece set thatinstances.to_pointsplaces.
This is the form io.output stands and io.export saves. To place a mesh on points with instances.to_points,
import the mesh asset itself (a mesh asset answers a Geometry) and pack it with instances.pack.
local lamp = g.io.import({ source = asset.resolve("@builtin::bundles.lamp_post", "bundle") })
local pieces = g.instances.from_elements({ elements = lamp }).pieces
An asset with neither
An asset whose type states no graph conversion and defines no instantiate is refused: the error says the type
states no graph conversion and cannot be instantiated.
local rock = g.io.import({ source = asset.resolve("@builtin::meshes.cube", "mesh") })
local lamp = g.io.import({ source = asset.resolve("@builtin::bundles.lamp_post", "bundle") })
local ground = g.io.import({ source = landscape, options = { cols = 65, rows = 65 } })
Inputs
source(AssetRef). The asset brought in, writtenasset.resolve("<identity>", "<type>").options(Record, optional). What the asset's type reads it with: a landscape'scolsandrows, the samples its heights are read at along x and z (129 each when left out). A type that reads nothing takes none.
Outputs
value: the asset as the value the node makes of it.