Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gltf export #94

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ flate2 = "1.0.28"
image = "0.25.1"
weezl = "0.1.8"
regex = "1.10.5"
gltf = "1.4.1"
unicase = "2.7.0"
bytemuck = { version = "1.16.1", features = ["derive"] }

[dev-dependencies]
dirs = "5.0.1"
Expand Down
72 changes: 48 additions & 24 deletions examples/create_basic_vpx_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use vpin::vpx;
use vpin::vpx::color::Color;
use vpin::vpx::gameitem::bumper::Bumper;
use vpin::vpx::gameitem::flipper::Flipper;
use vpin::vpx::gameitem::plunger::Plunger;
use vpin::vpx::gameitem::vertex2d::Vertex2D;
use vpin::vpx::gameitem::GameItemEnum;
use vpin::vpx::material::Material;
use vpin::vpx::VPX;
Expand All @@ -11,45 +13,67 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut vpx = VPX::default();

// playfield material
let mut material = Material::default();
material.name = "Playfield".to_string();
// material defaults to purple
material.base_color = Color::from_rgb(0x966F33); // Wood
let material = Material {
name: "Playfield".to_string(),
// material defaults to purple
base_color: Color::from_rgb(0x966F33), // Wood
..Default::default()
};
vpx.gamedata.materials = Some(vec![material]);

// black background (default is bluish gray)
vpx.gamedata.backdrop_color = Color::from_rgb(0x060606); // Dark Gray
vpx.gamedata.playfield_material = "Playfield".to_string();

// add a plunger
let mut plunger = vpx::gameitem::plunger::Plunger::default();
plunger.name = "Plunger".to_string();
plunger.center.x = 898.027;
plunger.center.y = 2105.312;
let plunger = Plunger {
name: "Plunger".to_string(),
center: Vertex2D {
x: 898.027,
y: 2105.312,
},
..Default::default()
};

vpx.add_game_item(GameItemEnum::Plunger(plunger));

// add a bumper in the center of the playfield
let mut bumper = Bumper::default();
bumper.name = "Bumper1".to_string();
bumper.center.x = (vpx.gamedata.left + vpx.gamedata.right) / 2.;
bumper.center.y = (vpx.gamedata.top + vpx.gamedata.bottom) / 2.;
let bumper = Bumper {
name: "Bumper1".to_string(),
center: Vertex2D {
x: (vpx.gamedata.left + vpx.gamedata.right) / 2.,
y: (vpx.gamedata.top + vpx.gamedata.bottom) / 2.,
},
..Default::default()
};

vpx.add_game_item(GameItemEnum::Bumper(bumper));

// add 2 flippers
let mut flipper_left = Flipper::default();
flipper_left.name = "LeftFlipper".to_string();
flipper_left.center.x = 278.2138;
flipper_left.center.y = 1803.271;
flipper_left.start_angle = 120.5;
flipper_left.end_angle = 70.;
let flipper_left = Flipper {
name: "LeftFlipper".to_string(),
center: Vertex2D {
x: 278.2138,
y: 1803.271,
},
start_angle: 120.5,
end_angle: 70.,
..Default::default()
};

vpx.add_game_item(GameItemEnum::Flipper(flipper_left));

let mut flipper_right = Flipper::default();
flipper_right.name = "RightFlipper".to_string();
flipper_right.center.x = 595.869;
flipper_right.center.y = 1803.271;
flipper_right.start_angle = -120.5;
flipper_right.end_angle = -70.;
let flipper_right = Flipper {
name: "RightFlipper".to_string(),
center: Vertex2D {
x: 595.869,
y: 1803.271,
},
start_angle: -120.5,
end_angle: -70.,
..Default::default()
};

vpx.add_game_item(GameItemEnum::Flipper(flipper_right));

// add a script
Expand Down
6 changes: 3 additions & 3 deletions src/vpx/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pub struct Color {
/// And since we want to round-trip the data, we need to store it in the json format as well.
/// Seems to contain 255 or 128 in the wild.
unused: u8,
r: u8,
g: u8,
b: u8,
pub r: u8,
pub g: u8,
pub b: u8,
}

impl Color {
Expand Down
Loading
Loading