Advertisement
cfox04

Untitled

Nov 17th, 2021
55
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def get_shader_index(mats, mat):
  2.     for i in range(len(mats)):
  3.         if mats[i] == mat:
  4.             return i
  5.  
  6.  
  7. def geometry_from_object(obj, mats, bones=None, export_settings=None):
  8.     geometry = GeometryItem()
  9.  
  10.     geometry.shader_index = get_shader_index(mats, obj.active_material)
  11.  
  12.     obj, mesh = apply_and_triangulate_object(obj)
  13.  
  14.     bbmin, bbmax = get_bound_extents(obj, world=export_settings.use_transforms)
  15.     geometry.bounding_box_min = bbmin
  16.     geometry.bounding_box_max = bbmax
  17.  
  18.     shader_name = obj.active_material.shader_properties.name
  19.     shader = ShaderManager.shaders[shader_name]
  20.  
  21.     layout = shader.get_layout_from_semantic(
  22.         get_semantic_from_object(shader, mesh))
  23.  
  24.     geometry.vertex_buffer.layout = layout.value
  25.     vertex_buffer, index_buffer = get_mesh_buffers(
  26.         obj, mesh, layout.vertex_type, bones, export_settings)
  27.  
  28.     geometry.vertex_buffer.data = vertex_buffer
  29.     geometry.index_buffer.data = index_buffer
  30.  
  31.     return geometry
  32.  
  33.  
  34. def drawable_model_from_object(obj, bones=None, export_settings=None):
  35.     drawable_model = DrawableModelItem()
  36.  
  37.     drawable_model.render_mask = obj.drawable_model_properties.render_mask
  38.     drawable_model.flags = obj.drawable_model_properties.flags
  39.  
  40.     # rawable_model.bone_index = 0
  41.     if bones is not None:
  42.         drawable_model.has_skin = 1
  43.         drawable_model.unknown_1 = len(bones)
  44.  
  45.     for child in obj.children:
  46.         if child.sollum_type == SollumType.DRAWABLE_GEOMETRY:
  47.             if len(child.data.materials) > 1:
  48.                 # Preserve original order of materials
  49.                 mats = child.data.copy().materials
  50.                 objs = split_object(child, obj)
  51.                 for obj in objs:
  52.                     geometry = geometry_from_object(
  53.                         obj, mats, bones, export_settings)  # MAYBE WRONG ASK LOYALIST
  54.                     drawable_model.geometries.append(geometry)
  55.                 join_objects(objs)
  56.             else:
  57.                 geometry = geometry_from_object(
  58.                     child, get_used_materials(obj.parent), bones, export_settings)
  59.                 drawable_model.geometries.append(geometry)
  60.  
  61.     return drawable_model
Advertisement
RAW Paste Data Copied
Advertisement