@@ -45,26 +45,23 @@ protected void VoxelizeData(BodyDataDTO data)
4545 data . BodyVertices [ i ] = new Vector3 ( ( float ) Math . Truncate ( data . BodyVertices [ i ] . X * _scale ) , ( float ) Math . Truncate ( data . BodyVertices [ i ] . Y * _scale ) , ( float ) Math . Truncate ( data . BodyVertices [ i ] . Z * _scale ) ) ;
4646 }
4747
48- ConcurrentDictionary < Vector3 , byte > set = new ConcurrentDictionary < Vector3 , byte > ( ) ;
49- ConcurrentBag < Vector3 > vertices = new ConcurrentBag < Vector3 > ( ) ;
50- ConcurrentBag < Color > colors = new ConcurrentBag < Color > ( ) ;
48+ HashSet < Vector3 > set = new HashSet < Vector3 > ( ) ;
49+ List < Vector3 > vertices = new List < Vector3 > ( ) ;
50+ List < Color > colors = new List < Color > ( ) ;
5151
5252 Console . WriteLine ( "[LOG] Started to voxelize data..." ) ;
53-
5453 using ( ProgressBar progressbar = new ProgressBar ( ) )
5554 {
56- int index = 0 ;
57- Parallel . For ( 0 , data . BodyVertices . Count , i =>
55+ for ( int i = 0 ; i < data . BodyVertices . Count ; i ++ )
5856 {
59- if ( ! set . ContainsKey ( data . BodyVertices [ i ] ) )
57+ if ( ! set . Contains ( data . BodyVertices [ i ] ) )
6058 {
61- set . TryAdd ( data . BodyVertices [ i ] , 0 ) ;
59+ set . Add ( data . BodyVertices [ i ] ) ;
6260 vertices . Add ( data . BodyVertices [ i ] ) ;
6361 colors . Add ( data . BodyColors [ i ] ) ;
6462 }
65- progressbar . Report ( index / ( float ) data . BodyVertices . Count ) ;
66- index ++ ;
67- } ) ;
63+ progressbar . Report ( i / ( float ) data . BodyVertices . Count ) ;
64+ }
6865 }
6966 Console . WriteLine ( "[LOG] Done." ) ;
7067
@@ -73,15 +70,13 @@ protected void VoxelizeData(BodyDataDTO data)
7370 minZ = vertices . MinBy ( t => t . Z ) ;
7471
7572 min = Math . Min ( minX . X , Math . Min ( minY . Y , minZ . Z ) ) ;
76- List < Vector3 > verticesList = vertices . ToList ( ) ;
77- List < Color > colorList = colors . ToList ( ) ;
7873 for ( int i = 0 ; i < vertices . Count ; i ++ )
7974 {
80- float max = Math . Max ( verticesList [ i ] . X , Math . Max ( verticesList [ i ] . Y , verticesList [ i ] . Z ) ) ;
75+ float max = Math . Max ( vertices [ i ] . X , Math . Max ( vertices [ i ] . Y , vertices [ i ] . Z ) ) ;
8176 if ( /*max - min < 8000 && */ max - min >= 0 )
8277 {
83- verticesList [ i ] -= new Vector3 ( min , min , min ) ;
84- _blocks . Add ( new Block ( ( ushort ) verticesList [ i ] . X , ( ushort ) verticesList [ i ] . Y , ( ushort ) verticesList [ i ] . Z , colorList [ i ] . ColorToUInt ( ) ) ) ;
78+ vertices [ i ] -= new Vector3 ( min , min , min ) ;
79+ _blocks . Add ( new Block ( ( ushort ) vertices [ i ] . X , ( ushort ) vertices [ i ] . Y , ( ushort ) vertices [ i ] . Z , colors [ i ] . ColorToUInt ( ) ) ) ;
8580 }
8681 }
8782 }
0 commit comments