ws-3d2/step: cad/step (ISO 10303-21 read/write + injected B-rep plug-in)

- src/Formats/cad/step: Part 21 editions 1-3 parsed into Types.Cad fully in-library (header, named DATA sections,
  complex instances, every parameter kind, string escapes to UTF-8, comments, ANCHOR/REFERENCE/SIGNATURE kept raw);
  writer round-trips at the entity level (integral reals keep their real-ness via a list metatable mark).
- B-rep plug-in: a small injected table { read, write, tessellate } (or brep-luau's { Step, StepBrep, StepWrite, Tess }
  as is), taken from opts.brep / opts.plugins.brep; Step.toBodies / fromBodies / tessellate (-> Scene, z up, mm).
- Types.luau: StepEntity gains optional parts (complex instances) and section (edition 3); backward compatible.
- init.luau (api): withHooks also passes opts.plugins = F.plugins to decoders/encoders unless given; new facades
  F.cad.toBodies / fromBodies / tessellate (pass F.plugins, pcall, Err-wrapped). Backward compatible.
- tests/cad/step.luau + tools/fixtures/step.py: OCCT (gmsh) generated and public STEP files, Python census, OCCT reads
  our output back, brep-luau through a generated tests/gen/.luaurc alias (luau only), fuzz.
- tools/bench.luau: step parse / write lines.
This commit is contained in:
4DBug committed 2026-10-31 09:33:58 -05:00
1 parent 646d18f056
commit 443a7e45cb
12 files changed
+2154 -2

No files matched your search

+30 -1
View File
@@ -255,11 +255,15 @@ end
-- so the api hands decoders opts.decodeImage(buf) -> Image | nil, Err and encoders opts.encodeImage(img, format) ->
-- buffer | nil, Err (unless the caller passed its own). Formats work without them (returning Err.UNSUPPORTED for
-- the embedded parts) when called directly.
-- They also see the injected plug-ins as opts.plugins (F.plugins: the B-rep kernel for cad/step) unless given their own.
local function withHooks(o: Options): Options
if o.decodeImage ~= nil and o.encodeImage ~= nil then
if o.decodeImage ~= nil and o.encodeImage ~= nil and o.plugins ~= nil then
return o
end
local c = table.clone(o)
if c.plugins == nil then
c.plugins = F.plugins
end
if c.decodeImage == nil then
c.decodeImage = function(b: buffer): (any, Err.Err?)
return F.load(b, { category = "image" })
@@ -539,6 +543,31 @@ for category in Types.CATEGORIES do
end
F.data.null = Types.null
-- F.cad.toBodies(cad, opts?) -> bodies, result | nil, Err; F.cad.fromBodies(bodies, opts?) -> Cad | nil, Err;
-- F.cad.tessellate(cad | bodies, opts?) -> Scene | nil, Err: cad/step's B-rep calls with the injected kernel
-- (F.plugins.brep, unless opts.brep / opts.plugins is given). Without a plug-in they return Err.UNSUPPORTED.
for _, fn in { "toBodies", "fromBodies", "tessellate" } do
local name: string = fn
F.cad[name] = function(value: any, opts: Options?): (any, any)
local o = if opts then table.clone(opts) else {}
if o.plugins == nil then
o.plugins = F.plugins
end
local m, err = F.format("step")
if not m then
return nil, err
end
local ok, a, b = pcall(m[name], value, o)
if not ok then
return nil, Err.wrap(Err.new(Err.CORRUPT, name .. " threw: " .. tostring(a)), "step")
end
if a == nil and type(b) == "table" and b.code then
return nil, Err.wrap(b, "step")
end
return a, b
end
end
-- F.model.loadTextures(scene, opts?) -> scene, { [index]: Err }: decodes each texture's encoded bytes (texture.data, or
-- texture.uri through opts.resolve) into texture.image with F.image.load. Model formats never decode images
-- themselves (a format does not require another format); this is the lazy step at the api layer. Textures whose