Skip to content
Open

Gui #227

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: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock

# Ignore Vim configuration files
*.swp
*.swo
*~

# Configuration file for editors using the RLS.
rls.toml
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exclude = ["doc/*", "bors.toml", ".travis.yml", "test_data/*"]
[features]
default = ["opengl", "audio"]
opengl = ["gfx_device_gl", "gfx_window_glutin", "glutin"]
nuklear = ["nuklear-rust", "nuklear-backend-gfx"]
audio = ["rodio"]

[build-dependencies]
Expand All @@ -30,6 +31,7 @@ derivative = "1.0"
froggy = "0.4.4"
genmesh = "0.6"
gfx = "0.17.1"
gfx_core = "^0.8"
gfx_glyph = "0.13"
gltf = { features = ["names", "utils", "import"], optional = true, version = "0.11.1" }
image = "0.20"
Expand All @@ -43,6 +45,10 @@ rodio = { version = "0.8", optional = true }
mint = "0.5"
vec_map = "0.8"

# Nuklear
nuklear-rust = {version = "0.6", features = ["rust_allocator"], optional = true}
nuklear-backend-gfx = {version = "0.8", optional = true}

# OpenGL
gfx_device_gl = { version = "0.15", optional = true }
gfx_window_glutin = { version = "0.28", optional = true }
Expand Down Expand Up @@ -105,3 +111,7 @@ required-features = ["gltf"]
[[example]]
name = "gltf-morph-targets"
required-features = ["gltf"]

[[example]]
name = "gui"
required-features = ["gltf", "nuklear"]
5 changes: 1 addition & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ extern crate includedir_codegen;
const SHADERS: &str = "data/shaders";

fn main() {
includedir_codegen::start("FILES")
.dir(SHADERS, includedir_codegen::Compression::Gzip)
.build("data.rs")
.unwrap();
includedir_codegen::start("FILES").dir(SHADERS, includedir_codegen::Compression::Gzip).build("data.rs").unwrap();
}
43 changes: 5 additions & 38 deletions examples/anim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,7 @@ const BIT_COLOR: u16 = 0x40;
const BIT_VERTEX_COLOR: u16 = 0x80;

fn make_vertices(slice: &[i16]) -> Vec<mint::Point3<f32>> {
slice
.chunks(3)
.map(|v| mint::Point3 {
x: v[0] as f32 * SCALE,
y: v[1] as f32 * SCALE,
z: v[2] as f32 * SCALE,
})
.collect()
slice.chunks(3).map(|v| mint::Point3 { x: v[0] as f32 * SCALE, y: v[1] as f32 * SCALE, z: v[2] as f32 * SCALE }).collect()
}

