Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
NotificationsYou must be signed in to change notification settings

Calcoph/TeProcedural

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Procedurally generate and visualize tile maps given a set of tiles and a set of rules.

preview of the 3D viewer

Running the example

To change the size of the map, modify/resources/size.txt.

Run withcargo run --example example for simple run andcargo run --example example --features view3d for the 3d viewer

Adding as dependency

Since this crate is not in crates.io, you'll have to add it to your Cargo.toml using a git path.

[dependencies]procedural = {git ="https://github.com/Calcoph/TeProcedural.git" }

Tutorial

  1. Create an enum that will represent your tiles.

    enumMyTile{Grass,Sand,Water}
  2. Implement theprocedural::Tile trait for your enum. See theexample.

    implTileforExampleTile{    ...}
  3. Make sure that rules are bidirectional.

    Enable the feature "validate" and run your code to see which rules are not. Validation will happen in Board::new(). It is recommended to disable this feature when you make no changes to your Tile/Direction, since the results won't change and the performance of the validation is O(n²*m) where n is the amount of tiles and m the amount of directions.

    The code below is wrong:

    fnget_rules(&self) ->Box<dynFn(&MyTile,Direction) ->bool +'_>{matchself{MyTile::Grass =>Box::new(|tile:&MyTile,_direction:Direction|match tile{            _ =>true// According to grass, it can be placed next to water}),MyTile::Sand =>Box::new(|tile:&MyTile,_direction:Direction|match tile{MyTile::Grass =>false,            _ =>true}),MyTile::Water =>Box::new(|tile:&MyTile,_direction:Direction|match tile{MyTile::Grass =>false,// According to water, grass can't be next to water.// Therefore the Grass <-> Water relationship is not bidirectionalMyTile::Sand =>true,MyTile::Water =>true,})}}
  4. Generate a board

    use procedural::Board;letmut board =Board<MyTile>;board.generate();// If you have also implemented Display for MyTile you can also do this:println!("{}", board);

Adding 3d models to your tiles

Models must have a 1.0x1.0 square footprint in order for them to be displayed properly.

  1. Enable the "view3d" feature in your Cargo.tomlprocedural = { git = ..., features = ["view3d"] }
  2. Two new methods of theTile trait will have to be implemented:get_name() andget_model(). If get_model() returns None, the tile will simply be ignored when rendering.

The model is formed by 3 parts. The texture, the vertices and the indices.

Each tile (that has a model)must have a distinct name (unless 2 tiles share the same model), this name is also used to get the texture for the model. So if a tile's name is"house", its texture will be atresources/tiles/house.png.

Vertices have 2 parts: the 3D position and the coords of the texture (from 0.0 to 1.0) at that point.

Indices represent which vertices form a triangle.

See/examples/models/mod.rs for manually made vertices and indices.

If your models are more complex than a single texture with a single mesh, you can leaveget_model() andget_name() unimplemented and make your ownload_models() instead of usingBoard::load_models().

Troubleshooting

  • Something doesn't work/works wrongly

Make sure that after adding a new tile to the enum, it's added to theVec returned byTile::all().

  • generate() is in an infinite loop/too slow

If even small boards are slow/infinite to generate, check that no rules confilct and they are bidirectional, seestep 3 of the tutorial

  • 3D model doesn't render correctly

Tengine doesn't have lighting at all. It also culls triangles that are facing away from the camera. So if some (or all) triangles of the model are invisible, change the order of the indices.

  • te_player::prepare() returns ErrorMake sure you have an icon and InitialConfiguration.icon_path points to it. InitialConfiguration.font_dir_path must also be a valid path. See theexample.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp