quickGeometry.package
- .metadata17 B
- ModelGraph.procGraph
- README.md10.3 KB
- V8Dyno.scene
- curve.module
- documentation
- expr.module
- math.module
- model.module
- model.nodebox
- modelpiece.module
- modelpose.module
- normals.module
- outline.module
- package.yaml130 B
- quickLighting.module
- sceneNouns.module
- shape.nodebox
- shapes.module
- studioKey.sceneLight
- studioLighting.sceneSetup
- studioSky.sky
This package holds more than this page lists. See all of its files in its world.
README.md
quickGeometry
Model a scene in Luau with three.js-shaped code. A build.luau or a .sceneModule builds Groups and Meshes from geometry constructors and materials; at the end of the build the tree is stored in the scene as data, drawn by one Generator, and nothing runs per frame.
A bare box reads as a placeholder. Every geometry takes modifiers that turn it into a modelled shape: round its edges, taper it, bend it, drill it, smooth it, or build it from a profile or cross-sections. A build whose parts are mostly bare boxes and planes logs a warning that names them.
Using it
The nouns are globals in a scene's build.luau and a .sceneModule's entry script: sceneNouns and quickLighting join both scripts' contexts, so the engine binds their exports when it loads the script, and the language server knows the same names.
function content()
local paint = MeshStandardMaterial({ color = "#b0332f", metalness = 0.45, roughness = 0.28 })
local steel = MeshStandardMaterial({ color = "#aab2ba", metalness = 1, roughness = 0.25 })
local body = Mesh(BoxGeometry(1, 1, 1):round(0.14), paint, "rounded_box")
body.position:set(0, 0.8, 0)
local block = Mesh(BoxGeometry(1.1, 1.1, 1.1):subtract(CylinderGeometry(0.3, 0.3, 2, 24)), steel, "drilled_block")
block.position:set(1.5, 0.8, 0)
local hull = Mesh(LoftGeometry({
{ shape = EllipseShape(0.45, 0.28), z = -1.2, scale = 0.25 },
{ shape = EllipseShape(0.45, 0.28), z = -0.55, scale = 0.95 },
{ shape = EllipseShape(0.45, 0.28), z = 0.4, scale = 1.0 },
{ shape = EllipseShape(0.45, 0.28), z = 1.2, scale = 0.3, offset = { y = -0.06 } },
}), paint, "hull")
hull.position:set(3.2, 0.8, 0)
end
The same code works in a .sceneModule's builder, where inputs declare what a placement may set.
A module joins those contexts with --!context sceneBuild sceneModule in its leading comment block, the way these two do. A world's own module joins the same way, and its exports become globals in every build script beside the nouns. A name that starts with _ stays inside its module. A module that exports _beginRun and _finish has them called around every run of a build. The script_context module's README covers contexts in full.
Parts
Group(name)holds other objects.Mesh(geometry, material, name)draws a geometry.object.position,object.rotation(Euler angles in radians, XYZ) andobject.scaletake.x,.y,.zand the vector methodsset,setScalar,copy,add,sub,multiplyScalar,cloneandtoArray; calls chain.parent:add(a, b, ...)nests objects under another, and their poses are then in the parent's frame; an object added elsewhere moves.parent:remove(a, ...)takes them out, and a removed object is not drawn until it is added again.object.parentandobject.childrenhold the tree.object.visible = falseleaves the object and everything under it out of the scene.object.userDatais a table for your own values.object:lookAt(x, y, z)orobject:lookAt(Vector3)turns the object so its +Z axis points at a point in its parent's frame; the object's position and the point are numbers.object:clone(recursive)copies the object, its pose, components and (unlessrecursiveis false) what is under it; the copy shares the geometry and material and is placed like a newMesh.object:traverse(fn)callsfnon the object and everything under it, andobject:getObjectByName(name)finds one.object:addComponent(type, data)puts an engine component on the entity a part becomes (Physics, a collider, aJoint). A part whose pose follows a formula is drawn as an instance and takes none.- An object that never moves and carries a component becomes an entity named for it, with its parent and local pose; one that never moves and carries none is folded into the object above it. A moving object's leaves are drawn as instances.
Geometry
| Constructor | Shape |
|---|---|
BoxGeometry(width, height, depth) | box |
CylinderGeometry(radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded) | cylinder; a cone when one radius is 0 |
ConeGeometry(radius, height, radialSegments, heightSegments, openEnded) | cone with its apex up |
SphereGeometry(radius, widthSegments, heightSegments) | UV sphere |
TorusGeometry(radius, tube, radialSegments, tubularSegments, arc) | torus |
TorusKnotGeometry(radius, tube, tubularSegments, radialSegments, p, q) | torus knot |
CapsuleGeometry(radius, length, capSegments, radialSegments) | capsule |
PlaneGeometry(width, height, widthSegments, heightSegments) | flat rectangle |
CircleGeometry(radius, segments) | flat disc |
RingGeometry(innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength) | flat annulus |
TetrahedronGeometry, OctahedronGeometry, IcosahedronGeometry, DodecahedronGeometry (radius, detail) | regular polyhedra; detail above 0 rounds them toward a sphere |
LatheGeometry(points, segments) | a profile of { x = radius, y } points revolved around Y |
ExtrudeGeometry(shape, { depth, curveSegments }) | an outline extruded along +Z |
ShapeGeometry(shape, curveSegments) | a flat, filled outline |
TubeGeometry(path, tubularSegments, radius, radialSegments, closed) | a circle swept along a curve |
LoftGeometry(sections, { caps }) | a surface through cross-sections along Z |
BufferGeometry() | a mesh from your own arrays |
mergeGeometries(list) | several geometries as one |
Every geometry also takes translate(x, y, z), rotateX/Y/Z(angle) and scale(x, y, z), which move it.
Outlines and curves
Shape() records an outline with moveTo, lineTo, quadraticCurveTo, bezierCurveTo and absarc. EllipseShape(rx, ry, segments) and RoundedRectShape(width, height, radius, segments) return ready outlines. CatmullRomCurve3(points, closed) and HelixCurve(radius, turns, height) return curves for TubeGeometry.
Loft
LoftGeometry takes sections in order, each { shape, z, scale?, offset? }: an outline, where along Z it stands, a scale (a number or { x, y }) and a move ({ x, y }). caps = false leaves the ends open. A body, a hull, a fuselage or a bottle is a loft.
Custom arrays
local triangle = BufferGeometry()
triangle:setAttribute("position", Float32BufferAttribute({ 0, 0, 0, 1, 0, 0, 0, 1, 0 }, 3))
setAttribute takes position, normal and uv; setIndex(list) gives triangle indices; without normals they are computed and shared across triangles (computeVertexNormals()).
Modifiers
A modifier changes the shape in its own frame, before translate/rotate/scale move it, and modifiers stack in the order called.
| Modifier | Effect |
|---|---|
:round(radius, segments) | round every edge with that radius |
:bevel(width, segments, angle) | round only edges sharper than angle degrees; width is how far it reaches onto each face |
:subdivide(levels, mode) | split every triangle into four, levels 1 to 3 times; "loop" (default) also smooths, "linear" only adds points |
:smooth() | one round of Loop smoothing |
:taper(amount, axis) | scale the cross-section by 1 - amount * d at distance d along axis ("y" by default) |
:twist(angle, axis) | turn the shape about axis by angle radians per metre along it |
:bend(curvature, axis) | curve it along axis; curvature is 1 over the bend's radius in metres |
:subtract(other), :union(other), :intersect(other) | combine with another closed solid, which stands where it was moved to |
subtract, union and intersect take one shape and one shape; merge parts after combining. Both must be closed solids (a box, cylinder, sphere, torus, capsule or polyhedron, or a bevelled or smoothed one).
Materials
MeshStandardMaterial({ color, roughness, metalness, emissive, emissiveIntensity, opacity, side }) and MeshBasicMaterial({ color, opacity, side }). A colour is a Color, a hex string ("#a3141b"), a number (0xa3141b), a name ("red") or { r, g, b }; hex colours are sRGB. side = "double" draws both faces; an opacity below 1 blends.
Math
Vector3, Color and MathUtils come from the same module as the other nouns and are described in the math module's README: vector methods and operators, colours from hex, names and HSL, and clamp, lerp, smoothstep and a seeded random.
MathUtils.setSeed(3)
for i = 1, 12 do
local post = Mesh(CylinderGeometry(0.05, 0.05, 1):round(0.01),
MeshStandardMaterial({ color = Color():setHSL(i / 12, 0.5, 0.5) }), "post" .. i)
post.position:set(i * 0.5, 0.5, MathUtils.randFloatSpread(0.2))
end
Motion
Write a pose as a formula of Time (seconds) and the Expr functions sin, cos, sqrt, atan2, abs, min, max, mod and floor, with + - * / ^:
local angle = Time * 6.28
piston.position.y = 1.74 * Expr.cos(angle) + Expr.sqrt(32 - 3 * Expr.sin(angle) ^ 2)
crank.rotation.z = -angle
The formula is stored with the scene and runs on the device each frame; children follow their parent's motion.
Lighting
Lighting({ background = "#0c0f12", environment = 1, sun = { color = "#fff1dc", intensity = 1.6, position = { 18, 30, 22 } } })
PostProcessing({ exposure = 0.9, toneMapping = "aces", bloom = { threshold = 1.05, intensity = 0.55 } })
A scene setup places a whole lighting composition as one asset. The V8Dyno scene places studioLighting, a studio backdrop, a warm key light and a sky light that lights the model from the backdrop:
asset.resolve("@builtin::systems.quickGeometry.studioLighting", "sceneSetup"):instantiate(nil, { name = "lighting" })
Where it lives
Each build ends by spawning one entity named model with a Generator on the ModelGraph graph in this package. The tree is the Generator's objects and channels inputs, stored in scene.json; the shapes are made by the nodes of the shape nodebox and the modifiers by procgen's geometry.* nodes. Names that two parts share get a numeric suffix.