forked from StrafesNET/strafe-client
cook PhysicsMeshTransform
This commit is contained in:
parent
96e163643b
commit
9ae4c5b0db
@ -368,46 +368,33 @@ impl MeshQuery<SubmeshFaceId,SubmeshDirectedEdgeId,SubmeshVertId> for PhysicsMes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PhysicsMeshTransform<'a>{
|
pub struct PhysicsMeshTransform{
|
||||||
vertex:&'a integer::Planar64Affine3,
|
vertex:integer::Planar64Affine3,
|
||||||
normal:&'a integer::Planar64Mat3,
|
normal:integer::Planar64Mat3,
|
||||||
det:Planar64,
|
det:Planar64,
|
||||||
}
|
}
|
||||||
impl PhysicsMeshTransform<'_>{
|
impl PhysicsMeshTransform{
|
||||||
pub fn new<'a>(
|
pub const fn new(transform:integer::Planar64Affine3)->Self{
|
||||||
vertex:&'a integer::Planar64Affine3,
|
Self{
|
||||||
normal:&'a integer::Planar64Mat3,
|
normal:transform.matrix3.inverse_times_det().transpose(),
|
||||||
det:Planar64
|
det:transform.matrix3.determinant(),
|
||||||
)->PhysicsMeshTransform<'a>{
|
vertex:transform,
|
||||||
PhysicsMeshTransform{
|
|
||||||
vertex,
|
|
||||||
normal,
|
|
||||||
det,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TransformedMesh<'a>{
|
pub struct TransformedMesh<'a>{
|
||||||
view:PhysicsMeshView<'a>,
|
view:PhysicsMeshView<'a>,
|
||||||
transform:PhysicsMeshTransform<'a>,
|
transform:&'a PhysicsMeshTransform,
|
||||||
}
|
}
|
||||||
impl TransformedMesh<'_>{
|
impl TransformedMesh<'_>{
|
||||||
pub fn new<'a>(
|
pub fn new<'a>(
|
||||||
mesh_data:&'a PhysicsMeshData,
|
view:PhysicsMeshView<'a>,
|
||||||
topology:&'a PhysicsMeshTopology,
|
transform:&'a PhysicsMeshTransform,
|
||||||
vertex:&'a integer::Planar64Affine3,
|
|
||||||
normal:&'a integer::Planar64Mat3,
|
|
||||||
det:Planar64,
|
|
||||||
)->TransformedMesh<'a>{
|
)->TransformedMesh<'a>{
|
||||||
TransformedMesh{
|
TransformedMesh{
|
||||||
view:PhysicsMeshView{
|
view,
|
||||||
data: mesh_data,
|
transform,
|
||||||
topology,
|
|
||||||
},
|
|
||||||
transform:PhysicsMeshTransform{
|
|
||||||
vertex,
|
|
||||||
normal,
|
|
||||||
det,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn farthest_vert(&self,dir:Planar64Vec3)->SubmeshVertId{
|
fn farthest_vert(&self,dir:Planar64Vec3)->SubmeshVertId{
|
||||||
@ -429,7 +416,7 @@ impl TransformedMesh<'_>{
|
|||||||
impl MeshQuery<SubmeshFaceId,SubmeshDirectedEdgeId,SubmeshVertId> for TransformedMesh<'_>{
|
impl MeshQuery<SubmeshFaceId,SubmeshDirectedEdgeId,SubmeshVertId> for TransformedMesh<'_>{
|
||||||
fn face_nd(&self,face_id:SubmeshFaceId)->(Planar64Vec3,Planar64){
|
fn face_nd(&self,face_id:SubmeshFaceId)->(Planar64Vec3,Planar64){
|
||||||
let (n,d)=self.view.face_nd(face_id);
|
let (n,d)=self.view.face_nd(face_id);
|
||||||
let transformed_n=*self.transform.normal*n;
|
let transformed_n=self.transform.normal*n;
|
||||||
let transformed_d=d+transformed_n.dot(self.transform.vertex.translation)/self.transform.det;
|
let transformed_d=d+transformed_n.dot(self.transform.vertex.translation)/self.transform.det;
|
||||||
(transformed_n/self.transform.det,transformed_d)
|
(transformed_n/self.transform.det,transformed_d)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use crate::model_physics::{self,PhysicsMesh,TransformedMesh,MeshQuery,PhysicsMeshId,PhysicsSubmeshId};
|
use crate::model_physics::{self,PhysicsMesh,PhysicsMeshTransform,TransformedMesh,MeshQuery,PhysicsMeshId,PhysicsSubmeshId};
|
||||||
use strafesnet_common::bvh;
|
use strafesnet_common::bvh;
|
||||||
use strafesnet_common::map;
|
use strafesnet_common::map;
|
||||||
use strafesnet_common::aabb;
|
use strafesnet_common::aabb;
|
||||||
@ -172,10 +172,8 @@ impl PhysicsModels{
|
|||||||
fn mesh(&self,convex_mesh_id:ConvexMeshId)->TransformedMesh{
|
fn mesh(&self,convex_mesh_id:ConvexMeshId)->TransformedMesh{
|
||||||
let model_idx=convex_mesh_id.model_id.get() as usize;
|
let model_idx=convex_mesh_id.model_id.get() as usize;
|
||||||
TransformedMesh::new(
|
TransformedMesh::new(
|
||||||
&self.meshes[model_idx].submesh_view(convex_mesh_id.submesh_id),
|
self.meshes[model_idx].submesh_view(convex_mesh_id.submesh_id),
|
||||||
&self.models[idx].transform,
|
&self.models[model_idx].transform
|
||||||
&self.models[idx].normal_transform,
|
|
||||||
self.models[idx].transform_det,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn model(&self,model_id:PhysicsModelId)->&PhysicsModel{
|
fn model(&self,model_id:PhysicsModelId)->&PhysicsModel{
|
||||||
@ -284,24 +282,24 @@ struct WorldState{}
|
|||||||
struct HitboxMesh{
|
struct HitboxMesh{
|
||||||
halfsize:Planar64Vec3,
|
halfsize:Planar64Vec3,
|
||||||
mesh:PhysicsMesh,
|
mesh:PhysicsMesh,
|
||||||
transform:PhysicsModelTransform,
|
transform:PhysicsMeshTransform,
|
||||||
}
|
}
|
||||||
impl HitboxMesh{
|
impl HitboxMesh{
|
||||||
fn new(mesh:PhysicsMesh,vertex_transform:integer::Planar64Affine3)->Self{
|
fn new(mesh:PhysicsMesh,transform:integer::Planar64Affine3)->Self{
|
||||||
//calculate extents
|
//calculate extents
|
||||||
let mut aabb=aabb::Aabb::default();
|
let mut aabb=aabb::Aabb::default();
|
||||||
for vert in mesh.complete_mesh_view().verts(){
|
for vert in mesh.complete_mesh_view().verts(){
|
||||||
aabb.grow(vertex_transform.transform_point3(vert));
|
aabb.grow(transform.transform_point3(vert));
|
||||||
}
|
}
|
||||||
Self{
|
Self{
|
||||||
halfsize:aabb.size()/2,
|
halfsize:aabb.size()/2,
|
||||||
mesh,
|
mesh,
|
||||||
transform:PhysicsModelTransform::new(vertex_transform)
|
transform:PhysicsMeshTransform::new(transform)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transformed_mesh(&self)->TransformedMesh{
|
fn transformed_mesh(&self)->TransformedMesh{
|
||||||
TransformedMesh::new(&self.mesh,&self.transform,&self.normal_transform,self.transform_det)
|
TransformedMesh::new(&self.mesh.complete_mesh_view(),&self.transform)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,38 +493,24 @@ impl From<ModelId> for PhysicsModelId{
|
|||||||
Self::new(value.get())
|
Self::new(value.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub struct PhysicsModelTransform{
|
|
||||||
vertex:integer::Planar64Affine3,
|
|
||||||
normal:integer::Planar64Mat3,
|
|
||||||
det:Planar64,
|
|
||||||
}
|
|
||||||
impl PhysicsModelTransform{
|
|
||||||
pub const fn new(vertex_transform:integer::Planar64Affine3)->Self{
|
|
||||||
Self{
|
|
||||||
normal:vertex_transform.matrix3.inverse_times_det().transpose(),
|
|
||||||
det:vertex_transform.matrix3.determinant(),
|
|
||||||
vertex:vertex_transform,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub struct PhysicsModel{
|
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_id:PhysicsMeshId,
|
mesh_id:PhysicsMeshId,
|
||||||
//put these up on the Model (data normalization)
|
//put these up on the Model (data normalization)
|
||||||
attr_id:PhysicsAttributesId,
|
attr_id:PhysicsAttributesId,
|
||||||
transform:PhysicsModelTransform,
|
transform:PhysicsMeshTransform,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PhysicsModel{
|
impl PhysicsModel{
|
||||||
pub const fn new(mesh_id:PhysicsMeshId,attr_id:PhysicsAttributesId,transform:PhysicsModelTransform)->Self{
|
pub const fn new(mesh_id:PhysicsMeshId,attr_id:PhysicsAttributesId,transform:PhysicsMeshTransform)->Self{
|
||||||
Self{
|
Self{
|
||||||
mesh_id,
|
mesh_id,
|
||||||
attr_id,
|
attr_id,
|
||||||
transform,
|
transform,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const fn transform(&self)->&PhysicsModelTransform{
|
const fn transform(&self)->&PhysicsMeshTransform{
|
||||||
&self.transform
|
&self.transform
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user