mirror of
https://github.com/Theaninova/mhlib.git
synced 2025-12-13 04:56:20 +00:00
(ノಠ益ಠ)ノ彡┻━┻
Materials were wrong because I used materials[polygon_materials[surface_material_id]] Don't ask me why, but it took me half a day and many refactorings to find.
This commit is contained in:
@@ -28,21 +28,20 @@ impl IntermediateLayer {
|
|||||||
pub fn commit(self, materials: &HashMap<u16, MaterialUvInfo>) -> Gd<ArrayMesh> {
|
pub fn commit(self, materials: &HashMap<u16, MaterialUvInfo>) -> Gd<ArrayMesh> {
|
||||||
let mut mesh = ArrayMesh::new();
|
let mut mesh = ArrayMesh::new();
|
||||||
mesh.set_name(self.name.clone().into());
|
mesh.set_name(self.name.clone().into());
|
||||||
let mut surface_material_ids = Vec::<u16>::new();
|
let surface_material_ids = self.material_mappings.values().unique().collect_vec();
|
||||||
|
|
||||||
for material_id in self.material_mappings.values().unique() {
|
for material_id in surface_material_ids.iter() {
|
||||||
let surface_info = SurfaceInfo::collect_from_layer(&self, &materials[material_id]);
|
let surface_info = SurfaceInfo::collect_from_layer(&self, &materials[material_id]);
|
||||||
|
|
||||||
if !surface_info.is_empty() {
|
debug_assert!(!surface_info.is_empty());
|
||||||
mesh.add_surface_from_arrays(
|
|
||||||
PrimitiveType::PRIMITIVE_TRIANGLES,
|
mesh.add_surface_from_arrays(
|
||||||
surface_info.commit_to_arrays(),
|
PrimitiveType::PRIMITIVE_TRIANGLES,
|
||||||
Array::new(),
|
surface_info.commit_to_arrays(),
|
||||||
Dictionary::new(),
|
Array::new(),
|
||||||
ArrayFormat::ARRAY_FORMAT_NORMAL,
|
Dictionary::new(),
|
||||||
);
|
ArrayFormat::ARRAY_FORMAT_NORMAL,
|
||||||
surface_material_ids.push(*material_id);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
godot_print!(
|
godot_print!(
|
||||||
@@ -55,12 +54,7 @@ impl IntermediateLayer {
|
|||||||
.collect_vec()
|
.collect_vec()
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut final_mesh = post_process_mesh(
|
let mut final_mesh = post_process_mesh(mesh, materials, surface_material_ids);
|
||||||
mesh,
|
|
||||||
materials,
|
|
||||||
surface_material_ids,
|
|
||||||
&self.material_mappings,
|
|
||||||
);
|
|
||||||
final_mesh.set_name(self.name.into());
|
final_mesh.set_name(self.name.into());
|
||||||
final_mesh
|
final_mesh
|
||||||
}
|
}
|
||||||
@@ -69,8 +63,7 @@ impl IntermediateLayer {
|
|||||||
fn post_process_mesh(
|
fn post_process_mesh(
|
||||||
mesh: Gd<ArrayMesh>,
|
mesh: Gd<ArrayMesh>,
|
||||||
materials: &HashMap<u16, MaterialUvInfo>,
|
materials: &HashMap<u16, MaterialUvInfo>,
|
||||||
material_ids: Vec<u16>,
|
material_ids: Vec<&u16>,
|
||||||
material_mappings: &HashMap<i32, u16>,
|
|
||||||
) -> Gd<ArrayMesh> {
|
) -> Gd<ArrayMesh> {
|
||||||
let mut out_mesh = ArrayMesh::new();
|
let mut out_mesh = ArrayMesh::new();
|
||||||
|
|
||||||
@@ -91,9 +84,8 @@ fn post_process_mesh(
|
|||||||
ArrayFormat::ARRAY_FORMAT_NORMAL,
|
ArrayFormat::ARRAY_FORMAT_NORMAL,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(mat) = materials.get(&material_mappings[&(surface_id as i32)]) {
|
let mat = &materials[surface_id];
|
||||||
out_mesh.surface_set_material(surface_idx as i64, mat.material.share().upcast())
|
out_mesh.surface_set_material(surface_idx as i64, mat.material.share().upcast())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out_mesh
|
out_mesh
|
||||||
|
|||||||
Reference in New Issue
Block a user