Add Chromium-only Blender WebEngine parity work
This commit is contained in:
67
tools/web/generate-rigged-fixture.py
Normal file
67
tools/web/generate-rigged-fixture.py
Normal file
@@ -0,0 +1,67 @@
|
||||
import math
|
||||
import sys
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
def main(output_path: str) -> None:
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
mesh = bpy.data.meshes.new("RiggedShapeMesh")
|
||||
mesh.from_pydata(
|
||||
[(-1.0, -1.0, 0.0), (1.0, -1.0, 0.0), (1.0, 1.0, 0.0), (-1.0, 1.0, 0.0)],
|
||||
[],
|
||||
[(0, 1, 2), (0, 2, 3)],
|
||||
)
|
||||
mesh.update()
|
||||
obj = bpy.data.objects.new("RiggedShapeObject", mesh)
|
||||
bpy.context.collection.objects.link(obj)
|
||||
obj.location = (0.5, 0.25, 0.0)
|
||||
|
||||
armature_data = bpy.data.armatures.new("RiggedArmature")
|
||||
armature_object = bpy.data.objects.new("RiggedArmatureObject", 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_bone = armature_data.edit_bones.new("Root")
|
||||
root_bone.head = (0.0, 0.0, -1.0)
|
||||
root_bone.tail = (0.0, 0.0, 0.0)
|
||||
tip_bone = armature_data.edit_bones.new("Tip")
|
||||
tip_bone.head = (0.0, 0.0, 0.0)
|
||||
tip_bone.tail = (0.0, 0.0, 1.0)
|
||||
tip_bone.parent = root_bone
|
||||
bpy.ops.object.mode_set(mode="OBJECT")
|
||||
armature_object.location = (0.25, -0.5, 0.0)
|
||||
armature_object.rotation_euler[2] = 0.15
|
||||
|
||||
root = obj.vertex_groups.new(name="Root")
|
||||
tip = obj.vertex_groups.new(name="Tip")
|
||||
root.add([0, 1], 1.0, "REPLACE")
|
||||
root.add([2, 3], 0.25, "REPLACE")
|
||||
tip.add([0, 1], 0.25, "REPLACE")
|
||||
tip.add([2, 3], 1.0, "REPLACE")
|
||||
|
||||
obj.shape_key_add(name="Basis")
|
||||
smile = obj.shape_key_add(name="Smile")
|
||||
smile.data[2].co.z = 0.5
|
||||
smile.data[3].co.z = 0.25
|
||||
smile.value = 0.6
|
||||
|
||||
armature_object.pose.bones["Tip"].rotation_mode = "XYZ"
|
||||
armature_object.pose.bones["Tip"].rotation_euler[1] = math.radians(27.0)
|
||||
|
||||
armature_modifier = obj.modifiers.new(name="Armature Deform", type="ARMATURE")
|
||||
armature_modifier.object = armature_object
|
||||
decimate = obj.modifiers.new(name="Preview Decimate", type="DECIMATE")
|
||||
decimate.ratio = 0.75
|
||||
decimate.show_render = False
|
||||
|
||||
bpy.context.view_layer.objects.active = obj
|
||||
obj.select_set(True)
|
||||
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("--") + 1:
|
||||
raise SystemExit("usage: blender -b --python generate-rigged-fixture.py -- output.blend")
|
||||
main(sys.argv[sys.argv.index("--") + 1])
|
||||
Reference in New Issue
Block a user