Add Chromium-only Blender WebEngine parity work
This commit is contained in:
81
tools/web/blender-check-nonmesh-usd-roundtrip.py
Normal file
81
tools/web/blender-check-nonmesh-usd-roundtrip.py
Normal file
@@ -0,0 +1,81 @@
|
||||
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(usd_path, output_path):
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
result = bpy.ops.wm.usd_import(filepath=os.path.abspath(usd_path))
|
||||
if "FINISHED" not in result:
|
||||
raise RuntimeError(f"Blender USD 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":
|
||||
mesh = obj.data
|
||||
mesh.calc_loop_triangles()
|
||||
positions = [vertex.co[:] for vertex in mesh.vertices]
|
||||
report[name] = {
|
||||
"type": obj.type,
|
||||
"vertexCount": len(mesh.vertices),
|
||||
"edgeCount": len(mesh.edges),
|
||||
"triangleCount": len(mesh.loop_triangles),
|
||||
"boundsMin": rounded([min((point[axis] for point in positions), default=0.0) for axis in range(3)]),
|
||||
"boundsMax": rounded([max((point[axis] for point in positions), default=0.0) for axis in range(3)]),
|
||||
}
|
||||
elif obj.type == "CURVES":
|
||||
curves = obj.data
|
||||
positions = [point.position[:] for point in curves.points]
|
||||
report[name] = {
|
||||
"type": obj.type,
|
||||
"vertexCount": len(curves.points),
|
||||
"edgeCount": sum(max(0, len(curve.points) - 1) for curve in curves.curves),
|
||||
"triangleCount": 0,
|
||||
"boundsMin": rounded([min((point[axis] for point in positions), default=0.0) for axis in range(3)]),
|
||||
"boundsMax": rounded([max((point[axis] for point in positions), default=0.0) for axis in range(3)]),
|
||||
}
|
||||
elif obj.type == "POINTCLOUD":
|
||||
points = obj.data
|
||||
positions = [point.co[:] for point in points.points]
|
||||
report[name] = {
|
||||
"type": obj.type,
|
||||
"vertexCount": len(points.points),
|
||||
"edgeCount": 0,
|
||||
"triangleCount": 0,
|
||||
"boundsMin": rounded([min((point[axis] for point in positions), default=0.0) for axis in range(3)]),
|
||||
"boundsMax": rounded([max((point[axis] for point in positions), default=0.0) for axis in range(3)]),
|
||||
}
|
||||
else:
|
||||
raise RuntimeError(f"{name} has unsupported imported type {obj.type}")
|
||||
|
||||
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-usd-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-usd-roundtrip.py -- input.usda output.json")
|
||||
main(arguments[0], arguments[1])
|
||||
Reference in New Issue
Block a user