From a5818e6f666a94dbaa4bfd7ac5d15844ba93d8c7 Mon Sep 17 00:00:00 2001 From: coderbot16 Date: Fri, 16 Nov 2018 11:52:04 -0800 Subject: [PATCH] Fix up texture coordinate handling from OBJ/COLLADA to CEM --- src/collada_export.rs | 4 ++-- src/main.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/collada_export.rs b/src/collada_export.rs index 42fa6ac..e5eb558 100644 --- a/src/collada_export.rs +++ b/src/collada_export.rs @@ -61,7 +61,7 @@ impl<'n> fmt::Display for Geometry<'n> { write_source("mesh-positions", &self.mesh_positions, 3, FORMAT_POS)?; write_source("mesh-normals", &self.mesh_normals, 3, FORMAT_POS)?; - write_source("mesh-map", &self.mesh_map, 3, FORMAT_TEX)?; + write_source("mesh-map", &self.mesh_map, 2, FORMAT_TEX)?; } writeln!(f, r##" "##, self.name)?; @@ -138,7 +138,7 @@ pub fn convert(cem: Scene) -> String { geometry.mesh_normals[index*3 + 2] = normal.z; geometry.mesh_map[index*2 + 0] = vertex.texture.x; - geometry.mesh_map[index*2 + 1] = vertex.texture.y; + geometry.mesh_map[index*2 + 1] = 1.0 - vertex.texture.y; } writeln!(string, "{}", geometry).unwrap(); diff --git a/src/main.rs b/src/main.rs index d395719..72969a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -210,7 +210,7 @@ fn obj_to_cem(i: &Object) -> V2 { vertices.push(v2::Vertex { position, normal, - texture: Point2 { x: texture.u as f32, y: texture.v as f32 }, + texture: Point2 { x: texture.u as f32, y: 1.0 - texture.v as f32 }, }); index @@ -285,7 +285,7 @@ fn cem2_to_obj(cem: V2, frame_index: usize) -> String { writeln!(string, "v {} {} {}", position.x, position.y, position.z).unwrap(); writeln!(string, "vn {} {} {}", normal.x, normal.y, normal.z).unwrap(); - writeln!(string, "vt {} {}", texture.x, texture.y).unwrap(); + writeln!(string, "vt {} {}", texture.x, 1.0 - texture.y).unwrap(); } for &v2::Material { ref name, texture, ref triangles, vertex_offset, vertex_count: _vertex_count, ref texture_name } in &cem.materials {