Repository navigation
Add clay_mesh_from_arrays: a mesh constructor that keeps uvs, normals and colours (#661) - #685
Merged
Merged
Conversation
) clay_mesh_from_triangles and _from_quads copy positions and indices only, so a host with its own uvs, normals or colours had to round-trip them through OBJ text via clay_mesh_load_memory. clay_mesh_arrays takes them directly, each NULL or vertex-aligned, with exactly one of a triangle or a quad index list; quads derive the triangles by the rule from_quads already uses. The three constructors now share one position/triangle/quad path. ABI 0.123.0 -> 0.124.0.
UVs, normals and colours read back bit-exactly and survive a mesh-layer attach, undo/redo and a save/load; NULL attributes stay absent; quads match from_quads; each malformed call is INVALID_ARGUMENT with out_mesh left NULL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
clay_mesh_from_trianglesandclay_mesh_from_quadscopy positions and indices and nothing else. A host that computed its own per-vertex attributes had no constructor that keeps them. ClaySpaceDesktop's retopology comes back from CyberRemesher with a UV layout (ClaySpaceDesktop#213), and the only entry point that attached uvs was the OBJ reader. So the host wrote vertex-alignedv/vn/vttext into memory and parsed it back throughclay_mesh_load_memory(..., "obj", ...): a text round trip standing in for a copy.Nothing below the boundary was missing.
mesh::Meshalready holdsnormals/colors/uvs, each empty or vertex-aligned.clay_mesh_normals/_colors/_uvsalready read them, andmesh_streamalready writes them into a document. Only the constructor was missing, so there is no data-model or format change.What lands
clay_mesh_arrays+clay_mesh_from_arrays(bindings/c/clay.h). The descriptor has a leadingstruct_sizeand is laid out as the issue sketched:positions/vertex_count,normals,colors,uvs(each NULL or vertex-aligned),indices/index_count,quad_indices/quad_index_count.(a,b,c),(a,c,d)ruleclay_mesh_from_quadsuses, soquads_consistentholds by construction. A kind counts as supplied by its pointer or its count, so a count without its pointer is refused, not ignored.vertex_countentries, bit-exactly.CLAY_ERROR_INVALID_ARGUMENTwithout_meshleft NULL for: NULL descriptor/out,struct_sizebelow the layout, NULL positions, zero vertices, neither or both index kinds, non-whole triangle/quad counts, an index past the vertices.positionsalready had) and attribute values (no renormalising, clamping, wrapping or NaN rejection).bindings/c/clay_c.cpp).start_mesh,take_triangles,take_quadsandtake_attributesare shared.from_trianglesandfrom_quadsare rebuilt on them and behave as before. The only visible difference is that theclay_last_errortext for a NULL pointer now names the one argument that was NULL. Every function is a handful of branches, well inside the backend complexity target.openspec/changes/add-mesh-from-arrays(c-abi ADDED requirement, proposal, design, tasks).docs/08-mesh-readback.mdlists the constructor in the producer, ownership and attribute tables, with a C example in the rebuild section.ABI 0.123.0 -> 0.124.0 (CMakeLists.txt,
clay.h, pyproject.toml). Additive.What building it found
clay_c.cpp'sextern "C"block, where returning astd::vectoris-Wreturn-type-c-linkageunder-Werror. They take out-parameters instead.check_binding_parity.pyruns pyclay -> C, so a C-only entry point passes it, but pyclay has the same gap:Mesh.normals/colors/uvsare read-only views andMesh.from_triangles/_from_quadstake positions and indices only. The host that asked is a C host. AMesh.from_arrayswould be checked against this entry point by the existingclay_mesh_prefix rule; it is left as a follow-up.Regression test
tests/unit/test_c_mesh_from_arrays.cpp(5 cases, 91 assertions):indicesasclay_mesh_from_quadsand keeps its quads..clayspacesave and load.out_mesh: NULL positions, zero vertices, a bad triangle or quad count, an out-of-range triangle index or quad corner, both kinds, neither kind, a count without its pointer, andstruct_size4 and 0.Proof it gates:
main, the test does not compile (unknown type name 'clay_mesh_arrays'): the capability did not exist.take_attributescommented out): 4 of 5 cases fail, 16 assertions.Verification
cmake --preset cpu-only -DCLAY_BUILD_TESTS=ON -DCLAY_BUILD_PYTHON=ON, full build,ctest: 11/11 passed (the four unit shards, shard partition, pyclay pytest).-Wall -Wextra -Wpedantic -Wshadow -Werror -fno-exceptions -fno-rttisyntax check ofbindings/c/clay_c.cppand the new test: clean (exit codes read directly, not through a pipe).npx @fission-ai/openspec@1.12.0 validate --all --strict: 77/77.tools/release_check.py --skip-slow: version, configure, build, tests, parity, layering, dialect, licenses, task-symbols, bindings (imported .../build/release/bindings/python/pyclay...so, a real check), kernels, abi (hygiene + ctypes FFI) and openspec all pass. The rows still red are the release-time hardware rows:device(the engine changed since the last device run) and the fourhardware/*waivers, which are stale againstinclude/clay/eval/bake_volume.h, a file this PR does not touch.Closes #661