Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
de86ad06b6
|
|||
373bd3c88f
|
|||
a3d39a81d0
|
|||
cb31c847d5
|
|||
f579370841
|
|||
2a542e0026
|
|||
ca51256a16
|
|||
65e17da386 | |||
1cf21be185 | |||
413e176741 | |||
39b2397d5e | |||
2ed01dffbd | |||
d0ee597416 | |||
be85530000 | |||
55ff199269 |
648
Cargo.lock
generated
648
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -11,4 +11,4 @@ id = { version = "0.1.0", registry = "strafesnet" }
|
||||
strafesnet_common = { path = "../../lib/common", registry = "strafesnet" }
|
||||
strafesnet_session = { path = "../session", registry = "strafesnet" }
|
||||
strafesnet_settings = { path = "../settings", registry = "strafesnet" }
|
||||
wgpu = "24.0.0"
|
||||
wgpu = "25.0.0"
|
||||
|
@ -107,6 +107,7 @@ enum TransientAcceleration{
|
||||
#[derive(Clone,Debug)]
|
||||
struct ContactMoveState{
|
||||
jump_direction:JumpDirection,
|
||||
// TODO: this is bad data normalization, remove this
|
||||
contact:ContactCollision,
|
||||
target:TransientAcceleration,
|
||||
}
|
||||
@ -601,12 +602,17 @@ impl MoveState{
|
||||
fn cull_velocity(&mut self,velocity:Planar64Vec3,body:&mut Body,touching:&mut TouchingState,models:&PhysicsModels,hitbox_mesh:&HitboxMesh,style:&StyleModifiers,camera:&PhysicsCamera,input_state:&InputState){
|
||||
//TODO: be more precise about contacts
|
||||
if set_velocity_cull(body,touching,models,hitbox_mesh,velocity){
|
||||
//TODO do better
|
||||
// TODO do better
|
||||
// TODO: unduplicate this code
|
||||
match self.get_walk_state(){
|
||||
//did you stop touching the thing you were walking on?
|
||||
// did you stop touching the thing you were walking on?
|
||||
Some(walk_state)=>if !touching.contacts.contains(&walk_state.contact){
|
||||
self.set_move_state(MoveState::Air,body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}else{
|
||||
// stopped touching something else while walking
|
||||
self.apply_enum_and_input_and_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
},
|
||||
// not walking, but stopped touching something
|
||||
None=>self.apply_enum_and_body(body,touching,models,hitbox_mesh,style,camera,input_state),
|
||||
}
|
||||
}
|
||||
@ -1620,10 +1626,14 @@ fn collision_end_contact(
|
||||
//TODO do better
|
||||
//this is inner code from move_state.cull_velocity
|
||||
match move_state.get_walk_state(){
|
||||
//did you stop touching the thing you were walking on?
|
||||
// did you stop touching the thing you were walking on?
|
||||
Some(walk_state)=>if walk_state.contact==contact{
|
||||
move_state.set_move_state(MoveState::Air,body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
}else{
|
||||
// stopped touching something else while walking
|
||||
move_state.apply_enum_and_input_and_body(body,touching,models,hitbox_mesh,style,camera,input_state);
|
||||
},
|
||||
// not walking, but stopped touching something
|
||||
None=>move_state.apply_enum_and_body(body,touching,models,hitbox_mesh,style,camera,input_state),
|
||||
}
|
||||
}
|
||||
|
@ -22,17 +22,17 @@ impl From<std::io::Error> for TextureError{
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TextureLoader<'a>(std::marker::PhantomData<&'a ()>);
|
||||
impl TextureLoader<'_>{
|
||||
pub struct TextureLoader;
|
||||
impl TextureLoader{
|
||||
pub fn new()->Self{
|
||||
Self(std::marker::PhantomData)
|
||||
Self
|
||||
}
|
||||
}
|
||||
impl<'a> Loader for TextureLoader<'a>{
|
||||
impl Loader for TextureLoader{
|
||||
type Error=TextureError;
|
||||
type Index=Cow<'a,str>;
|
||||
type Index<'a>=Cow<'a,str>;
|
||||
type Resource=Texture;
|
||||
fn load(&mut self,index:Self::Index)->Result<Self::Resource,Self::Error>{
|
||||
fn load<'a>(&mut self,index:Self::Index<'a>)->Result<Self::Resource,Self::Error>{
|
||||
let file_name=format!("textures/{}.dds",index);
|
||||
let mut file=std::fs::File::open(file_name)?;
|
||||
let mut data=Vec::new();
|
||||
@ -100,30 +100,24 @@ impl<'bsp,'vpk> BspFinder<'bsp,'vpk>{
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ModelLoader<'bsp,'vpk,'a>{
|
||||
pub struct ModelLoader<'bsp,'vpk>{
|
||||
finder:BspFinder<'bsp,'vpk>,
|
||||
life:core::marker::PhantomData<&'a ()>,
|
||||
}
|
||||
impl ModelLoader<'_,'_,'_>{
|
||||
impl ModelLoader<'_,'_>{
|
||||
#[inline]
|
||||
pub const fn new<'bsp,'vpk,'a>(
|
||||
pub const fn new<'bsp,'vpk>(
|
||||
finder:BspFinder<'bsp,'vpk>,
|
||||
)->ModelLoader<'bsp,'vpk,'a>{
|
||||
)->ModelLoader<'bsp,'vpk>{
|
||||
ModelLoader{
|
||||
finder,
|
||||
life:core::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'bsp,'vpk,'a> Loader for ModelLoader<'bsp,'vpk,'a>
|
||||
where
|
||||
'bsp:'a,
|
||||
'vpk:'a,
|
||||
{
|
||||
impl<'bsp,'vpk> Loader for ModelLoader<'bsp,'vpk>{
|
||||
type Error=MeshError;
|
||||
type Index=&'a str;
|
||||
type Index<'a>=&'a str where Self:'a;
|
||||
type Resource=vmdl::Model;
|
||||
fn load(&mut self,index:Self::Index)->Result<Self::Resource,Self::Error>{
|
||||
fn load<'a>(&'a mut self,index:Self::Index<'a>)->Result<Self::Resource,Self::Error>{
|
||||
let mdl_path_lower=index.to_lowercase();
|
||||
//.mdl, .vvd, .dx90.vtx
|
||||
let path=std::path::PathBuf::from(mdl_path_lower.as_str());
|
||||
@ -143,31 +137,27 @@ impl<'bsp,'vpk,'a> Loader for ModelLoader<'bsp,'vpk,'a>
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MeshLoader<'bsp,'vpk,'load,'a>{
|
||||
pub struct MeshLoader<'bsp,'vpk,'load,'str>{
|
||||
finder:BspFinder<'bsp,'vpk>,
|
||||
deferred_loader:&'load mut strafesnet_deferred_loader::deferred_loader::RenderConfigDeferredLoader<Cow<'a,str>>,
|
||||
deferred_loader:&'load mut strafesnet_deferred_loader::deferred_loader::RenderConfigDeferredLoader<Cow<'str,str>>,
|
||||
}
|
||||
impl MeshLoader<'_,'_,'_,'_>{
|
||||
#[inline]
|
||||
pub const fn new<'bsp,'vpk,'load,'a>(
|
||||
pub const fn new<'bsp,'vpk,'load,'str>(
|
||||
finder:BspFinder<'bsp,'vpk>,
|
||||
deferred_loader:&'load mut strafesnet_deferred_loader::deferred_loader::RenderConfigDeferredLoader<Cow<'a,str>>,
|
||||
)->MeshLoader<'bsp,'vpk,'load,'a>{
|
||||
deferred_loader:&'load mut strafesnet_deferred_loader::deferred_loader::RenderConfigDeferredLoader<Cow<'str,str>>,
|
||||
)->MeshLoader<'bsp,'vpk,'load,'str>{
|
||||
MeshLoader{
|
||||
finder,
|
||||
deferred_loader
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'bsp,'vpk,'load,'a> Loader for MeshLoader<'bsp,'vpk,'load,'a>
|
||||
where
|
||||
'bsp:'a,
|
||||
'vpk:'a,
|
||||
{
|
||||
impl<'str,'bsp,'vpk,'load> Loader for MeshLoader<'bsp,'vpk,'load,'str>{
|
||||
type Error=MeshError;
|
||||
type Index=&'a str;
|
||||
type Index<'a>=&'a str where Self:'a;
|
||||
type Resource=Mesh;
|
||||
fn load(&mut self,index:Self::Index)->Result<Self::Resource,Self::Error>{
|
||||
fn load<'a>(&'a mut self,index:Self::Index<'a>)->Result<Self::Resource,Self::Error>{
|
||||
let model=ModelLoader::new(self.finder).load(index)?;
|
||||
let mesh=crate::mesh::convert_mesh(model,&mut self.deferred_loader);
|
||||
Ok(mesh)
|
||||
|
@ -45,7 +45,7 @@ impl<H:core::hash::Hash+Eq> RenderConfigDeferredLoader<H>{
|
||||
pub fn into_indices(self)->impl Iterator<Item=H>{
|
||||
self.render_config_id_from_asset_id.into_keys().flatten()
|
||||
}
|
||||
pub fn into_render_configs<L:Loader<Resource=Texture,Index=H>>(mut self,loader:&mut L,failure_mode:LoadFailureMode)->Result<RenderConfigs,L::Error>{
|
||||
pub fn into_render_configs<'a,L:Loader<Resource=Texture,Index<'a>=H>+'a>(mut self,loader:&mut L,failure_mode:LoadFailureMode)->Result<RenderConfigs,L::Error>{
|
||||
let mut sorted_textures=vec![None;self.texture_count as usize];
|
||||
for (index_option,render_config_id) in self.render_config_id_from_asset_id{
|
||||
let render_config=&mut self.render_configs[render_config_id.get() as usize];
|
||||
@ -93,7 +93,7 @@ impl<H:core::hash::Hash+Eq> MeshDeferredLoader<H>{
|
||||
pub fn into_indices(self)->impl Iterator<Item=H>{
|
||||
self.mesh_id_from_asset_id.into_keys()
|
||||
}
|
||||
pub fn into_meshes<L:Loader<Resource=Mesh,Index=H>>(self,loader:&mut L,failure_mode:LoadFailureMode)->Result<Meshes,L::Error>{
|
||||
pub fn into_meshes<'a,L:Loader<Resource=Mesh,Index<'a>=H>+'a>(self,loader:&mut L,failure_mode:LoadFailureMode)->Result<Meshes,L::Error>{
|
||||
let mut mesh_list=vec![None;self.mesh_id_from_asset_id.len()];
|
||||
for (index,mesh_id) in self.mesh_id_from_asset_id{
|
||||
let resource_result=loader.load(index);
|
||||
|
@ -2,7 +2,7 @@ use std::error::Error;
|
||||
|
||||
pub trait Loader{
|
||||
type Error:Error;
|
||||
type Index;
|
||||
type Index<'a> where Self:'a;
|
||||
type Resource;
|
||||
fn load(&mut self,index:Self::Index)->Result<Self::Resource,Self::Error>;
|
||||
fn load<'a>(&mut self,index:Self::Index<'a>)->Result<Self::Resource,Self::Error>;
|
||||
}
|
||||
|
@ -13,11 +13,11 @@ authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
||||
bytemuck = "1.14.3"
|
||||
glam = "0.30.0"
|
||||
lazy-regex = "3.1.0"
|
||||
rbx_binary = { version = "0.7.4", registry = "strafesnet" }
|
||||
rbx_dom_weak = { version = "2.7.0", registry = "strafesnet" }
|
||||
rbx_binary = { version = "1.1.0-sn4", registry = "strafesnet" }
|
||||
rbx_dom_weak = { version = "3.1.0-sn2", registry = "strafesnet", features = ["instance-userdata"] }
|
||||
rbx_mesh = "0.3.1"
|
||||
rbx_reflection_database = { version = "0.2.10", registry = "strafesnet" }
|
||||
rbx_xml = { version = "0.13.3", registry = "strafesnet" }
|
||||
rbx_reflection_database = "1.0.0"
|
||||
rbx_xml = { version = "1.1.0-sn4", registry = "strafesnet" }
|
||||
rbxassetid = { version = "0.1.0", path = "../rbxassetid", registry = "strafesnet" }
|
||||
roblox_emulator = { version = "0.4.7", path = "../roblox_emulator", registry = "strafesnet" }
|
||||
strafesnet_common = { version = "0.6.0", path = "../common", registry = "strafesnet" }
|
||||
|
@ -1,10 +1,11 @@
|
||||
use std::io::Read;
|
||||
use rbx_dom_weak::ustr;
|
||||
use rbxassetid::{RobloxAssetId,RobloxAssetIdParseErr};
|
||||
use strafesnet_common::model::Mesh;
|
||||
use strafesnet_deferred_loader::{loader::Loader,texture::Texture};
|
||||
|
||||
use crate::data::RobloxMeshBytes;
|
||||
use crate::rbx::RobloxFaceTextureDescription;
|
||||
use crate::rbx::RobloxPartDescription;
|
||||
|
||||
fn read_entire_file(path:impl AsRef<std::path::Path>)->Result<Vec<u8>,std::io::Error>{
|
||||
let mut file=std::fs::File::open(path)?;
|
||||
@ -36,17 +37,17 @@ impl From<RobloxAssetIdParseErr> for TextureError{
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TextureLoader<'a>(std::marker::PhantomData<&'a ()>);
|
||||
impl TextureLoader<'_>{
|
||||
pub struct TextureLoader;
|
||||
impl TextureLoader{
|
||||
pub fn new()->Self{
|
||||
Self(std::marker::PhantomData)
|
||||
Self
|
||||
}
|
||||
}
|
||||
impl<'a> Loader for TextureLoader<'a>{
|
||||
impl Loader for TextureLoader{
|
||||
type Error=TextureError;
|
||||
type Index=&'a str;
|
||||
type Index<'a>=&'a str;
|
||||
type Resource=Texture;
|
||||
fn load(&mut self,index:Self::Index)->Result<Self::Resource,Self::Error>{
|
||||
fn load<'a>(&mut self,index:Self::Index<'a>)->Result<Self::Resource,Self::Error>{
|
||||
let RobloxAssetId(asset_id)=index.parse()?;
|
||||
let file_name=format!("textures/{}.dds",asset_id);
|
||||
let data=read_entire_file(file_name)?;
|
||||
@ -104,7 +105,7 @@ pub enum MeshType<'a>{
|
||||
mesh_data:&'a [u8],
|
||||
physics_data:&'a [u8],
|
||||
size_float_bits:[u32;3],
|
||||
part_texture_description:[Option<RobloxFaceTextureDescription>;6],
|
||||
part_texture_description:RobloxPartDescription,
|
||||
},
|
||||
}
|
||||
#[derive(Hash,Eq,PartialEq)]
|
||||
@ -124,7 +125,7 @@ impl MeshIndex<'_>{
|
||||
mesh_data:&'a [u8],
|
||||
physics_data:&'a [u8],
|
||||
size:&rbx_dom_weak::types::Vector3,
|
||||
part_texture_description:crate::rbx::RobloxPartDescription,
|
||||
part_texture_description:RobloxPartDescription,
|
||||
)->MeshIndex<'a>{
|
||||
MeshIndex{
|
||||
mesh_type:MeshType::Union{
|
||||
@ -138,17 +139,17 @@ impl MeshIndex<'_>{
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MeshLoader<'a>(std::marker::PhantomData<&'a ()>);
|
||||
impl MeshLoader<'_>{
|
||||
pub struct MeshLoader;
|
||||
impl MeshLoader{
|
||||
pub fn new()->Self{
|
||||
Self(std::marker::PhantomData)
|
||||
Self
|
||||
}
|
||||
}
|
||||
impl<'a> Loader for MeshLoader<'a>{
|
||||
impl Loader for MeshLoader{
|
||||
type Error=MeshError;
|
||||
type Index=MeshIndex<'a>;
|
||||
type Index<'a>=MeshIndex<'a>;
|
||||
type Resource=Mesh;
|
||||
fn load(&mut self,index:Self::Index)->Result<Self::Resource,Self::Error>{
|
||||
fn load<'a>(&mut self,index:Self::Index<'a>)->Result<Self::Resource,Self::Error>{
|
||||
let mesh=match index.mesh_type{
|
||||
MeshType::FileMesh=>{
|
||||
let RobloxAssetId(asset_id)=index.content.parse()?;
|
||||
@ -171,12 +172,12 @@ impl<'a> Loader for MeshLoader<'a>{
|
||||
return Err(MeshError::MissingInstance);
|
||||
};
|
||||
if physics_data.is_empty(){
|
||||
if let Some(rbx_dom_weak::types::Variant::BinaryString(data))=instance.properties.get("PhysicsData"){
|
||||
if let Some(rbx_dom_weak::types::Variant::BinaryString(data))=instance.properties.get(&ustr("PhysicsData")){
|
||||
physics_data=data.as_ref();
|
||||
}
|
||||
}
|
||||
if mesh_data.is_empty(){
|
||||
if let Some(rbx_dom_weak::types::Variant::BinaryString(data))=instance.properties.get("MeshData"){
|
||||
if let Some(rbx_dom_weak::types::Variant::BinaryString(data))=instance.properties.get(&ustr("MeshData")){
|
||||
mesh_data=data.as_ref();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use strafesnet_common::model::{Color4,TextureCoordinate,Mesh,IndexedGraphicsGroup,IndexedPhysicsGroup,IndexedVertex,PolygonGroupId,PolygonGroup,PolygonList,PositionId,TextureCoordinateId,NormalId,ColorId,VertexId,RenderConfigId};
|
||||
use strafesnet_common::integer::{vec3,Planar64Vec3};
|
||||
use crate::rbx::{RobloxPartDescription,RobloxWedgeDescription,RobloxCornerWedgeDescription};
|
||||
use strafesnet_common::model::{Color4,TextureCoordinate,Mesh,MeshBuilder,IndexedGraphicsGroup,IndexedPhysicsGroup,IndexedVertex,PolygonGroupId,PolygonGroup,PolygonList,PositionId,TextureCoordinateId,NormalId,ColorId,VertexId,RenderConfigId};
|
||||
use strafesnet_common::integer::{vec3,Planar64,Planar64Vec3};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Primitives{
|
||||
@ -9,7 +10,22 @@ pub enum Primitives{
|
||||
Wedge,
|
||||
CornerWedge,
|
||||
}
|
||||
#[derive(Hash,PartialEq,Eq)]
|
||||
#[derive(Debug)]
|
||||
pub struct PrimitivesError;
|
||||
impl TryFrom<u32> for Primitives{
|
||||
type Error=PrimitivesError;
|
||||
fn try_from(value:u32)->Result<Self,Self::Error>{
|
||||
match value{
|
||||
0=>Ok(Primitives::Sphere),
|
||||
1=>Ok(Primitives::Cube),
|
||||
2=>Ok(Primitives::Cylinder),
|
||||
3=>Ok(Primitives::Wedge),
|
||||
4=>Ok(Primitives::CornerWedge),
|
||||
_=>Err(PrimitivesError),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone,Copy,Hash,PartialEq,Eq)]
|
||||
pub enum CubeFace{
|
||||
Right,
|
||||
Top,
|
||||
@ -18,6 +34,22 @@ pub enum CubeFace{
|
||||
Bottom,
|
||||
Front,
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub struct CubeFaceError;
|
||||
impl TryFrom<u32> for CubeFace{
|
||||
type Error=CubeFaceError;
|
||||
fn try_from(value:u32)->Result<Self,Self::Error>{
|
||||
match value{
|
||||
0=>Ok(CubeFace::Right),
|
||||
1=>Ok(CubeFace::Top),
|
||||
2=>Ok(CubeFace::Back),
|
||||
3=>Ok(CubeFace::Left),
|
||||
4=>Ok(CubeFace::Bottom),
|
||||
5=>Ok(CubeFace::Front),
|
||||
_=>Err(CubeFaceError),
|
||||
}
|
||||
}
|
||||
}
|
||||
const CUBE_DEFAULT_TEXTURE_COORDS:[TextureCoordinate;4]=[
|
||||
TextureCoordinate::new(0.0,0.0),
|
||||
TextureCoordinate::new(1.0,0.0),
|
||||
@ -43,103 +75,36 @@ const CUBE_DEFAULT_NORMALS:[Planar64Vec3;6]=[
|
||||
vec3::int( 0, 0,-1),//CubeFace::Front
|
||||
];
|
||||
|
||||
#[derive(Hash,PartialEq,Eq)]
|
||||
pub enum WedgeFace{
|
||||
Right,
|
||||
TopFront,
|
||||
Back,
|
||||
Left,
|
||||
Bottom,
|
||||
}
|
||||
const WEDGE_DEFAULT_NORMALS:[Planar64Vec3;5]=[
|
||||
vec3::int( 1, 0, 0),//Wedge::Right
|
||||
vec3::int( 0, 1,-1),//Wedge::TopFront
|
||||
vec3::int( 0, 0, 1),//Wedge::Back
|
||||
vec3::int(-1, 0, 0),//Wedge::Left
|
||||
vec3::int( 0,-1, 0),//Wedge::Bottom
|
||||
];
|
||||
/*
|
||||
local cornerWedgeVerticies = {
|
||||
Vector3.new(-1/2,-1/2,-1/2),7
|
||||
Vector3.new(-1/2,-1/2, 1/2),0
|
||||
Vector3.new( 1/2,-1/2,-1/2),6
|
||||
Vector3.new( 1/2,-1/2, 1/2),1
|
||||
Vector3.new( 1/2, 1/2,-1/2),5
|
||||
}
|
||||
*/
|
||||
#[derive(Hash,PartialEq,Eq)]
|
||||
pub enum CornerWedgeFace{
|
||||
Right,
|
||||
TopBack,
|
||||
TopLeft,
|
||||
Bottom,
|
||||
Front,
|
||||
}
|
||||
const CORNERWEDGE_DEFAULT_NORMALS:[Planar64Vec3;5]=[
|
||||
vec3::int( 1, 0, 0),//CornerWedge::Right
|
||||
vec3::int( 0, 1, 1),//CornerWedge::BackTop
|
||||
vec3::int(-1, 1, 0),//CornerWedge::LeftTop
|
||||
vec3::int( 0,-1, 0),//CornerWedge::Bottom
|
||||
vec3::int( 0, 0,-1),//CornerWedge::Front
|
||||
];
|
||||
#[derive(Default)]
|
||||
pub struct CubeFaceDescription([Option<FaceDescription>;6]);
|
||||
pub struct CubeFaceDescription([FaceDescription;Self::FACES]);
|
||||
impl CubeFaceDescription{
|
||||
pub fn insert(&mut self,index:CubeFace,value:FaceDescription){
|
||||
self.0[index as usize]=Some(value);
|
||||
}
|
||||
pub fn pairs(self)->impl Iterator<Item=(usize,FaceDescription)>{
|
||||
self.0.into_iter().enumerate().filter_map(|(i,v)|v.map(|u|(i,u)))
|
||||
pub const FACES:usize=6;
|
||||
pub fn new(RobloxPartDescription(part_description):RobloxPartDescription,textureless_render_id:RenderConfigId)->Self{
|
||||
Self(part_description.map(|face_description|match face_description{
|
||||
Some(roblox_texture_transform)=>roblox_texture_transform.to_face_description(),
|
||||
None=>FaceDescription::new_with_render_id(textureless_render_id),
|
||||
}))
|
||||
}
|
||||
}
|
||||
pub fn unit_cube(render:RenderConfigId)->Mesh{
|
||||
let mut t=CubeFaceDescription::default();
|
||||
t.insert(CubeFace::Right,FaceDescription::new_with_render_id(render));
|
||||
t.insert(CubeFace::Top,FaceDescription::new_with_render_id(render));
|
||||
t.insert(CubeFace::Back,FaceDescription::new_with_render_id(render));
|
||||
t.insert(CubeFace::Left,FaceDescription::new_with_render_id(render));
|
||||
t.insert(CubeFace::Bottom,FaceDescription::new_with_render_id(render));
|
||||
t.insert(CubeFace::Front,FaceDescription::new_with_render_id(render));
|
||||
generate_partial_unit_cube(t)
|
||||
}
|
||||
#[derive(Default)]
|
||||
pub struct WedgeFaceDescription([Option<FaceDescription>;5]);
|
||||
pub struct WedgeFaceDescription([FaceDescription;Self::FACES]);
|
||||
impl WedgeFaceDescription{
|
||||
pub fn insert(&mut self,index:WedgeFace,value:FaceDescription){
|
||||
self.0[index as usize]=Some(value);
|
||||
}
|
||||
pub fn pairs(self)->std::iter::FilterMap<std::iter::Enumerate<std::array::IntoIter<Option<FaceDescription>,5>>,impl FnMut((usize,Option<FaceDescription>))->Option<(usize,FaceDescription)>>{
|
||||
self.0.into_iter().enumerate().filter_map(|v|v.1.map(|u|(v.0,u)))
|
||||
pub const FACES:usize=5;
|
||||
pub fn new(RobloxWedgeDescription(part_description):RobloxWedgeDescription,textureless_render_id:RenderConfigId)->Self{
|
||||
Self(part_description.map(|face_description|match face_description{
|
||||
Some(roblox_texture_transform)=>roblox_texture_transform.to_face_description(),
|
||||
None=>FaceDescription::new_with_render_id(textureless_render_id),
|
||||
}))
|
||||
}
|
||||
}
|
||||
// pub fn unit_wedge(render:RenderConfigId)->Mesh{
|
||||
// let mut t=WedgeFaceDescription::default();
|
||||
// t.insert(WedgeFace::Right,FaceDescription::new_with_render_id(render));
|
||||
// t.insert(WedgeFace::TopFront,FaceDescription::new_with_render_id(render));
|
||||
// t.insert(WedgeFace::Back,FaceDescription::new_with_render_id(render));
|
||||
// t.insert(WedgeFace::Left,FaceDescription::new_with_render_id(render));
|
||||
// t.insert(WedgeFace::Bottom,FaceDescription::new_with_render_id(render));
|
||||
// generate_partial_unit_wedge(t)
|
||||
// }
|
||||
#[derive(Default)]
|
||||
pub struct CornerWedgeFaceDescription([Option<FaceDescription>;5]);
|
||||
pub struct CornerWedgeFaceDescription([FaceDescription;Self::FACES]);
|
||||
impl CornerWedgeFaceDescription{
|
||||
pub fn insert(&mut self,index:CornerWedgeFace,value:FaceDescription){
|
||||
self.0[index as usize]=Some(value);
|
||||
}
|
||||
pub fn pairs(self)->std::iter::FilterMap<std::iter::Enumerate<std::array::IntoIter<Option<FaceDescription>,5>>,impl FnMut((usize,Option<FaceDescription>))->Option<(usize,FaceDescription)>>{
|
||||
self.0.into_iter().enumerate().filter_map(|v|v.1.map(|u|(v.0,u)))
|
||||
pub const FACES:usize=5;
|
||||
pub fn new(RobloxCornerWedgeDescription(part_description):RobloxCornerWedgeDescription,textureless_render_id:RenderConfigId)->Self{
|
||||
Self(part_description.map(|face_description|match face_description{
|
||||
Some(roblox_texture_transform)=>roblox_texture_transform.to_face_description(),
|
||||
None=>FaceDescription::new_with_render_id(textureless_render_id),
|
||||
}))
|
||||
}
|
||||
}
|
||||
// pub fn unit_cornerwedge(render:RenderConfigId)->Mesh{
|
||||
// let mut t=CornerWedgeFaceDescription::default();
|
||||
// t.insert(CornerWedgeFace::Right,FaceDescription::new_with_render_id(render));
|
||||
// t.insert(CornerWedgeFace::TopBack,FaceDescription::new_with_render_id(render));
|
||||
// t.insert(CornerWedgeFace::TopLeft,FaceDescription::new_with_render_id(render));
|
||||
// t.insert(CornerWedgeFace::Bottom,FaceDescription::new_with_render_id(render));
|
||||
// t.insert(CornerWedgeFace::Front,FaceDescription::new_with_render_id(render));
|
||||
// generate_partial_unit_cornerwedge(t)
|
||||
// }
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct FaceDescription{
|
||||
@ -148,7 +113,7 @@ pub struct FaceDescription{
|
||||
pub color:Color4,
|
||||
}
|
||||
impl FaceDescription{
|
||||
pub fn new_with_render_id(render:RenderConfigId)->Self {
|
||||
pub fn new_with_render_id(render:RenderConfigId)->Self{
|
||||
Self{
|
||||
render,
|
||||
transform:glam::Affine2::IDENTITY,
|
||||
@ -156,49 +121,49 @@ impl FaceDescription{
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn generate_partial_unit_cube(face_descriptions:CubeFaceDescription)->Mesh{
|
||||
const CUBE_DEFAULT_POLYS:[[[u32;3];4];6]=[
|
||||
pub fn unit_cube(CubeFaceDescription(face_descriptions):CubeFaceDescription)->Mesh{
|
||||
const CUBE_DEFAULT_POLYS:[[[u32;2];4];6]=[
|
||||
// right (1, 0, 0)
|
||||
[
|
||||
[6,2,0],//[vertex,tex,norm]
|
||||
[5,1,0],
|
||||
[2,0,0],
|
||||
[1,3,0],
|
||||
[6,2],//[vertex,tex]
|
||||
[5,1],
|
||||
[2,0],
|
||||
[1,3],
|
||||
],
|
||||
// top (0, 1, 0)
|
||||
[
|
||||
[5,3,1],
|
||||
[4,2,1],
|
||||
[3,1,1],
|
||||
[2,0,1],
|
||||
[5,3],
|
||||
[4,2],
|
||||
[3,1],
|
||||
[2,0],
|
||||
],
|
||||
// back (0, 0, 1)
|
||||
[
|
||||
[0,3,2],
|
||||
[1,2,2],
|
||||
[2,1,2],
|
||||
[3,0,2],
|
||||
[0,3],
|
||||
[1,2],
|
||||
[2,1],
|
||||
[3,0],
|
||||
],
|
||||
// left (-1, 0, 0)
|
||||
[
|
||||
[0,2,3],
|
||||
[3,1,3],
|
||||
[4,0,3],
|
||||
[7,3,3],
|
||||
[0,2],
|
||||
[3,1],
|
||||
[4,0],
|
||||
[7,3],
|
||||
],
|
||||
// bottom (0,-1, 0)
|
||||
[
|
||||
[1,1,4],
|
||||
[0,0,4],
|
||||
[7,3,4],
|
||||
[6,2,4],
|
||||
[1,1],
|
||||
[0,0],
|
||||
[7,3],
|
||||
[6,2],
|
||||
],
|
||||
// front (0, 0,-1)
|
||||
[
|
||||
[4,1,5],
|
||||
[5,0,5],
|
||||
[6,3,5],
|
||||
[7,2,5],
|
||||
[4,1],
|
||||
[5,0],
|
||||
[6,3],
|
||||
[7,2],
|
||||
],
|
||||
];
|
||||
let mut generated_pos=Vec::new();
|
||||
@ -211,7 +176,7 @@ pub fn generate_partial_unit_cube(face_descriptions:CubeFaceDescription)->Mesh{
|
||||
let mut physics_group=IndexedPhysicsGroup::default();
|
||||
let mut transforms=Vec::new();
|
||||
//note that on a cube every vertex is guaranteed to be unique, so there's no need to hash them against existing vertices.
|
||||
for (face_id,face_description) in face_descriptions.pairs(){
|
||||
for (face_id,face_description) in face_descriptions.into_iter().enumerate(){
|
||||
//assume that scanning short lists is faster than hashing.
|
||||
let transform_index=if let Some(transform_index)=transforms.iter().position(|&transform|transform==face_description.transform){
|
||||
transform_index
|
||||
@ -238,8 +203,8 @@ pub fn generate_partial_unit_cube(face_descriptions:CubeFaceDescription)->Mesh{
|
||||
//push vertices as they are needed
|
||||
let group_id=PolygonGroupId::new(polygon_groups.len() as u32);
|
||||
polygon_groups.push(PolygonGroup::PolygonList(PolygonList::new(vec![
|
||||
CUBE_DEFAULT_POLYS[face_id].map(|tup|{
|
||||
let pos=CUBE_DEFAULT_VERTICES[tup[0] as usize];
|
||||
CUBE_DEFAULT_POLYS[face_id].map(|[pos_id,tex_id]|{
|
||||
let pos=CUBE_DEFAULT_VERTICES[pos_id as usize];
|
||||
let pos_index=if let Some(pos_index)=generated_pos.iter().position(|&p|p==pos){
|
||||
pos_index
|
||||
}else{
|
||||
@ -251,7 +216,7 @@ pub fn generate_partial_unit_cube(face_descriptions:CubeFaceDescription)->Mesh{
|
||||
//always push vertex
|
||||
let vertex=IndexedVertex{
|
||||
pos:PositionId::new(pos_index),
|
||||
tex:TextureCoordinateId::new(tup[1]+4*transform_index),
|
||||
tex:TextureCoordinateId::new(tex_id+4*transform_index),
|
||||
normal:NormalId::new(normal_index),
|
||||
color:ColorId::new(color_index),
|
||||
};
|
||||
@ -278,42 +243,49 @@ pub fn generate_partial_unit_cube(face_descriptions:CubeFaceDescription)->Mesh{
|
||||
}
|
||||
}
|
||||
//don't think too hard about the copy paste because this is all going into the map tool eventually...
|
||||
pub fn generate_partial_unit_wedge(face_descriptions:WedgeFaceDescription)->Mesh{
|
||||
const WEDGE_DEFAULT_POLYS:[&[[u32;3]];5]=[
|
||||
pub fn unit_wedge(WedgeFaceDescription(face_descriptions):WedgeFaceDescription)->Mesh{
|
||||
const WEDGE_DEFAULT_POLYS:[&[[u32;2]];5]=[
|
||||
// right (1, 0, 0)
|
||||
&[
|
||||
[6,2,0],//[vertex,tex,norm]
|
||||
[2,0,0],
|
||||
[1,3,0],
|
||||
[6,2],//[vertex,tex]
|
||||
[2,0],
|
||||
[1,3],
|
||||
],
|
||||
// FrontTop (0, 1, -1)
|
||||
&[
|
||||
[3,1,1],
|
||||
[2,0,1],
|
||||
[6,3,1],
|
||||
[7,2,1],
|
||||
[3,1],
|
||||
[2,0],
|
||||
[6,3],
|
||||
[7,2],
|
||||
],
|
||||
// back (0, 0, 1)
|
||||
&[
|
||||
[0,3,2],
|
||||
[1,2,2],
|
||||
[2,1,2],
|
||||
[3,0,2],
|
||||
[0,3],
|
||||
[1,2],
|
||||
[2,1],
|
||||
[3,0],
|
||||
],
|
||||
// left (-1, 0, 0)
|
||||
&[
|
||||
[0,2,3],
|
||||
[3,1,3],
|
||||
[7,3,3],
|
||||
[0,2],
|
||||
[3,1],
|
||||
[7,3],
|
||||
],
|
||||
// bottom (0,-1, 0)
|
||||
&[
|
||||
[1,1,4],
|
||||
[0,0,4],
|
||||
[7,3,4],
|
||||
[6,2,4],
|
||||
[1,1],
|
||||
[0,0],
|
||||
[7,3],
|
||||
[6,2],
|
||||
],
|
||||
];
|
||||
const WEDGE_DEFAULT_NORMALS:[Planar64Vec3;5]=[
|
||||
vec3::int( 1, 0, 0),//Wedge::Right
|
||||
vec3::int( 0, 1,-1),//Wedge::TopFront
|
||||
vec3::int( 0, 0, 1),//Wedge::Back
|
||||
vec3::int(-1, 0, 0),//Wedge::Left
|
||||
vec3::int( 0,-1, 0),//Wedge::Bottom
|
||||
];
|
||||
let mut generated_pos=Vec::new();
|
||||
let mut generated_tex=Vec::new();
|
||||
let mut generated_normal=Vec::new();
|
||||
@ -324,7 +296,7 @@ pub fn generate_partial_unit_wedge(face_descriptions:WedgeFaceDescription)->Mesh
|
||||
let mut physics_group=IndexedPhysicsGroup::default();
|
||||
let mut transforms=Vec::new();
|
||||
//note that on a cube every vertex is guaranteed to be unique, so there's no need to hash them against existing vertices.
|
||||
for (face_id,face_description) in face_descriptions.pairs(){
|
||||
for (face_id,face_description) in face_descriptions.into_iter().enumerate(){
|
||||
//assume that scanning short lists is faster than hashing.
|
||||
let transform_index=if let Some(transform_index)=transforms.iter().position(|&transform|transform==face_description.transform){
|
||||
transform_index
|
||||
@ -351,8 +323,8 @@ pub fn generate_partial_unit_wedge(face_descriptions:WedgeFaceDescription)->Mesh
|
||||
//push vertices as they are needed
|
||||
let group_id=PolygonGroupId::new(polygon_groups.len() as u32);
|
||||
polygon_groups.push(PolygonGroup::PolygonList(PolygonList::new(vec![
|
||||
WEDGE_DEFAULT_POLYS[face_id].iter().map(|tup|{
|
||||
let pos=CUBE_DEFAULT_VERTICES[tup[0] as usize];
|
||||
WEDGE_DEFAULT_POLYS[face_id].iter().map(|&[pos_id,tex_id]|{
|
||||
let pos=CUBE_DEFAULT_VERTICES[pos_id as usize];
|
||||
let pos_index=if let Some(pos_index)=generated_pos.iter().position(|&p|p==pos){
|
||||
pos_index
|
||||
}else{
|
||||
@ -364,7 +336,7 @@ pub fn generate_partial_unit_wedge(face_descriptions:WedgeFaceDescription)->Mesh
|
||||
//always push vertex
|
||||
let vertex=IndexedVertex{
|
||||
pos:PositionId::new(pos_index),
|
||||
tex:TextureCoordinateId::new(tup[1]+4*transform_index),
|
||||
tex:TextureCoordinateId::new(tex_id+4*transform_index),
|
||||
normal:NormalId::new(normal_index),
|
||||
color:ColorId::new(color_index),
|
||||
};
|
||||
@ -391,40 +363,47 @@ pub fn generate_partial_unit_wedge(face_descriptions:WedgeFaceDescription)->Mesh
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_partial_unit_cornerwedge(face_descriptions:CornerWedgeFaceDescription)->Mesh{
|
||||
const CORNERWEDGE_DEFAULT_POLYS:[&[[u32;3]];5]=[
|
||||
pub fn unit_cornerwedge(CornerWedgeFaceDescription(face_descriptions):CornerWedgeFaceDescription)->Mesh{
|
||||
const CORNERWEDGE_DEFAULT_POLYS:[&[[u32;2]];5]=[
|
||||
// right (1, 0, 0)
|
||||
&[
|
||||
[6,2,0],//[vertex,tex,norm]
|
||||
[5,1,0],
|
||||
[1,3,0],
|
||||
[6,2],//[vertex,tex]
|
||||
[5,1],
|
||||
[1,3],
|
||||
],
|
||||
// BackTop (0, 1, 1)
|
||||
&[
|
||||
[5,3,1],
|
||||
[0,1,1],
|
||||
[1,0,1],
|
||||
[5,3],
|
||||
[0,1],
|
||||
[1,0],
|
||||
],
|
||||
// LeftTop (-1, 1, 0)
|
||||
&[
|
||||
[5,3,2],
|
||||
[7,2,2],
|
||||
[0,1,2],
|
||||
[5,3],
|
||||
[7,2],
|
||||
[0,1],
|
||||
],
|
||||
// bottom (0,-1, 0)
|
||||
&[
|
||||
[1,1,3],
|
||||
[0,0,3],
|
||||
[7,3,3],
|
||||
[6,2,3],
|
||||
[1,1],
|
||||
[0,0],
|
||||
[7,3],
|
||||
[6,2],
|
||||
],
|
||||
// front (0, 0,-1)
|
||||
&[
|
||||
[5,0,4],
|
||||
[6,3,4],
|
||||
[7,2,4],
|
||||
[5,0],
|
||||
[6,3],
|
||||
[7,2],
|
||||
],
|
||||
];
|
||||
const CORNERWEDGE_DEFAULT_NORMALS:[Planar64Vec3;5]=[
|
||||
vec3::int( 1, 0, 0),//CornerWedge::Right
|
||||
vec3::int( 0, 1, 1),//CornerWedge::BackTop
|
||||
vec3::int(-1, 1, 0),//CornerWedge::LeftTop
|
||||
vec3::int( 0,-1, 0),//CornerWedge::Bottom
|
||||
vec3::int( 0, 0,-1),//CornerWedge::Front
|
||||
];
|
||||
let mut generated_pos=Vec::new();
|
||||
let mut generated_tex=Vec::new();
|
||||
let mut generated_normal=Vec::new();
|
||||
@ -435,7 +414,7 @@ pub fn generate_partial_unit_cornerwedge(face_descriptions:CornerWedgeFaceDescri
|
||||
let mut physics_group=IndexedPhysicsGroup::default();
|
||||
let mut transforms=Vec::new();
|
||||
//note that on a cube every vertex is guaranteed to be unique, so there's no need to hash them against existing vertices.
|
||||
for (face_id,face_description) in face_descriptions.pairs(){
|
||||
for (face_id,face_description) in face_descriptions.into_iter().enumerate(){
|
||||
//assume that scanning short lists is faster than hashing.
|
||||
let transform_index=if let Some(transform_index)=transforms.iter().position(|&transform|transform==face_description.transform){
|
||||
transform_index
|
||||
@ -462,8 +441,8 @@ pub fn generate_partial_unit_cornerwedge(face_descriptions:CornerWedgeFaceDescri
|
||||
//push vertices as they are needed
|
||||
let group_id=PolygonGroupId::new(polygon_groups.len() as u32);
|
||||
polygon_groups.push(PolygonGroup::PolygonList(PolygonList::new(vec![
|
||||
CORNERWEDGE_DEFAULT_POLYS[face_id].iter().map(|tup|{
|
||||
let pos=CUBE_DEFAULT_VERTICES[tup[0] as usize];
|
||||
CORNERWEDGE_DEFAULT_POLYS[face_id].iter().map(|&[pos_id,tex_id]|{
|
||||
let pos=CUBE_DEFAULT_VERTICES[pos_id as usize];
|
||||
let pos_index=if let Some(pos_index)=generated_pos.iter().position(|&p|p==pos){
|
||||
pos_index
|
||||
}else{
|
||||
@ -475,7 +454,7 @@ pub fn generate_partial_unit_cornerwedge(face_descriptions:CornerWedgeFaceDescri
|
||||
//always push vertex
|
||||
let vertex=IndexedVertex{
|
||||
pos:PositionId::new(pos_index),
|
||||
tex:TextureCoordinateId::new(tup[1]+4*transform_index),
|
||||
tex:TextureCoordinateId::new(tex_id+4*transform_index),
|
||||
normal:NormalId::new(normal_index),
|
||||
color:ColorId::new(color_index),
|
||||
};
|
||||
@ -501,3 +480,133 @@ pub fn generate_partial_unit_cornerwedge(face_descriptions:CornerWedgeFaceDescri
|
||||
physics_groups:vec![physics_group],
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: fix face texture orientation
|
||||
pub fn unit_cylinder(face_descriptions:CubeFaceDescription)->Mesh{
|
||||
// cylinder is oriented about the x axis
|
||||
// roblox cylinders use projected grid coordinates
|
||||
/// how many grid coordinates to use (positive and negative)
|
||||
const GON:i32=3;
|
||||
/// grid perimeter
|
||||
const POINTS:[[i32;2];4*2*GON as usize]=const{
|
||||
let mut points=[[0;2];{4*2*GON as usize}];
|
||||
let mut i=-GON;
|
||||
while i<GON{
|
||||
points[(i+GON) as usize]=[i,GON];
|
||||
points[(i+GON+1*2*GON) as usize]=[GON,-i];
|
||||
points[(i+GON+2*2*GON) as usize]=[-i,-GON];
|
||||
points[(i+GON+3*2*GON) as usize]=[-GON,i];
|
||||
i+=1;
|
||||
}
|
||||
points
|
||||
};
|
||||
|
||||
let mut mb=MeshBuilder::new();
|
||||
let mut polygon_groups=Vec::with_capacity(CubeFaceDescription::FACES);
|
||||
let mut graphics_groups=Vec::with_capacity(CubeFaceDescription::FACES);
|
||||
let mut physics_group=IndexedPhysicsGroup{groups:Vec::with_capacity(CubeFaceDescription::FACES)};
|
||||
let CubeFaceDescription([right,top,back,left,bottom,front])=face_descriptions;
|
||||
|
||||
macro_rules! end_face{
|
||||
($face_description:expr,$end:expr,$iter:expr)=>{
|
||||
let normal=mb.acquire_normal_id($end);
|
||||
let color=mb.acquire_color_id($face_description.color);
|
||||
|
||||
// single polygon for physics
|
||||
let polygon:Vec<_>=$iter.map(|[x,y]|{
|
||||
let tex=mb.acquire_tex_id(
|
||||
$face_description.transform.transform_point2(
|
||||
(glam::vec2(-x as f32,y as f32).normalize()+1.0)/2.0
|
||||
)
|
||||
);
|
||||
let pos=mb.acquire_pos_id($end+vec3::int(0,-x,y).with_length(Planar64::ONE).divide().wrap_1());
|
||||
mb.acquire_vertex_id(IndexedVertex{pos,tex,normal,color})
|
||||
}).collect();
|
||||
|
||||
// fanned polygons for graphics
|
||||
let pos=mb.acquire_pos_id($end);
|
||||
let tex=mb.acquire_tex_id($face_description.transform.transform_point2(glam::Vec2::ONE/2.0));
|
||||
let center=mb.acquire_vertex_id(IndexedVertex{pos,tex,normal,color});
|
||||
let polygon_list=(0..POINTS.len()).map(|i|
|
||||
vec![center,polygon[i],polygon[(i+1)%POINTS.len()]]
|
||||
).collect();
|
||||
|
||||
// end face graphics
|
||||
let group_id=PolygonGroupId::new(polygon_groups.len() as u32);
|
||||
polygon_groups.push(PolygonGroup::PolygonList(PolygonList::new(polygon_list)));
|
||||
graphics_groups.push(IndexedGraphicsGroup{
|
||||
render:$face_description.render,
|
||||
groups:vec![group_id],
|
||||
});
|
||||
|
||||
// end face physics
|
||||
let polygon_list=vec![polygon];
|
||||
|
||||
let group_id=PolygonGroupId::new(polygon_groups.len() as u32);
|
||||
polygon_groups.push(PolygonGroup::PolygonList(PolygonList::new(polygon_list)));
|
||||
physics_group.groups.push(group_id);
|
||||
}
|
||||
}
|
||||
macro_rules! tex{
|
||||
($face_description:expr,$tex:expr)=>{{
|
||||
let [x,y]=$tex;
|
||||
$face_description.transform.transform_point2(
|
||||
glam::vec2((x+GON) as f32,(y+GON) as f32)/(2*GON) as f32
|
||||
)
|
||||
}};
|
||||
}
|
||||
macro_rules! barrel_face{
|
||||
($face_description:expr,$loop:ident,$lo_dir:expr,$hi_dir:expr,$tex_0:expr,$tex_1:expr,$tex_2:expr,$tex_3:expr)=>{
|
||||
let mut polygon_list=Vec::with_capacity(CubeFaceDescription::FACES);
|
||||
for $loop in -GON..GON{
|
||||
// lo Z
|
||||
let lz_dir=$lo_dir.with_length(Planar64::ONE).divide().wrap_1();
|
||||
// hi Z
|
||||
let hz_dir=$hi_dir.with_length(Planar64::ONE).divide().wrap_1();
|
||||
|
||||
// pos
|
||||
let lx_lz_pos=mb.acquire_pos_id(vec3::NEG_X+lz_dir);
|
||||
let lx_hz_pos=mb.acquire_pos_id(vec3::NEG_X+hz_dir);
|
||||
let hx_hz_pos=mb.acquire_pos_id(vec3::X+hz_dir);
|
||||
let hx_lz_pos=mb.acquire_pos_id(vec3::X+lz_dir);
|
||||
// tex
|
||||
let lx_lz_tex=mb.acquire_tex_id(tex!($face_description,$tex_0));
|
||||
let lx_hz_tex=mb.acquire_tex_id(tex!($face_description,$tex_1));
|
||||
let hx_hz_tex=mb.acquire_tex_id(tex!($face_description,$tex_2));
|
||||
let hx_lz_tex=mb.acquire_tex_id(tex!($face_description,$tex_3));
|
||||
// norm
|
||||
let lz_norm=mb.acquire_normal_id(lz_dir);
|
||||
let hz_norm=mb.acquire_normal_id(hz_dir);
|
||||
// color
|
||||
let color=mb.acquire_color_id($face_description.color);
|
||||
|
||||
polygon_list.push(vec![
|
||||
mb.acquire_vertex_id(IndexedVertex{pos:lx_lz_pos,tex:lx_lz_tex,normal:lz_norm,color}),
|
||||
mb.acquire_vertex_id(IndexedVertex{pos:lx_hz_pos,tex:lx_hz_tex,normal:hz_norm,color}),
|
||||
mb.acquire_vertex_id(IndexedVertex{pos:hx_hz_pos,tex:hx_hz_tex,normal:hz_norm,color}),
|
||||
mb.acquire_vertex_id(IndexedVertex{pos:hx_lz_pos,tex:hx_lz_tex,normal:lz_norm,color}),
|
||||
]);
|
||||
}
|
||||
|
||||
// push face
|
||||
let group_id=PolygonGroupId::new(polygon_groups.len() as u32);
|
||||
polygon_groups.push(PolygonGroup::PolygonList(PolygonList::new(polygon_list)));
|
||||
graphics_groups.push(IndexedGraphicsGroup{
|
||||
render:$face_description.render,
|
||||
groups:vec![group_id],
|
||||
});
|
||||
physics_group.groups.push(group_id);
|
||||
};
|
||||
}
|
||||
|
||||
end_face!(right, vec3::X,POINTS.into_iter());
|
||||
barrel_face!(top, z,vec3::int(0,GON,z),vec3::int(0,GON,z+1), [GON,z],[GON,z+1],[-GON,z+1],[-GON,z]);
|
||||
barrel_face!(back, y,vec3::int(0,y+1,GON),vec3::int(0,y,GON), [GON,y+1],[GON,y],[-GON,y],[-GON,y+1]);
|
||||
end_face!(left, vec3::NEG_X,POINTS.into_iter().rev());
|
||||
barrel_face!(bottom, z,vec3::int(0,-GON,z+1),vec3::int(0,-GON,z), [-GON,z+1],[-GON,z],[GON,z],[GON,z+1]);
|
||||
barrel_face!(front, y,vec3::int(0,y,-GON),vec3::int(0,y+1,-GON), [-GON,y],[-GON,y+1],[GON,y+1],[GON,y]);
|
||||
|
||||
let physics_groups=vec![physics_group];
|
||||
|
||||
mb.build(polygon_groups,graphics_groups,physics_groups)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
use crate::loader::MeshIndex;
|
||||
use crate::primitives;
|
||||
use crate::primitives::{self,CubeFace,CubeFaceDescription,WedgeFaceDescription,CornerWedgeFaceDescription,FaceDescription,Primitives};
|
||||
use rbx_dom_weak::ustr;
|
||||
use strafesnet_common::aabb::Aabb;
|
||||
use strafesnet_common::map;
|
||||
use strafesnet_common::model;
|
||||
@ -347,17 +348,40 @@ impl RobloxFaceTextureDescription{
|
||||
transform:self.transform.to_bits(),
|
||||
}
|
||||
}
|
||||
pub fn to_face_description(&self)->primitives::FaceDescription{
|
||||
primitives::FaceDescription{
|
||||
pub fn to_face_description(&self)->FaceDescription{
|
||||
FaceDescription{
|
||||
render:self.render,
|
||||
transform:self.transform.affine(),
|
||||
color:self.color,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub type RobloxPartDescription=[Option<RobloxFaceTextureDescription>;6];
|
||||
type RobloxWedgeDescription=[Option<RobloxFaceTextureDescription>;5];
|
||||
type RobloxCornerWedgeDescription=[Option<RobloxFaceTextureDescription>;5];
|
||||
macro_rules! impl_description_index{
|
||||
($description:ident,$index:ty)=>{
|
||||
impl core::ops::Index<$index> for $description{
|
||||
type Output=Option<RobloxFaceTextureDescription>;
|
||||
fn index(&self,index:$index)->&Self::Output{
|
||||
&self.0[index as usize]
|
||||
}
|
||||
}
|
||||
impl core::ops::IndexMut<$index> for $description{
|
||||
fn index_mut(&mut self,index:$index)->&mut Self::Output{
|
||||
&mut self.0[index as usize]
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Clone,Default,Eq,Hash,PartialEq)]
|
||||
pub struct RobloxPartDescription(pub(crate)[Option<RobloxFaceTextureDescription>;6]);
|
||||
impl_description_index!(RobloxPartDescription,CubeFace);
|
||||
|
||||
#[derive(Clone,Default,Eq,Hash,PartialEq)]
|
||||
pub struct RobloxWedgeDescription(pub(crate)[Option<RobloxFaceTextureDescription>;5]);
|
||||
|
||||
#[derive(Clone,Default,Eq,Hash,PartialEq)]
|
||||
pub struct RobloxCornerWedgeDescription(pub(crate)[Option<RobloxFaceTextureDescription>;5]);
|
||||
|
||||
#[derive(Clone,Eq,Hash,PartialEq)]
|
||||
enum RobloxBasePartDescription{
|
||||
Sphere(RobloxPartDescription),
|
||||
@ -366,6 +390,18 @@ enum RobloxBasePartDescription{
|
||||
Wedge(RobloxWedgeDescription),
|
||||
CornerWedge(RobloxCornerWedgeDescription),
|
||||
}
|
||||
|
||||
// TODO: initialize all ustrs in a top level struct thrown around as a reference
|
||||
// struct UstrKludge{
|
||||
// }
|
||||
|
||||
fn get_content_url(content:&rbx_dom_weak::types::Content)->Option<&str>{
|
||||
match content.value(){
|
||||
rbx_dom_weak::types::ContentType::Uri(uri)=>Some(uri.as_str()),
|
||||
_=>None,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_texture_description<'a>(
|
||||
temp_objects:&mut Vec<rbx_dom_weak::types::Ref>,
|
||||
render_config_deferred_loader:&mut RenderConfigDeferredLoader<&'a str>,
|
||||
@ -374,80 +410,83 @@ fn get_texture_description<'a>(
|
||||
size:&rbx_dom_weak::types::Vector3,
|
||||
)->RobloxPartDescription{
|
||||
//use the biggest one and cut it down later...
|
||||
let mut part_texture_description:RobloxPartDescription=[None,None,None,None,None,None];
|
||||
let mut part_texture_description=RobloxPartDescription::default();
|
||||
temp_objects.clear();
|
||||
recursive_collect_superclass(temp_objects,&dom,object,"Decal");
|
||||
for &mut decal_ref in temp_objects{
|
||||
if let Some(decal)=dom.get_by_ref(decal_ref){
|
||||
if let (
|
||||
Some(rbx_dom_weak::types::Variant::Content(content)),
|
||||
let Some(decal)=dom.get_by_ref(decal_ref) else{
|
||||
println!("Decal get_by_ref failed");
|
||||
continue;
|
||||
};
|
||||
let (
|
||||
Some(rbx_dom_weak::types::Variant::ContentId(content)),
|
||||
Some(rbx_dom_weak::types::Variant::Enum(normalid)),
|
||||
Some(rbx_dom_weak::types::Variant::Color3(decal_color3)),
|
||||
Some(rbx_dom_weak::types::Variant::Float32(decal_transparency)),
|
||||
) = (
|
||||
decal.properties.get("Texture"),
|
||||
decal.properties.get("Face"),
|
||||
decal.properties.get("Color3"),
|
||||
decal.properties.get("Transparency"),
|
||||
) {
|
||||
let render_id=render_config_deferred_loader.acquire_render_config_id(Some(content.as_ref()));
|
||||
let normal_id=normalid.to_u32();
|
||||
if normal_id<6{
|
||||
let (roblox_texture_color,roblox_texture_transform)=if decal.class=="Texture"{
|
||||
//generate tranform
|
||||
if let (
|
||||
Some(&rbx_dom_weak::types::Variant::Float32(offset_studs_u)),
|
||||
Some(&rbx_dom_weak::types::Variant::Float32(offset_studs_v)),
|
||||
Some(&rbx_dom_weak::types::Variant::Float32(studs_per_tile_u)),
|
||||
Some(&rbx_dom_weak::types::Variant::Float32(studs_per_tile_v)),
|
||||
) = (
|
||||
decal.properties.get("OffsetStudsU"),
|
||||
decal.properties.get("OffsetStudsV"),
|
||||
decal.properties.get("StudsPerTileU"),
|
||||
decal.properties.get("StudsPerTileV"),
|
||||
)
|
||||
{
|
||||
let (size_u,size_v)=match normal_id{
|
||||
0=>(size.z,size.y),//right
|
||||
1=>(size.x,size.z),//top
|
||||
2=>(size.x,size.y),//back
|
||||
3=>(size.z,size.y),//left
|
||||
4=>(size.x,size.z),//bottom
|
||||
5=>(size.x,size.y),//front
|
||||
_=>unreachable!(),
|
||||
};
|
||||
(
|
||||
glam::vec4(decal_color3.r,decal_color3.g,decal_color3.b,1.0-*decal_transparency),
|
||||
RobloxTextureTransform{
|
||||
offset_studs_u,
|
||||
offset_studs_v,
|
||||
studs_per_tile_u,
|
||||
studs_per_tile_v,
|
||||
size_u,
|
||||
size_v,
|
||||
}
|
||||
)
|
||||
}else{
|
||||
(glam::Vec4::ONE,RobloxTextureTransform::identity())
|
||||
}
|
||||
}else{
|
||||
(glam::Vec4::ONE,RobloxTextureTransform::identity())
|
||||
};
|
||||
part_texture_description[normal_id as usize]=Some(RobloxFaceTextureDescription{
|
||||
render:render_id,
|
||||
color:roblox_texture_color,
|
||||
transform:roblox_texture_transform,
|
||||
});
|
||||
}else{
|
||||
println!("NormalId={} is invalid",normal_id);
|
||||
}
|
||||
)=(
|
||||
decal.properties.get(&ustr("Texture")),
|
||||
decal.properties.get(&ustr("Face")),
|
||||
decal.properties.get(&ustr("Color3")),
|
||||
decal.properties.get(&ustr("Transparency")),
|
||||
)else{
|
||||
println!("Decal is missing a required property");
|
||||
continue;
|
||||
};
|
||||
let texture_id=Some(content.as_str());
|
||||
let render_id=render_config_deferred_loader.acquire_render_config_id(texture_id);
|
||||
let Ok(cube_face)=normalid.to_u32().try_into()else{
|
||||
println!("NormalId is invalid");
|
||||
continue;
|
||||
};
|
||||
let (roblox_texture_color,roblox_texture_transform)=if decal.class=="Texture"{
|
||||
//generate tranform
|
||||
if let (
|
||||
Some(&rbx_dom_weak::types::Variant::Float32(offset_studs_u)),
|
||||
Some(&rbx_dom_weak::types::Variant::Float32(offset_studs_v)),
|
||||
Some(&rbx_dom_weak::types::Variant::Float32(studs_per_tile_u)),
|
||||
Some(&rbx_dom_weak::types::Variant::Float32(studs_per_tile_v)),
|
||||
) = (
|
||||
decal.properties.get(&ustr("OffsetStudsU")),
|
||||
decal.properties.get(&ustr("OffsetStudsV")),
|
||||
decal.properties.get(&ustr("StudsPerTileU")),
|
||||
decal.properties.get(&ustr("StudsPerTileV")),
|
||||
)
|
||||
{
|
||||
let (size_u,size_v)=match cube_face{
|
||||
CubeFace::Right=>(size.z,size.y),//right
|
||||
CubeFace::Top=>(size.x,size.z),//top
|
||||
CubeFace::Back=>(size.x,size.y),//back
|
||||
CubeFace::Left=>(size.z,size.y),//left
|
||||
CubeFace::Bottom=>(size.x,size.z),//bottom
|
||||
CubeFace::Front=>(size.x,size.y),//front
|
||||
};
|
||||
(
|
||||
glam::vec4(decal_color3.r,decal_color3.g,decal_color3.b,1.0-*decal_transparency),
|
||||
RobloxTextureTransform{
|
||||
offset_studs_u,
|
||||
offset_studs_v,
|
||||
studs_per_tile_u,
|
||||
studs_per_tile_v,
|
||||
size_u,
|
||||
size_v,
|
||||
}
|
||||
)
|
||||
}else{
|
||||
(glam::Vec4::ONE,RobloxTextureTransform::identity())
|
||||
}
|
||||
}
|
||||
}else{
|
||||
(glam::Vec4::ONE,RobloxTextureTransform::identity())
|
||||
};
|
||||
part_texture_description[cube_face]=Some(RobloxFaceTextureDescription{
|
||||
render:render_id,
|
||||
color:roblox_texture_color,
|
||||
transform:roblox_texture_transform,
|
||||
});
|
||||
}
|
||||
part_texture_description
|
||||
}
|
||||
enum Shape{
|
||||
Primitive(primitives::Primitives),
|
||||
Primitive(Primitives),
|
||||
MeshPart,
|
||||
PhysicsData,
|
||||
}
|
||||
@ -508,12 +547,12 @@ pub fn convert<'a>(
|
||||
Some(rbx_dom_weak::types::Variant::Color3uint8(color3)),
|
||||
Some(rbx_dom_weak::types::Variant::Bool(can_collide)),
|
||||
) = (
|
||||
object.properties.get("CFrame"),
|
||||
object.properties.get("Size"),
|
||||
object.properties.get("Velocity"),
|
||||
object.properties.get("Transparency"),
|
||||
object.properties.get("Color"),
|
||||
object.properties.get("CanCollide"),
|
||||
object.properties.get(&ustr("CFrame")),
|
||||
object.properties.get(&ustr("Size")),
|
||||
object.properties.get(&ustr("Velocity")),
|
||||
object.properties.get(&ustr("Transparency")),
|
||||
object.properties.get(&ustr("Color")),
|
||||
object.properties.get(&ustr("CanCollide")),
|
||||
)
|
||||
{
|
||||
let model_transform=planar64_affine3_from_roblox(cf,size);
|
||||
@ -532,26 +571,19 @@ pub fn convert<'a>(
|
||||
|
||||
//TODO: also detect "CylinderMesh" etc here
|
||||
let shape=match object.class.as_str(){
|
||||
"Part"=>if let Some(rbx_dom_weak::types::Variant::Enum(shape))=object.properties.get("Shape"){
|
||||
Shape::Primitive(match shape.to_u32(){
|
||||
0=>primitives::Primitives::Sphere,
|
||||
1=>primitives::Primitives::Cube,
|
||||
2=>primitives::Primitives::Cylinder,
|
||||
3=>primitives::Primitives::Wedge,
|
||||
4=>primitives::Primitives::CornerWedge,
|
||||
other=>panic!("Funky roblox PartType={};",other),
|
||||
})
|
||||
"Part"=>if let Some(rbx_dom_weak::types::Variant::Enum(shape))=object.properties.get(&ustr("Shape")){
|
||||
Shape::Primitive(shape.to_u32().try_into().expect("Funky roblox PartType"))
|
||||
}else{
|
||||
panic!("Part has no Shape!");
|
||||
},
|
||||
"TrussPart"=>Shape::Primitive(primitives::Primitives::Cube),
|
||||
"WedgePart"=>Shape::Primitive(primitives::Primitives::Wedge),
|
||||
"CornerWedgePart"=>Shape::Primitive(primitives::Primitives::CornerWedge),
|
||||
"TrussPart"=>Shape::Primitive(Primitives::Cube),
|
||||
"WedgePart"=>Shape::Primitive(Primitives::Wedge),
|
||||
"CornerWedgePart"=>Shape::Primitive(Primitives::CornerWedge),
|
||||
"MeshPart"=>Shape::MeshPart,
|
||||
"UnionOperation"=>Shape::PhysicsData,
|
||||
_=>{
|
||||
println!("Unsupported BasePart ClassName={}; defaulting to cube",object.class);
|
||||
Shape::Primitive(primitives::Primitives::Cube)
|
||||
Shape::Primitive(Primitives::Cube)
|
||||
}
|
||||
};
|
||||
|
||||
@ -560,34 +592,34 @@ pub fn convert<'a>(
|
||||
//TODO: TAB TAB
|
||||
let part_texture_description=get_texture_description(&mut temp_objects,render_config_deferred_loader,dom,object,size);
|
||||
//obscure rust syntax "slice pattern"
|
||||
let [
|
||||
let RobloxPartDescription([
|
||||
f0,//Cube::Right
|
||||
f1,//Cube::Top
|
||||
f2,//Cube::Back
|
||||
f3,//Cube::Left
|
||||
f4,//Cube::Bottom
|
||||
f5,//Cube::Front
|
||||
]=part_texture_description;
|
||||
])=part_texture_description;
|
||||
let basepart_description=match primitive_shape{
|
||||
primitives::Primitives::Sphere=>RobloxBasePartDescription::Sphere([f0,f1,f2,f3,f4,f5]),
|
||||
primitives::Primitives::Cube=>RobloxBasePartDescription::Part([f0,f1,f2,f3,f4,f5]),
|
||||
primitives::Primitives::Cylinder=>RobloxBasePartDescription::Cylinder([f0,f1,f2,f3,f4,f5]),
|
||||
Primitives::Sphere=>RobloxBasePartDescription::Sphere(RobloxPartDescription([f0,f1,f2,f3,f4,f5])),
|
||||
Primitives::Cube=>RobloxBasePartDescription::Part(RobloxPartDescription([f0,f1,f2,f3,f4,f5])),
|
||||
Primitives::Cylinder=>RobloxBasePartDescription::Cylinder(RobloxPartDescription([f0,f1,f2,f3,f4,f5])),
|
||||
//use front face texture first and use top face texture as a fallback
|
||||
primitives::Primitives::Wedge=>RobloxBasePartDescription::Wedge([
|
||||
Primitives::Wedge=>RobloxBasePartDescription::Wedge(RobloxWedgeDescription([
|
||||
f0,//Cube::Right->Wedge::Right
|
||||
f5.or(f1),//Cube::Front|Cube::Top->Wedge::TopFront
|
||||
f2,//Cube::Back->Wedge::Back
|
||||
f3,//Cube::Left->Wedge::Left
|
||||
f4,//Cube::Bottom->Wedge::Bottom
|
||||
]),
|
||||
])),
|
||||
//TODO: fix Left+Back texture coordinates to match roblox when not overwridden by Top
|
||||
primitives::Primitives::CornerWedge=>RobloxBasePartDescription::CornerWedge([
|
||||
Primitives::CornerWedge=>RobloxBasePartDescription::CornerWedge(RobloxCornerWedgeDescription([
|
||||
f0,//Cube::Right->CornerWedge::Right
|
||||
f2.or(f1.clone()),//Cube::Back|Cube::Top->CornerWedge::TopBack
|
||||
f3.or(f1),//Cube::Left|Cube::Top->CornerWedge::TopLeft
|
||||
f4,//Cube::Bottom->CornerWedge::Bottom
|
||||
f5,//Cube::Front->CornerWedge::Front
|
||||
]),
|
||||
])),
|
||||
};
|
||||
//make new model if unit cube has not been created before
|
||||
let mesh_id=if let Some(&mesh_id)=mesh_id_from_description.get(&basepart_description){
|
||||
@ -597,66 +629,11 @@ pub fn convert<'a>(
|
||||
let mesh_id=model::MeshId::new(primitive_meshes.len() as u32);
|
||||
mesh_id_from_description.insert(basepart_description.clone(),mesh_id);//borrow checker going crazy
|
||||
let mesh=match basepart_description{
|
||||
RobloxBasePartDescription::Cylinder(part_texture_description)=>primitives::unit_cylinder(CubeFaceDescription::new(part_texture_description,textureless_render_group)),
|
||||
RobloxBasePartDescription::Sphere(part_texture_description)
|
||||
|RobloxBasePartDescription::Cylinder(part_texture_description)
|
||||
|RobloxBasePartDescription::Part(part_texture_description)=>{
|
||||
let mut cube_face_description=primitives::CubeFaceDescription::default();
|
||||
for (face_id,roblox_face_description) in part_texture_description.iter().enumerate(){
|
||||
cube_face_description.insert(
|
||||
match face_id{
|
||||
0=>primitives::CubeFace::Right,
|
||||
1=>primitives::CubeFace::Top,
|
||||
2=>primitives::CubeFace::Back,
|
||||
3=>primitives::CubeFace::Left,
|
||||
4=>primitives::CubeFace::Bottom,
|
||||
5=>primitives::CubeFace::Front,
|
||||
_=>unreachable!(),
|
||||
},
|
||||
match roblox_face_description{
|
||||
Some(roblox_texture_transform)=>roblox_texture_transform.to_face_description(),
|
||||
None=>primitives::FaceDescription::new_with_render_id(textureless_render_group),
|
||||
});
|
||||
}
|
||||
primitives::generate_partial_unit_cube(cube_face_description)
|
||||
},
|
||||
RobloxBasePartDescription::Wedge(wedge_texture_description)=>{
|
||||
let mut wedge_face_description=primitives::WedgeFaceDescription::default();
|
||||
for (face_id,roblox_face_description) in wedge_texture_description.iter().enumerate(){
|
||||
wedge_face_description.insert(
|
||||
match face_id{
|
||||
0=>primitives::WedgeFace::Right,
|
||||
1=>primitives::WedgeFace::TopFront,
|
||||
2=>primitives::WedgeFace::Back,
|
||||
3=>primitives::WedgeFace::Left,
|
||||
4=>primitives::WedgeFace::Bottom,
|
||||
_=>unreachable!(),
|
||||
},
|
||||
match roblox_face_description{
|
||||
Some(roblox_texture_transform)=>roblox_texture_transform.to_face_description(),
|
||||
None=>primitives::FaceDescription::new_with_render_id(textureless_render_group),
|
||||
});
|
||||
}
|
||||
primitives::generate_partial_unit_wedge(wedge_face_description)
|
||||
},
|
||||
RobloxBasePartDescription::CornerWedge(cornerwedge_texture_description)=>{
|
||||
let mut cornerwedge_face_description=primitives::CornerWedgeFaceDescription::default();
|
||||
for (face_id,roblox_face_description) in cornerwedge_texture_description.iter().enumerate(){
|
||||
cornerwedge_face_description.insert(
|
||||
match face_id{
|
||||
0=>primitives::CornerWedgeFace::Right,
|
||||
1=>primitives::CornerWedgeFace::TopBack,
|
||||
2=>primitives::CornerWedgeFace::TopLeft,
|
||||
3=>primitives::CornerWedgeFace::Bottom,
|
||||
4=>primitives::CornerWedgeFace::Front,
|
||||
_=>unreachable!(),
|
||||
},
|
||||
match roblox_face_description{
|
||||
Some(roblox_texture_transform)=>roblox_texture_transform.to_face_description(),
|
||||
None=>primitives::FaceDescription::new_with_render_id(textureless_render_group),
|
||||
});
|
||||
}
|
||||
primitives::generate_partial_unit_cornerwedge(cornerwedge_face_description)
|
||||
},
|
||||
|RobloxBasePartDescription::Part(part_texture_description)=>primitives::unit_cube(CubeFaceDescription::new(part_texture_description,textureless_render_group)),
|
||||
RobloxBasePartDescription::Wedge(wedge_texture_description)=>primitives::unit_wedge(WedgeFaceDescription::new(wedge_texture_description,textureless_render_group)),
|
||||
RobloxBasePartDescription::CornerWedge(cornerwedge_texture_description)=>primitives::unit_cornerwedge(CornerWedgeFaceDescription::new(cornerwedge_texture_description,textureless_render_group)),
|
||||
};
|
||||
primitive_meshes.push(mesh);
|
||||
mesh_id
|
||||
@ -664,15 +641,19 @@ pub fn convert<'a>(
|
||||
(MeshAvailability::Immediate,mesh_id)
|
||||
},
|
||||
Shape::MeshPart=>if let (
|
||||
Some(rbx_dom_weak::types::Variant::Content(mesh_asset_id)),
|
||||
Some(rbx_dom_weak::types::Variant::Content(texture_asset_id)),
|
||||
Some(rbx_dom_weak::types::Variant::Content(mesh_content)),
|
||||
Some(rbx_dom_weak::types::Variant::Content(texture_content)),
|
||||
)=(
|
||||
object.properties.get("MeshId"),
|
||||
object.properties.get("TextureID"),
|
||||
// mesh must exist
|
||||
object.properties.get(&ustr("MeshContent")),
|
||||
// texture is allowed to be none
|
||||
object.properties.get(&ustr("TextureContent")),
|
||||
){
|
||||
let mesh_asset_id=get_content_url(mesh_content).expect("MeshPart Mesh is not a Uri");
|
||||
let texture_asset_id=get_content_url(texture_content);
|
||||
(
|
||||
MeshAvailability::DeferredMesh(render_config_deferred_loader.acquire_render_config_id(Some(texture_asset_id.as_ref()))),
|
||||
mesh_deferred_loader.acquire_mesh_id(MeshIndex::file_mesh(mesh_asset_id.as_ref())),
|
||||
MeshAvailability::DeferredMesh(render_config_deferred_loader.acquire_render_config_id(texture_asset_id)),
|
||||
mesh_deferred_loader.acquire_mesh_id(MeshIndex::file_mesh(mesh_asset_id)),
|
||||
)
|
||||
}else{
|
||||
panic!("Mesh has no Mesh or Texture");
|
||||
@ -681,13 +662,13 @@ pub fn convert<'a>(
|
||||
let mut content="";
|
||||
let mut mesh_data:&[u8]=&[];
|
||||
let mut physics_data:&[u8]=&[];
|
||||
if let Some(rbx_dom_weak::types::Variant::Content(asset_id))=object.properties.get("AssetId"){
|
||||
if let Some(rbx_dom_weak::types::Variant::ContentId(asset_id))=object.properties.get(&ustr("AssetId")){
|
||||
content=asset_id.as_ref();
|
||||
}
|
||||
if let Some(rbx_dom_weak::types::Variant::BinaryString(data))=object.properties.get("MeshData"){
|
||||
if let Some(rbx_dom_weak::types::Variant::BinaryString(data))=object.properties.get(&ustr("MeshData")){
|
||||
mesh_data=data.as_ref();
|
||||
}
|
||||
if let Some(rbx_dom_weak::types::Variant::BinaryString(data))=object.properties.get("PhysicsData"){
|
||||
if let Some(rbx_dom_weak::types::Variant::BinaryString(data))=object.properties.get(&ustr("PhysicsData")){
|
||||
physics_data=data.as_ref();
|
||||
}
|
||||
let part_texture_description=get_texture_description(&mut temp_objects,render_config_deferred_loader,dom,object,size);
|
||||
@ -768,7 +749,7 @@ fn acquire_union_id_from_render_config_id<'a>(
|
||||
let union_id=model::MeshId::new(primitive_meshes.len() as u32);
|
||||
let mut union_clone=union_with_aabb.mesh.clone();
|
||||
//set the render groups
|
||||
for (graphics_group,maybe_face_texture_description) in union_clone.graphics_groups.iter_mut().zip(part_texture_description){
|
||||
for (graphics_group,maybe_face_texture_description) in union_clone.graphics_groups.iter_mut().zip(part_texture_description.0){
|
||||
if let Some(face_texture_description)=maybe_face_texture_description{
|
||||
graphics_group.render=face_texture_description.render;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use rbx_mesh::mesh_data::NormalId2 as MeshDataNormalId2;
|
||||
use rbx_mesh::mesh_data::{NormalId2 as MeshDataNormalId2,VertexId as MeshDataVertexId};
|
||||
use rbx_mesh::physics_data::VertexId as PhysicsDataVertexId;
|
||||
use strafesnet_common::model::{self,IndexedVertex,PolygonGroup,PolygonGroupId,PolygonList,RenderConfigId};
|
||||
use strafesnet_common::integer::vec3;
|
||||
|
||||
@ -56,7 +57,7 @@ pub fn convert(
|
||||
roblox_physics_data:&[u8],
|
||||
roblox_mesh_data:&[u8],
|
||||
size:glam::Vec3,
|
||||
part_texture_description:crate::rbx::RobloxPartDescription,
|
||||
crate::rbx::RobloxPartDescription(part_texture_description):crate::rbx::RobloxPartDescription,
|
||||
)->Result<model::Mesh,Error>{
|
||||
const NORMAL_FACES:usize=6;
|
||||
let mut polygon_groups_normal_id=vec![Vec::new();NORMAL_FACES];
|
||||
@ -79,11 +80,11 @@ pub fn convert(
|
||||
rbx_mesh::mesh_data::MeshData::CSGMDL(rbx_mesh::mesh_data::CSGMDL::CSGMDL2(mesh_data2))=>mesh_data2.mesh,
|
||||
rbx_mesh::mesh_data::MeshData::CSGMDL(rbx_mesh::mesh_data::CSGMDL::CSGMDL4(mesh_data4))=>mesh_data4.mesh,
|
||||
};
|
||||
for [vertex_id0,vertex_id1,vertex_id2] in graphics_mesh.faces{
|
||||
for [MeshDataVertexId(vertex_id0),MeshDataVertexId(vertex_id1),MeshDataVertexId(vertex_id2)] in graphics_mesh.faces{
|
||||
let face=[
|
||||
graphics_mesh.vertices.get(vertex_id0.0 as usize).ok_or(Error::MissingVertexId(vertex_id0.0))?,
|
||||
graphics_mesh.vertices.get(vertex_id1.0 as usize).ok_or(Error::MissingVertexId(vertex_id1.0))?,
|
||||
graphics_mesh.vertices.get(vertex_id2.0 as usize).ok_or(Error::MissingVertexId(vertex_id2.0))?,
|
||||
graphics_mesh.vertices.get(vertex_id0 as usize).ok_or(Error::MissingVertexId(vertex_id0))?,
|
||||
graphics_mesh.vertices.get(vertex_id1 as usize).ok_or(Error::MissingVertexId(vertex_id1))?,
|
||||
graphics_mesh.vertices.get(vertex_id2 as usize).ok_or(Error::MissingVertexId(vertex_id2))?,
|
||||
];
|
||||
let mut normal_agreement_checker=MeshDataNormalChecker::new();
|
||||
let face=face.into_iter().map(|vertex|{
|
||||
@ -151,11 +152,11 @@ pub fn convert(
|
||||
let color=mb.acquire_color_id(glam::Vec4::ONE);
|
||||
let tex=mb.acquire_tex_id(glam::Vec2::ZERO);
|
||||
// physics polygon groups (to do physics)
|
||||
Ok(PolygonGroup::PolygonList(PolygonList::new(mesh.faces.into_iter().map(|[vertex_id0,vertex_id1,vertex_id2]|{
|
||||
Ok(PolygonGroup::PolygonList(PolygonList::new(mesh.faces.into_iter().map(|[PhysicsDataVertexId(vertex_id0),PhysicsDataVertexId(vertex_id1),PhysicsDataVertexId(vertex_id2)]|{
|
||||
let face=[
|
||||
mesh.vertices.get(vertex_id0.0 as usize).ok_or(Error::MissingVertexId(vertex_id0.0))?,
|
||||
mesh.vertices.get(vertex_id1.0 as usize).ok_or(Error::MissingVertexId(vertex_id1.0))?,
|
||||
mesh.vertices.get(vertex_id2.0 as usize).ok_or(Error::MissingVertexId(vertex_id2.0))?,
|
||||
mesh.vertices.get(vertex_id0 as usize).ok_or(Error::MissingVertexId(vertex_id0))?,
|
||||
mesh.vertices.get(vertex_id1 as usize).ok_or(Error::MissingVertexId(vertex_id1))?,
|
||||
mesh.vertices.get(vertex_id2 as usize).ok_or(Error::MissingVertexId(vertex_id2))?,
|
||||
].map(|v|glam::Vec3::from_slice(v)/size);
|
||||
let vertex_norm=(face[1]-face[0])
|
||||
.cross(face[2]-face[0]);
|
||||
|
@ -15,7 +15,7 @@ run-service=[]
|
||||
glam = "0.30.0"
|
||||
mlua = { version = "0.10.1", features = ["luau"] }
|
||||
phf = { version = "0.11.2", features = ["macros"] }
|
||||
rbx_dom_weak = { version = "2.7.0", registry = "strafesnet" }
|
||||
rbx_reflection = { version = "4.7.0", registry = "strafesnet" }
|
||||
rbx_reflection_database = { version = "0.2.10", registry = "strafesnet" }
|
||||
rbx_types = { version = "1.10.0", registry = "strafesnet" }
|
||||
rbx_dom_weak = { version = "3.1.0-sn1", registry = "strafesnet", features = ["instance-userdata"] }
|
||||
rbx_reflection = "5.0.0"
|
||||
rbx_reflection_database = "1.0.0"
|
||||
rbx_types = "2.0.0"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use rbx_dom_weak::{types::Ref,InstanceBuilder,WeakDom};
|
||||
use rbx_dom_weak::{types::Ref,ustr,InstanceBuilder,WeakDom};
|
||||
|
||||
pub fn class_is_a(class:&str,superclass:&str)->bool{
|
||||
class==superclass
|
||||
@ -70,8 +70,8 @@ impl Context{
|
||||
{
|
||||
//Lowercase and upper case workspace property!
|
||||
let game=self.dom.root_mut();
|
||||
game.properties.insert("workspace".to_owned(),rbx_types::Variant::Ref(workspace));
|
||||
game.properties.insert("Workspace".to_owned(),rbx_types::Variant::Ref(workspace));
|
||||
game.properties.insert(ustr("workspace"),rbx_types::Variant::Ref(workspace));
|
||||
game.properties.insert(ustr("Workspace"),rbx_types::Variant::Ref(workspace));
|
||||
}
|
||||
self.dom.insert(game,InstanceBuilder::new("Lighting"));
|
||||
|
||||
|
@ -2,14 +2,13 @@ use std::collections::{hash_map::Entry,HashMap};
|
||||
|
||||
use mlua::{FromLua,FromLuaMulti,IntoLua,IntoLuaMulti};
|
||||
use rbx_types::Ref;
|
||||
use rbx_dom_weak::{InstanceBuilder,WeakDom};
|
||||
use rbx_dom_weak::{ustr,Ustr,InstanceBuilder,WeakDom};
|
||||
|
||||
use crate::runner::vector3::Vector3;
|
||||
|
||||
pub fn set_globals(lua:&mlua::Lua,globals:&mlua::Table)->Result<(),mlua::Error>{
|
||||
//class functions store
|
||||
lua.set_app_data(ClassMethodsStore::default());
|
||||
lua.set_app_data(InstanceValueStore::default());
|
||||
|
||||
let instance_table=lua.create_table()?;
|
||||
|
||||
@ -58,7 +57,7 @@ fn get_full_name(dom:&rbx_dom_weak::WeakDom,instance:&rbx_dom_weak::Instance)->S
|
||||
pub fn get_name_source(lua:&mlua::Lua,script:Instance)->Result<(String,String),mlua::Error>{
|
||||
dom_mut(lua,|dom|{
|
||||
let instance=script.get(dom)?;
|
||||
let source=match instance.properties.get("Source"){
|
||||
let source=match instance.properties.get(&ustr("Source")){
|
||||
Some(rbx_dom_weak::types::Variant::String(s))=>s.clone(),
|
||||
_=>Err(mlua::Error::external("Missing script.Source"))?,
|
||||
};
|
||||
@ -97,25 +96,6 @@ impl Instance{
|
||||
}
|
||||
type_from_lua_userdata!(Instance);
|
||||
|
||||
//TODO: update rbx_reflection and use dom.superclasses_iter
|
||||
pub struct SuperClassIter<'a> {
|
||||
database: &'a rbx_reflection::ReflectionDatabase<'a>,
|
||||
descriptor: Option<&'a rbx_reflection::ClassDescriptor<'a>>,
|
||||
}
|
||||
impl<'a> SuperClassIter<'a> {
|
||||
fn next_descriptor(&self) -> Option<&'a rbx_reflection::ClassDescriptor<'a>> {
|
||||
let superclass = self.descriptor?.superclass.as_ref()?;
|
||||
self.database.classes.get(superclass)
|
||||
}
|
||||
}
|
||||
impl<'a> Iterator for SuperClassIter<'a> {
|
||||
type Item = &'a rbx_reflection::ClassDescriptor<'a>;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let next_descriptor = self.next_descriptor();
|
||||
std::mem::replace(&mut self.descriptor, next_descriptor)
|
||||
}
|
||||
}
|
||||
|
||||
impl mlua::UserData for Instance{
|
||||
fn add_fields<F:mlua::UserDataFields<Self>>(fields:&mut F){
|
||||
fields.add_field_method_get("Parent",|lua,this|{
|
||||
@ -148,7 +128,7 @@ impl mlua::UserData for Instance{
|
||||
fields.add_field_method_get("ClassName",|lua,this|{
|
||||
dom_mut(lua,|dom|{
|
||||
let instance=this.get(dom)?;
|
||||
Ok(instance.class.clone())
|
||||
Ok(instance.class.to_owned())
|
||||
})
|
||||
});
|
||||
}
|
||||
@ -227,26 +207,21 @@ impl mlua::UserData for Instance{
|
||||
});
|
||||
methods.add_meta_function(mlua::MetaMethod::Index,|lua,(this,index):(Instance,mlua::String)|{
|
||||
let index_str=&*index.to_str()?;
|
||||
let index_ustr=ustr(index_str);
|
||||
dom_mut(lua,|dom|{
|
||||
let instance=this.get(dom)?;
|
||||
//println!("__index t={} i={index:?}",instance.name);
|
||||
let db=rbx_reflection_database::get();
|
||||
let class=db.classes.get(instance.class.as_str()).ok_or_else(||mlua::Error::runtime("Class missing"))?;
|
||||
//Find existing property
|
||||
match instance.properties.get(index_str)
|
||||
match instance.properties.get(&index_ustr)
|
||||
.cloned()
|
||||
//Find default value
|
||||
.or_else(||db.find_default_property(class,index_str).cloned())
|
||||
//Find virtual property
|
||||
.or_else(||{
|
||||
SuperClassIter{
|
||||
database:db,
|
||||
descriptor:Some(class),
|
||||
}
|
||||
.find_map(|class|
|
||||
find_virtual_property(&instance.properties,class,index_str)
|
||||
)
|
||||
})
|
||||
.or_else(||db.superclasses_iter(class).find_map(|class|
|
||||
find_virtual_property(&instance.properties,class,&index_ustr)
|
||||
))
|
||||
{
|
||||
Some(rbx_types::Variant::Int32(val))=>return val.into_lua(lua),
|
||||
Some(rbx_types::Variant::Int64(val))=>return val.into_lua(lua),
|
||||
@ -260,11 +235,7 @@ impl mlua::UserData for Instance{
|
||||
}
|
||||
//find a function with a matching name
|
||||
if let Some(function)=class_methods_store_mut(lua,|cf|{
|
||||
let mut iter=SuperClassIter{
|
||||
database:db,
|
||||
descriptor:Some(class),
|
||||
};
|
||||
iter.find_map(|class|{
|
||||
db.superclasses_iter(class).find_map(|class|{
|
||||
let mut class_methods=cf.get_or_create_class_methods(&class.name)?;
|
||||
class_methods.get_or_create_function(lua,index_str)
|
||||
.transpose()
|
||||
@ -274,16 +245,13 @@ impl mlua::UserData for Instance{
|
||||
}
|
||||
|
||||
//find or create an associated userdata object
|
||||
if let Some(value)=instance_value_store_mut(lua,|ivs|{
|
||||
//TODO: walk class tree somehow
|
||||
match ivs.get_or_create_instance_values(&instance){
|
||||
Some(mut instance_values)=>instance_values.get_or_create_value(lua,index_str),
|
||||
None=>Ok(None)
|
||||
}
|
||||
})?{
|
||||
let instance=this.get_mut(dom)?;
|
||||
if let Some(value)=get_or_create_userdata(instance,lua,index_ustr)?{
|
||||
return value.into_lua(lua);
|
||||
}
|
||||
// drop mutable borrow
|
||||
//find a child with a matching name
|
||||
let instance=this.get(dom)?;
|
||||
find_first_child(dom,instance,index_str)
|
||||
.map(|instance|Instance::new(instance.referent()))
|
||||
.into_lua(lua)
|
||||
@ -294,21 +262,22 @@ impl mlua::UserData for Instance{
|
||||
let instance=this.get_mut(dom)?;
|
||||
//println!("__newindex t={} i={index:?} v={value:?}",instance.name);
|
||||
let index_str=&*index.to_str()?;
|
||||
let index_ustr=ustr(index_str);
|
||||
let db=rbx_reflection_database::get();
|
||||
let class=db.classes.get(instance.class.as_str()).ok_or_else(||mlua::Error::runtime("Class missing"))?;
|
||||
let mut iter=SuperClassIter{
|
||||
database:db,
|
||||
descriptor:Some(class),
|
||||
};
|
||||
let property=iter.find_map(|cls|cls.properties.get(index_str)).ok_or_else(||mlua::Error::runtime(format!("Property '{index_str}' missing on class '{}'",class.name)))?;
|
||||
let property=db.superclasses_iter(class).find_map(|cls|
|
||||
cls.properties.get(index_str)
|
||||
).ok_or_else(||
|
||||
mlua::Error::runtime(format!("Property '{index_str}' missing on class '{}'",class.name))
|
||||
)?;
|
||||
match &property.data_type{
|
||||
rbx_reflection::DataType::Value(rbx_types::VariantType::Vector3)=>{
|
||||
let typed_value:Vector3=*value.as_userdata().ok_or_else(||mlua::Error::runtime("Expected Userdata"))?.borrow()?;
|
||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Vector3(typed_value.into()));
|
||||
instance.properties.insert(index_ustr,rbx_types::Variant::Vector3(typed_value.into()));
|
||||
},
|
||||
rbx_reflection::DataType::Value(rbx_types::VariantType::Float32)=>{
|
||||
let typed_value:f32=coerce_float32(&value).ok_or_else(||mlua::Error::runtime("Expected f32"))?;
|
||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Float32(typed_value));
|
||||
instance.properties.insert(index_ustr,rbx_types::Variant::Float32(typed_value));
|
||||
},
|
||||
rbx_reflection::DataType::Enum(enum_name)=>{
|
||||
let typed_value=match &value{
|
||||
@ -324,27 +293,27 @@ impl mlua::UserData for Instance{
|
||||
},
|
||||
_=>Err(mlua::Error::runtime("Expected Enum")),
|
||||
}?;
|
||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Enum(typed_value));
|
||||
instance.properties.insert(index_ustr,rbx_types::Variant::Enum(typed_value));
|
||||
},
|
||||
rbx_reflection::DataType::Value(rbx_types::VariantType::Color3)=>{
|
||||
let typed_value:crate::runner::color3::Color3=*value.as_userdata().ok_or_else(||mlua::Error::runtime("Expected Color3"))?.borrow()?;
|
||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Color3(typed_value.into()));
|
||||
instance.properties.insert(index_ustr,rbx_types::Variant::Color3(typed_value.into()));
|
||||
},
|
||||
rbx_reflection::DataType::Value(rbx_types::VariantType::Bool)=>{
|
||||
let typed_value=value.as_boolean().ok_or_else(||mlua::Error::runtime("Expected boolean"))?;
|
||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::Bool(typed_value));
|
||||
instance.properties.insert(index_ustr,rbx_types::Variant::Bool(typed_value));
|
||||
},
|
||||
rbx_reflection::DataType::Value(rbx_types::VariantType::String)=>{
|
||||
let typed_value=value.as_str().ok_or_else(||mlua::Error::runtime("Expected boolean"))?;
|
||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::String(typed_value.to_owned()));
|
||||
instance.properties.insert(index_ustr,rbx_types::Variant::String(typed_value.to_owned()));
|
||||
},
|
||||
rbx_reflection::DataType::Value(rbx_types::VariantType::NumberSequence)=>{
|
||||
let typed_value:crate::runner::number_sequence::NumberSequence=*value.as_userdata().ok_or_else(||mlua::Error::runtime("Expected NumberSequence"))?.borrow()?;
|
||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::NumberSequence(typed_value.into()));
|
||||
instance.properties.insert(index_ustr,rbx_types::Variant::NumberSequence(typed_value.into()));
|
||||
},
|
||||
rbx_reflection::DataType::Value(rbx_types::VariantType::ColorSequence)=>{
|
||||
let typed_value:crate::runner::color_sequence::ColorSequence=*value.as_userdata().ok_or_else(||mlua::Error::runtime("Expected ColorSequence"))?.borrow()?;
|
||||
instance.properties.insert(index_str.to_owned(),rbx_types::Variant::ColorSequence(typed_value.into()));
|
||||
instance.properties.insert(index_ustr,rbx_types::Variant::ColorSequence(typed_value.into()));
|
||||
},
|
||||
other=>return Err(mlua::Error::runtime(format!("Unimplemented property type: {other:?}"))),
|
||||
}
|
||||
@ -480,24 +449,22 @@ static VIRTUAL_PROPERTY_DATABASE:VPD=phf::phf_map!{
|
||||
};
|
||||
|
||||
fn find_virtual_property(
|
||||
properties:&HashMap<String,rbx_types::Variant>,
|
||||
properties:&rbx_dom_weak::UstrMap<rbx_types::Variant>,
|
||||
class:&rbx_reflection::ClassDescriptor,
|
||||
index:&str
|
||||
index:&Ustr,
|
||||
)->Option<rbx_types::Variant>{
|
||||
//Find virtual property
|
||||
let class_virtual_properties=VIRTUAL_PROPERTY_DATABASE.get(&class.name)?;
|
||||
let virtual_property=class_virtual_properties.get(index)?;
|
||||
|
||||
//Get source property
|
||||
let variant=properties.get(virtual_property.property)?;
|
||||
let variant=properties.get(&ustr(virtual_property.property))?;
|
||||
|
||||
//Transform Source property with provided function
|
||||
(virtual_property.pointer)(variant)
|
||||
}
|
||||
|
||||
// lazy-loaded per-instance userdata values
|
||||
// This whole thing is a bad idea and a garbage collection nightmare.
|
||||
// TODO: recreate rbx_dom_weak with my own instance type that owns this data.
|
||||
type CreateUserData=fn(&mlua::Lua)->mlua::Result<mlua::AnyUserData>;
|
||||
type LUD=phf::Map<&'static str,// Class name
|
||||
phf::Map<&'static str,// Value name
|
||||
@ -506,52 +473,19 @@ type LUD=phf::Map<&'static str,// Class name
|
||||
>;
|
||||
static LAZY_USER_DATA:LUD=phf::phf_map!{
|
||||
"RunService"=>phf::phf_map!{
|
||||
"RenderStepped"=>|lua|{
|
||||
lua.create_any_userdata(crate::runner::script_signal::ScriptSignal::new())
|
||||
},
|
||||
"RenderStepped"=>|lua|lua.create_any_userdata(crate::runner::script_signal::ScriptSignal::new()),
|
||||
},
|
||||
};
|
||||
#[derive(Default)]
|
||||
pub struct InstanceValueStore{
|
||||
values:HashMap<Ref,
|
||||
HashMap<&'static str,
|
||||
mlua::AnyUserData
|
||||
>
|
||||
>,
|
||||
}
|
||||
pub struct InstanceValues<'a>{
|
||||
named_values:&'static phf::Map<&'static str,CreateUserData>,
|
||||
values:&'a mut HashMap<&'static str,mlua::AnyUserData>,
|
||||
}
|
||||
impl InstanceValueStore{
|
||||
pub fn get_or_create_instance_values(&mut self,instance:&rbx_dom_weak::Instance)->Option<InstanceValues>{
|
||||
LAZY_USER_DATA.get(instance.class.as_str())
|
||||
.map(|named_values|
|
||||
InstanceValues{
|
||||
named_values,
|
||||
values:self.values.entry(instance.referent())
|
||||
.or_insert_with(||HashMap::new()),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
impl InstanceValues<'_>{
|
||||
pub fn get_or_create_value(&mut self,lua:&mlua::Lua,index:&str)->mlua::Result<Option<mlua::AnyUserData>>{
|
||||
Ok(match self.named_values.get_entry(index){
|
||||
Some((&static_index_str,&function_pointer))=>Some(
|
||||
match self.values.entry(static_index_str){
|
||||
Entry::Occupied(entry)=>entry.get().clone(),
|
||||
Entry::Vacant(entry)=>entry.insert(
|
||||
function_pointer(lua)?
|
||||
).clone(),
|
||||
}
|
||||
),
|
||||
None=>None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn instance_value_store_mut<T>(lua:&mlua::Lua,mut f:impl FnMut(&mut InstanceValueStore)->mlua::Result<T>)->mlua::Result<T>{
|
||||
let mut cf=lua.app_data_mut::<InstanceValueStore>().ok_or_else(||mlua::Error::runtime("InstanceValueStore missing"))?;
|
||||
f(&mut *cf)
|
||||
fn get_or_create_userdata(instance:&mut rbx_dom_weak::Instance,lua:&mlua::Lua,index:rbx_dom_weak::Ustr)->mlua::Result<Option<mlua::AnyUserData>>{
|
||||
use std::collections::hash_map::Entry;
|
||||
Ok(match LAZY_USER_DATA.get(instance.class.as_str()){
|
||||
Some(userdata_map)=>match instance.userdata.entry(index){
|
||||
Entry::Occupied(entry)=>Some(entry.get().clone()),
|
||||
Entry::Vacant(entry)=>match userdata_map.get(index.as_str()){
|
||||
Some(create_userdata)=>Some(entry.insert(create_userdata(lua)?).clone()),
|
||||
None=>None,
|
||||
},
|
||||
},
|
||||
None=>None,
|
||||
})
|
||||
}
|
||||
|
@ -123,20 +123,15 @@ impl Runnable<'_>{
|
||||
}
|
||||
#[cfg(feature="run-service")]
|
||||
pub fn run_service_step(&self)->Result<(),mlua::Error>{
|
||||
let render_stepped=super::instance::instance::dom_mut(&self.lua,|dom|{
|
||||
let render_stepped_signal=super::instance::instance::dom_mut(&self.lua,|dom|{
|
||||
let run_service=super::instance::instance::find_first_child_of_class(dom,dom.root(),"RunService").ok_or_else(||mlua::Error::runtime("RunService missing"))?;
|
||||
super::instance::instance::instance_value_store_mut(&self.lua,|instance_value_store|{
|
||||
//unwrap because I trust my find_first_child_of_class function to
|
||||
let mut instance_values=instance_value_store.get_or_create_instance_values(run_service).ok_or_else(||mlua::Error::runtime("RunService InstanceValues missing"))?;
|
||||
let render_stepped=instance_values.get_or_create_value(&self.lua,"RenderStepped")?;
|
||||
//let stepped=instance_values.get_or_create_value(&self.lua,"Stepped")?;
|
||||
//let heartbeat=instance_values.get_or_create_value(&self.lua,"Heartbeat")?;
|
||||
Ok(render_stepped)
|
||||
Ok(match run_service.userdata.get(&rbx_dom_weak::ustr("RenderStepped")){
|
||||
Some(render_stepped)=>Some(render_stepped.borrow::<super::script_signal::ScriptSignal>()?.clone()),
|
||||
None=>None
|
||||
})
|
||||
})?;
|
||||
if let Some(render_stepped)=render_stepped{
|
||||
let signal:&super::script_signal::ScriptSignal=&*render_stepped.borrow()?;
|
||||
signal.fire(&mlua::MultiValue::new());
|
||||
if let Some(render_stepped_signal)=render_stepped_signal{
|
||||
render_stepped_signal.fire(&mlua::MultiValue::new());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -13,11 +13,11 @@ futures = "0.3.31"
|
||||
image = "0.25.2"
|
||||
image_dds = "0.7.1"
|
||||
lazy-regex = "3.1.0"
|
||||
rbx_asset = { version = "0.2.5", registry = "strafesnet" }
|
||||
rbx_binary = { version = "0.7.4", registry = "strafesnet" }
|
||||
rbx_dom_weak = { version = "2.7.0", registry = "strafesnet" }
|
||||
rbx_reflection_database = { version = "0.2.10", registry = "strafesnet" }
|
||||
rbx_xml = { version = "0.13.3", registry = "strafesnet" }
|
||||
rbx_asset = { version = "0.4.4", registry = "strafesnet" }
|
||||
rbx_binary = { version = "1.1.0-sn4", registry = "strafesnet" }
|
||||
rbx_dom_weak = { version = "3.1.0-sn2", registry = "strafesnet" }
|
||||
rbx_reflection_database = "1.0.0"
|
||||
rbx_xml = { version = "1.1.0-sn4", registry = "strafesnet" }
|
||||
rbxassetid = { version = "0.1.0", registry = "strafesnet" }
|
||||
strafesnet_bsp_loader = { version = "0.3.0", path = "../lib/bsp_loader", registry = "strafesnet" }
|
||||
strafesnet_deferred_loader = { version = "0.5.0", path = "../lib/deferred_loader", registry = "strafesnet" }
|
||||
|
@ -3,7 +3,7 @@ use std::io::{Cursor,Read,Seek};
|
||||
use std::collections::HashSet;
|
||||
use clap::{Args,Subcommand};
|
||||
use anyhow::Result as AResult;
|
||||
use rbx_dom_weak::Instance;
|
||||
use rbx_dom_weak::{ustr,Instance};
|
||||
use strafesnet_deferred_loader::deferred_loader::LoadFailureMode;
|
||||
use rbxassetid::RobloxAssetId;
|
||||
use tokio::io::AsyncReadExt;
|
||||
@ -88,17 +88,45 @@ SurfaceAppearance.NormalMap
|
||||
SurfaceAppearance.RoughnessMap
|
||||
SurfaceAppearance.TexturePack
|
||||
*/
|
||||
fn accumulate_content_id(content_list:&mut HashSet<RobloxAssetId>,object:&Instance,property:&str){
|
||||
if let Some(rbx_dom_weak::types::Variant::Content(content))=object.properties.get(property){
|
||||
let url:&str=content.as_ref();
|
||||
if let Ok(asset_id)=url.parse(){
|
||||
content_list.insert(asset_id);
|
||||
}else{
|
||||
println!("Content failed to parse into AssetID: {:?}",content);
|
||||
}
|
||||
}else{
|
||||
/* These properties now use Content
|
||||
BaseWrap.CageMeshContent
|
||||
Decal.TextureContent
|
||||
ImageButton.ImageContent
|
||||
ImageLabel.ImageContent
|
||||
MeshPart.MeshContent
|
||||
MeshPart.TextureContent
|
||||
SurfaceAppearance.ColorMapContent
|
||||
SurfaceAppearance.MetalnessMapContent
|
||||
SurfaceAppearance.NormalMapContent
|
||||
SurfaceAppearance.RoughnessMapContent
|
||||
WrapLayer.ReferenceMeshContent
|
||||
*/
|
||||
|
||||
fn accumulate_content(content_list:&mut HashSet<RobloxAssetId>,object:&Instance,property:&str){
|
||||
let Some(rbx_dom_weak::types::Variant::Content(content))=object.properties.get(&ustr(property))else{
|
||||
println!("property={} does not exist for class={}",property,object.class.as_str());
|
||||
}
|
||||
return;
|
||||
};
|
||||
let rbx_dom_weak::types::ContentType::Uri(uri)=content.value()else{
|
||||
println!("ContentType is not Uri");
|
||||
return;
|
||||
};
|
||||
let Ok(asset_id)=uri.parse()else{
|
||||
println!("Content failed to parse into AssetID: {:?}",content);
|
||||
return;
|
||||
};
|
||||
content_list.insert(asset_id);
|
||||
}
|
||||
fn accumulate_content_id(content_list:&mut HashSet<RobloxAssetId>,object:&Instance,property:&str){
|
||||
let Some(rbx_dom_weak::types::Variant::ContentId(content))=object.properties.get(&ustr(property))else{
|
||||
println!("property={} does not exist for class={}",property,object.class.as_str());
|
||||
return;
|
||||
};
|
||||
let Ok(asset_id)=content.as_str().parse()else{
|
||||
println!("Content failed to parse into AssetID: {:?}",content);
|
||||
return;
|
||||
};
|
||||
content_list.insert(asset_id);
|
||||
}
|
||||
async fn read_entire_file(path:impl AsRef<Path>)->Result<Cursor<Vec<u8>>,std::io::Error>{
|
||||
let mut file=tokio::fs::File::open(path).await?;
|
||||
@ -120,8 +148,8 @@ impl UniqueAssets{
|
||||
"Texture"=>accumulate_content_id(&mut self.textures,object,"Texture"),
|
||||
"FileMesh"=>accumulate_content_id(&mut self.textures,object,"TextureId"),
|
||||
"MeshPart"=>{
|
||||
accumulate_content_id(&mut self.textures,object,"TextureID");
|
||||
accumulate_content_id(&mut self.meshes,object,"MeshId");
|
||||
accumulate_content(&mut self.textures,object,"TextureContent");
|
||||
accumulate_content(&mut self.meshes,object,"MeshContent");
|
||||
},
|
||||
"SpecialMesh"=>accumulate_content_id(&mut self.meshes,object,"MeshId"),
|
||||
"ParticleEmitter"=>accumulate_content_id(&mut self.textures,object,"Texture"),
|
||||
@ -165,16 +193,16 @@ enum DownloadType{
|
||||
impl DownloadType{
|
||||
fn path(&self)->PathBuf{
|
||||
match self{
|
||||
DownloadType::Texture(asset_id)=>format!("downloaded_textures/{}",asset_id.0.to_string()).into(),
|
||||
DownloadType::Mesh(asset_id)=>format!("meshes/{}",asset_id.0.to_string()).into(),
|
||||
DownloadType::Union(asset_id)=>format!("unions/{}",asset_id.0.to_string()).into(),
|
||||
DownloadType::Texture(RobloxAssetId(asset_id))=>format!("downloaded_textures/{asset_id}").into(),
|
||||
DownloadType::Mesh(RobloxAssetId(asset_id))=>format!("meshes/{asset_id}").into(),
|
||||
DownloadType::Union(RobloxAssetId(asset_id))=>format!("unions/{asset_id}").into(),
|
||||
}
|
||||
}
|
||||
fn asset_id(&self)->u64{
|
||||
match self{
|
||||
DownloadType::Texture(asset_id)=>asset_id.0,
|
||||
DownloadType::Mesh(asset_id)=>asset_id.0,
|
||||
DownloadType::Union(asset_id)=>asset_id.0,
|
||||
&DownloadType::Texture(RobloxAssetId(asset_id))=>asset_id,
|
||||
&DownloadType::Mesh(RobloxAssetId(asset_id))=>asset_id,
|
||||
&DownloadType::Union(RobloxAssetId(asset_id))=>asset_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -191,9 +219,8 @@ struct Stats{
|
||||
failed_downloads:u32,
|
||||
timed_out_downloads:u32,
|
||||
}
|
||||
async fn download_retry(stats:&mut Stats,context:&rbx_asset::cookie::CookieContext,download_instruction:DownloadType)->Result<DownloadResult,std::io::Error>{
|
||||
async fn download_retry(stats:&mut Stats,context:&rbx_asset::cookie::Context,download_instruction:DownloadType)->Result<DownloadResult,std::io::Error>{
|
||||
stats.total_assets+=1;
|
||||
let download_instruction=download_instruction;
|
||||
// check if file exists on disk
|
||||
let path=download_instruction.path();
|
||||
if tokio::fs::try_exists(path.as_path()).await?{
|
||||
@ -213,10 +240,11 @@ async fn download_retry(stats:&mut Stats,context:&rbx_asset::cookie::CookieConte
|
||||
match asset_result{
|
||||
Ok(asset_result)=>{
|
||||
stats.downloaded_assets+=1;
|
||||
tokio::fs::write(path,&asset_result).await?;
|
||||
break Ok(DownloadResult::Data(asset_result));
|
||||
let data=asset_result.to_vec()?;
|
||||
tokio::fs::write(path,&data).await?;
|
||||
break Ok(DownloadResult::Data(data));
|
||||
},
|
||||
Err(rbx_asset::cookie::GetError::Response(rbx_asset::ResponseError::StatusCodeWithUrlAndBody(scwuab)))=>{
|
||||
Err(rbx_asset::cookie::GetError::Response(rbx_asset::types::ResponseError::StatusCodeWithUrlAndBody(scwuab)))=>{
|
||||
if scwuab.status_code.as_u16()==429{
|
||||
if retry==12{
|
||||
println!("Giving up asset download {asset_id}");
|
||||
@ -252,7 +280,7 @@ enum ConvertTextureError{
|
||||
#[error("DDS write error {0:?}")]
|
||||
DDSWrite(#[from]image_dds::ddsfile::Error),
|
||||
}
|
||||
async fn convert_texture(asset_id:RobloxAssetId,download_result:DownloadResult)->Result<(),ConvertTextureError>{
|
||||
async fn convert_texture(RobloxAssetId(asset_id):RobloxAssetId,download_result:DownloadResult)->Result<(),ConvertTextureError>{
|
||||
let data=match download_result{
|
||||
DownloadResult::Cached(path)=>tokio::fs::read(path).await?,
|
||||
DownloadResult::Data(data)=>data,
|
||||
@ -277,7 +305,7 @@ async fn convert_texture(asset_id:RobloxAssetId,download_result:DownloadResult)-
|
||||
image_dds::Mipmaps::GeneratedAutomatic,
|
||||
)?;
|
||||
|
||||
let file_name=format!("textures/{}.dds",asset_id.0);
|
||||
let file_name=format!("textures/{asset_id}.dds");
|
||||
let mut file=std::fs::File::create(file_name)?;
|
||||
dds.write(&mut file)?;
|
||||
Ok(())
|
||||
@ -315,7 +343,7 @@ async fn download_assets(paths:Vec<PathBuf>,cookie:rbx_asset::cookie::Cookie)->A
|
||||
// insert into global unique assets guy
|
||||
// add to download queue if the asset is globally unique and does not already exist on disk
|
||||
let mut stats=Stats::default();
|
||||
let context=rbx_asset::cookie::CookieContext::new(cookie);
|
||||
let context=rbx_asset::cookie::Context::new(cookie);
|
||||
let mut globally_unique_assets=UniqueAssets::default();
|
||||
// pop a job = retry_queue.pop_front() or ingest(recv.recv().await)
|
||||
// SLOW MODE:
|
||||
|
@ -28,5 +28,5 @@ strafesnet_rbx_loader = { path = "../lib/rbx_loader", registry = "strafesnet", o
|
||||
strafesnet_session = { path = "../engine/session", registry = "strafesnet" }
|
||||
strafesnet_settings = { path = "../engine/settings", registry = "strafesnet" }
|
||||
strafesnet_snf = { path = "../lib/snf", registry = "strafesnet", optional = true }
|
||||
wgpu = "24.0.0"
|
||||
wgpu = "25.0.0"
|
||||
winit = "0.30.7"
|
||||
|
@ -2,14 +2,12 @@ pub type QNWorker<'a,Task>=CompatNWorker<'a,Task>;
|
||||
pub type INWorker<'a,Task>=CompatNWorker<'a,Task>;
|
||||
|
||||
pub struct CompatNWorker<'a,Task>{
|
||||
data:std::marker::PhantomData<Task>,
|
||||
f:Box<dyn FnMut(Task)+Send+'a>,
|
||||
}
|
||||
|
||||
impl<'a,Task> CompatNWorker<'a,Task>{
|
||||
pub fn new(f:impl FnMut(Task)+Send+'a)->CompatNWorker<'a,Task>{
|
||||
Self{
|
||||
data:std::marker::PhantomData,
|
||||
f:Box::new(f),
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,6 @@ impl<'a> SetupContextPartial3<'a>{
|
||||
// Make sure we use the texture resolution limits from the adapter, so we can support images the size of the surface.
|
||||
let needed_limits=strafesnet_graphics::graphics::required_limits().using_resolution(self.adapter.limits());
|
||||
|
||||
let trace_dir=std::env::var("WGPU_TRACE");
|
||||
let (device, queue)=pollster::block_on(self.adapter
|
||||
.request_device(
|
||||
&wgpu::DeviceDescriptor {
|
||||
@ -125,8 +124,8 @@ impl<'a> SetupContextPartial3<'a>{
|
||||
required_features: (optional_features & self.adapter.features()) | required_features,
|
||||
required_limits: needed_limits,
|
||||
memory_hints:wgpu::MemoryHints::Performance,
|
||||
trace: wgpu::Trace::Off,
|
||||
},
|
||||
trace_dir.ok().as_ref().map(std::path::Path::new),
|
||||
))
|
||||
.expect("Unable to find a suitable GPU adapter!");
|
||||
|
||||
|
Reference in New Issue
Block a user