diff options
Diffstat (limited to 'extractor/rsm_format.gd')
-rw-r--r-- | extractor/rsm_format.gd | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/extractor/rsm_format.gd b/extractor/rsm_format.gd index cf83af9..2eccbd2 100644 --- a/extractor/rsm_format.gd +++ b/extractor/rsm_format.gd @@ -39,10 +39,12 @@ var texture_count: int ## Length: [member texture_count] ## Byte Length: 40 +## Versions: [<2.3] var texture_names: Array[String] ## Byte Type: u8 ## Byte Length: 40 +## Versions: [<2.2] var root_node_name: String ## Byte Type: u32 [br] @@ -90,23 +92,24 @@ static func from_bytes(bytes: ByteStream) -> RSMFormat: rsm_format.texture_names = [] as Array[String] for _n in rsm_format.texture_count: - rsm_format.texture_names.append(bytes.get_string_from_utf8(40)) + rsm_format.texture_names.append(bytes.get_string_from_ascii(40)) - rsm_format.root_node_name = bytes.get_string_from_utf8(40) + if version.lower_than(2, 2): + rsm_format.root_node_name = bytes.get_string_from_ascii(40) if version.higher_than(2, 1): # >= 2.2 rsm_format.root_node_count = bytes.decode_u32() rsm_format.root_node_names = [] as Array[String] for _n in rsm_format.root_node_count: - rsm_format.root_node_names.append(bytes.get_string_from_utf8(40)) + rsm_format.root_node_names.append(bytes.get_string_from_ascii(40)) rsm_format.node_count = bytes.decode_u32() rsm_format.nodes = [] as Array[ModelNode] for _n in rsm_format.node_count: rsm_format.nodes.append(ModelNode.from_bytes(bytes, version)) - print(inst_to_dict(rsm_format)) + #print(inst_to_dict(rsm_format)) #print(inst_to_dict(rsm_format.nodes[0].texture_coordinates[0])) #rsm_format.nodes[0].texture_coordinates.clear() #print(inst_to_dict(rsm_format.nodes[0].faces[0])) @@ -115,12 +118,16 @@ static func from_bytes(bytes: ByteStream) -> RSMFormat: return rsm_format -func convert() -> Node3D: - var node := Node3D.new() - node.name = root_node_name +func convert(data_path: String) -> Node3D: + var root_node := Node3D.new() + root_node.name = root_node_name #node.set_script(load("res://extractor/model.gd")) - return node + for model_node in nodes: + var node: Node = model_node.convert(texture_names, data_path) + root_node.add_child(node) + + return root_node class ModelNode: @@ -245,7 +252,7 @@ class ModelNode: var node = ModelNode.new() node.node_name = bytes.get_string_from_utf8(40) - node.parent_node_name = bytes.get_string_from_utf8(40) + node.parent_node_name = bytes.get_string_from_ascii(40) if version.lower_than(2, 3): # < 2.3 node.texture_count = bytes.decode_u32() @@ -259,7 +266,7 @@ class ModelNode: node.texture_names = [] as Array[String] for _n in node.texture_name_count: - node.texture_names.append(bytes.get_string_from_utf8(40)) + node.texture_names.append(bytes.get_string_from_ascii(40)) node.offset_matrix = [] as Array[Vector3] for _in in 3: @@ -345,6 +352,43 @@ class ModelNode: node.textures_keyframes.append(TexturesKeyframe.from_bytes(bytes)) return node + + + func convert(textures: Array[String], data_path: String): + var node := MeshInstance3D.new() + node.name = node_name + + node.translate(translation_2) + + if rotation_axis != Vector3.ZERO: + node.rotate(rotation_axis, rotation_angle) + + node.scale = scale + + var surface_tool := SurfaceTool.new() + surface_tool.begin(Mesh.PRIMITIVE_TRIANGLES) + + var mesh := ArrayMesh.new() + for idx in faces.size(): + var face := faces[idx] + + surface_tool.add_triangle_fan( + PackedVector3Array(face.vertex_position_indices.map(func(idx): + return vertex_positions[idx]) + ), + PackedVector2Array(face.texture_coordinate_indices.map(func(idx): + return texture_coordinates[idx].coordinates) + ) + ) + surface_tool.commit(mesh) + + var material := StandardMaterial3D.new() + material.albedo_texture = load("%s/data/texture/%s" % [data_path, textures[face.texture_index]]) + mesh.surface_set_material(idx, material) + + node.mesh = mesh + + return node class TextureCoordinate: |