convert this small blender plugin into a c# unity script make this work in unity in a…
- User
convert this small blender plugin into a c# unity script make this work in unity in a logical way.
import bpy import os import xml.etree.ElementTree as ET import xml.dom.minidom as md import math import numpy as np from distutils.util import strtobool from mathutils import Vector
def parse_elements( element , armature ): pbone = None
if "name" in element.attrib and (element.tag == "bone" or element.tag == "collision_volume"): pbone = armature.data.edit_bones[element.attrib['name']] #endif for bone in element: #print(bone.get('name')) bname = bone.get('name') exists_bone = False for ebone in armature.data.edit_bones: if ebone.name == bname: exists_bone = True break #endif #endfor if exists_bone: bn = armature.data.edit_bones[bname] else: bn = armature.data.edit_bones.new(bname) #endif if bone.tag == "bone": pos = Vector(np.fromstring(bone.get('pivot'), sep=' ')) bn.use_connect = strtobool(bone.get('connected')) if bone.get("support") == 'base': bn['prop'] = 'Base' bn.color.palette = 'THEME04' else: bn['prop'] = 'Extended' bn.color.palette = 'THEME03' else: pos = Vector(np.fromstring(bone.get('pos'), sep=' ')) bn['prop'] = 'Collision' bn.color.palette = 'THEME01' #endif end = Vector(np.fromstring(bone.get('end'), sep=' ')) if pbone != None: bn.parent = pbone #endif bn.head = pos bn.tail = end #endfor for sub in element: parse_elements( sub , armature ) #endfordef main(self, context): if context.view_layer.objects.active != None: bpy.ops.object.mode_set(mode='OBJECT', toggle=False) bpy.ops.object.select_all(action='DESELECT')
armature = None for collection in bpy.data.collections: for obj in collection.all_objects: if obj.type == 'ARMATURE': armature = obj bpy.context.view_layer.objects.active = armature #endif #endfor #endfor if armature == None: armature = bpy.ops.object.armature_add(enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)) armature = bpy.context.view_layer.objects.active #endif armature.data.name = 'Root' # remove default bone bpy.ops.object.mode_set(mode='EDIT', toggle=False) bpy.ops.armature.select_all(action='SELECT') bpy.ops.armature.delete() bpy.ops.object.mode_set(mode='OBJECT', toggle=False) # prepare bone collection armature.data.collections[0].name = 'Base' bpy.ops.armature.collection_add() armature.data.collections[1].name = 'Extended' armature.data.collections[1].is_visible = False bpy.ops.armature.collection_add() armature.data.collections[2].name = 'Collision' armature.data.collections[2].is_visible = False armature.show_in_front = True if __name__ == '__main__':xmlpath = "D:\Users\Utano\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\mnmSLBoneGenerator\avatar_skeleton.xml"
- Assistant
- User
good now alter the script to make it all a code generated avatar.
- Assistant