1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#![warn(missing_docs)]
//! Three.js inspired 3D engine.
//!
//! # Getting Started
//!
//! ## Creating a window
//!
//! Every `three` application begins with a [`Window`]. We create it as follows.
//!
//! ```rust,no_run
//! # extern crate three;
//! # fn main() {
//! let title = "Getting started with three-rs";
//! let mut window = three::Window::new(title);
//! # }
//! ```
//!
//! ## The four key structs
//!
//! Every [`Window`] comes equipped with four structures, namely [`Factory`],
//! [`Renderer`], [`Input`], and [`Scene`].
//!
//! * The [`Factory`] instantiates game objects such as [`Mesh`] and [`Camera`].
//! * The [`Input`] handles window events at a high-level.
//! * The [`Scene`] is the root node of the component-graph system.
//! * The [`Renderer`] renders the [`Scene`] from the view of a [`Camera`] object.
//!
//! ## Creating a basic mesh
//!
//! Renderable 3D objects are represented by the [`Mesh`] struct. A mesh is a
//! combination of [`Geometry`], describing the shape of the object, paired with a
//! [`Material`], describing the appearance of the object.
//!
//! ```rust,no_run
//! # extern crate three;
//! # fn main() {
//! # let title = "Getting started with three-rs";
//! # let mut window = three::Window::new(title);
//! let geometry = three::Geometry::with_vertices(vec![
//!     [-0.5, -0.5, -0.5].into(),
//!     [ 0.5, -0.5, -0.5].into(),
//!     [ 0.0,  0.5, -0.5].into(),
//! ]);
//! let material = three::material::Basic {
//!     color: 0xFFFF00,
//!     .. Default::default()
//! };
//! let mut mesh = window.factory.mesh(geometry, material);
//! # }
//! ```
//!
//! ## Managing the scene
//!
//! In order to be rendered by the [`Renderer`], meshes must be placed in the
//! [`Scene`] within the viewable region. Any marked with the [`Object`] trait
//! may be placed into the scene heirarchy, including user-defined structs.
//!
//! ```rust,no_run
//! # extern crate three;
//! # fn main() {
//! # let title = "Getting started with three-rs";
//! # let mut window = three::Window::new(title);
//! # let vertices = vec![
//! #     [-0.5, -0.5, -0.5].into(),
//! #     [ 0.5, -0.5, -0.5].into(),
//! #     [ 0.0,  0.5, -0.5].into(),
//! # ];
//! # let geometry = three::Geometry::with_vertices(vertices);
//! # let material = three::material::Basic {
//! #      color: 0xFFFF00,
//! #      .. Default::default()
//! # };
//! # let mesh = window.factory.mesh(geometry, material);
//! window.scene.add(&mesh);
//! # }
//! ```
//!
//! We can set the initial scene background using the `Scene::background`
//! field. The default background is solid black. Let's set the background to a
//! sky blue color instead.
//!
//! ```rust,no_run
//! # extern crate three;
//! # fn main() {
//! # let title = "Getting started with three-rs";
//! # let mut window = three::Window::new(title);
//! window.scene.background = three::Background::Color(0xC6F0FF);
//! # }
//! ```
//!
//! ## Creating the game loop
//!
//! All is left to do to render our triangle is to create a camera and to
//! write the main game loop.
//!
//! ```rust,no_run
//! # extern crate three;
//! # fn main() {
//! #     let title = "Getting started with three-rs";
//! #     let mut window = three::Window::new(title);
//! #     let vertices = vec![
//! #         [-0.5, -0.5, -0.5].into(),
//! #         [ 0.5, -0.5, -0.5].into(),
//! #         [ 0.0,  0.5, -0.5].into(),
//! #     ];
//! #     let geometry = three::Geometry::with_vertices(vertices);
//! #     let material = three::material::Basic {
//! #         color: 0xFFFF00,
//! #         .. Default::default()
//! #     };
//! #     let mut mesh = window.factory.mesh(geometry, material);
//! #     window.scene.add(&mesh);
//! let center = [0.0, 0.0];
//! let yextent = 1.0;
//! let zrange = -1.0 .. 1.0;
//! let camera = window.factory.orthographic_camera(center, yextent, zrange);
//! while window.update() {
//!     window.render(&camera);
//! }
//! # }
//! ```
//!
//! ## Putting it all together
//!
//! You should have the following code which renders a single yellow triangle
//! upon a sky blue background.
//!
//! ```rust,no_run
//! extern crate three;
//!
//! use three::Object;
//!
//! fn main() {
//!     let title = "Getting started with three-rs";
//!     let mut window = three::Window::new(title);
//!
//!     let vertices = vec![
//!         [-0.5, -0.5, -0.5].into(),
//!         [ 0.5, -0.5, -0.5].into(),
//!         [ 0.0,  0.5, -0.5].into(),
//!     ];
//!     let geometry = three::Geometry::with_vertices(vertices);
//!     let material = three::material::Basic {
//!         color: 0xFFFF00,
//!         .. Default::default()
//!     };
//!     let mesh = window.factory.mesh(geometry, material);
//!     window.scene.add(&mesh);
//!
//!     let center = [0.0, 0.0];
//!     let yextent = 1.0;
//!     let zrange = -1.0 .. 1.0;
//!     let camera = window.factory.orthographic_camera(center, yextent, zrange);
//!
//!     while window.update() {
//!         window.render(&camera);
//!     }
//! }
//! ```
//!
//! # Highlighted features
//!
//! ## Scene management
//!
//! We use [`froggy`] to manage the scene heirarchy. `three` takes a slightly
//! different approach to regular scene graphs whereby child objects keep their
//! parents alive, opposed to parents keeping their children alive.
//!
//! At the heart of the scene heirarchy is the [`object::Base`] type, which
//! is a member of all `three` objects that are placeable in the scene.
//!
//! All three objects are marked by the [`Object`] trait which provides the
//! library with the [`object::Base`] type. Users may implement this trait in
//! order to add their own structs into the scene heirarchy. Three-rs provides a helper
//! macro [`three_object`] which provides a convenient way to implement [`Object`] for your
//! types:
//!
//! ```rust,no_run
//! #[macro_use]
//! extern crate three;
//!
//! use three::Object;
//!
//! struct MyObject {
//!     group: three::Group,
//! }
//!
//! three_object!(MyObject::group);
//!
//! fn main() {
//! #    let mut window = three::Window::new("");
//!     // Initialization code omitted.
//!     let my_object = MyObject { group: window.factory.group() };
//!     window.scene.add(&my_object);
//! }
//! ```
//!
//! ## Multiple graphics pipelines
//!
//! Graphics pipeline management is handled implicitly by `three`. The pipeline used
//! to render a [`Mesh`] is chosen by its [`Material`] properties and the available
//! vertex attributes from its [`Geometry`].
//!
//! The range of graphics pipelines available range from simple sprite rendering to
//! physically based rendering.
//!
//! ## 3D format loading
//!
//! ### glTF 2.0
//!
//! `three` comes equipped with support for rendering and animating glTF scenes.
//!
//! See [`Factory::load_gltf`] to get started.
//!
//! ### Wavefront OBJ
//!
//! For less complex meshes, `three` supports loading models in OBJ format.
//!
//! See [`Factory::load_obj`] for more information.
//!
//! ## Procedurally generated geometry
//!
//! The [`Geometry`] struct leverages the [`genmesh`] crate to provide procedurally
//! generated primtives such as cuboids, spheres, and cylinders. See the
//! documentation on the [`Geometry`] struct for more information.
//!
//! [`froggy`]: https://crates.io/crates/froggy
//! [`genmesh`]: https://crates.io/crates/genmesh
//!
//! [`Camera`]: camera/struct.Camera.html
//! [`Factory`]: factory/struct.Factory.html
//! [`Factory::load_gltf`]: factory/struct.Factory.html#method.load_gltf
//! [`Factory::load_obj`]: factory/struct.Factory.html#method.load_obj
//! [`Geometry`]: geometry/struct.Geometry.html
//! [`Input`]: input/struct.Input.html
//! [`Material`]: material/enum.Material.html
//! [`Mesh`]: mesh/struct.Mesh.html
//! [`object::Base`]: object/struct.Base.html
//! [`Object`]: object/trait.Object.html
//! [`Renderer`]: struct.Renderer.html
//! [`Scene`]: scene/struct.Scene.html
//! [`Window`]: window/struct.Window.html
//! [`three_object`]: macro.three_object.html