fn make_indices(meta: &[u16]) -> Vec<[u32; 3]> {
Expand Down Expand Up @@ -88,33 +81,11 @@ fn make_indices(meta: &[u16]) -> Vec<[u32; 3]> {
fn main() {
let mut win = three::Window::new("Three-rs mesh blending example");
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],
Some([0.0, 1.0, 0.0].into()),
);
cam.look_at([100.0, 0.0, 100.0], [0.0, 0.0, 30.0], Some([0.0, 1.0, 0.0].into()));

let geom = three::Geometry {
base: three::Shape {
vertices: make_vertices(VERTICES),
normals: Vec::new(),
..three::Shape::default()
},
faces: make_indices(INDICES),
shapes: V_FLY
.iter()
.map(|data| {
three::Shape {
vertices: make_vertices(data),
.. three::Shape::default()
}
})
.collect(),
..three::Geometry::default()
};
let geom = three::Geometry { base: three::Shape { vertices: make_vertices(VERTICES), normals: Vec::new(), ..three::Shape::default() }, faces: make_indices(INDICES), shapes: V_FLY.iter().map(|data| three::Shape { vertices: make_vertices(data), ..three::Shape::default() }).collect(), ..three::Geometry::default() };

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

let (mut id0, mut id1) = (0, 1);
Expand All @@ -129,11 +100,7 @@ fn main() {
if id0 == V_FLY.len() {
id0 = 0;
}
id1 = if id0 + 1 < V_FLY.len() {
id0 + 1
} else {
0
};
id1 = if id0 + 1 < V_FLY.len() { id0 + 1 } else { 0 };
timer.reset();
}
win.render(&cam);
Expand Down
9 changes: 2 additions & 7 deletions examples/aviator/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ fn main() {

let sea = {
let geo = three::Geometry::cylinder(600.0, 600.0, 800.0, 40);
let material = three::material::Lambert {
color: COLOR_BLUE,
flat: true,
};
let material = three::material::Lambert { color: COLOR_BLUE, flat: true };
win.factory.mesh(geo, material)
};
let sea_base_q = cgmath::Quaternion::from_angle_x(-cgmath::Rad::turn_div_4());
Expand All @@ -59,9 +56,7 @@ fn main() {
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_transform([0.0, 100.0, 0.0], [0.0, 0.0, 0.0, 1.0], 0.25);
win.scene.add(&airplane.group);

let timer = three::Timer::new();
Expand Down
62 changes: 8 additions & 54 deletions examples/aviator/plane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,76 +27,31 @@ impl AirPlane {
v.y += if v.y > 0.0 { -10.0 } else { 30.0 };
}
}
factory.mesh(
geo,
three::material::Lambert {
color: COLOR_RED,
flat: false,
},
)
factory.mesh(geo, three::material::Lambert { color: COLOR_RED, flat: false })
};
group.add(&cockpit);

let engine = factory.mesh(
three::Geometry::cuboid(20.0, 50.0, 50.0),
three::material::Lambert {
color: COLOR_WHITE,
flat: false,
},
);
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]);
group.add(&engine);

let tail = factory.mesh(
three::Geometry::cuboid(15.0, 20.0, 5.0),
three::material::Lambert {
color: COLOR_RED,
flat: false,
},
);
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]);
group.add(&tail);

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

let propeller_group = factory.group();
propeller_group.set_position([50.0, 0.0, 0.0]);
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,
},
);
let propeller = factory.mesh(three::Geometry::cuboid(20.0, 10.0, 10.0), three::material::Lambert { color: COLOR_BROWN, flat: false });
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,
},
);
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]);
propeller_group.add(&blade);

AirPlane {
group,
_cockpit: cockpit,
_engine: engine,
_tail: tail,
_wing: wing,
propeller_group,
_propeller: propeller,
_blade: blade,
}
AirPlane { group, _cockpit: cockpit, _engine: engine, _tail: tail, _wing: wing, propeller_group, _propeller: propeller, _blade: blade }
}

pub fn update(
Expand All @@ -106,7 +61,6 @@ impl AirPlane {
) {
let q = Quaternion::from_angle_x(Rad(0.3 * time));
self.propeller_group.set_orientation(q);
self.group
.set_position([0.0 + target.x * 100.0, 100.0 + target.y * 75.0, 0.0]);
self.group.set_position([0.0 + target.x * 100.0, 100.0 + target.y * 75.0, 0.0]);
}
}
22 changes: 3 additions & 19 deletions examples/aviator/sky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use three::{self, Object};

use COLOR_WHITE;


