7 Commits

Author SHA1 Message Date
c5ec89093d fix it 2026-03-27 09:51:08 -07:00
1fab9524bd copy graphical data 2026-03-27 09:34:33 -07:00
77fcb52731 sigmoid 2026-03-27 09:34:33 -07:00
5902f4fb1b png 2026-03-27 09:34:33 -07:00
1f7dbbfee9 png 2026-03-27 09:34:33 -07:00
f496b0ecb0 use none for rows_per_image 2026-03-27 09:34:33 -07:00
d60ba4da04 include world offset 2026-03-27 09:34:33 -07:00
3 changed files with 44 additions and 6 deletions

1
Cargo.lock generated
View File

@@ -5451,6 +5451,7 @@ name = "strafe-ai"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"burn", "burn",
"png",
"pollster", "pollster",
"strafesnet_common", "strafesnet_common",
"strafesnet_graphics", "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_roblox_bot_player = { version = "=0.6.2-depth", registry = "strafesnet" }
strafesnet_snf = { version = "0.4.0", registry = "strafesnet" } strafesnet_snf = { version = "0.4.0", registry = "strafesnet" }
pollster = "0.4.0" 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_graphics::setup;
use strafesnet_roblox_bot_file::v0; 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_X: usize = 64;
const SIZE_Y: usize = 36; const SIZE_Y: usize = 36;
const INPUT: usize = SIZE_X * SIZE_Y; const INPUT: usize = SIZE_X * SIZE_Y;
@@ -89,6 +104,9 @@ fn training() {
.unwrap(); .unwrap();
let timelines = let timelines =
strafesnet_roblox_bot_file::v0::read_all_to_block(std::io::Cursor::new(bot_file)).unwrap(); strafesnet_roblox_bot_file::v0::read_all_to_block(std::io::Cursor::new(bot_file)).unwrap();
let bot = strafesnet_roblox_bot_player::bot::CompleteBot::new(timelines).unwrap();
let world_offset = bot.world_offset();
let timelines = bot.timelines();
// setup graphics // setup graphics
let desc = wgpu::InstanceDescriptor::new_without_display_handle_from_env(); let desc = wgpu::InstanceDescriptor::new_without_display_handle_from_env();
@@ -129,7 +147,9 @@ fn training() {
mip_level_count: 1, mip_level_count: 1,
sample_count: 1, sample_count: 1,
dimension: wgpu::TextureDimension::D2, 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: &[], view_formats: &[],
}); });
let graphics_texture_view = graphics_texture.create_view(&wgpu::TextureViewDescriptor { let graphics_texture_view = graphics_texture.create_view(&wgpu::TextureViewDescriptor {
@@ -164,7 +184,7 @@ fn training() {
let mut last_mx = first.event.mouse_pos.x; let mut last_mx = first.event.mouse_pos.x;
let mut last_my = first.event.mouse_pos.y; 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_dx = input_event.event.mouse_pos.x - last_mx;
let mouse_dy = input_event.event.mouse_pos.y - last_my; let mouse_dy = input_event.event.mouse_pos.y - last_my;
last_mx = input_event.event.mouse_pos.x; last_mx = input_event.event.mouse_pos.x;
@@ -235,6 +255,9 @@ fn training() {
fn a(a: v0::Vector3) -> [f32; 2] { fn a(a: v0::Vector3) -> [f32; 2] {
[a.y, a.x] [a.y, a.x]
} }
fn add<T: core::ops::Add>(lhs: T, rhs: T) -> T::Output {
lhs + rhs
}
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("wgpu encoder"), label: Some("wgpu encoder"),
@@ -244,14 +267,14 @@ fn training() {
graphics.encode_commands( graphics.encode_commands(
&mut encoder, &mut encoder,
&graphics_texture_view, &graphics_texture_view,
p(output_event.event.position).into(), add(world_offset, p(output_event.event.position).into()),
a(output_event.event.angles).into(), a(output_event.event.angles).into(),
); );
// copy the depth texture into ram // copy the depth texture into ram
encoder.copy_texture_to_buffer( encoder.copy_texture_to_buffer(
wgpu::TexelCopyTextureInfo { wgpu::TexelCopyTextureInfo {
texture: graphics.depth_texture(), texture: &graphics_texture,
mip_level: 0, mip_level: 0,
origin: wgpu::Origin3d::ZERO, origin: wgpu::Origin3d::ZERO,
aspect: wgpu::TextureAspect::All, aspect: wgpu::TextureAspect::All,
@@ -262,7 +285,7 @@ fn training() {
offset: 0, offset: 0,
// This needs to be a multiple of 256. // This needs to be a multiple of 256.
bytes_per_row: Some(stride_size as u32), bytes_per_row: Some(stride_size as u32),
rows_per_image: Some(size.y), rows_per_image: None,
}, },
}, },
wgpu::Extent3d { wgpu::Extent3d {
@@ -288,16 +311,29 @@ fn training() {
} }
output_staging_buffer.unmap(); output_staging_buffer.unmap();
println!("{texture_data:?}");
// discombolulate stride // discombolulate stride
for y in 0..size.y { for y in 0..size.y {
inputs.extend( inputs.extend(
texture_data[(stride_size * y) as usize texture_data[(stride_size * y) as usize
..(stride_size * y + size.x * size_of::<f32>() as u32) as usize] ..(stride_size * y + size.x * size_of::<f32>() as u32) as usize]
.chunks_exact(4) .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 as u8)
.collect::<Vec<u8>>(),
(SIZE_X, SIZE_Y),
format!("depth_images/{i}.png").into(),
);
texture_data.clear(); texture_data.clear();
} }