forked from StrafesNET/strafe-client
sprinkle sacred runes
This commit is contained in:
parent
59ee0cee3b
commit
822c9d6d5f
12
src/body.rs
12
src/body.rs
@ -284,7 +284,7 @@ pub enum AabbFace{
|
|||||||
Bottom,
|
Bottom,
|
||||||
Front,
|
Front,
|
||||||
}
|
}
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Aabb {
|
pub struct Aabb {
|
||||||
min: glam::Vec3,
|
min: glam::Vec3,
|
||||||
max: glam::Vec3,
|
max: glam::Vec3,
|
||||||
@ -393,7 +393,7 @@ pub struct ModelPhysics {
|
|||||||
impl ModelPhysics {
|
impl ModelPhysics {
|
||||||
pub fn from_model(model:&crate::model::IndexedModel,model_transform:glam::Affine3A) -> Self {
|
pub fn from_model(model:&crate::model::IndexedModel,model_transform:glam::Affine3A) -> Self {
|
||||||
let mut aabb=Aabb::new();
|
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])));
|
aabb.grow(model_transform.transform_point3(glam::Vec3::from_array(model.unique_pos[indexed_vertex.pos as usize])));
|
||||||
}
|
}
|
||||||
Self{
|
Self{
|
||||||
@ -403,14 +403,14 @@ impl ModelPhysics {
|
|||||||
pub fn unit_vertices(&self) -> [glam::Vec3;8] {
|
pub fn unit_vertices(&self) -> [glam::Vec3;8] {
|
||||||
Aabb::unit_vertices()
|
Aabb::unit_vertices()
|
||||||
}
|
}
|
||||||
pub fn mesh(&self) -> TreyMesh {
|
pub fn mesh(&self) -> &TreyMesh {
|
||||||
return self.mesh;
|
return &self.mesh;
|
||||||
}
|
}
|
||||||
pub fn unit_face_vertices(&self,face:TreyMeshFace) -> [glam::Vec3;4] {
|
pub fn unit_face_vertices(&self,face:TreyMeshFace) -> [glam::Vec3;4] {
|
||||||
Aabb::unit_face_vertices(face)
|
Aabb::unit_face_vertices(face)
|
||||||
}
|
}
|
||||||
pub fn face_mesh(&self,face:TreyMeshFace) -> TreyMesh {
|
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
|
//in this implementation face = worldspace aabb face
|
||||||
match face {
|
match face {
|
||||||
AabbFace::Right => aabb.min.x=aabb.max.x,
|
AabbFace::Right => aabb.min.x=aabb.max.x,
|
||||||
@ -437,7 +437,7 @@ pub struct RelativeCollision {
|
|||||||
|
|
||||||
impl RelativeCollision {
|
impl RelativeCollision {
|
||||||
pub fn mesh(&self,models:&Vec<ModelPhysics>) -> TreyMesh {
|
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 {
|
pub fn normal(&self,models:&Vec<ModelPhysics>) -> glam::Vec3 {
|
||||||
return models.get(self.model as usize).unwrap().face_normal(self.face)
|
return models.get(self.model as usize).unwrap().face_normal(self.face)
|
||||||
|
@ -70,7 +70,7 @@ impl std::hash::Hash for RobloxTextureTransform {
|
|||||||
self.scale_v.to_ne_bytes().hash(state);
|
self.scale_v.to_ne_bytes().hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(PartialEq)]
|
#[derive(Clone,PartialEq)]
|
||||||
struct RobloxFaceTextureDescription{
|
struct RobloxFaceTextureDescription{
|
||||||
texture:u32,
|
texture:u32,
|
||||||
color:glam::Vec4,
|
color:glam::Vec4,
|
||||||
@ -88,10 +88,10 @@ impl std::hash::Hash for RobloxFaceTextureDescription {
|
|||||||
}
|
}
|
||||||
type RobloxPartDescription=[Option<RobloxFaceTextureDescription>;6];
|
type RobloxPartDescription=[Option<RobloxFaceTextureDescription>;6];
|
||||||
type RobloxWedgeDescription=[Option<RobloxFaceTextureDescription>;5];
|
type RobloxWedgeDescription=[Option<RobloxFaceTextureDescription>;5];
|
||||||
#[derive(Eq, Hash, PartialEq)]
|
#[derive(Clone,Eq,Hash,PartialEq)]
|
||||||
enum RobloxBasePartDescription{
|
enum RobloxBasePartDescription{
|
||||||
Part(RobloxPartDescription),
|
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>>{
|
pub fn generate_indexed_models_roblox(dom:rbx_dom_weak::WeakDom) -> Result<(IndexedModelInstances,glam::Vec3), Box<dyn std::error::Error>>{
|
||||||
//IndexedModelInstances includes textures
|
//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
|
//push to existing texture model
|
||||||
model_id
|
model_id
|
||||||
}else{
|
}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();
|
let model_id=indexed_models.len();
|
||||||
indexed_models.push(indexed_model);
|
model_id_from_description.insert(basepart_texture_description.clone(),model_id);//borrow checker going crazy
|
||||||
model_id_from_description.insert(basepart_texture_description,model_id);
|
match basepart_texture_description{
|
||||||
model_id
|
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 {
|
indexed_models[model_id].instances.push(ModelInstance {
|
||||||
model_transform,
|
model_transform,
|
||||||
|
@ -84,9 +84,9 @@ impl GraphicsData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn generate_model_physics(&mut self,indexed_models:&model::IndexedModelInstances){
|
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
|
//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));
|
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
|
//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.
|
//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());
|
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
|
//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 id=unique_texture_models.len();
|
||||||
let mut unique_textures=Vec::new();
|
let mut unique_textures=Vec::new();
|
||||||
|
12
src/model.rs
12
src/model.rs
@ -62,13 +62,13 @@ pub struct IndexedModelInstances{
|
|||||||
|
|
||||||
pub fn generate_indexed_model_list_from_obj(data:obj::ObjData,color:[f32;4]) -> Vec<IndexedModel>{
|
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();
|
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();
|
unique_vertex_index.clear();
|
||||||
let mut unique_vertices = Vec::new();
|
let mut unique_vertices = Vec::new();
|
||||||
let groups = object.groups.iter().map(|&group|{
|
let groups = object.groups.iter().map(|group|{
|
||||||
IndexedGroup{
|
IndexedGroup{
|
||||||
texture:None,
|
texture:None,
|
||||||
polys:group.polys.iter().map(|&poly|{
|
polys:group.polys.iter().map(|poly|{
|
||||||
IndexedPolygon{
|
IndexedPolygon{
|
||||||
vertices:poly.0.iter().map(|&tup|{
|
vertices:poly.0.iter().map(|&tup|{
|
||||||
if let Some(&i)=unique_vertex_index.get(&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();
|
}).collect();
|
||||||
IndexedModel{
|
IndexedModel{
|
||||||
unique_pos: data.position,
|
unique_pos: data.position.clone(),
|
||||||
unique_tex: data.texture,
|
unique_tex: data.texture.clone(),
|
||||||
unique_normal: data.normal,
|
unique_normal: data.normal.clone(),
|
||||||
unique_color: vec![color],
|
unique_color: vec![color],
|
||||||
unique_vertices,
|
unique_vertices,
|
||||||
groups,
|
groups,
|
||||||
|
@ -69,9 +69,9 @@ pub fn the_unit_cube_lol() -> crate::model::IndexedModel{
|
|||||||
|
|
||||||
#[derive(Copy,Clone)]
|
#[derive(Copy,Clone)]
|
||||||
pub struct FaceDescription{
|
pub struct FaceDescription{
|
||||||
texture:Option<u32>,
|
pub texture:Option<u32>,
|
||||||
transform:glam::Affine2,
|
pub transform:glam::Affine2,
|
||||||
color:glam::Vec4,
|
pub color:glam::Vec4,
|
||||||
}
|
}
|
||||||
impl std::default::Default for FaceDescription{
|
impl std::default::Default for FaceDescription{
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
Loading…
Reference in New Issue
Block a user