예제 #1
0
 def test_niff2_st_group_builder(self, _, index, st_floats, expected_size):
     st_group = niff2_st_group_builder(index, st_floats)
     self.assertEqual(st_group.st_group_tag, 0x00070100)
     self.assertEqual(st_group.this_st_group_index, index)
     self.assertEqual(st_group.st_group_header_size, 20)
     self.assertEqual(st_group.st_group_size, expected_size)
     self.assertEqual(st_group.st_num, len(st_floats) // 2)
예제 #2
0
    def create_st_groups(self, objs):
        """
        Create and register texture coord groups.
        """
        default_st = [0.5, 0.5]  # center
        default_st_group = niff2_st_group_builder(0, default_st)
        self.st_groups.append(default_st_group)

        meshes = [obj.data for obj in objs if isinstance(obj.data, Mesh)]

        for mesh in meshes:
            if mesh.uv_layers:
                mesh.calc_loop_triangles()

                # Collect unique tex coords in index_by_st with undefined indices
                index_by_st = {}
                for tri in mesh.loop_triangles:
                    for i in range(3):
                        loop_index = tri.loops[i]
                        s_t = tuple(mesh.uv_layers[0].data[loop_index].uv)
                        index_by_st[s_t] = -1

                # Map keys to st and set indices
                st_list = list(index_by_st.keys())
                for index, s_t in zip(range(len(st_list)), st_list):
                    index_by_st[s_t] = index

                # Create mesh st indices
                st_indices = []
                for tri in mesh.loop_triangles:
                    for i in range(3):
                        loop_index = tri.loops[i]
                        s_t = tuple(mesh.uv_layers[0].data[loop_index].uv)
                        st_indices.append(index_by_st[s_t])
                self.st_indices_by_mesh[mesh] = st_indices

                # Create NIFF2 data
                st_group = niff2_st_group_builder(len(
                    self.st_groups), [value for st in st_list for value in st])
                self.st_groups.append(st_group)

            else:
                self.st_indices_by_mesh[mesh] = [0] * len(
                    mesh.loop_triangles) * 3
                st_group = niff2_st_group_builder(len(self.st_groups),
                                                  default_st)
                self.st_groups.append(st_group)
예제 #3
0
 def test_niff2_st_list_header_builder(self):
     st_floats = [1.0, 2.0, 3.0, 4.0]
     st_group = niff2_st_group_builder(123, st_floats)
     st_list_header = niff2_st_list_header_builder([st_group])
     self.assertEqual(st_list_header.st_list_tag, 0x00070000)
     self.assertEqual(st_list_header.st_list_header_size, 28)
     self.assertEqual(st_list_header.st_list_size, 64)
     self.assertEqual(st_list_header.st_group_num, 1)
     self.assertEqual(st_list_header.nintendo_extension_block_size, 0)
     self.assertEqual(st_list_header.user_extension_block_size, 0)
예제 #4
0
 def test_niff2_st_group_writer(self):
     st_floats = [1.0, 2.0, 3.0, 4.0]
     st_group = niff2_st_group_builder(123, st_floats)
     buf = niff2_st_group_writer(st_group, bytearray())
     byte_list = [
         0x00, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x7B, 0x00, 0x00, 0x00,
         0x14, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x02, 0x3F, 0x80,
         0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x40,
         0x80, 0x00, 0x00
     ]
     self.assertEqual(list(buf), byte_list)
예제 #5
0
 def test_niff2_st_list_header_writer(self):
     st_floats = [1.0, 2.0, 3.0, 4.0]
     st_group = niff2_st_group_builder(123, st_floats)
     st_list_header = niff2_st_list_header_builder([st_group])
     buf = niff2_st_list_header_writer(st_list_header, [st_group],
                                       bytearray())
     byte_list = [
         0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00,
         0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
         0x00, 0x00, 0x00, 0x00, 0x00, 0x24
     ]
     self.assertEqual(list(buf), byte_list)