Load Publish (Loaded panel) searches every asset of the project, then loads any of its published .blend files at any version, cast in the shot or not. The file the casting would load and the latest version on this site are preselected; a version not on this site is requested instead. Built on the existing wtd_list_assets / wtd_get_asset_files / wtd_get_revisions commands. New instances are numbered (COL_bob_01, tree_01...), counting on from the highest number in the file (SCENE_MANAGER_INSTANCE_NAME). README: Pick Shot only lists shots that exist in Libreflow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
3.4 KiB
Python
73 lines
3.4 KiB
Python
"""Write the asset files used by fake_libreflow.py into <workdir>/lib.
|
|
|
|
blender -b --factory-startup --python dev/make_test_assets.py -- <workdir>
|
|
|
|
bob: a rig (COL_bob: armature + meshes), v001 has 1 mesh, v002 has 2.
|
|
tree: COL_tree holding only LOD collections (COL_tree_LOD0, COL_tree_LOD1), plus an
|
|
unrelated top-level collection. v002 adds a mesh outside the LODs, v003 has no LOD.
|
|
car: a rig, COL_car: armature + named LODs COL_car_LODlow, _LODhigh, _LODmid.
|
|
chair: COL_chair (not cast, loaded with Load Publish).
|
|
rock: a single top-level collection not named after the asset (fallback case), its mesh
|
|
using a node group linked from Blender's essentials (an indirect library).
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
|
|
import bpy
|
|
|
|
WORKDIR = sys.argv[sys.argv.index("--") + 1]
|
|
|
|
|
|
def mesh_object(name):
|
|
mesh = bpy.data.meshes.new(name)
|
|
mesh.from_pydata([(0, 0, 0), (1, 0, 0), (0, 1, 0)], [], [(0, 1, 2)])
|
|
return bpy.data.objects.new(name, mesh)
|
|
|
|
|
|
def write(path, collection_name, meshes=1, rig=False, extra=False, node_group=False, lods=()):
|
|
bpy.ops.wm.read_homefile(use_empty=True)
|
|
scene = bpy.context.scene
|
|
collection = bpy.data.collections.new(collection_name)
|
|
scene.collection.children.link(collection)
|
|
parent = None
|
|
if rig:
|
|
parent = bpy.data.objects.new("RIG_" + collection_name, bpy.data.armatures.new("RIG_" + collection_name))
|
|
collection.objects.link(parent)
|
|
bpy.context.view_layer.objects.active = parent
|
|
bpy.ops.object.mode_set(mode="EDIT")
|
|
bone = parent.data.edit_bones.new("root")
|
|
bone.tail = (0, 0, 1)
|
|
bpy.ops.object.mode_set(mode="OBJECT")
|
|
for index in range(meshes):
|
|
ob = mesh_object(f"GEO_{collection_name}_{index}")
|
|
ob.parent = parent
|
|
collection.objects.link(ob)
|
|
for lod in lods:
|
|
lod_collection = bpy.data.collections.new(f"{collection_name}_LOD{lod}")
|
|
collection.children.link(lod_collection)
|
|
ob = mesh_object(f"GEO_{collection_name}_LOD{lod}")
|
|
ob.parent = parent
|
|
lod_collection.objects.link(ob)
|
|
if node_group:
|
|
essentials = os.path.join(bpy.utils.system_resource("DATAFILES"), "assets", "nodes", "geometry_nodes_essentials.blend")
|
|
with bpy.data.libraries.load(essentials, link=True) as (_data_from, data_to):
|
|
data_to.node_groups = ["Smooth by Angle"]
|
|
ob.modifiers.new("Smooth", "NODES").node_group = data_to.node_groups[0]
|
|
if extra:
|
|
scene.collection.children.link(bpy.data.collections.new("WIP_other"))
|
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
bpy.ops.wm.save_as_mainfile(filepath=path)
|
|
|
|
|
|
lib = os.path.join(WORKDIR, "lib")
|
|
write(os.path.join(lib, "bob", "v001", "rig.blend"), "COL_bob", meshes=1, rig=True, extra=True)
|
|
write(os.path.join(lib, "bob", "v002", "rig.blend"), "COL_bob", meshes=2, rig=True, extra=True)
|
|
write(os.path.join(lib, "tree", "v001", "model.blend"), "COL_tree", meshes=0, extra=True, lods=["0", "1"])
|
|
write(os.path.join(lib, "tree", "v002", "model.blend"), "COL_tree", meshes=1, extra=True, lods=["0", "1"])
|
|
write(os.path.join(lib, "tree", "v003", "model.blend"), "COL_tree", meshes=1, extra=True)
|
|
write(os.path.join(lib, "rock", "v001", "rock.blend"), "rock_geo", node_group=True)
|
|
write(os.path.join(lib, "car", "v001", "car.blend"), "COL_car", meshes=0, rig=True, lods=["low", "high", "mid"])
|
|
write(os.path.join(lib, "chair", "v001", "chair.blend"), "COL_chair")
|
|
print("Test assets written in", lib)
|