Skip to content

Commit

Permalink
Merge pull request #406 from StarArawn/fix-3d-iso
Browse files Browse the repository at this point in the history
Fixed 3d iso example..
  • Loading branch information
StarArawn authored Mar 26, 2023
2 parents 37cfe06 + 7d4ee4a commit 05ec72e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 21 deletions.
28 changes: 14 additions & 14 deletions assets/iso_map.tmx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.4" tiledversion="1.4.3" orientation="isometric" renderorder="right-down" width="12" height="12" tilewidth="64" tileheight="32" infinite="0" nextlayerid="6" nextobjectid="1">
<tileset firstgid="1" name="isometric-sheet" tilewidth="64" tileheight="64" tilecount="9" columns="6">
<map version="1.9" tiledversion="1.9.2" orientation="isometric" renderorder="right-down" width="12" height="12" tilewidth="64" tileheight="32" infinite="0" nextlayerid="6" nextobjectid="1">
<tileset firstgid="1" name="isometric-sheet" tilewidth="64" tileheight="64" tilecount="6" columns="6">
<image source="isometric-sheet.png" trans="ff00ff" width="384" height="64"/>
</tileset>
<layer id="1" name="0" width="12" height="12">
Expand All @@ -24,12 +24,12 @@
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,5,5,5,5,5,5,0,0,0,
0,0,0,5,0,0,0,0,0,0,0,0,
0,0,0,5,0,0,0,0,0,0,0,0,
0,0,0,5,0,0,0,0,0,0,0,0,
0,0,0,5,0,0,0,0,0,0,0,0,
0,0,0,5,0,0,0,0,0,0,0,0,
0,0,0,6,6,6,6,6,6,0,0,0,
0,0,0,6,0,0,0,0,0,0,0,0,
0,0,0,6,0,0,0,0,0,0,0,0,
0,0,0,6,0,0,0,0,0,0,0,0,
0,0,0,6,0,0,0,0,0,0,0,0,
0,0,0,6,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
Expand All @@ -39,12 +39,12 @@
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,5,5,5,5,5,5,0,0,0,0,
0,0,5,5,5,5,5,5,0,0,0,0,
0,0,5,5,5,5,5,5,0,0,0,0,
0,0,5,5,5,5,5,5,0,0,0,0,
0,0,5,5,5,5,5,0,0,0,0,0,
0,0,5,5,5,5,0,0,0,0,0,0,
0,0,6,6,6,6,6,6,0,0,0,0,
0,0,6,6,6,6,6,6,0,0,0,0,
0,0,6,6,6,6,6,6,0,0,0,0,
0,0,6,6,6,6,6,6,0,0,0,0,
0,0,6,6,6,6,6,0,0,0,0,0,
0,0,6,6,6,6,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
Expand Down
44 changes: 44 additions & 0 deletions examples/3d_iso.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use bevy::prelude::*;
use bevy_ecs_tilemap::prelude::*;

mod helpers;

fn startup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());

let map_handle: Handle<helpers::tiled::TiledMap> = asset_server.load("iso_map.tmx");

commands.spawn(helpers::tiled::TiledMapBundle {
tiled_map: map_handle,
..Default::default()
});
}

fn main() {
App::new()
.insert_resource(TilemapRenderSettings {
// Map size is 12x12 so we'll have render chunks that are:
// 12 tiles wide and 1 tile tall.
render_chunk_size: UVec2::new(3, 1),
})
.add_plugins(
DefaultPlugins
.set(WindowPlugin {
primary_window: Some(Window {
title: String::from("3D Isometric Example"),
..Default::default()
}),
..default()
})
.set(ImagePlugin::default_nearest())
.set(AssetPlugin {
watch_for_changes: true,
..default()
}),
)
.add_plugin(TilemapPlugin)
.add_plugin(helpers::tiled::TiledMapPlugin)
.add_startup_system(startup)
.add_system(helpers::camera::movement)
.run();
}
6 changes: 2 additions & 4 deletions examples/helpers/tiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,8 @@ pub fn process_loaded_maps(

for x in 0..map_size.x {
for y in 0..map_size.y {
let mut mapped_y = y;
if tiled_map.map.orientation == tiled::Orientation::Orthogonal {
mapped_y = (tiled_map.map.height - 1) - y;
}
// Transform TMX coords into bevy coords.
let mapped_y = tiled_map.map.height - 1 - y;

let mapped_x = x as i32;
let mapped_y = mapped_y as i32;
Expand Down
4 changes: 2 additions & 2 deletions src/render/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ pub struct RenderChunk2d {
/// [`TilemapType`] of the map this chunk belongs to.
map_type: TilemapType,
/// The grid size of the map this chunk belongs to.
grid_size: TilemapGridSize,
pub grid_size: TilemapGridSize,
/// The tile size of the map this chunk belongs to.
tile_size: TilemapTileSize,
pub tile_size: TilemapTileSize,
/// The [`Aabb`] of this chunk, based on the map type, grid size, and tile size. It is not
/// transformed by the `global_transform` or [`local_transform`]
aabb: Aabb,
Expand Down
6 changes: 5 additions & 1 deletion src/render/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,15 @@ pub fn queue_meshes(
};

let pipeline_id = pipelines.specialize(&pipeline_cache, &tilemap_pipeline, key);
let z = transform.translation.z
+ (1.0
- (transform.translation.y
/ (chunk.map_size.y as f32 * chunk.tile_size.y)));
transparent_phase.add(Transparent2d {
entity,
draw_function: draw_tilemap,
pipeline: pipeline_id,
sort_key: FloatOrd(transform.translation.z),
sort_key: FloatOrd(z),
batch_range: None,
});
}
Expand Down

0 comments on commit 05ec72e

Please sign in to comment.