rename Model{Graphics|Physics} for consistency
This commit is contained in:
parent
953b17bc69
commit
9fc7884270
@ -1,9 +1,9 @@
|
||||
use std::borrow::Cow;
|
||||
use wgpu::{util::DeviceExt,AstcBlock,AstcChannel};
|
||||
use crate::model_graphics::{GraphicsVertex,ModelGraphicsColor4,ModelGraphicsInstance,ModelGraphicsSingleTexture,IndexedModelGraphicsSingleTexture,IndexedGroupFixedTexture};
|
||||
use crate::model_graphics::{GraphicsVertex,GraphicsModelColor4,GraphicsModelInstance,GraphicsModelSingleTexture,IndexedGraphicsModelSingleTexture,IndexedGroupFixedTexture};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ModelUpdate{
|
||||
pub struct GraphicsModelUpdate{
|
||||
transform:Option<glam::Mat4>,
|
||||
color:Option<glam::Vec4>,
|
||||
}
|
||||
@ -26,13 +26,13 @@ fn create_entities<T:bytemuck::Pod>(device:&wgpu::Device,entities:&Vec<Vec<T>>)-
|
||||
}).collect()
|
||||
}
|
||||
|
||||
struct ModelGraphics{
|
||||
struct GraphicsModel{
|
||||
entities:Vec<Entity>,
|
||||
model_buf:wgpu::Buffer,
|
||||
vertex_buf:wgpu::Buffer,
|
||||
bind_group:wgpu::BindGroup,
|
||||
index_format:wgpu::IndexFormat,
|
||||
instances:Vec<ModelGraphicsInstance>,
|
||||
instances:Vec<GraphicsModelInstance>,
|
||||
}
|
||||
|
||||
pub struct GraphicsSamplers{
|
||||
@ -110,7 +110,7 @@ pub struct GraphicsState{
|
||||
camera:GraphicsCamera,
|
||||
camera_buf: wgpu::Buffer,
|
||||
temp_squid_texture_view: wgpu::TextureView,
|
||||
models: Vec<ModelGraphics>,
|
||||
models: Vec<GraphicsModel>,
|
||||
depth_view: wgpu::TextureView,
|
||||
staging_belt: wgpu::util::StagingBelt,
|
||||
}
|
||||
@ -214,15 +214,15 @@ impl GraphicsState{
|
||||
let indexed_models_len=indexed_models.models.len();
|
||||
let mut unique_texture_models=Vec::with_capacity(indexed_models_len);
|
||||
for model in indexed_models.models.into_iter(){
|
||||
//convert ModelInstance into ModelGraphicsInstance
|
||||
let instances:Vec<ModelGraphicsInstance>=model.instances.into_iter().filter_map(|instance|{
|
||||
//convert ModelInstance into GraphicsModelInstance
|
||||
let instances:Vec<GraphicsModelInstance>=model.instances.into_iter().filter_map(|instance|{
|
||||
if instance.color.w==0.0{
|
||||
None
|
||||
}else{
|
||||
Some(ModelGraphicsInstance{
|
||||
Some(GraphicsModelInstance{
|
||||
transform: instance.transform.into(),
|
||||
normal_transform: Into::<glam::Mat3>::into(instance.transform.matrix3).inverse().transpose(),
|
||||
color:ModelGraphicsColor4::from(instance.color),
|
||||
color:GraphicsModelColor4::from(instance.color),
|
||||
})
|
||||
}
|
||||
}).collect();
|
||||
@ -241,7 +241,7 @@ impl GraphicsState{
|
||||
//create new texture_index
|
||||
let texture_index=unique_textures.len();
|
||||
unique_textures.push(group.texture);
|
||||
unique_texture_models.push(IndexedModelGraphicsSingleTexture{
|
||||
unique_texture_models.push(IndexedGraphicsModelSingleTexture{
|
||||
unique_pos:model.unique_pos.iter().map(|&v|*Into::<glam::Vec3>::into(v).as_ref()).collect(),
|
||||
unique_tex:model.unique_tex.iter().map(|v|*v.as_ref()).collect(),
|
||||
unique_normal:model.unique_normal.iter().map(|&v|*Into::<glam::Vec3>::into(v).as_ref()).collect(),
|
||||
@ -396,7 +396,7 @@ impl GraphicsState{
|
||||
}
|
||||
}
|
||||
//push model into dedup
|
||||
deduplicated_models.push(IndexedModelGraphicsSingleTexture{
|
||||
deduplicated_models.push(IndexedGraphicsModelSingleTexture{
|
||||
unique_pos,
|
||||
unique_tex,
|
||||
unique_normal,
|
||||
@ -406,7 +406,7 @@ impl GraphicsState{
|
||||
groups:vec![IndexedGroupFixedTexture{
|
||||
polys
|
||||
}],
|
||||
instances:vec![ModelGraphicsInstance{
|
||||
instances:vec![GraphicsModelInstance{
|
||||
transform:glam::Mat4::IDENTITY,
|
||||
normal_transform:glam::Mat3::IDENTITY,
|
||||
color
|
||||
@ -424,7 +424,7 @@ impl GraphicsState{
|
||||
|
||||
//de-index models
|
||||
let deduplicated_models_len=deduplicated_models.len();
|
||||
let models:Vec<ModelGraphicsSingleTexture>=deduplicated_models.into_iter().map(|model|{
|
||||
let models:Vec<GraphicsModelSingleTexture>=deduplicated_models.into_iter().map(|model|{
|
||||
let mut vertices = Vec::new();
|
||||
let mut index_from_vertex = std::collections::HashMap::new();//::<IndexedVertex,usize>
|
||||
//this mut be combined in a more complex way if the models use different render patterns per group
|
||||
@ -452,7 +452,7 @@ impl GraphicsState{
|
||||
}
|
||||
}
|
||||
}
|
||||
ModelGraphicsSingleTexture{
|
||||
GraphicsModelSingleTexture{
|
||||
instances:model.instances,
|
||||
entities:if (u16::MAX as usize)<vertices.len(){
|
||||
crate::model_graphics::Entities::U32(vec![indices.into_iter().map(|vertex_id|vertex_id as u32).collect()])
|
||||
@ -512,7 +512,7 @@ impl GraphicsState{
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
//all of these are being moved here
|
||||
self.models.push(ModelGraphics{
|
||||
self.models.push(GraphicsModel{
|
||||
instances:instances_chunk.to_vec(),
|
||||
vertex_buf,
|
||||
index_format:match &model.entities{
|
||||
@ -982,7 +982,7 @@ impl GraphicsState{
|
||||
}
|
||||
const MODEL_BUFFER_SIZE:usize=4*4 + 12 + 4;//let size=std::mem::size_of::<ModelInstance>();
|
||||
const MODEL_BUFFER_SIZE_BYTES:usize=MODEL_BUFFER_SIZE*4;
|
||||
fn get_instances_buffer_data(instances:&[ModelGraphicsInstance]) -> Vec<f32> {
|
||||
fn get_instances_buffer_data(instances:&[GraphicsModelInstance]) -> Vec<f32> {
|
||||
let mut raw = Vec::with_capacity(MODEL_BUFFER_SIZE*instances.len());
|
||||
for (i,mi) in instances.iter().enumerate(){
|
||||
let mut v = raw.split_off(MODEL_BUFFER_SIZE*i);
|
||||
|
@ -1,6 +1,6 @@
|
||||
pub enum Instruction{
|
||||
Render(crate::physics::PhysicsOutputState,crate::integer::Time,glam::IVec2),
|
||||
//UpdateModel(crate::graphics::ModelUpdate),
|
||||
//UpdateModel(crate::graphics::GraphicsModelUpdate),
|
||||
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
|
||||
GenerateModels(crate::model::IndexedModelInstances),
|
||||
ClearModels,
|
||||
|
@ -11,7 +11,7 @@ pub struct GraphicsVertex {
|
||||
pub struct IndexedGroupFixedTexture{
|
||||
pub polys:Vec<IndexedPolygon>,
|
||||
}
|
||||
pub struct IndexedModelGraphicsSingleTexture{
|
||||
pub struct IndexedGraphicsModelSingleTexture{
|
||||
pub unique_pos:Vec<[f32; 3]>,
|
||||
pub unique_tex:Vec<[f32; 2]>,
|
||||
pub unique_normal:Vec<[f32; 3]>,
|
||||
@ -19,41 +19,41 @@ pub struct IndexedModelGraphicsSingleTexture{
|
||||
pub unique_vertices:Vec<IndexedVertex>,
|
||||
pub texture:Option<u32>,//RenderPattern? material/texture/shader/flat color
|
||||
pub groups: Vec<IndexedGroupFixedTexture>,
|
||||
pub instances:Vec<ModelGraphicsInstance>,
|
||||
pub instances:Vec<GraphicsModelInstance>,
|
||||
}
|
||||
pub enum Entities{
|
||||
U32(Vec<Vec<u32>>),
|
||||
U16(Vec<Vec<u16>>),
|
||||
}
|
||||
pub struct ModelGraphicsSingleTexture{
|
||||
pub instances:Vec<ModelGraphicsInstance>,
|
||||
pub struct GraphicsModelSingleTexture{
|
||||
pub instances:Vec<GraphicsModelInstance>,
|
||||
pub vertices:Vec<GraphicsVertex>,
|
||||
pub entities:Entities,
|
||||
pub texture:Option<u32>,
|
||||
}
|
||||
#[derive(Clone,PartialEq)]
|
||||
pub struct ModelGraphicsColor4(glam::Vec4);
|
||||
impl ModelGraphicsColor4{
|
||||
pub struct GraphicsModelColor4(glam::Vec4);
|
||||
impl GraphicsModelColor4{
|
||||
pub const fn get(&self)->glam::Vec4{
|
||||
self.0
|
||||
}
|
||||
}
|
||||
impl From<glam::Vec4> for ModelGraphicsColor4{
|
||||
impl From<glam::Vec4> for GraphicsModelColor4{
|
||||
fn from(value:glam::Vec4)->Self{
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
impl std::hash::Hash for ModelGraphicsColor4{
|
||||
impl std::hash::Hash for GraphicsModelColor4{
|
||||
fn hash<H: std::hash::Hasher>(&self,state:&mut H) {
|
||||
for &f in self.0.as_ref(){
|
||||
bytemuck::cast::<f32,u32>(f).hash(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Eq for ModelGraphicsColor4{}
|
||||
impl Eq for GraphicsModelColor4{}
|
||||
#[derive(Clone)]
|
||||
pub struct ModelGraphicsInstance{
|
||||
pub struct GraphicsModelInstance{
|
||||
pub transform:glam::Mat4,
|
||||
pub normal_transform:glam::Mat3,
|
||||
pub color:ModelGraphicsColor4,
|
||||
pub color:GraphicsModelColor4,
|
||||
}
|
@ -155,7 +155,7 @@ impl Default for Modes{
|
||||
}
|
||||
|
||||
struct PhysicsModels{
|
||||
models:Vec<ModelPhysics>,
|
||||
models:Vec<PhysicsModel>,
|
||||
model_id_from_wormhole_id:std::collections::HashMap::<u32,usize>,
|
||||
}
|
||||
impl PhysicsModels{
|
||||
@ -163,13 +163,13 @@ impl PhysicsModels{
|
||||
self.models.clear();
|
||||
self.model_id_from_wormhole_id.clear();
|
||||
}
|
||||
fn get(&self,i:usize)->Option<&ModelPhysics>{
|
||||
fn get(&self,i:usize)->Option<&PhysicsModel>{
|
||||
self.models.get(i)
|
||||
}
|
||||
fn get_wormhole_model(&self,wormhole_id:u32)->Option<&ModelPhysics>{
|
||||
fn get_wormhole_model(&self,wormhole_id:u32)->Option<&PhysicsModel>{
|
||||
self.models.get(*self.model_id_from_wormhole_id.get(&wormhole_id)?)
|
||||
}
|
||||
fn push(&mut self,model:ModelPhysics)->usize{
|
||||
fn push(&mut self,model:PhysicsModel)->usize{
|
||||
let model_id=self.models.len();
|
||||
self.models.push(model);
|
||||
model_id
|
||||
@ -602,7 +602,7 @@ enum PhysicsCollisionAttributes{
|
||||
},
|
||||
}
|
||||
|
||||
pub struct ModelPhysics {
|
||||
pub struct PhysicsModel {
|
||||
//A model is a thing that has a hitbox. can be represented by a list of TreyMesh-es
|
||||
//in this iteration, all it needs is extents.
|
||||
mesh: TreyMesh,
|
||||
@ -610,7 +610,7 @@ pub struct ModelPhysics {
|
||||
attributes:PhysicsCollisionAttributes,
|
||||
}
|
||||
|
||||
impl ModelPhysics {
|
||||
impl PhysicsModel {
|
||||
fn from_model_transform_attributes(model:&crate::model::IndexedModel,transform:&crate::integer::Planar64Affine3,attributes:PhysicsCollisionAttributes)->Self{
|
||||
let mut aabb=TreyMesh::default();
|
||||
for indexed_vertex in &model.unique_vertices {
|
||||
@ -624,8 +624,8 @@ impl ModelPhysics {
|
||||
}
|
||||
pub fn from_model(model:&crate::model::IndexedModel,instance:&crate::model::ModelInstance) -> Option<Self> {
|
||||
match &instance.attributes{
|
||||
crate::model::CollisionAttributes::Contact{contacting,general}=>Some(ModelPhysics::from_model_transform_attributes(model,&instance.transform,PhysicsCollisionAttributes::Contact{contacting:contacting.clone(),general:general.clone()})),
|
||||
crate::model::CollisionAttributes::Intersect{intersecting,general}=>Some(ModelPhysics::from_model_transform_attributes(model,&instance.transform,PhysicsCollisionAttributes::Intersect{intersecting:intersecting.clone(),general:general.clone()})),
|
||||
crate::model::CollisionAttributes::Contact{contacting,general}=>Some(PhysicsModel::from_model_transform_attributes(model,&instance.transform,PhysicsCollisionAttributes::Contact{contacting:contacting.clone(),general:general.clone()})),
|
||||
crate::model::CollisionAttributes::Intersect{intersecting,general}=>Some(PhysicsModel::from_model_transform_attributes(model,&instance.transform,PhysicsCollisionAttributes::Intersect{intersecting:intersecting.clone(),general:general.clone()})),
|
||||
crate::model::CollisionAttributes::Decoration=>None,
|
||||
}
|
||||
}
|
||||
@ -652,10 +652,10 @@ pub struct RelativeCollision {
|
||||
}
|
||||
|
||||
impl RelativeCollision {
|
||||
fn model<'a>(&self,models:&'a PhysicsModels)->Option<&'a ModelPhysics>{
|
||||
fn model<'a>(&self,models:&'a PhysicsModels)->Option<&'a PhysicsModel>{
|
||||
models.get(self.model)
|
||||
}
|
||||
// pub fn mesh(&self,models:&Vec<ModelPhysics>) -> TreyMesh {
|
||||
// pub fn mesh(&self,models:&Vec<PhysicsModel>) -> TreyMesh {
|
||||
// return self.model(models).unwrap().face_mesh(self.face).clone()
|
||||
// }
|
||||
fn normal(&self,models:&PhysicsModels) -> Planar64Vec3 {
|
||||
@ -792,7 +792,7 @@ impl PhysicsState {
|
||||
for model in &indexed_models.models{
|
||||
//make aabb and run vertices to get realistic bounds
|
||||
for model_instance in &model.instances{
|
||||
if let Some(model_physics)=ModelPhysics::from_model(model,model_instance){
|
||||
if let Some(model_physics)=PhysicsModel::from_model(model,model_instance){
|
||||
let model_id=self.models.push(model_physics);
|
||||
for attr in &model_instance.temp_indexing{
|
||||
match attr{
|
||||
@ -1263,7 +1263,7 @@ fn teleport_to_spawn(body:&mut Body,touching:&mut TouchingState,style:&StyleModi
|
||||
Some(teleport(body,touching,style,point))
|
||||
}
|
||||
|
||||
fn run_teleport_behaviour(teleport_behaviour:&Option<crate::model::TeleportBehaviour>,game:&mut GameMechanicsState,models:&PhysicsModels,modes:&Modes,style:&StyleModifiers,touching:&mut TouchingState,body:&mut Body,model:&ModelPhysics)->Option<MoveState>{
|
||||
fn run_teleport_behaviour(teleport_behaviour:&Option<crate::model::TeleportBehaviour>,game:&mut GameMechanicsState,models:&PhysicsModels,modes:&Modes,style:&StyleModifiers,touching:&mut TouchingState,body:&mut Body,model:&PhysicsModel)->Option<MoveState>{
|
||||
match teleport_behaviour{
|
||||
Some(crate::model::TeleportBehaviour::StageElement(stage_element))=>{
|
||||
if stage_element.force||game.stage_id<stage_element.stage_id{
|
||||
|
Loading…
Reference in New Issue
Block a user