Skip to content

Commit

Permalink
use brickadia instead of brs, add glow feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Meshiest committed Oct 15, 2021
1 parent 7fb851c commit 0793208
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 379 deletions.
473 changes: 269 additions & 204 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "heightmap"
version = "0.4.2"
version = "0.5.0"
authors = ["Meshiest <[email protected]>"]
edition = "2018"
resolver = "2"

[dependencies]
brs = "0.2.0"
brickadia = "0.1.24"
image = "0.23.4"
clap = "2.33.0"
byteorder = "1.3.4"
uuid = "0.8.2"

[dev-dependencies]
nfd = "0.0.4"
Expand Down
13 changes: 10 additions & 3 deletions examples/gui.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![allow(dead_code, unused_variables)]

use brickadia::write::{self, SaveWriter};

use {
brs::write_save,
heightmap::{map::*, quad::*, util::*},
std::{boxed::Box, cell::RefCell, fs::File, path::Path, rc::Rc},
};
Expand Down Expand Up @@ -29,6 +30,7 @@ pub struct HeightmapApp {
opt_lrgb: bool,
opt_hdmap: bool,
opt_snap: bool,
opt_glow: bool,
mode: BrickMode,
}

Expand All @@ -46,6 +48,7 @@ impl HeightmapApp {
stud: self.mode == BrickMode::Stud,
snap: self.opt_snap,
img: self.heightmaps.borrow().len() == 0 && self.colormap.borrow().is_some(),
glow: self.opt_glow,
hdmap: self.opt_hdmap,
lrgb: self.opt_lrgb,
nocollide: self.opt_nocollide,
Expand Down Expand Up @@ -113,8 +116,9 @@ impl HeightmapApp {

println!("Writing Save to {}", self.out_file);
let data = bricks_to_save(bricks, self.owner_id.clone(), self.owner_name.clone());
let mut write_dest = File::create(self.out_file.clone()).unwrap();
write_save(&mut write_dest, &data).expect("Could not save file");
SaveWriter::new(File::create(self.out_file.clone()).unwrap(), data)
.write()
.expect("Failed to write file!");
println!("Done!");
}
}
Expand All @@ -134,6 +138,7 @@ impl Default for HeightmapApp {
opt_nocollide: false,
opt_lrgb: false,
opt_snap: false,
opt_glow: false,
opt_hdmap: false,
mode: BrickMode::Default,
}
Expand Down Expand Up @@ -206,6 +211,8 @@ impl epi::App for HeightmapApp {
.on_hover_text("Use linear rgb input color instead of sRGB");
ui.checkbox(&mut self.opt_hdmap, "HD Map")
.on_hover_text("Using a high detail rgb color encoded heightmap");
ui.checkbox(&mut self.opt_glow, "Glow")
.on_hover_text("Glow bricks at lowest intensity");
});
ui.end_row();

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pub mod map;
pub mod old;
pub mod quad;
pub mod util;
pub use brs;
23 changes: 8 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
pub mod map;
pub mod old;
pub mod quad;
pub mod util;

use crate::map::*;
use crate::old::gen_heightmap;
use crate::quad::*;
use crate::util::*;
use brs::*;
use brickadia::write::SaveWriter;
use clap::clap_app;
use std::boxed::Box;
use std::fs::File;

fn main() {
let matches = clap_app!(heightmap =>
(version: "0.4.0")
(version: "0.5.0")
(author: "github.com/Meshiest")
(about: "Converts heightmap png files to Brickadia save files")
(@arg INPUT: +required +multiple "Input heightmap PNG images")
Expand All @@ -29,7 +27,7 @@ fn main() {
(@arg snap: --snap "Snap bricks to the brick grid")
(@arg lrgb: --lrgb "Use linear rgb input color instead of sRGB")
(@arg img: -i --img "Make the heightmap flat and render an image")
(@arg old: --old "Use old unoptimized heightmap code")
(@arg glow: --glow "Make the heightmap glow at 0 intensity")
(@arg hdmap: --hdmap "Using a high detail rgb color encoded heightmap")
(@arg nocollide: --nocollide "Disable brick collision")
(@arg owner_id: --owner_id +takes_value "Set the owner id (default a1b16aca-9627-4a16-a160-67fa9adbb7b6)")
Expand All @@ -55,9 +53,6 @@ fn main() {
.to_string();
let owner_name = matches.value_of("owner").unwrap_or("Generator").to_string();

// determine generator mode
let old_mode = matches.is_present("old");

// output options
let mut options = GenOptions {
size: matches
Expand All @@ -78,6 +73,7 @@ fn main() {
stud: matches.is_present("stud"),
snap: matches.is_present("snap"),
img: matches.is_present("img"),
glow: matches.is_present("glow"),
hdmap: matches.is_present("hdmap"),
lrgb: matches.is_present("lrgb"),
nocollide: matches.is_present("nocollide"),
Expand Down Expand Up @@ -128,15 +124,12 @@ fn main() {
return println!("Unsupported heightmap format");
};

let bricks = if old_mode {
gen_heightmap(&*heightmap, &colormap, options)
} else {
gen_opt_heightmap(&*heightmap, &colormap, options)
};
let bricks = gen_opt_heightmap(&*heightmap, &colormap, options);

println!("Writing Save to {}", out_file);
let data = bricks_to_save(bricks, owner_id, owner_name);
let mut write_dest = File::create(out_file).unwrap();
write_save(&mut write_dest, &data).expect("Could not save file");
SaveWriter::new(File::create(out_file).unwrap(), data)
.write()
.expect("Failed to write file!");
println!("Done!");
}
88 changes: 0 additions & 88 deletions src/old.rs

This file was deleted.

37 changes: 23 additions & 14 deletions src/quad.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
extern crate brs;
extern crate image;

use crate::map::*;
use crate::util::*;
use brs::*;

use brickadia::save::Brick;
use brickadia::save::BrickColor;
use brickadia::save::Collision;
use brickadia::save::Color;
use brickadia::save::Size;
use std::cell::RefCell;
use std::cmp::{max, min};
use std::collections::HashSet;
Expand Down Expand Up @@ -286,9 +288,9 @@ impl QuadTree {
min(max(desired_height, if options.stud { 5 } else { 2 }), 250) as u32;
let height = height + height % (if options.stud { 5 } else { 2 });

bricks.push(brs::Brick {
bricks.push(Brick {
asset_name_index: options.asset,
size: (
size: Size::Procedural(
t.size.0 * options.size,
t.size.1 * options.size,
// if it's a microbrick image, just use the block size so it's cubes
Expand All @@ -303,15 +305,22 @@ impl QuadTree {
((t.center.1 * 2 + t.size.1) * options.size) as i32,
z as i32 - height as i32 + 2,
),
direction: Direction::ZPositive,
rotation: Rotation::Deg0,
collision: !options.nocollide,
visibility: true,
material_index: 0,
color: ColorMode::Custom(Color::from_rgba(
t.color[0], t.color[1], t.color[2], t.color[3],
)),
owner_index: Some(0),
collision: Collision {
player: !options.nocollide,
weapon: !options.nocollide,
interaction: !options.nocollide,
tool: true,
},
color: BrickColor::Unique(Color {
r: t.color[0],
g: t.color[1],
b: t.color[2],
a: t.color[3],
}),
owner_index: 1,
material_intensity: 0,
material_index: if options.glow { 1 } else { 0 },
..Default::default()
});

// update Z and remaining height
Expand Down
Loading

0 comments on commit 0793208

Please sign in to comment.