sprinkle sacred runes

This commit is contained in:
Quaternions 2023-09-28 17:45:47 -07:00
parent 59ee0cee3b
commit 822c9d6d5f
5 changed files with 46 additions and 42 deletions

View File

@ -284,7 +284,7 @@ pub enum AabbFace{
Bottom,
Front,
}
#[derive(Clone)]
pub struct Aabb {
min: glam::Vec3,
max: glam::Vec3,
@ -393,7 +393,7 @@ pub struct ModelPhysics {
impl ModelPhysics {
pub fn from_model(model:&crate::model::IndexedModel,model_transform:glam::Affine3A) -> Self {
let mut aabb=Aabb::new();
for &indexed_vertex in &model.unique_vertices {
for indexed_vertex in &model.unique_vertices {
aabb.grow(model_transform.transform_point3(glam::Vec3::from_array(model.unique_pos[indexed_vertex.pos as usize])));
}
Self{
@ -403,14 +403,14 @@ impl ModelPhysics {
pub fn unit_vertices(&self) -> [glam::Vec3;8] {
Aabb::unit_vertices()
}
pub fn mesh(&self) -> TreyMesh {
return self.mesh;
pub fn mesh(&self) -> &TreyMesh {
return &self.mesh;
}
pub fn unit_face_vertices(&self,face:TreyMeshFace) -> [glam::Vec3;4] {
Aabb::unit_face_vertices(face)
}
pub fn face_mesh(&self,face:TreyMeshFace) -> TreyMesh {
let mut aabb=self.mesh;
let mut aabb=self.mesh.clone();
//in this implementation face = worldspace aabb face
match face {
AabbFace::Right => aabb.min.x=aabb.max.x,
@ -437,7 +437,7 @@ pub struct RelativeCollision {
impl RelativeCollision {
pub fn mesh(&self,models:&Vec<ModelPhysics>) -> TreyMesh {
return models.get(self.model as usize).unwrap().face_mesh(self.face)
return models.get(self.model as usize).unwrap().face_mesh(self.face).clone()
}
pub fn normal(&self,models:&Vec<ModelPhysics>) -> glam::Vec3 {
return models.get(self.model as usize).unwrap().face_normal(self.face)

View File

@ -70,7 +70,7 @@ impl std::hash::Hash for RobloxTextureTransform {
self.scale_v.to_ne_bytes().hash(state);
}
}
#[derive(PartialEq)]
#[derive(Clone,PartialEq)]
struct RobloxFaceTextureDescription{
texture:u32,
color:glam::Vec4,
@ -88,10 +88,10 @@ impl std::hash::Hash for RobloxFaceTextureDescription {
}
type RobloxPartDescription=[Option<RobloxFaceTextureDescription>;6];
type RobloxWedgeDescription=[Option<RobloxFaceTextureDescription>;5];
#[derive(Eq, Hash, PartialEq)]
#[derive(Clone,Eq,Hash,PartialEq)]
enum RobloxBasePartDescription{
Part(RobloxPartDescription),
Wedge(RobloxWedgeDescription),
//Wedge(RobloxWedgeDescription),
}
pub fn generate_indexed_models_roblox(dom:rbx_dom_weak::WeakDom) -> Result<(IndexedModelInstances,glam::Vec3), Box<dyn std::error::Error>>{
//IndexedModelInstances includes textures
@ -221,28 +221,32 @@ pub fn generate_indexed_models_roblox(dom:rbx_dom_weak::WeakDom) -> Result<(Inde
//push to existing texture model
model_id
}else{
let unit_cube_faces=part_texture_description.map(|face|{
match face{
Some(roblox_texture_transform)=>Some(
primitives::FaceDescription{
texture:Some(roblox_texture_transform.texture),
transform:glam::Affine2::from_translation(
glam::vec2(roblox_texture_transform.transform.offset_u,roblox_texture_transform.transform.offset_v)
)
*glam::Affine2::from_scale(
glam::vec2(roblox_texture_transform.transform.scale_u,roblox_texture_transform.transform.scale_v)
),
color:roblox_texture_transform.color,
}
),
None=>None,
}
});
let mut indexed_model=primitives::generate_partial_unit_cube(unit_cube_faces);
let model_id=indexed_models.len();
indexed_models.push(indexed_model);
model_id_from_description.insert(basepart_texture_description,model_id);
model_id
model_id_from_description.insert(basepart_texture_description.clone(),model_id);//borrow checker going crazy
match basepart_texture_description{
RobloxBasePartDescription::Part(part_texture_description)=>{
let unit_cube_faces=part_texture_description.map(|face|{
match face{
Some(roblox_texture_transform)=>Some(
primitives::FaceDescription{
texture:Some(roblox_texture_transform.texture),
transform:glam::Affine2::from_translation(
glam::vec2(roblox_texture_transform.transform.offset_u,roblox_texture_transform.transform.offset_v)
)
*glam::Affine2::from_scale(
glam::vec2(roblox_texture_transform.transform.scale_u,roblox_texture_transform.transform.scale_v)
),
color:roblox_texture_transform.color,
}
),
None=>None,
}
});
let indexed_model=primitives::generate_partial_unit_cube(unit_cube_faces);
indexed_models.push(indexed_model);
model_id
},
}
};
indexed_models[model_id].instances.push(ModelInstance {
model_transform,

View File

@ -84,9 +84,9 @@ impl GraphicsData {
}
fn generate_model_physics(&mut self,indexed_models:&model::IndexedModelInstances){
for model in indexed_models.models{
for model in &indexed_models.models{
//make aabb and run vertices to get realistic bounds
for model_instance in model.instances{
for model_instance in &model.instances{
self.physics.models.push(body::ModelPhysics::from_model(&model,model_instance.model_transform));
}
}
@ -140,7 +140,7 @@ impl GraphicsData {
//de-index models and split groups with different textures into separate models
//the models received here are supposed to be tightly packed, i.e. no code needs to check if two models are using the same groups.
let mut unique_texture_models=Vec::with_capacity(indexed_models.models.len());
for model in indexed_models.models.drain(..){
for mut model in indexed_models.models.drain(..){
//check each group, if it's using a new texture then make a new clone of the model
let id=unique_texture_models.len();
let mut unique_textures=Vec::new();

View File

@ -62,13 +62,13 @@ pub struct IndexedModelInstances{
pub fn generate_indexed_model_list_from_obj(data:obj::ObjData,color:[f32;4]) -> Vec<IndexedModel>{
let mut unique_vertex_index = std::collections::HashMap::<obj::IndexTuple,u32>::new();
return data.objects.iter().map(|&object|{
return data.objects.iter().map(|object|{
unique_vertex_index.clear();
let mut unique_vertices = Vec::new();
let groups = object.groups.iter().map(|&group|{
let groups = object.groups.iter().map(|group|{
IndexedGroup{
texture:None,
polys:group.polys.iter().map(|&poly|{
polys:group.polys.iter().map(|poly|{
IndexedPolygon{
vertices:poly.0.iter().map(|&tup|{
if let Some(&i)=unique_vertex_index.get(&tup){
@ -90,9 +90,9 @@ pub fn generate_indexed_model_list_from_obj(data:obj::ObjData,color:[f32;4]) ->
}
}).collect();
IndexedModel{
unique_pos: data.position,
unique_tex: data.texture,
unique_normal: data.normal,
unique_pos: data.position.clone(),
unique_tex: data.texture.clone(),
unique_normal: data.normal.clone(),
unique_color: vec![color],
unique_vertices,
groups,

View File

@ -69,9 +69,9 @@ pub fn the_unit_cube_lol() -> crate::model::IndexedModel{
#[derive(Copy,Clone)]
pub struct FaceDescription{
texture:Option<u32>,
transform:glam::Affine2,
color:glam::Vec4,
pub texture:Option<u32>,
pub transform:glam::Affine2,
pub color:glam::Vec4,
}
impl std::default::Default for FaceDescription{
fn default() -> Self {