Builtin Library
- ..
- .metadata208 B
- README.md1.9 KB
- init.luau11.3 KB
- readings.module
README.md
geometry.subdivide
Split every triangle into four, levels times: each side gets a midpoint shared by the triangles on either side of it. "linear" puts the midpoints on the sides and keeps the shape; "loop" moves every point by Loop's rules (the even points toward their neighbours, the new points toward the opposite corners), which rounds the surface, and rebuilds the normals. A point attribute of numbers or vectors (P, N, uv and every other) averages across a side, an Int one takes the whole part of the mean, and any other takes the value of the side's first end. Primitive attributes repeat on the four children, and a vertex attribute of a child corner is the middle of the two parent corners it stands between (an Int one the whole part of it), or the parent corner's own where it stands on one. Two sides are one side when they join the same two points, so faces that share points are smoothed as one surface; faces that stand at one place with points of their own are separate pieces, and geometry.weld first joins them. The input is read as triangles.
Inputs
geometry(Surface). The surface subdivided. A geometry holding no primitives is refused.levels(Float, default 1, 1 to 3). How many times every triangle is split: each level multiplies the triangle count by four.mode(String, default "linear", one of "linear", "loop"). "linear" places each new point at the middle of its side. "loop" smooths by Loop's weights.max_vertices(Float, default 250000, at least 4). The most points a level may produce. A level that would pass it is refused, naming the count it would have allocated.
Outputs
geometry(Geometry). The subdivided surface, numbered byid.
local smooth = g.geometry.subdivide({ geometry = g.geometry.weld({ geometry = g.mesh.box({}) }).geometry, levels = 2, mode = "loop" })