pub fn build(
        &mut self,
        commands: &mut Commands,
        meshes: &mut ResMut<Assets<Mesh>>,
        material: Handle<ColorMaterial>,
        map_entity: Entity,
        populate_chunks: bool,
    ) {
        for x in 0..self.size.x {
            for y in 0..self.size.y {
                let mut chunk_entity = None;
                commands.entity(map_entity).with_children(|child_builder| {
                    chunk_entity = Some(child_builder.spawn().id());
                });
                let chunk_entity = chunk_entity.unwrap();

                let chunk_pos = MapVec2::new(x, y);
                let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
                mesh.set_attribute("Vertex_Position", VertexAttributeValues::Float3(vec![]));
                mesh.set_attribute("Vertex_Normal", VertexAttributeValues::Float3(vec![]));
                mesh.set_attribute("Vertex_Uv", VertexAttributeValues::Float2(vec![]));
                mesh.set_indices(Some(Indices::U32(vec![])));
                let mesh_handle =  meshes.add(mesh);
                let mut chunk = Chunk::new(map_entity, chunk_pos, self.chunk_size, self.tile_size, self.texture_size, mesh_handle.clone(), self.layer_id, dyn_clone::clone_box(&*self.mesher));

                if populate_chunks {
                    chunk.build_tiles(commands, chunk_entity);
                }

                self.chunks.insert(chunk_pos, (chunk_entity, chunk.tiles.clone()));

                commands.entity(chunk_entity)
                    .insert_bundle(ChunkBundle {
                        chunk,
                        mesh: mesh_handle,
                        material: material.clone(),
                        transform: Transform::default(),
                        ..Default::default()
                    });
            }
        }
    }
/// Builds the map's chunks and tiles if populate_chunks is true.
/// Note: This should always be called right after creating a map.
Builds the map's chunks and tiles if populate_chunks is true.
Note: This should always be called right after creating a map.
Builds the map ' s chunks and tiles if populate_chunks is true . Note : This should always be called right after creating a map .
pub fn build(
        &mut self,
        commands: &mut Commands,
        meshes: &mut ResMut<Assets<Mesh>>,
        material: Handle<ColorMaterial>,
        map_entity: Entity,
        populate_chunks: bool,
    ) {
        for x in 0..self.size.x {
            for y in 0..self.size.y {
                let mut chunk_entity = None;
                commands.entity(map_entity).with_children(|child_builder| {
                    chunk_entity = Some(child_builder.spawn().id());
                });
                let chunk_entity = chunk_entity.unwrap();
                let chunk_pos = MapVec2::new(x, y);
                let mut mesh = Mesh::new(PrimitiveTopology::TriangleList);
                mesh.set_attribute("Vertex_Position", VertexAttributeValues::Float3(vec![]));
                mesh.set_attribute("Vertex_Normal", VertexAttributeValues::Float3(vec![]));
                mesh.set_attribute("Vertex_Uv", VertexAttributeValues::Float2(vec![]));
                mesh.set_indices(Some(Indices::U32(vec![])));
                let mesh_handle =  meshes.add(mesh);
                let mut chunk = Chunk::new(map_entity, chunk_pos, self.chunk_size, self.tile_size, self.texture_size, mesh_handle.clone(), self.layer_id, dyn_clone::clone_box(&*self.mesher));
                if populate_chunks {
                    chunk.build_tiles(commands, chunk_entity);
                }
                self.chunks.insert(chunk_pos, (chunk_entity, chunk.tiles.clone()));
                commands.entity(chunk_entity)
                    .insert_bundle(ChunkBundle {
                        chunk,
                        mesh: mesh_handle,
                        material: material.clone(),
                        transform: Transform::default(),
                        ..Default::default()
                    });
            }
        }
    }
pub fn build ( & mut self , commands : & mut Commands , meshes : & mut ResMut < Assets < Mesh > > , material : Handle < ColorMaterial > , map_entity : Entity , populate_chunks : bool , ) { for x in 0 .. self . size . x { for y in 0 .. self . size . y { let mut chunk_entity = None ; commands . entity ( map_entity ) . with_children ( | child_builder | { chunk_entity = Some ( child_builder . spawn ( ) . id ( ) ) ; } ) ; let chunk_entity = chunk_entity . unwrap ( ) ; let chunk_pos = MapVec2 :: new ( x , y ) ; let mut mesh = Mesh :: new ( PrimitiveTopology :: TriangleList ) ; mesh . set_attribute ( " " , VertexAttributeValues :: Float3 ( vec ! [ ] ) ) ; mesh . set_attribute ( " " , VertexAttributeValues :: Float3 ( vec ! [ ] ) ) ; mesh . set_attribute ( " " , VertexAttributeValues :: Float2 ( vec ! [ ] ) ) ; mesh . set_indices ( Some ( Indices :: U32 ( vec ! [ ] ) ) ) ; let mesh_handle = meshes . add ( mesh ) ; let mut chunk = Chunk :: new ( map_entity , chunk_pos , self . chunk_size , self . tile_size , self . texture_size , mesh_handle . clone ( ) , self . layer_id , dyn_clone :: clone_box ( & * self . mesher ) ) ; if populate_chunks { chunk . build_tiles ( commands , chunk_entity ) ; } self . chunks . insert ( chunk_pos , ( chunk_entity , chunk . tiles . clone ( ) ) ) ; commands . entity ( chunk_entity ) . insert_bundle ( ChunkBundle { chunk , mesh : mesh_handle , material : material . clone ( ) , transform : Transform :: default ( ) , .. Default :: default ( ) } ) ; } } }
Builds the map's chunks and tiles if populate_chunks is true.
Builds the map ' s chunks and tiles if populate_chunks is true .
&mut self
commands
&mut Commands
meshes
&mut ResMut<Assets<Mesh>>
material
Handle<ColorMaterial>
map_entity
Entity
populate_chunks
bool
&mut self
commands
&mut Commands
meshes
&mut ResMut<Assets<Mesh>>
material
Handle<ColorMaterial>
map_entity
Entity
populate_chunks
bool