forked from StrafesNET/strafe-project
Compare commits
37 Commits
load-textu
...
load-roblo
Author | SHA1 | Date | |
---|---|---|---|
382ecfa713 | |||
28cad39b10 | |||
2af43480f1 | |||
bb7ccd97bb | |||
ff7b12e90e | |||
e70dc9ad0f | |||
c5deef8753 | |||
7c2666fdf5 | |||
6da4c81826 | |||
c868a91a06 | |||
b513e4037d | |||
a803ada0e4 | |||
eafcbae677 | |||
2e786b090f | |||
70e8f7a0ad | |||
48091fc15d | |||
23857d38d9 | |||
1c9bc347f6 | |||
c9afa2d059 | |||
1a66dfbaf7 | |||
847209aac4 | |||
42ba757ec0 | |||
1cee3b52ac | |||
e27ce3b507 | |||
bc8f2bd566 | |||
eed932212d | |||
73edb9ff95 | |||
ae0c9e73ee | |||
953d424a57 | |||
ca919b92fd | |||
1de3501e89 | |||
0135b17917 | |||
1878528a4f | |||
25e80a7c17 | |||
21835d13f6 | |||
91f6a5261f | |||
fb4a5efa14 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/target
|
||||
/textures
|
281
Cargo.lock
generated
281
Cargo.lock
generated
@ -157,6 +157,12 @@ dependencies = [
|
||||
"rustc-demangle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.5.3"
|
||||
@ -184,12 +190,35 @@ version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
||||
|
||||
[[package]]
|
||||
name = "blake3"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"constant_time_eq",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-sys"
|
||||
version = "0.1.0-beta.1"
|
||||
@ -302,6 +331,12 @@ dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "constant_time_eq"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.3"
|
||||
@ -360,6 +395,16 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "d3d12"
|
||||
version = "0.7.0"
|
||||
@ -382,6 +427,17 @@ dependencies = [
|
||||
"enum_primitive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dispatch"
|
||||
version = "0.2.0"
|
||||
@ -555,6 +611,16 @@ dependencies = [
|
||||
"waker-fn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.10"
|
||||
@ -822,6 +888,26 @@ version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||
|
||||
[[package]]
|
||||
name = "lz4"
|
||||
version = "1.24.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e9e2dd86df36ce760a60f6ff6ad526f7ba1f14ba0356f8254fb6905e6494df1"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"lz4-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lz4-sys"
|
||||
version = "1.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57d27b317e207b10f69f5e75494119e391a96f48861ae870d1da6edac98ca900"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "malloc_buf"
|
||||
version = "0.0.6"
|
||||
@ -1198,6 +1284,12 @@ version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.3.1"
|
||||
@ -1222,6 +1314,19 @@ name = "profiling"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "46b2164ebdb1dfeec5e337be164292351e11daf63a05174c6776b2f47460f0c9"
|
||||
dependencies = [
|
||||
"profiling-procmacros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "profiling-procmacros"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74c55e9e629af5298a40e0fa106435b2da30484c4ec76b41d19bc4d00dd8b903"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 2.0.29",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
@ -1232,6 +1337,36 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "range-alloc"
|
||||
version = "0.1.3"
|
||||
@ -1244,6 +1379,83 @@ version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
|
||||
|
||||
[[package]]
|
||||
name = "rbx_binary"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e50573021d04b680018955662eba7dc4aac3de92219231798f6c9b41e38ab01"
|
||||
dependencies = [
|
||||
"log",
|
||||
"lz4",
|
||||
"profiling",
|
||||
"rbx_dom_weak",
|
||||
"rbx_reflection",
|
||||
"rbx_reflection_database",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rbx_dom_weak"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "161729449bbb0cfa657ce7bcca6a160d0af06d8b8d9efdc9abe14735dccacdb9"
|
||||
dependencies = [
|
||||
"rbx_types",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rbx_reflection"
|
||||
version = "4.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08bd48487192046fec8f805f3fa29f3d7d5beb9890b0859b1a92bd8aff580343"
|
||||
dependencies = [
|
||||
"rbx_types",
|
||||
"serde",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rbx_reflection_database"
|
||||
version = "0.2.7+roblox-588"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1be6cf674182806f11ad4899dd1feafe977591f1ae035ae05a58d4b74e487276"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"rbx_reflection",
|
||||
"rmp-serde",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rbx_types"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "070106e926b8ae54c7bc443e5db4d868d7f0af51c1d7cfd7efe1364c1753d8a3"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bitflags 1.3.2",
|
||||
"blake3",
|
||||
"lazy_static",
|
||||
"rand",
|
||||
"serde",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rbx_xml"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4bc65b70827519fdc4ab47416d1085b912f087fadab9ed415471b6daba635574"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"log",
|
||||
"rbx_dom_weak",
|
||||
"rbx_reflection",
|
||||
"rbx_reflection_database",
|
||||
"xml-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.3.5"
|
||||
@ -1255,9 +1467,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.9.4"
|
||||
version = "1.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29"
|
||||
checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@ -1267,9 +1479,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.3.7"
|
||||
version = "0.3.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629"
|
||||
checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
@ -1288,6 +1500,28 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b"
|
||||
|
||||
[[package]]
|
||||
name = "rmp"
|
||||
version = "0.8.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f9860a6cc38ed1da53456442089b4dfa35e7cedaa326df63017af88385e6b20"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"num-traits 0.2.16",
|
||||
"paste",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rmp-serde"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"rmp",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.23"
|
||||
@ -1338,6 +1572,26 @@ dependencies = [
|
||||
"tiny-skia",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.188"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.29",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simd-adler32"
|
||||
version = "0.3.7"
|
||||
@ -1405,7 +1659,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strafe-client"
|
||||
version = "0.3.0"
|
||||
version = "0.5.0"
|
||||
dependencies = [
|
||||
"async-executor",
|
||||
"bytemuck",
|
||||
@ -1415,6 +1669,11 @@ dependencies = [
|
||||
"log",
|
||||
"obj",
|
||||
"pollster",
|
||||
"rbx_binary",
|
||||
"rbx_dom_weak",
|
||||
"rbx_reflection_database",
|
||||
"rbx_xml",
|
||||
"regex",
|
||||
"wgpu",
|
||||
"winit",
|
||||
]
|
||||
@ -1425,6 +1684,12 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
@ -1524,6 +1789,12 @@ version = "0.19.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a464a4b34948a5f67fddd2b823c62d9d92e44be75058b99939eae6c5b6960b33"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.11"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "strafe-client"
|
||||
version = "0.3.0"
|
||||
version = "0.5.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
@ -14,6 +14,11 @@ glam = "0.24.1"
|
||||
log = "0.4.20"
|
||||
obj = "0.10.2"
|
||||
pollster = "0.3.0"
|
||||
rbx_binary = "0.7.1"
|
||||
rbx_dom_weak = "2.5.0"
|
||||
rbx_reflection_database = "0.2.7"
|
||||
rbx_xml = "0.13.1"
|
||||
regex = "1.9.5"
|
||||
wgpu = "0.17.0"
|
||||
winit = "0.28.6"
|
||||
|
||||
|
34
src/body.rs
34
src/body.rs
@ -16,6 +16,8 @@ pub enum PhysicsInstruction {
|
||||
// bool,//true = Trigger; false = teleport
|
||||
// bool,//true = Force
|
||||
// )
|
||||
//temp
|
||||
SetPosition(glam::Vec3),
|
||||
}
|
||||
|
||||
pub struct Body {
|
||||
@ -135,8 +137,8 @@ pub struct PhysicsState {
|
||||
pub hitbox_halfsize: glam::Vec3,
|
||||
pub contacts: std::collections::HashSet::<RelativeCollision>,
|
||||
//pub intersections: Vec<ModelId>,
|
||||
pub models: Vec<ModelPhysics>,
|
||||
//temp
|
||||
pub models_cringe_clone: Vec<Model>,
|
||||
pub temp_control_dir: glam::Vec3,
|
||||
//camera must exist in state because wormholes modify the camera, also camera punch
|
||||
//pub camera: Camera,
|
||||
@ -264,13 +266,13 @@ impl Aabb {
|
||||
type TreyMeshFace = AabbFace;
|
||||
type TreyMesh = Aabb;
|
||||
|
||||
pub struct Model {
|
||||
pub struct ModelPhysics {
|
||||
//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.
|
||||
transform: glam::Mat4,
|
||||
}
|
||||
|
||||
impl Model {
|
||||
impl ModelPhysics {
|
||||
pub fn new(transform:glam::Mat4) -> Self {
|
||||
Self{transform}
|
||||
}
|
||||
@ -314,10 +316,10 @@ pub struct RelativeCollision {
|
||||
}
|
||||
|
||||
impl RelativeCollision {
|
||||
pub fn mesh(&self,models:&Vec<Model>) -> TreyMesh {
|
||||
pub fn mesh(&self,models:&Vec<ModelPhysics>) -> TreyMesh {
|
||||
return models.get(self.model as usize).unwrap().face_mesh(self.face)
|
||||
}
|
||||
pub fn normal(&self,models:&Vec<Model>) -> glam::Vec3 {
|
||||
pub fn normal(&self,models:&Vec<ModelPhysics>) -> glam::Vec3 {
|
||||
return models.get(self.model as usize).unwrap().face_normal(self.face)
|
||||
}
|
||||
}
|
||||
@ -368,7 +370,7 @@ impl PhysicsState {
|
||||
|
||||
fn contact_constrain_velocity(&self,velocity:&mut glam::Vec3){
|
||||
for contact in self.contacts.iter() {
|
||||
let n=contact.normal(&self.models_cringe_clone);
|
||||
let n=contact.normal(&self.models);
|
||||
let d=velocity.dot(n);
|
||||
if d<0f32{
|
||||
(*velocity)-=d/n.length_squared()*n;
|
||||
@ -377,7 +379,7 @@ impl PhysicsState {
|
||||
}
|
||||
fn contact_constrain_acceleration(&self,acceleration:&mut glam::Vec3){
|
||||
for contact in self.contacts.iter() {
|
||||
let n=contact.normal(&self.models_cringe_clone);
|
||||
let n=contact.normal(&self.models);
|
||||
let d=acceleration.dot(n);
|
||||
if d<0f32{
|
||||
(*acceleration)-=d/n.length_squared()*n;
|
||||
@ -457,7 +459,7 @@ impl PhysicsState {
|
||||
let mut best_time=time_limit;
|
||||
let mut exit_face:Option<TreyMeshFace>=None;
|
||||
let mesh0=self.mesh();
|
||||
let mesh1=self.models_cringe_clone.get(collision_data.model as usize).unwrap().mesh();
|
||||
let mesh1=self.models.get(collision_data.model as usize).unwrap().mesh();
|
||||
let (v,a)=(-self.body.velocity,self.body.acceleration);
|
||||
//collect x
|
||||
match collision_data.face {
|
||||
@ -608,7 +610,7 @@ impl PhysicsState {
|
||||
let mut best_time=time_limit;
|
||||
let mut best_face:Option<TreyMeshFace>=None;
|
||||
let mesh0=self.mesh();
|
||||
let mesh1=self.models_cringe_clone.get(model_id as usize).unwrap().mesh();
|
||||
let mesh1=self.models.get(model_id as usize).unwrap().mesh();
|
||||
let (p,v,a)=(self.body.position,self.body.velocity,self.body.acceleration);
|
||||
//collect x
|
||||
for t in zeroes2(mesh0.max.x-mesh1.min.x,v.x,0.5*a.x) {
|
||||
@ -733,7 +735,7 @@ impl crate::instruction::InstructionEmitter<PhysicsInstruction> for PhysicsState
|
||||
collector.collect(self.predict_collision_end(self.time,time_limit,collision_data));
|
||||
}
|
||||
//check for collision start instructions (against every part in the game with no optimization!!)
|
||||
for i in 0..self.models_cringe_clone.len() {
|
||||
for i in 0..self.models.len() {
|
||||
collector.collect(self.predict_collision_start(self.time,time_limit,i as u32));
|
||||
}
|
||||
if self.grounded {
|
||||
@ -756,6 +758,7 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
||||
//selectively update body
|
||||
match &ins.instruction {
|
||||
PhysicsInstruction::SetWalkTargetVelocity(_)
|
||||
|PhysicsInstruction::SetPosition(_)
|
||||
|PhysicsInstruction::SetControlDir(_) => self.time=ins.time,//TODO: queue instructions
|
||||
PhysicsInstruction::RefreshWalkTarget
|
||||
|PhysicsInstruction::ReachWalkTargetVelocity
|
||||
@ -765,6 +768,15 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
||||
|PhysicsInstruction::Jump => self.advance_time(ins.time),
|
||||
}
|
||||
match ins.instruction {
|
||||
PhysicsInstruction::SetPosition(position)=>{
|
||||
//temp
|
||||
self.body.position=position;
|
||||
//manual clear //for c in self.contacts{process_instruction(CollisionEnd(c))}
|
||||
self.contacts.clear();
|
||||
self.body.acceleration=self.gravity;
|
||||
self.walk.state=WalkEnum::Reached;
|
||||
self.grounded=false;
|
||||
}
|
||||
PhysicsInstruction::CollisionStart(c) => {
|
||||
//check ground
|
||||
match &c.face {
|
||||
@ -854,4 +866,4 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ pub trait Example: 'static + Sized {
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
);
|
||||
fn update(&mut self, event: WindowEvent);
|
||||
fn update(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, event: WindowEvent);
|
||||
fn move_mouse(&mut self, delta: (f64,f64));
|
||||
fn render(
|
||||
&mut self,
|
||||
@ -181,9 +181,41 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
||||
|
||||
(size, surface)
|
||||
};
|
||||
let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, Some(&surface))
|
||||
.await
|
||||
.expect("No suitable GPU adapters found on the system!");
|
||||
|
||||
let adapter;
|
||||
|
||||
let optional_features = E::optional_features();
|
||||
let required_features = E::required_features();
|
||||
|
||||
//no helper function smh gotta write it myself
|
||||
let adapters = instance.enumerate_adapters(backends);
|
||||
|
||||
let mut chosen_adapter = None;
|
||||
let mut chosen_adapter_score=0;
|
||||
for adapter in adapters {
|
||||
if !adapter.is_surface_supported(&surface) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let score=match adapter.get_info().device_type{
|
||||
wgpu::DeviceType::IntegratedGpu=>3,
|
||||
wgpu::DeviceType::DiscreteGpu=>4,
|
||||
wgpu::DeviceType::VirtualGpu=>2,
|
||||
wgpu::DeviceType::Other|wgpu::DeviceType::Cpu=>1,
|
||||
};
|
||||
|
||||
let adapter_features = adapter.features();
|
||||
if chosen_adapter_score<score&&adapter_features.contains(required_features) {
|
||||
chosen_adapter_score=score;
|
||||
chosen_adapter=Some(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(maybe_chosen_adapter) = chosen_adapter{
|
||||
adapter=maybe_chosen_adapter;
|
||||
}else{
|
||||
panic!("No suitable GPU adapters found on the system!");
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
@ -191,15 +223,6 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
||||
println!("Using {} ({:?})", adapter_info.name, adapter_info.backend);
|
||||
}
|
||||
|
||||
let optional_features = E::optional_features();
|
||||
let required_features = E::required_features();
|
||||
let adapter_features = adapter.features();
|
||||
assert!(
|
||||
adapter_features.contains(required_features),
|
||||
"Adapter does not support required features for this example: {:?}",
|
||||
required_features - adapter_features
|
||||
);
|
||||
|
||||
let required_downlevel_capabilities = E::required_downlevel_capabilities();
|
||||
let downlevel_capabilities = adapter.get_downlevel_capabilities();
|
||||
assert!(
|
||||
@ -223,7 +246,7 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
||||
.request_device(
|
||||
&wgpu::DeviceDescriptor {
|
||||
label: None,
|
||||
features: (optional_features & adapter_features) | required_features,
|
||||
features: (optional_features & adapter.features()) | required_features,
|
||||
limits: needed_limits,
|
||||
},
|
||||
trace_dir.ok().as_ref().map(std::path::Path::new),
|
||||
@ -346,7 +369,7 @@ fn start<E: Example>(
|
||||
println!("{:#?}", instance.generate_report());
|
||||
}
|
||||
_ => {
|
||||
example.update(event);
|
||||
example.update(&device,&queue,event);
|
||||
}
|
||||
},
|
||||
event::Event::DeviceEvent {
|
||||
|
@ -1,4 +0,0 @@
|
||||
pub mod framework;
|
||||
pub mod body;
|
||||
pub mod zeroes;
|
||||
pub mod instruction;
|
140
src/load_roblox.rs
Normal file
140
src/load_roblox.rs
Normal file
@ -0,0 +1,140 @@
|
||||
use std::todo;
|
||||
|
||||
use crate::model::{ModelData,ModelInstance};
|
||||
|
||||
use crate::primitives;
|
||||
|
||||
fn class_is_a(class: &str, superclass: &str) -> bool {
|
||||
if class==superclass {
|
||||
return true
|
||||
}
|
||||
let class_descriptor=rbx_reflection_database::get().classes.get(class);
|
||||
if let Some(descriptor) = &class_descriptor {
|
||||
if let Some(class_super) = &descriptor.superclass {
|
||||
return class_is_a(&class_super, superclass)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
fn recursive_collect_superclass(objects: &mut std::vec::Vec<rbx_dom_weak::types::Ref>,dom: &rbx_dom_weak::WeakDom, instance: &rbx_dom_weak::Instance, superclass: &str){
|
||||
for &referent in instance.children() {
|
||||
if let Some(c) = dom.get_by_ref(referent) {
|
||||
if class_is_a(c.class.as_str(), superclass) {
|
||||
objects.push(c.referent());//copy ref
|
||||
}
|
||||
recursive_collect_superclass(objects,dom,c,superclass);
|
||||
}
|
||||
}
|
||||
}
|
||||
fn get_texture_refs(dom:&rbx_dom_weak::WeakDom) -> Vec<rbx_dom_weak::types::Ref>{
|
||||
let mut objects = std::vec::Vec::new();
|
||||
recursive_collect_superclass(&mut objects, dom, dom.root(),"Decal");
|
||||
//get ids
|
||||
//clear vec
|
||||
//next class
|
||||
objects
|
||||
}
|
||||
|
||||
struct RobloxAssetId(u64);
|
||||
struct RobloxAssetIdParseErr;
|
||||
impl std::str::FromStr for RobloxAssetId {
|
||||
type Err=RobloxAssetIdParseErr;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err>{
|
||||
let regman=regex::Regex::new(r"(\d+)$").unwrap();
|
||||
if let Some(captures) = regman.captures(s) {
|
||||
if captures.len()==2{//captures[0] is all captures concatenated, and then each individual capture
|
||||
if let Ok(id) = captures[0].parse::<u64>() {
|
||||
return Ok(Self(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(RobloxAssetIdParseErr)
|
||||
}
|
||||
}
|
||||
pub fn generate_modeldatas_roblox(dom:rbx_dom_weak::WeakDom) -> Result<(Vec<ModelData>,Vec<String>,glam::Vec3), Box<dyn std::error::Error>>{
|
||||
//ModelData includes texture dds
|
||||
let mut spawn_point=glam::Vec3::ZERO;
|
||||
|
||||
//TODO: generate unit Block, Wedge, etc. after based on part shape lists
|
||||
let mut modeldatas=crate::model::generate_modeldatas(primitives::the_unit_cube_lol(),ModelData::COLOR_FLOATS_WHITE);
|
||||
let unit_cube_modeldata=modeldatas[0].clone();
|
||||
|
||||
let mut texture_id_from_asset_id=std::collections::HashMap::<u64,u32>::new();
|
||||
let mut asset_id_from_texture_id=Vec::new();
|
||||
|
||||
let mut object_refs = std::vec::Vec::new();
|
||||
let mut temp_objects = std::vec::Vec::new();
|
||||
recursive_collect_superclass(&mut object_refs, &dom, dom.root(),"BasePart");
|
||||
for object_ref in object_refs {
|
||||
if let Some(object)=dom.get_by_ref(object_ref){
|
||||
if let (
|
||||
Some(rbx_dom_weak::types::Variant::CFrame(cf)),
|
||||
Some(rbx_dom_weak::types::Variant::Vector3(size)),
|
||||
Some(rbx_dom_weak::types::Variant::Float32(transparency)),
|
||||
Some(rbx_dom_weak::types::Variant::Color3uint8(color3)),
|
||||
Some(rbx_dom_weak::types::Variant::Enum(shape)),
|
||||
) = (
|
||||
object.properties.get("CFrame"),
|
||||
object.properties.get("Size"),
|
||||
object.properties.get("Transparency"),
|
||||
object.properties.get("Color"),
|
||||
object.properties.get("Shape"),//this will also skip unions
|
||||
)
|
||||
{
|
||||
let model_instance=ModelInstance {
|
||||
transform:glam::Mat4::from_translation(
|
||||
glam::Vec3::new(cf.position.x,cf.position.y,cf.position.z)
|
||||
)
|
||||
* glam::Mat4::from_mat3(
|
||||
glam::Mat3::from_cols(
|
||||
glam::Vec3::new(cf.orientation.x.x,cf.orientation.y.x,cf.orientation.z.x),
|
||||
glam::Vec3::new(cf.orientation.x.y,cf.orientation.y.y,cf.orientation.z.y),
|
||||
glam::Vec3::new(cf.orientation.x.z,cf.orientation.y.z,cf.orientation.z.z),
|
||||
),
|
||||
)
|
||||
* glam::Mat4::from_scale(
|
||||
glam::Vec3::new(size.x,size.y,size.z)/2.0
|
||||
),
|
||||
color: glam::vec4(color3.r as f32/255f32, color3.g as f32/255f32, color3.b as f32/255f32, 1.0-*transparency),
|
||||
};
|
||||
if object.name=="MapStart"{
|
||||
spawn_point=glam::Vec4Swizzles::xyz(model_instance.transform*glam::Vec3::Y.extend(1.0))+glam::vec3(0.0,2.5,0.0);
|
||||
println!("Found MapStart{:?}",spawn_point);
|
||||
}
|
||||
if *transparency==1.0||shape.to_u32()!=1 {
|
||||
continue;
|
||||
}
|
||||
temp_objects.clear();
|
||||
recursive_collect_superclass(&mut temp_objects, &dom, object,"Decal");
|
||||
|
||||
let mut i_can_only_load_one_texture_per_model=None;
|
||||
for &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)) = decal.properties.get("Texture") {
|
||||
if let Ok(asset_id)=content.clone().into_string().parse::<RobloxAssetId>(){
|
||||
if let Some(&texture_id)=texture_id_from_asset_id.get(&asset_id.0){
|
||||
i_can_only_load_one_texture_per_model=Some(texture_id);
|
||||
}else{
|
||||
let texture_id=asset_id_from_texture_id.len();
|
||||
texture_id_from_asset_id.insert(asset_id.0,texture_id as u32);
|
||||
asset_id_from_texture_id.push(asset_id.0);
|
||||
//make new model
|
||||
let mut unit_cube_texture=unit_cube_modeldata.clone();
|
||||
unit_cube_texture.texture=Some(texture_id as u32);
|
||||
modeldatas.push(unit_cube_texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
match i_can_only_load_one_texture_per_model{
|
||||
//push to existing texture model
|
||||
Some(texture_id)=>modeldatas[(texture_id+1) as usize].instances.push(model_instance),
|
||||
//push instance to big unit cube in the sky
|
||||
None=>modeldatas[0].instances.push(model_instance),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok((modeldatas,asset_id_from_texture_id.iter().map(|t|t.to_string()).collect(),spawn_point))
|
||||
}
|
480
src/main.rs
480
src/main.rs
@ -1,31 +1,22 @@
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use std::{borrow::Cow, time::Instant};
|
||||
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};
|
||||
use model::{Vertex,ModelData,ModelInstance};
|
||||
|
||||
const IMAGE_SIZE: u32 = 128;
|
||||
|
||||
#[derive(Clone, Copy, Pod, Zeroable)]
|
||||
#[repr(C)]
|
||||
struct Vertex {
|
||||
pos: [f32; 3],
|
||||
texture: [f32; 2],
|
||||
normal: [f32; 3],
|
||||
}
|
||||
mod body;
|
||||
mod model;
|
||||
mod zeroes;
|
||||
mod framework;
|
||||
mod primitives;
|
||||
mod instruction;
|
||||
mod load_roblox;
|
||||
|
||||
struct Entity {
|
||||
index_count: u32,
|
||||
index_buf: wgpu::Buffer,
|
||||
}
|
||||
|
||||
//temp?
|
||||
struct ModelData {
|
||||
transforms: Vec<glam::Mat4>,
|
||||
vertex_buf: wgpu::Buffer,
|
||||
entities: Vec<Entity>,
|
||||
}
|
||||
|
||||
struct ModelGraphics {
|
||||
transforms: Vec<glam::Mat4>,
|
||||
instances: Vec<ModelInstance>,
|
||||
vertex_buf: wgpu::Buffer,
|
||||
entities: Vec<Entity>,
|
||||
bind_group: wgpu::BindGroup,
|
||||
@ -112,6 +103,13 @@ impl Camera {
|
||||
raw
|
||||
}
|
||||
}
|
||||
pub struct GraphicsSamplers{
|
||||
repeat: wgpu::Sampler,
|
||||
}
|
||||
|
||||
pub struct GraphicsBindGroupLayouts{
|
||||
model: wgpu::BindGroupLayout,
|
||||
}
|
||||
|
||||
pub struct GraphicsBindGroups {
|
||||
camera: wgpu::BindGroup,
|
||||
@ -126,9 +124,12 @@ pub struct GraphicsPipelines {
|
||||
pub struct GraphicsData {
|
||||
start_time: std::time::Instant,
|
||||
camera: Camera,
|
||||
physics: strafe_client::body::PhysicsState,
|
||||
physics: body::PhysicsState,
|
||||
pipelines: GraphicsPipelines,
|
||||
bind_groups: GraphicsBindGroups,
|
||||
bind_group_layouts: GraphicsBindGroupLayouts,
|
||||
samplers: GraphicsSamplers,
|
||||
temp_squid_texture_view: wgpu::TextureView,
|
||||
camera_buf: wgpu::Buffer,
|
||||
models: Vec<ModelGraphics>,
|
||||
depth_view: wgpu::TextureView,
|
||||
@ -159,113 +160,196 @@ impl GraphicsData {
|
||||
|
||||
depth_texture.create_view(&wgpu::TextureViewDescriptor::default())
|
||||
}
|
||||
|
||||
fn generate_model_physics(&mut self,modeldatas:&Vec<ModelData>){
|
||||
self.physics.models.append(&mut modeldatas.iter().map(|m|
|
||||
//make aabb and run vertices to get realistic bounds
|
||||
m.instances.iter().map(|t|body::ModelPhysics::new(t.transform))
|
||||
).flatten().collect());
|
||||
println!("Physics Objects: {}",self.physics.models.len());
|
||||
}
|
||||
fn generate_model_graphics(&mut self,device:&wgpu::Device,queue:&wgpu::Queue,mut modeldatas:Vec<ModelData>,textures:Vec<String>){
|
||||
//generate texture view per texture
|
||||
|
||||
//idk how to do this gooder lol
|
||||
let mut double_map=std::collections::HashMap::<u32,u32>::new();
|
||||
let mut texture_views:Vec<wgpu::TextureView>=Vec::with_capacity(textures.len());
|
||||
for (i,t) in textures.iter().enumerate(){
|
||||
if let Ok(mut file) = std::fs::File::open(std::path::Path::new(&format!("textures/{}.dds",t))){
|
||||
let image = ddsfile::Dds::read(&mut file).unwrap();
|
||||
|
||||
let size = wgpu::Extent3d {
|
||||
width: image.get_width()/4*4,//floor(w,4), should be ceil(w,4)
|
||||
height: image.get_height()/4*4,
|
||||
depth_or_array_layers: 1,
|
||||
};
|
||||
|
||||
let layer_size = wgpu::Extent3d {
|
||||
depth_or_array_layers: 1,
|
||||
..size
|
||||
};
|
||||
let max_mips = layer_size.max_mips(wgpu::TextureDimension::D2);
|
||||
|
||||
let texture = device.create_texture_with_data(
|
||||
queue,
|
||||
&wgpu::TextureDescriptor {
|
||||
size,
|
||||
mip_level_count: max_mips,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Bc7RgbaUnorm,
|
||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
||||
label: Some(format!("Texture{}",i).as_str()),
|
||||
view_formats: &[],
|
||||
},
|
||||
&image.data,
|
||||
);
|
||||
|
||||
double_map.insert(i as u32, texture_views.len() as u32);
|
||||
texture_views.push(texture.create_view(&wgpu::TextureViewDescriptor {
|
||||
label: Some(format!("Texture{} View",i).as_str()),
|
||||
dimension: Some(wgpu::TextureViewDimension::D2),
|
||||
..wgpu::TextureViewDescriptor::default()
|
||||
}));
|
||||
}
|
||||
}
|
||||
//drain the modeldata vec so entities can be /moved/ to models.entities
|
||||
let mut instance_count=0;
|
||||
self.models.reserve(modeldatas.len());
|
||||
for (i,modeldata) in modeldatas.drain(..).enumerate() {
|
||||
let n_instances=modeldata.instances.len();
|
||||
if 0<n_instances{
|
||||
let model_uniforms = get_instances_buffer_data(&modeldata.instances);
|
||||
let model_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some(format!("Model{} Buf",i).as_str()),
|
||||
contents: bytemuck::cast_slice(&model_uniforms),
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
});
|
||||
let texture_view=match modeldata.texture{
|
||||
Some(texture_id)=>{
|
||||
match double_map.get(&texture_id){
|
||||
Some(&mapped_texture_id)=>&texture_views[mapped_texture_id as usize],
|
||||
None=>&self.temp_squid_texture_view,
|
||||
}
|
||||
},
|
||||
None=>&self.temp_squid_texture_view,
|
||||
};
|
||||
let model_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &self.bind_group_layouts.model,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: model_buf.as_entire_binding(),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::TextureView(texture_view),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 2,
|
||||
resource: wgpu::BindingResource::Sampler(&self.samplers.repeat),
|
||||
},
|
||||
],
|
||||
label: Some(format!("Model{} Bind Group",i).as_str()),
|
||||
});
|
||||
let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Vertex"),
|
||||
contents: bytemuck::cast_slice(&modeldata.vertices),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
//all of these are being moved here
|
||||
instance_count+=n_instances;
|
||||
self.models.push(ModelGraphics{
|
||||
instances:modeldata.instances,
|
||||
vertex_buf,
|
||||
entities: modeldata.entities.iter().map(|indices|{
|
||||
let index_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Index"),
|
||||
contents: bytemuck::cast_slice(&indices),
|
||||
usage: wgpu::BufferUsages::INDEX,
|
||||
});
|
||||
Entity {
|
||||
index_buf,
|
||||
index_count: indices.len() as u32,
|
||||
}
|
||||
}).collect(),
|
||||
bind_group: model_bind_group,
|
||||
model_buf,
|
||||
});
|
||||
}else{
|
||||
println!("WARNING: Model{} has 0 instances",i);
|
||||
}
|
||||
}
|
||||
println!("Graphics Objects: {}",self.models.len());
|
||||
println!("Graphics Instances: {}",instance_count);
|
||||
}
|
||||
}
|
||||
|
||||
fn get_transform_uniform_data(transforms:&Vec<glam::Mat4>) -> Vec<f32> {
|
||||
let mut raw = Vec::with_capacity(4*4*transforms.len());
|
||||
for (i,t) in transforms.iter().enumerate(){
|
||||
let mut v = raw.split_off(4*4*i);
|
||||
raw.extend_from_slice(&AsRef::<[f32; 4*4]>::as_ref(t)[..]);
|
||||
fn get_instances_buffer_data(instances:&Vec<ModelInstance>) -> Vec<f32> {
|
||||
const SIZE: usize=4*4+4;//let size=std::mem::size_of::<ModelInstance>();
|
||||
let mut raw = Vec::with_capacity(SIZE*instances.len());
|
||||
for (i,mi) in instances.iter().enumerate(){
|
||||
let mut v = raw.split_off(SIZE*i);
|
||||
raw.extend_from_slice(&AsRef::<[f32; 4*4]>::as_ref(&mi.transform)[..]);
|
||||
raw.extend_from_slice(AsRef::<[f32; 4]>::as_ref(&mi.color));
|
||||
raw.append(&mut v);
|
||||
}
|
||||
raw
|
||||
}
|
||||
|
||||
fn add_obj(device:&wgpu::Device,modeldatas:& mut Vec<ModelData>,data:obj::ObjData){
|
||||
let mut vertices = Vec::new();
|
||||
let mut vertex_index = std::collections::HashMap::<obj::IndexTuple,u16>::new();
|
||||
for object in data.objects {
|
||||
let mut entities = Vec::<Entity>::new();
|
||||
for group in object.groups {
|
||||
let mut indices = Vec::new();
|
||||
for poly in group.polys {
|
||||
for end_index in 2..poly.0.len() {
|
||||
for &index in &[0, end_index - 1, end_index] {
|
||||
let vert = poly.0[index];
|
||||
if let Some(&i)=vertex_index.get(&vert){
|
||||
indices.push(i);
|
||||
}else{
|
||||
let i=vertices.len() as u16;
|
||||
vertices.push(Vertex {
|
||||
pos: data.position[vert.0],
|
||||
texture: data.texture[vert.1.unwrap()],
|
||||
normal: data.normal[vert.2.unwrap()],
|
||||
});
|
||||
vertex_index.insert(vert,i);
|
||||
indices.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let index_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Index"),
|
||||
contents: bytemuck::cast_slice(&indices),
|
||||
usage: wgpu::BufferUsages::INDEX,
|
||||
});
|
||||
entities.push(Entity {
|
||||
index_buf,
|
||||
index_count: indices.len() as u32,
|
||||
});
|
||||
}
|
||||
let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Vertex"),
|
||||
contents: bytemuck::cast_slice(&vertices),
|
||||
usage: wgpu::BufferUsages::VERTEX,
|
||||
});
|
||||
modeldatas.push(ModelData {
|
||||
transforms: vec![glam::Mat4::default()],
|
||||
vertex_buf,
|
||||
entities,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl strafe_client::framework::Example for GraphicsData {
|
||||
impl framework::Example for GraphicsData {
|
||||
fn optional_features() -> wgpu::Features {
|
||||
wgpu::Features::TEXTURE_COMPRESSION_ASTC
|
||||
| wgpu::Features::TEXTURE_COMPRESSION_ETC2
|
||||
| wgpu::Features::TEXTURE_COMPRESSION_BC
|
||||
}
|
||||
|
||||
fn required_limits() -> wgpu::Limits {
|
||||
wgpu::Limits::default() //framework.rs was using goofy limits that caused me a multi-day headache
|
||||
}
|
||||
fn init(
|
||||
config: &wgpu::SurfaceConfiguration,
|
||||
_adapter: &wgpu::Adapter,
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
) -> Self {
|
||||
let unit_cube=primitives::the_unit_cube_lol();
|
||||
let mut modeldatas = Vec::<ModelData>::new();
|
||||
let ground=obj::ObjData{
|
||||
position: vec![[-1.0,0.0,-1.0],[1.0,0.0,-1.0],[1.0,0.0,1.0],[-1.0,0.0,1.0]],
|
||||
texture: vec![[-10.0,-10.0],[10.0,-10.0],[10.0,10.0],[-10.0,10.0]],
|
||||
normal: vec![[0.0,1.0,0.0]],
|
||||
objects: vec![obj::Object{
|
||||
name: "Ground Object".to_owned(),
|
||||
groups: vec![obj::Group{
|
||||
name: "Ground Group".to_owned(),
|
||||
index: 0,
|
||||
material: None,
|
||||
polys: vec![obj::SimplePolygon(vec![
|
||||
obj::IndexTuple(0,Some(0),Some(0)),
|
||||
obj::IndexTuple(1,Some(1),Some(0)),
|
||||
obj::IndexTuple(2,Some(2),Some(0)),
|
||||
obj::IndexTuple(3,Some(3),Some(0)),
|
||||
])]
|
||||
}]
|
||||
}],
|
||||
material_libs: Vec::new(),
|
||||
};
|
||||
add_obj(device,& mut modeldatas,obj::ObjData::load_buf(&include_bytes!("../models/teslacyberv3.0.obj")[..]).unwrap());
|
||||
add_obj(device,& mut modeldatas,obj::ObjData::load_buf(&include_bytes!("../models/suzanne.obj")[..]).unwrap());
|
||||
add_obj(device,& mut modeldatas,obj::ObjData::load_buf(&include_bytes!("../models/teapot.obj")[..]).unwrap());
|
||||
add_obj(device,& mut modeldatas,ground);
|
||||
modeldatas.append(&mut model::generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/teslacyberv3.0.obj")[..]).unwrap(),ModelData::COLOR_FLOATS_WHITE));
|
||||
modeldatas.append(&mut model::generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/suzanne.obj")[..]).unwrap(),ModelData::COLOR_FLOATS_WHITE));
|
||||
modeldatas.append(&mut model::generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/teapot.obj")[..]).unwrap(),ModelData::COLOR_FLOATS_WHITE));
|
||||
modeldatas.append(&mut model::generate_modeldatas(unit_cube.clone(),ModelData::COLOR_FLOATS_WHITE));
|
||||
println!("models.len = {:?}", modeldatas.len());
|
||||
modeldatas[0].transforms[0]=glam::Mat4::from_translation(glam::vec3(10.,0.,-10.));
|
||||
modeldatas[1].transforms[0]=glam::Mat4::from_translation(glam::vec3(10.,5.,10.));
|
||||
modeldatas[1].transforms.push(glam::Mat4::from_translation(glam::vec3(20.,5.,10.)));
|
||||
modeldatas[1].transforms.push(glam::Mat4::from_translation(glam::vec3(10.,5.,20.)));
|
||||
modeldatas[1].transforms.push(glam::Mat4::from_translation(glam::vec3(20.,5.,20.)));
|
||||
modeldatas[2].transforms[0]=glam::Mat4::from_translation(glam::vec3(-10.,5.,10.));
|
||||
modeldatas[3].transforms[0]=glam::Mat4::from_translation(glam::vec3(0.,0.,0.))*glam::Mat4::from_scale(glam::vec3(160.0, 1.0, 160.0));
|
||||
modeldatas[0].instances.push(ModelInstance{
|
||||
transform:glam::Mat4::from_translation(glam::vec3(10.,0.,-10.)),
|
||||
color:ModelData::COLOR_VEC4_WHITE,
|
||||
});
|
||||
//quad monkeys
|
||||
modeldatas[1].instances.push(ModelInstance{
|
||||
transform:glam::Mat4::from_translation(glam::vec3(10.,5.,10.)),
|
||||
color:ModelData::COLOR_VEC4_WHITE,
|
||||
});
|
||||
modeldatas[1].instances.push(ModelInstance{
|
||||
transform:glam::Mat4::from_translation(glam::vec3(20.,5.,10.)),
|
||||
color:glam::vec4(1.0,0.0,0.0,1.0),
|
||||
});
|
||||
modeldatas[1].instances.push(ModelInstance{
|
||||
transform:glam::Mat4::from_translation(glam::vec3(10.,5.,20.)),
|
||||
color:glam::vec4(0.0,1.0,0.0,1.0),
|
||||
});
|
||||
modeldatas[1].instances.push(ModelInstance{
|
||||
transform:glam::Mat4::from_translation(glam::vec3(20.,5.,20.)),
|
||||
color:glam::vec4(0.0,0.0,1.0,1.0),
|
||||
});
|
||||
//teapot
|
||||
modeldatas[2].instances.push(ModelInstance{
|
||||
transform:glam::Mat4::from_translation(glam::vec3(-10.,5.,10.)),
|
||||
color:ModelData::COLOR_VEC4_WHITE,
|
||||
});
|
||||
//ground
|
||||
modeldatas[3].instances.push(ModelInstance{
|
||||
transform:glam::Mat4::from_translation(glam::vec3(0.,0.,0.))*glam::Mat4::from_scale(glam::vec3(160.0, 1.0, 160.0)),
|
||||
color:ModelData::COLOR_VEC4_WHITE,
|
||||
});
|
||||
|
||||
let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
label: None,
|
||||
@ -370,8 +454,8 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
yaw: 0.0,
|
||||
controls:0,
|
||||
};
|
||||
let physics = strafe_client::body::PhysicsState {
|
||||
body: strafe_client::body::Body::with_pva(glam::vec3(0.0,50.0,0.0),glam::vec3(0.0,0.0,0.0),glam::vec3(0.0,-100.0,0.0)),
|
||||
let physics = body::PhysicsState {
|
||||
body: body::Body::with_pva(glam::vec3(0.0,50.0,0.0),glam::vec3(0.0,0.0,0.0),glam::vec3(0.0,-100.0,0.0)),
|
||||
time: 0,
|
||||
tick: 0,
|
||||
strafe_tick_num: 100,//100t
|
||||
@ -385,8 +469,8 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
temp_control_dir: glam::Vec3::ZERO,
|
||||
walkspeed: 18.0,
|
||||
contacts: std::collections::HashSet::new(),
|
||||
models_cringe_clone: modeldatas.iter().map(|m|m.transforms.iter().map(|t|strafe_client::body::Model::new(*t))).flatten().collect(),
|
||||
walk: strafe_client::body::WalkState::new(),
|
||||
models: Vec::new(),
|
||||
walk: body::WalkState::new(),
|
||||
hitbox_halfsize: glam::vec3(1.0,2.5,1.0),
|
||||
};
|
||||
|
||||
@ -411,9 +495,22 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
wgpu::TextureFormat::Bgra8UnormSrgb
|
||||
};
|
||||
|
||||
let bytes = match skybox_format {
|
||||
wgpu::TextureFormat::Astc {
|
||||
block: AstcBlock::B4x4,
|
||||
channel: AstcChannel::UnormSrgb,
|
||||
} => &include_bytes!("../images/astc.dds")[..],
|
||||
wgpu::TextureFormat::Etc2Rgb8UnormSrgb => &include_bytes!("../images/etc2.dds")[..],
|
||||
wgpu::TextureFormat::Bc1RgbaUnormSrgb => &include_bytes!("../images/bc1.dds")[..],
|
||||
wgpu::TextureFormat::Bgra8UnormSrgb => &include_bytes!("../images/bgra.dds")[..],
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let skybox_image = ddsfile::Dds::read(&mut std::io::Cursor::new(bytes)).unwrap();
|
||||
|
||||
let size = wgpu::Extent3d {
|
||||
width: IMAGE_SIZE,
|
||||
height: IMAGE_SIZE,
|
||||
width: skybox_image.get_width(),
|
||||
height: skybox_image.get_height(),
|
||||
depth_or_array_layers: 6,
|
||||
};
|
||||
|
||||
@ -426,24 +523,11 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
log::debug!(
|
||||
"Copying {:?} skybox images of size {}, {}, 6 with {} mips to gpu",
|
||||
skybox_format,
|
||||
IMAGE_SIZE,
|
||||
IMAGE_SIZE,
|
||||
size.width,
|
||||
size.height,
|
||||
max_mips,
|
||||
);
|
||||
|
||||
let bytes = match skybox_format {
|
||||
wgpu::TextureFormat::Astc {
|
||||
block: AstcBlock::B4x4,
|
||||
channel: AstcChannel::UnormSrgb,
|
||||
} => &include_bytes!("../images/astc.dds")[..],
|
||||
wgpu::TextureFormat::Etc2Rgb8UnormSrgb => &include_bytes!("../images/etc2.dds")[..],
|
||||
wgpu::TextureFormat::Bc1RgbaUnormSrgb => &include_bytes!("../images/bc1.dds")[..],
|
||||
wgpu::TextureFormat::Bgra8UnormSrgb => &include_bytes!("../images/bgra.dds")[..],
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let skybox_image = ddsfile::Dds::read(&mut std::io::Cursor::new(&bytes)).unwrap();
|
||||
|
||||
let skybox_texture = device.create_texture_with_data(
|
||||
queue,
|
||||
&wgpu::TextureDescriptor {
|
||||
@ -468,9 +552,13 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
|
||||
//squid
|
||||
let squid_texture_view={
|
||||
let bytes = include_bytes!("../images/squid.dds");
|
||||
|
||||
let image = ddsfile::Dds::read(&mut std::io::Cursor::new(bytes)).unwrap();
|
||||
|
||||
let size = wgpu::Extent3d {
|
||||
width: 1076,
|
||||
height: 1076,
|
||||
width: image.get_width(),
|
||||
height: image.get_height(),
|
||||
depth_or_array_layers: 1,
|
||||
};
|
||||
|
||||
@ -480,10 +568,6 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
};
|
||||
let max_mips = layer_size.max_mips(wgpu::TextureDimension::D2);
|
||||
|
||||
let bytes = &include_bytes!("../images/squid.dds")[..];
|
||||
|
||||
let image = ddsfile::Dds::read(&mut std::io::Cursor::new(&bytes)).unwrap();
|
||||
|
||||
let texture = device.create_texture_with_data(
|
||||
queue,
|
||||
&wgpu::TextureDescriptor {
|
||||
@ -506,43 +590,6 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
})
|
||||
};
|
||||
|
||||
//drain the modeldata vec so entities can be /moved/ to models.entities
|
||||
let mut models = Vec::<ModelGraphics>::with_capacity(modeldatas.len());
|
||||
for (i,modeldata) in modeldatas.drain(..).enumerate() {
|
||||
let model_uniforms = get_transform_uniform_data(&modeldata.transforms);
|
||||
let model_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some(format!("ModelGraphics{}",i).as_str()),
|
||||
contents: bytemuck::cast_slice(&model_uniforms),
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
});
|
||||
let model_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &model_bind_group_layout,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: model_buf.as_entire_binding(),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::TextureView(&squid_texture_view),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 2,
|
||||
resource: wgpu::BindingResource::Sampler(&repeat_sampler),
|
||||
},
|
||||
],
|
||||
label: Some(format!("ModelGraphics{}",i).as_str()),
|
||||
});
|
||||
//all of these are being moved here
|
||||
models.push(ModelGraphics{
|
||||
transforms: modeldata.transforms,
|
||||
vertex_buf:modeldata.vertex_buf,
|
||||
entities: modeldata.entities,
|
||||
bind_group: model_bind_group,
|
||||
model_buf,
|
||||
})
|
||||
}
|
||||
|
||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: None,
|
||||
bind_group_layouts: &[
|
||||
@ -590,7 +637,7 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
buffers: &[wgpu::VertexBufferLayout {
|
||||
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
|
||||
step_mode: wgpu::VertexStepMode::Vertex,
|
||||
attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2, 2 => Float32x3],
|
||||
attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2, 2 => Float32x3, 3 => Float32x4],
|
||||
}],
|
||||
},
|
||||
fragment: Some(wgpu::FragmentState {
|
||||
@ -646,7 +693,7 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
|
||||
let depth_view = Self::create_depth_texture(config, device);
|
||||
|
||||
GraphicsData {
|
||||
let mut graphics=GraphicsData {
|
||||
start_time: Instant::now(),
|
||||
camera,
|
||||
physics,
|
||||
@ -659,15 +706,78 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
skybox_texture:skybox_texture_bind_group,
|
||||
},
|
||||
camera_buf,
|
||||
models,
|
||||
models: Vec::new(),
|
||||
depth_view,
|
||||
staging_belt: wgpu::util::StagingBelt::new(0x100),
|
||||
}
|
||||
bind_group_layouts: GraphicsBindGroupLayouts { model: model_bind_group_layout },
|
||||
samplers: GraphicsSamplers { repeat: repeat_sampler },
|
||||
temp_squid_texture_view: squid_texture_view,
|
||||
};
|
||||
|
||||
graphics.generate_model_physics(&modeldatas);
|
||||
graphics.generate_model_graphics(&device,&queue,modeldatas,Vec::new());
|
||||
|
||||
return graphics;
|
||||
}
|
||||
|
||||
#[allow(clippy::single_match)]
|
||||
fn update(&mut self, event: winit::event::WindowEvent) {
|
||||
fn update(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, event: winit::event::WindowEvent) {
|
||||
//nothing atm
|
||||
match event {
|
||||
winit::event::WindowEvent::DroppedFile(path) => {
|
||||
println!("opening file: {:?}", &path);
|
||||
//oh boy! let's load the map!
|
||||
if let Ok(file)=std::fs::File::open(path){
|
||||
let mut input = std::io::BufReader::new(file);
|
||||
let mut first_8=[0u8;8];
|
||||
//.rbxm roblox binary = "<roblox!"
|
||||
//.rbxmx roblox xml = "<roblox "
|
||||
//.bsp = "VBSP"
|
||||
//.vmf =
|
||||
//.snf = "SNMF"
|
||||
//.snf = "SNBF"
|
||||
if let (Ok(()),Ok(()))=(std::io::Read::read_exact(&mut input, &mut first_8),std::io::Seek::rewind(&mut input)){
|
||||
//
|
||||
if let Some(Ok((modeldatas,textures,spawn_point)))={
|
||||
if &first_8==b"<roblox!"{
|
||||
if let Ok(dom) = rbx_binary::from_reader(input){
|
||||
Some(load_roblox::generate_modeldatas_roblox(dom))
|
||||
}else{
|
||||
None
|
||||
}
|
||||
}else if &first_8==b"<roblox "{
|
||||
if let Ok(dom) = rbx_xml::from_reader(input,rbx_xml::DecodeOptions::default()){
|
||||
Some(load_roblox::generate_modeldatas_roblox(dom))
|
||||
}else{
|
||||
None
|
||||
}
|
||||
//}else if &first_8[0..4]==b"VBSP"{
|
||||
// self.generate_modeldatas_valve(input)
|
||||
}else{
|
||||
None
|
||||
}
|
||||
}{
|
||||
//if generate_modeldatas succeeds, clear the previous ones
|
||||
self.models.clear();
|
||||
self.physics.models.clear();
|
||||
self.generate_model_physics(&modeldatas);
|
||||
self.generate_model_graphics(device,queue,modeldatas,textures);
|
||||
//manual reset
|
||||
let time=self.physics.time;
|
||||
instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{
|
||||
time,
|
||||
instruction: body::PhysicsInstruction::SetPosition(spawn_point),
|
||||
})
|
||||
}else{
|
||||
println!("No modeldatas were generated");
|
||||
}
|
||||
}else{
|
||||
println!("Failed ro read first 8 bytes and seek back to beginning of file.");
|
||||
}
|
||||
}else{
|
||||
println!("Could not open file");
|
||||
}
|
||||
},
|
||||
winit::event::WindowEvent::KeyboardInput {
|
||||
input:
|
||||
winit::event::KeyboardInput {
|
||||
@ -737,7 +847,7 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
view: &wgpu::TextureView,
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
_spawner: &strafe_client::framework::Spawner,
|
||||
_spawner: &framework::Spawner,
|
||||
) {
|
||||
let camera_mat=glam::Mat3::from_rotation_y(self.camera.yaw);
|
||||
let control_dir=camera_mat*get_control_dir(self.camera.controls&(CONTROL_MOVELEFT|CONTROL_MOVERIGHT|CONTROL_MOVEFORWARD|CONTROL_MOVEBACK)).normalize_or_zero();
|
||||
@ -750,16 +860,16 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
let walk_target_velocity=self.physics.walkspeed*control_dir;
|
||||
//autohop (already pressing spacebar; the signal to begin trying to jump is different)
|
||||
if self.physics.grounded&&walk_target_velocity!=self.physics.walk.target_velocity {
|
||||
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
|
||||
instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{
|
||||
time,
|
||||
instruction:strafe_client::body::PhysicsInstruction::SetWalkTargetVelocity(walk_target_velocity)
|
||||
instruction:body::PhysicsInstruction::SetWalkTargetVelocity(walk_target_velocity)
|
||||
});
|
||||
}
|
||||
|
||||
if control_dir!=self.physics.temp_control_dir {
|
||||
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
|
||||
instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{
|
||||
time,
|
||||
instruction:strafe_client::body::PhysicsInstruction::SetControlDir(control_dir)
|
||||
instruction:body::PhysicsInstruction::SetControlDir(control_dir)
|
||||
});
|
||||
}
|
||||
|
||||
@ -767,9 +877,9 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
//autohop (already pressing spacebar; the signal to begin trying to jump is different)
|
||||
if self.physics.grounded&&self.physics.jump_trying {
|
||||
//scroll will be implemented with InputInstruction::Jump(true) but it blocks setting self.jump_trying=true
|
||||
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
|
||||
instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{
|
||||
time,
|
||||
instruction:strafe_client::body::PhysicsInstruction::Jump
|
||||
instruction:body::PhysicsInstruction::Jump
|
||||
});
|
||||
}
|
||||
|
||||
@ -789,7 +899,7 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
.copy_from_slice(bytemuck::cast_slice(&camera_uniforms));
|
||||
//This code only needs to run when the uniforms change
|
||||
for model in self.models.iter() {
|
||||
let model_uniforms = get_transform_uniform_data(&model.transforms);
|
||||
let model_uniforms = get_instances_buffer_data(&model.instances);
|
||||
self.staging_belt
|
||||
.write_buffer(
|
||||
&mut encoder,
|
||||
@ -838,7 +948,7 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
|
||||
for entity in model.entities.iter() {
|
||||
rpass.set_index_buffer(entity.index_buf.slice(..), wgpu::IndexFormat::Uint16);
|
||||
rpass.draw_indexed(0..entity.index_count, 0, 0..model.transforms.len() as u32);
|
||||
rpass.draw_indexed(0..entity.index_count, 0, 0..model.instances.len() as u32);
|
||||
}
|
||||
}
|
||||
|
||||
@ -853,7 +963,7 @@ impl strafe_client::framework::Example for GraphicsData {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
strafe_client::framework::run::<GraphicsData>(
|
||||
framework::run::<GraphicsData>(
|
||||
format!("Strafe Client v{}",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
).as_str()
|
||||
|
70
src/model.rs
Normal file
70
src/model.rs
Normal file
@ -0,0 +1,70 @@
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
#[derive(Clone, Copy, Pod, Zeroable)]
|
||||
#[repr(C)]
|
||||
pub struct Vertex {
|
||||
pub pos: [f32; 3],
|
||||
pub texture: [f32; 2],
|
||||
pub normal: [f32; 3],
|
||||
pub color: [f32; 4],
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ModelInstance {
|
||||
pub transform: glam::Mat4,
|
||||
pub color: glam::Vec4,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ModelData {
|
||||
pub instances: Vec<ModelInstance>,
|
||||
pub vertices: Vec<Vertex>,
|
||||
pub entities: Vec<Vec<u16>>,
|
||||
pub texture: Option<u32>,
|
||||
}
|
||||
|
||||
impl ModelData {
|
||||
pub const COLOR_FLOATS_WHITE: [f32;4] = [1.0,1.0,1.0,1.0];
|
||||
pub const COLOR_VEC4_WHITE: glam::Vec4 = glam::vec4(1.0,1.0,1.0,1.0);
|
||||
}
|
||||
|
||||
pub fn generate_modeldatas(data:obj::ObjData,color:[f32;4]) -> Vec<ModelData>{
|
||||
let mut modeldatas=Vec::new();
|
||||
let mut vertices = Vec::new();
|
||||
let mut vertex_index = std::collections::HashMap::<obj::IndexTuple,u16>::new();
|
||||
for object in data.objects {
|
||||
vertices.clear();
|
||||
vertex_index.clear();
|
||||
let mut entities = Vec::new();
|
||||
for group in object.groups {
|
||||
let mut indices = Vec::new();
|
||||
for poly in group.polys {
|
||||
for end_index in 2..poly.0.len() {
|
||||
for &index in &[0, end_index - 1, end_index] {
|
||||
let vert = poly.0[index];
|
||||
if let Some(&i)=vertex_index.get(&vert){
|
||||
indices.push(i);
|
||||
}else{
|
||||
let i=vertices.len() as u16;
|
||||
vertices.push(Vertex {
|
||||
pos: data.position[vert.0],
|
||||
texture: data.texture[vert.1.unwrap()],
|
||||
normal: data.normal[vert.2.unwrap()],
|
||||
color,
|
||||
});
|
||||
vertex_index.insert(vert,i);
|
||||
indices.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
entities.push(indices);
|
||||
}
|
||||
modeldatas.push(ModelData {
|
||||
instances: Vec::new(),
|
||||
vertices:vertices.clone(),
|
||||
entities,
|
||||
texture: None,
|
||||
});
|
||||
}
|
||||
modeldatas
|
||||
}
|
76
src/primitives.rs
Normal file
76
src/primitives.rs
Normal file
@ -0,0 +1,76 @@
|
||||
pub fn the_unit_cube_lol() -> obj::ObjData{
|
||||
obj::ObjData{
|
||||
position: vec![
|
||||
[-1.,-1., 1.],//left bottom back
|
||||
[ 1.,-1., 1.],//right bottom back
|
||||
[ 1., 1., 1.],//right top back
|
||||
[-1., 1., 1.],//left top back
|
||||
[-1., 1.,-1.],//left top front
|
||||
[ 1., 1.,-1.],//right top front
|
||||
[ 1.,-1.,-1.],//right bottom front
|
||||
[-1.,-1.,-1.],//left bottom front
|
||||
],
|
||||
texture: vec![[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0]],
|
||||
normal: vec![
|
||||
[1.,0.,0.],//AabbFace::Right
|
||||
[0.,1.,0.],//AabbFace::Top
|
||||
[0.,0.,1.],//AabbFace::Back
|
||||
[-1.,0.,0.],//AabbFace::Left
|
||||
[0.,-1.,0.],//AabbFace::Bottom
|
||||
[0.,0.,-1.],//AabbFace::Front
|
||||
],
|
||||
objects: vec![obj::Object{
|
||||
name: "Unit Cube".to_owned(),
|
||||
groups: vec![obj::Group{
|
||||
name: "Cube Vertices".to_owned(),
|
||||
index: 0,
|
||||
material: None,
|
||||
polys: vec![
|
||||
// back (0, 0, 1)
|
||||
obj::SimplePolygon(vec![
|
||||
obj::IndexTuple(0,Some(0),Some(2)),
|
||||
obj::IndexTuple(1,Some(1),Some(2)),
|
||||
obj::IndexTuple(2,Some(2),Some(2)),
|
||||
obj::IndexTuple(3,Some(3),Some(2)),
|
||||
]),
|
||||
// front (0, 0,-1)
|
||||
obj::SimplePolygon(vec![
|
||||
obj::IndexTuple(4,Some(0),Some(5)),
|
||||
obj::IndexTuple(5,Some(1),Some(5)),
|
||||
obj::IndexTuple(6,Some(2),Some(5)),
|
||||
obj::IndexTuple(7,Some(3),Some(5)),
|
||||
]),
|
||||
// right (1, 0, 0)
|
||||
obj::SimplePolygon(vec![
|
||||
obj::IndexTuple(6,Some(0),Some(0)),
|
||||
obj::IndexTuple(5,Some(1),Some(0)),
|
||||
obj::IndexTuple(2,Some(2),Some(0)),
|
||||
obj::IndexTuple(1,Some(3),Some(0)),
|
||||
]),
|
||||
// left (-1, 0, 0)
|
||||
obj::SimplePolygon(vec![
|
||||
obj::IndexTuple(0,Some(0),Some(3)),
|
||||
obj::IndexTuple(3,Some(1),Some(3)),
|
||||
obj::IndexTuple(4,Some(2),Some(3)),
|
||||
obj::IndexTuple(7,Some(3),Some(3)),
|
||||
]),
|
||||
// top (0, 1, 0)
|
||||
obj::SimplePolygon(vec![
|
||||
obj::IndexTuple(5,Some(1),Some(1)),
|
||||
obj::IndexTuple(4,Some(0),Some(1)),
|
||||
obj::IndexTuple(3,Some(3),Some(1)),
|
||||
obj::IndexTuple(2,Some(2),Some(1)),
|
||||
]),
|
||||
// bottom (0,-1, 0)
|
||||
obj::SimplePolygon(vec![
|
||||
obj::IndexTuple(1,Some(1),Some(4)),
|
||||
obj::IndexTuple(0,Some(0),Some(4)),
|
||||
obj::IndexTuple(7,Some(3),Some(4)),
|
||||
obj::IndexTuple(6,Some(2),Some(4)),
|
||||
]),
|
||||
],
|
||||
}]
|
||||
}],
|
||||
material_libs: Vec::new(),
|
||||
}
|
||||
}
|
@ -41,15 +41,18 @@ fn vs_sky(@builtin(vertex_index) vertex_index: u32) -> SkyOutput {
|
||||
return result;
|
||||
}
|
||||
|
||||
const MAX_ENTITY_INSTANCES=1024;
|
||||
//group 1 is the model
|
||||
@group(1)
|
||||
@binding(0)
|
||||
var<uniform> entity_transforms: array<mat4x4<f32>,MAX_ENTITY_INSTANCES>;
|
||||
//var<uniform> entity_texture_transforms: array<mat3x3<f32>,MAX_ENTITY_INSTANCES>;
|
||||
struct ModelInstance{
|
||||
transform:mat4x4<f32>,
|
||||
//texture_transform:mat3x3<f32>,
|
||||
color:vec4<f32>,
|
||||
}
|
||||
//my fancy idea is to create a megatexture for each model that includes all the textures each intance will need
|
||||
//the texture transform then maps the texture coordinates to the location of the specific texture
|
||||
//how to do no texture?
|
||||
//group 1 is the model
|
||||
const MAX_MODEL_INSTANCES=4096;
|
||||
@group(1)
|
||||
@binding(0)
|
||||
var<uniform> model_instances: array<ModelInstance, MAX_MODEL_INSTANCES>;
|
||||
@group(1)
|
||||
@binding(1)
|
||||
var model_texture: texture_2d<f32>;
|
||||
@ -62,6 +65,7 @@ struct EntityOutputTexture {
|
||||
@location(1) texture: vec2<f32>,
|
||||
@location(2) normal: vec3<f32>,
|
||||
@location(3) view: vec3<f32>,
|
||||
@location(4) color: vec4<f32>,
|
||||
};
|
||||
@vertex
|
||||
fn vs_entity_texture(
|
||||
@ -69,11 +73,13 @@ fn vs_entity_texture(
|
||||
@location(0) pos: vec3<f32>,
|
||||
@location(1) texture: vec2<f32>,
|
||||
@location(2) normal: vec3<f32>,
|
||||
@location(3) color: vec4<f32>,
|
||||
) -> EntityOutputTexture {
|
||||
var position: vec4<f32> = entity_transforms[instance] * vec4<f32>(pos, 1.0);
|
||||
var position: vec4<f32> = model_instances[instance].transform * vec4<f32>(pos, 1.0);
|
||||
var result: EntityOutputTexture;
|
||||
result.normal = (entity_transforms[instance] * vec4<f32>(normal, 0.0)).xyz;
|
||||
result.texture=texture;//(entity_texture_transforms[instance] * vec3<f32>(texture, 1.0)).xy;
|
||||
result.normal = (model_instances[instance].transform * vec4<f32>(normal, 0.0)).xyz;
|
||||
result.texture=texture;//(model_instances[instance].texture_transform * vec3<f32>(texture, 1.0)).xy;
|
||||
result.color=model_instances[instance].color * color;
|
||||
result.view = position.xyz - camera.cam_pos.xyz;
|
||||
result.position = camera.proj * camera.view * position;
|
||||
return result;
|
||||
@ -99,7 +105,7 @@ fn fs_entity_texture(vertex: EntityOutputTexture) -> @location(0) vec4<f32> {
|
||||
let d = dot(normal, incident);
|
||||
let reflected = incident - 2.0 * d * normal;
|
||||
|
||||
let fragment_color = textureSample(model_texture, model_sampler, vertex.texture).rgb;
|
||||
let fragment_color = textureSample(model_texture, model_sampler, vertex.texture)*vertex.color;
|
||||
let reflected_color = textureSample(cube_texture, cube_sampler, reflected).rgb;
|
||||
return vec4<f32>(mix(vec3<f32>(0.1) + 0.5 * reflected_color,fragment_color,1.0-pow(1.0-abs(d),2.0)), 1.0);
|
||||
return mix(vec4<f32>(vec3<f32>(0.1) + 0.5 * reflected_color,1.0),fragment_color,1.0-pow(1.0-abs(d),2.0));
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
//find roots of polynomials
|
||||
#[inline]
|
||||
pub fn zeroes2(a0:f32,a1:f32,a2:f32) -> Vec<f32>{
|
||||
if a2==0f32{
|
||||
return zeroes1(a0, a1);
|
||||
|
Reference in New Issue
Block a user