コード例 #1
0
 def test_niff2_tri_list_header_builder(self):
     one_tri = niff2_tri_group_builder(1, 2, 3, [4, 5, 6], [7, 8, 9],
                                       [10, 11, 12])
     two_tris = niff2_tri_group_builder(1, 2, 3, [4, 5, 6, 7, 8, 9],
                                        [10, 11, 12, 13, 14, 15],
                                        [16, 17, 18, 19, 20, 21])
     tri_list_header = niff2_tri_list_header_builder([one_tri, two_tris])
     self.assertEqual(tri_list_header.tri_list_tag, 0x00080000)
     self.assertEqual(tri_list_header.tri_list_header_size, 32)
     self.assertEqual(tri_list_header.tri_list_size, 372)
     self.assertEqual(tri_list_header.tri_group_num, 2)
     self.assertEqual(tri_list_header.nintendo_extension_block_size, 0)
     self.assertEqual(tri_list_header.user_extension_block_size, 0)
コード例 #2
0
 def test_niff2_tri_list_header_writer(self):
     one_tri = niff2_tri_group_builder(1, 2, 3, [4, 5, 6], [7, 8, 9],
                                       [10, 11, 12])
     two_tris = niff2_tri_group_builder(1, 2, 3, [4, 5, 6, 7, 8, 9],
                                        [10, 11, 12, 13, 14, 15],
                                        [16, 17, 18, 19, 20, 21])
     tri_groups = [one_tri, two_tris]
     tri_list_header = niff2_tri_list_header_builder(tri_groups)
     buf = niff2_tri_list_header_writer(tri_list_header, tri_groups,
                                        bytearray())
     byte_list = [
         0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x01,
         0x74, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0xD0
     ]
     self.assertEqual(list(buf), byte_list)
コード例 #3
0
 def test_niff2_tri_group_writer(self):
     tri_group = niff2_tri_group_builder(12, 34, 56, [1, 2, 3], [4, 5, 6],
                                         [7, 8, 9])
     buf = niff2_tri_group_writer(tri_group, bytearray())
     byte_list = [
         0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00,
         0x20, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
         0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00,
         0x39, 0x00, 0x08, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04,
         0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
         0x08, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
         0x00, 0x03, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x06, 0x00,
         0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     ]
     self.assertEqual(list(buf), byte_list)
コード例 #4
0
 def test_niff2_tri_group_builder(self, _, index, name_index,
                                  vtx_group_index, vtx_indices,
                                  normal_indices, st_indices,
                                  expected_size):
     tri_group = niff2_tri_group_builder(index, name_index, vtx_group_index,
                                         vtx_indices, normal_indices,
                                         st_indices)
     self.assertEqual(tri_group.tri_group_tag, 0x00080100)
     self.assertEqual(tri_group.this_tri_group_index, index)
     self.assertEqual(tri_group.tri_group_header_size, 32)
     self.assertEqual(tri_group.tri_group_size, expected_size)
     self.assertEqual(tri_group.tri_group_name_index, name_index)
     self.assertEqual(tri_group.tri_anim_type, 0)
     self.assertEqual(tri_group.tri_anim_frame_num, 0)
     self.assertEqual(tri_group.tri_num, len(vtx_indices) // 3)
     self.assertEqual(tri_group.vtx_group_index, vtx_group_index)
     self.assertEqual(tri_group.tri_color_group_index, 0)
     self.assertEqual(tri_group.vtx_color_group_index, vtx_group_index + 1)
     self.assertEqual(tri_group.tri_nv_group_index, 0)
     self.assertEqual(tri_group.vtx_nv_group_index, vtx_group_index + 1)
     self.assertEqual(tri_group.st_group_index, vtx_group_index + 1)
     for tri_index, tri in zip(range(len(tri_group.tris)), tri_group.tris):
         self.assertEqual(tri_index, tri.this_tri_index)
コード例 #5
0
ファイル: exporter.py プロジェクト: 1r3n33/blend2niff
    def create_tri_groups(self, objs):
        """
        Create and register all triangle groups.
        """
        meshes = [obj.data for obj in objs if isinstance(obj.data, Mesh)]

        for mesh in meshes:
            mesh.calc_loop_triangles()

            tri_group_name = self.create_name(mesh.name + ".tri")
            vtx_group = self.vtx_group_by_mesh[mesh]
            vtx_indices = [
                index for tri in mesh.loop_triangles for index in tri.vertices
            ]
            normal_indices = self.normal_indices_by_mesh[mesh]
            st_indices = self.st_indices_by_mesh[mesh]

            tri_group = niff2_tri_group_builder(len(self.tri_groups),
                                                tri_group_name.index(),
                                                vtx_group.index(), vtx_indices,
                                                normal_indices, st_indices)

            self.tri_groups.append(tri_group)
            self.tri_group_by_mesh[mesh] = tri_group