Add Chromium-only Blender WebEngine parity work
This commit is contained in:
36
tools/web/generate-packed-image-fixture.py
Normal file
36
tools/web/generate-packed-image-fixture.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
def main(output_path: str, image_path: str) -> None:
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
|
||||
mesh = bpy.data.meshes.new("PackedImageMesh")
|
||||
mesh.from_pydata([(-1.0, -1.0, 0.0), (1.0, -1.0, 0.0), (0.0, 1.0, 0.0)], [], [(0, 1, 2)])
|
||||
mesh.update()
|
||||
obj = bpy.data.objects.new("PackedImageObject", mesh)
|
||||
bpy.context.collection.objects.link(obj)
|
||||
|
||||
material = bpy.data.materials.new("PackedImageMaterial")
|
||||
material.use_nodes = True
|
||||
texture = material.node_tree.nodes.new("ShaderNodeTexImage")
|
||||
texture.image = bpy.data.images.load(str(pathlib.Path(image_path).resolve()), check_existing=False)
|
||||
texture.image.name = "PackedTexture"
|
||||
material.node_tree.links.new(texture.outputs["Color"], material.node_tree.nodes["Principled BSDF"].inputs["Base Color"])
|
||||
mesh.materials.append(material)
|
||||
|
||||
bpy.context.view_layer.objects.active = obj
|
||||
obj.select_set(True)
|
||||
bpy.ops.file.pack_all()
|
||||
if not texture.image.packed_file:
|
||||
raise RuntimeError("Blender did not pack the texture")
|
||||
bpy.ops.wm.save_as_mainfile(filepath=output_path, compress=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if "--" not in sys.argv or len(sys.argv) <= sys.argv.index("--") + 2:
|
||||
raise SystemExit("usage: blender -b --python generate-packed-image-fixture.py -- output.blend image.png")
|
||||
arguments = sys.argv[sys.argv.index("--") + 1:]
|
||||
main(arguments[0], arguments[1])
|
||||
Reference in New Issue
Block a user