Vertex groups importing properly. ENVL indicies refer to each model's MNDX, which start from 1, not 0/don't necessarily refer to order in file...
This commit is contained in:
parent
8273e01167
commit
aa62fd47ea
|
@ -12,6 +12,8 @@ from .crc import *
|
||||||
|
|
||||||
envls = []
|
envls = []
|
||||||
|
|
||||||
|
model_counter = 0
|
||||||
|
|
||||||
def read_scene(input_file) -> Scene:
|
def read_scene(input_file) -> Scene:
|
||||||
|
|
||||||
scene = Scene()
|
scene = Scene()
|
||||||
|
@ -71,6 +73,11 @@ def read_scene(input_file) -> Scene:
|
||||||
else:
|
else:
|
||||||
with hedr.read_child() as null:
|
with hedr.read_child() as null:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
for envl in envls:
|
||||||
|
#print("Envelope: ")
|
||||||
|
for index in envl:
|
||||||
|
pass#print("\t" + scene.models[index].name)
|
||||||
|
|
||||||
return scene
|
return scene
|
||||||
|
|
||||||
|
@ -149,7 +156,10 @@ def _read_modl(modl: Reader, materials_list: List[Material]) -> Model:
|
||||||
|
|
||||||
elif "MNDX" in next_header:
|
elif "MNDX" in next_header:
|
||||||
with modl.read_child() as mndx:
|
with modl.read_child() as mndx:
|
||||||
pass
|
index = mndx.read_u32()
|
||||||
|
global model_counter
|
||||||
|
print("Encountered model {} with index {}".format(model_counter, index))
|
||||||
|
model_counter += 1
|
||||||
|
|
||||||
elif "NAME" in next_header:
|
elif "NAME" in next_header:
|
||||||
with modl.read_child() as name:
|
with modl.read_child() as name:
|
||||||
|
@ -169,7 +179,10 @@ def _read_modl(modl: Reader, materials_list: List[Material]) -> Model:
|
||||||
|
|
||||||
elif "GEOM" in next_header:
|
elif "GEOM" in next_header:
|
||||||
model.geometry = []
|
model.geometry = []
|
||||||
|
envelope = []
|
||||||
|
|
||||||
with modl.read_child() as geom:
|
with modl.read_child() as geom:
|
||||||
|
|
||||||
while geom.could_have_child():
|
while geom.could_have_child():
|
||||||
next_header_geom = geom.peak_next_header()
|
next_header_geom = geom.peak_next_header()
|
||||||
|
|
||||||
|
@ -179,14 +192,22 @@ def _read_modl(modl: Reader, materials_list: List[Material]) -> Model:
|
||||||
|
|
||||||
elif "ENVL" in next_header_geom:
|
elif "ENVL" in next_header_geom:
|
||||||
with geom.read_child() as envl:
|
with geom.read_child() as envl:
|
||||||
global envls
|
|
||||||
num_indicies = envl.read_u32()
|
num_indicies = envl.read_u32()
|
||||||
print("reading ENVL with " + str(num_indicies) + " indicies")
|
envelope += [envl.read_u32() - 1 for _ in range(num_indicies)]
|
||||||
envls += [envl.read_u32() for _ in range(num_indicies)]
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
with geom.read_child() as null:
|
with geom.read_child() as null:
|
||||||
pass
|
pass
|
||||||
|
if envelope:
|
||||||
|
global envls
|
||||||
|
envls.append(envelope)
|
||||||
|
|
||||||
|
for seg in model.geometry:
|
||||||
|
if seg.weights:
|
||||||
|
for weight_set in seg.weights:
|
||||||
|
for i in range(len(weight_set)):
|
||||||
|
weight = weight_set[i]
|
||||||
|
weight_set[i] = (envelope[weight[0]], weight[1])
|
||||||
|
|
||||||
elif "SWCI" in next_header:
|
elif "SWCI" in next_header:
|
||||||
prim = CollisionPrimitive()
|
prim = CollisionPrimitive()
|
||||||
|
@ -282,24 +303,30 @@ def _read_segm(segm: Reader, materials_list: List[Material]) -> GeometrySegment:
|
||||||
segm.skip_bytes(-2)
|
segm.skip_bytes(-2)
|
||||||
|
|
||||||
elif "WGHT" in next_header:
|
elif "WGHT" in next_header:
|
||||||
|
print("===================================")
|
||||||
with segm.read_child() as wght:
|
with segm.read_child() as wght:
|
||||||
pass
|
|
||||||
'''
|
|
||||||
geometry_seg.weights = []
|
geometry_seg.weights = []
|
||||||
|
|
||||||
num_weights = wght.read_u32()
|
num_weights = wght.read_u32()
|
||||||
|
|
||||||
for _ in range(num_weights):
|
for _ in range(num_weights):
|
||||||
weight_set = []
|
weight_set = []
|
||||||
|
print_str = ""
|
||||||
for _ in range(4):
|
for _ in range(4):
|
||||||
index = wght.read_u32()
|
index = wght.read_u32()
|
||||||
value = wght.read_f32()
|
value = wght.read_f32()
|
||||||
|
|
||||||
|
print_str += "({}, {}) ".format(index,value)
|
||||||
|
|
||||||
if value > 0.000001:
|
if value > 0.000001:
|
||||||
weight_set.append((index,value))
|
weight_set.append((index,value))
|
||||||
|
|
||||||
|
#print(print_str)
|
||||||
|
|
||||||
geometry_seg.weights.append(weight_set)
|
geometry_seg.weights.append(weight_set)
|
||||||
'''
|
print("===================================")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
with segm.read_child() as unknown:
|
with segm.read_child() as unknown:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -41,7 +41,7 @@ def refined_skeleton_to_armature(refined_skeleton : List[Model], model_map):
|
||||||
|
|
||||||
bone_children = [b for b in get_model_children(bone, refined_skeleton)]
|
bone_children = [b for b in get_model_children(bone, refined_skeleton)]
|
||||||
|
|
||||||
if len(bone_children) > 0:
|
if bone_children:
|
||||||
edit_bone.tail = Vector((0.0,0.0,0.0))
|
edit_bone.tail = Vector((0.0,0.0,0.0))
|
||||||
for bone_child in bone_children:
|
for bone_child in bone_children:
|
||||||
edit_bone.tail += model_map[bone_child.name].matrix_world.translation
|
edit_bone.tail += model_map[bone_child.name].matrix_world.translation
|
||||||
|
@ -50,6 +50,7 @@ def refined_skeleton_to_armature(refined_skeleton : List[Model], model_map):
|
||||||
edit_bone.tail = model_map[bone.name].matrix_world @ Vector((-0.2,0.0,0.0))
|
edit_bone.tail = model_map[bone.name].matrix_world @ Vector((-0.2,0.0,0.0))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
armature_obj.select_set(True)
|
armature_obj.select_set(True)
|
||||||
bpy.context.view_layer.update()
|
bpy.context.view_layer.update()
|
||||||
|
@ -121,12 +122,6 @@ def extract_models(scene: Scene, materials_map):
|
||||||
for model in sort_by_parent(scene.models):
|
for model in sort_by_parent(scene.models):
|
||||||
new_obj = None
|
new_obj = None
|
||||||
|
|
||||||
if "bone_l_toe" in model.name:
|
|
||||||
loc = get_model_world_matrix(model, scene.models).translation
|
|
||||||
print("World bone_l_toe: " + str(loc))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if model.name.startswith("p_") or "collision" in model.name or model.name.startswith("c_") or model.name.startswith("sv_"):
|
if model.name.startswith("p_") or "collision" in model.name or model.name.startswith("c_") or model.name.startswith("sv_"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -141,6 +136,8 @@ def extract_models(scene: Scene, materials_map):
|
||||||
|
|
||||||
full_texcoords = []
|
full_texcoords = []
|
||||||
|
|
||||||
|
weights_offsets = {}
|
||||||
|
|
||||||
for i,seg in enumerate(model.geometry):
|
for i,seg in enumerate(model.geometry):
|
||||||
|
|
||||||
if i == 0:
|
if i == 0:
|
||||||
|
@ -148,6 +145,9 @@ def extract_models(scene: Scene, materials_map):
|
||||||
|
|
||||||
verts += [tuple(convert_vector_space(v)) for v in seg.positions]
|
verts += [tuple(convert_vector_space(v)) for v in seg.positions]
|
||||||
|
|
||||||
|
if seg.weights:
|
||||||
|
weights_offsets[offset] = seg.weights
|
||||||
|
|
||||||
if seg.texcoords is not None:
|
if seg.texcoords is not None:
|
||||||
full_texcoords += seg.texcoords
|
full_texcoords += seg.texcoords
|
||||||
else:
|
else:
|
||||||
|
@ -162,7 +162,7 @@ def extract_models(scene: Scene, materials_map):
|
||||||
new_mesh.validate()
|
new_mesh.validate()
|
||||||
|
|
||||||
|
|
||||||
if len(full_texcoords) > 0:
|
if full_texcoords:
|
||||||
|
|
||||||
edit_mesh = bmesh.new()
|
edit_mesh = bmesh.new()
|
||||||
edit_mesh.from_mesh(new_mesh)
|
edit_mesh.from_mesh(new_mesh)
|
||||||
|
@ -180,10 +180,21 @@ def extract_models(scene: Scene, materials_map):
|
||||||
edit_mesh.to_mesh(new_mesh)
|
edit_mesh.to_mesh(new_mesh)
|
||||||
edit_mesh.free()
|
edit_mesh.free()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
new_obj = bpy.data.objects.new(new_mesh.name, new_mesh)
|
new_obj = bpy.data.objects.new(new_mesh.name, new_mesh)
|
||||||
|
|
||||||
|
|
||||||
|
for offset in weights_offsets:
|
||||||
|
vertex_groups_indicies = {}
|
||||||
|
for i, weight_set in enumerate(weights_offsets[offset]):
|
||||||
|
for weight in weight_set:
|
||||||
|
index = weight[0]
|
||||||
|
|
||||||
|
if index not in vertex_groups_indicies:
|
||||||
|
model_name = scene.models[index].name
|
||||||
|
vertex_groups_indicies[index] = new_obj.vertex_groups.new(name=model_name)
|
||||||
|
|
||||||
|
vertex_groups_indicies[index].add([offset + i], weight[1], 'ADD')
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Assign Materials - will do per segment later...
|
Assign Materials - will do per segment later...
|
||||||
'''
|
'''
|
||||||
|
@ -250,6 +261,12 @@ def extract_scene(filepath: str, scene: Scene):
|
||||||
|
|
||||||
matmap = extract_materials(folder,scene)
|
matmap = extract_materials(folder,scene)
|
||||||
|
|
||||||
|
if scene.skeleton:
|
||||||
|
#print("Skeleton models: ")
|
||||||
|
for model in scene.models:
|
||||||
|
if crc(model.name) in scene.skeleton:
|
||||||
|
pass#print("\tName: " + model.name + " Parent: " + model.parent)
|
||||||
|
|
||||||
model_map = extract_models(scene, matmap)
|
model_map = extract_models(scene, matmap)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue