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

Add object trait #148

Merged
merged 1 commit into from Dec 6, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -1,6 +1,8 @@
extern crate mint;
extern crate three;

use three::Object;

const SCALE: f32 = 1.0 / 10.0;
#[cfg_attr(rustfmt, rustfmt_skip)]
const VERTICES: &[i16] = &[0,101,79,0,55,189,0,-80,-186,0,88,-85,-110,-66,-79,1,-50,328,-25,-14,426,-95,-81,54,5,2,914,-64,-117,28,2,27,542,0,-102,-122,-70,-70,-148,-110,72,62,-27,-45,290,0,-133,29,-23,93,828,2,-24,551,5,104,825,6,10,1004,3,53,713,-82,27,-197,-82,-116,-132,6,-13,953,6,97,899,0,30,231,-129,-16,-100,-20,15,719,-55,-18,196,-18,-16,974,0,57,-181,5,-90,979,-18,13,423,0,107,-17,4,18,819,-93,60,133,-66,-53,-156,1,19,417,0,-26,-266,-24,43,911,-32,6,285,-31,-38,-259,-26,40,832,-57,17,195,-24,-10,553,-64,-116,-150,1,-36,425,-20,77,909,-40,57,-160,-36,-7,303,-25,39,715,-137,-33,-51,6,48,974,4,70,765,-115,18,85,-30,-20,354,-34,-73,-187,1,-38,362,-24,12,550,-63,82,-99,-30,-68,-252,-119,59,92,5,-4,882,-69,-84,-152,-40,-69,-290,0,-67,-283,-85,97,-25,-16,13,986,0,20,272,-65,-85,-345,0,-72,247,0,-56,-364,-56,-102,-159,-89,-97,-138,-80,-169,-348,-69,-168,-348,-63,-158,-351,-74,-152,-353,-85,-158,-351,-91,-277,-688,-63,-278,-688,-95,-241,-698,-58,-243,-700,-57,-175,-407,-74,-155,-413,-65,-188,-464,-75,-182,-465,-100,-174,-407,-86,-196,-461,-92,-197,-401,-81,-203,-460,-66,-196,-401,-70,-202,-460,-67,-253,-676,-75,-248,-677,-83,-254,-676,-81,-262,-673,-71,-261,-673,-28,38,191,-38,-66,-292,-130,-398,200,-212,-350,-59,-169,-48,-22,-255,-355,-108,-102,-393,204,-101,-5,100,-189,-394,68,-203,-239,35,-158,-169,160,-130,-166,170,-120,-171,143,-216,-221,-147,-250,-357,-78,-231,-206,-151,-212,-198,-182,-105,-396,217,-219,-469,-64,-215,-472,-78,-64,-641,224,-193,-541,-19,-36,-636,228,-40,-638,241,-158,-387,60,-161,-534,-29,-48,-635,196,-73,-640,205,-100,-603,161,-75,-597,151,-119,-628,105,-92,-622,92,-146,-584,67,-119,-577,51,-162,-587,26,-132,-581,14,-60,-765,131,-101,-721,56,-135,-669,5,-163,-615,-33,-24,-726,238,-25,-784,203,-136,4,27,-162,-191,22,124,-59,-80,28,-14,426,95,-56,76,64,-117,28,70,-70,-148,113,74,62,28,-45,290,34,93,828,85,28,-198,79,-116,-132,129,-16,-100,28,15,719,55,-18,196,30,-16,973,22,13,423,93,60,133,66,-53,-156,36,43,911,34,6,284,31,-38,-259,37,40,831,57,17,195,29,-10,552,62,-116,-150,33,76,908,40,57,-160,37,-7,303,33,39,715,137,-33,-51,115,18,85,33,-20,354,36,-72,-188,29,11,549,63,82,-99,30,-68,-252,122,61,92,67,-84,-152,40,-69,-290,85,97,-25,28,12,986,65,-85,-345,53,-102,-159,87,-97,-137,78,-169,-348,67,-168,-348,61,-158,-351,72,-152,-353,83,-159,-351,84,-275,-688,60,-275,-688,88,-243,-697,56,-245,-700,55,-175,-407,71,-155,-413,61,-188,-464,71,-182,-465,97,-174,-407,82,-196,-461,89,-197,-401,77,-203,-460,63,-196,-401,66,-202,-460,64,-253,-676,73,-248,-677,80,-254,-676,78,-262,-673,68,-261,-673,28,38,191,38,-66,-292,143,-392,194,224,-342,-65,178,-64,-4,267,-347,-114,115,-387,198,109,-2,99,201,-387,62,217,-233,34,172,-162,159,144,-160,169,133,-165,143,230,-213,-148,263,-350,-84,245,-199,-153,226,-190,-183,118,-389,211,231,-462,-71,227,-464,-84,77,-635,217,205,-534,-26,49,-630,221,53,-632,234,170,-381,54,173,-527,-36,61,-629,189,86,-634,198,113,-596,154,87,-591,144,131,-622,98,105,-616,85,158,-577,60,131,-570,44,175,-580,19,145,-574,7,73,-759,123,114,-714,49,147,-662,-2,176,-608,-40,37,-720,231,38,-778,195,139,5,27,176,-184,21,72,-272,-762,-77,-272,-758,40,58,900,46,65,844,44,72,875,45,39,864,43,54,869,41,61,882,38,67,860,47,83,856,33,64,871,-33,40,864,-27,59,901,-34,65,845,-36,84,856,-21,64,871,-29,61,883,-31,55,870,-27,68,860,-32,73,875];
@@ -8,7 +8,7 @@ mod plane;
mod sky;

