Compare commits
6 Commits
thread-tex
...
redo-input
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d9d4efedb | |||
| bd04f680d8 | |||
| 46cc082c07 | |||
| 55fcdb8e27 | |||
| d7df468388 | |||
| 990199b4c7 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1 @@
|
|||||||
/target
|
/target
|
||||||
/textures
|
|
||||||
281
Cargo.lock
generated
281
Cargo.lock
generated
@@ -157,12 +157,6 @@ dependencies = [
|
|||||||
"rustc-demangle",
|
"rustc-demangle",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "base64"
|
|
||||||
version = "0.13.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bit-set"
|
name = "bit-set"
|
||||||
version = "0.5.3"
|
version = "0.5.3"
|
||||||
@@ -190,35 +184,12 @@ version = "2.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
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]]
|
[[package]]
|
||||||
name = "block"
|
name = "block"
|
||||||
version = "0.1.6"
|
version = "0.1.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
|
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]]
|
[[package]]
|
||||||
name = "block-sys"
|
name = "block-sys"
|
||||||
version = "0.1.0-beta.1"
|
version = "0.1.0-beta.1"
|
||||||
@@ -331,12 +302,6 @@ dependencies = [
|
|||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "constant_time_eq"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.3"
|
version = "0.9.3"
|
||||||
@@ -395,16 +360,6 @@ dependencies = [
|
|||||||
"cfg-if",
|
"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]]
|
[[package]]
|
||||||
name = "d3d12"
|
name = "d3d12"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
@@ -427,17 +382,6 @@ dependencies = [
|
|||||||
"enum_primitive",
|
"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]]
|
[[package]]
|
||||||
name = "dispatch"
|
name = "dispatch"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -611,16 +555,6 @@ dependencies = [
|
|||||||
"waker-fn",
|
"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]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.10"
|
version = "0.2.10"
|
||||||
@@ -888,26 +822,6 @@ version = "0.4.20"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
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]]
|
[[package]]
|
||||||
name = "malloc_buf"
|
name = "malloc_buf"
|
||||||
version = "0.0.6"
|
version = "0.0.6"
|
||||||
@@ -1284,12 +1198,6 @@ version = "0.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2"
|
checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ppv-lite86"
|
|
||||||
version = "0.2.17"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-crate"
|
name = "proc-macro-crate"
|
||||||
version = "1.3.1"
|
version = "1.3.1"
|
||||||
@@ -1314,19 +1222,6 @@ name = "profiling"
|
|||||||
version = "1.0.9"
|
version = "1.0.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "46b2164ebdb1dfeec5e337be164292351e11daf63a05174c6776b2f47460f0c9"
|
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]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
@@ -1337,36 +1232,6 @@ dependencies = [
|
|||||||
"proc-macro2",
|
"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]]
|
[[package]]
|
||||||
name = "range-alloc"
|
name = "range-alloc"
|
||||||
version = "0.1.3"
|
version = "0.1.3"
|
||||||
@@ -1379,83 +1244,6 @@ version = "0.5.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
|
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]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.3.5"
|
version = "0.3.5"
|
||||||
@@ -1467,9 +1255,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.9.5"
|
version = "1.9.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47"
|
checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"memchr",
|
"memchr",
|
||||||
@@ -1479,9 +1267,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex-automata"
|
name = "regex-automata"
|
||||||
version = "0.3.8"
|
version = "0.3.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795"
|
checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"memchr",
|
"memchr",
|
||||||
@@ -1500,28 +1288,6 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b"
|
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]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.23"
|
version = "0.1.23"
|
||||||
@@ -1572,26 +1338,6 @@ dependencies = [
|
|||||||
"tiny-skia",
|
"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]]
|
[[package]]
|
||||||
name = "simd-adler32"
|
name = "simd-adler32"
|
||||||
version = "0.3.7"
|
version = "0.3.7"
|
||||||
@@ -1659,7 +1405,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strafe-client"
|
name = "strafe-client"
|
||||||
version = "0.7.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-executor",
|
"async-executor",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
@@ -1669,11 +1415,6 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"obj",
|
"obj",
|
||||||
"pollster",
|
"pollster",
|
||||||
"rbx_binary",
|
|
||||||
"rbx_dom_weak",
|
|
||||||
"rbx_reflection_database",
|
|
||||||
"rbx_xml",
|
|
||||||
"regex",
|
|
||||||
"wgpu",
|
"wgpu",
|
||||||
"winit",
|
"winit",
|
||||||
]
|
]
|
||||||
@@ -1684,12 +1425,6 @@ version = "0.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
|
checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "subtle"
|
|
||||||
version = "2.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.109"
|
version = "1.0.109"
|
||||||
@@ -1789,12 +1524,6 @@ version = "0.19.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a464a4b34948a5f67fddd2b823c62d9d92e44be75058b99939eae6c5b6960b33"
|
checksum = "a464a4b34948a5f67fddd2b823c62d9d92e44be75058b99939eae6c5b6960b33"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "typenum"
|
|
||||||
version = "1.16.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.11"
|
version = "1.0.11"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "strafe-client"
|
name = "strafe-client"
|
||||||
version = "0.7.0"
|
version = "0.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
@@ -14,11 +14,6 @@ glam = "0.24.1"
|
|||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
obj = "0.10.2"
|
obj = "0.10.2"
|
||||||
pollster = "0.3.0"
|
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"
|
wgpu = "0.17.0"
|
||||||
winit = "0.28.6"
|
winit = "0.28.6"
|
||||||
|
|
||||||
|
|||||||
81
src/body.rs
81
src/body.rs
@@ -12,10 +12,8 @@ pub enum PhysicsInstruction {
|
|||||||
// bool,//true = Trigger; false = teleport
|
// bool,//true = Trigger; false = teleport
|
||||||
// bool,//true = Force
|
// bool,//true = Force
|
||||||
// )
|
// )
|
||||||
//InputInstructions conditionally activate RefreshWalkTarget (by doing what SetWalkTargetVelocity used to do and then flagging it)
|
//Both of these conditionally activate RefreshWalkTarget (by doing what SetWalkTargetVelocity used to do and then flagging it)
|
||||||
Input(InputInstruction),
|
Input(InputInstruction),
|
||||||
//temp
|
|
||||||
SetSpawnPosition(glam::Vec3),
|
|
||||||
}
|
}
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum InputInstruction {
|
pub enum InputInstruction {
|
||||||
@@ -29,10 +27,6 @@ pub enum InputInstruction {
|
|||||||
Jump(bool),
|
Jump(bool),
|
||||||
Zoom(bool),
|
Zoom(bool),
|
||||||
Reset,
|
Reset,
|
||||||
Idle,
|
|
||||||
//Idle: there were no input events, but the simulation is safe to advance to this timestep
|
|
||||||
//for interpolation / networking / playback reasons, most playback heads will always want
|
|
||||||
//to be 1 instruction ahead to generate the next state for interpolation.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Body {
|
pub struct Body {
|
||||||
@@ -193,20 +187,20 @@ impl Camera {
|
|||||||
offset,
|
offset,
|
||||||
angles: glam::DVec2::ZERO,
|
angles: glam::DVec2::ZERO,
|
||||||
fov: glam::vec2(aspect,1.0),
|
fov: glam::vec2(aspect,1.0),
|
||||||
sensitivity: glam::dvec2(1.0/6144.0,1.0/6144.0),
|
sensitivity: glam::dvec2(1.0/2048.0,1.0/2048.0),
|
||||||
time: 0,
|
time: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn simulate_move_angles(&self, delta: glam::IVec2) -> glam::DVec2 {
|
fn simulate_move_angles(&self, delta: glam::IVec2) -> glam::DVec2 {
|
||||||
let mut a=self.angles-self.sensitivity*delta.as_dvec2();
|
let mut a=self.angles-self.sensitivity*delta.as_dvec2();
|
||||||
a.y=a.y.clamp(-std::f64::consts::FRAC_PI_2, std::f64::consts::FRAC_PI_2);
|
a.y=a.y.clamp(-std::f64::consts::PI, std::f64::consts::PI);
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
fn simulate_move_rotation_y(&self, delta_x: i32) -> glam::Mat3 {
|
fn simulate_move_rotation_y(&self, delta_x: i32) -> glam::Mat3 {
|
||||||
mat3_from_rotation_y_f64(self.angles.x-self.sensitivity.x*(delta_x as f64))
|
mat3_from_rotation_y_f64(self.angles.x-self.sensitivity.x*(delta_x as f64))
|
||||||
}
|
}
|
||||||
pub fn proj(&self)->glam::Mat4{
|
pub fn proj(&self)->glam::Mat4{
|
||||||
perspective_rh(self.fov.x, self.fov.y, 0.5, 2000.0)
|
perspective_rh(self.fov.x, self.fov.y, 0.5, 1000.0)
|
||||||
}
|
}
|
||||||
pub fn view(&self,pos:glam::Vec3)->glam::Mat4{
|
pub fn view(&self,pos:glam::Vec3)->glam::Mat4{
|
||||||
//f32 good enough for view matrix
|
//f32 good enough for view matrix
|
||||||
@@ -260,7 +254,8 @@ pub struct PhysicsState {
|
|||||||
pub hitbox_halfsize: glam::Vec3,
|
pub hitbox_halfsize: glam::Vec3,
|
||||||
pub contacts: std::collections::HashSet::<RelativeCollision>,
|
pub contacts: std::collections::HashSet::<RelativeCollision>,
|
||||||
//pub intersections: Vec<ModelId>,
|
//pub intersections: Vec<ModelId>,
|
||||||
pub models: Vec<ModelPhysics>,
|
//temp
|
||||||
|
pub models_cringe_clone: Vec<Model>,
|
||||||
//camera must exist in state because wormholes modify the camera, also camera punch
|
//camera must exist in state because wormholes modify the camera, also camera punch
|
||||||
pub camera: Camera,
|
pub camera: Camera,
|
||||||
pub mouse_interpolation: MouseInterpolationState,
|
pub mouse_interpolation: MouseInterpolationState,
|
||||||
@@ -276,7 +271,6 @@ pub struct PhysicsState {
|
|||||||
pub walk_accel: f32,
|
pub walk_accel: f32,
|
||||||
pub gravity: glam::Vec3,
|
pub gravity: glam::Vec3,
|
||||||
pub grounded: bool,
|
pub grounded: bool,
|
||||||
pub spawn_point: glam::Vec3,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
|
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
|
||||||
@@ -288,7 +282,7 @@ pub enum AabbFace{
|
|||||||
Bottom,
|
Bottom,
|
||||||
Front,
|
Front,
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Aabb {
|
pub struct Aabb {
|
||||||
min: glam::Vec3,
|
min: glam::Vec3,
|
||||||
max: glam::Vec3,
|
max: glam::Vec3,
|
||||||
@@ -388,33 +382,31 @@ impl Aabb {
|
|||||||
type TreyMeshFace = AabbFace;
|
type TreyMeshFace = AabbFace;
|
||||||
type TreyMesh = Aabb;
|
type TreyMesh = Aabb;
|
||||||
|
|
||||||
pub struct ModelPhysics {
|
pub struct Model {
|
||||||
//A model is a thing that has a hitbox. can be represented by a list of TreyMesh-es
|
//A model is a thing that has a hitbox. can be represented by a list of TreyMesh-es
|
||||||
//in this iteration, all it needs is extents.
|
//in this iteration, all it needs is extents.
|
||||||
mesh: TreyMesh,
|
transform: glam::Mat4,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModelPhysics {
|
impl Model {
|
||||||
pub fn from_model(model:&crate::model::IndexedModel,model_transform:glam::Affine3A) -> Self {
|
pub fn new(transform:glam::Mat4) -> Self {
|
||||||
let mut aabb=Aabb::new();
|
Self{transform}
|
||||||
for indexed_vertex in &model.unique_vertices {
|
|
||||||
aabb.grow(model_transform.transform_point3(glam::Vec3::from_array(model.unique_pos[indexed_vertex.pos as usize])));
|
|
||||||
}
|
|
||||||
Self{
|
|
||||||
mesh:aabb,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn unit_vertices(&self) -> [glam::Vec3;8] {
|
pub fn unit_vertices(&self) -> [glam::Vec3;8] {
|
||||||
Aabb::unit_vertices()
|
Aabb::unit_vertices()
|
||||||
}
|
}
|
||||||
pub fn mesh(&self) -> &TreyMesh {
|
pub fn mesh(&self) -> TreyMesh {
|
||||||
return &self.mesh;
|
let mut aabb=Aabb::new();
|
||||||
|
for &vertex in self.unit_vertices().iter() {
|
||||||
|
aabb.grow(glam::Vec4Swizzles::xyz(self.transform*vertex.extend(1.0)));
|
||||||
|
}
|
||||||
|
return aabb;
|
||||||
}
|
}
|
||||||
pub fn unit_face_vertices(&self,face:TreyMeshFace) -> [glam::Vec3;4] {
|
pub fn unit_face_vertices(&self,face:TreyMeshFace) -> [glam::Vec3;4] {
|
||||||
Aabb::unit_face_vertices(face)
|
Aabb::unit_face_vertices(face)
|
||||||
}
|
}
|
||||||
pub fn face_mesh(&self,face:TreyMeshFace) -> TreyMesh {
|
pub fn face_mesh(&self,face:TreyMeshFace) -> TreyMesh {
|
||||||
let mut aabb=self.mesh.clone();
|
let mut aabb=self.mesh();
|
||||||
//in this implementation face = worldspace aabb face
|
//in this implementation face = worldspace aabb face
|
||||||
match face {
|
match face {
|
||||||
AabbFace::Right => aabb.min.x=aabb.max.x,
|
AabbFace::Right => aabb.min.x=aabb.max.x,
|
||||||
@@ -427,7 +419,7 @@ impl ModelPhysics {
|
|||||||
return aabb;
|
return aabb;
|
||||||
}
|
}
|
||||||
pub fn face_normal(&self,face:TreyMeshFace) -> glam::Vec3 {
|
pub fn face_normal(&self,face:TreyMeshFace) -> glam::Vec3 {
|
||||||
Aabb::normal(face)//this is wrong for scale
|
glam::Vec4Swizzles::xyz(Aabb::normal(face).extend(0.0))//this is wrong for scale
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,10 +432,10 @@ pub struct RelativeCollision {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RelativeCollision {
|
impl RelativeCollision {
|
||||||
pub fn mesh(&self,models:&Vec<ModelPhysics>) -> TreyMesh {
|
pub fn mesh(&self,models:&Vec<Model>) -> TreyMesh {
|
||||||
return models.get(self.model as usize).unwrap().face_mesh(self.face).clone()
|
return models.get(self.model as usize).unwrap().face_mesh(self.face)
|
||||||
}
|
}
|
||||||
pub fn normal(&self,models:&Vec<ModelPhysics>) -> glam::Vec3 {
|
pub fn normal(&self,models:&Vec<Model>) -> glam::Vec3 {
|
||||||
return models.get(self.model as usize).unwrap().face_normal(self.face)
|
return models.get(self.model as usize).unwrap().face_normal(self.face)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -502,7 +494,7 @@ impl PhysicsState {
|
|||||||
|
|
||||||
fn contact_constrain_velocity(&self,velocity:&mut glam::Vec3){
|
fn contact_constrain_velocity(&self,velocity:&mut glam::Vec3){
|
||||||
for contact in self.contacts.iter() {
|
for contact in self.contacts.iter() {
|
||||||
let n=contact.normal(&self.models);
|
let n=contact.normal(&self.models_cringe_clone);
|
||||||
let d=velocity.dot(n);
|
let d=velocity.dot(n);
|
||||||
if d<0f32{
|
if d<0f32{
|
||||||
(*velocity)-=d/n.length_squared()*n;
|
(*velocity)-=d/n.length_squared()*n;
|
||||||
@@ -511,7 +503,7 @@ impl PhysicsState {
|
|||||||
}
|
}
|
||||||
fn contact_constrain_acceleration(&self,acceleration:&mut glam::Vec3){
|
fn contact_constrain_acceleration(&self,acceleration:&mut glam::Vec3){
|
||||||
for contact in self.contacts.iter() {
|
for contact in self.contacts.iter() {
|
||||||
let n=contact.normal(&self.models);
|
let n=contact.normal(&self.models_cringe_clone);
|
||||||
let d=acceleration.dot(n);
|
let d=acceleration.dot(n);
|
||||||
if d<0f32{
|
if d<0f32{
|
||||||
(*acceleration)-=d/n.length_squared()*n;
|
(*acceleration)-=d/n.length_squared()*n;
|
||||||
@@ -611,7 +603,7 @@ impl PhysicsState {
|
|||||||
let mut best_time=time_limit;
|
let mut best_time=time_limit;
|
||||||
let mut exit_face:Option<TreyMeshFace>=None;
|
let mut exit_face:Option<TreyMeshFace>=None;
|
||||||
let mesh0=self.mesh();
|
let mesh0=self.mesh();
|
||||||
let mesh1=self.models.get(collision_data.model as usize).unwrap().mesh();
|
let mesh1=self.models_cringe_clone.get(collision_data.model as usize).unwrap().mesh();
|
||||||
let (v,a)=(-self.body.velocity,self.body.acceleration);
|
let (v,a)=(-self.body.velocity,self.body.acceleration);
|
||||||
//collect x
|
//collect x
|
||||||
match collision_data.face {
|
match collision_data.face {
|
||||||
@@ -762,7 +754,7 @@ impl PhysicsState {
|
|||||||
let mut best_time=time_limit;
|
let mut best_time=time_limit;
|
||||||
let mut best_face:Option<TreyMeshFace>=None;
|
let mut best_face:Option<TreyMeshFace>=None;
|
||||||
let mesh0=self.mesh();
|
let mesh0=self.mesh();
|
||||||
let mesh1=self.models.get(model_id as usize).unwrap().mesh();
|
let mesh1=self.models_cringe_clone.get(model_id as usize).unwrap().mesh();
|
||||||
let (p,v,a)=(self.body.position,self.body.velocity,self.body.acceleration);
|
let (p,v,a)=(self.body.position,self.body.velocity,self.body.acceleration);
|
||||||
//collect x
|
//collect x
|
||||||
for t in zeroes2(mesh0.max.x-mesh1.min.x,v.x,0.5*a.x) {
|
for t in zeroes2(mesh0.max.x-mesh1.min.x,v.x,0.5*a.x) {
|
||||||
@@ -887,7 +879,7 @@ impl crate::instruction::InstructionEmitter<PhysicsInstruction> for PhysicsState
|
|||||||
collector.collect(self.predict_collision_end(self.time,time_limit,collision_data));
|
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!!)
|
//check for collision start instructions (against every part in the game with no optimization!!)
|
||||||
for i in 0..self.models.len() {
|
for i in 0..self.models_cringe_clone.len() {
|
||||||
collector.collect(self.predict_collision_start(self.time,time_limit,i as u32));
|
collector.collect(self.predict_collision_start(self.time,time_limit,i as u32));
|
||||||
}
|
}
|
||||||
if self.grounded {
|
if self.grounded {
|
||||||
@@ -912,16 +904,12 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|||||||
match &ins.instruction {
|
match &ins.instruction {
|
||||||
PhysicsInstruction::Input(InputInstruction::MoveMouse(_)) => (),//dodge time for mouse movement
|
PhysicsInstruction::Input(InputInstruction::MoveMouse(_)) => (),//dodge time for mouse movement
|
||||||
PhysicsInstruction::Input(_)
|
PhysicsInstruction::Input(_)
|
||||||
|PhysicsInstruction::SetSpawnPosition(_)
|
|
||||||
|PhysicsInstruction::ReachWalkTargetVelocity
|
|PhysicsInstruction::ReachWalkTargetVelocity
|
||||||
|PhysicsInstruction::CollisionStart(_)
|
|PhysicsInstruction::CollisionStart(_)
|
||||||
|PhysicsInstruction::CollisionEnd(_)
|
|PhysicsInstruction::CollisionEnd(_)
|
||||||
|PhysicsInstruction::StrafeTick => self.advance_time(ins.time),
|
|PhysicsInstruction::StrafeTick => self.advance_time(ins.time),
|
||||||
}
|
}
|
||||||
match ins.instruction {
|
match ins.instruction {
|
||||||
PhysicsInstruction::SetSpawnPosition(position)=>{
|
|
||||||
self.spawn_point=position;
|
|
||||||
}
|
|
||||||
PhysicsInstruction::CollisionStart(c) => {
|
PhysicsInstruction::CollisionStart(c) => {
|
||||||
//check ground
|
//check ground
|
||||||
match &c.face {
|
match &c.face {
|
||||||
@@ -1017,16 +1005,7 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|||||||
InputInstruction::Zoom(s) => {
|
InputInstruction::Zoom(s) => {
|
||||||
self.set_control(CONTROL_ZOOM,s);
|
self.set_control(CONTROL_ZOOM,s);
|
||||||
},
|
},
|
||||||
InputInstruction::Reset => {
|
InputInstruction::Reset => println!("reset"),
|
||||||
//temp
|
|
||||||
self.body.position=self.spawn_point;
|
|
||||||
//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;
|
|
||||||
},
|
|
||||||
InputInstruction::Idle => (),//literally idle!
|
|
||||||
}
|
}
|
||||||
//calculate control dir
|
//calculate control dir
|
||||||
let camera_mat=self.camera.simulate_move_rotation_y(self.mouse_interpolation.interpolated_position(self.time).x-self.mouse_interpolation.mouse0.x);
|
let camera_mat=self.camera.simulate_move_rotation_y(self.mouse_interpolation.interpolated_position(self.time).x-self.mouse_interpolation.mouse0.x);
|
||||||
@@ -1039,4 +1018,4 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ pub trait Example: 'static + Sized {
|
|||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
queue: &wgpu::Queue,
|
queue: &wgpu::Queue,
|
||||||
);
|
);
|
||||||
fn update(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, event: WindowEvent);
|
fn update(&mut self, event: WindowEvent);
|
||||||
fn device_event(&mut self, event: DeviceEvent);
|
fn device_event(&mut self, event: DeviceEvent);
|
||||||
fn render(
|
fn render(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -179,41 +179,9 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
|||||||
|
|
||||||
(size, surface)
|
(size, surface)
|
||||||
};
|
};
|
||||||
|
let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, Some(&surface))
|
||||||
let adapter;
|
.await
|
||||||
|
.expect("No suitable GPU adapters found on the system!");
|
||||||
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"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
{
|
{
|
||||||
@@ -221,6 +189,15 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
|||||||
println!("Using {} ({:?})", adapter_info.name, adapter_info.backend);
|
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 required_downlevel_capabilities = E::required_downlevel_capabilities();
|
||||||
let downlevel_capabilities = adapter.get_downlevel_capabilities();
|
let downlevel_capabilities = adapter.get_downlevel_capabilities();
|
||||||
assert!(
|
assert!(
|
||||||
@@ -244,7 +221,7 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
|||||||
.request_device(
|
.request_device(
|
||||||
&wgpu::DeviceDescriptor {
|
&wgpu::DeviceDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
features: (optional_features & adapter.features()) | required_features,
|
features: (optional_features & adapter_features) | required_features,
|
||||||
limits: needed_limits,
|
limits: needed_limits,
|
||||||
},
|
},
|
||||||
trace_dir.ok().as_ref().map(std::path::Path::new),
|
trace_dir.ok().as_ref().map(std::path::Path::new),
|
||||||
@@ -358,7 +335,7 @@ fn start<E: Example>(
|
|||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
input:
|
||||||
event::KeyboardInput {
|
event::KeyboardInput {
|
||||||
virtual_keycode: Some(event::VirtualKeyCode::Scroll),
|
virtual_keycode: Some(event::VirtualKeyCode::R),
|
||||||
state: event::ElementState::Pressed,
|
state: event::ElementState::Pressed,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
@@ -367,7 +344,7 @@ fn start<E: Example>(
|
|||||||
println!("{:#?}", instance.generate_report());
|
println!("{:#?}", instance.generate_report());
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
example.update(&device,&queue,event);
|
example.update(event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
event::Event::DeviceEvent {
|
event::Event::DeviceEvent {
|
||||||
|
|||||||
4
src/lib.rs
Normal file
4
src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
pub mod framework;
|
||||||
|
pub mod body;
|
||||||
|
pub mod zeroes;
|
||||||
|
pub mod instruction;
|
||||||
@@ -1,384 +0,0 @@
|
|||||||
use crate::model::{IndexedModelInstances,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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[derive(Clone,Copy,PartialEq)]
|
|
||||||
struct RobloxTextureTransform{
|
|
||||||
offset_u:f32,
|
|
||||||
offset_v:f32,
|
|
||||||
scale_u:f32,
|
|
||||||
scale_v:f32,
|
|
||||||
}
|
|
||||||
impl std::cmp::Eq for RobloxTextureTransform{}//????
|
|
||||||
impl std::default::Default for RobloxTextureTransform{
|
|
||||||
fn default() -> Self {
|
|
||||||
Self{offset_u:0.0,offset_v:0.0,scale_u:1.0,scale_v:1.0}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl std::hash::Hash for RobloxTextureTransform {
|
|
||||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
|
||||||
self.offset_u.to_ne_bytes().hash(state);
|
|
||||||
self.offset_v.to_ne_bytes().hash(state);
|
|
||||||
self.scale_u.to_ne_bytes().hash(state);
|
|
||||||
self.scale_v.to_ne_bytes().hash(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[derive(Clone,PartialEq)]
|
|
||||||
struct RobloxFaceTextureDescription{
|
|
||||||
texture:u32,
|
|
||||||
color:glam::Vec4,
|
|
||||||
transform:RobloxTextureTransform,
|
|
||||||
}
|
|
||||||
impl std::cmp::Eq for RobloxFaceTextureDescription{}//????
|
|
||||||
impl std::hash::Hash for RobloxFaceTextureDescription {
|
|
||||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
|
||||||
self.texture.hash(state);
|
|
||||||
self.transform.hash(state);
|
|
||||||
for &el in self.color.as_ref().iter() {
|
|
||||||
el.to_ne_bytes().hash(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl RobloxFaceTextureDescription{
|
|
||||||
fn to_face_description(&self)->primitives::FaceDescription{
|
|
||||||
primitives::FaceDescription{
|
|
||||||
texture:Some(self.texture),
|
|
||||||
transform:glam::Affine2::from_translation(
|
|
||||||
glam::vec2(self.transform.offset_u,self.transform.offset_v)
|
|
||||||
)
|
|
||||||
*glam::Affine2::from_scale(
|
|
||||||
glam::vec2(self.transform.scale_u,self.transform.scale_v)
|
|
||||||
),
|
|
||||||
color:self.color,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
type RobloxPartDescription=[Option<RobloxFaceTextureDescription>;6];
|
|
||||||
type RobloxWedgeDescription=[Option<RobloxFaceTextureDescription>;5];
|
|
||||||
type RobloxCornerWedgeDescription=[Option<RobloxFaceTextureDescription>;4];
|
|
||||||
#[derive(Clone,Eq,Hash,PartialEq)]
|
|
||||||
enum RobloxBasePartDescription{
|
|
||||||
Sphere,
|
|
||||||
Part(RobloxPartDescription),
|
|
||||||
Cylinder,
|
|
||||||
Wedge(RobloxWedgeDescription),
|
|
||||||
CornerWedge(RobloxCornerWedgeDescription),
|
|
||||||
}
|
|
||||||
pub fn generate_indexed_models_roblox(dom:rbx_dom_weak::WeakDom) -> Result<(IndexedModelInstances,glam::Vec3), Box<dyn std::error::Error>>{
|
|
||||||
//IndexedModelInstances includes textures
|
|
||||||
let mut spawn_point=glam::Vec3::ZERO;
|
|
||||||
|
|
||||||
let mut indexed_models=Vec::new();
|
|
||||||
let mut model_id_from_description=std::collections::HashMap::<RobloxBasePartDescription,usize>::new();
|
|
||||||
|
|
||||||
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=Vec::new();
|
|
||||||
let mut temp_objects=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)),
|
|
||||||
) = (
|
|
||||||
object.properties.get("CFrame"),
|
|
||||||
object.properties.get("Size"),
|
|
||||||
object.properties.get("Transparency"),
|
|
||||||
object.properties.get("Color"),
|
|
||||||
)
|
|
||||||
{
|
|
||||||
let model_transform=glam::Affine3A::from_translation(
|
|
||||||
glam::Vec3::new(cf.position.x,cf.position.y,cf.position.z)
|
|
||||||
)
|
|
||||||
* glam::Affine3A::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::Affine3A::from_scale(
|
|
||||||
glam::Vec3::new(size.x,size.y,size.z)/2.0
|
|
||||||
);
|
|
||||||
if object.name=="MapStart"{
|
|
||||||
spawn_point=model_transform.transform_point3(glam::Vec3::Y)+glam::vec3(0.0,2.5,0.0);
|
|
||||||
println!("Found MapStart{:?}",spawn_point);
|
|
||||||
}
|
|
||||||
if *transparency==1.0 {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let shape=match &object.class[..]{
|
|
||||||
"Part"=>{
|
|
||||||
if let Some(rbx_dom_weak::types::Variant::Enum(shape))=object.properties.get("Shape"){
|
|
||||||
match shape.to_u32(){
|
|
||||||
0=>primitives::Primitives::Sphere,
|
|
||||||
1=>primitives::Primitives::Cube,
|
|
||||||
2=>primitives::Primitives::Cylinder,
|
|
||||||
3=>primitives::Primitives::Wedge,
|
|
||||||
4=>primitives::Primitives::CornerWedge,
|
|
||||||
_=>{
|
|
||||||
println!("Funky roblox PartType={}; defaulting to cube",shape.to_u32());
|
|
||||||
primitives::Primitives::Cube
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
println!("Part has no Shape! defaulting to cube");
|
|
||||||
primitives::Primitives::Cube
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"WedgePart"=>primitives::Primitives::Wedge,
|
|
||||||
"CornerWedgePart"=>primitives::Primitives::CornerWedge,
|
|
||||||
_=>{
|
|
||||||
println!("Unsupported BasePart ClassName={}; defaulting to cube",object.class);
|
|
||||||
primitives::Primitives::Cube
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//TODO: also detect "CylinderMesh" etc here
|
|
||||||
let mut face_map=std::collections::HashMap::new();
|
|
||||||
match shape{
|
|
||||||
primitives::Primitives::Cube => {
|
|
||||||
face_map.insert(0,0);//Right
|
|
||||||
face_map.insert(1,1);//Top
|
|
||||||
face_map.insert(2,2);//Back
|
|
||||||
face_map.insert(3,3);//Left
|
|
||||||
face_map.insert(4,4);//Bottom
|
|
||||||
face_map.insert(5,5);//Front
|
|
||||||
},
|
|
||||||
primitives::Primitives::Wedge => {
|
|
||||||
face_map.insert(0,0);//Right
|
|
||||||
face_map.insert(1,1);//Top -> TopFront (some surf maps put surf textures on the Top face)
|
|
||||||
face_map.insert(2,1);//Front -> TopFront
|
|
||||||
face_map.insert(3,2);//Back
|
|
||||||
face_map.insert(4,3);//Left
|
|
||||||
face_map.insert(5,4);//Bottom
|
|
||||||
},
|
|
||||||
primitives::Primitives::CornerWedge => {
|
|
||||||
//Right -> None
|
|
||||||
face_map.insert(1,0);//Top
|
|
||||||
//Back -> None
|
|
||||||
face_map.insert(3,1);//Right
|
|
||||||
face_map.insert(4,2);//Bottom
|
|
||||||
face_map.insert(5,3);//Front
|
|
||||||
},
|
|
||||||
//do not support textured spheres/cylinders imported from roblox
|
|
||||||
//this can be added later, there are some maps that use it
|
|
||||||
primitives::Primitives::Sphere
|
|
||||||
|primitives::Primitives::Cylinder => (),
|
|
||||||
}
|
|
||||||
//use the biggest one and cut it down later...
|
|
||||||
let mut part_texture_description:RobloxPartDescription=[None,None,None,None,None,None];
|
|
||||||
temp_objects.clear();
|
|
||||||
recursive_collect_superclass(&mut temp_objects, &dom, object,"Decal");
|
|
||||||
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)),
|
|
||||||
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"),
|
|
||||||
) {
|
|
||||||
if let Ok(asset_id)=content.clone().into_string().parse::<RobloxAssetId>(){
|
|
||||||
let texture_id=if let Some(&texture_id)=texture_id_from_asset_id.get(&asset_id.0){
|
|
||||||
texture_id
|
|
||||||
}else{
|
|
||||||
let texture_id=asset_id_from_texture_id.len() as u32;
|
|
||||||
texture_id_from_asset_id.insert(asset_id.0,texture_id);
|
|
||||||
asset_id_from_texture_id.push(asset_id.0);
|
|
||||||
texture_id
|
|
||||||
};
|
|
||||||
let normal_id=normalid.to_u32();
|
|
||||||
if let Some(&face)=face_map.get(&normal_id){
|
|
||||||
let mut roblox_texture_transform=RobloxTextureTransform::default();
|
|
||||||
let mut roblox_texture_color=glam::Vec4::ONE;
|
|
||||||
if decal.class=="Texture"{
|
|
||||||
//generate tranform
|
|
||||||
if let (
|
|
||||||
Some(rbx_dom_weak::types::Variant::Float32(ox)),
|
|
||||||
Some(rbx_dom_weak::types::Variant::Float32(oy)),
|
|
||||||
Some(rbx_dom_weak::types::Variant::Float32(sx)),
|
|
||||||
Some(rbx_dom_weak::types::Variant::Float32(sy)),
|
|
||||||
) = (
|
|
||||||
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
|
|
||||||
_=>(1.,1.),
|
|
||||||
};
|
|
||||||
roblox_texture_transform=RobloxTextureTransform{
|
|
||||||
offset_u:*ox/(*sx),offset_v:*oy/(*sy),
|
|
||||||
scale_u:size_u/(*sx),scale_v:size_v/(*sy),
|
|
||||||
};
|
|
||||||
roblox_texture_color=glam::vec4(decal_color3.r,decal_color3.g,decal_color3.b,1.0-*decal_transparency);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
part_texture_description[face]=Some(RobloxFaceTextureDescription{
|
|
||||||
texture:texture_id,
|
|
||||||
color:roblox_texture_color,
|
|
||||||
transform:roblox_texture_transform,
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
println!("NormalId={} unsupported for shape={:?}",normal_id,shape);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//obscure rust syntax "slice pattern"
|
|
||||||
let [f0,f1,f2,f3,f4,f5]=part_texture_description;
|
|
||||||
let basepart_texture_description=match shape{
|
|
||||||
primitives::Primitives::Sphere=>RobloxBasePartDescription::Sphere,
|
|
||||||
primitives::Primitives::Cube=>RobloxBasePartDescription::Part([f0,f1,f2,f3,f4,f5]),
|
|
||||||
primitives::Primitives::Cylinder=>RobloxBasePartDescription::Cylinder,
|
|
||||||
//HAHAHA
|
|
||||||
primitives::Primitives::Wedge=>RobloxBasePartDescription::Wedge([f0,f1,f2,f3,f4]),
|
|
||||||
primitives::Primitives::CornerWedge=>RobloxBasePartDescription::CornerWedge([f0,f1,f2,f3]),
|
|
||||||
};
|
|
||||||
//make new model if unit cube has not been crated before
|
|
||||||
let model_id=if let Some(&model_id)=model_id_from_description.get(&basepart_texture_description){
|
|
||||||
//push to existing texture model
|
|
||||||
model_id
|
|
||||||
}else{
|
|
||||||
let model_id=indexed_models.len();
|
|
||||||
model_id_from_description.insert(basepart_texture_description.clone(),model_id);//borrow checker going crazy
|
|
||||||
indexed_models.push(match basepart_texture_description{
|
|
||||||
RobloxBasePartDescription::Sphere=>primitives::unit_sphere(),
|
|
||||||
RobloxBasePartDescription::Part(part_texture_description)=>{
|
|
||||||
let mut cube_face_description=primitives::CubeFaceDescription::new();
|
|
||||||
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,
|
|
||||||
_=>panic!("unreachable"),
|
|
||||||
},
|
|
||||||
match roblox_face_description{
|
|
||||||
Some(roblox_texture_transform)=>roblox_texture_transform.to_face_description(),
|
|
||||||
None=>primitives::FaceDescription::default(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
primitives::generate_partial_unit_cube(cube_face_description)
|
|
||||||
},
|
|
||||||
RobloxBasePartDescription::Cylinder=>primitives::unit_cylinder(),
|
|
||||||
RobloxBasePartDescription::Wedge(wedge_texture_description)=>{
|
|
||||||
let mut wedge_face_description=primitives::WedgeFaceDescription::new();
|
|
||||||
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,
|
|
||||||
_=>panic!("unreachable"),
|
|
||||||
},
|
|
||||||
match roblox_face_description{
|
|
||||||
Some(roblox_texture_transform)=>roblox_texture_transform.to_face_description(),
|
|
||||||
None=>primitives::FaceDescription::default(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
primitives::generate_partial_unit_wedge(wedge_face_description)
|
|
||||||
},
|
|
||||||
RobloxBasePartDescription::CornerWedge(cornerwedge_texture_description)=>{
|
|
||||||
let mut cornerwedge_face_description=primitives::CornerWedgeFaceDescription::new();
|
|
||||||
for (face_id,roblox_face_description) in cornerwedge_texture_description.iter().enumerate(){
|
|
||||||
cornerwedge_face_description.insert(
|
|
||||||
match face_id{
|
|
||||||
0=>primitives::CornerWedgeFace::Top,
|
|
||||||
1=>primitives::CornerWedgeFace::Right,
|
|
||||||
2=>primitives::CornerWedgeFace::Bottom,
|
|
||||||
3=>primitives::CornerWedgeFace::Front,
|
|
||||||
_=>panic!("unreachable"),
|
|
||||||
},
|
|
||||||
match roblox_face_description{
|
|
||||||
Some(roblox_texture_transform)=>roblox_texture_transform.to_face_description(),
|
|
||||||
None=>primitives::FaceDescription::default(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
primitives::generate_partial_unit_cornerwedge(cornerwedge_face_description)
|
|
||||||
},
|
|
||||||
});
|
|
||||||
model_id
|
|
||||||
};
|
|
||||||
indexed_models[model_id].instances.push(ModelInstance {
|
|
||||||
transform:model_transform,
|
|
||||||
color:glam::vec4(color3.r as f32/255f32, color3.g as f32/255f32, color3.b as f32/255f32, 1.0-*transparency),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok((IndexedModelInstances{
|
|
||||||
textures:asset_id_from_texture_id.iter().map(|t|t.to_string()).collect(),
|
|
||||||
models:indexed_models,
|
|
||||||
},spawn_point))
|
|
||||||
}
|
|
||||||
633
src/main.rs
633
src/main.rs
@@ -1,38 +1,36 @@
|
|||||||
|
use bytemuck::{Pod, Zeroable};
|
||||||
|
use strafe_client::{instruction::{TimedInstruction, InstructionConsumer},body::{InputInstruction, PhysicsInstruction}};
|
||||||
use std::{borrow::Cow, time::Instant};
|
use std::{borrow::Cow, time::Instant};
|
||||||
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};
|
use wgpu::{util::DeviceExt, AstcBlock, AstcChannel};
|
||||||
use model::{Vertex,ModelInstance,ModelGraphicsInstance};
|
|
||||||
use body::{InputInstruction, PhysicsInstruction};
|
|
||||||
use instruction::{TimedInstruction, InstructionConsumer};
|
|
||||||
|
|
||||||
mod body;
|
const IMAGE_SIZE: u32 = 128;
|
||||||
mod model;
|
|
||||||
mod zeroes;
|
#[derive(Clone, Copy, Pod, Zeroable)]
|
||||||
mod framework;
|
#[repr(C)]
|
||||||
mod primitives;
|
struct Vertex {
|
||||||
mod instruction;
|
pos: [f32; 3],
|
||||||
mod load_roblox;
|
texture: [f32; 2],
|
||||||
|
normal: [f32; 3],
|
||||||
|
}
|
||||||
|
|
||||||
struct Entity {
|
struct Entity {
|
||||||
index_count: u32,
|
index_count: u32,
|
||||||
index_buf: wgpu::Buffer,
|
index_buf: wgpu::Buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ModelData {
|
||||||
|
transforms: Vec<glam::Mat4>,
|
||||||
|
vertices: Vec<Vertex>,
|
||||||
|
entities: Vec<Vec<u16>>,
|
||||||
|
}
|
||||||
|
|
||||||
struct ModelGraphics {
|
struct ModelGraphics {
|
||||||
instances: Vec<ModelGraphicsInstance>,
|
transforms: Vec<glam::Mat4>,
|
||||||
vertex_buf: wgpu::Buffer,
|
vertex_buf: wgpu::Buffer,
|
||||||
entities: Vec<Entity>,
|
entities: Vec<Entity>,
|
||||||
bind_group: wgpu::BindGroup,
|
bind_group: wgpu::BindGroup,
|
||||||
model_buf: wgpu::Buffer,
|
model_buf: wgpu::Buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GraphicsSamplers{
|
|
||||||
repeat: wgpu::Sampler,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GraphicsBindGroupLayouts{
|
|
||||||
model: wgpu::BindGroupLayout,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GraphicsBindGroups {
|
pub struct GraphicsBindGroups {
|
||||||
camera: wgpu::BindGroup,
|
camera: wgpu::BindGroup,
|
||||||
skybox_texture: wgpu::BindGroup,
|
skybox_texture: wgpu::BindGroup,
|
||||||
@@ -46,12 +44,9 @@ pub struct GraphicsPipelines {
|
|||||||
pub struct GraphicsData {
|
pub struct GraphicsData {
|
||||||
start_time: std::time::Instant,
|
start_time: std::time::Instant,
|
||||||
screen_size: (u32, u32),
|
screen_size: (u32, u32),
|
||||||
physics: body::PhysicsState,
|
physics: strafe_client::body::PhysicsState,
|
||||||
pipelines: GraphicsPipelines,
|
pipelines: GraphicsPipelines,
|
||||||
bind_groups: GraphicsBindGroups,
|
bind_groups: GraphicsBindGroups,
|
||||||
bind_group_layouts: GraphicsBindGroupLayouts,
|
|
||||||
samplers: GraphicsSamplers,
|
|
||||||
temp_squid_texture_view: wgpu::TextureView,
|
|
||||||
camera_buf: wgpu::Buffer,
|
camera_buf: wgpu::Buffer,
|
||||||
models: Vec<ModelGraphics>,
|
models: Vec<ModelGraphics>,
|
||||||
depth_view: wgpu::TextureView,
|
depth_view: wgpu::TextureView,
|
||||||
@@ -82,254 +77,60 @@ impl GraphicsData {
|
|||||||
|
|
||||||
depth_texture.create_view(&wgpu::TextureViewDescriptor::default())
|
depth_texture.create_view(&wgpu::TextureViewDescriptor::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_model_physics(&mut self,indexed_models:&model::IndexedModelInstances){
|
|
||||||
for model in &indexed_models.models{
|
|
||||||
//make aabb and run vertices to get realistic bounds
|
|
||||||
for model_instance in &model.instances{
|
|
||||||
self.physics.models.push(body::ModelPhysics::from_model(&model,model_instance.transform));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
println!("Physics Objects: {}",self.physics.models.len());
|
|
||||||
}
|
|
||||||
fn generate_model_graphics(&mut self,device:&wgpu::Device,queue:&wgpu::Queue,mut indexed_models:model::IndexedModelInstances){
|
|
||||||
//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_loading_threads=Vec::new();
|
|
||||||
for (i,t) in indexed_models.textures.iter().enumerate(){
|
|
||||||
if let Ok(mut file) = std::fs::File::open(std::path::Path::new(&format!("textures/{}.dds",t))){
|
|
||||||
double_map.insert(i as u32, texture_loading_threads.len() as u32);
|
|
||||||
texture_loading_threads.push(std::thread::spawn(move ||{
|
|
||||||
(i,ddsfile::Dds::read(&mut file).unwrap())
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let texture_views:Vec<wgpu::TextureView>=texture_loading_threads.into_iter().map(|t|{
|
|
||||||
let (i,image)=t.join().unwrap();
|
|
||||||
|
|
||||||
let (mut width,mut height)=(image.get_width(),image.get_height());
|
|
||||||
|
|
||||||
let format=match image.header10.unwrap().dxgi_format{
|
|
||||||
ddsfile::DxgiFormat::R8G8B8A8_UNorm_sRGB => wgpu::TextureFormat::Rgba8UnormSrgb,
|
|
||||||
ddsfile::DxgiFormat::BC7_UNorm_sRGB => {
|
|
||||||
//floor(w,4), should be ceil(w,4)
|
|
||||||
width=width/4*4;
|
|
||||||
height=height/4*4;
|
|
||||||
wgpu::TextureFormat::Bc7RgbaUnormSrgb
|
|
||||||
},
|
|
||||||
other=>panic!("unsupported format {:?}",other),
|
|
||||||
};
|
|
||||||
|
|
||||||
let size = wgpu::Extent3d {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
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,
|
|
||||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
|
||||||
label: Some(format!("Texture{}",i).as_str()),
|
|
||||||
view_formats: &[],
|
|
||||||
},
|
|
||||||
&image.data,
|
|
||||||
);
|
|
||||||
texture.create_view(&wgpu::TextureViewDescriptor {
|
|
||||||
label: Some(format!("Texture{} View",i).as_str()),
|
|
||||||
dimension: Some(wgpu::TextureViewDimension::D2),
|
|
||||||
..wgpu::TextureViewDescriptor::default()
|
|
||||||
})
|
|
||||||
}).collect();
|
|
||||||
|
|
||||||
let indexed_models_len=indexed_models.models.len();
|
|
||||||
//split groups with different textures into separate models
|
|
||||||
//the models received here are supposed to be tightly packed, i.e. no code needs to check if two models are using the same groups.
|
|
||||||
let mut unique_texture_models=Vec::with_capacity(indexed_models.models.len());
|
|
||||||
for mut model in indexed_models.models.drain(..){
|
|
||||||
//convert ModelInstance into ModelGraphicsInstance
|
|
||||||
let instances:Vec<ModelGraphicsInstance>=model.instances.iter().map(|instance|{
|
|
||||||
ModelGraphicsInstance{
|
|
||||||
transform: glam::Mat4::from(instance.transform),
|
|
||||||
normal_transform: glam::Mat4::from(instance.transform.inverse()).transpose(),
|
|
||||||
color: instance.color,
|
|
||||||
}
|
|
||||||
}).collect();
|
|
||||||
//check each group, if it's using a new texture then make a new clone of the model
|
|
||||||
let id=unique_texture_models.len();
|
|
||||||
let mut unique_textures=Vec::new();
|
|
||||||
for group in model.groups.drain(..){
|
|
||||||
//ignore zero coppy optimization for now
|
|
||||||
let texture_index=if let Some(texture_index)=unique_textures.iter().position(|&texture|texture==group.texture){
|
|
||||||
texture_index
|
|
||||||
}else{
|
|
||||||
//create new texture_index
|
|
||||||
let texture_index=unique_textures.len();
|
|
||||||
unique_textures.push(group.texture);
|
|
||||||
unique_texture_models.push(model::IndexedModelSingleTexture{
|
|
||||||
unique_pos:model.unique_pos.clone(),
|
|
||||||
unique_tex:model.unique_tex.clone(),
|
|
||||||
unique_normal:model.unique_normal.clone(),
|
|
||||||
unique_color:model.unique_color.clone(),
|
|
||||||
unique_vertices:model.unique_vertices.clone(),
|
|
||||||
texture:group.texture,
|
|
||||||
groups:Vec::new(),
|
|
||||||
instances:instances.clone(),
|
|
||||||
});
|
|
||||||
texture_index
|
|
||||||
};
|
|
||||||
unique_texture_models[id+texture_index].groups.push(model::IndexedGroupFixedTexture{
|
|
||||||
polys:group.polys,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//de-index models
|
|
||||||
let mut models=Vec::with_capacity(unique_texture_models.len());
|
|
||||||
for model in unique_texture_models.drain(..){
|
|
||||||
let mut vertices = Vec::new();
|
|
||||||
let mut index_from_vertex = std::collections::HashMap::new();//::<IndexedVertex,usize>
|
|
||||||
let mut entities = Vec::new();
|
|
||||||
//TODO: combine groups using the same render pattern
|
|
||||||
for group in model.groups {
|
|
||||||
let mut indices = Vec::new();
|
|
||||||
for poly in group.polys {
|
|
||||||
for end_index in 2..poly.vertices.len() {
|
|
||||||
for &index in &[0, end_index - 1, end_index] {
|
|
||||||
let vertex_index = poly.vertices[index];
|
|
||||||
if let Some(&i)=index_from_vertex.get(&vertex_index){
|
|
||||||
indices.push(i);
|
|
||||||
}else{
|
|
||||||
let i=vertices.len() as u16;
|
|
||||||
let vertex=&model.unique_vertices[vertex_index as usize];
|
|
||||||
vertices.push(Vertex {
|
|
||||||
pos: model.unique_pos[vertex.pos as usize],
|
|
||||||
tex: model.unique_tex[vertex.tex as usize],
|
|
||||||
normal: model.unique_normal[vertex.normal as usize],
|
|
||||||
color:model.unique_color[vertex.color as usize],
|
|
||||||
});
|
|
||||||
index_from_vertex.insert(vertex_index,i);
|
|
||||||
indices.push(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
entities.push(indices);
|
|
||||||
}
|
|
||||||
models.push(model::ModelSingleTexture{
|
|
||||||
instances:model.instances,
|
|
||||||
vertices,
|
|
||||||
entities,
|
|
||||||
texture:model.texture,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//drain the modeldata vec so entities can be /moved/ to models.entities
|
|
||||||
let mut model_count=0;
|
|
||||||
let mut instance_count=0;
|
|
||||||
let uniform_buffer_binding_size=<GraphicsData as framework::Example>::required_limits().max_uniform_buffer_binding_size as usize;
|
|
||||||
let chunk_size=uniform_buffer_binding_size/MODEL_BUFFER_SIZE_BYTES;
|
|
||||||
self.models.reserve(models.len());
|
|
||||||
for model in models.drain(..) {
|
|
||||||
instance_count+=model.instances.len();
|
|
||||||
for instances_chunk in model.instances.rchunks(chunk_size){
|
|
||||||
model_count+=1;
|
|
||||||
let model_uniforms = get_instances_buffer_data(instances_chunk);
|
|
||||||
let model_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
||||||
label: Some(format!("Model{} Buf",model_count).as_str()),
|
|
||||||
contents: bytemuck::cast_slice(&model_uniforms),
|
|
||||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
|
||||||
});
|
|
||||||
let texture_view=match model.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",model_count).as_str()),
|
|
||||||
});
|
|
||||||
let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
||||||
label: Some("Vertex"),
|
|
||||||
contents: bytemuck::cast_slice(&model.vertices),
|
|
||||||
usage: wgpu::BufferUsages::VERTEX,
|
|
||||||
});
|
|
||||||
//all of these are being moved here
|
|
||||||
self.models.push(ModelGraphics{
|
|
||||||
instances:instances_chunk.to_vec(),
|
|
||||||
vertex_buf,
|
|
||||||
entities: model.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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
println!("Texture References={}",indexed_models.textures.len());
|
|
||||||
println!("Textures Loaded={}",texture_views.len());
|
|
||||||
println!("Indexed Models={}",indexed_models_len);
|
|
||||||
println!("Graphics Objects: {}",self.models.len());
|
|
||||||
println!("Graphics Instances: {}",instance_count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const MODEL_BUFFER_SIZE:usize=4*4 + 4*4 + 4;//let size=std::mem::size_of::<ModelInstance>();
|
fn get_transform_uniform_data(transforms:&Vec<glam::Mat4>) -> Vec<f32> {
|
||||||
const MODEL_BUFFER_SIZE_BYTES:usize=MODEL_BUFFER_SIZE*4;
|
let mut raw = Vec::with_capacity(4*4*transforms.len());
|
||||||
fn get_instances_buffer_data(instances:&[ModelGraphicsInstance]) -> Vec<f32> {
|
for (i,t) in transforms.iter().enumerate(){
|
||||||
let mut raw = Vec::with_capacity(MODEL_BUFFER_SIZE*instances.len());
|
let mut v = raw.split_off(4*4*i);
|
||||||
for (i,mi) in instances.iter().enumerate(){
|
raw.extend_from_slice(&AsRef::<[f32; 4*4]>::as_ref(t)[..]);
|
||||||
let mut v = raw.split_off(MODEL_BUFFER_SIZE*i);
|
|
||||||
//model transform
|
|
||||||
raw.extend_from_slice(&AsRef::<[f32; 4*4]>::as_ref(&mi.transform)[..]);
|
|
||||||
//normal transform
|
|
||||||
raw.extend_from_slice(&AsRef::<[f32; 4*4]>::as_ref(&mi.normal_transform)[..]);
|
|
||||||
//color
|
|
||||||
raw.extend_from_slice(AsRef::<[f32; 4]>::as_ref(&mi.color));
|
|
||||||
raw.append(&mut v);
|
raw.append(&mut v);
|
||||||
}
|
}
|
||||||
raw
|
raw
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_uniform_data(camera: &body::Camera, pos: glam::Vec3) -> [f32; 16 * 3 + 4] {
|
fn generate_modeldatas(data:obj::ObjData) -> 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()],
|
||||||
|
});
|
||||||
|
vertex_index.insert(vert,i);
|
||||||
|
indices.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entities.push(indices);
|
||||||
|
}
|
||||||
|
modeldatas.push(ModelData {
|
||||||
|
transforms: vec![],
|
||||||
|
vertices:vertices.clone(),
|
||||||
|
entities,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
modeldatas
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn to_uniform_data(camera: &strafe_client::body::Camera, pos: glam::Vec3) -> [f32; 16 * 3 + 4] {
|
||||||
let proj=camera.proj();
|
let proj=camera.proj();
|
||||||
let proj_inv = proj.inverse();
|
let proj_inv = proj.inverse();
|
||||||
let view=camera.view(pos);
|
let view=camera.view(pos);
|
||||||
@@ -343,60 +144,52 @@ fn to_uniform_data(camera: &body::Camera, pos: glam::Vec3) -> [f32; 16 * 3 + 4]
|
|||||||
raw
|
raw
|
||||||
}
|
}
|
||||||
|
|
||||||
impl framework::Example for GraphicsData {
|
impl strafe_client::framework::Example for GraphicsData {
|
||||||
fn optional_features() -> wgpu::Features {
|
fn optional_features() -> wgpu::Features {
|
||||||
wgpu::Features::TEXTURE_COMPRESSION_ASTC
|
wgpu::Features::TEXTURE_COMPRESSION_ASTC
|
||||||
| wgpu::Features::TEXTURE_COMPRESSION_ETC2
|
| wgpu::Features::TEXTURE_COMPRESSION_ETC2
|
||||||
|
| wgpu::Features::TEXTURE_COMPRESSION_BC
|
||||||
}
|
}
|
||||||
fn required_features() -> wgpu::Features {
|
|
||||||
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(
|
fn init(
|
||||||
config: &wgpu::SurfaceConfiguration,
|
config: &wgpu::SurfaceConfiguration,
|
||||||
_adapter: &wgpu::Adapter,
|
_adapter: &wgpu::Adapter,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
queue: &wgpu::Queue,
|
queue: &wgpu::Queue,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut indexed_models = Vec::new();
|
let ground=obj::ObjData{
|
||||||
indexed_models.append(&mut model::generate_indexed_model_list_from_obj(obj::ObjData::load_buf(&include_bytes!("../models/teslacyberv3.0.obj")[..]).unwrap(),*glam::Vec4::ONE.as_ref()));
|
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]],
|
||||||
indexed_models.push(primitives::unit_sphere());
|
texture: vec![[-10.0,-10.0],[10.0,-10.0],[10.0,10.0],[-10.0,10.0]],
|
||||||
indexed_models.push(primitives::unit_cylinder());
|
normal: vec![[0.0,1.0,0.0]],
|
||||||
indexed_models.push(primitives::unit_cube());
|
objects: vec![obj::Object{
|
||||||
println!("models.len = {:?}", indexed_models.len());
|
name: "Ground Object".to_owned(),
|
||||||
indexed_models[0].instances.push(ModelInstance{
|
groups: vec![obj::Group{
|
||||||
transform:glam::Affine3A::from_translation(glam::vec3(10.,0.,-10.)),
|
name: "Ground Group".to_owned(),
|
||||||
color:glam::Vec4::ONE,
|
index: 0,
|
||||||
});
|
material: None,
|
||||||
//quad monkeys
|
polys: vec![obj::SimplePolygon(vec![
|
||||||
indexed_models[1].instances.push(ModelInstance{
|
obj::IndexTuple(0,Some(0),Some(0)),
|
||||||
transform:glam::Affine3A::from_translation(glam::vec3(10.,5.,10.)),
|
obj::IndexTuple(1,Some(1),Some(0)),
|
||||||
color:glam::Vec4::ONE,
|
obj::IndexTuple(2,Some(2),Some(0)),
|
||||||
});
|
obj::IndexTuple(3,Some(3),Some(0)),
|
||||||
indexed_models[1].instances.push(ModelInstance{
|
])]
|
||||||
transform:glam::Affine3A::from_translation(glam::vec3(20.,5.,10.)),
|
}]
|
||||||
color:glam::vec4(1.0,0.0,0.0,1.0),
|
}],
|
||||||
});
|
material_libs: Vec::new(),
|
||||||
indexed_models[1].instances.push(ModelInstance{
|
};
|
||||||
transform:glam::Affine3A::from_translation(glam::vec3(10.,5.,20.)),
|
let mut modeldatas = Vec::<ModelData>::new();
|
||||||
color:glam::vec4(0.0,1.0,0.0,1.0),
|
modeldatas.append(&mut generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/teslacyberv3.0.obj")[..]).unwrap()));
|
||||||
});
|
modeldatas.append(&mut generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/suzanne.obj")[..]).unwrap()));
|
||||||
indexed_models[1].instances.push(ModelInstance{
|
modeldatas.append(&mut generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/teapot.obj")[..]).unwrap()));
|
||||||
transform:glam::Affine3A::from_translation(glam::vec3(20.,5.,20.)),
|
modeldatas.append(&mut generate_modeldatas(ground));
|
||||||
color:glam::vec4(0.0,0.0,1.0,1.0),
|
println!("models.len = {:?}", modeldatas.len());
|
||||||
});
|
modeldatas[0].transforms.push(glam::Mat4::from_translation(glam::vec3(10.,0.,-10.)));
|
||||||
//teapot
|
modeldatas[1].transforms.push(glam::Mat4::from_translation(glam::vec3(10.,5.,10.)));
|
||||||
indexed_models[2].instances.push(ModelInstance{
|
modeldatas[1].transforms.push(glam::Mat4::from_translation(glam::vec3(20.,5.,10.)));
|
||||||
transform:glam::Affine3A::from_scale_rotation_translation(glam::vec3(0.5, 1.0, 0.2),glam::quat(-0.22248298016985793,-0.839457167990537,-0.05603504040830783,-0.49261857546227916),glam::vec3(-10.,7.,10.)),
|
modeldatas[1].transforms.push(glam::Mat4::from_translation(glam::vec3(10.,5.,20.)));
|
||||||
color:glam::Vec4::ONE,
|
modeldatas[1].transforms.push(glam::Mat4::from_translation(glam::vec3(20.,5.,20.)));
|
||||||
});
|
modeldatas[2].transforms.push(glam::Mat4::from_translation(glam::vec3(-10.,5.,10.)));
|
||||||
//ground
|
modeldatas[3].transforms.push(glam::Mat4::from_translation(glam::vec3(0.,0.,0.))*glam::Mat4::from_scale(glam::vec3(160.0, 1.0, 160.0)));
|
||||||
indexed_models[3].instances.push(ModelInstance{
|
|
||||||
transform:glam::Affine3A::from_translation(glam::vec3(0.,0.,0.))*glam::Affine3A::from_scale(glam::vec3(160.0, 1.0, 160.0)),
|
|
||||||
color:glam::Vec4::ONE,
|
|
||||||
});
|
|
||||||
|
|
||||||
let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
@@ -493,9 +286,8 @@ impl framework::Example for GraphicsData {
|
|||||||
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
|
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))),
|
||||||
});
|
});
|
||||||
|
|
||||||
let physics = body::PhysicsState {
|
let physics = strafe_client::body::PhysicsState {
|
||||||
spawn_point:glam::vec3(0.0,50.0,0.0),
|
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)),
|
||||||
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,
|
time: 0,
|
||||||
tick: 0,
|
tick: 0,
|
||||||
strafe_tick_num: 100,//100t
|
strafe_tick_num: 100,//100t
|
||||||
@@ -507,11 +299,11 @@ impl framework::Example for GraphicsData {
|
|||||||
grounded: false,
|
grounded: false,
|
||||||
walkspeed: 18.0,
|
walkspeed: 18.0,
|
||||||
contacts: std::collections::HashSet::new(),
|
contacts: std::collections::HashSet::new(),
|
||||||
models: Vec::new(),
|
models_cringe_clone: modeldatas.iter().map(|m|m.transforms.iter().map(|t|strafe_client::body::Model::new(*t))).flatten().collect(),
|
||||||
walk: body::WalkState::new(),
|
walk: strafe_client::body::WalkState::new(),
|
||||||
hitbox_halfsize: glam::vec3(1.0,2.5,1.0),
|
hitbox_halfsize: glam::vec3(1.0,2.5,1.0),
|
||||||
camera: body::Camera::from_offset(glam::vec3(0.0,4.5-2.5,0.0),(config.width as f32)/(config.height as f32)),
|
camera: strafe_client::body::Camera::from_offset(glam::vec3(0.0,4.5-2.5,0.0),(config.width as f32)/(config.height as f32)),
|
||||||
mouse_interpolation: body::MouseInterpolationState::new(),
|
mouse_interpolation: strafe_client::body::MouseInterpolationState::new(),
|
||||||
controls: 0,
|
controls: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -536,22 +328,9 @@ impl framework::Example for GraphicsData {
|
|||||||
wgpu::TextureFormat::Bgra8UnormSrgb
|
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 {
|
let size = wgpu::Extent3d {
|
||||||
width: skybox_image.get_width(),
|
width: IMAGE_SIZE,
|
||||||
height: skybox_image.get_height(),
|
height: IMAGE_SIZE,
|
||||||
depth_or_array_layers: 6,
|
depth_or_array_layers: 6,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -564,11 +343,24 @@ impl framework::Example for GraphicsData {
|
|||||||
log::debug!(
|
log::debug!(
|
||||||
"Copying {:?} skybox images of size {}, {}, 6 with {} mips to gpu",
|
"Copying {:?} skybox images of size {}, {}, 6 with {} mips to gpu",
|
||||||
skybox_format,
|
skybox_format,
|
||||||
size.width,
|
IMAGE_SIZE,
|
||||||
size.height,
|
IMAGE_SIZE,
|
||||||
max_mips,
|
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(
|
let skybox_texture = device.create_texture_with_data(
|
||||||
queue,
|
queue,
|
||||||
&wgpu::TextureDescriptor {
|
&wgpu::TextureDescriptor {
|
||||||
@@ -593,13 +385,9 @@ impl framework::Example for GraphicsData {
|
|||||||
|
|
||||||
//squid
|
//squid
|
||||||
let squid_texture_view={
|
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 {
|
let size = wgpu::Extent3d {
|
||||||
width: image.get_width(),
|
width: 1076,
|
||||||
height: image.get_height(),
|
height: 1076,
|
||||||
depth_or_array_layers: 1,
|
depth_or_array_layers: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -609,6 +397,10 @@ impl framework::Example for GraphicsData {
|
|||||||
};
|
};
|
||||||
let max_mips = layer_size.max_mips(wgpu::TextureDimension::D2);
|
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(
|
let texture = device.create_texture_with_data(
|
||||||
queue,
|
queue,
|
||||||
&wgpu::TextureDescriptor {
|
&wgpu::TextureDescriptor {
|
||||||
@@ -631,19 +423,63 @@ impl framework::Example for GraphicsData {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
let model_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
//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()),
|
||||||
|
});
|
||||||
|
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
|
||||||
|
models.push(ModelGraphics{
|
||||||
|
transforms:modeldata.transforms,
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
bind_group_layouts: &[
|
bind_group_layouts: &[
|
||||||
&camera_bind_group_layout,
|
&camera_bind_group_layout,
|
||||||
&skybox_texture_bind_group_layout,
|
|
||||||
&model_bind_group_layout,
|
&model_bind_group_layout,
|
||||||
],
|
|
||||||
push_constant_ranges: &[],
|
|
||||||
});
|
|
||||||
let sky_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
|
||||||
label: None,
|
|
||||||
bind_group_layouts: &[
|
|
||||||
&camera_bind_group_layout,
|
|
||||||
&skybox_texture_bind_group_layout,
|
&skybox_texture_bind_group_layout,
|
||||||
],
|
],
|
||||||
push_constant_ranges: &[],
|
push_constant_ranges: &[],
|
||||||
@@ -652,7 +488,7 @@ impl framework::Example for GraphicsData {
|
|||||||
// Create the render pipelines
|
// Create the render pipelines
|
||||||
let sky_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
let sky_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
label: Some("Sky Pipeline"),
|
label: Some("Sky Pipeline"),
|
||||||
layout: Some(&sky_pipeline_layout),
|
layout: Some(&pipeline_layout),
|
||||||
vertex: wgpu::VertexState {
|
vertex: wgpu::VertexState {
|
||||||
module: &shader,
|
module: &shader,
|
||||||
entry_point: "vs_sky",
|
entry_point: "vs_sky",
|
||||||
@@ -679,14 +515,14 @@ impl framework::Example for GraphicsData {
|
|||||||
});
|
});
|
||||||
let model_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
let model_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
label: Some("Model Pipeline"),
|
label: Some("Model Pipeline"),
|
||||||
layout: Some(&model_pipeline_layout),
|
layout: Some(&pipeline_layout),
|
||||||
vertex: wgpu::VertexState {
|
vertex: wgpu::VertexState {
|
||||||
module: &shader,
|
module: &shader,
|
||||||
entry_point: "vs_entity_texture",
|
entry_point: "vs_entity_texture",
|
||||||
buffers: &[wgpu::VertexBufferLayout {
|
buffers: &[wgpu::VertexBufferLayout {
|
||||||
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
|
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
|
||||||
step_mode: wgpu::VertexStepMode::Vertex,
|
step_mode: wgpu::VertexStepMode::Vertex,
|
||||||
attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2, 2 => Float32x3, 3 => Float32x4],
|
attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2, 2 => Float32x3],
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
fragment: Some(wgpu::FragmentState {
|
fragment: Some(wgpu::FragmentState {
|
||||||
@@ -742,7 +578,7 @@ impl framework::Example for GraphicsData {
|
|||||||
|
|
||||||
let depth_view = Self::create_depth_texture(config, device);
|
let depth_view = Self::create_depth_texture(config, device);
|
||||||
|
|
||||||
let mut graphics=GraphicsData {
|
GraphicsData {
|
||||||
start_time: Instant::now(),
|
start_time: Instant::now(),
|
||||||
screen_size: (config.width,config.height),
|
screen_size: (config.width,config.height),
|
||||||
physics,
|
physics,
|
||||||
@@ -755,90 +591,15 @@ impl framework::Example for GraphicsData {
|
|||||||
skybox_texture:skybox_texture_bind_group,
|
skybox_texture:skybox_texture_bind_group,
|
||||||
},
|
},
|
||||||
camera_buf,
|
camera_buf,
|
||||||
models: Vec::new(),
|
models,
|
||||||
depth_view,
|
depth_view,
|
||||||
staging_belt: wgpu::util::StagingBelt::new(0x100),
|
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,
|
|
||||||
};
|
|
||||||
|
|
||||||
let indexed_model_instances=model::IndexedModelInstances{
|
|
||||||
textures:Vec::new(),
|
|
||||||
models:indexed_models,
|
|
||||||
};
|
|
||||||
graphics.generate_model_physics(&indexed_model_instances);
|
|
||||||
graphics.generate_model_graphics(&device,&queue,indexed_model_instances);
|
|
||||||
|
|
||||||
return graphics;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::single_match)]
|
#[allow(clippy::single_match)]
|
||||||
fn update(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, event: winit::event::WindowEvent) {
|
fn update(&mut self, event: winit::event::WindowEvent) {
|
||||||
//nothing atm
|
//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((indexed_model_instances,spawn_point)))={
|
|
||||||
match &first_8[0..4]{
|
|
||||||
b"<rob"=>{
|
|
||||||
match match &first_8[4..8]{
|
|
||||||
b"lox!"=>rbx_binary::from_reader(input).map_err(|e|format!("{:?}",e)),
|
|
||||||
b"lox "=>rbx_xml::from_reader(input,rbx_xml::DecodeOptions::default()).map_err(|e|format!("{:?}",e)),
|
|
||||||
other=>Err(format!("Unknown Roblox file type {:?}",other)),
|
|
||||||
}{
|
|
||||||
Ok(dom)=>Some(load_roblox::generate_indexed_models_roblox(dom)),
|
|
||||||
Err(e)=>{
|
|
||||||
println!("Error loading roblox file:{:?}",e);
|
|
||||||
None
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
//b"VBSP"=>load_valve::generate_indexed_models_valve(input),
|
|
||||||
//b"SNFM"=>sniffer::generate_indexed_models(input),
|
|
||||||
//b"SNFB"=>sniffer::load_bot(input),
|
|
||||||
_=>None,
|
|
||||||
}
|
|
||||||
}{
|
|
||||||
//if generate_indexed_models succeeds, clear the previous ones
|
|
||||||
self.models.clear();
|
|
||||||
self.physics.models.clear();
|
|
||||||
self.generate_model_physics(&indexed_model_instances);
|
|
||||||
self.generate_model_graphics(device,queue,indexed_model_instances);
|
|
||||||
//manual reset
|
|
||||||
let time=self.physics.time;
|
|
||||||
instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{
|
|
||||||
time,
|
|
||||||
instruction: body::PhysicsInstruction::SetSpawnPosition(spawn_point),
|
|
||||||
});
|
|
||||||
instruction::InstructionConsumer::process_instruction(&mut self.physics, instruction::TimedInstruction{
|
|
||||||
time,
|
|
||||||
instruction: body::PhysicsInstruction::Input(body::InputInstruction::Reset),
|
|
||||||
});
|
|
||||||
}else{
|
|
||||||
println!("No modeldatas were generated");
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
println!("Failed to read first 8 bytes and seek back to beginning of file.");
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
println!("Could not open file");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_=>(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn device_event(&mut self, event: winit::event::DeviceEvent) {
|
fn device_event(&mut self, event: winit::event::DeviceEvent) {
|
||||||
@@ -917,7 +678,7 @@ impl framework::Example for GraphicsData {
|
|||||||
view: &wgpu::TextureView,
|
view: &wgpu::TextureView,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
queue: &wgpu::Queue,
|
queue: &wgpu::Queue,
|
||||||
_spawner: &framework::Spawner,
|
_spawner: &strafe_client::framework::Spawner,
|
||||||
) {
|
) {
|
||||||
let time=self.start_time.elapsed().as_nanos() as i64;
|
let time=self.start_time.elapsed().as_nanos() as i64;
|
||||||
|
|
||||||
@@ -939,7 +700,7 @@ impl framework::Example for GraphicsData {
|
|||||||
.copy_from_slice(bytemuck::cast_slice(&camera_uniforms));
|
.copy_from_slice(bytemuck::cast_slice(&camera_uniforms));
|
||||||
//This code only needs to run when the uniforms change
|
//This code only needs to run when the uniforms change
|
||||||
for model in self.models.iter() {
|
for model in self.models.iter() {
|
||||||
let model_uniforms = get_instances_buffer_data(&model.instances);
|
let model_uniforms = get_transform_uniform_data(&model.transforms);
|
||||||
self.staging_belt
|
self.staging_belt
|
||||||
.write_buffer(
|
.write_buffer(
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
@@ -979,16 +740,16 @@ impl framework::Example for GraphicsData {
|
|||||||
});
|
});
|
||||||
|
|
||||||
rpass.set_bind_group(0, &self.bind_groups.camera, &[]);
|
rpass.set_bind_group(0, &self.bind_groups.camera, &[]);
|
||||||
rpass.set_bind_group(1, &self.bind_groups.skybox_texture, &[]);
|
rpass.set_bind_group(2, &self.bind_groups.skybox_texture, &[]);
|
||||||
|
|
||||||
rpass.set_pipeline(&self.pipelines.model);
|
rpass.set_pipeline(&self.pipelines.model);
|
||||||
for model in self.models.iter() {
|
for model in self.models.iter() {
|
||||||
rpass.set_bind_group(2, &model.bind_group, &[]);
|
rpass.set_bind_group(1, &model.bind_group, &[]);
|
||||||
rpass.set_vertex_buffer(0, model.vertex_buf.slice(..));
|
rpass.set_vertex_buffer(0, model.vertex_buf.slice(..));
|
||||||
|
|
||||||
for entity in model.entities.iter() {
|
for entity in model.entities.iter() {
|
||||||
rpass.set_index_buffer(entity.index_buf.slice(..), wgpu::IndexFormat::Uint16);
|
rpass.set_index_buffer(entity.index_buf.slice(..), wgpu::IndexFormat::Uint16);
|
||||||
rpass.draw_indexed(0..entity.index_count, 0, 0..model.instances.len() as u32);
|
rpass.draw_indexed(0..entity.index_count, 0, 0..model.transforms.len() as u32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1003,7 +764,7 @@ impl framework::Example for GraphicsData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
framework::run::<GraphicsData>(
|
strafe_client::framework::run::<GraphicsData>(
|
||||||
format!("Strafe Client v{}",
|
format!("Strafe Client v{}",
|
||||||
env!("CARGO_PKG_VERSION")
|
env!("CARGO_PKG_VERSION")
|
||||||
).as_str()
|
).as_str()
|
||||||
|
|||||||
107
src/model.rs
107
src/model.rs
@@ -1,107 +0,0 @@
|
|||||||
use bytemuck::{Pod, Zeroable};
|
|
||||||
#[derive(Clone, Copy, Pod, Zeroable)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct Vertex {
|
|
||||||
pub pos: [f32; 3],
|
|
||||||
pub tex: [f32; 2],
|
|
||||||
pub normal: [f32; 3],
|
|
||||||
pub color: [f32; 4],
|
|
||||||
}
|
|
||||||
#[derive(Clone,Hash,PartialEq,Eq)]
|
|
||||||
pub struct IndexedVertex{
|
|
||||||
pub pos:u32,
|
|
||||||
pub tex:u32,
|
|
||||||
pub normal:u32,
|
|
||||||
pub color:u32,
|
|
||||||
}
|
|
||||||
pub struct IndexedPolygon{
|
|
||||||
pub vertices:Vec<u32>,
|
|
||||||
}
|
|
||||||
pub struct IndexedGroup{
|
|
||||||
pub texture:Option<u32>,//RenderPattern? material/texture/shader/flat color
|
|
||||||
pub polys:Vec<IndexedPolygon>,
|
|
||||||
}
|
|
||||||
pub struct IndexedModel{
|
|
||||||
pub unique_pos:Vec<[f32; 3]>,
|
|
||||||
pub unique_tex:Vec<[f32; 2]>,
|
|
||||||
pub unique_normal:Vec<[f32; 3]>,
|
|
||||||
pub unique_color:Vec<[f32; 4]>,
|
|
||||||
pub unique_vertices:Vec<IndexedVertex>,
|
|
||||||
pub groups: Vec<IndexedGroup>,
|
|
||||||
pub instances:Vec<ModelInstance>,
|
|
||||||
}
|
|
||||||
pub struct IndexedGroupFixedTexture{
|
|
||||||
pub polys:Vec<IndexedPolygon>,
|
|
||||||
}
|
|
||||||
pub struct IndexedModelSingleTexture{
|
|
||||||
pub unique_pos:Vec<[f32; 3]>,
|
|
||||||
pub unique_tex:Vec<[f32; 2]>,
|
|
||||||
pub unique_normal:Vec<[f32; 3]>,
|
|
||||||
pub unique_color:Vec<[f32; 4]>,
|
|
||||||
pub unique_vertices:Vec<IndexedVertex>,
|
|
||||||
pub texture:Option<u32>,//RenderPattern? material/texture/shader/flat color
|
|
||||||
pub groups: Vec<IndexedGroupFixedTexture>,
|
|
||||||
pub instances:Vec<ModelGraphicsInstance>,
|
|
||||||
}
|
|
||||||
pub struct ModelSingleTexture{
|
|
||||||
pub instances: Vec<ModelGraphicsInstance>,
|
|
||||||
pub vertices: Vec<Vertex>,
|
|
||||||
pub entities: Vec<Vec<u16>>,
|
|
||||||
pub texture: Option<u32>,
|
|
||||||
}
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ModelGraphicsInstance{
|
|
||||||
pub transform:glam::Mat4,
|
|
||||||
pub normal_transform:glam::Mat4,
|
|
||||||
pub color:glam::Vec4,
|
|
||||||
}
|
|
||||||
pub struct ModelInstance{
|
|
||||||
pub transform:glam::Affine3A,
|
|
||||||
pub color:glam::Vec4,
|
|
||||||
}
|
|
||||||
pub struct IndexedModelInstances{
|
|
||||||
pub textures:Vec<String>,//RenderPattern
|
|
||||||
pub models:Vec<IndexedModel>,
|
|
||||||
//object_index for spawns, triggers etc?
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn generate_indexed_model_list_from_obj(data:obj::ObjData,color:[f32;4]) -> Vec<IndexedModel>{
|
|
||||||
let mut unique_vertex_index = std::collections::HashMap::<obj::IndexTuple,u32>::new();
|
|
||||||
return data.objects.iter().map(|object|{
|
|
||||||
unique_vertex_index.clear();
|
|
||||||
let mut unique_vertices = Vec::new();
|
|
||||||
let groups = object.groups.iter().map(|group|{
|
|
||||||
IndexedGroup{
|
|
||||||
texture:None,
|
|
||||||
polys:group.polys.iter().map(|poly|{
|
|
||||||
IndexedPolygon{
|
|
||||||
vertices:poly.0.iter().map(|&tup|{
|
|
||||||
if let Some(&i)=unique_vertex_index.get(&tup){
|
|
||||||
i
|
|
||||||
}else{
|
|
||||||
let i=unique_vertices.len() as u32;
|
|
||||||
unique_vertices.push(IndexedVertex{
|
|
||||||
pos: tup.0 as u32,
|
|
||||||
tex: tup.1.unwrap() as u32,
|
|
||||||
normal: tup.2.unwrap() as u32,
|
|
||||||
color: 0,
|
|
||||||
});
|
|
||||||
unique_vertex_index.insert(tup,i);
|
|
||||||
i
|
|
||||||
}
|
|
||||||
}).collect()
|
|
||||||
}
|
|
||||||
}).collect()
|
|
||||||
}
|
|
||||||
}).collect();
|
|
||||||
IndexedModel{
|
|
||||||
unique_pos: data.position.clone(),
|
|
||||||
unique_tex: data.texture.clone(),
|
|
||||||
unique_normal: data.normal.clone(),
|
|
||||||
unique_color: vec![color],
|
|
||||||
unique_vertices,
|
|
||||||
groups,
|
|
||||||
instances:Vec::new(),
|
|
||||||
}
|
|
||||||
}).collect()
|
|
||||||
}
|
|
||||||
@@ -1,503 +0,0 @@
|
|||||||
use crate::model::{IndexedModel, IndexedPolygon, IndexedGroup, IndexedVertex};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Primitives{
|
|
||||||
Sphere,
|
|
||||||
Cube,
|
|
||||||
Cylinder,
|
|
||||||
Wedge,
|
|
||||||
CornerWedge,
|
|
||||||
}
|
|
||||||
#[derive(Hash,PartialEq,Eq)]
|
|
||||||
pub enum CubeFace{
|
|
||||||
Right,
|
|
||||||
Top,
|
|
||||||
Back,
|
|
||||||
Left,
|
|
||||||
Bottom,
|
|
||||||
Front,
|
|
||||||
}
|
|
||||||
const CUBE_DEFAULT_TEXTURE_COORDS:[[f32;2];4]=[[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0]];
|
|
||||||
const CUBE_DEFAULT_VERTICES:[[f32;3];8]=[
|
|
||||||
[-1.,-1., 1.],//0 left bottom back
|
|
||||||
[ 1.,-1., 1.],//1 right bottom back
|
|
||||||
[ 1., 1., 1.],//2 right top back
|
|
||||||
[-1., 1., 1.],//3 left top back
|
|
||||||
[-1., 1.,-1.],//4 left top front
|
|
||||||
[ 1., 1.,-1.],//5 right top front
|
|
||||||
[ 1.,-1.,-1.],//6 right bottom front
|
|
||||||
[-1.,-1.,-1.],//7 left bottom front
|
|
||||||
];
|
|
||||||
const CUBE_DEFAULT_NORMALS:[[f32;3];6]=[
|
|
||||||
[ 1., 0., 0.],//CubeFace::Right
|
|
||||||
[ 0., 1., 0.],//CubeFace::Top
|
|
||||||
[ 0., 0., 1.],//CubeFace::Back
|
|
||||||
[-1., 0., 0.],//CubeFace::Left
|
|
||||||
[ 0.,-1., 0.],//CubeFace::Bottom
|
|
||||||
[ 0., 0.,-1.],//CubeFace::Front
|
|
||||||
];
|
|
||||||
const CUBE_DEFAULT_POLYS:[[[u32;3];4];6]=[
|
|
||||||
// right (1, 0, 0)
|
|
||||||
[
|
|
||||||
[6,2,0],//[vertex,tex,norm]
|
|
||||||
[5,1,0],
|
|
||||||
[2,0,0],
|
|
||||||
[1,3,0],
|
|
||||||
],
|
|
||||||
// top (0, 1, 0)
|
|
||||||
[
|
|
||||||
[5,3,1],
|
|
||||||
[4,2,1],
|
|
||||||
[3,1,1],
|
|
||||||
[2,0,1],
|
|
||||||
],
|
|
||||||
// back (0, 0, 1)
|
|
||||||
[
|
|
||||||
[0,3,2],
|
|
||||||
[1,2,2],
|
|
||||||
[2,1,2],
|
|
||||||
[3,0,2],
|
|
||||||
],
|
|
||||||
// left (-1, 0, 0)
|
|
||||||
[
|
|
||||||
[0,2,3],
|
|
||||||
[3,1,3],
|
|
||||||
[4,0,3],
|
|
||||||
[7,3,3],
|
|
||||||
],
|
|
||||||
// bottom (0,-1, 0)
|
|
||||||
[
|
|
||||||
[1,1,4],
|
|
||||||
[0,0,4],
|
|
||||||
[7,3,4],
|
|
||||||
[6,2,4],
|
|
||||||
],
|
|
||||||
// front (0, 0,-1)
|
|
||||||
[
|
|
||||||
[4,1,5],
|
|
||||||
[5,0,5],
|
|
||||||
[6,3,5],
|
|
||||||
[7,2,5],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
#[derive(Hash,PartialEq,Eq)]
|
|
||||||
pub enum WedgeFace{
|
|
||||||
Right,
|
|
||||||
TopFront,
|
|
||||||
Back,
|
|
||||||
Left,
|
|
||||||
Bottom,
|
|
||||||
}
|
|
||||||
const WEDGE_DEFAULT_NORMALS:[[f32;3];5]=[
|
|
||||||
[ 1., 0., 0.],//Wedge::Right
|
|
||||||
[ 0., 1.,-1.],//Wedge::TopFront
|
|
||||||
[ 0., 0., 1.],//Wedge::Back
|
|
||||||
[-1., 0., 0.],//Wedge::Left
|
|
||||||
[ 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{
|
|
||||||
Top,
|
|
||||||
Right,
|
|
||||||
Bottom,
|
|
||||||
Front,
|
|
||||||
}
|
|
||||||
const CORNERWEDGE_DEFAULT_NORMALS:[[f32;3];5]=[
|
|
||||||
[ 1., 0., 0.],//Wedge::Right
|
|
||||||
[ 0., 1., 1.],//Wedge::BackTop
|
|
||||||
[-1., 1., 0.],//Wedge::LeftTop
|
|
||||||
[ 0.,-1., 0.],//Wedge::Bottom
|
|
||||||
[ 0., 0.,-1.],//Wedge::Front
|
|
||||||
];
|
|
||||||
//HashMap fits this use case perfectly but feels like using a sledgehammer to drive a nail
|
|
||||||
pub fn unit_sphere()->crate::model::IndexedModel{
|
|
||||||
let mut indexed_model=crate::model::generate_indexed_model_list_from_obj(obj::ObjData::load_buf(&include_bytes!("../models/suzanne.obj")[..]).unwrap(),*glam::Vec4::ONE.as_ref()).remove(0);
|
|
||||||
for pos in indexed_model.unique_pos.iter_mut(){
|
|
||||||
pos[0]=pos[0]*0.5;
|
|
||||||
pos[1]=pos[1]*0.5;
|
|
||||||
pos[2]=pos[2]*0.5;
|
|
||||||
}
|
|
||||||
indexed_model
|
|
||||||
}
|
|
||||||
pub type CubeFaceDescription=std::collections::HashMap::<CubeFace,FaceDescription>;
|
|
||||||
pub fn unit_cube()->crate::model::IndexedModel{
|
|
||||||
let mut t=CubeFaceDescription::new();
|
|
||||||
t.insert(CubeFace::Right,FaceDescription::default());
|
|
||||||
t.insert(CubeFace::Top,FaceDescription::default());
|
|
||||||
t.insert(CubeFace::Back,FaceDescription::default());
|
|
||||||
t.insert(CubeFace::Left,FaceDescription::default());
|
|
||||||
t.insert(CubeFace::Bottom,FaceDescription::default());
|
|
||||||
t.insert(CubeFace::Front,FaceDescription::default());
|
|
||||||
generate_partial_unit_cube(t)
|
|
||||||
}
|
|
||||||
const TEAPOT_TRANSFORM:glam::Mat3=glam::mat3(glam::vec3(0.0,0.1,0.0),glam::vec3(-0.1,0.0,0.0),glam::vec3(0.0,0.0,0.1));
|
|
||||||
pub fn unit_cylinder()->crate::model::IndexedModel{
|
|
||||||
let mut indexed_model=crate::model::generate_indexed_model_list_from_obj(obj::ObjData::load_buf(&include_bytes!("../models/teapot.obj")[..]).unwrap(),*glam::Vec4::ONE.as_ref()).remove(0);
|
|
||||||
for pos in indexed_model.unique_pos.iter_mut(){
|
|
||||||
[pos[0],pos[1],pos[2]]=*(TEAPOT_TRANSFORM*glam::Vec3::from_array(*pos)).as_ref();
|
|
||||||
}
|
|
||||||
indexed_model
|
|
||||||
}
|
|
||||||
pub type WedgeFaceDescription=std::collections::HashMap::<WedgeFace,FaceDescription>;
|
|
||||||
pub fn unit_wedge()->crate::model::IndexedModel{
|
|
||||||
let mut t=WedgeFaceDescription::new();
|
|
||||||
t.insert(WedgeFace::Right,FaceDescription::default());
|
|
||||||
t.insert(WedgeFace::TopFront,FaceDescription::default());
|
|
||||||
t.insert(WedgeFace::Back,FaceDescription::default());
|
|
||||||
t.insert(WedgeFace::Left,FaceDescription::default());
|
|
||||||
t.insert(WedgeFace::Bottom,FaceDescription::default());
|
|
||||||
generate_partial_unit_wedge(t)
|
|
||||||
}
|
|
||||||
pub type CornerWedgeFaceDescription=std::collections::HashMap::<CornerWedgeFace,FaceDescription>;
|
|
||||||
pub fn unit_cornerwedge()->crate::model::IndexedModel{
|
|
||||||
let mut t=CornerWedgeFaceDescription::new();
|
|
||||||
t.insert(CornerWedgeFace::Right,FaceDescription::default());
|
|
||||||
t.insert(CornerWedgeFace::Top,FaceDescription::default());
|
|
||||||
t.insert(CornerWedgeFace::Bottom,FaceDescription::default());
|
|
||||||
t.insert(CornerWedgeFace::Front,FaceDescription::default());
|
|
||||||
generate_partial_unit_cornerwedge(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Copy,Clone)]
|
|
||||||
pub struct FaceDescription{
|
|
||||||
pub texture:Option<u32>,
|
|
||||||
pub transform:glam::Affine2,
|
|
||||||
pub color:glam::Vec4,
|
|
||||||
}
|
|
||||||
impl std::default::Default for FaceDescription{
|
|
||||||
fn default()->Self {
|
|
||||||
Self{
|
|
||||||
texture:None,
|
|
||||||
transform:glam::Affine2::IDENTITY,
|
|
||||||
color:glam::vec4(1.0,1.0,1.0,0.0),//zero alpha to hide the default texture
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl FaceDescription{
|
|
||||||
pub fn new(texture:u32,transform:glam::Affine2,color:glam::Vec4)->Self{
|
|
||||||
Self{texture:Some(texture),transform,color}
|
|
||||||
}
|
|
||||||
pub fn from_texture(texture:u32)->Self{
|
|
||||||
Self{
|
|
||||||
texture:Some(texture),
|
|
||||||
transform:glam::Affine2::IDENTITY,
|
|
||||||
color:glam::Vec4::ONE,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//TODO: it's probably better to use a shared vertex buffer between all primitives and use indexed rendering instead of generating a unique vertex buffer for each primitive.
|
|
||||||
//implementation: put all roblox primitives into one model.groups <- this won't work but I forget why
|
|
||||||
pub fn generate_partial_unit_cube(face_descriptions:CubeFaceDescription)->crate::model::IndexedModel{
|
|
||||||
let mut generated_pos=Vec::<[f32;3]>::new();
|
|
||||||
let mut generated_tex=Vec::new();
|
|
||||||
let mut generated_normal=Vec::new();
|
|
||||||
let mut generated_color=Vec::new();
|
|
||||||
let mut generated_vertices=Vec::new();
|
|
||||||
let mut groups=Vec::new();
|
|
||||||
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,face_description) in face_descriptions.iter(){
|
|
||||||
//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
|
|
||||||
}else{
|
|
||||||
//create new transform_index
|
|
||||||
let transform_index=transforms.len();
|
|
||||||
transforms.push(face_description.transform);
|
|
||||||
for tex in CUBE_DEFAULT_TEXTURE_COORDS{
|
|
||||||
generated_tex.push(*face_description.transform.transform_point2(glam::Vec2::from_array(tex)).as_ref());
|
|
||||||
}
|
|
||||||
transform_index
|
|
||||||
} as u32;
|
|
||||||
let color_index=if let Some(color_index)=generated_color.iter().position(|color|color==face_description.color.as_ref()){
|
|
||||||
color_index
|
|
||||||
}else{
|
|
||||||
//create new color_index
|
|
||||||
let color_index=generated_color.len();
|
|
||||||
generated_color.push(*face_description.color.as_ref());
|
|
||||||
color_index
|
|
||||||
} as u32;
|
|
||||||
let face_id=match face{
|
|
||||||
CubeFace::Right => 0,
|
|
||||||
CubeFace::Top => 1,
|
|
||||||
CubeFace::Back => 2,
|
|
||||||
CubeFace::Left => 3,
|
|
||||||
CubeFace::Bottom => 4,
|
|
||||||
CubeFace::Front => 5,
|
|
||||||
};
|
|
||||||
//always push normal
|
|
||||||
let normal_index=generated_normal.len() as u32;
|
|
||||||
generated_normal.push(CUBE_DEFAULT_NORMALS[face_id]);
|
|
||||||
//push vertices as they are needed
|
|
||||||
groups.push(IndexedGroup{
|
|
||||||
texture:face_description.texture,
|
|
||||||
polys:vec![IndexedPolygon{
|
|
||||||
vertices:CUBE_DEFAULT_POLYS[face_id].map(|tup|{
|
|
||||||
let pos=CUBE_DEFAULT_VERTICES[tup[0] as usize];
|
|
||||||
let pos_index=if let Some(pos_index)=generated_pos.iter().position(|&p|p==pos){
|
|
||||||
pos_index
|
|
||||||
}else{
|
|
||||||
//create new pos_index
|
|
||||||
let pos_index=generated_pos.len();
|
|
||||||
generated_pos.push(pos);
|
|
||||||
pos_index
|
|
||||||
} as u32;
|
|
||||||
//always push vertex
|
|
||||||
let vertex=IndexedVertex{
|
|
||||||
pos:pos_index,
|
|
||||||
tex:tup[1]+4*transform_index,
|
|
||||||
normal:normal_index,
|
|
||||||
color:color_index,
|
|
||||||
};
|
|
||||||
let vert_index=generated_vertices.len();
|
|
||||||
generated_vertices.push(vertex);
|
|
||||||
vert_index as u32
|
|
||||||
}).to_vec(),
|
|
||||||
}],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
IndexedModel{
|
|
||||||
unique_pos:generated_pos,
|
|
||||||
unique_tex:generated_tex,
|
|
||||||
unique_normal:generated_normal,
|
|
||||||
unique_color:generated_color,
|
|
||||||
unique_vertices:generated_vertices,
|
|
||||||
groups,
|
|
||||||
instances:Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//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)->crate::model::IndexedModel{
|
|
||||||
let wedge_default_polys=vec![
|
|
||||||
// right (1, 0, 0)
|
|
||||||
vec![
|
|
||||||
[6,2,0],//[vertex,tex,norm]
|
|
||||||
[2,0,0],
|
|
||||||
[1,3,0],
|
|
||||||
],
|
|
||||||
// FrontTop (0, 1, -1)
|
|
||||||
vec![
|
|
||||||
[3,1,1],
|
|
||||||
[2,0,1],
|
|
||||||
[6,3,1],
|
|
||||||
[7,2,1],
|
|
||||||
],
|
|
||||||
// back (0, 0, 1)
|
|
||||||
vec![
|
|
||||||
[0,3,2],
|
|
||||||
[1,2,2],
|
|
||||||
[2,1,2],
|
|
||||||
[3,0,2],
|
|
||||||
],
|
|
||||||
// left (-1, 0, 0)
|
|
||||||
vec![
|
|
||||||
[0,2,3],
|
|
||||||
[3,1,3],
|
|
||||||
[7,3,3],
|
|
||||||
],
|
|
||||||
// bottom (0,-1, 0)
|
|
||||||
vec![
|
|
||||||
[1,1,4],
|
|
||||||
[0,0,4],
|
|
||||||
[7,3,4],
|
|
||||||
[6,2,4],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
let mut generated_pos=Vec::<[f32;3]>::new();
|
|
||||||
let mut generated_tex=Vec::new();
|
|
||||||
let mut generated_normal=Vec::new();
|
|
||||||
let mut generated_color=Vec::new();
|
|
||||||
let mut generated_vertices=Vec::new();
|
|
||||||
let mut groups=Vec::new();
|
|
||||||
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,face_description) in face_descriptions.iter(){
|
|
||||||
//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
|
|
||||||
}else{
|
|
||||||
//create new transform_index
|
|
||||||
let transform_index=transforms.len();
|
|
||||||
transforms.push(face_description.transform);
|
|
||||||
for tex in CUBE_DEFAULT_TEXTURE_COORDS{
|
|
||||||
generated_tex.push(*face_description.transform.transform_point2(glam::Vec2::from_array(tex)).as_ref());
|
|
||||||
}
|
|
||||||
transform_index
|
|
||||||
} as u32;
|
|
||||||
let color_index=if let Some(color_index)=generated_color.iter().position(|color|color==face_description.color.as_ref()){
|
|
||||||
color_index
|
|
||||||
}else{
|
|
||||||
//create new color_index
|
|
||||||
let color_index=generated_color.len();
|
|
||||||
generated_color.push(*face_description.color.as_ref());
|
|
||||||
color_index
|
|
||||||
} as u32;
|
|
||||||
let face_id=match face{
|
|
||||||
WedgeFace::Right => 0,
|
|
||||||
WedgeFace::TopFront => 1,
|
|
||||||
WedgeFace::Back => 2,
|
|
||||||
WedgeFace::Left => 3,
|
|
||||||
WedgeFace::Bottom => 4,
|
|
||||||
};
|
|
||||||
//always push normal
|
|
||||||
let normal_index=generated_normal.len() as u32;
|
|
||||||
generated_normal.push(WEDGE_DEFAULT_NORMALS[face_id]);
|
|
||||||
//push vertices as they are needed
|
|
||||||
groups.push(IndexedGroup{
|
|
||||||
texture:face_description.texture,
|
|
||||||
polys:vec![IndexedPolygon{
|
|
||||||
vertices:wedge_default_polys[face_id].iter().map(|tup|{
|
|
||||||
let pos=CUBE_DEFAULT_VERTICES[tup[0] as usize];
|
|
||||||
let pos_index=if let Some(pos_index)=generated_pos.iter().position(|&p|p==pos){
|
|
||||||
pos_index
|
|
||||||
}else{
|
|
||||||
//create new pos_index
|
|
||||||
let pos_index=generated_pos.len();
|
|
||||||
generated_pos.push(pos);
|
|
||||||
pos_index
|
|
||||||
} as u32;
|
|
||||||
//always push vertex
|
|
||||||
let vertex=IndexedVertex{
|
|
||||||
pos:pos_index,
|
|
||||||
tex:tup[1]+4*transform_index,
|
|
||||||
normal:normal_index,
|
|
||||||
color:color_index,
|
|
||||||
};
|
|
||||||
let vert_index=generated_vertices.len();
|
|
||||||
generated_vertices.push(vertex);
|
|
||||||
vert_index as u32
|
|
||||||
}).collect(),
|
|
||||||
}],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
IndexedModel{
|
|
||||||
unique_pos:generated_pos,
|
|
||||||
unique_tex:generated_tex,
|
|
||||||
unique_normal:generated_normal,
|
|
||||||
unique_color:generated_color,
|
|
||||||
unique_vertices:generated_vertices,
|
|
||||||
groups,
|
|
||||||
instances:Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn generate_partial_unit_cornerwedge(face_descriptions:CornerWedgeFaceDescription)->crate::model::IndexedModel{
|
|
||||||
let cornerwedge_default_polys=vec![
|
|
||||||
// right (1, 0, 0)
|
|
||||||
vec![
|
|
||||||
[6,2,0],//[vertex,tex,norm]
|
|
||||||
[5,1,0],
|
|
||||||
[1,3,0],
|
|
||||||
],
|
|
||||||
// BackTop (0, 1, 1)
|
|
||||||
vec![
|
|
||||||
[5,3,1],
|
|
||||||
[0,1,1],
|
|
||||||
[1,0,1],
|
|
||||||
],
|
|
||||||
// LeftTop (-1, 1, 0)
|
|
||||||
vec![
|
|
||||||
[5,3,2],
|
|
||||||
[7,2,2],
|
|
||||||
[0,1,2],
|
|
||||||
],
|
|
||||||
// bottom (0,-1, 0)
|
|
||||||
vec![
|
|
||||||
[1,1,3],
|
|
||||||
[0,0,3],
|
|
||||||
[7,3,3],
|
|
||||||
[6,2,3],
|
|
||||||
],
|
|
||||||
// front (0, 0,-1)
|
|
||||||
vec![
|
|
||||||
[5,0,4],
|
|
||||||
[6,3,4],
|
|
||||||
[7,2,4],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
let mut generated_pos=Vec::<[f32;3]>::new();
|
|
||||||
let mut generated_tex=Vec::new();
|
|
||||||
let mut generated_normal=Vec::new();
|
|
||||||
let mut generated_color=Vec::new();
|
|
||||||
let mut generated_vertices=Vec::new();
|
|
||||||
let mut groups=Vec::new();
|
|
||||||
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,face_description) in face_descriptions.iter(){
|
|
||||||
//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
|
|
||||||
}else{
|
|
||||||
//create new transform_index
|
|
||||||
let transform_index=transforms.len();
|
|
||||||
transforms.push(face_description.transform);
|
|
||||||
for tex in CUBE_DEFAULT_TEXTURE_COORDS{
|
|
||||||
generated_tex.push(*face_description.transform.transform_point2(glam::Vec2::from_array(tex)).as_ref());
|
|
||||||
}
|
|
||||||
transform_index
|
|
||||||
} as u32;
|
|
||||||
let color_index=if let Some(color_index)=generated_color.iter().position(|color|color==face_description.color.as_ref()){
|
|
||||||
color_index
|
|
||||||
}else{
|
|
||||||
//create new color_index
|
|
||||||
let color_index=generated_color.len();
|
|
||||||
generated_color.push(*face_description.color.as_ref());
|
|
||||||
color_index
|
|
||||||
} as u32;
|
|
||||||
let face_id=match face{
|
|
||||||
CornerWedgeFace::Right => 0,
|
|
||||||
CornerWedgeFace::Top => 1,
|
|
||||||
CornerWedgeFace::Bottom => 2,
|
|
||||||
CornerWedgeFace::Front => 3,
|
|
||||||
};
|
|
||||||
//always push normal
|
|
||||||
let normal_index=generated_normal.len() as u32;
|
|
||||||
generated_normal.push(CORNERWEDGE_DEFAULT_NORMALS[face_id]);
|
|
||||||
//push vertices as they are needed
|
|
||||||
groups.push(IndexedGroup{
|
|
||||||
texture:face_description.texture,
|
|
||||||
polys:vec![IndexedPolygon{
|
|
||||||
vertices:cornerwedge_default_polys[face_id].iter().map(|tup|{
|
|
||||||
let pos=CUBE_DEFAULT_VERTICES[tup[0] as usize];
|
|
||||||
let pos_index=if let Some(pos_index)=generated_pos.iter().position(|&p|p==pos){
|
|
||||||
pos_index
|
|
||||||
}else{
|
|
||||||
//create new pos_index
|
|
||||||
let pos_index=generated_pos.len();
|
|
||||||
generated_pos.push(pos);
|
|
||||||
pos_index
|
|
||||||
} as u32;
|
|
||||||
//always push vertex
|
|
||||||
let vertex=IndexedVertex{
|
|
||||||
pos:pos_index,
|
|
||||||
tex:tup[1]+4*transform_index,
|
|
||||||
normal:normal_index,
|
|
||||||
color:color_index,
|
|
||||||
};
|
|
||||||
let vert_index=generated_vertices.len();
|
|
||||||
generated_vertices.push(vertex);
|
|
||||||
vert_index as u32
|
|
||||||
}).collect(),
|
|
||||||
}],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
IndexedModel{
|
|
||||||
unique_pos:generated_pos,
|
|
||||||
unique_tex:generated_tex,
|
|
||||||
unique_normal:generated_normal,
|
|
||||||
unique_color:generated_color,
|
|
||||||
unique_vertices:generated_vertices,
|
|
||||||
groups,
|
|
||||||
instances:Vec::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -41,22 +41,19 @@ fn vs_sky(@builtin(vertex_index) vertex_index: u32) -> SkyOutput {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ModelInstance{
|
const MAX_ENTITY_INSTANCES=1024;
|
||||||
transform:mat4x4<f32>,
|
//group 1 is the model
|
||||||
normal_transform:mat4x4<f32>,
|
@group(1)
|
||||||
color:vec4<f32>,
|
@binding(0)
|
||||||
}
|
var<uniform> entity_transforms: array<mat4x4<f32>,MAX_ENTITY_INSTANCES>;
|
||||||
|
//var<uniform> entity_texture_transforms: array<mat3x3<f32>,MAX_ENTITY_INSTANCES>;
|
||||||
//my fancy idea is to create a megatexture for each model that includes all the textures each intance will need
|
//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
|
//the texture transform then maps the texture coordinates to the location of the specific texture
|
||||||
//group 1 is the model
|
//how to do no texture?
|
||||||
const MAX_MODEL_INSTANCES=4096;
|
@group(1)
|
||||||
@group(2)
|
|
||||||
@binding(0)
|
|
||||||
var<uniform> model_instances: array<ModelInstance, MAX_MODEL_INSTANCES>;
|
|
||||||
@group(2)
|
|
||||||
@binding(1)
|
@binding(1)
|
||||||
var model_texture: texture_2d<f32>;
|
var model_texture: texture_2d<f32>;
|
||||||
@group(2)
|
@group(1)
|
||||||
@binding(2)
|
@binding(2)
|
||||||
var model_sampler: sampler;
|
var model_sampler: sampler;
|
||||||
|
|
||||||
@@ -65,8 +62,6 @@ struct EntityOutputTexture {
|
|||||||
@location(1) texture: vec2<f32>,
|
@location(1) texture: vec2<f32>,
|
||||||
@location(2) normal: vec3<f32>,
|
@location(2) normal: vec3<f32>,
|
||||||
@location(3) view: vec3<f32>,
|
@location(3) view: vec3<f32>,
|
||||||
@location(4) color: vec4<f32>,
|
|
||||||
@location(5) @interpolate(flat) model_color: vec4<f32>,
|
|
||||||
};
|
};
|
||||||
@vertex
|
@vertex
|
||||||
fn vs_entity_texture(
|
fn vs_entity_texture(
|
||||||
@@ -74,30 +69,27 @@ fn vs_entity_texture(
|
|||||||
@location(0) pos: vec3<f32>,
|
@location(0) pos: vec3<f32>,
|
||||||
@location(1) texture: vec2<f32>,
|
@location(1) texture: vec2<f32>,
|
||||||
@location(2) normal: vec3<f32>,
|
@location(2) normal: vec3<f32>,
|
||||||
@location(3) color: vec4<f32>,
|
|
||||||
) -> EntityOutputTexture {
|
) -> EntityOutputTexture {
|
||||||
var position: vec4<f32> = model_instances[instance].transform * vec4<f32>(pos, 1.0);
|
var position: vec4<f32> = entity_transforms[instance] * vec4<f32>(pos, 1.0);
|
||||||
var result: EntityOutputTexture;
|
var result: EntityOutputTexture;
|
||||||
result.normal = (model_instances[instance].normal_transform * vec4<f32>(normal, 1.0)).xyz;
|
result.normal = (entity_transforms[instance] * vec4<f32>(normal, 0.0)).xyz;
|
||||||
result.texture = texture;
|
result.texture=texture;//(entity_texture_transforms[instance] * vec3<f32>(texture, 1.0)).xy;
|
||||||
result.color = color;
|
|
||||||
result.model_color = model_instances[instance].color;
|
|
||||||
result.view = position.xyz - camera.cam_pos.xyz;
|
result.view = position.xyz - camera.cam_pos.xyz;
|
||||||
result.position = camera.proj * camera.view * position;
|
result.position = camera.proj * camera.view * position;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//group 2 is the skybox texture
|
//group 2 is the skybox texture
|
||||||
@group(1)
|
@group(2)
|
||||||
@binding(0)
|
@binding(0)
|
||||||
var cube_texture: texture_cube<f32>;
|
var cube_texture: texture_cube<f32>;
|
||||||
@group(1)
|
@group(2)
|
||||||
@binding(1)
|
@binding(1)
|
||||||
var cube_sampler: sampler;
|
var cube_sampler: sampler;
|
||||||
|
|
||||||
@fragment
|
@fragment
|
||||||
fn fs_sky(vertex: SkyOutput) -> @location(0) vec4<f32> {
|
fn fs_sky(vertex: SkyOutput) -> @location(0) vec4<f32> {
|
||||||
return textureSample(cube_texture, cube_sampler, vertex.sampledir);
|
return textureSample(cube_texture, model_sampler, vertex.sampledir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@fragment
|
@fragment
|
||||||
@@ -107,7 +99,7 @@ fn fs_entity_texture(vertex: EntityOutputTexture) -> @location(0) vec4<f32> {
|
|||||||
let d = dot(normal, incident);
|
let d = dot(normal, incident);
|
||||||
let reflected = incident - 2.0 * d * normal;
|
let reflected = incident - 2.0 * d * normal;
|
||||||
|
|
||||||
let fragment_color = textureSample(model_texture, model_sampler, vertex.texture)*vertex.color;
|
let fragment_color = textureSample(model_texture, model_sampler, vertex.texture).rgb;
|
||||||
let reflected_color = textureSample(cube_texture, cube_sampler, reflected).rgb;
|
let reflected_color = textureSample(cube_texture, cube_sampler, reflected).rgb;
|
||||||
return mix(vec4<f32>(vec3<f32>(0.05) + 0.2 * reflected_color,1.0),mix(vertex.model_color,vec4<f32>(fragment_color.rgb,1.0),fragment_color.a),1.0-pow(1.0-abs(d),2.0));
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//find roots of polynomials
|
//find roots of polynomials
|
||||||
#[inline]
|
|
||||||
pub fn zeroes2(a0:f32,a1:f32,a2:f32) -> Vec<f32>{
|
pub fn zeroes2(a0:f32,a1:f32,a2:f32) -> Vec<f32>{
|
||||||
if a2==0f32{
|
if a2==0f32{
|
||||||
return zeroes1(a0, a1);
|
return zeroes1(a0, a1);
|
||||||
|
|||||||
Reference in New Issue
Block a user