はじめに
Pyxel 3 の 3D(Pyxel Cube)は、3D の形を GLB で読み込みます。Mesh.from_glb("model.glb") の 1 行です。
では、その GLB をどう作るか。この数週間、私は 4 つの方法で作ってきました。
- Three.js の書き方で作る(Three-Live)
- Python で直接書く
- Blockbench で手で作る(公式のおすすめ)
- CC0 の素材を変換して使う
この記事では、それぞれの作り方と、つまずいたところ、確かめ方をまとめます。
GLB の仕様の細かい話(色は ×255 で一番近いパレット色になる、法線は面ごと、頂点の共有で遅くなる、など)は前の記事に書いたので、ここでは繰り返しません。
公式の説明は、ユーザーガイドの「Cube 用リソースの作成」にあります。この記事で「公式ガイド」と書くのは、この節のことです。
数値と画像は、特に書いていないものは クラウドの Linux(Pyxel 3.0.1、デスクトップ版) で測ったり描いたりしたものです。ブラウザ版や Mac では測っていません。
2026-11-12 追記:Three-Live 1.4.0 で確かめ直しました。2 章の「確かめたこと」の表、色の書き方、モーションの焼き込み(前の版では「書き出されない」と書いていましたが、焼き込めました)を直しています。
2026-11-16 追記:3 章に「trimesh を使う」、6 章に「軽くするとき(glTF-Transform)」を足しました。glTF-Transform の optimize は、そのままだと Pyxel で読めなくなったり、形が黙って欠けたりします。
2026-11-21 追記(Pyxel 3.0.3):Pyxel 3.0.3 から、GLB の材質の色(baseColorFactor)をリニアの値として読むようになりました。この記事の色の書き方(Three-Live の setRGB、Python の「値 ÷ 255」)は 3.0.1 までのものです。3.0.3 では、Three-Live は { color: 0x... } のまま、Python はリニアに直して書くと、元の色になります(2 章と 3 章に追記しました)。
1. どれを選ぶか
| Three.js(Three-Live) | Python | Blockbench | CC0 素材 | |
|---|---|---|---|---|
| 向いているもの | 丸い物、くり抜いた物 | 箱の組み合わせ、自動で大量に | キャラクター、手描きのテクスチャ | 建物や小物をすぐ使いたい |
| 作り方 | JavaScript を書く | Python を書く | マウスで作る | 変換するだけ |
| モーション | △(焼き込めるが、1 か所直す) | ○(自分で書く) | ○ | 素材による。骨で曲げる物は × |
| 気をつけること | 既定が両面。色の書き方は Pyxel の版で変わる | 面の向き。値は「置き換え」。3.0.3 は色をリニアで | 書き出しの設定 |
.gltf、0〜1 の外の UV、2 つ目の UV |
私の使い分けは、だいたいこうです。
- 形を言葉で決められる物(カップ、ドーナツ、コイン)→ Three.js
- 同じ作りの物をたくさん、または動かしたい物 → Python
- 見た目を手で整えたいキャラクター → Blockbench
- 背景を早く埋めたい → CC0 素材
2. Three.js の書き方で作る(Three-Live)
Three-Live(Apache-2.0)は、Three.js と同じ書き方で GLB などを作れるライブラリです。Node.js で動くので、ブラウザがなくても GLB が書き出せます。
検証には、dist/three-author.cjs と dist/three-live-cad.cjs を使いました。版は 2 つです。
- 1.2.3(コミット 1df55fe)
- 1.4.0(コミット e9130e9)。ソースから作り直したもの
入手方法(npm、Releases の zip、ソースからのビルド)はリポジトリの README にあります。
リポジトリを git pull で新しくしても、dist/ は古いままです。npm run build で作り直さないと、新しい版にはなりません(私はここで一度、古い版のまま確かめかけました)。
カップを作る
円柱から円柱をくり抜いて(CSG)、カップにします。
// node cup.cjs -> cup.glb (Three-Live 1.2.3 / 1.4.0: dist/three-author.cjs + dist/three-live-cad.cjs)
// SPDX-License-Identifier: MIT
const fs = require('fs');
const A = require('./three-author.cjs');
const THREE = A.THREE || A;
require('./three-live-cad.cjs').installCadExtension(THREE); // adds THREE.CSG
// colour: setRGB keeps Pyxel's palette value as is (from 1.4.0, { color: 0x... } is turned into linear colour)
const pyxel = (hex) => new THREE.Color().setRGB((hex >> 16 & 255) / 255, (hex >> 8 & 255) / 255, (hex & 255) / 255);
// single-sided: side 0 (= THREE.FrontSide from 1.4.0) and doubleSided false; the default is double-sided
const mat = (hex) => new THREE.MeshStandardMaterial({ color: pyxel(hex), side: 0, doubleSided: false });
const scene = new THREE.Scene();
const outer = new THREE.Mesh(new THREE.CylinderGeometry(6, 5, 8, 24), mat(0xEEEEEE));
const inner = new THREE.Mesh(new THREE.CylinderGeometry(5, 4, 8, 24), mat(0xEEEEEE));
inner.position.y = 1; // hollow from the top, keep the bottom
const cup = THREE.CSG.subtract(outer, inner);
cup.name = 'Cup';
cup.position.y = 4;
scene.add(cup);
const saucer = new THREE.Mesh(new THREE.CylinderGeometry(10, 8, 1, 24), mat(0x7696DE));
saucer.name = 'Saucer';
scene.add(saucer);
fs.writeFileSync('cup.glb', Buffer.from(scene.toGLB()));
console.log('cup.glb', fs.statSync('cup.glb').size, 'bytes');
node cup.cjs
確かめたこと
| 試したこと | 1.2.3 | 1.4.0 |
|---|---|---|
色 { color: 0xD38441 }
|
211, 132, 65 のまま入る | 166, 59, 13 に変わる(下の「色」) |
色 new THREE.Color().setRGB(r/255, g/255, b/255)
|
211, 132, 65 のまま | 211, 132, 65 のまま |
| 何も指定しない材質 | doubleSided: true(両面) |
同じ(両面) |
side: THREE.FrontSide |
THREE.FrontSide is unsupported; degraded to no-op proxy. と出て、両面のまま |
片面になる |
side: 0, doubleSided: false |
片面になる(上のコード) | 片面になる |
OctahedronGeometry(正八面体) |
OctahedronGeometry is unsupported; degraded to SphereGeometry と出て、球に置き換わる(一番上の画像の右から 2 番目) |
本物の正八面体(三角形 8 枚) |
AnimationClip と QuaternionKeyframeTrack
|
何も起きない。GLB のアニメーションは 0 本 | 「unsupported; degraded to no-op proxy」と出て、0 本 |
動きを焼き込む(animateFn) |
書き出される。ただしそのままでは Pyxel が読めない(下の「モーション」) | 同じ |
頂点カラー(color 属性) |
書き出されない |
COLOR_0 として書き出される。Pyxel では色に使われず、警告が 1 つ出る |
| くり抜き(CSG) |
THREE.CSG.subtract(a, b) で使える。くり抜いた面も外向きで、片面にしても欠けない |
同じ(カップの三角形は 692 → 500 枚) |
| 書き出した GLB(カップ) | Khronos の glTF Validator でエラー 0、Pyxel の警告 0 | 同じ |
色:1.4.0 は 0x... の書き方でずれる
Pyxel 3.0.3 では逆になります。 3.0.3 は GLB の色をリニアとして読むので、{ color: 0xD38441 }(Three-Live がリニアに直して書く)がそのまま元の色になり、setRGB(r / 255, ...) で書いた方が薄い色にずれます。この節とカップのコードは 3.0.1 での結果です。
1.4.0 では、{ color: 0xD38441 } のように書いた色を、書き出すときに「リニア」という形の色に変えます。glTF の決まりとしては正しい動きです。
でも Pyxel は、GLB に書かれた色をそのまま 255 倍して、一番近いパレットの色にします。そのため、オレンジ(9 番)が茶色っぽい色(4 番)になりました。記事のカップの皿も、0x7696DE(12 番)が 5 番になります。
new THREE.Color().setRGB(r / 255, g / 255, b / 255) で色を作ると、数字がそのまま書き出されて、元の色になります。上のカップのコードは、この形にしてあります(1.2.3 でも同じ結果です)。
モーション:焼き込めるが、1 か所直す
AnimationClip は使えませんが、Three-Live には「時間を渡すと形を動かす関数」を書いておくと、書き出すときに動きを焼き込む機能があります(1.2.3 にもありました。前の版のこの記事では見落としていました)。
// node anim.cjs -> anim.glb : a box that turns and hops, baked by Three-Live (then fix it for Pyxel)
const fs = require('fs');
const A = require('./three-author.cjs');
const THREE = A.THREE || A;
const scene = new THREE.Scene();
const box = new THREE.Mesh(new THREE.BoxGeometry(4, 4, 4),
new THREE.MeshStandardMaterial({ color: new THREE.Color().setRGB(0x19 / 255, 0x95 / 255, 0x9C / 255), side: 0, doubleSided: false }));
box.name = 'Box';
scene.add(box);
// called for every sampled time t (seconds) while the GLB is written
const animate = (t) => { box.rotation.y = t * Math.PI; box.position.y = Math.abs(Math.sin(t * Math.PI)) * 3; };
const glb = A.sceneToGLB(scene, { animateFn: animate, duration: 2, fps: 30 });
fs.writeFileSync('anim.glb', Buffer.from(glb));
console.log('anim.glb', glb.length, 'bytes');
sceneToGLB に animateFn(動かす関数)、duration(秒)、fps を渡します。何も渡さずに scene.toGLB() を使ったときは、scene.userData.animate があれば、それを 4 秒・15 fps で焼き込みます。
ただし、できた GLB を Pyxel 3.0.1 で読むと、こうなります。
invalid glTF: bufferViews[4].target: Invalid value; bufferViews[5].target: Invalid value; ...
アニメーションのデータに、glTF では使えない "target": 0 という印が付いているためです。Validator では警告だけですが、Pyxel はファイル全体を読みません。
この印を消せば読めます。5 章の glb_for_pyxel.py に、この直しを入れました。
node anim.cjs
python glb_for_pyxel.py anim.glb anim_fixed.glb
直した anim_fixed.glb は、1.2.3 でも 1.4.0 でも、Pyxel でモーション ProceduralLoop(60 フレーム)として読み込まれました。Validator もエラー 0・警告 0 です。
両面だと何が困るかは、6 章で測っています。片面にできる物は片面にした方が速いです。
1.2.3 で正八面体が欲しいときは、Python で書きました(一番上の画像の右端)。1.4.0 なら Three-Live でも作れます。
パーツごとに細かく動かしたい物は、Python か Blockbench で作っています。
1.5.0 でも、色(0x... がリニアになる)、既定の両面、モーションの "target": 0 は、1.4.0 と同じ結果でした(2026-11-21)。
3. Python で直接書く
GLB は「JSON + バイナリ」を 1 つにしたファイルです。numpy と標準ライブラリだけで書けます。
下は、箱を組み合わせたロボットに、首を振るモーションを 1 本付けて書き出す例です。100 行ほどです。
mini_glb.py(全文)
"""The smallest useful GLB writer for Pyxel 3: coloured boxes in a node tree, plus one animation.
Only numpy and the standard library. python mini_glb.py -> robot.glb
"""
# SPDX-License-Identifier: MIT
import json
import struct
import numpy as np
PAL = [0x000000, 0x2B335F, 0x7E2072, 0x19959C, 0x8B4852, 0x395C98, 0xA9C1FF, 0xEEEEEE,
0xD4186C, 0xD38441, 0xE9C35B, 0x70C6A9, 0x7696DE, 0xA3A3A3, 0xFF9798, 0xEDC7B0] # Pyxel's 16 colours
def box(sx, sy, sz, y0=0.0):
"""A box from y0 up, 24 vertices (flat normals), faces wound counter-clockwise seen from outside."""
P, N, I = [], [], []
for n, u, v in (((1, 0, 0), (0, 0, -1), (0, 1, 0)), ((-1, 0, 0), (0, 0, 1), (0, 1, 0)),
((0, 1, 0), (1, 0, 0), (0, 0, -1)), ((0, -1, 0), (1, 0, 0), (0, 0, 1)),
((0, 0, 1), (1, 0, 0), (0, 1, 0)), ((0, 0, -1), (-1, 0, 0), (0, 1, 0))):
n, u, v = map(np.array, (n, u, v))
b = len(P)
for a, c in ((-1, -1), (1, -1), (1, 1), (-1, 1)):
P.append((n + a * u + c * v) * 0.5)
N.append(n)
I += [b, b + 1, b + 2, b, b + 2, b + 3]
P = np.array(P) * (sx, sy, sz) + (0, y0 + sy / 2, 0)
return P.astype(np.float32), np.array(N, np.float32), np.array(I, np.uint16)
class GLB:
def __init__(self):
self.j = {"asset": {"version": "2.0"}, "scene": 0, "scenes": [{"nodes": []}], "nodes": [], "meshes": [],
"materials": [], "accessors": [], "bufferViews": [], "animations": []}
self.bin = bytearray()
def acc(self, arr, typ, minmax=False):
while len(self.bin) % 4:
self.bin.append(0)
self.j["bufferViews"].append({"buffer": 0, "byteOffset": len(self.bin), "byteLength": arr.nbytes})
self.bin += arr.tobytes()
a = {"bufferView": len(self.j["bufferViews"]) - 1, "count": len(arr), "type": typ,
"componentType": 5123 if arr.dtype == np.uint16 else 5126}
if minmax:
a["min"], a["max"] = np.atleast_1d(arr.min(0)).tolist(), np.atleast_1d(arr.max(0)).tolist()
self.j["accessors"].append(a)
return len(self.j["accessors"]) - 1
def node(self, name, geo=None, col=0, t=(0, 0, 0), parent=None):
nd = {"name": name, "translation": list(t)}
if geo is not None:
c = PAL[col] # colour = palette value / 255 -> exact palette match
self.j["materials"].append({"pbrMetallicRoughness": {
"baseColorFactor": [(c >> 16 & 255) / 255, (c >> 8 & 255) / 255, (c & 255) / 255, 1.0],
"metallicFactor": 0.0, "roughnessFactor": 1.0}})
P, N, I = geo
self.j["meshes"].append({"primitives": [{"attributes": {"POSITION": self.acc(P, "VEC3", True),
"NORMAL": self.acc(N, "VEC3")},
"indices": self.acc(I, "SCALAR"),
"material": len(self.j["materials"]) - 1}]})
nd["mesh"] = len(self.j["meshes"]) - 1
self.j["nodes"].append(nd)
i = len(self.j["nodes"]) - 1
if parent is None:
self.j["scenes"][0]["nodes"].append(i)
else:
self.j["nodes"][parent].setdefault("children", []).append(i)
return i
def anim(self, name, node, path, times, values):
"""path: 'translation' / 'rotation' (x, y, z, w) / 'scale'. Values REPLACE the node's own value."""
a = {"name": name, "samplers": [], "channels": []}
a["samplers"].append({"input": self.acc(np.array(times, np.float32), "SCALAR", True),
"output": self.acc(np.array(values, np.float32), "VEC4" if path == "rotation" else "VEC3")})
a["channels"].append({"sampler": 0, "target": {"node": node, "path": path}})
self.j["animations"].append(a)
def save(self, path):
while len(self.bin) % 4:
self.bin.append(0)
self.j["buffers"] = [{"byteLength": len(self.bin)}]
j = {k: v for k, v in self.j.items() if v != []} # glTF does not allow empty arrays
js = json.dumps(j, separators=(",", ":")).encode()
js += b" " * (-len(js) % 4)
with open(path, "wb") as f:
f.write(struct.pack("<III", 0x46546C67, 2, 28 + len(js) + len(self.bin)))
f.write(struct.pack("<II", len(js), 0x4E4F534A) + js)
f.write(struct.pack("<II", len(self.bin), 0x004E4942) + bytes(self.bin))
def quat_y(deg):
r = np.radians(deg) / 2
return [0.0, float(np.sin(r)), 0.0, float(np.cos(r))]
g = GLB()
body = g.node("Body", box(10, 12, 6, y0=6), col=12) # +Z is the front, 1 = 1 cm
head = g.node("Head", box(8, 7, 7), col=15, t=(0, 18, 0), parent=body)
g.node("Eye", box(4, 1.5, 1), col=8, t=(0, 3, 3.6), parent=head)
for x in (-3, 3):
g.node("Leg", box(3, 6, 3), col=5, t=(x, 0, 0), parent=body)
g.anim("look", head, "rotation", [0, 0.5, 1.0, 1.5, 2.0],
[quat_y(0), quat_y(40), quat_y(0), quat_y(-40), quat_y(0)])
g.save("robot.glb")
print("robot.glb", len(g.bin), "bytes of data")
python mini_glb.py
Pyxel 3.0.3 では、色をリニアに直して書きます。 3.0.1 までは「値 ÷ 255」でパレットの色にぴったり一致しましたが、3.0.3 ではこのままだと 16 色中 14 色がずれます。baseColorFactor の行を、次のように変えてください。
def lin(v): # sRGB (0-255) -> linear (0-1)
v /= 255
return v / 12.92 if v <= 0.04045 else ((v + 0.055) / 1.055) ** 2.4
"baseColorFactor": [lin(c >> 16 & 255), lin(c >> 8 & 255), lin(c & 255), 1.0],
できる robot.glb は 7,232 バイト、三角形 60 枚です。Validator のエラー 0、Pyxel の警告 0 で、モーション look(60 フレーム)が読み込まれます。
ハマったところ
面の向き。 外から見て反時計回りに頂点を並べます。逆にすると、その面は消えます(6 章)。
モーションの値は「置き換え」。 glTF のアニメーションは、ノードの translation や rotation を上書きします。「元の位置からどれだけ動かすか」ではありません。たとえば元の位置が (0, 18, 0) のパーツを上下に揺らすなら、(0, 18, 0)、(0, 19, 0) …と、元の位置を足した値を書きます。
時間は秒で書く。 Pyxel が読み込むときにフレームに変わります。上の例では 2 秒 → 60 フレームでした。
Validator に怒られたこと。
| 書いたもの | Validator の結果 | 直し方 |
|---|---|---|
1 要素(SCALAR)の min / max を数値で書いた |
エラー |
[0.0] のように配列にする |
空の "animations": []
|
EMPTY_ENTITY |
空の配列は書かない |
どちらも Pyxel は読み込めました。ただ、ほかのツールで開いたときに困るかもしれないので、直しています。
大きくするとき
ゲームで使うときは、上の mini_glb.py に機能を足したものを使っています。足したのは次のことです。
- 同じ色の面を 1 つの材質にまとめる(材質の数を減らす)
- 面の向きを自動で直す
- 小さなテクスチャを 1 枚にまとめる(アトラス)。PNG も自前で書く
一番上の画像の中段(うさぎ、いちご)は、これで作りました。うさぎは三角形 2,396 枚、モーションは idle 60・walk 18・jump 15 フレームです。
ほかに、trimesh と pygltflib を使って作ったこともあります。ただ、頂点カラーで色を付けると Pyxel では色が出ません(公式ガイドにも「反映されない」とあります)。色は材質の色か、テクスチャで付けます。
trimesh を使う
形を自分で組むのが面倒なら、Python のライブラリ trimesh(MIT)が使えます。回転体(revolve)、トーラス、箱などを作って、そのまま GLB に書き出せます。
# python cup_trimesh.py -> cup_trimesh.glb (trimesh; Pyxel 3.0.1)
# SPDX-License-Identifier: MIT
import numpy as np
import trimesh
from trimesh.visual import TextureVisuals
from trimesh.visual.material import PBRMaterial
def mat(hex_):
# baseColorFactor = palette colour / 255 as is (Pyxel picks the nearest palette colour)
rgb = [(hex_ >> 16) & 255, (hex_ >> 8) & 255, hex_ & 255, 255]
return PBRMaterial(baseColorFactor=rgb, metallicFactor=0.0,
roughnessFactor=1.0, doubleSided=False)
def paint(mesh, hex_):
mesh.visual = TextureVisuals(material=mat(hex_)) # vertex colours are ignored by Pyxel
return mesh
# cup: profile (radius, height) from the bottom centre, round the outside, back down the inside
profile = [(0, 0), (5, 0), (6, 8), (5, 8), (4, 1), (0, 1)]
cup = trimesh.creation.revolve(np.array(profile), sections=24)
cup.apply_translation([0, 0, 0.5])
# revolve() turns around Z; Pyxel's up is +Y
cup.apply_transform(trimesh.transformations.rotation_matrix(-np.pi / 2, [1, 0, 0]))
# handle: half of a torus on the +X side
handle = trimesh.creation.torus(major_radius=2.2, minor_radius=0.6,
major_sections=16, minor_sections=8)
v = handle.vertices
handle.update_faces(np.all(v[handle.faces][:, :, 0] >= -0.01, axis=1))
handle.remove_unreferenced_vertices()
handle.apply_transform(trimesh.transformations.rotation_matrix(np.pi / 2, [1, 0, 0]))
handle.apply_translation([5.4, 5.0, 0])
saucer = trimesh.creation.revolve(np.array([(0, 0), (8, 0), (10, 1), (0, 1)]), sections=24)
saucer.apply_transform(trimesh.transformations.rotation_matrix(-np.pi / 2, [1, 0, 0]))
scene = trimesh.Scene()
scene.add_geometry(paint(cup, 0xEEEEEE), node_name="Cup")
scene.add_geometry(paint(handle, 0xEEEEEE), node_name="Handle")
scene.add_geometry(paint(saucer, 0x7696DE), node_name="Saucer")
scene.export("cup_trimesh.glb")
print("cup_trimesh.glb", len(open("cup_trimesh.glb", "rb").read()), "bytes")
- 三角形 416、9,752 B。Pyxel の警告 0、Khronos glTF Validator もエラー 0・警告 0 でした。
- 色は
TextureVisuals(material=PBRMaterial(baseColorFactor=...))で付けます。trimesh でよく使う頂点カラー(ColorVisuals)は、Pyxel が無視するので使えません。 -
doubleSided=Falseで片面になります。 - trimesh の回転体は Z 軸のまわりに回るので、Pyxel の上(+Y)に向けるために X 軸で -90 度回しています。
4. Blockbench で手で作る
公式のおすすめは Blockbench です。手順は公式ガイドに詳しくあるので、要点だけ書きます。
- Generic Model 形式で作る。動かすパーツはグループに分ける
- Pyxel のパレット(
pyxel.gpl)を Paint モードの Import Palette で読む(Replace old palette を有効に)。Lock Palette で色の追加・削除や並べ替えを防げる - 不透明度 100%、ぼかし 0 で描く
- 書き出しは File → Export → Export glTF Model から Binary (glb)
- Embed Textures:有効
- Export Groups as Armature:無効
- Export Animations:モーションを入れるなら有効
確かめたこと
Blockbench 5.2.2 で書き出した GLB を、Pyxel 3.0.1 で読みました。
| GLB | 三角形 | 材質 | モーション | Pyxel の警告 |
|---|---|---|---|---|
| ねこ | 508 | MASK・両面 × 1 | idle 60、walk 24、jump 30 フレーム | 0 |
| 庭のステージ | 1,860 | MASK・両面 × 16 | なし | 0 |
一番上の画像の下段が、このねこと庭です。材質は MASK(切り抜き)で、両面で書き出されていました。箱だけでできている物なら、片面にすると速くなります(6 章)。
5. CC0 の素材を変換して使う
すぐに背景を作りたいときは、CC0 の素材が助かります。ここでは Quaternius の Medieval Village MegaKit(CC0)の 43 パーツで試しました。そのままでは使えない理由が 3 つありました。
その 1:.gltf は読めない
キットの中身は .gltf(JSON)と .bin と PNG に分かれています。そのまま読むと、こうなります。
GLB binary header is required
公式ガイドにも「外部ファイルを参照する GLB は読み込めない」とあります。1 つの GLB にまとめる必要があります。
その 2:使わないデータで警告が出る
まとめた GLB を読むと、壁のパーツで GLB unsupported vertex attribute が 2 つ出ました。2 つ目の UV(TEXCOORD_1)です。Pyxel は最初の UV しか使わないので、見た目は変わりません。消せば警告も消えます。
その 3:0〜1 の外の UV は「繰り返し」にならない
これが一番大きな違いでした。43 パーツのうち 30 パーツ で、UV が 0〜1 の外に出ていました。普通の 3D ソフトでは、テクスチャが繰り返して貼られます。
公式ガイドには、こうあります。
0〜1 の範囲外の UV 座標は画像の端に固定されます。
8×8 の画像(左半分が赤、右半分が青)を、UV 0〜1 と 0〜3 の板に貼って確かめました。glTF のサンプラーで繰り返し(REPEAT)を指定していても、端の色が伸びるだけでした。
屋根で見ると、こうなります。
公式ガイドの通り「繰り返す模様は画像に描き込み、UV を 0〜1 に収め」れば直ります。下のスクリプトの --repeat は、これを自動でします。テクスチャを必要な回数だけ並べた画像を作り、UV をその中に収めます。
その代わり、画像は大きくなります。この屋根では、256×256 の画像が 1280×256 と 1024×512 になり、GLB は 289,912 → 585,244 バイトになりました。
まとめて直すスクリプト
上の 3 つ(+両面を片面にする、2 章の Three-Live のモーションを直す)を 1 本にしたものです。numpy と Pillow を使います。
glb_for_pyxel.py(全文)
"""Turn a .gltf / .glb into a GLB that Pyxel 3 (pyxel.cube) loads cleanly.
python glb_for_pyxel.py in.gltf out.glb pack (+ .bin + images) into one GLB, clean it
python glb_for_pyxel.py in.glb out.glb --repeat also bake repeated textures (UV outside 0..1)
python glb_for_pyxel.py in.glb out.glb --single also set doubleSided to false (faster)
options: --tex 256 longest side of the packed images (only when packing a .gltf)
What it does
pack : .gltf + .bin + images -> one GLB. Only base colour images are kept (downscaled);
normal / occlusion / emissive / metal-rough maps are dropped (Pyxel does not use them).
clean : drops TEXCOORD_1 and COLOR_0, turns BLEND into OPAQUE, sets alpha factor to 1.
Pyxel ignores these anyway; removing them only removes the load warnings.
Also removes "target": 0 from buffer views (Three-Live writes it for baked motions;
it is not a valid glTF value and Pyxel refuses the whole file).
--repeat : Pyxel clamps UVs to 0..1. The image is repeated nx * ny times and the UVs scaled back
into 0..1, so it looks like a repeating texture. The image gets nx * ny times bigger.
--single : doubleSided false on every material. Faces seen from behind disappear, so use it only
when every face points outwards (closed boxes etc.), and look at the result.
Needs numpy and Pillow. Not handled: skins (Pyxel ignores them), sparse accessors, KTX/WebP images.
"""
# SPDX-License-Identifier: MIT
import io
import json
import math
import struct
import sys
from pathlib import Path
import numpy as np
from PIL import Image
def read_glb(data):
if data[:4] != b"glTF":
raise ValueError("not a GLB")
n = struct.unpack_from("<I", data, 12)[0]
j = json.loads(data[20:20 + n])
rest = data[20 + n:]
blob = bytearray(rest[8:8 + struct.unpack_from("<I", rest, 0)[0]]) if len(rest) >= 8 else bytearray()
return j, blob
def write_glb(j, blob):
while len(blob) % 4:
blob.append(0)
j["buffers"] = [{"byteLength": len(blob)}]
js = json.dumps(j, separators=(",", ":")).encode()
js += b" " * (-len(js) % 4)
head = struct.pack("<III", 0x46546C67, 2, 28 + len(js) + len(blob))
return head + struct.pack("<II", len(js), 0x4E4F534A) + js + struct.pack("<II", len(blob), 0x004E4942) + bytes(blob)
def add_view(j, blob, data):
while len(blob) % 4:
blob.append(0)
j["bufferViews"].append({"buffer": 0, "byteOffset": len(blob), "byteLength": len(data)})
blob.extend(data)
return len(j["bufferViews"]) - 1
def view_bytes(j, blob, vi):
bv = j["bufferViews"][vi]
o = bv.get("byteOffset", 0)
return bytes(blob[o:o + bv["byteLength"]])
def png_bytes(im):
b = io.BytesIO()
im.save(b, "PNG", optimize=True)
return b.getvalue()
def pack(path, tex=256):
""".gltf with external .bin / images -> (json, one binary blob)."""
p = Path(path)
j = json.loads(p.read_text(encoding="utf-8"))
bins = [(p.parent / b["uri"]).read_bytes() for b in j["buffers"]]
used = set()
for m in j.get("materials", []):
pbr = m.get("pbrMetallicRoughness", {})
if "baseColorTexture" in pbr:
used.add(j["textures"][pbr["baseColorTexture"]["index"]]["source"])
for k in ("normalTexture", "occlusionTexture", "emissiveTexture"):
m.pop(k, None)
pbr.pop("metallicRoughnessTexture", None)
views, blob = j.get("bufferViews", []), bytearray()
j["bufferViews"] = []
for bv in views:
o = bv.get("byteOffset", 0)
k = add_view(j, blob, bins[bv["buffer"]][o:o + bv["byteLength"]])
if "byteStride" in bv:
j["bufferViews"][k]["byteStride"] = bv["byteStride"]
if "target" in bv:
j["bufferViews"][k]["target"] = bv["target"]
images = []
for i, im in enumerate(j.get("images", [])):
if i in used:
src = Image.open(p.parent / im["uri"]).convert("RGBA")
src.thumbnail((tex, tex), Image.LANCZOS)
else: # unused (normal map etc.): a 1x1 grey placeholder
src = Image.new("RGBA", (1, 1), (128, 128, 128, 255))
images.append({"bufferView": add_view(j, blob, png_bytes(src)), "mimeType": "image/png"})
if images:
j["images"] = images
return j, blob
def clean(j):
for bv in j.get("bufferViews", []):
if bv.get("target") not in (None, 34962, 34963):
del bv["target"]
for m in j.get("meshes", []):
for p in m["primitives"]:
for k in ("TEXCOORD_1", "COLOR_0"):
p["attributes"].pop(k, None)
for m in j.get("materials", []):
if m.get("alphaMode") == "BLEND":
m["alphaMode"] = "OPAQUE"
f = m.get("pbrMetallicRoughness", {}).get("baseColorFactor")
if f and len(f) == 4:
f[3] = 1.0
def repeat(j, blob):
changed = 0
for mesh in j.get("meshes", []):
for p in mesh["primitives"]:
mat = j["materials"][p["material"]] if "material" in p else None
tex = mat and mat.get("pbrMetallicRoughness", {}).get("baseColorTexture")
if not tex or "TEXCOORD_0" not in p["attributes"]:
continue
acc = j["accessors"][p["attributes"]["TEXCOORD_0"]]
if acc.get("componentType") != 5126 or "sparse" in acc:
continue
bv = j["bufferViews"][acc["bufferView"]]
stride = bv.get("byteStride", 8)
raw = view_bytes(j, blob, acc["bufferView"])
o = acc.get("byteOffset", 0)
uv = np.array([np.frombuffer(raw, np.float32, 2, o + k * stride) for k in range(acc["count"])])
u0, v0 = math.floor(uv[:, 0].min() + 1e-4), math.floor(uv[:, 1].min() + 1e-4)
u1, v1 = math.ceil(uv[:, 0].max() - 1e-4), math.ceil(uv[:, 1].max() - 1e-4)
nx, ny = max(1, u1 - u0), max(1, v1 - v0)
if (u0, v0, nx, ny) == (0, 0, 1, 1):
continue
src = j["images"][j["textures"][tex["index"]]["source"]]
im = Image.open(io.BytesIO(view_bytes(j, blob, src["bufferView"]))).convert("RGBA")
big = Image.new("RGBA", (im.width * nx, im.height * ny))
for y in range(ny):
for x in range(nx):
big.paste(im, (x * im.width, y * im.height))
j["images"].append({"bufferView": add_view(j, blob, png_bytes(big)), "mimeType": "image/png"})
j["textures"].append(dict(j["textures"][tex["index"]], source=len(j["images"]) - 1))
new_mat = json.loads(json.dumps(mat))
new_mat["pbrMetallicRoughness"]["baseColorTexture"]["index"] = len(j["textures"]) - 1
j["materials"].append(new_mat)
p["material"] = len(j["materials"]) - 1
uv[:, 0] = (uv[:, 0] - u0) / nx
uv[:, 1] = (uv[:, 1] - v0) / ny
new = dict(acc, bufferView=add_view(j, blob, uv.astype(np.float32).tobytes()), byteOffset=0,
min=[float(uv[:, 0].min()), float(uv[:, 1].min())],
max=[float(uv[:, 0].max()), float(uv[:, 1].max())])
j["accessors"].append(new)
p["attributes"]["TEXCOORD_0"] = len(j["accessors"]) - 1
changed += 1
return changed
def main(argv):
args = [a for a in argv if not a.startswith("--")]
src, dst = args[0], args[1]
tex = int(argv[argv.index("--tex") + 1]) if "--tex" in argv else 256
if "--tex" in argv:
args.remove(str(tex))
if src.lower().endswith(".gltf"):
j, blob = pack(src, tex)
else:
j, blob = read_glb(Path(src).read_bytes())
clean(j)
note = ""
if "--repeat" in argv:
note += " %d primitive(s) repeated" % repeat(j, blob)
if "--single" in argv:
for m in j.get("materials", []):
m["doubleSided"] = False
out = write_glb(j, blob)
Path(dst).write_bytes(out)
print(dst, len(out), "bytes" + note)
if __name__ == "__main__":
main(sys.argv[1:])
python glb_for_pyxel.py Roof_RoundTiles_4x6.gltf roof.glb --repeat
43 パーツすべてで、変換後の Pyxel の警告は 0、Validator のエラーも 0 でした(--repeat を付けた屋根でも 0)。
骨で曲げるキャラクターは動かない
Quaternius の Universal Animation Library(CC0)のマネキン(7.6 MB)を読むと、モーション 43 本は読み込まれます。でも、体は曲がりません。
Pyxel warning: GLB skins are not supported; skinning is ignored
公式ガイドにも「…反映されないため、腕や脚などは別パーツにして動かします」とあります。キャラクターを動かすなら、パーツを分けて作るか、自分で頂点を動かします。私が VRM でやった方法(骨ごとに硬い部品に分ける、CPU で頂点を動かす)は、こちらに書きました。
6. どの道でも同じ確かめ方
Validator だけでは足りない
Khronos の glTF Validator は、ファイルの形が正しいかを調べます。ただ、Pyxel で困ることの多くは、Validator ではエラーになりません。
たとえば、立方体の前の面だけ頂点の順番を逆にしたもの。Validator はエラー 0 です。でも Pyxel で描くと、前の面が消えます。
逆に、Validator がエラーを出すファイルでも、Pyxel は読み込めることがありました。反対に、Validator では警告だけなのに、Pyxel がファイルごと読まないものもありました(2 章の Three-Live のモーション)。
Pyxel 向けのチェック
そこで、Pyxel 3 で困ることだけを調べるスクリプトを作りました。numpy だけ使います。
pyxel_glb_check.py(全文)
"""Check a GLB against what Pyxel 3's Mesh.from_glb can use. Prints one line per problem.
python pyxel_glb_check.py model.glb [more.glb ...]
"""
# SPDX-License-Identifier: MIT
import io
import json
import struct
import sys
import numpy as np
def read(j, binc, ai, comps):
"""A float32 / unsigned index accessor as a numpy array (no sparse, no normalised ints)."""
a = j["accessors"][ai]
bv = j["bufferViews"][a["bufferView"]]
dt = {5126: np.float32, 5125: np.uint32, 5123: np.uint16, 5121: np.uint8}[a["componentType"]]
o = bv.get("byteOffset", 0) + a.get("byteOffset", 0)
stride = bv.get("byteStride")
size = np.dtype(dt).itemsize * comps
if stride and stride != size:
rows = [np.frombuffer(binc, dt, comps, o + k * stride) for k in range(a["count"])]
return np.array(rows)
return np.frombuffer(binc, dt, a["count"] * comps, o).reshape(-1, comps) if comps > 1 else \
np.frombuffer(binc, dt, a["count"], o)
def count_flipped(j, binc, p):
"""Triangles whose winding disagrees with the stored vertex normals."""
at = p["attributes"]
if "NORMAL" not in at or "indices" not in p:
return 0
try:
P = read(j, binc, at["POSITION"], 3).astype(np.float64)
N = read(j, binc, at["NORMAL"], 3).astype(np.float64)
I = read(j, binc, p["indices"], 1).astype(np.int64).reshape(-1, 3)
except (KeyError, ValueError):
return 0
f = np.cross(P[I[:, 1]] - P[I[:, 0]], P[I[:, 2]] - P[I[:, 0]])
nn = N[I].sum(1)
big = np.linalg.norm(f, axis=1) > 1e-9
return int(((np.sum(f * nn, 1) < 0) & big).sum())
def check(path):
data = open(path, "rb").read()
out = []
if data[:4] != b"glTF":
return ["not a GLB (a .gltf with separate files has to be packed into one .glb)"]
n = struct.unpack_from("<I", data, 12)[0]
j = json.loads(data[20:20 + n])
binc = data[28 + n:]
for b in j.get("buffers", []):
if "uri" in b:
out.append("external buffer: " + b["uri"])
for im in j.get("images", []):
if "uri" in im:
out.append("external image: " + im["uri"][:40])
if "KHR_animation_pointer" in j.get("extensionsUsed", []):
out.append("KHR_animation_pointer: every animation is ignored")
if j.get("skins"):
out.append("%d skin(s): ignored, the mesh will not bend" % len(j["skins"]))
for i, nd in enumerate(j.get("nodes", [])):
if "matrix" in nd:
out.append("node %s uses a matrix (decomposed, with a warning)" % nd.get("name", i))
for m in j.get("materials", []):
if m.get("alphaMode") == "BLEND":
out.append("material %s: BLEND is drawn opaque" % m.get("name", "?"))
if m.get("doubleSided"):
out.append("material %s: doubleSided (slower; set false if the faces point outwards)" % m.get("name", "?"))
for mi, mesh in enumerate(j.get("meshes", [])):
for p in mesh["primitives"]:
if p.get("mode", 4) != 4:
out.append("mesh %s: mode %d (only triangles load)" % (mesh.get("name", mi), p["mode"]))
extra = [a for a in p["attributes"] if a not in ("POSITION", "NORMAL", "TEXCOORD_0")]
if extra:
out.append("mesh %s: ignored attributes %s" % (mesh.get("name", mi), ",".join(extra)))
if p.get("targets"):
out.append("mesh %s: %d morph targets (ignored)" % (mesh.get("name", mi), len(p["targets"])))
flipped = count_flipped(j, binc, p)
if flipped:
out.append("mesh %s: %d triangle(s) face the other way from their normals (they vanish when "
"single-sided)" % (mesh.get("name", mi), flipped))
uv = p["attributes"].get("TEXCOORD_0")
if uv is not None and "material" in p:
mat = j["materials"][p["material"]]
if "baseColorTexture" in mat.get("pbrMetallicRoughness", {}):
a = j["accessors"][uv]
lo, hi = a.get("min"), a.get("max")
if lo is None and "bufferView" in a and a.get("componentType") == 5126:
bv = j["bufferViews"][a["bufferView"]]
o = bv.get("byteOffset", 0) + a.get("byteOffset", 0)
arr = np.frombuffer(binc, np.float32, a["count"] * 2, o)
lo, hi = [float(arr.min())] * 2, [float(arr.max())] * 2
if lo and (min(lo) < -0.001 or max(hi) > 1.001):
out.append("mesh %s: UV %.2f..%.2f (Pyxel clamps, it does not repeat)" % (
mesh.get("name", mi), min(lo), max(hi)))
return out
if __name__ == "__main__":
for f in sys.argv[1:]:
res = check(f)
print("%-34s %s" % (f.split("/")[-1], "OK" if not res else ""))
seen = set()
for r in res:
key = r.split(":")[0].split(" ")[0] + r.split(":")[-1]
if key not in seen:
seen.add(key)
print(" - " + r)
調べることは次の通りです。
| 調べること | 起きること(公式ガイド・実測) |
|---|---|
| GLB でない、外部ファイル | 読めない |
KHR_animation_pointer |
アニメーションが全部無視される |
| スキン、モーフ | 曲がらない。モーフのアニメーションがあると読めない |
BLEND |
透明部分も不透明で描かれる |
doubleSided |
両面で描く(遅くなる) |
| 三角形以外 | 読めない |
TEXCOORD_1、COLOR_0 など |
無視される(警告が出る) |
| 法線と逆向きの三角形 | 片面だと消える |
| 0〜1 の外の UV | 繰り返さず、端で止まる |
実行すると、こう出ます(wall_raw.glb は、壁のパーツを 1 つの GLB にまとめただけで、まだ直していないもの)。
$ python pyxel_glb_check.py robot.glb cube_badfront.glb wall_raw.glb
robot.glb OK
cube_badfront.glb
- mesh 0: 2 triangle(s) face the other way from their normals (they vanish when single-sided)
wall_raw.glb
- material MI_WoodTrim: doubleSided (slower; set false if the faces point outwards)
- mesh Cube.027: ignored attributes TEXCOORD_1
- mesh Cube.027: UV -0.39..1.30 (Pyxel clamps, it does not repeat)
- mesh Cube.027: UV 0.00..1.25 (Pyxel clamps, it does not repeat)
「面の向き」は、頂点に入っている法線と、三角形の向きが逆のものを数えています。法線が入っていない GLB では調べられません。
最後は Pyxel で見る
チェックで何も出なくても、最後は Pyxel で見ます。読み込むときの警告もここで出ます。
view_glb.py(全文)
"""Look at a GLB in Pyxel 3: it turns slowly and plays its first motion.
python view_glb.py model.glb (left / right: turn, up / down: zoom, M: next motion)
"""
# SPDX-License-Identifier: MIT
import math
import sys
import pyxel
from pyxel.cube import Camera, Mat4, Mesh, Node, Shading, Vec3
W, H = 256, 192
class App:
def __init__(self, path):
pyxel.init(W, H, title="view_glb")
self.mesh = Mesh.from_glb(path) # warnings (if any) are printed here
print("motions:", [(m.name, m.length) for m in self.mesh.motions])
self.stage = Node()
self.cam = Camera()
self.cam.fov = 30.0
self.cam.near = 0.5
self.cam.far = 5000.0
self.cam.clear_color = 1
self.stage.camera = self.cam
self.stage.shading = Shading(list(pyxel.colors))
self.model = Node.from_mesh(self.mesh)
self.stage.add_child(self.model)
self.yaw, self.dist, self.mi, self.frame = 30.0, 80.0, 0, 0.0
pyxel.run(self.update, self.draw)
def update(self):
self.yaw += (pyxel.btn(pyxel.KEY_RIGHT) - pyxel.btn(pyxel.KEY_LEFT)) * 3 + 0.5
self.dist *= 1.03 ** (pyxel.btn(pyxel.KEY_DOWN) - pyxel.btn(pyxel.KEY_UP))
motions = self.mesh.motions
if motions:
if pyxel.btnp(pyxel.KEY_M):
self.mi, self.frame = (self.mi + 1) % len(motions), 0.0
m = motions[self.mi]
self.frame = (self.frame + 1) % max(m.length, 1)
self.model.apply_motion(m, self.frame)
a = math.radians(self.yaw)
eye = Vec3(math.sin(a) * self.dist, self.dist * 0.5, math.cos(a) * self.dist)
self.cam.transform = Mat4.look_at(eye, Vec3(0.0, self.dist * 0.2, 0.0), Vec3.UP)
def draw(self):
self.stage.draw(0, 0, W, H)
if self.mesh.motions:
pyxel.text(4, 4, "%s %d" % (self.mesh.motions[self.mi].name, self.frame), 7)
App(sys.argv[1])
python view_glb.py cat.glb
左右キーで回し、上下キーで寄ったり離れたりします。M キーで次のモーションに切り替えます。
両面はどれくらい遅いか
同じ GLB の doubleSided だけを変えて、描く時間を比べました。320×240 の画面に、カメラを回しながら 60 フレーム描いた中央値です。3 回測りました。
| GLB | 三角形 | 両面 | 片面 |
|---|---|---|---|
| Python で作ったステージ | 15,568 | 7.4〜7.6 ms | 4.5〜4.6 ms |
| Blockbench の庭 | 1,860 | 1.7〜1.8 ms | 1.1 ms |
この 2 つでは、片面にすると描く時間が 4 割ほど短くなりました。クラウドの Linux(デスクトップ版)での数字なので、ブラウザ版やほかのパソコンでは違うはずです。
見た目は、ほとんど変わりませんでした。両面と片面で違った画素は、ねこで 0.18%、庭で 0.25%、Three.js のカップ(一番上の画像のもの)で 0.89%、ドーナツで 0.18% でした。
ただし、片面にすると、1 枚の板(草の板、旗など)は裏から見えなくなります。片面にしたら、いろいろな向きから見て確かめます。
軽くするとき(glTF-Transform)
GLB を小さくする定番の道具は glTF-Transform(MIT)の optimize です。ただし、Pyxel 向けには 4 つの設定が必要でした(Draco の draco コマンドも、Pyxel は読めません)。
gltf-transform optimize in.glb out.glb \
--compress false --texture-compress false --sparse false --instance false
| 設定 | 付けないとどうなるか |
|---|---|
--compress false |
既定の Meshopt 圧縮がかかり、Pyxel が読めない(EXT_meshopt_compression: Unsupported extension) |
--texture-compress false |
念のため。画像の形式を変える設定を止める(今回のサンプルでは、付けなくても PNG のまま読めた) |
--sparse false |
モーション付きの GLB が読めなくなる(下の 1) |
--instance false |
形の一部が黙って消える(下の 2) |
1. --sparse false を付けないと、読めなくなる
公式サンプルの gazelle.glb(モーション 13 本)に --sparse false なしで optimize をかけると、Pyxel は invalid glTF: accessors[205].bufferView: Missing data で読み込みを止めました。
全部 0 の小さな配列(この例ではアニメの時刻 1 つ)が、データを持たない形で書き出されるためです。glTF では「0 で埋める」と決まっている正しい書き方で、Khronos glTF Validator もエラー 0 でした。Pyxel 3.0.1 は、これを読めません。
2. --instance false を付けないと、形が黙って欠ける
公式サンプルの garden_stage.glb に --instance false なしでかけると、同じ形を並べる拡張(EXT_mesh_gpu_instancing)が使われます。Pyxel はこの拡張に対応していませんが、警告もエラーも出さずに読み込み、三角形が 6,978 から 4,366 に減りました。並べたはずの部品が消えています。
4 つの設定を付けた結果(公式サンプル 7 個)
| ファイル | 変換前 | 変換後 | 三角形 | モーション |
|---|---|---|---|---|
| garden_coin.glb | 5,608 B | 4,004 B | 36 → 36 | 0 |
| garden_platform.glb | 5,020 B | 3,660 B | 28 → 28 | 0 |
| garden_platform_collision.glb | 3,008 B | 2,220 B | 12 → 12 | 0 |
| garden_player.glb | 83,528 B | 60,504 B | 530 → 530 | 3 → 3 |
| garden_stage.glb | 971,248 B | 546,324 B | 6,978 → 6,846 | 0 |
| garden_stage_collision.glb | 196,856 B | 96,500 B | 1,120 → 1,120 | 0 |
| gazelle.glb | 166,064 B | 89,892 B | 200 → 200 | 13 → 13 |
7 個とも警告なしで読めて、モーションも残りました。大きさは 3〜5 割減りました。
garden_stage.glb の三角形が 132 減ったのは、optimize の中の減面(simplify)です。3 方向から描いて比べると、違う画素は 1 万 2 千〜1 万 7 千画素のうち 5〜27 画素でした。三角形を 1 つも減らしたくないときは --simplify false を足します(550 KB、6,978 三角形のまま)。
小さくなるのはファイルの大きさです。描く重さは三角形の数でほぼ決まるので(こちらの記事)、描画はほとんど速くなりません。
まとめ
-
Three.js(Three-Live):言葉で形を決められる物に。既定が両面。色は、Pyxel 3.0.1 までは setRGB、3.0.3 からは 0x... で書く。動きは焼き込めるが、
"target": 0を消してから Pyxel へ - Python:箱の組み合わせや、たくさん作る物、動かす物に。面の向きと、モーションの値が「置き換え」であることに注意。色は、3.0.3 からリニアに直して書く
- Blockbench:公式のおすすめ。書き出すと MASK・両面になる
-
CC0 素材:
.gltfを 1 つの GLB にまとめる。0〜1 の外の UV は、繰り返した画像に描き直す。骨で曲げる物は動かない - 確かめ方:Validator だけでは足りない。Pyxel 向けのチェックをして、最後は Pyxel で見る。片面にできる物は片面に
クレジット
- Pyxel 3:Takashi Kitao(MIT License)https://github.com/kitao/pyxel
- Three-Live:Google LLC(Apache-2.0)https://github.com/google/three-live
- Blockbench:JannisX11 ほか(GPL-3.0)https://www.blockbench.net/
- Medieval Village MegaKit、Universal Animation Library:Quaternius(CC0)https://quaternius.com/
- glTF Validator:The Khronos Group(Apache-2.0)https://github.com/KhronosGroup/glTF-Validator
- trimesh:Michael Dawson-Haggerty ほか(MIT License)https://trimesh.org/
- glTF-Transform:Don McCurdy(MIT License)https://gltf-transform.dev/
- この記事のスクリプト(
cup.cjs、anim.cjs、mini_glb.py、glb_for_pyxel.py、pyxel_glb_check.py、view_glb.py、cup_trimesh.py):haruka_apps(MIT License)