use cgmath::prelude::*;

use three::Object;

const COLOR_BACKGROUND: three::Color = 0xf0e0b6;
const COLOR_RED: three::Color = 0xf25346;
@@ -1,6 +1,6 @@
use cgmath::{Quaternion, Rad, Rotation3};
use mint;
use three;
use three::{self, Object};

use {COLOR_BROWN, COLOR_BROWN_DARK, COLOR_RED, COLOR_WHITE};

@@ -3,11 +3,10 @@ use std::f32::consts::PI;
use cgmath;
use cgmath::prelude::*;
use rand::Rng;
use three;
use three::{self, Object};

use COLOR_WHITE;


struct Cloud {
group: three::Group,
meshes: Vec<three::Mesh>,
@@ -1,5 +1,7 @@
extern crate three;

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);
@@ -1,5 +1,7 @@
extern crate three;

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);
@@ -3,6 +3,7 @@ extern crate mint;
extern crate three;

use cgmath::{Angle, Decomposed, One, Quaternion, Rad, Rotation3, Transform, Vector3};
use three::Object;

struct Level {
speed: f32,
@@ -1,5 +1,7 @@
extern crate three;

use three::Object;

fn main() {
let mut win = three::Window::new("Three-rs lights example");
let mut cam = win.factory.perspective_camera(45.0, 1.0 .. 50.0);
@@ -17,11 +19,11 @@ fn main() {
.debug_shadow_quad(&shadow_map, 1, [10, 10], [256, 256]);
dir_light.set_shadow(shadow_map, 40.0, 1.0 .. 200.0);

let mut lights: [&mut three::Object; 4] = [
&mut hemisphere_light,
&mut ambient_light,
&mut point_light,
&mut dir_light,
let mut lights: [&mut three::object::Base; 4] = [

This comment has been minimized.

Copy link
@alteous

alteous Dec 3, 2017

Author Member

Solves Self: Sized requirement for generic methods in trait Object.

hemisphere_light.as_mut(),
ambient_light.as_mut(),
point_light.as_mut(),
dir_light.as_mut(),
];
for l in lights.iter_mut() {
l.set_parent(&win.scene);
@@ -1,5 +1,7 @@
extern crate three;

use three::Object;

fn main() {
let mut win = three::Window::new("Three-rs materials example");
let mut cam = win.factory.perspective_camera(75.0, 1.0 .. 50.0);
@@ -4,6 +4,7 @@ extern crate three;

use cgmath::prelude::*;
use std::f32::consts::PI;
use three::Object;

fn make_tetrahedron_geometry() -> three::Geometry {
let vertices = vec![
@@ -1,6 +1,7 @@
extern crate three;

use std::env;
use three::Object;

fn main() {
let mut args = env::args();
@@ -7,6 +7,7 @@ use std::sync::mpsc;
use notify::Watcher;
use std::path::{Path, PathBuf};
use std::time::Duration;
use three::Object;

const MANDELBROT_VERTEX_SHADER_CODE: &'static str = r#"
#version 150 core
@@ -3,6 +3,7 @@ extern crate mint;
extern crate three;

use cgmath::prelude::*;
use three::Object;

fn main() {
let mut win = three::Window::new("Three-rs shapes example");
@@ -1,5 +1,7 @@
extern crate three;

use three::Object;

struct Animator {
cell_size: [u16; 2],
cell_counts: [u16; 2],
@@ -1,5 +1,7 @@
extern crate three;

use three::Object;

fn main() {
let mut window = three::Window::new("Getting started with three-rs");

@@ -42,6 +42,7 @@
//!
//! ```rust,no_run
//! # let mut window = three::Window::new("");
//! use three::Object;
//! let mut gltf = window.factory.load_gltf("AnimatedScene.gltf");
//! gltf.group.set_parent(&window.scene);
//! ```
@@ -55,6 +56,7 @@
//! immediately.
//!
//! ```rust,no_run
//! # use three::Object;
//! # let mut window = three::Window::new("");
//! # let mut mixer = three::animation::Mixer::new();
//! # let mut gltf = window.factory.load_gltf("AnimatedScene.gltf");
@@ -71,6 +73,7 @@
//! game loop.
//!
//! ```rust,no_run
//! # use three::Object;
//! # let mut window = three::Window::new("");
//! # let camera = unimplemented!();
//! # let mut mixer = three::animation::Mixer::new();
@@ -103,12 +106,15 @@
use cgmath;
use froggy;
use mint;
use object;
use std::hash::{Hash, Hasher};
use std::sync::mpsc;

use Object;
use mint::IntraXYZ as IntraXyz;

/// A target of an animation.
pub type Target = object::Base;

/// Describes the interpolation behaviour between keyframes.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum Interpolation {
@@ -157,15 +163,15 @@ pub enum Binding {
///
/// The corresponding keyframe values must be [`Vector3`].
///
/// [`Object`]: ../object/struct.Object.html
/// [`Object`]: ../object/trait.Object.html
/// [`Vector3`]: enum.Values.html#variant.Vector3
Position,

/// Targets the orientation property of an [`Object`].
///
/// The corresponding keyframe values must be [`Quaternion`] or [`Euler`].
///
/// [`Object`]: ../object/struct.Object.html
/// [`Object`]: ../object/trait.Object.html
/// [`Quaternion`]: enum.Values.html#variant.Quaternion
/// [`Euler`]: enum.Values.html#variant.Euler
Orientation,
@@ -174,7 +180,7 @@ pub enum Binding {
///
/// The corresponding keyframe values must be [`Scalar`].
///
/// [`Object`]: ../object/struct.Object.html
/// [`Object`]: ../object/trait.Object.html
/// [`Scalar`]: enum.Values.html#variant.Scalar
Scale,
}
@@ -295,7 +301,7 @@ pub struct Clip {
pub name: Option<String>,

/// The animation keyframe tracks.
pub tracks: Vec<(Track, Object)>,
pub tracks: Vec<(Track, Target)>,
}

/// A track of animation keyframes.
@@ -1,5 +1,6 @@
//! Primitives for audio playback.

use object;
use std::fmt;
use std::io::Cursor;
use std::rc::Rc;
@@ -9,7 +10,6 @@ use rodio as r;
use rodio::Source as _Source;

use hub::Operation as HubOperation;
use object::Object;

/// Audio segment with sound effects.
///
@@ -114,11 +114,12 @@ impl AudioData {
/// You may create several `Source`s to play sounds simultaneously.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Source {
pub(crate) object: Object,
pub(crate) object: object::Base,
}
three_object!(Source::object);

impl Source {
pub(crate) fn with_object(object: Object) -> Self {
pub(crate) fn with_object(object: object::Base) -> Self {
Source { object }
}

@@ -252,6 +253,6 @@ impl SourceInternal {

/* TODO: Implement 3d sound.
pub struct Listener {
pub(crate) object: Object,
pub(crate) object: object::Base,
}
*/
@@ -52,16 +52,15 @@
//!
//! [`Factory::orthographic_camera`]: ../factory/struct.Factory.html#method.orthographic_camera
//! [`Factory::perspective_camera`]: ../factory/struct.Factory.html#method.perspective_camera
//! [`Object`]: ../object/struct.Object.html
//! [`object::Base`]: ../object/struct.Base.html
//! [`Orthographic`]: struct.Orthographic.html
//! [`Perspective`]: struct.Perspective.html

use cgmath;
use mint;
use object;
use std::ops;

use object::Object;

/// The Z values of the near and far clipping planes of a camera's projection.
#[derive(Clone, Debug, PartialEq)]
pub enum ZRange {
@@ -98,11 +97,12 @@ pub enum Projection {
/// [`Projection`]: enum.Projection.html
#[derive(Clone, Debug, PartialEq)]
pub struct Camera {
pub(crate) object: Object,
pub(crate) object: object::Base,

/// Projection parameters of this camera.
pub projection: Projection,
}
three_object!(Camera::object);

impl Camera {
/// Computes the projection matrix representing the camera's projection.
@@ -158,8 +158,6 @@ impl Projection {
}
}

three_object_wrapper!(Camera);

/// Orthographic projection parameters.
#[derive(Clone, Debug, PartialEq)]
pub struct Orthographic {
@@ -1,5 +1,6 @@
use cgmath;
use mint;
use object;
use std::ops;

use cgmath::Rotation3;
@@ -33,7 +34,7 @@ impl Default for Axes {
/// Controls for first person camera.
#[derive(Clone, Debug, PartialEq)]
pub struct FirstPerson {
object: Object,
object: object::Base,
position: mint::Point3<f32>,
yaw: f32,
pitch: f32,
@@ -48,7 +49,7 @@ pub struct FirstPerson {
/// Constructs custom [`FirstPerson`](struct.FirstPerson.html) controls.
#[derive(Clone, Debug, PartialEq)]
pub struct Builder {
object: Object,
object: object::Base,
position: mint::Point3<f32>,
pitch_range: Option<ops::Range<f32>>,
yaw: f32,
@@ -62,9 +63,9 @@ pub struct Builder {

impl Builder {
/// Create new `Builder` with default parameters.
pub fn new(object: &Object) -> Self {
pub fn new<T: Object>(object: &T) -> Self {
Builder {
object: object.clone(),
object: object.upcast(),
position: [0.0, 0.0, 0.0].into(),
yaw: 0.0,
pitch: 0.0,
@@ -221,12 +222,12 @@ impl Builder {

impl FirstPerson {
/// Create a `Builder`.
pub fn builder(object: &Object) -> Builder {
pub fn builder<T: Object>(object: &T) -> Builder {
Builder::new(object)
}

/// Create `FirstPerson` controls with default parameters.
pub fn default(object: &Object) -> Self {
pub fn default<T: Object>(object: &T) -> Self {
Self::builder(object).build()
}

@@ -355,27 +356,27 @@ impl FirstPerson {
}
}

self.axes
.vertical
.map(|a| if let Some(diff) = input.timed(a) {
self.axes.vertical.map(|a| {

This comment has been minimized.

Copy link
@alteous

alteous Dec 3, 2017

Author Member

@vitvakatu Looks like formatting has regressed again. Will try to fix.

This comment has been minimized.

Copy link
@alteous

alteous Dec 3, 2017

Author Member

Not sure I can fix this, sorry!

$ cargo fmt -- --version
0.2.16-nightly ( )

This comment has been minimized.

Copy link
@vitvakatu

vitvakatu Dec 4, 2017

Member

It's okay, the same version, same changes in my fork.

if let Some(diff) = input.timed(a) {
self.position.y += self.move_speed * diff;
});
}
});

self.axes
.forward
.map(|a| if let Some(diff) = input.timed(a) {
self.axes.forward.map(|a| {
if let Some(diff) = input.timed(a) {
self.position.x += self.move_speed * diff * self.yaw.sin();
self.position.z -= self.move_speed * diff * self.yaw.cos();
if self.vertical_move {
self.position.y -= self.move_speed * diff * self.pitch.sin();
}
});
self.axes
.strafing
.map(|a| if let Some(diff) = input.timed(a) {
}
});
self.axes.strafing.map(|a| {
if let Some(diff) = input.timed(a) {
self.position.x += self.move_speed * diff * self.yaw.cos();
self.position.z += self.move_speed * diff * self.yaw.sin();
});
}
});

let yrot = cgmath::Quaternion::from_angle_y(cgmath::Rad(-self.yaw));
let xrot = cgmath::Quaternion::from_angle_x(cgmath::Rad(-self.pitch));
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.