extern crate arrayvec;
#[macro_use]
extern crate bitflags;
extern crate cgmath;
#[macro_use]
extern crate derivative;
extern crate froggy;
extern crate genmesh;
#[macro_use]
extern crate gfx;
extern crate gfx_glyph;
#[cfg(feature = "gltf")]
extern crate gltf;
extern crate image;
extern crate includedir;
#[macro_use]
extern crate itertools;
#[macro_use]
extern crate log;
extern crate mint;
extern crate obj;
extern crate phf;
#[macro_use]
extern crate quick_error;
extern crate rodio;
extern crate vec_map;

#[cfg(feature = "opengl")]
extern crate gfx_device_gl;
#[cfg(feature = "opengl")]
extern crate gfx_window_glutin;
#[cfg(feature = "opengl")]
extern crate glutin;

#[macro_use]
mod macros;

pub mod audio;
pub mod animation;
pub mod camera;
pub mod color;
pub mod controls;
pub mod custom;
mod data;
mod factory;
mod geometry;
mod hub;
mod input;
pub mod light;
pub mod material;
mod mesh;
mod node;
pub mod object;
pub mod render;
pub mod scene;
pub mod skeleton;
mod sprite;
pub mod template;
mod text;
mod texture;
mod util;

#[cfg(feature = "opengl")]
pub mod window;

#[doc(inline)]
pub use color::Color;

#[doc(inline)]
pub use controls::{AXIS_DOWN_UP, AXIS_LEFT_RIGHT, KEY_ESCAPE, KEY_SPACE, MOUSE_LEFT, MOUSE_RIGHT};

#[doc(inline)]
pub use controls::{Button, MouseButton, Input, Timer};

#[doc(inline)]
pub use factory::Factory;

#[doc(inline)]
pub use geometry::{Geometry, Joints, Shape};

#[cfg(feature = "opengl")]
#[doc(inline)]
pub use glutin::VirtualKeyCode as Key;

//#[doc(inline)]
//pub use group::Group;

#[doc(inline)]
pub use material::Material;

#[doc(inline)]
pub use mesh::{DynamicMesh, Mesh};

#[doc(inline)]
pub use node::{Node, Transform, Local, World};

#[doc(inline)]
pub use object::{Group, Object};

#[doc(inline)]
pub use render::Renderer;

#[doc(inline)]
pub use scene::{Background, Scene};

#[doc(inline)]
pub use sprite::Sprite;

#[doc(inline)]
pub use text::{Align, Font, Layout, Text};

#[doc(inline)]
pub use texture::{CubeMap, CubeMapPath, FilterMethod, Sampler, Texture, WrapMode};

#[cfg(feature = "opengl")]
#[doc(inline)]
pub use window::Window;