tweaking for 2d
This commit is contained in:
@@ -112,3 +112,28 @@ pub fn load_obj(obj_path: &str) -> Result<RawMesh, String> {
|
||||
indices: index_data.to_vec(),
|
||||
})
|
||||
}
|
||||
|
||||
// pub fn create_quad_mesh() -> RawMesh {
|
||||
//
|
||||
// let mut index_data: Vec<[u32; 3]> = Vec::new();
|
||||
// let mut vertex_data = Vec::new();
|
||||
//
|
||||
// vertex_data.push(Vertex::from(
|
||||
// [
|
||||
// mesh.positions[3 * v],
|
||||
// mesh.positions[3 * v + 1],
|
||||
// mesh.positions[3 * v + 2],
|
||||
// ],
|
||||
// [
|
||||
// mesh.normals[3 * v],
|
||||
// mesh.normals[3 * v + 1],
|
||||
// mesh.normals[3 * v + 2],
|
||||
// ],
|
||||
// [mesh.texcoords[2 * v], mesh.texcoords[2 * v + 1]],
|
||||
// ));
|
||||
//
|
||||
// RawMesh {
|
||||
// vertices: vertex_data.to_vec(),
|
||||
// indices: index_data.to_vec(),
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -107,6 +107,10 @@ Todo:
|
||||
Figure out eventing, GameInput, passing all events, etc.
|
||||
+ texturing
|
||||
|
||||
I need to figure out the way that I want to do 2d graphics in a 3d engine...
|
||||
I suppose I will need sprites. And those are just 2 polygons which are textured
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -19,11 +19,13 @@ use rapier3d::pipeline::{ChannelEventCollector, PhysicsPipeline};
|
||||
|
||||
use crate::camera::{Camera, CameraController};
|
||||
use crate::components::{Collider, ImguiWindow, LoopState, Mesh, Physics, Position};
|
||||
use crate::geometry::RawMesh;
|
||||
use crate::geometry;
|
||||
use crate::physics::state::PhysicsState;
|
||||
use crate::render::state::RenderState;
|
||||
use crate::render::system::{ImguiGenericOutputLine, ImguiPerformanceProfilerLine};
|
||||
use crate::runtime::state::RuntimeState;
|
||||
use crate::geometry::create_quad_mesh;
|
||||
use crate::geometry::RawMesh;
|
||||
|
||||
pub fn quad_color(color: [f32; 4]) -> [[f32; 4]; 4] {
|
||||
[color, color, color, color]
|
||||
@@ -126,6 +128,59 @@ pub fn runtime_spawn(
|
||||
) {
|
||||
for entity in &runtime_state.get_entities() {
|
||||
match entity.type_name.as_ref() {
|
||||
"Sprite" => {
|
||||
|
||||
let raw_mesh = create_quad_mesh();
|
||||
|
||||
let mesh_name = entity.mesh.clone().unwrap();
|
||||
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
||||
None => {
|
||||
log::warn!("Skipping entity with invalid mesh file {:?} ", mesh_name);
|
||||
continue;
|
||||
}
|
||||
Some(mesh) => mesh,
|
||||
};
|
||||
|
||||
let position = Position::from(entity.position.clone());
|
||||
|
||||
let mut static_body = RigidBodyBuilder::new_static()
|
||||
.position(Isometry3::new(
|
||||
Vector3::new(position.x, position.y, position.z),
|
||||
Vector::y(),
|
||||
))
|
||||
.build();
|
||||
|
||||
let mesh_collider = ColliderBuilder::trimesh(
|
||||
raw_mesh.vertices.iter().map(|v| v.position()).collect(),
|
||||
raw_mesh.indices.clone(),
|
||||
)
|
||||
.build();
|
||||
|
||||
let gpu_mesh_buffer = renderer
|
||||
.upload_mesh_to_buffer(
|
||||
raw_mesh,
|
||||
Some(wgpu::Color {
|
||||
r: 1.0,
|
||||
g: 0.7,
|
||||
b: 0.3,
|
||||
a: 1.0,
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let entity: Entity = cmd.push((
|
||||
position,
|
||||
gpu_mesh_buffer,
|
||||
Physics {
|
||||
rigid_body: static_body,
|
||||
rigid_body_handle: None,
|
||||
},
|
||||
Collider {
|
||||
collider: mesh_collider,
|
||||
collider_handle: None,
|
||||
},
|
||||
));
|
||||
}
|
||||
"PhysicsEntity" => {
|
||||
let mesh_name = entity.mesh.as_ref().unwrap();
|
||||
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
||||
@@ -178,7 +233,7 @@ pub fn runtime_spawn(
|
||||
ImguiGenericOutputLine::new("wahoo! from a physics entity".to_string()),
|
||||
));
|
||||
}
|
||||
"Terrain" => {
|
||||
"StaticMesh" => {
|
||||
let mesh_name = entity.mesh.clone().unwrap();
|
||||
let raw_mesh = match runtime_state.get_mesh(mesh_name.as_str()) {
|
||||
None => {
|
||||
|
||||
Reference in New Issue
Block a user