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