@threenative/blender-bridge 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -2
- package/dist/bridge.d.ts +111 -0
- package/dist/bridge.js +321 -0
- package/gpl/LICENSE.GPL +117 -0
- package/gpl/convert.py +192 -0
- package/gpl/fixtures/make_world_fixture.py +184 -0
- package/gpl/recipes/_common.py +180 -0
- package/gpl/recipes/bake_ao.py +111 -0
- package/gpl/recipes/decimate.py +70 -0
- package/gpl/recipes/export_world.py +699 -0
- package/gpl/recipes/retarget.py +131 -0
- package/gpl/recipes/unwrap.py +71 -0
- package/package.json +54 -3
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
2
|
+
#
|
|
3
|
+
# Copyright (C) 2026 ThreeNative contributors
|
|
4
|
+
#
|
|
5
|
+
# This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
6
|
+
# GNU General Public License as published by the Free Software Foundation; either version 2 of the
|
|
7
|
+
# License, or (at your option) any later version. See ../LICENSE.GPL.
|
|
8
|
+
#
|
|
9
|
+
# Reduce a model's triangle count to a requested fraction, preserving its materials, UVs and rig.
|
|
10
|
+
# It changes how much geometry there is, never what the geometry looks like: no material, colour,
|
|
11
|
+
# light or curve is authored here.
|
|
12
|
+
#
|
|
13
|
+
# blender --background --factory-startup --python decimate.py -- \
|
|
14
|
+
# '{"source":"/abs/in.glb","out":"/abs/out.glb","ratio":0.5}'
|
|
15
|
+
#
|
|
16
|
+
# Adapt it: `ratio` is per-object here; a real budget is usually per-object, weighted by how close
|
|
17
|
+
# the object gets to the camera. Read `blender_recipes` for this text and edit it into your game.
|
|
18
|
+
|
|
19
|
+
import os
|
|
20
|
+
import sys
|
|
21
|
+
|
|
22
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
23
|
+
|
|
24
|
+
import bpy # noqa: E402
|
|
25
|
+
|
|
26
|
+
from _common import (
|
|
27
|
+
collapse_decimate,
|
|
28
|
+
emit,
|
|
29
|
+
export,
|
|
30
|
+
fail,
|
|
31
|
+
load,
|
|
32
|
+
meshes,
|
|
33
|
+
request,
|
|
34
|
+
triangles,
|
|
35
|
+
) # noqa: E402
|
|
36
|
+
|
|
37
|
+
payload = request()
|
|
38
|
+
source = payload.get("source")
|
|
39
|
+
out = payload.get("out")
|
|
40
|
+
ratio = payload.get("ratio", 0.5)
|
|
41
|
+
|
|
42
|
+
if not isinstance(source, str) or not source:
|
|
43
|
+
fail("decimate requires a 'source' path")
|
|
44
|
+
if not isinstance(out, str) or not out:
|
|
45
|
+
fail("decimate requires an 'out' path")
|
|
46
|
+
if not isinstance(ratio, (int, float)) or not 0 < float(ratio) <= 1:
|
|
47
|
+
fail("'ratio' must be greater than 0 and at most 1, got %r" % (ratio,))
|
|
48
|
+
|
|
49
|
+
load(source)
|
|
50
|
+
before = triangles()
|
|
51
|
+
if before == 0:
|
|
52
|
+
fail("'%s' has no triangles to decimate" % source)
|
|
53
|
+
|
|
54
|
+
for item in meshes():
|
|
55
|
+
collapse_decimate(item, ratio)
|
|
56
|
+
|
|
57
|
+
after = triangles()
|
|
58
|
+
export(out)
|
|
59
|
+
emit(
|
|
60
|
+
{
|
|
61
|
+
"achievedRatio": (after / before) if before else 0.0,
|
|
62
|
+
"out": out,
|
|
63
|
+
"outBytes": os.path.getsize(out),
|
|
64
|
+
"recipe": "decimate",
|
|
65
|
+
"requestedRatio": float(ratio),
|
|
66
|
+
"source": source,
|
|
67
|
+
"trianglesAfter": after,
|
|
68
|
+
"trianglesBefore": before,
|
|
69
|
+
}
|
|
70
|
+
)
|