forked from StrafesNET/strafe-project
common: truncate vertex precision to 16 bits in MeshBuilder
The physics algorithm expects vertices to align exactly with faces. Since the face normal is calculated via the cross product of vertex positions, this allows the face normals to be exact with respect to the vertex positions.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::integer::{Planar64Vec3,Planar64Affine3};
|
||||
use crate::integer::{Planar64,Planar64Vec3,Planar64Affine3};
|
||||
use crate::gameplay_attributes;
|
||||
|
||||
pub type TextureCoordinate=glam::Vec2;
|
||||
@@ -168,6 +168,11 @@ impl MeshBuilder{
|
||||
}
|
||||
}
|
||||
pub fn acquire_pos_id(&mut self,pos:Planar64Vec3)->PositionId{
|
||||
// Truncate the 16 most precise bits of the vertex positions.
|
||||
// This allows the normal vectors to exactly represent the face.
|
||||
// Remove this in Mesh V2
|
||||
const MASK:Planar64=Planar64::raw(!((1<<16)-1));
|
||||
let pos=pos.map(|c|c&MASK);
|
||||
*self.pos_id_from.entry(pos).or_insert_with(||{
|
||||
let pos_id=PositionId::new(self.unique_pos.len() as u32);
|
||||
self.unique_pos.push(pos);
|
||||
|
||||
Reference in New Issue
Block a user