def test_transform_to_parent(self): basis = asr.Basis3f( asr.Vector3f(1.0, 0.0, 0.0), # normal asr.Vector3f(0.0, 0.0, 1.0), # u asr.Vector3f(0.0, 1.0, 0.0)) # v v = basis.transform_to_parent(asr.Vector3f(3.0, 1.0, 2.0)) self.assertEqual(asr.Vector3f(1.0, 2.0, 3.0), v)
def __set_mesh_key(self, me, key_index): pose = key_index - 1 # Vertices. for i, v in enumerate(me.vertices): self.__mesh_object.set_vertex_pose(i, pose, asr.Vector3f(v.co[0], v.co[1], v.co[2])) # Normals. if self.bl_obj.data.appleseed.export_normals: me.calc_normals_split() loops = me.loops normal_index = 0 for f in me.polygons: loop = f.loop_indices for i in range(0, 3): n = loops[f.loop_indices[i]].normal self.__mesh_object.set_vertex_normal_pose(normal_index, pose, asr.Vector3f(n[0], n[1], n[2])) normal_index += 1
def __convert_mesh(self, me): # Material slots. material_slots = self.bl_obj.material_slots self.__mesh_object.reserve_material_slots(len(material_slots)) if len(material_slots) > 1: for i, m in enumerate(material_slots): self.__mesh_object.push_material_slot("slot-%s" % i) else: self.__mesh_object.push_material_slot("default") # Vertices self.__mesh_object.reserve_vertices(len(me.vertices)) for v in me.vertices: self.__mesh_object.push_vertex(asr.Vector3f(v.co[0], v.co[1], v.co[2])) # Faces. self.__mesh_object.reserve_triangles(len(me.polygons)) for f in me.polygons: assert (len(f.vertices) == 3) tri = asr.Triangle( f.vertices[0], f.vertices[1], f.vertices[2], f.material_index) self.__mesh_object.push_triangle(tri) loops = me.loops # UVs. if self.bl_obj.data.appleseed.export_uvs and len(me.uv_textures) > 0: uv_texture = me.uv_textures.active.data[:] uv_layer = me.uv_layers.active.data[:] self.__mesh_object.reserve_tex_coords(len(me.polygons) * 3) uv_index = 0 for i, f in enumerate(me.polygons): loop = f.loop_indices tri = self.__mesh_object.get_triangle(i) uv = uv_layer[f.loop_indices[0]].uv self.__mesh_object.push_tex_coords(asr.Vector2f(uv[0], uv[1])) tri.m_a0 = uv_index uv_index += 1 uv = uv_layer[f.loop_indices[1]].uv self.__mesh_object.push_tex_coords(asr.Vector2f(uv[0], uv[1])) tri.m_a1 = uv_index uv_index += 1 uv = uv_layer[f.loop_indices[2]].uv self.__mesh_object.push_tex_coords(asr.Vector2f(uv[0], uv[1])) tri.m_a2 = uv_index uv_index += 1 # Normals. if self.bl_obj.data.appleseed.export_normals: me.calc_normals_split() self.__mesh_object.reserve_vertex_normals(len(me.polygons) * 3) normal_index = 0 for i, f in enumerate(me.polygons): loop = f.loop_indices tri = self.__mesh_object.get_triangle(i) n = loops[f.loop_indices[0]].normal self.__mesh_object.push_vertex_normal(asr.Vector3f(n[0], n[1], n[2])) tri.m_n0 = normal_index normal_index += 1 n = loops[f.loop_indices[1]].normal self.__mesh_object.push_vertex_normal(asr.Vector3f(n[0], n[1], n[2])) tri.m_n1 = normal_index normal_index += 1 n = loops[f.loop_indices[2]].normal self.__mesh_object.push_vertex_normal(asr.Vector3f(n[0], n[1], n[2])) tri.m_n2 = normal_index normal_index += 1