mirror of https://github.com/Leinnan/doppler.git
Init work on 2d
This commit is contained in:
parent
9320ed97b6
commit
102eadf5c9
|
|
@ -0,0 +1,72 @@
|
||||||
|
use doppler::assets_cache::AssetsCache;
|
||||||
|
use doppler::camera::*;
|
||||||
|
use doppler::client::Client;
|
||||||
|
use doppler::glutin::event::{ElementState, VirtualKeyCode};
|
||||||
|
use doppler::shader::Shader;
|
||||||
|
use doppler::map::*;
|
||||||
|
use doppler::components::*;
|
||||||
|
|
||||||
|
pub struct Client2D{
|
||||||
|
delta: f32,
|
||||||
|
models_2d: ModelComponent,
|
||||||
|
shader: Shader
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Client2D {
|
||||||
|
fn default() -> Self {
|
||||||
|
Client2D {
|
||||||
|
delta: 0.0,
|
||||||
|
models_2d: ModelComponent::default(),
|
||||||
|
shader: Shader::from_file(
|
||||||
|
"resources/shaders/multiple_lights.vs",
|
||||||
|
"resources/shaders/multiple_lights.fs",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Client for Client2D {
|
||||||
|
fn on_keyboard(&mut self, code: &VirtualKeyCode, state: &ElementState) {
|
||||||
|
match (code, state) {
|
||||||
|
(VirtualKeyCode::W, ElementState::Pressed) => (),
|
||||||
|
(VirtualKeyCode::S, ElementState::Pressed) => (),
|
||||||
|
(VirtualKeyCode::A, ElementState::Pressed) => (),
|
||||||
|
(VirtualKeyCode::D, ElementState::Pressed) => (),
|
||||||
|
(VirtualKeyCode::LControl, _) => (),
|
||||||
|
(_, _) => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_assets(&mut self, cache: &mut AssetsCache) {
|
||||||
|
self.models_2d.model = cache.load_2d("resources/objects/ddd.jpg");
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn draw(&mut self) {
|
||||||
|
use doppler::math::prelude::*;
|
||||||
|
self.models_2d.draw(&self.shader);
|
||||||
|
// let projection: Matrix4<f32> = perspective(
|
||||||
|
// Deg(self.camera.zoom),
|
||||||
|
// consts::SCR_WIDTH as f32 / consts::SCR_HEIGHT as f32,
|
||||||
|
// 0.1,
|
||||||
|
// 1000.0,
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, delta: f32) {
|
||||||
|
self.delta = delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn debug_draw(&mut self, ui: &doppler::imgui::Ui) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_mouse_scroll(&mut self, yoffset: f32) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_mouse_move(&mut self, x: f32, y: f32) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
doppler::engine::Engine::default().run::<Client2D>();
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,7 @@ pub struct ExampleClient {
|
||||||
delta: f32,
|
delta: f32,
|
||||||
show_object_info: bool,
|
show_object_info: bool,
|
||||||
show_camera_info: bool,
|
show_camera_info: bool,
|
||||||
|
imgui_grabs_input: bool,
|
||||||
object_info_id: i32,
|
object_info_id: i32,
|
||||||
show_light_info: bool,
|
show_light_info: bool,
|
||||||
light_info_id: i32,
|
light_info_id: i32,
|
||||||
|
|
@ -26,6 +27,7 @@ impl Default for ExampleClient {
|
||||||
show_camera_info: false,
|
show_camera_info: false,
|
||||||
show_object_info: false,
|
show_object_info: false,
|
||||||
show_light_info: false,
|
show_light_info: false,
|
||||||
|
imgui_grabs_input: false,
|
||||||
light_info_id: 0,
|
light_info_id: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -189,12 +191,21 @@ impl Client for ExampleClient {
|
||||||
self.show_light_info = show_window;
|
self.show_light_info = show_window;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.imgui_grabs_input = ui.is_any_item_hovered() || ui.is_any_item_focused();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_mouse_scroll(&mut self, yoffset: f32) {
|
fn on_mouse_scroll(&mut self, yoffset: f32) {
|
||||||
|
if self.imgui_grabs_input {
|
||||||
|
println!("DD");
|
||||||
|
return;
|
||||||
|
}
|
||||||
self.map.camera.process_mouse_scroll(yoffset as f32);
|
self.map.camera.process_mouse_scroll(yoffset as f32);
|
||||||
}
|
}
|
||||||
fn on_mouse_move(&mut self, x: f32, y: f32) {
|
fn on_mouse_move(&mut self, x: f32, y: f32) {
|
||||||
|
if self.imgui_grabs_input {
|
||||||
|
println!("DD");
|
||||||
|
return;
|
||||||
|
}
|
||||||
self.map.camera.process_mouse_movement(x, y, true);
|
self.map.camera.process_mouse_movement(x, y, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
# Blender MTL File: 'None'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl None
|
||||||
|
Ns 500
|
||||||
|
Ka 0.8 0.8 0.8
|
||||||
|
Kd 0.8 0.8 0.8
|
||||||
|
Ks 0.8 0.8 0.8
|
||||||
|
d 1
|
||||||
|
illum 2
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
# Blender v2.93.4 OBJ File: ''
|
||||||
|
# www.blender.org
|
||||||
|
mtllib plane.mtl
|
||||||
|
o Plane
|
||||||
|
v -1.000000 0.000000 1.000000
|
||||||
|
v 1.000000 0.000000 1.000000
|
||||||
|
v -1.000000 0.000000 -1.000000
|
||||||
|
v 1.000000 0.000000 -1.000000
|
||||||
|
vt 0.999900 0.999900
|
||||||
|
vt 0.000100 0.999900
|
||||||
|
vt 0.000100 0.000100
|
||||||
|
vt 0.999900 0.000100
|
||||||
|
vn 0.0000 1.0000 0.0000
|
||||||
|
usemtl None
|
||||||
|
s off
|
||||||
|
f 1/1/1 2/2/1 4/3/1 3/4/1
|
||||||
|
|
@ -54,28 +54,6 @@ objects:
|
||||||
y: 0.0
|
y: 0.0
|
||||||
z: 0.0
|
z: 0.0
|
||||||
scale: 1.0
|
scale: 1.0
|
||||||
- model_hash: 4360533331876312021
|
|
||||||
transform:
|
|
||||||
position:
|
|
||||||
x: 0.0
|
|
||||||
y: 0.0
|
|
||||||
z: 0.0
|
|
||||||
rotation:
|
|
||||||
x: 0.0
|
|
||||||
y: 0.0
|
|
||||||
z: 0.0
|
|
||||||
scale: 1.0
|
|
||||||
- model_hash: 6024833582843300776
|
|
||||||
transform:
|
|
||||||
position:
|
|
||||||
x: 8.3
|
|
||||||
y: 0.0
|
|
||||||
z: 3.0
|
|
||||||
rotation:
|
|
||||||
x: 0.0
|
|
||||||
y: 120.0
|
|
||||||
z: 0.0
|
|
||||||
scale: 0.025
|
|
||||||
- model_hash: 12474845581084103280
|
- model_hash: 12474845581084103280
|
||||||
transform:
|
transform:
|
||||||
position:
|
position:
|
||||||
|
|
@ -87,6 +65,61 @@ objects:
|
||||||
y: 0.0
|
y: 0.0
|
||||||
z: 0.0
|
z: 0.0
|
||||||
scale: 1.0
|
scale: 1.0
|
||||||
|
- model_hash: 7463349984896526650
|
||||||
|
transform:
|
||||||
|
position:
|
||||||
|
x: 2.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
rotation:
|
||||||
|
x: 0.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
scale: 1.0
|
||||||
|
- model_hash: 13800530402659272349
|
||||||
|
transform:
|
||||||
|
position:
|
||||||
|
x: 44.0
|
||||||
|
y: 0.0
|
||||||
|
z: 33.0
|
||||||
|
rotation:
|
||||||
|
x: 0.0
|
||||||
|
y: 128.0
|
||||||
|
z: 0.0
|
||||||
|
scale: 3.0
|
||||||
|
- model_hash: 10609347989321310959
|
||||||
|
transform:
|
||||||
|
position:
|
||||||
|
x: 55.0
|
||||||
|
y: 0.0
|
||||||
|
z: -28.0
|
||||||
|
rotation:
|
||||||
|
x: 0.0
|
||||||
|
y: -67.0
|
||||||
|
z: 0.0
|
||||||
|
scale: 2.0
|
||||||
|
- model_hash: 14496278726830200225
|
||||||
|
transform:
|
||||||
|
position:
|
||||||
|
x: 39.0
|
||||||
|
y: 0.0
|
||||||
|
z: -39.0
|
||||||
|
rotation:
|
||||||
|
x: -12.0
|
||||||
|
y: 70.0
|
||||||
|
z: 30.0
|
||||||
|
scale: 1.5
|
||||||
|
- model_hash: 448611579693571817
|
||||||
|
transform:
|
||||||
|
position:
|
||||||
|
x: 11.0
|
||||||
|
y: 0.0
|
||||||
|
z: -40.0
|
||||||
|
rotation:
|
||||||
|
x: 0.0
|
||||||
|
y: 0.0
|
||||||
|
z: 0.0
|
||||||
|
scale: 2.0
|
||||||
camera:
|
camera:
|
||||||
position:
|
position:
|
||||||
x: 0.0
|
x: 0.0
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
resources/objects/ground/ground.obj
|
resources/objects/ground/ground.obj
|
||||||
resources/objects/robot/robot.obj
|
resources/objects/robot/robot.obj
|
||||||
resources/objects/grass/grass.obj foliage.png
|
resources/objects/grass/grass.obj foliage.png
|
||||||
resources/objects/gaz_tank/gaz_tank.obj
|
|
||||||
resources/objects/tree/tree_6_d.obj tree_e.png
|
resources/objects/tree/tree_6_d.obj tree_e.png
|
||||||
resources/objects/tree/tree_6_c.obj tree_e.png
|
resources/objects/tree/tree_6_c.obj tree_e.png
|
||||||
resources/objects/tree/tree_6_c.obj tree_e.png
|
resources/objects/tree/tree_6_c.obj tree_e.png
|
||||||
resources/objects/ruins/ruins.obj
|
resources/objects/citypack/policeman.obj
|
||||||
|
resources/objects/sclavinia/wapienne_skaly.obj wapno.png
|
||||||
|
resources/objects/sclavinia/wapienne_skaly_2.obj wapno.png
|
||||||
|
resources/objects/sclavinia/wapienne_skaly_3.obj wapno.png
|
||||||
|
resources/objects/sclavinia/chata_zniszczona_1.obj palev2.png
|
||||||
|
|
@ -5,6 +5,7 @@ use log::{error, info};
|
||||||
use std::collections::hash_map::DefaultHasher;
|
use std::collections::hash_map::DefaultHasher;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct AssetsCache {
|
pub struct AssetsCache {
|
||||||
|
|
@ -13,6 +14,23 @@ pub struct AssetsCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AssetsCache {
|
impl AssetsCache {
|
||||||
|
pub fn load_2d(&mut self, path: &str) -> Model {
|
||||||
|
let fullpath = Path::new(&path);
|
||||||
|
let dir = fullpath
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
let filename = fullpath.file_name().unwrap().to_str().unwrap();
|
||||||
|
let texture = self.get_material_texture(&dir, &filename, "texture_diffuse");
|
||||||
|
let mut model = Model::new_2d( self);
|
||||||
|
for ele in &mut model.meshes {
|
||||||
|
ele.textures.push(texture.clone())
|
||||||
|
}
|
||||||
|
model
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_all_from_file(&mut self, path: &str) {
|
pub fn load_all_from_file(&mut self, path: &str) {
|
||||||
let path = std::path::Path::new(path);
|
let path = std::path::Path::new(path);
|
||||||
let meta = std::fs::metadata(path);
|
let meta = std::fs::metadata(path);
|
||||||
|
|
@ -70,7 +88,7 @@ impl AssetsCache {
|
||||||
fn load_model_ext(&mut self, path: &str, diff_texture: Option<&str>) {
|
fn load_model_ext(&mut self, path: &str, diff_texture: Option<&str>) {
|
||||||
let hash = Self::path_hash(path);
|
let hash = Self::path_hash(path);
|
||||||
info!("Loading model: {}({})", path, hash);
|
info!("Loading model: {}({})", path, hash);
|
||||||
let model = Model::new_ext(path, diff_texture, self);
|
let model = Model::new_ext(path, diff_texture, self, false);
|
||||||
self.models.insert(hash, model);
|
self.models.insert(hash, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::default;
|
||||||
|
|
||||||
#[cfg(feature = "imgui_inspect")]
|
#[cfg(feature = "imgui_inspect")]
|
||||||
use crate::imgui_helper::*;
|
use crate::imgui_helper::*;
|
||||||
use crate::model::Model;
|
use crate::model::Model;
|
||||||
|
|
@ -47,6 +49,16 @@ pub struct ModelComponent {
|
||||||
pub transform: Transform,
|
pub transform: Transform,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ModelComponent {
|
||||||
|
fn default() -> Self {
|
||||||
|
ModelComponent {
|
||||||
|
model: Model::default(),
|
||||||
|
hash: u64::default(),
|
||||||
|
transform: Transform::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ModelComponent {
|
impl ModelComponent {
|
||||||
pub unsafe fn draw(&self, shader: &Shader) {
|
pub unsafe fn draw(&self, shader: &Shader) {
|
||||||
let matrix = self.transform.get_matrix();
|
let matrix = self.transform.get_matrix();
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ impl Default for DirectionalLight {
|
||||||
DirectionalLight {
|
DirectionalLight {
|
||||||
direction: vec3(-0.3, -1.0, -0.3),
|
direction: vec3(-0.3, -1.0, -0.3),
|
||||||
ambient: vec3(0.05, 0.05, 0.05),
|
ambient: vec3(0.05, 0.05, 0.05),
|
||||||
diffuse: vec3(0.4, 0.4, 0.4),
|
diffuse: vec3(0.9, 0.9, 0.8),
|
||||||
specular: vec3(0.5, 0.5, 0.5),
|
specular: vec3(0.5, 0.5, 0.5),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use cgmath::prelude::*;
|
||||||
use cgmath::{Vector2, Vector3};
|
use cgmath::{Vector2, Vector3};
|
||||||
use gl;
|
use gl;
|
||||||
|
|
||||||
|
use crate::assets_cache::AssetsCache;
|
||||||
use crate::shader::Shader;
|
use crate::shader::Shader;
|
||||||
|
|
||||||
// NOTE: without repr(C) the compiler may reorder the fields or use different padding/alignment than C.
|
// NOTE: without repr(C) the compiler may reorder the fields or use different padding/alignment than C.
|
||||||
|
|
@ -90,7 +91,6 @@ impl Mesh {
|
||||||
VBO: 0,
|
VBO: 0,
|
||||||
EBO: 0,
|
EBO: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
// now that we have all the required data, set the vertex buffers and its attribute pointers.
|
// now that we have all the required data, set the vertex buffers and its attribute pointers.
|
||||||
unsafe { mesh.setupMesh() }
|
unsafe { mesh.setupMesh() }
|
||||||
mesh
|
mesh
|
||||||
|
|
|
||||||
105
src/model.rs
105
src/model.rs
|
|
@ -28,8 +28,17 @@ impl Default for Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Model {
|
impl Model {
|
||||||
|
pub fn new_2d(cache: &mut AssetsCache) -> Model {
|
||||||
|
Self::new_ext("resources/defaults/plane.obj", None, cache, true)
|
||||||
|
}
|
||||||
|
|
||||||
/// constructor, expects a filepath to a 3D model.
|
/// constructor, expects a filepath to a 3D model.
|
||||||
pub fn new_ext(path: &str, diff_texture: Option<&str>, cache: &mut AssetsCache) -> Model {
|
pub fn new_ext(
|
||||||
|
path: &str,
|
||||||
|
diff_texture: Option<&str>,
|
||||||
|
cache: &mut AssetsCache,
|
||||||
|
skip_textures: bool,
|
||||||
|
) -> Model {
|
||||||
let pathObj = Path::new(path);
|
let pathObj = Path::new(path);
|
||||||
let mut model = Model {
|
let mut model = Model {
|
||||||
meshes: Vec::<Mesh>::new(),
|
meshes: Vec::<Mesh>::new(),
|
||||||
|
|
@ -43,7 +52,7 @@ impl Model {
|
||||||
};
|
};
|
||||||
|
|
||||||
if pathObj.exists() {
|
if pathObj.exists() {
|
||||||
model.load_model(path, diff_texture, cache);
|
model.load_model(path, diff_texture, cache, skip_textures);
|
||||||
} else {
|
} else {
|
||||||
warn!("{} does not exist, returning empty model", path);
|
warn!("{} does not exist, returning empty model", path);
|
||||||
}
|
}
|
||||||
|
|
@ -52,7 +61,7 @@ impl Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(path: &str, cache: &mut AssetsCache) -> Model {
|
pub fn new(path: &str, cache: &mut AssetsCache) -> Model {
|
||||||
Model::new_ext(path, None, cache)
|
Model::new_ext(path, None, cache, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn Draw(&self, shader: &Shader) {
|
pub fn Draw(&self, shader: &Shader) {
|
||||||
|
|
@ -64,7 +73,13 @@ impl Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
// loads a model from file and stores the resulting meshes in the meshes vector.
|
// loads a model from file and stores the resulting meshes in the meshes vector.
|
||||||
fn load_model(&mut self, path: &str, diffuse_path: Option<&str>, cache: &mut AssetsCache) {
|
fn load_model(
|
||||||
|
&mut self,
|
||||||
|
path: &str,
|
||||||
|
diffuse_path: Option<&str>,
|
||||||
|
cache: &mut AssetsCache,
|
||||||
|
skip_textures: bool,
|
||||||
|
) {
|
||||||
let path = Path::new(path);
|
let path = Path::new(path);
|
||||||
// println!("Started loading model from path: {}", path.display());
|
// println!("Started loading model from path: {}", path.display());
|
||||||
|
|
||||||
|
|
@ -98,47 +113,61 @@ impl Model {
|
||||||
|
|
||||||
// process material
|
// process material
|
||||||
let mut textures = Vec::new();
|
let mut textures = Vec::new();
|
||||||
if let Some(material_id) = mesh.material_id {
|
|
||||||
let material = &materials[material_id];
|
|
||||||
|
|
||||||
// 1. diffuse map
|
if !skip_textures {
|
||||||
if !material.diffuse_texture.is_empty() {
|
if let Some(material_id) = mesh.material_id {
|
||||||
|
let material = &materials[material_id];
|
||||||
|
|
||||||
|
// 1. diffuse map
|
||||||
|
if !material.diffuse_texture.is_empty() {
|
||||||
|
let texture = cache.get_material_texture(
|
||||||
|
&self.directory,
|
||||||
|
&material.diffuse_texture,
|
||||||
|
"texture_diffuse",
|
||||||
|
);
|
||||||
|
textures.push(texture);
|
||||||
|
}
|
||||||
|
// 2. specular map
|
||||||
|
if !material.specular_texture.is_empty() {
|
||||||
|
let texture = cache.get_material_texture(
|
||||||
|
&self.directory,
|
||||||
|
&material.specular_texture,
|
||||||
|
"texture_specular",
|
||||||
|
);
|
||||||
|
textures.push(texture);
|
||||||
|
}
|
||||||
|
// 3. normal map
|
||||||
|
if !material.normal_texture.is_empty() {
|
||||||
|
let texture = cache.get_material_texture(
|
||||||
|
&self.directory,
|
||||||
|
&material.normal_texture,
|
||||||
|
"texture_normal",
|
||||||
|
);
|
||||||
|
textures.push(texture);
|
||||||
|
}
|
||||||
|
// NOTE: no height maps
|
||||||
|
} else if diffuse_path.is_some() {
|
||||||
|
let path = diffuse_path.unwrap();
|
||||||
|
println!("Loading {}", path);
|
||||||
|
let dir: String = if path.contains("/") {
|
||||||
|
Path::new(&path)
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.to_string()
|
||||||
|
} else {
|
||||||
|
self.directory.to_string()
|
||||||
|
};
|
||||||
let texture = cache.get_material_texture(
|
let texture = cache.get_material_texture(
|
||||||
&self.directory,
|
&self.directory,
|
||||||
&material.diffuse_texture,
|
&diffuse_path.unwrap(),
|
||||||
"texture_diffuse",
|
"texture_diffuse",
|
||||||
);
|
);
|
||||||
textures.push(texture);
|
textures.push(texture);
|
||||||
|
} else {
|
||||||
|
warn!("There are no materials for: {}", path.display());
|
||||||
}
|
}
|
||||||
// 2. specular map
|
|
||||||
if !material.specular_texture.is_empty() {
|
|
||||||
let texture = cache.get_material_texture(
|
|
||||||
&self.directory,
|
|
||||||
&material.specular_texture,
|
|
||||||
"texture_specular",
|
|
||||||
);
|
|
||||||
textures.push(texture);
|
|
||||||
}
|
|
||||||
// 3. normal map
|
|
||||||
if !material.normal_texture.is_empty() {
|
|
||||||
let texture = cache.get_material_texture(
|
|
||||||
&self.directory,
|
|
||||||
&material.normal_texture,
|
|
||||||
"texture_normal",
|
|
||||||
);
|
|
||||||
textures.push(texture);
|
|
||||||
}
|
|
||||||
// NOTE: no height maps
|
|
||||||
} else if diffuse_path.is_some() {
|
|
||||||
println!("Loading {}", &diffuse_path.unwrap());
|
|
||||||
let texture = cache.get_material_texture(
|
|
||||||
&self.directory,
|
|
||||||
&diffuse_path.unwrap(),
|
|
||||||
"texture_diffuse",
|
|
||||||
);
|
|
||||||
textures.push(texture);
|
|
||||||
} else {
|
|
||||||
warn!("There are no materials for: {}", path.display());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.meshes.push(Mesh::new(vertices, indices, textures));
|
self.meshes.push(Mesh::new(vertices, indices, textures));
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,13 @@ pub unsafe fn load_texture(path: &str, file_format: &str) -> u32 {
|
||||||
|
|
||||||
pub unsafe fn load_texture_from_dir(filename: &str, directory: &str) -> u32 {
|
pub unsafe fn load_texture_from_dir(filename: &str, directory: &str) -> u32 {
|
||||||
let fullpath = format!("{}/{}", directory, filename);
|
let fullpath = format!("{}/{}", directory, filename);
|
||||||
let dot = filename.find(".").unwrap_or_default() + 1usize;
|
|
||||||
let (_, format) = filename.split_at(dot);
|
load_texture_from_fullpath(&fullpath)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn load_texture_from_fullpath(fullpath: &str) -> u32 {
|
||||||
|
let dot = fullpath.find(".").unwrap_or_default() + 1usize;
|
||||||
|
let (_, format) = fullpath.split_at(dot);
|
||||||
|
|
||||||
load_texture(&fullpath, format)
|
load_texture(&fullpath, format)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue