@threenative/core 0.3.6 → 0.3.9
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 +3 -5
- package/capabilities.json +739 -50
- package/dist/{assets-CqvE429w.d.ts → assets-YUbXa3-Y.d.ts} +101 -2
- package/dist/{canvas-layer-C1-5CviZ.d.ts → canvas-layer-vCtanIeB.d.ts} +1 -1
- package/dist/{game-Jz4Fdoeb.d.ts → game-cb99J-YE.d.ts} +100 -31
- package/dist/hot.d.ts +4 -4
- package/dist/hot.js +23 -5
- package/dist/index.d.ts +1742 -29
- package/dist/index.js +22443 -12423
- package/dist/{model-lod-BDAUYgsS.d.ts → model-lod-CTpZ6imz.d.ts} +1 -1
- package/dist/net.js +39 -12
- package/dist/playtest.d.ts +4 -4
- package/dist/playtest.js +48 -9
- package/dist/react-css.js +23 -0
- package/dist/react.d.ts +2 -2
- package/dist/{renderer-9yEo9hPa.d.ts → renderer-rZm0hVqq.d.ts} +178 -5
- package/dist/ui-layer.d.ts +11 -2
- package/dist/ui-layer.js +76 -4
- package/dist/worker.d.ts +36 -0
- package/dist/worker.js +1088 -0
- package/dist/world.d.ts +11 -3
- package/dist/world.js +1117 -197
- package/mcp/animation-server.mjs +265 -0
- package/mcp/animation.mjs +22 -0
- package/mcp/call.mjs +105 -0
- package/mcp/devtools.mjs +5 -0
- package/mcp/engine-server.mjs +713 -37
- package/mcp/launch.mjs +3 -2
- package/mcp/servers.d.mts +2 -0
- package/mcp/servers.mjs +33 -8
- package/package.json +12 -8
- package/patches/three@0.185.1-prd269-upgrade.patch +308 -0
- package/patches/three@0.185.1.patch +481 -272
- package/src/animation-packet-state.ts +88 -0
- package/src/animation-pose-packet.ts +537 -0
- package/src/animation.ts +779 -31
- package/src/asset-cache.ts +719 -0
- package/src/assets.ts +521 -152
- package/src/audio.ts +29 -3
- package/src/auto-batch.ts +792 -0
- package/src/config.ts +2 -0
- package/src/frame-budget.ts +268 -2
- package/src/game.ts +525 -105
- package/src/grounding.ts +7 -6
- package/src/hot.ts +19 -5
- package/src/index.ts +381 -6
- package/src/input.ts +21 -2
- package/src/interpolation.ts +19 -1
- package/src/launch-diagnostics.ts +7 -2
- package/src/look/ao-multibounce.ts +29 -0
- package/src/look/ao-reach.ts +39 -0
- package/src/look/auto-exposure.ts +264 -0
- package/src/look/default-tone-mapping.ts +44 -0
- package/src/look/exposure-graph.ts +208 -0
- package/src/look/exposure-readback.ts +97 -0
- package/src/look/exposure-settings.ts +132 -0
- package/src/look/filmic-tone-mapping.ts +852 -0
- package/src/look/gi-registry.ts +55 -0
- package/src/look/local-exposure.ts +507 -0
- package/src/look/look-diagnostics.ts +24 -0
- package/src/look/motion-blur.ts +42 -0
- package/src/look/quality.ts +309 -0
- package/src/look/reflection-trace.ts +344 -0
- package/src/look/unreal-bloom.ts +295 -0
- package/src/look/vignette.ts +14 -0
- package/src/look/world-environment.ts +2033 -0
- package/src/loop.ts +25 -1
- package/src/merge-parts.ts +25 -10
- package/src/model-lod.ts +14 -0
- package/src/net-session.ts +58 -14
- package/src/ocean/spectral.ts +41 -7
- package/src/picking.ts +72 -5
- package/src/platform.ts +29 -1
- package/src/playtest.ts +54 -8
- package/src/profiling/FrameCounters.ts +166 -5
- package/src/profiling/FrameStages.ts +289 -0
- package/src/profiling/Spans.ts +39 -25
- package/src/profiling/debug-telemetry.ts +312 -0
- package/src/profiling/scene-warning.ts +42 -6
- package/src/projection-apply.ts +11 -3
- package/src/projection-content.ts +189 -0
- package/src/projection-marker.ts +6 -2
- package/src/projection-plan.ts +279 -28
- package/src/projection-skinned.ts +620 -5
- package/src/projection-stability.ts +16 -0
- package/src/projection-uniform.ts +5 -1
- package/src/quiet-markers.ts +56 -0
- package/src/render/budget-ladder.ts +256 -0
- package/src/render/chain.ts +89 -7
- package/src/render/exposure-units.ts +59 -0
- package/src/render/frame-time-budget.ts +162 -0
- package/src/render/gi-budget.ts +231 -0
- package/src/render/gi-visualize.ts +49 -0
- package/src/render/material-key.ts +1 -0
- package/src/render/probe-volume.ts +196 -36
- package/src/render/rough-diffuse.ts +177 -0
- package/src/render/scene-trace.ts +532 -0
- package/src/render/shadow-filter-budget.ts +237 -0
- package/src/render/sky-capture.ts +194 -0
- package/src/render/soft-shadow.ts +607 -0
- package/src/render/surface-cache.ts +418 -0
- package/src/render/traced-reflections.ts +408 -0
- package/src/render/two-sided-foliage.ts +120 -0
- package/src/render/virtual-shadow-pages.ts +112 -12
- package/src/render/virtual-shadow.ts +386 -38
- package/src/render-camera-cull.ts +536 -31
- package/src/render-pass-budget.ts +140 -22
- package/src/renderProjection.ts +65 -9
- package/src/renderer-config.ts +3 -2
- package/src/renderer.ts +289 -14
- package/src/resolution-scaler.ts +65 -7
- package/src/skeletal-mesh.ts +4 -0
- package/src/snow-field.ts +46 -0
- package/src/softbody.ts +6 -5
- package/src/startup-offscreen-bytes.ts +168 -0
- package/src/startup-readiness.ts +137 -2
- package/src/ui-bridge.ts +38 -0
- package/src/ui-hit-regions.ts +6 -2
- package/src/ui-layer.ts +1 -0
- package/src/ui-state.ts +32 -3
- package/src/version.ts +1 -1
- package/src/viewport.ts +8 -5
- package/src/warmup.ts +76 -10
- package/src/worker-audio.ts +579 -0
- package/src/worker.ts +842 -0
- package/src/world-cells.ts +4 -1
- package/gpl/LICENSE.GPL +0 -117
- package/gpl/convert.py +0 -192
- package/gpl/fixtures/make_world_fixture.py +0 -184
- package/gpl/recipes/_common.py +0 -180
- package/gpl/recipes/bake_ao.py +0 -111
- package/gpl/recipes/decimate.py +0 -70
- package/gpl/recipes/export_world.py +0 -699
- package/gpl/recipes/retarget.py +0 -131
- package/gpl/recipes/unwrap.py +0 -71
- package/mcp/blender-server.mjs +0 -689
- package/mcp/blender.mjs +0 -26
package/gpl/recipes/_common.py
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
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
|
-
# What every recipe repeats: read the JSON request after `--`, load the source, export the GLB,
|
|
10
|
-
# print one machine-readable result line. A recipe file is then only the operation itself, which is
|
|
11
|
-
# the part an agent reads and adapts.
|
|
12
|
-
|
|
13
|
-
import json
|
|
14
|
-
import os
|
|
15
|
-
import sys
|
|
16
|
-
|
|
17
|
-
import bpy
|
|
18
|
-
|
|
19
|
-
RESULT_PREFIX = "TN_BLENDER_RESULT "
|
|
20
|
-
|
|
21
|
-
IMPORTERS = {
|
|
22
|
-
".fbx": lambda p: bpy.ops.import_scene.fbx(filepath=p),
|
|
23
|
-
".obj": lambda p: bpy.ops.wm.obj_import(filepath=p),
|
|
24
|
-
".dae": lambda p: bpy.ops.wm.collada_import(filepath=p),
|
|
25
|
-
".gltf": lambda p: bpy.ops.import_scene.gltf(filepath=p),
|
|
26
|
-
".glb": lambda p: bpy.ops.import_scene.gltf(filepath=p),
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def fail(message):
|
|
31
|
-
sys.stderr.write("TN_BLENDER_ERROR: %s\n" % message)
|
|
32
|
-
sys.stderr.flush()
|
|
33
|
-
os._exit(2)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
def request():
|
|
37
|
-
if "--" not in sys.argv:
|
|
38
|
-
fail("no '--' separator; pass the JSON request after it")
|
|
39
|
-
tail = sys.argv[sys.argv.index("--") + 1 :]
|
|
40
|
-
if len(tail) != 1:
|
|
41
|
-
fail("expected exactly one JSON argument, got %d" % len(tail))
|
|
42
|
-
try:
|
|
43
|
-
return json.loads(tail[0])
|
|
44
|
-
except ValueError as error:
|
|
45
|
-
fail("request is not JSON: %s" % error)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def load(source):
|
|
49
|
-
if not os.path.isfile(source):
|
|
50
|
-
fail("source '%s' does not exist" % source)
|
|
51
|
-
extension = os.path.splitext(source)[1].lower()
|
|
52
|
-
if extension == ".blend":
|
|
53
|
-
bpy.ops.wm.open_mainfile(filepath=source)
|
|
54
|
-
return
|
|
55
|
-
importer = IMPORTERS.get(extension)
|
|
56
|
-
if importer is None:
|
|
57
|
-
fail("unsupported source extension '%s'" % extension)
|
|
58
|
-
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
59
|
-
importer(source)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def meshes():
|
|
63
|
-
return [item for item in bpy.data.objects if item.type == "MESH"]
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def triangles():
|
|
67
|
-
depsgraph = bpy.context.evaluated_depsgraph_get()
|
|
68
|
-
total = 0
|
|
69
|
-
for item in meshes():
|
|
70
|
-
evaluated = item.evaluated_get(depsgraph)
|
|
71
|
-
mesh = evaluated.to_mesh()
|
|
72
|
-
try:
|
|
73
|
-
mesh.calc_loop_triangles()
|
|
74
|
-
total += len(mesh.loop_triangles)
|
|
75
|
-
finally:
|
|
76
|
-
evaluated.to_mesh_clear()
|
|
77
|
-
return total
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def uv_layers():
|
|
81
|
-
return sum(len(item.data.uv_layers) for item in meshes())
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def collapse_decimate(item, ratio):
|
|
85
|
-
"""Add the collapse-decimate modifier `decimate` uses, so other recipes reuse that recipe's
|
|
86
|
-
operation instead of copying it. It measures nothing and writes nothing; the caller decides
|
|
87
|
-
what to export."""
|
|
88
|
-
modifier = item.modifiers.new(name="TNDecimate", type="DECIMATE")
|
|
89
|
-
modifier.decimate_type = "COLLAPSE"
|
|
90
|
-
modifier.ratio = float(ratio)
|
|
91
|
-
modifier.use_collapse_triangulate = True
|
|
92
|
-
return modifier
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def export(out):
|
|
96
|
-
directory = os.path.dirname(out)
|
|
97
|
-
if directory and not os.path.isdir(directory):
|
|
98
|
-
os.makedirs(directory, exist_ok=True)
|
|
99
|
-
for item in bpy.data.objects:
|
|
100
|
-
if item.animation_data is None or item.animation_data.action is None:
|
|
101
|
-
continue
|
|
102
|
-
action = item.animation_data.action
|
|
103
|
-
existing = {
|
|
104
|
-
strip.action.name
|
|
105
|
-
for track in item.animation_data.nla_tracks
|
|
106
|
-
for strip in track.strips
|
|
107
|
-
if strip.action
|
|
108
|
-
}
|
|
109
|
-
if action.name in existing:
|
|
110
|
-
continue
|
|
111
|
-
track = item.animation_data.nla_tracks.new()
|
|
112
|
-
track.name = action.name
|
|
113
|
-
track.strips.new(action.name, int(action.frame_range[0]), action)
|
|
114
|
-
item.animation_data.action = None
|
|
115
|
-
# `export_apply` is not the default, and without it a recipe that works through a
|
|
116
|
-
# modifier reports the number it measured and writes the geometry it started with:
|
|
117
|
-
# `decimate` at ratio 0.25 reported trianglesAfter 154 and shipped a 620-triangle GLB,
|
|
118
|
-
# byte-identical to the unmodified export. Blender's glTF exporter excludes armature
|
|
119
|
-
# modifiers from this, so a rig still exports as a rig rather than being baked flat.
|
|
120
|
-
bpy.ops.export_scene.gltf(
|
|
121
|
-
filepath=out,
|
|
122
|
-
export_apply=True,
|
|
123
|
-
export_format="GLB",
|
|
124
|
-
export_animations=True,
|
|
125
|
-
export_nla_strips=True,
|
|
126
|
-
export_skins=True,
|
|
127
|
-
export_yup=True,
|
|
128
|
-
use_selection=False,
|
|
129
|
-
)
|
|
130
|
-
if not os.path.isfile(out):
|
|
131
|
-
fail("export wrote no file at '%s'" % out)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def emit(summary):
|
|
135
|
-
summary["blender"] = bpy.app.version_string
|
|
136
|
-
sys.stdout.write("\n" + RESULT_PREFIX + json.dumps(summary, sort_keys=True) + "\n")
|
|
137
|
-
sys.stdout.flush()
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
def action_fcurves(action):
|
|
141
|
-
"""Every F-curve in an action, across both of Blender's action shapes.
|
|
142
|
-
|
|
143
|
-
Blender 4.4 replaced `action.fcurves` with slotted actions — layers, strips and channelbags —
|
|
144
|
-
and 5.2 removed the old attribute outright, so a recipe written against `action.fcurves` dies
|
|
145
|
-
with `AttributeError: 'Action' object has no attribute 'fcurves'` on a current Blender while
|
|
146
|
-
still working on the 4.2 floor. Both shapes are read here so a recipe never has to know.
|
|
147
|
-
"""
|
|
148
|
-
curves = getattr(action, "fcurves", None)
|
|
149
|
-
if curves is not None:
|
|
150
|
-
return list(curves)
|
|
151
|
-
collected = []
|
|
152
|
-
for layer in action.layers:
|
|
153
|
-
for strip in layer.strips:
|
|
154
|
-
for bag in strip.channelbags:
|
|
155
|
-
collected.extend(bag.fcurves)
|
|
156
|
-
return collected
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
def new_action(name, owner):
|
|
160
|
-
"""A new action and the F-curve collection to write into, for either action shape.
|
|
161
|
-
|
|
162
|
-
Returns `(action, fcurves, slot)`. `slot` is None on Blender before 4.4; `assign_action`
|
|
163
|
-
handles both.
|
|
164
|
-
"""
|
|
165
|
-
action = bpy.data.actions.new(name)
|
|
166
|
-
action.use_fake_user = True
|
|
167
|
-
if hasattr(action, "fcurves"):
|
|
168
|
-
return action, action.fcurves, None
|
|
169
|
-
slot = action.slots.new(id_type="OBJECT", name=owner.name)
|
|
170
|
-
layer = action.layers.new("Layer")
|
|
171
|
-
strip = layer.strips.new(type="KEYFRAME")
|
|
172
|
-
bag = strip.channelbag(slot, ensure=True)
|
|
173
|
-
return action, bag.fcurves, slot
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
def assign_action(owner, action, slot):
|
|
177
|
-
owner.animation_data_create()
|
|
178
|
-
owner.animation_data.action = action
|
|
179
|
-
if slot is not None:
|
|
180
|
-
owner.animation_data.action_slot = slot
|
package/gpl/recipes/bake_ao.py
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
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
|
-
# Bake ambient occlusion into a texture. AO is *computed from geometry* — how much of the sky each
|
|
10
|
-
# point can see — so this measures the model rather than choosing an appearance. What the game then
|
|
11
|
-
# does with the map (multiply it, tint it, ignore it) is the game's decision, in src/render/.
|
|
12
|
-
#
|
|
13
|
-
# blender --background --factory-startup --python bake_ao.py -- \
|
|
14
|
-
# '{"source":"/abs/in.glb","out":"/abs/ao.png","size":256,"samples":16}'
|
|
15
|
-
#
|
|
16
|
-
# Adapt it: bake to a UV set the game controls, or raise `samples` for a hero asset. The recipe
|
|
17
|
-
# unwraps meshes that have no UVs, because a bake with no parameterisation writes nothing.
|
|
18
|
-
|
|
19
|
-
import math
|
|
20
|
-
import os
|
|
21
|
-
import sys
|
|
22
|
-
|
|
23
|
-
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
24
|
-
|
|
25
|
-
import bpy # noqa: E402
|
|
26
|
-
|
|
27
|
-
from _common import emit, fail, load, meshes, request # noqa: E402
|
|
28
|
-
|
|
29
|
-
payload = request()
|
|
30
|
-
source = payload.get("source")
|
|
31
|
-
out = payload.get("out")
|
|
32
|
-
size = int(payload.get("size", 256))
|
|
33
|
-
samples = int(payload.get("samples", 16))
|
|
34
|
-
|
|
35
|
-
if not isinstance(source, str) or not source:
|
|
36
|
-
fail("bake_ao requires a 'source' path")
|
|
37
|
-
if not isinstance(out, str) or not out:
|
|
38
|
-
fail("bake_ao requires an 'out' path for the baked PNG")
|
|
39
|
-
if size < 16 or size > 4096:
|
|
40
|
-
fail("'size' must be between 16 and 4096, got %d" % size)
|
|
41
|
-
|
|
42
|
-
load(source)
|
|
43
|
-
targets = meshes()
|
|
44
|
-
if not targets:
|
|
45
|
-
fail("'%s' has no meshes to bake" % source)
|
|
46
|
-
|
|
47
|
-
image = bpy.data.images.new("TN_AO", width=size, height=size)
|
|
48
|
-
|
|
49
|
-
for item in targets:
|
|
50
|
-
if len(item.data.uv_layers) == 0:
|
|
51
|
-
bpy.context.view_layer.objects.active = item
|
|
52
|
-
for other in bpy.context.selected_objects:
|
|
53
|
-
other.select_set(False)
|
|
54
|
-
item.select_set(True)
|
|
55
|
-
bpy.ops.object.mode_set(mode="EDIT")
|
|
56
|
-
bpy.ops.mesh.select_all(action="SELECT")
|
|
57
|
-
bpy.ops.uv.smart_project(angle_limit=math.radians(66.0), island_margin=0.02)
|
|
58
|
-
bpy.ops.object.mode_set(mode="OBJECT")
|
|
59
|
-
if not item.data.materials:
|
|
60
|
-
item.data.materials.append(bpy.data.materials.new("TN_BakeTarget"))
|
|
61
|
-
for material in item.data.materials:
|
|
62
|
-
if material is None:
|
|
63
|
-
continue
|
|
64
|
-
material.use_nodes = True
|
|
65
|
-
node = material.node_tree.nodes.new("ShaderNodeTexImage")
|
|
66
|
-
node.image = image
|
|
67
|
-
node.select = True
|
|
68
|
-
material.node_tree.nodes.active = node
|
|
69
|
-
|
|
70
|
-
bpy.context.scene.render.engine = "CYCLES"
|
|
71
|
-
bpy.context.scene.cycles.samples = samples
|
|
72
|
-
bpy.context.scene.render.bake.use_selected_to_active = False
|
|
73
|
-
|
|
74
|
-
for other in bpy.context.selected_objects:
|
|
75
|
-
other.select_set(False)
|
|
76
|
-
for item in targets:
|
|
77
|
-
item.select_set(True)
|
|
78
|
-
bpy.context.view_layer.objects.active = targets[0]
|
|
79
|
-
bpy.ops.object.bake(type="AO")
|
|
80
|
-
|
|
81
|
-
directory = os.path.dirname(out)
|
|
82
|
-
if directory and not os.path.isdir(directory):
|
|
83
|
-
os.makedirs(directory, exist_ok=True)
|
|
84
|
-
image.filepath_raw = out
|
|
85
|
-
image.file_format = "PNG"
|
|
86
|
-
image.save()
|
|
87
|
-
if not os.path.isfile(out):
|
|
88
|
-
fail("bake wrote no file at '%s'" % out)
|
|
89
|
-
|
|
90
|
-
pixels = list(image.pixels)
|
|
91
|
-
luminance = [
|
|
92
|
-
0.2126 * pixels[index] + 0.7152 * pixels[index + 1] + 0.0722 * pixels[index + 2]
|
|
93
|
-
for index in range(0, len(pixels), 4)
|
|
94
|
-
]
|
|
95
|
-
mean = sum(luminance) / len(luminance) if luminance else 0.0
|
|
96
|
-
lowest = min(luminance) if luminance else 0.0
|
|
97
|
-
highest = max(luminance) if luminance else 0.0
|
|
98
|
-
|
|
99
|
-
emit(
|
|
100
|
-
{
|
|
101
|
-
"meanLuminance": mean,
|
|
102
|
-
"maxLuminance": highest,
|
|
103
|
-
"minLuminance": lowest,
|
|
104
|
-
"out": out,
|
|
105
|
-
"outBytes": os.path.getsize(out),
|
|
106
|
-
"recipe": "bake_ao",
|
|
107
|
-
"samples": samples,
|
|
108
|
-
"size": size,
|
|
109
|
-
"source": source,
|
|
110
|
-
}
|
|
111
|
-
)
|
package/gpl/recipes/decimate.py
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
)
|