Files
workinf_Blender_Wasm/tools/web/generated/WBV2-P3-004.py
mes123456 c2c65d3a09
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
Rebuild local Blender WASM environment and recovery evidence
2026-08-27 20:22:15 +08:00

99 lines
4.1 KiB
Python

#!/usr/bin/env python3
import pathlib
import sys
import bpy
def main(output):
bpy.ops.wm.read_factory_settings(use_empty=True)
scene = bpy.context.scene
scene.name = "WBV2P3004GLBRoundTripScene"
scene.frame_start = 1
scene.frame_end = 20
scene.render.fps = 24
mesh = bpy.data.meshes.new("WBV2P3004RoundTripMesh")
mesh.from_pydata(
[(-1, -1, 0), (1, -1, 0), (1, 1, 0), (-1, 1, 0),
(-1, -1, 2), (1, -1, 2), (1, 1, 2), (-1, 1, 2)],
[],
[(0, 1, 2), (0, 2, 3), (4, 6, 5), (4, 7, 6),
(0, 4, 5), (0, 5, 1), (1, 5, 6), (1, 6, 2),
(2, 6, 7), (2, 7, 3), (4, 0, 3), (4, 3, 7)],
)
mesh.update()
uv = mesh.uv_layers.new(name="WBV2P3004UV")
for loop_index, loop in enumerate(mesh.loops):
uv.data[loop_index].uv = ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0))[loop.vertex_index % 4]
mesh_object = bpy.data.objects.new("WBV2P3004RoundTripMeshObject", mesh)
bpy.context.collection.objects.link(mesh_object)
mesh_object.shape_key_add(name="Basis")
morph = mesh_object.shape_key_add(name="WBV2P3004Morph")
morph.data[2].co.z += 0.3
morph.data[6].co.z += 0.3
morph.value = 0.5
material = bpy.data.materials.new("WBV2P3004PBRMaterial")
material.use_nodes = True
material.diffuse_color = (0.22, 0.48, 0.82, 1.0)
principled = material.node_tree.nodes.get("Principled BSDF")
principled.inputs["Base Color"].default_value = (0.22, 0.48, 0.82, 1.0)
principled.inputs["Metallic"].default_value = 0.35
principled.inputs["Roughness"].default_value = 0.42
principled.inputs["Emission Color"].default_value = (0.0, 0.0, 0.0, 1.0)
principled.inputs["Emission Strength"].default_value = 1.0
image = bpy.data.images.load(str(pathlib.Path("tests/files/web/resources/udim_1001.png").resolve()), check_existing=False)
image.name = "WBV2P3004PackedTexture"
image.pack()
texture = material.node_tree.nodes.new("ShaderNodeTexImage")
texture.name = "WBV2P3004PackedTextureNode"
texture.image = image
material.node_tree.links.new(texture.outputs["Color"], principled.inputs["Base Color"])
mesh.materials.append(material)
armature_data = bpy.data.armatures.new("WBV2P3004Armature")
armature_object = bpy.data.objects.new("WBV2P3004ArmatureObject", armature_data)
bpy.context.collection.objects.link(armature_object)
bpy.context.view_layer.objects.active = armature_object
armature_object.select_set(True)
bpy.ops.object.mode_set(mode="EDIT")
root = armature_data.edit_bones.new("WBV2P3004Root")
root.head = (0, 0, 0)
root.tail = (0, 0, 1)
tip = armature_data.edit_bones.new("WBV2P3004Tip")
tip.head = (0, 0, 1)
tip.tail = (0, 0, 2)
tip.parent = root
tip.use_connect = True
bpy.ops.object.mode_set(mode="OBJECT")
root_group = mesh_object.vertex_groups.new(name="WBV2P3004Root")
tip_group = mesh_object.vertex_groups.new(name="WBV2P3004Tip")
root_group.add([0, 1, 2, 3], 1.0, "REPLACE")
root_group.add([4, 5, 6, 7], 0.25, "REPLACE")
tip_group.add([4, 5, 6, 7], 0.75, "REPLACE")
modifier = mesh_object.modifiers.new(name="WBV2P3004ArmatureDeform", type="ARMATURE")
modifier.object = armature_object
scene.frame_set(1)
mesh_object.location = (0, 0, 0)
mesh_object.keyframe_insert(data_path="location", frame=1)
mesh_object.location = (1.25, -0.5, 0.25)
mesh_object.keyframe_insert(data_path="location", frame=10)
mesh_object.location = (2.0, 0.0, 0.5)
mesh_object.keyframe_insert(data_path="location", frame=20)
if mesh_object.animation_data and mesh_object.animation_data.action:
mesh_object.animation_data.action.name = "WBV2P3004RoundTripAction"
scene.frame_set(1)
scene.world = bpy.data.worlds.new("WBV2P3004GLBWorld")
scene.world.color = (0.02, 0.03, 0.05)
bpy.ops.wm.save_as_mainfile(filepath=str(pathlib.Path(output).resolve()), check_existing=False, compress=True)
if __name__ == "__main__":
arguments = sys.argv[sys.argv.index("--") + 1:]
if len(arguments) != 1:
raise SystemExit("usage: blender -b --factory-startup --python WBV2-P3-004.py -- OUTPUT")
main(arguments[0])