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

Node tree rewrite #155

Merged
merged 8 commits into from
Jan 4, 2018
Merged
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
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ exclude = ["doc", "bors.toml", ".travis.yml", "test_data"]

[lib]

[profile.release]
debug = true

[features]
default = ["opengl"]
"opengl" = ["gfx_device_gl", "gfx_window_glutin", "glutin"]
Expand All @@ -28,7 +31,7 @@ cgmath = { version = "0.15", features = ["mint"] }
derivative = "1.0"
froggy = "0.4.4"
genmesh = "0.5"
gfx = "0.16"
gfx = "0.16.3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because your instancing changes require it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of strict version rules in Cargo. It will use the latest available version anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your position is in the minority within the community then. Latest will be used on fresh checkout, if we don't check in Cargo.lock. But people who already have Cargo.lock will get breakage if you don't write the exact version in the Cargo.toml. Another case is - some crate that depends on you may say gfx = "=0.16.2" and it will try to build but will fail even after cargo update.

TL;DR: Cargo versioning rules are here to stay and be respected

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there is a proposal (which I supported) about making cargo publish checking out all the minimal compatible versions (as opposed to latest). Think about it ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, you convicted me

gfx_glyph = "0.7"
gltf = { features = ["names"], version = "0.9.2" }
gltf-importer = { features = ["names"], version = "0.9.2" }
Expand Down
6 changes: 3 additions & 3 deletions examples/anim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn make_geometry() -> three::Geometry {

fn main() {
let mut win = three::Window::new("Three-rs mesh blending example");
let mut cam = win.factory.perspective_camera(60.0, 1.0 .. 1000.0);
let cam = win.factory.perspective_camera(60.0, 1.0 .. 1000.0);
cam.look_at(
[100.0, 0.0, 100.0],
[0.0, 0.0, 30.0],
Expand All @@ -119,9 +119,9 @@ fn main() {
);
}

let mut mesh = win.factory
let mesh = win.factory
.mesh_dynamic(geom, three::material::Wireframe { color: 0xFFFFFF });
mesh.set_parent(&win.scene);
win.scene.add(&mesh);

let mut shape = 0;
let (mut name0, mut name1) = ("fly00".to_string(), "fly01".to_string());
Expand Down
24 changes: 12 additions & 12 deletions examples/aviator/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ fn main() {
let mut win = three::Window::new("Three-rs Aviator demo");
win.scene.background = three::Background::Color(COLOR_BACKGROUND);

let mut cam = win.factory.perspective_camera(60.0, 1.0 .. 1000.0);
let cam = win.factory.perspective_camera(60.0, 1.0 .. 1000.0);
cam.set_position([0.0, 100.0, 200.0]);
cam.set_parent(&win.scene);
win.scene.add(&cam);

//TODO: win.scene.fog = Some(three::Fog::new(...));
//TODO: Phong materials

let mut hemi_light = win.factory.hemisphere_light(0xaaaaaa, 0x000000, 0.9);
hemi_light.set_parent(&win.scene);
let hemi_light = win.factory.hemisphere_light(0xaaaaaa, 0x000000, 0.9);
win.scene.add(&hemi_light);
let mut dir_light = win.factory.directional_light(0xffffff, 0.9);
dir_light.look_at([150.0, 350.0, 350.0], [0.0, 0.0, 0.0], None);
let shadow_map = win.factory.shadow_map(2048, 2048);
dir_light.set_shadow(shadow_map, 400.0, 1.0 .. 1000.0);
dir_light.set_parent(&win.scene);
let mut ambient_light = win.factory.ambient_light(0xdc8874, 0.5);
ambient_light.set_parent(&win.scene);
win.scene.add(&dir_light);
let ambient_light = win.factory.ambient_light(0xdc8874, 0.5);
win.scene.add(&ambient_light);

let mut sea = {
let sea = {
let geo = three::Geometry::cylinder(600.0, 600.0, 800.0, 40);
let material = three::material::Lambert {
color: COLOR_BLUE,
Expand All @@ -52,17 +52,17 @@ fn main() {
};
let sea_base_q = cgmath::Quaternion::from_angle_x(-cgmath::Rad::turn_div_4());
sea.set_transform([0.0, -600.0, 0.0], sea_base_q, 1.0);
sea.set_parent(&win.scene);
win.scene.add(&sea);

let mut sky = sky::Sky::new(&mut rng, &mut win.factory);
let sky = sky::Sky::new(&mut rng, &mut win.factory);
sky.group.set_position([0.0, -600.0, 0.0]);
sky.group.set_parent(&win.scene);
win.scene.add(&sky.group);

let mut airplane = plane::AirPlane::new(&mut win.factory);
airplane
.group
.set_transform([0.0, 100.0, 0.0], [0.0, 0.0, 0.0, 1.0], 0.25);
airplane.group.set_parent(&win.scene);
win.scene.add(&airplane.group);

let timer = win.input.time();
while win.update() && !win.input.hit(three::KEY_ESCAPE) {
Expand Down
28 changes: 14 additions & 14 deletions examples/aviator/plane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl AirPlane {
pub fn new(factory: &mut three::Factory) -> Self {
let group = factory.group();

let mut cockpit = {
let cockpit = {
let mut geo = three::Geometry::cuboid(80.0, 50.0, 50.0);
for v in geo.base_shape.vertices.iter_mut() {
if v.x < 0.0 {
Expand All @@ -35,57 +35,57 @@ impl AirPlane {
},
)
};
cockpit.set_parent(&group);
group.add(&cockpit);

let mut engine = factory.mesh(
let engine = factory.mesh(
three::Geometry::cuboid(20.0, 50.0, 50.0),
three::material::Lambert {
color: COLOR_WHITE,
flat: false,
},
);
engine.set_position([40.0, 0.0, 0.0]);
engine.set_parent(&group);
group.add(&engine);

let mut tail = factory.mesh(
let tail = factory.mesh(
three::Geometry::cuboid(15.0, 20.0, 5.0),
three::material::Lambert {
color: COLOR_RED,
flat: false,
},
);
tail.set_position([-35.0, 25.0, 0.0]);
tail.set_parent(&group);
group.add(&tail);

let mut wing = factory.mesh(
let wing = factory.mesh(
three::Geometry::cuboid(40.0, 8.0, 150.0),
three::material::Lambert {
color: COLOR_RED,
flat: false,
},
);
wing.set_parent(&group);
group.add(&wing);

let mut propeller_group = factory.group();
let propeller_group = factory.group();
propeller_group.set_position([50.0, 0.0, 0.0]);
propeller_group.set_parent(&group);
let mut propeller = factory.mesh(
group.add(&propeller_group);
let propeller = factory.mesh(
three::Geometry::cuboid(20.0, 10.0, 10.0),
three::material::Lambert {
color: COLOR_BROWN,
flat: false,
},
);
propeller.set_parent(&propeller_group);
let mut blade = factory.mesh(
propeller_group.add(&propeller);
let blade = factory.mesh(
three::Geometry::cuboid(1.0, 100.0, 20.0),
three::material::Lambert {
color: COLOR_BROWN_DARK,
flat: false,
},
);
blade.set_position([8.0, 0.0, 0.0]);
blade.set_parent(&propeller_group);
propeller_group.add(&blade);

AirPlane {
group,
Expand Down
45 changes: 15 additions & 30 deletions examples/aviator/sky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@ use three::{self, Object};

use COLOR_WHITE;

struct Cloud {
group: three::Group,
meshes: Vec<three::Mesh>,

pub struct Sky {
pub group: three::Group,
}

impl Cloud {
fn new<R: Rng>(
impl Sky {
fn make_cloud<R: Rng>(
rng: &mut R,
factory: &mut three::Factory,
) -> Self {
let mut cloud = Cloud {
group: factory.group(),
meshes: Vec::new(),
};
) -> three::Group {
let group = factory.group();
let geo = three::Geometry::cuboid(20.0, 20.0, 20.0);
let material = three::material::Lambert {
color: COLOR_WHITE,
flat: true,
};
let template = factory.mesh(geo, material.clone());
for i in 0i32 .. rng.gen_range(3, 6) {
let mut m = factory.mesh_instance(&template);
let m = factory.mesh_instance(&template);
let rot: cgmath::Quaternion<f32> = rng.gen();
let q = rot.normalize();
m.set_transform(
Expand All @@ -40,31 +37,20 @@ impl Cloud {
q,
rng.gen_range(0.1, 1.0),
);
m.set_parent(&cloud.group);
cloud.meshes.push(m);
group.add(&m);
}
cloud
group
}
}

pub struct Sky {
pub group: three::Group,
clouds: Vec<Cloud>,
}

impl Sky {
pub fn new<R: Rng>(
rng: &mut R,
factory: &mut three::Factory,
) -> Self {
let mut sky = Sky {
group: factory.group(),
clouds: Vec::new(),
};
let group = factory.group();
let num = 20i32;
let step_angle = PI * 2.0 / num as f32;
for i in 0 .. num {
let mut c = Cloud::new(rng, factory);
let cloud = Self::make_cloud(rng, factory);
let angle = cgmath::Rad(i as f32 * step_angle);
let dist = rng.gen_range(750.0, 950.0);
let pos = [
Expand All @@ -73,10 +59,9 @@ impl Sky {
rng.gen_range(-800.0, -400.0),
];
let q = cgmath::Quaternion::from_angle_z(angle + cgmath::Rad::turn_div_4());
c.group.set_transform(pos, q, rng.gen_range(1.0, 3.0));
c.group.set_parent(&sky.group);
sky.clouds.push(c);
cloud.set_transform(pos, q, rng.gen_range(1.0, 3.0));
group.add(&cloud);
}
sky
Sky { group }
}
}
10 changes: 5 additions & 5 deletions examples/gltf-animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ use three::Object;

fn main() {
let mut window = three::Window::new("Three-rs glTF animation example");
let mut light = window.factory.directional_light(0xFFFFFF, 0.4);
let light = window.factory.directional_light(0xFFFFFF, 0.4);
light.look_at([1.0, 1.0, 1.0], [0.0, 0.0, 0.0], None);
light.set_parent(&window.scene);
window.scene.add(&light);
window.scene.background = three::Background::Color(0xC6F0FF);

let default = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/BoxAnimated.gltf");
let path = std::env::args().nth(1).unwrap_or(default.into());
let mut gltf = window.factory.load_gltf(&path);
gltf.group.set_parent(&window.scene);
let gltf = window.factory.load_gltf(&path);
window.scene.add(&gltf.group);

let mut mixer = three::animation::Mixer::new();
for clip in gltf.clips {
mixer.action(clip);
}

let mut camera = window.factory.perspective_camera(60.0, 0.1 .. 10.0);
let camera = window.factory.perspective_camera(60.0, 0.1 .. 10.0);
camera.set_position([0.0, 1.0, 5.0]);
while window.update() && !window.input.hit(three::KEY_ESCAPE) {
mixer.update(window.input.delta_time());
Expand Down
17 changes: 10 additions & 7 deletions examples/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ use three::Object;

fn main() {
let mut win = three::Window::new("Three-rs glTF example");
let mut light = win.factory.directional_light(0xFFFFFF, 7.0);
let light = win.factory.directional_light(0xFFFFFF, 7.0);
light.look_at([1.0, 1.0, 1.0], [0.0, 0.0, 0.0], None);
light.set_parent(&win.scene);
win.scene.add(&light);
win.scene.background = three::Background::Color(0xC6F0FF);

let default = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/Lantern.gltf");
let path = std::env::args().nth(1).unwrap_or(default.into());
let mut gltf = win.factory.load_gltf(&path);
gltf.group.set_parent(&win.scene);
win.scene.add(&gltf.group);

let mut cam = if gltf.cameras.len() > 0 {
let cam = if gltf.cameras.len() > 0 {
gltf.cameras.swap_remove(0)
} else {
let mut default = win.factory.perspective_camera(60.0, 0.001 .. 100.0);
default.set_parent(&win.scene);
let default = win.factory.perspective_camera(60.0, 0.001 .. 100.0);
win.scene.add(&default);
default
};

Expand All @@ -36,7 +36,10 @@ fn main() {
win.scene.background = three::Background::Skybox(skybox);
}

let init = cam.sync(&win.scene).world_transform;
let init = win.scene
.sync_guard()
.resolve_world(&cam)
.transform;
let mut controls = three::controls::FirstPerson::builder(&cam)
.position(init.position)
.move_speed(4.0)
Expand Down
Loading