aboutsummaryrefslogtreecommitdiff
path: root/examples3d/all_examples3.rs
blob: 9c1dffc627eb7bf349617f36e8834a102ad58077 (plain)
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
#![allow(dead_code)]

extern crate nalgebra as na;

#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;

use inflector::Inflector;

use rapier_testbed3d::Testbed;
use std::cmp::Ordering;

mod add_remove3;
mod collision_groups3;
mod compound3;
mod damping3;
mod debug_boxes3;
mod debug_cylinder3;
mod debug_triangle3;
mod debug_trimesh3;
mod domino3;
mod heightfield3;
mod joints3;
mod keva3;
mod platform3;
mod primitives3;
mod restitution3;
mod sensor3;
mod stacks3;
mod trimesh3;

fn demo_name_from_command_line() -> Option<String> {
    let mut args = std::env::args();

    while let Some(arg) = args.next() {
        if &arg[..] == "--example" {
            return args.next();
        }
    }

    None
}

#[cfg(any(target_arch = "wasm32", target_arch = "asmjs"))]
fn demo_name_from_url() -> Option<String> {
    None
    //    let window = stdweb::web::window();
    //    let hash = window.location()?.search().ok()?;
    //    if hash.len() > 0 {
    //        Some(hash[1..].to_string())
    //    } else {
    //        None
    //    }
}

#[cfg(not(any(target_arch = "wasm32", target_arch = "asmjs")))]
fn demo_name_from_url() -> Option<String> {
    None
}

#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
pub fn main() {
    let demo = demo_name_from_command_line()
        .or_else(|| demo_name_from_url())
        .unwrap_or(String::new())
        .to_camel_case();

    let mut builders: Vec<(_, fn(&mut Testbed))> = vec![
        ("Add remove", add_remove3::init_world),
        ("Primitives", primitives3::init_world),
        ("Collision groups", collision_groups3::init_world),
        ("Compound", compound3::init_world),
        ("Damping", damping3::init_world),
        ("Domino", domino3::init_world),
        ("Heightfield", heightfield3::init_world),
        ("Joints", joints3::init_world),
        ("Platform", platform3::init_world),
        ("Restitution", restitution3::init_world),
        ("Stacks", stacks3::init_world),
        ("Sensor", sensor3::init_world),
        ("Trimesh", trimesh3::init_world),
        ("Keva tower", keva3::init_world),
        ("(Debug) boxes", debug_boxes3::init_world),
        ("(Debug) triangle", debug_triangle3::init_world),
        ("(Debug) trimesh", debug_trimesh3::init_world),
        ("(Debug) cylinder", debug_cylinder3::init_world),
    ];

    // Lexicographic sort, with stress tests moved at the end of the list.
    builders.sort_by(|a, b| match (a.0.starts_with("("), b.0.starts_with("(")) {
        (true, true) | (false, false) => a.0.cmp(b.0),
        (true, false) => Ordering::Greater,
        (false, true) => Ordering::Less,
    });

    let i = builders
        .iter()
        .position(|builder| builder.0.to_camel_case().as_str() == demo.as_str())
        .unwrap_or(0);

    let testbed = Testbed::from_builders(i, builders);

    testbed.run()
}