pub struct Sky {
pub group: three::Group,
}
Expand All @@ -19,24 +18,13 @@ impl Sky {
) -> 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 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 m = factory.mesh_instance(&template);
let rot = cgmath::Quaternion::<f32>::new(rng.gen(), rng.gen(), rng.gen(), rng.gen());
let q = rot.normalize();
m.set_transform(
[
i as f32 * 15.0,
rng.gen::<f32>() * 10.0,
rng.gen::<f32>() * 10.0,
],
q,
rng.gen_range(0.1, 1.0),
);
m.set_transform([i as f32 * 15.0, rng.gen::<f32>() * 10.0, rng.gen::<f32>() * 10.0], q, rng.gen_range(0.1, 1.0));
group.add(&m);
}
group
Expand All @@ -53,11 +41,7 @@ impl Sky {
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 = [
angle.cos() * dist,
angle.sin() * dist,
rng.gen_range(-800.0, -400.0),
];
let pos = [angle.cos() * dist, angle.sin() * dist, rng.gen_range(-800.0, -400.0)];
let q = cgmath::Quaternion::from_angle_z(angle + cgmath::Rad::turn_div_4());
cloud.set_transform(pos, q, rng.gen_range(1.0, 3.0));
group.add(&cloud);
Expand Down
5 changes: 1 addition & 4 deletions examples/gltf-morph-targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ fn main() {
// Create a camera with which to render the scene, and control it with the built-in
// orbit controller, set to orbit the model.
let camera = window.factory.perspective_camera(60.0, 0.1 .. 20.0);
let mut controls = three::controls::Orbit::builder(&camera)
.position([-3.0, 3.0, -3.0])
.up([0.0, 1.0, 0.0])
.build();
let mut controls = three::controls::Orbit::builder(&camera).position([-3.0, 3.0, -3.0]).up([0.0, 1.0, 0.0]).build();

// Run the main loop, updating the camera controller, animations, and rendering the scene
// every frame.
Expand Down
5 changes: 1 addition & 4 deletions examples/gltf-node-animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ fn main() {
// Create a camera with which to render the scene, and control it with the built-in
// orbit controller, set to orbit the model.
let camera = window.factory.perspective_camera(60.0, 0.1 .. 100.0);
let mut controls = three::controls::Orbit::builder(&camera)
.position([3.0, 3.0, 3.0])
.target([0.0, 1.0, 0.0])
.build();
let mut controls = three::controls::Orbit::builder(&camera).position([3.0, 3.0, 3.0]).target([0.0, 1.0, 0.0]).build();

// Run the main loop, updating the camera controller, animations, and rendering the scene
// every frame.
Expand Down
29 changes: 5 additions & 24 deletions examples/gltf-pbr-shader.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
extern crate three;

use three::{
camera::Camera,
Object,
};
use three::{camera::Camera, Object};

fn main() {
let mut win = three::Window::new("Three-rs glTF example");
Expand All @@ -26,10 +23,7 @@ fn main() {

// Attempt to find a camera in the instantiated template to use as the perspective for
// rendering.
let cam = win
.scene
.sync_guard()
.find_child_of_type::<Camera>(&instance);
let cam = win.scene.sync_guard().find_child_of_type::<Camera>(&instance);

// If we didn't find a camera in the glTF scene, create a default one to use.
let cam = cam.unwrap_or_else(|| {
Expand All @@ -39,29 +33,16 @@ fn main() {
});

// Create a skybox for the scene.
let skybox_path = three::CubeMapPath {
front: "test_data/skybox/posz.jpg",
back: "test_data/skybox/negz.jpg",
up: "test_data/skybox/posy.jpg",
down: "test_data/skybox/negy.jpg",
left: "test_data/skybox/negx.jpg",
right: "test_data/skybox/posx.jpg",
};
let skybox_path = three::CubeMapPath { front: "test_data/skybox/posz.jpg", back: "test_data/skybox/negz.jpg", up: "test_data/skybox/posy.jpg", down: "test_data/skybox/negy.jpg", left: "test_data/skybox/negx.jpg", right: "test_data/skybox/posx.jpg" };
let skybox = win.factory.load_cubemap(&skybox_path);
win.scene.background = three::Background::Skybox(skybox);

// Determine the current position of the camera so that we can use it to initialize the
// camera controller.
let init = win.scene
.sync_guard()
.resolve_world(&cam)
.transform;
let init = win.scene.sync_guard().resolve_world(&cam).transform;

// Create a first person camera controller, starting at the camera's current position.
let mut controls = three::controls::FirstPerson::builder(&cam)
.position(init.position)
.move_speed(4.0)
.build();
let mut controls = three::controls::FirstPerson::builder(&cam).position(init.position).move_speed(4.0).build();

// Run the main loop, updating the camera controller and rendering the scene every frame.
while win.update() && !win.input.hit(three::KEY_ESCAPE) {
Expand Down
Loading