Add Chromium-only Blender WebEngine parity work
This commit is contained in:
62
tools/web/blender-check-nonmesh-glb-roundtrip.py
Normal file
62
tools/web/blender-check-nonmesh-glb-roundtrip.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
EXPECTED_OBJECTS = {
|
||||
"WebCurveObject",
|
||||
"WebSurfaceObject",
|
||||
"WebFontObject",
|
||||
"WebMetaballObject",
|
||||
"WebPointCloudObject",
|
||||
"WebCurvesObject",
|
||||
"WebHairObject",
|
||||
}
|
||||
|
||||
|
||||
def rounded(values):
|
||||
return [round(float(value), 7) for value in values]
|
||||
|
||||
|
||||
def main(glb_path, output_path):
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
result = bpy.ops.import_scene.gltf(filepath=os.path.abspath(glb_path))
|
||||
if "FINISHED" not in result:
|
||||
raise RuntimeError(f"Blender glTF importer failed: {result}")
|
||||
|
||||
report = {}
|
||||
for name in sorted(EXPECTED_OBJECTS):
|
||||
obj = bpy.data.objects.get(name)
|
||||
if obj is None:
|
||||
raise RuntimeError(f"{name} was not imported")
|
||||
if obj.type != "MESH":
|
||||
raise RuntimeError(f"{name} was not imported as a mesh")
|
||||
mesh = obj.data
|
||||
mesh.calc_loop_triangles()
|
||||
report[name] = {
|
||||
"vertexCount": len(mesh.vertices),
|
||||
"edgeCount": len(mesh.edges),
|
||||
"triangleCount": len(mesh.loop_triangles),
|
||||
"boundsMin": rounded([
|
||||
min((vertex.co[axis] for vertex in mesh.vertices), default=0.0)
|
||||
for axis in range(3)
|
||||
]),
|
||||
"boundsMax": rounded([
|
||||
max((vertex.co[axis] for vertex in mesh.vertices), default=0.0)
|
||||
for axis in range(3)
|
||||
]),
|
||||
}
|
||||
|
||||
with open(output_path, "w", encoding="ascii") as output:
|
||||
json.dump(report, output, indent=2, sort_keys=True)
|
||||
output.write("\n")
|
||||
print(f"blender-nonmesh-glb-import-ok objects={len(report)}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
arguments = sys.argv[sys.argv.index("--") + 1:]
|
||||
if len(arguments) != 2:
|
||||
raise SystemExit("usage: blender -b --python blender-check-nonmesh-glb-roundtrip.py -- input.glb output.json")
|
||||
main(arguments[0], arguments[1])
|
||||
Reference in New Issue
Block a user