4 Commits

Author SHA1 Message Date
4a2cdac65c copy graphical data 2026-03-26 14:10:21 -07:00
1e3c01e419 sigmoid 2026-03-26 13:48:43 -07:00
27b02025e7 png 2026-03-26 13:29:59 -07:00
9c455141cf png 2026-03-26 13:24:08 -07:00
3 changed files with 36 additions and 4 deletions

1
Cargo.lock generated
View File

@@ -5451,6 +5451,7 @@ name = "strafe-ai"
version = "0.1.0"
dependencies = [
"burn",
"png",
"pollster",
"strafesnet_common",
"strafesnet_graphics",

View File

@@ -14,3 +14,4 @@ strafesnet_roblox_bot_file = { version = "0.9.4", registry = "strafesnet" }
strafesnet_roblox_bot_player = { version = "=0.6.2-depth", registry = "strafesnet" }
strafesnet_snf = { version = "0.4.0", registry = "strafesnet" }
pollster = "0.4.0"
png = "0.18.1"

View File

@@ -11,6 +11,21 @@ const LIMITS: wgpu::Limits = wgpu::Limits::defaults();
use strafesnet_graphics::setup;
use strafesnet_roblox_bot_file::v0;
pub fn output_image_native(image_data: &[u8], texture_dims: (usize, usize), path: String) {
use std::io::Write;
let mut png_data = Vec::<u8>::with_capacity(image_data.len());
let mut encoder =
png::Encoder::new(&mut png_data, texture_dims.0 as u32, texture_dims.1 as u32);
encoder.set_color(png::ColorType::Grayscale);
let mut png_writer = encoder.write_header().unwrap();
png_writer.write_image_data(image_data).unwrap();
png_writer.finish().unwrap();
let mut file = std::fs::File::create(&path).unwrap();
file.write_all(&png_data).unwrap();
}
const SIZE_X: usize = 64;
const SIZE_Y: usize = 36;
const INPUT: usize = SIZE_X * SIZE_Y;
@@ -129,7 +144,9 @@ fn training() {
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::TEXTURE_BINDING
| wgpu::TextureUsages::COPY_SRC,
view_formats: &[],
});
let graphics_texture_view = graphics_texture.create_view(&wgpu::TextureViewDescriptor {
@@ -164,7 +181,7 @@ fn training() {
let mut last_mx = first.event.mouse_pos.x;
let mut last_my = first.event.mouse_pos.y;
for input_event in it {
for (i, input_event) in it.enumerate() {
let mouse_dx = input_event.event.mouse_pos.x - last_mx;
let mouse_dy = input_event.event.mouse_pos.y - last_my;
last_mx = input_event.event.mouse_pos.x;
@@ -251,7 +268,7 @@ fn training() {
// copy the depth texture into ram
encoder.copy_texture_to_buffer(
wgpu::TexelCopyTextureInfo {
texture: graphics.depth_texture(),
texture: &graphics_texture,
mip_level: 0,
origin: wgpu::Origin3d::ZERO,
aspect: wgpu::TextureAspect::All,
@@ -288,16 +305,29 @@ fn training() {
}
output_staging_buffer.unmap();
println!("{texture_data:?}");
// discombolulate stride
for y in 0..size.y {
inputs.extend(
texture_data[(stride_size * y) as usize
..(stride_size * y + size.x * size_of::<f32>() as u32) as usize]
.chunks_exact(4)
.map(|b| f32::from_le_bytes(b.try_into().unwrap())),
.map(|b| b[0] as f32 + b[1] as f32 + b[2] as f32),
)
}
// write a png
output_image_native(
&inputs[i * INPUT..(i + 1) * INPUT]
.iter()
.copied()
.map(|f| (f * 255.0) as u8)
.collect::<Vec<u8>>(),
(SIZE_X, SIZE_Y),
format!("depth_images/{i}.png").into(),
);
texture_data.clear();
}