示例#1
0
 def test_niff2_part_list_header_builder(self):
     one_tri = niff2_part_node_builder(12, 34, 56, 78, [1])
     two_tris = niff2_part_node_builder(12, 34, 56, 78, [1, 2])
     parts = [one_tri, two_tris]
     part_list_header = niff2_part_list_header_builder(parts)
     self.assertEqual(part_list_header.part_list_tag, 0x00090000)
     self.assertEqual(part_list_header.part_list_header_size, 32)
     self.assertEqual(part_list_header.part_list_size, 116)
     self.assertEqual(part_list_header.part_num, 2)
     self.assertEqual(part_list_header.nintendo_extension_block_size, 0)
     self.assertEqual(part_list_header.user_extension_block_size, 0)
示例#2
0
 def test_niff2_part_list_header_writer(self):
     one_tri = niff2_part_node_builder(12, 34, 56, 78, [1])
     two_tris = niff2_part_node_builder(12, 34, 56, 78, [1, 2])
     parts = [one_tri, two_tris]
     part_list_header = niff2_part_list_header_builder(parts)
     buf = niff2_part_list_header_writer(part_list_header, parts,
                                         bytearray())
     byte_list = [
         0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
         0x74, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x2C
     ]
     self.assertEqual(list(buf), byte_list)
示例#3
0
 def test_niff2_shape_node_writer(self):
     part0 = niff2_part_node_builder(1, 2, 3, 4, [5, 6])
     part1 = niff2_part_node_builder(7, 8, 9, 0, [1, 2, 3])
     shape_node = niff2_shape_node_builder(12, 34, 56, 78, [part0, part1])
     buf = niff2_shape_node_writer(shape_node, bytearray())
     byte_list = [
         0x00, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
         0x3C, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00,
         0x00, 0x38, 0x00, 0x00, 0x00, 0x4E, 0x00, 0x00, 0x00, 0x02, 0x00,
         0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
         0x00, 0x00, 0x00, 0x07, 0x00, 0x08, 0x01, 0x00, 0xFF, 0xFF, 0xFF,
         0xFF, 0xFF, 0xFF, 0xFF, 0xFF
     ]
     self.assertEqual(list(buf), byte_list)
示例#4
0
 def test_niff2_shape_list_header_builder(self):
     part0 = niff2_part_node_builder(1, 2, 3, 4, [5])
     part1 = niff2_part_node_builder(6, 7, 8, 9, [0, 1])
     part2 = niff2_part_node_builder(2, 3, 4, 5, [6, 7, 8])
     one_part = niff2_shape_node_builder(12, 34, 56, 78, [part0])
     two_parts = niff2_shape_node_builder(78, 56, 43, 21, [part1, part2])
     shape_list_header = niff2_shape_list_header_builder(
         [one_part, two_parts])
     self.assertEqual(shape_list_header.shape_list_tag, 0x00030000)
     self.assertEqual(shape_list_header.shape_list_header_size, 32)
     self.assertEqual(shape_list_header.shape_list_size, 148)
     self.assertEqual(shape_list_header.shape_num, 2)
     self.assertEqual(shape_list_header.nintendo_extension_block_size, 0)
     self.assertEqual(shape_list_header.user_extension_block_size, 0)
示例#5
0
    def create_parts(self, objs):
        """
        Create and register shape parts.
        """
        meshes = [obj.data for obj in objs if isinstance(obj.data, Mesh)]

        for mesh in meshes:
            mesh.calc_loop_triangles()

            self.parts_by_mesh[mesh] = []

            for mat_index in range(len(mesh.materials)):
                tri_indices = []

                for tri_index, tri in zip(range(len(mesh.loop_triangles)),
                                          mesh.loop_triangles):
                    if tri.material_index == mat_index:
                        tri_indices.append(tri_index)

                tri_group_index = self.tri_group_by_mesh[mesh].index()
                part_name = self.create_name(mesh.name + ".part." +
                                             str(mat_index).zfill(2))
                mat_index = self.materials_by_mesh[mesh][mat_index].index()

                part_node = niff2_part_node_builder(len(self.parts),
                                                    part_name.index(),
                                                    tri_group_index, mat_index,
                                                    tri_indices)

                self.parts.append(part_node)
                self.parts_by_mesh[mesh].append(part_node)
示例#6
0
 def test_niff2_shape_list_header_writer(self):
     part0 = niff2_part_node_builder(1, 2, 3, 4, [5])
     part1 = niff2_part_node_builder(6, 7, 8, 9, [0, 1])
     part2 = niff2_part_node_builder(2, 3, 4, 5, [6, 7, 8])
     one_part = niff2_shape_node_builder(12, 34, 56, 78, [part0])
     two_parts = niff2_shape_node_builder(78, 56, 43, 21, [part1, part2])
     shape_list_header = niff2_shape_list_header_builder(
         [one_part, two_parts])
     buf = niff2_shape_list_header_writer(shape_list_header,
                                          [one_part, two_parts],
                                          bytearray())
     byte_list = [
         0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
         0x94, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x3C
     ]
     self.assertEqual(list(buf), byte_list)
示例#7
0
 def test_niff2_shape_node_builder(self):
     part0 = niff2_part_node_builder(1, 2, 3, 4, [5, 6])
     part1 = niff2_part_node_builder(7, 8, 9, 0, [1, 2, 3])
     shape_node = niff2_shape_node_builder(12, 34, 56, 78, [part0, part1])
     self.assertEqual(shape_node.shape_tag, 0x00030100)
     self.assertEqual(shape_node.this_shape_index, 12)
     self.assertEqual(shape_node.shape_size, 60)
     self.assertEqual(shape_node.shape_name_index, 34)
     self.assertEqual(shape_node.shape_type, 0x00000014)
     self.assertEqual(shape_node.shape_tri_link, 56)
     self.assertEqual(shape_node.shape_mat_link, 78)
     self.assertEqual(shape_node.shape_part_num, 2)
     self.assertEqual(shape_node.nintendo_extension_block_size, 12)
     self.assertEqual(shape_node.user_extension_block_size, 0)
     self.assertEqual(shape_node.kind_of_node_for_geometry, 0x00080100)
     self.assertEqual(shape_node.external_mat_file_name_index, 0xFFFFFFFF)
     self.assertEqual(shape_node.external_mat_name_index, 0xFFFFFFFF)
     self.assertEqual(shape_node.parts, [part0, part1])
示例#8
0
 def test_niff2_part_node_writer(self):
     part_node = niff2_part_node_builder(1, 2, 3, 4, [5, 6, 7, 8, 9, 0])
     buf = niff2_part_node_writer(part_node, bytearray())
     byte_list = [
         0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
         0x3C, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
         0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06,
         0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
         0x09, 0x00, 0x00, 0x00, 0x00
     ]
     self.assertEqual(list(buf), byte_list)
示例#9
0
 def test_niff2_part_node_builder(self):
     part_node = niff2_part_node_builder(1, 2, 3, 4, [5, 6, 7, 8, 9, 0])
     self.assertEqual(part_node.part_tag, 0x00090100)
     self.assertEqual(part_node.this_part_index, 1)
     self.assertEqual(part_node.part_size, 60)
     self.assertEqual(part_node.part_name_index, 2)
     self.assertEqual(part_node.mat_index, 4)
     self.assertEqual(part_node.tri_group_index, 3)
     self.assertEqual(part_node.part_tri_num, 6)
     self.assertEqual(part_node.nintendo_extension_block_size, 0)
     self.assertEqual(part_node.user_extension_block_size, 0)
     self.assertEqual(part_node.tri_indices, [5, 6, 7, 8, 9, 0])