mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 22:50:19 +00:00
Fix mesh byte generation
This commit is contained in:
parent
d8b183de02
commit
86d0ae6470
4 changed files with 17 additions and 13 deletions
|
@ -62,9 +62,9 @@ pub struct VertexAttribute {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VertexAttribute {
|
impl VertexAttribute {
|
||||||
pub const POSITION: &'static str = "position";
|
pub const POSITION: &'static str = "Vertex_Position";
|
||||||
pub const NORMAL: &'static str = "normal";
|
pub const NORMAL: &'static str = "Vertex_Normal";
|
||||||
pub const UV: &'static str = "uv";
|
pub const UV: &'static str = "Vertex_Uv";
|
||||||
|
|
||||||
pub fn position(positions: Vec<[f32; 3]>) -> Self {
|
pub fn position(positions: Vec<[f32; 3]>) -> Self {
|
||||||
VertexAttribute {
|
VertexAttribute {
|
||||||
|
@ -127,7 +127,7 @@ impl Mesh {
|
||||||
match self
|
match self
|
||||||
.attributes
|
.attributes
|
||||||
.iter()
|
.iter()
|
||||||
.find(|a| VertexFormat::from(&a.values) == vertex_attribute.format)
|
.find(|a| vertex_attribute.name == a.name)
|
||||||
{
|
{
|
||||||
Some(mesh_attribute) => {
|
Some(mesh_attribute) => {
|
||||||
let attribute_bytes = mesh_attribute.values.get_bytes();
|
let attribute_bytes = mesh_attribute.values.get_bytes();
|
||||||
|
@ -321,8 +321,12 @@ pub fn mesh_batcher_system() -> Box<dyn Schedulable> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(tests)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::{Vertex, pipeline::state_descriptors::PrimitiveTopology, shader::AsUniforms};
|
||||||
|
use super::{Mesh, VertexAttribute};
|
||||||
|
use zerocopy::AsBytes;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_vertex_bytes() {
|
fn test_get_vertex_bytes() {
|
||||||
let vertices = &[
|
let vertices = &[
|
||||||
|
@ -335,9 +339,9 @@ mod tests {
|
||||||
let mut normals = Vec::new();
|
let mut normals = Vec::new();
|
||||||
let mut uvs = Vec::new();
|
let mut uvs = Vec::new();
|
||||||
for (position, normal, uv) in vertices.iter() {
|
for (position, normal, uv) in vertices.iter() {
|
||||||
positions.push(position.clone());
|
positions.push(*position);
|
||||||
normals.push(normal.clone());
|
normals.push(*normal);
|
||||||
uvs.push(uv.clone());
|
uvs.push(*uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mesh = Mesh {
|
let mesh = Mesh {
|
||||||
|
@ -368,8 +372,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let descriptor = Vertex::get_vertex_buffer_descriptor();
|
let descriptor = Vertex::get_vertex_buffer_descriptor().unwrap();
|
||||||
|
assert_eq!(mesh.get_vertex_buffer_bytes(descriptor).unwrap(), expected_vertices.as_bytes(), "buffer bytes are equal");
|
||||||
assert_eq!(mesh.get_vertex_buffer_bytes(descriptor), expected_vertices.as_bytes(), "buffer bytes are equal");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,5 +53,5 @@ void main() {
|
||||||
}
|
}
|
||||||
// multiply the light by material color
|
// multiply the light by material color
|
||||||
o_Target = vec4(color, 1.0) * albedo;
|
o_Target = vec4(color, 1.0) * albedo;
|
||||||
o_Target = vec4(v_Normal, 1.0);
|
// o_Target = vec4(v_Normal, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ void main() {
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
v_Normal = (Model * vec4(Vertex_Normal, 1.0)).xyz;
|
v_Normal = (Model * vec4(Vertex_Normal, 1.0)).xyz;
|
||||||
|
v_Normal = mat3(Model) * Vertex_Normal;
|
||||||
v_Position = (Model * vec4(Vertex_Position, 1.0)).xyz;
|
v_Position = (Model * vec4(Vertex_Position, 1.0)).xyz;
|
||||||
v_Uv = Vertex_Uv;
|
v_Uv = Vertex_Uv;
|
||||||
gl_Position = ViewProj * vec4(v_Position, 1.0);
|
gl_Position = ViewProj * vec4(v_Position, 1.0);
|
||||||
|
|
|
@ -21,7 +21,7 @@ layout(set = 1, binding = 1) uniform StandardMaterial_albedo {
|
||||||
};
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
v_Normal = (Model * vec4(Vertex_Normal, 1.0)).xyz;
|
v_Normal = mat3(Model) * Vertex_Normal;
|
||||||
v_Position = (Model * vec4(Vertex_Position, 1.0)).xyz;
|
v_Position = (Model * vec4(Vertex_Position, 1.0)).xyz;
|
||||||
gl_Position = ViewProj * v_Position;
|
gl_Position = ViewProj * v_Position;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue