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
use crate::api::BabylonApi; use crate::core::*; use crate::math::*; use js_ffi::*; pub trait Material { fn get_js_ref(&self) -> &JSObject; } pub struct StandardMaterial { js_ref: JSObject, diffuse_color: Color, specular_color: Color, emmisive_color: Color, ambient_color: Color, alpha: f64, } impl StandardMaterial { pub fn new(scene: &Scene) -> StandardMaterial { StandardMaterial { js_ref: BabylonApi::create_standard_material(scene.get_js_ref()), diffuse_color: Color::new(0.0, 0.0, 0.0), specular_color: Color::new(0.0, 0.0, 0.0), emmisive_color: Color::new(0.0, 0.0, 0.0), ambient_color: Color::new(0.0, 0.0, 0.0), alpha: 1.0, } } pub fn set_diffuse_color(&mut self, c: Color) { self.diffuse_color = c; BabylonApi::set_diffuse_color(self.get_js_ref(), c.x, c.y, c.z); } pub fn set_emmisive_color(&mut self, c: Color) { self.emmisive_color = c; BabylonApi::set_emmisive_color(self.get_js_ref(), c.x, c.y, c.z); } pub fn set_specular_color(&mut self, c: Color) { self.specular_color = c; BabylonApi::set_specular_color(self.get_js_ref(), c.x, c.y, c.z); } pub fn set_ambient_color(&mut self, c: Color) { self.ambient_color = c; BabylonApi::set_ambient_color(self.get_js_ref(), c.x, c.y, c.z); } pub fn set_alpha(&mut self, a: f64) { self.alpha = a; BabylonApi::set_alpha(self.get_js_ref(), a); } } impl Material for StandardMaterial { fn get_js_ref(&self) -> &JSObject { return &self.js_ref; } }