x-model3d-u
5 端静态 glTF 模型查看器。运行时只吃 GLB 单文件(无 Draco / meshopt / KTX2)。
兼容性
| Harmony | IOS | Android | WEB | 小程序 |
|---|---|---|---|---|
| 支持 # | 支持 | 支持 | 支持 | 支持 |
用法
uvue
<x-model3d-u ref="viewerRef" :src="modelUrl" width="100%" height="420"
@load="onLoad" @error="onError" @progress="onProgress"></x-model3d-u>uts
viewerRef.value!.fitToScreen()
viewerRef.value!.resetView()
viewerRef.value!.load(url)统一方法:load / fitToScreen / resetView / setCamera / getCamera / snapshot / getBounds
统一事件:ready / load / error / progress
微信小程序要改两个文件,少一个都跑不起来。
pages.json 里注册原生组件(用到的页面各写一份,或写进 globalStyle 全局生效):
json
{
"globalStyle": {
"usingComponents": {
"x-model3d-xr": "/uni_modules/x-model3d-u/wxcomponents/x-model3d-xr/index"
}
}
}manifest.json 的 mp-weixin 段里打开按需注入:
json
{
"mp-weixin": {
"lazyCodeLoading": "requiredComponents"
}
}lazyCodeLoading 必须写在 manifest.json,写进 pages.json 不生效。xr-frame 是非 webview 渲染器,微信强制要求整个小程序开启按需注入,漏了会在真机和开发者工具里直接报:
text
a render renderer besides `webview` will be accepted only with `lazyCodeLoading` set to `requiredComponents`OBJ / 散装 glTF 必须先走仓库根目录 scripts/prepare_model.sh 转成无扩展纯 GLB。树叶请把 alpha blend 改成 alpha mask。回归树可用 node scripts/generate_tree_glb.mjs。
截图对比清单
| 项 | 约定 |
|---|---|
| 模型 | Helmet、tree |
| 机位 | yaw 30 / pitch 20 / fill 1.15 |
| 背景 | #1a1a1e |
| 自转 | 关 |
| 输出 | 各端 snapshot(鸿蒙、微信暂不回读像素,用真机截屏) |
包体量级
| 端 | 增量 | 备注 |
|---|---|---|
| 鸿蒙 | 0 | 系统 3D |
| 微信 | 0 | 客户端内置 |
| Web | ~1.2MB | three.module.js + addons,随插件走 |
| Android | ~7MB | 4.7MB,当前只打 arm64-v8a |
| iOS | ~4.3MB | 预置(ios-arm64) |
帧率 / 内存需真机测:建议 Helmet + tree 各看 10 秒轨道操作,记峰值 RSS 与平均 FPS。
更新日志
0.1.0(2026-08-27)
- 新增 5 端静态 GLB 查看器:Android Filament、iOS SceneKit+GLTFKit2、鸿蒙 ArkGraphics 3D、Web three.js、微信 xr-frame
- 统一 API:load / fitToScreen / resetView / setCamera / snapshot
- 离线管线:
scripts/prepare_model.sh、scripts/generate_tree_glb.mjs
