Skip to content

Commit c8e06cc

Browse files
authored
mcpplibs.mwrap.meshoptimizer 1.3, mcpplibs.mwrap.cgltf 1.15: meshoptimizer-m and cgltf-m (mesh optimisation and the glTF 2.0 loader and writer as C++23 modules) (#778)
* mcpplibs.mwrap.meshoptimizer 1.3, mcpplibs.mwrap.cgltf 1.15: meshoptimizer-m and cgltf-m (mesh optimisation and the glTF 2.0 loader and writer as C++23 modules) * docs(mwrap): the template's dependency key as a dotted key under mcpp 2026.11.8.1 and later
1 parent d8d94f9 commit c8e06cc

13 files changed

Lines changed: 335 additions & 2 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Add mcpplibs.mwrap.meshoptimizer (meshoptimizer-m 1.3) and mcpplibs.mwrap.cgltf (cgltf-m 1.15)
2+
3+
## Form
4+
5+
- Third-party upstreams [zeux/meshoptimizer](https://github.com/zeux/meshoptimizer), release v1.3, MIT, and
6+
[jkuhlmann/cgltf](https://github.com/jkuhlmann/cgltf), release v1.15, MIT (it embeds jsmn, MIT).
7+
- Form A external mwrap module repositories [mcpplibs/meshoptimizer-m](https://github.com/mcpplibs/meshoptimizer-m) and
8+
[mcpplibs/cgltf-m](https://github.com/mcpplibs/cgltf-m); packages `mcpplibs.mwrap.meshoptimizer` 1.3 and
9+
`mcpplibs.mwrap.cgltf` 1.15 (first releases of both identities), tags `mwrap-1.3` and `mwrap-1.15`; release assets
10+
`meshoptimizer-m-1.3.tar.gz` (`5172030f…4e7e`) and `cgltf-m-1.15.tar.gz` (`242d90c6…070b`), CN mirrors
11+
`gitcode.com/mcpp-res/mwrap-meshoptimizer` and `gitcode.com/mcpp-res/mwrap-cgltf` with identical bytes.
12+
- Implementation ownership: neither library has a compat package in this index, so each wrapper vendors its upstream
13+
from the release archive (checksums in `upstream/documents.json`) and builds it itself: meshoptimizer's `src/*.cpp`
14+
unchanged; cgltf's two headers unchanged, their implementation in one C translation unit of the package
15+
(`port/cgltf.c`) with upstream's defaults. Both deploy upstream's README and license with their own LICENSE/NOTICE
16+
(`runtime.deploy`).
17+
18+
## Modules
19+
20+
- `mcpplibs.mwrap.meshoptimizer`: every public name of `<meshoptimizer.h>` (9 types, 20 enumerators, 89 functions) by
21+
`export using`, in the global namespace where upstream declares them; `mcpplibs.mwrap.meshoptimizer.macros`:
22+
`MESHOPTIMIZER_VERSION` as a constant.
23+
- `mcpplibs.mwrap.cgltf`: every public name of `<cgltf.h>` (72 types, 102 enumerators, 37 functions), re-exporting
24+
`mcpplibs.mwrap.cgltf.write` (`<cgltf_write.h>`: `cgltf_write`, `cgltf_write_file`). Neither header's public part
25+
has an object-like constant, so there is no `.macros` module; the configuration macros (`CGLTF_MALLOC` …) are fixed
26+
at upstream's defaults by the package's one implementation.
27+
- Both export lists are derived from the headers by each repository's `tools/surface.py` and audited in CI
28+
(`tools/check_exports.py`).
29+
30+
## Verification
31+
32+
- Wrapper CI (Linux x86_64 GCC 16.1 and LLVM 23.1.3, macOS LLVM, Windows LLVM): the module tests, header mixing, the
33+
export check, and the default template from an installed copy with a strict build.
34+
- This index: consumers `tests/mwrap/meshoptimizer-simplify` (indexing, vertex cache order, simplification, meshlets,
35+
both codecs) and `tests/mwrap/cgltf-inspect` (parse, load, validate, accessors, a node's transform, the writer, the
36+
reasons broken documents are refused with); the installed-template check with `--deploy` for both
37+
(`STATIC_NOTICES`).
38+
- `tests/mwrap/check_installed_template.py` reads the generated manifest's dependency whether its key is quoted or
39+
dotted: both templates write the dotted form (mcpp 2026.11.8.1 warns on a quoted key that needs none, and the check
40+
builds with `--strict`).

‎.github/workflows/validate.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,16 @@ jobs:
17181718
shell: bash
17191719
run: python3 tests/mwrap/check_installed_template.py --mcpp "$MCPP" --package mcpplibs.mwrap.xxhash@0.8.3 --deploy
17201720

1721+
- name: Installed meshoptimizer wrapper archive, actual default simplification template and its relocated notices
1722+
if: contains(format(' {0} ', env.MEMBERS), ' meshoptimizer-simplify ') && matrix.toolchain == 'default'
1723+
shell: bash
1724+
run: python3 tests/mwrap/check_installed_template.py --mcpp "$MCPP" --package mcpplibs.mwrap.meshoptimizer@1.3 --deploy
1725+
1726+
- name: Installed cgltf wrapper archive, actual default inspection template and its relocated notices
1727+
if: contains(format(' {0} ', env.MEMBERS), ' cgltf-inspect ') && matrix.toolchain == 'default'
1728+
shell: bash
1729+
run: python3 tests/mwrap/check_installed_template.py --mcpp "$MCPP" --package mcpplibs.mwrap.cgltf@1.15 --deploy
1730+
17211731
- name: Installed libarchive wrapper archive, actual default archive template and its relocated notices
17221732
if: contains(format(' {0} ', env.MEMBERS), ' libarchive-bundle ') && matrix.toolchain == 'default'
17231733
shell: bash

‎CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838

3939
### Added
4040

41+
- **mcpplibs.mwrap.meshoptimizer 1.3、mcpplibs.mwrap.cgltf 1.15(新包)。** 两个 mwrap 包:meshoptimizer-m 以 `export using`
42+
导出 `<meshoptimizer.h>` 的全部公开名字(9 个类型、20 个枚举值、89 个函数),`MESHOPTIMIZER_VERSION` 在 `.macros` 中为同名常量;
43+
cgltf-m 导出 `<cgltf.h>` 的全部公开名字(72 个类型、102 个枚举值、37 个函数),并再导出 `.write`(`<cgltf_write.h>`)。
44+
本索引没有这两个库的 compat 包,封装仓库各自从上游发布包取源码(校验和在 `upstream/documents.json`)并自行构建;导出清单由
45+
各仓库的 `tools/surface.py` 从头文件推出并在 CI 中审计。消费者测试 `tests/mwrap/meshoptimizer-simplify`、
46+
`tests/mwrap/cgltf-inspect`,安装后模板检查带 `--deploy`(`STATIC_NOTICES`);该检查读取生成的清单时同时接受带引号与
47+
点分两种依赖键。GLOBAL 为 GitHub 发布资产,CN 为 GitCode `mcpp-res/mwrap-<lib>` 镜像,sha256 相同。
4148
- **mtest 0.8.3.** 四个包的 0.8.3(同一标签、同一归档;含未入索引的 0.8.1、0.8.2 的内容):`bench::each` 的一次调用可以说明自己的组成
4249
(`part`、`time`、`value`),给出最慢的几次、超过上限的次数与分配计数;`bench::laps` 是同一测量的循环形式;
4350
程序单独运行时打印测得的数字,并按标识、名字或带 `*` 的模式选择用例。只增不改。

‎docs/mwrap.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ Templates are data, without execution hooks. With the pinned current mcpp,
150150
```
151151

152152
Quote the selector as one key; do not place it under another namespace table.
153+
From mcpp 2026.11.8.1 a quoted key that needs no quotes is reported (and `--strict` refuses it); a template
154+
tested with that client writes the same selector as a dotted key, `{{self.name}} = "{{self.version}}"`, which
155+
names the same package. `tests/mwrap/check_installed_template.py` reads either form.
153156
Declare required features explicitly and keep the library version tied to
154157
`{{self.version}}`. Test actual `mcpp new`, then build and run the generated
155158
project. A source candidate may use an isolated preseeded installed-package

‎docs/zh/mwrap.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ mcpp new --list-templates mcpplibs.mwrap.opencv@5.0.0
9797
mcpp new viewer --template mcpplibs.mwrap.opencv@5.0.0:window
9898
```
9999

100-
模板是纯数据,不执行 hook。当前 mcpp 的 self.name 为完整包选择器,应作为一个带引号的 key:
100+
模板是纯数据,不执行 hook。当前 mcpp 的 self.name 为完整包选择器,应作为一个带引号的 key(mcpp 2026.11.8.1 起,不需要引号的
101+
key 带引号会被提示,`--strict` 下被拒绝;以该版本测试的模板把同一选择器写成点分 key `{{self.name}} = "{{self.version}}"`,
102+
指向同一个包,`tests/mwrap/check_installed_template.py` 两种写法都读):
101103

102104
```toml
103105
[dependencies]

‎mcpp.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ members = [
3535
"tests/mwrap/zstd-squeeze",
3636
"tests/mwrap/xz-pack",
3737
"tests/mwrap/xxhash-digest",
38+
"tests/mwrap/meshoptimizer-simplify",
39+
"tests/mwrap/cgltf-inspect",
3840
"tests/mwrap/libarchive-bundle",
3941
"tests/mwrap/libc-stdio",
4042
"tests/mwrap/miniaudio-engine",

‎pkgs/mwrap/cgltf.lua‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- Immutable upstream-aligned mwrap source release (cgltf-m mwrap-1.15);
2+
-- GLOBAL and CN bytes are identical.
3+
--
4+
-- The wrapper is Apache-2.0; the library it vendors and links statically,
5+
-- cgltf 1.15 (it embeds jsmn), is MIT: the package deploys its README and
6+
-- LICENSE beside programs (runtime.deploy).
7+
package = {
8+
spec = "1",
9+
namespace = "mcpplibs.mwrap",
10+
name = "cgltf",
11+
description = "cgltf-m: cgltf 1.15 (glTF 2.0 loader and writer: parsing, buffers, validation, accessors, node transforms) as C++23 modules",
12+
licenses = { "Apache-2.0" },
13+
repo = "https://github.com/mcpplibs/cgltf-m",
14+
type = "package",
15+
extensions = {
16+
autoupdate = {
17+
tag = "mwrap-${version}",
18+
url = "https://github.com/mcpplibs/cgltf-m/releases/download/${tag}/cgltf-m-${version}.tar.gz",
19+
},
20+
},
21+
xpm = {
22+
linux = {
23+
["1.15"] = {
24+
url = {
25+
GLOBAL = "https://github.com/mcpplibs/cgltf-m/releases/download/mwrap-1.15/cgltf-m-1.15.tar.gz",
26+
CN = "https://gitcode.com/mcpp-res/mwrap-cgltf/releases/download/1.15/cgltf-m-1.15.tar.gz",
27+
},
28+
sha256 = "242d90c65178d0746a25a22b375984bf95af19d9820f7d91b0fb32a06d51070b",
29+
},
30+
},
31+
macosx = {
32+
["1.15"] = {
33+
url = {
34+
GLOBAL = "https://github.com/mcpplibs/cgltf-m/releases/download/mwrap-1.15/cgltf-m-1.15.tar.gz",
35+
CN = "https://gitcode.com/mcpp-res/mwrap-cgltf/releases/download/1.15/cgltf-m-1.15.tar.gz",
36+
},
37+
sha256 = "242d90c65178d0746a25a22b375984bf95af19d9820f7d91b0fb32a06d51070b",
38+
},
39+
},
40+
windows = {
41+
["1.15"] = {
42+
url = {
43+
GLOBAL = "https://github.com/mcpplibs/cgltf-m/releases/download/mwrap-1.15/cgltf-m-1.15.tar.gz",
44+
CN = "https://gitcode.com/mcpp-res/mwrap-cgltf/releases/download/1.15/cgltf-m-1.15.tar.gz",
45+
},
46+
sha256 = "242d90c65178d0746a25a22b375984bf95af19d9820f7d91b0fb32a06d51070b",
47+
},
48+
},
49+
},
50+
}

‎pkgs/mwrap/meshoptimizer.lua‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- Immutable upstream-aligned mwrap source release (meshoptimizer-m mwrap-1.3);
2+
-- GLOBAL and CN bytes are identical.
3+
--
4+
-- The wrapper is Apache-2.0; the library it vendors and links statically,
5+
-- meshoptimizer 1.3, is MIT: the package deploys its README and LICENSE beside
6+
-- programs (runtime.deploy).
7+
package = {
8+
spec = "1",
9+
namespace = "mcpplibs.mwrap",
10+
name = "meshoptimizer",
11+
description = "meshoptimizer-m: meshoptimizer 1.3 (indexing, vertex cache and overdraw ordering, simplification, meshlets, vertex and index codecs) as C++23 modules",
12+
licenses = { "Apache-2.0" },
13+
repo = "https://github.com/mcpplibs/meshoptimizer-m",
14+
type = "package",
15+
extensions = {
16+
autoupdate = {
17+
tag = "mwrap-${version}",
18+
url = "https://github.com/mcpplibs/meshoptimizer-m/releases/download/${tag}/meshoptimizer-m-${version}.tar.gz",
19+
},
20+
},
21+
xpm = {
22+
linux = {
23+
["1.3"] = {
24+
url = {
25+
GLOBAL = "https://github.com/mcpplibs/meshoptimizer-m/releases/download/mwrap-1.3/meshoptimizer-m-1.3.tar.gz",
26+
CN = "https://gitcode.com/mcpp-res/mwrap-meshoptimizer/releases/download/1.3/meshoptimizer-m-1.3.tar.gz",
27+
},
28+
sha256 = "5172030f7b27b757cff2945d661e12969a191b08ed8b8ce19e70220fd3654e7e",
29+
},
30+
},
31+
macosx = {
32+
["1.3"] = {
33+
url = {
34+
GLOBAL = "https://github.com/mcpplibs/meshoptimizer-m/releases/download/mwrap-1.3/meshoptimizer-m-1.3.tar.gz",
35+
CN = "https://gitcode.com/mcpp-res/mwrap-meshoptimizer/releases/download/1.3/meshoptimizer-m-1.3.tar.gz",
36+
},
37+
sha256 = "5172030f7b27b757cff2945d661e12969a191b08ed8b8ce19e70220fd3654e7e",
38+
},
39+
},
40+
windows = {
41+
["1.3"] = {
42+
url = {
43+
GLOBAL = "https://github.com/mcpplibs/meshoptimizer-m/releases/download/mwrap-1.3/meshoptimizer-m-1.3.tar.gz",
44+
CN = "https://gitcode.com/mcpp-res/mwrap-meshoptimizer/releases/download/1.3/meshoptimizer-m-1.3.tar.gz",
45+
},
46+
sha256 = "5172030f7b27b757cff2945d661e12969a191b08ed8b8ce19e70220fd3654e7e",
47+
},
48+
},
49+
},
50+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "cgltf-inspect"
3+
version = "1.15"
4+
description = "Consume the immutable cgltf wrapper: parse a glTF document, load and validate its buffer, read its accessors, write it and parse it again"
5+
6+
[indices]
7+
# Use the complete candidate built-in index prepared by tests/run_members.sh.
8+
# An explicit empty table overrides the legacy workspace redirect.
9+
10+
[dependencies]
11+
mcpplibs.mwrap.cgltf = "1.15"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// The installed cgltf wrapper: a triangle whose buffer is in the document,
2+
// parsed, loaded, validated and read; a broken document refused with its
3+
// reason; the writer's output parsed again.
4+
import std;
5+
import mcpplibs.mwrap.cgltf;
6+
7+
namespace {
8+
9+
// Three positions (36 bytes of floats) and three 16-bit indices (6 bytes, padded to 44), as base64.
10+
constexpr std::string_view triangle = R"({
11+
"asset": {"version": "2.0"},
12+
"scene": 0,
13+
"scenes": [{"nodes": [0]}],
14+
"nodes": [{"name": "a triangle", "mesh": 0, "translation": [1, 2, 3]}],
15+
"meshes": [{"name": "tri", "primitives": [{"attributes": {"POSITION": 0}, "indices": 1, "material": 0}]}],
16+
"materials": [{"name": "red", "pbrMetallicRoughness": {"baseColorFactor": [1, 0, 0, 1], "metallicFactor": 0.25}}],
17+
"buffers": [{"byteLength": 44, "uri": "data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAAAAABAAIAAAA="}],
18+
"bufferViews": [{"buffer": 0, "byteLength": 36}, {"buffer": 0, "byteOffset": 36, "byteLength": 6}],
19+
"accessors": [
20+
{"bufferView": 0, "componentType": 5126, "count": 3, "type": "VEC3", "min": [0, 0, 0], "max": [1, 1, 0]},
21+
{"bufferView": 1, "componentType": 5123, "count": 3, "type": "SCALAR"}
22+
]
23+
})";
24+
25+
} // namespace
26+
27+
int main() {
28+
const cgltf_options options{};
29+
cgltf_data* data = nullptr;
30+
if (cgltf_parse(&options, triangle.data(), triangle.size(), &data) != cgltf_result_success) return 1;
31+
if (cgltf_load_buffers(&options, data, nullptr) != cgltf_result_success || cgltf_validate(data) != cgltf_result_success) return 2;
32+
if (data->meshes_count != 1 || data->nodes[0].mesh != &data->meshes[0] || std::string_view(data->nodes[0].name) != "a triangle") return 3;
33+
34+
const cgltf_primitive& primitive = data->meshes[0].primitives[0];
35+
const cgltf_accessor* positions = cgltf_find_accessor(&primitive, cgltf_attribute_type_position, 0);
36+
std::array<cgltf_float, 9> corners{};
37+
if (!positions || cgltf_accessor_unpack_floats(positions, corners.data(), corners.size()) != 9) return 4;
38+
if (corners != std::array<cgltf_float, 9>{0, 0, 0, 1, 0, 0, 0, 1, 0}) return 5;
39+
if (!primitive.indices || cgltf_accessor_read_index(primitive.indices, 2) != 2) return 6;
40+
if (!primitive.material || primitive.material->pbr_metallic_roughness.metallic_factor != 0.25f) return 7;
41+
std::array<cgltf_float, 16> world{};
42+
cgltf_node_transform_world(&data->nodes[0], world.data());
43+
if (world[12] != 1 || world[13] != 2 || world[14] != 3) return 8;
44+
45+
// The writer (mcpplibs.mwrap.cgltf.write, re-exported) gives a document that parses the same.
46+
std::string written(cgltf_write(&options, nullptr, 0, data), '\0');
47+
if (written.empty() || cgltf_write(&options, written.data(), written.size(), data) != written.size()) return 9;
48+
cgltf_data* again = nullptr;
49+
if (cgltf_parse(&options, written.data(), written.size() - 1, &again) != cgltf_result_success) return 10;
50+
const bool same = again->accessors_count == 2 && std::string_view(again->materials[0].name) == "red" && again->nodes[0].translation[2] == 3;
51+
cgltf_free(again);
52+
cgltf_free(data);
53+
if (!same) return 11;
54+
55+
// What is not glTF is refused with its reason.
56+
const std::string_view broken = R"({"asset": {"version": "2.0"}, "meshes": [)";
57+
const std::string_view past = R"({"asset": {"version": "2.0"}, "nodes": [{"mesh": 3}]})";
58+
cgltf_data* none = nullptr;
59+
if (cgltf_parse(&options, broken.data(), broken.size(), &none) != cgltf_result_invalid_json) return 12;
60+
if (cgltf_parse(&options, past.data(), past.size(), &none) != cgltf_result_invalid_gltf) return 13;
61+
62+
std::println("cgltf 1.15 through import mcpplibs.mwrap.cgltf: a triangle of {} positions read, written in {} bytes and parsed again", corners.size() / 3, written.size() - 1);
63+
return 0;
64+
}

0 commit comments

Comments
 (0)