Skip to content

Commit

Permalink
Merge pull request #54 from shawnscode/0.5.0
Browse files Browse the repository at this point in the history
0.5.0
  • Loading branch information
shawnscode authored Aug 24, 2018
2 parents 382799e + c4fbeeb commit d8f3e72
Show file tree
Hide file tree
Showing 52 changed files with 275 additions and 134 deletions.
13 changes: 9 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ script:
- cargo build --all --verbose --no-default-features
- cargo test --all --verbose --no-default-features
- |
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
for file in examples/*.rs; do if [[ -f $file ]]; then filename=$(basename $file); target/debug/examples/${filename%.*} headless; fi done;
fi
for file in crayon-examples/*.rs; do
if [[ -f $file ]]; then
filename=$(basename $file);
filename=${filename#*_};
filename=${filename%.*};
RUST_BACKTRACE=1 target/debug/${filename} headless;
fi
done;
# Perform coverage test based on kcov, and upload it.
after_success: |
Expand All @@ -68,6 +73,6 @@ after_success: |
cd ../.. &&
rm -rf kcov-master &&
for file in target/debug/*-*[^\.d]; do mkdir -p "target/cov/tests_$(basename $file)"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/tests_$(basename $file)" "$file"; done &&
for file in examples/*.rs; do if [[ -f $file ]]; then filename=$(basename $file); mkdir -p "target/cov/examples_$filename"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/examples_$filename" "target/debug/examples/${filename%.*}" "headless"; fi done &&
for file in crayon-examples/*.rs; do if [[ -f $file ]]; then filename=$(basename $file); filename=${filename#*_}; filename=${filename%.*}; mkdir -p "target/cov/examples_$filename"; ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/examples_$filename" "target/debug/${filename}" "headless"; fi done &&
bash <(curl -s https://codecov.io/bash);
fi
11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@ appveyor = { repository = "shawnscode/crayon", branch = "master", service = "git
codecov = { repository = "shawnscode/crayon", branch = "master", service = "github" }

[workspace]
members = [ "modules/imgui", "modules/3d" ]
members = [ "crayon-examples", "modules/imgui", "modules/3d" ]

[dependencies]
gl = "0.10.0"
glutin = "0.17.0"
glutin = "0.18.0"
crossbeam-deque = "0.5.1"
failure = "0.1.1"
failure = "0.1.2"
log = "0.4.4"

serde = { version = "1.0.70", features = ["serde_derive"] }
serde = { version = "1.0.74", features = ["serde_derive"] }
bincode = "1.0.1"

uuid = { version = "0.6.5", features = ["serde"] }
cgmath = { version = "0.16.1", features = ["serde"] }

[dev-dependencies]
crayon-testbed = { path = "examples/testbed" }
rand = "0.5.4"
rand = "0.5.5"
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ The asset workflow comes with the version 0.0.5. During the developent, the asse

Currently, we are supporting assets with:

1. Transmission files like `.gltf`, `.blend`, `.fbx`, etc.. through [assimp](https://github.com/assimp/assimp).
1. Transmission files like `.glTF`, `.blend`, `.fbx`, etc.. through [assimp](https://github.com/assimp/assimp).
* Notes that not only `Mesh`, but also the nodes will be imported as `Prefab` for scene creation.
2. Texture files like `.PSD`, `.PNG`, `.JPEG`, `.BMP`, etc.. through [PvrTexTool](https://community.imgtec.com/developers/powervr/tools/pvrtextool/) and [crunch](https://github.com/BKcore/crunch-osx).
2. Texture files like `.psd`, `.png`, `.jpeg`, `.bmp`, etc.. through [PvrTexTool](https://community.imgtec.com/developers/powervr/tools/pvrtextool/) and [crunch](https://github.com/BKcore/crunch-osx).
* Notes that texture files could be compressed into `PVRTC`, `ETC2` or `S3TC` formats based on platform.
3. Universal shader files through [SPIRV](https://www.khronos.org/registry/spir-v/) are also in planning, and should be ready in next few releases.

The assets manipulation codes are placed under [crayon-tools](), checks out the repository for further details.
The assets manipulation codes are placed under [crayon-tools](https://github.com/shawnscode/crayon-tools), checks out the repository for further details.

### Quick Example
For the sake of brevity, you can als run a simple and quick example with commands:

``` sh
git clone [email protected]:shawnscode/crayon.git
cargo run --example modules_3d_prefab
git clone [email protected]:shawnscode/crayon.git && cd crayon-examples
cargo run --bin prefab
```
27 changes: 27 additions & 0 deletions crayon-examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "crayon-examples"
version = "0.0.0"
authors = [ "Jingkai Mao <[email protected]>" ]

[dependencies]
crayon-testbed = { path = "testbed" }

[[bin]]
name = "render_texture"
path = "core_render_texture.rs"

[[bin]]
name = "texture"
path = "core_texture.rs"

[[bin]]
name = "input"
path = "core_input.rs"

[[bin]]
name = "imgui"
path = "modules_imgui.rs"

[[bin]]
name = "prefab"
path = "modules_prefab.rs"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions examples/input.rs → crayon-examples/core_input.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
extern crate crayon;
#[macro_use]
extern crate crayon_testbed;

use crayon::prelude::*;
use crayon_testbed::prelude::*;
use crayon_testbed::ImGuiCond;

struct Window {
canvas: ConsoleCanvas,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#[macro_use]
extern crate crayon;
extern crate crayon_testbed;

use crayon::prelude::*;
use crayon_testbed::prelude::*;

impl_vertex!{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#[macro_use]
extern crate crayon;
extern crate crayon_testbed;

use crayon::prelude::*;
use crayon_testbed::prelude::*;

use crayon::video::assets::texture::TextureHandle as CoreTextureHandle;

impl_vertex!{
Vertex {
position => [Position; Float; 2; false],
Expand All @@ -17,7 +12,7 @@ struct Window {
surface: SurfaceHandle,
shader: ShaderHandle,
mesh: MeshHandle,
texture: CoreTextureHandle,
texture: TextureHandle,
canvas: ConsoleCanvas,
}

Expand Down
3 changes: 0 additions & 3 deletions examples/imgui.rs → crayon-examples/modules_imgui.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
extern crate crayon;
extern crate crayon_testbed;

use crayon::prelude::*;
use crayon_testbed::prelude::*;

struct Window {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
extern crate crayon;
extern crate crayon_testbed;

use crayon::prelude::*;
use crayon_testbed::prelude::*;

struct Window {
Expand All @@ -12,19 +9,27 @@ struct Window {

impl Window {
fn new(engine: &mut Engine) -> Result<Self> {
//
let world_resources = WorldResources::new(engine);

let ctx = engine.context();
let pipeline = SimpleRenderer::new(&ctx)?;
let mut world = World::new(world_resources.shared(), pipeline);

//
let prefab = ctx.res.load("res:cornell_box.obj")?;
ctx.res.wait(prefab)?;

//
let mut world = World::new(world_resources.shared(), pipeline);
let room = world.instantiate(prefab).unwrap();

// Lets give shortBox some red color.
let mut m = SimpleMaterial::default();
let e = world.find("cornell_box.obj/shortBox").unwrap();
m.diffuse = [255, 100, 100, 255].into();
world.renderer.add(e, m);

let e = world.find("cornell_box.obj/tallBox").unwrap();
m.diffuse = [55, 55, 255, 255].into();
world.renderer.add(e, m);

//
let lit = world.create();
let rotation = math::Euler::new(math::Deg(45.0), math::Deg(0.0), math::Deg(0.0));
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crayon-testbed"
version = "0.1.0"
version = "0.0.0"
authors = ["maojingkai <[email protected]>"]

[dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::sync::Arc;

use crayon::errors::*;
use crayon::prelude::*;
use crayon_imgui;
use crayon_imgui::prelude::*;

use crayon_imgui::{self, Canvas, ImGuiCond};

fn to_ms(duration: ::std::time::Duration) -> f32 {
duration.as_secs() as f32 * 1000.0 + duration.subsec_nanos() as f32 / 1_000_000.0
Expand Down
16 changes: 14 additions & 2 deletions examples/testbed/src/lib.rs → crayon-examples/testbed/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
extern crate crayon;
pub use crayon::*;

extern crate crayon_3d;
#[macro_use]
extern crate crayon_imgui;
pub use crayon_imgui::*;

extern crate env_logger;

pub mod console;
Expand Down Expand Up @@ -29,6 +34,7 @@ pub fn find_res_dir() -> crayon::res::vfs::DiskFS {
let search_dirs = [
root.join("resources"),
root.parent().unwrap().join("resources"),
root.join("crayon-examples/resources"),
];

for v in &search_dirs {
Expand All @@ -42,7 +48,13 @@ pub fn find_res_dir() -> crayon::res::vfs::DiskFS {

pub mod prelude {
pub use super::console::ConsoleCanvas;
pub use crayon::errors::*;

pub use crayon_3d::prelude::*;
pub use crayon_imgui::prelude::*;

// pub use crayon_imgui::prelude::TextureHandle as ImGuiTextureHandle;
// pub use crayon_imgui::prelude::*;

pub use crayon::errors::*;
pub use crayon::prelude::*;
pub use crayon::video::assets::prelude::*;
}
File renamed without changes.
8 changes: 4 additions & 4 deletions modules/3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
name = "crayon-3d"
version = "0.1.0"
authors = ["Jingkai Mao <[email protected]>"]
description = "An embeddable 3d module of crayon."
description = "Just another 3d module."
repository = "https://github.com/shawnscode/crayon"
license = "Apache-2.0"
keywords = ["crayon", "game-dev", "scene", "3d"]
categories = ["multimedia", "game-engines"]

[dependencies]
crayon = { path = "../../", version = "0.5.0" }
serde = { version = "1.0.70", features = ["serde_derive"] }
failure = "0.1.1"
serde = { version = "1.0.74", features = ["serde_derive"] }
failure = "0.1.2"

[dev-dependencies]
rand = "0.5.4"
rand = "0.5.5"
6 changes: 3 additions & 3 deletions modules/3d/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ mod world;
pub use self::world::{world_impl, Entity, World};

pub mod prelude {
pub use assets::WorldResources;
pub use renderers::{Camera, Lit, MeshRenderer, SimpleRenderer};
pub use scene::SceneGraph;
pub use assets::{Prefab, WorldResources};
pub use renderers::{Camera, Lit, MeshRenderer, SimpleMaterial, SimpleRenderer};
pub use scene::{SceneGraph, Transform};
pub use world::{Entity, World};
}
2 changes: 1 addition & 1 deletion modules/3d/src/renderers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod mesh_renderer;
pub use self::mesh_renderer::MeshRenderer;

pub mod simple;
pub use self::simple::SimpleRenderer;
pub use self::simple::{SimpleMaterial, SimpleRenderer};

use scene::SceneGraph;
use {Component, Entity};
Expand Down
6 changes: 3 additions & 3 deletions modules/3d/src/renderers/simple/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ use crayon::math;
use crayon::video::assets::texture::TextureHandle;

#[derive(Debug, Copy, Clone)]
pub struct Material {
pub struct SimpleMaterial {
pub texture: TextureHandle,
pub ambient: math::Color<f32>,
pub diffuse: math::Color<f32>,
pub specular: math::Color<f32>,
pub shininess: f32,
}

impl Default for Material {
impl Default for SimpleMaterial {
fn default() -> Self {
Material {
SimpleMaterial {
texture: TextureHandle::default(),
ambient: math::Color::white(),
diffuse: math::Color::white(),
Expand Down
12 changes: 7 additions & 5 deletions modules/3d/src/renderers/simple/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod material;
pub use self::material::Material;
pub use self::material::SimpleMaterial;

use crayon::application::Context;
use crayon::errors::*;
Expand All @@ -15,8 +15,9 @@ use {Component, Entity};
pub const MAX_DIR_LITS: usize = 1;
pub const MAX_POINT_LITS: usize = 4;

/// A simple renderer that draws some color into mesh objects.
pub struct SimpleRenderer {
materials: Component<Material>,
materials: Component<SimpleMaterial>,

surface: SurfaceHandle,
shader: ShaderHandle,
Expand All @@ -28,6 +29,7 @@ pub struct SimpleRenderer {
}

impl SimpleRenderer {
/// Creates a new `SimpleRenderer`.
pub fn new(ctx: &Context) -> Result<Self> {
// Create shader state.
let attributes = AttributeLayout::build()
Expand Down Expand Up @@ -127,7 +129,7 @@ impl SimpleRenderer {
}

#[inline]
pub fn add(&mut self, ent: Entity, material: Material) -> Option<Material> {
pub fn add(&mut self, ent: Entity, material: SimpleMaterial) -> Option<SimpleMaterial> {
self.materials.add(ent, material)
}

Expand All @@ -137,12 +139,12 @@ impl SimpleRenderer {
}

#[inline]
pub fn material(&self, ent: Entity) -> Option<&Material> {
pub fn material(&self, ent: Entity) -> Option<&SimpleMaterial> {
self.materials.get(ent)
}

#[inline]
pub fn material_mut(&mut self, ent: Entity) -> Option<&mut Material> {
pub fn material_mut(&mut self, ent: Entity) -> Option<&mut SimpleMaterial> {
self.materials.get_mut(ent)
}

Expand Down
Loading

0 comments on commit d8f3e72

Please sign in to comment.