"""Blender-authored pocket torch; local -Z exports as the grip's -Y axis.""" import bpy, math from pathlib import Path ROOT = Path('D:/project/sunrise') previous = bpy.context.window.scene scene = bpy.data.scenes.new('Sheep pocket flashlight') bpy.context.window.scene = scene root = bpy.data.objects.new('Flashlight', None) scene.collection.objects.link(root) def material(name, color, metal=0): m=bpy.data.materials.new(name);m.use_nodes=True s=next(n for n in m.node_tree.nodes if n.type=='BSDF_PRINCIPLED') s.inputs['Base Color'].default_value=(*color,1) s.inputs['Metallic'].default_value=metal;s.inputs['Roughness'].default_value=.45 return m body=material('Torch charcoal',(.065,.085,.10)) trim=material('Torch warm brass',(.55,.35,.12),.5) lens=material('Torch lens',(.72,.83,.88)) def cylinder(name, radius, depth, z, mat): bpy.ops.mesh.primitive_cylinder_add(vertices=24,radius=radius,depth=depth,location=(0,0,z)) o=bpy.context.object;o.name=name;o.parent=root;o.data.materials.append(mat) bevel=o.modifiers.new('Soft edges','BEVEL');bevel.width=.007;bevel.segments=2 return o cylinder('Torch grip',.065,.22,-.035,body) for z in [-.10,-.06,-.02,.02]: cylinder('Grip ring',.068,.012,z,trim) cylinder('Torch cap',.07,.035,.09,body) cylinder('Torch bezel',.10,.09,-.19,body) cylinder('Lens rim',.105,.018,-.24,trim) cylinder('FlashlightLens',.088,.009,-.253,lens) for o in scene.objects:o.select_set(True) bpy.context.view_layer.objects.active=root import io_scene_gltf2 fmt=next(i[0] for i in io_scene_gltf2.get_format_items(None,bpy.context) if i[0]=='GLB') bpy.ops.export_scene.gltf(filepath=str(ROOT/'public/characters/flashlight.glb'),export_format=fmt,use_selection=True,use_active_scene=True,export_yup=True,export_apply=True) (ROOT/'assets/characters').mkdir(parents=True,exist_ok=True) bpy.data.libraries.write(str(ROOT/'assets/characters/flashlight.blend'),{scene}) bpy.context.window.scene=previous print('Exported flashlight.glb; charcoal body, brass grip rings, inset lens')