@@ -9,6 +9,7 @@ use smallvec::SmallVec;
99use sourcerenderer_core:: Vec3 ;
1010use sourcerenderer_core:: gpu:: { Format , SampleCount , TextureDimension , TextureInfo , TextureUsage } ;
1111use std:: sync:: Arc ;
12+ use crate :: renderer:: passes:: volume:: MARCHING_CUBES_MAX_SIZE ;
1213
1314pub struct RawVolumeLoaderTexture { }
1415
@@ -116,11 +117,12 @@ impl AssetLoader for RawVolumeLoaderTexture {
116117 progress. inc_finished ( 1 ) ;
117118
118119 log:: info!(
119- "Loading density data. Resolution: {}x{}x{}, {} voxels, spacing: {:?}" ,
120+ "Loading density data. Resolution: {}x{}x{}, {} voxels, {} bytes, spacing: {:?}" ,
120121 width,
121122 height,
122123 depth,
123124 ( width as usize ) * ( height as usize ) * ( depth as usize ) ,
125+ src_data_bytes. len( ) ,
124126 spacing,
125127 ) ;
126128
@@ -139,7 +141,7 @@ impl AssetLoader for RawVolumeLoaderTexture {
139141 data. push ( src_data_f16) ;
140142
141143 // Build lower mips
142- let mip_count = width. ilog2 ( ) . min ( height. ilog2 ( ) ) . min ( depth. ilog2 ( ) ) ;
144+ let mut mip_count = width. ilog2 ( ) . min ( height. ilog2 ( ) ) . min ( depth. ilog2 ( ) ) ;
143145 progress. inc_expected ( mip_count - 1 ) ;
144146 for mip in 1 ..mip_count {
145147 let source_image_width = width >> ( mip - 1 ) ;
@@ -261,6 +263,19 @@ impl AssetLoader for RawVolumeLoaderTexture {
261263 }
262264 progress. inc_finished ( 1 ) ;
263265
266+ if width > MARCHING_CUBES_MAX_SIZE || height > MARCHING_CUBES_MAX_SIZE || depth > MARCHING_CUBES_MAX_SIZE {
267+ log:: warn!( "Resolution larger than 512! Skipping mip 0" ) ;
268+ mips_boxed. remove ( 0 ) ;
269+ mips_boxed_min. remove ( 0 ) ;
270+ mips_boxed_max. remove ( 0 ) ;
271+
272+ width /= 2 ;
273+ height /= 2 ;
274+ depth /= 2 ;
275+ mip_count -= 1 ;
276+ }
277+ assert_eq ! ( mips_boxed. len( ) , mip_count as usize ) ;
278+
264279 manager. add_asset_data_with_progress (
265280 file. path ( ) ,
266281 AssetData :: Texture ( TextureData {
0 commit comments