-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for custom glTF vertex attributes. (#5370)
# Objective The objective is to be able to load data from "application-specific" (see glTF spec 3.7.2.1.) vertex attribute semantics from glTF files into Bevy meshes. ## Solution Rather than probe the glTF for the specific attributes supported by Bevy, this PR changes the loader to iterate through all the attributes and map them onto `MeshVertexAttribute`s. This mapping includes all the previously supported attributes, plus it is now possible to add mappings using the `add_custom_vertex_attribute()` method on `GltfPlugin`. ## Changelog - Add support for loading custom vertex attributes from glTF files. - Add the `custom_gltf_vertex_attribute.rs` example to illustrate loading custom vertex attributes. ## Migration Guide - If you were instantiating `GltfPlugin` using the unit-like struct syntax, you must instead use `GltfPlugin::default()` as the type is no longer unit-like.
- Loading branch information
Showing
9 changed files
with
561 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"accessors": [ | ||
{ | ||
"bufferView": 0, | ||
"byteOffset": 0, | ||
"count": 4, | ||
"componentType": 5126, | ||
"type": "VEC3", | ||
"min": [ | ||
-1.0, | ||
-1.0, | ||
0.0 | ||
], | ||
"max": [ | ||
1.0, | ||
1.0, | ||
0.0 | ||
] | ||
}, | ||
{ | ||
"bufferView": 0, | ||
"byteOffset": 12, | ||
"count": 4, | ||
"componentType": 5126, | ||
"type": "VEC4" | ||
}, | ||
{ | ||
"bufferView": 0, | ||
"byteOffset": 28, | ||
"count": 4, | ||
"componentType": 5126, | ||
"type": "VEC3" | ||
}, | ||
{ | ||
"bufferView": 1, | ||
"byteOffset": 0, | ||
"count": 6, | ||
"componentType": 5123, | ||
"type": "SCALAR" | ||
} | ||
], | ||
"asset": { | ||
"version": "2.0" | ||
}, | ||
"buffers": [ | ||
{ | ||
"byteLength": 172, | ||
"uri": "data:application/gltf-buffer;base64,AACAvwAAgL8AAAAAAACAPwAAAAAAAAAAAACAPwAAgD8AAAAAAAAAAAAAgD8AAIC/AAAAAAAAAD8AAAA/AAAAAAAAgD8AAAAAAACAPwAAAAAAAIC/AACAPwAAAAAAAAA/AAAAPwAAAAAAAIA/AAAAAAAAAAAAAIA/AACAPwAAgD8AAAAAAAAAAAAAgD8AAAAAAACAPwAAgD8AAAAAAAAAAAAAAQACAAIAAQADAA==" | ||
} | ||
], | ||
"bufferViews": [ | ||
{ | ||
"buffer": 0, | ||
"byteLength": 160, | ||
"byteOffset": 0, | ||
"byteStride": 40, | ||
"target": 34962 | ||
}, | ||
{ | ||
"buffer": 0, | ||
"byteLength": 12, | ||
"byteOffset": 160, | ||
"target": 34962 | ||
} | ||
], | ||
"meshes": [ | ||
{ | ||
"primitives": [ | ||
{ | ||
"attributes": { | ||
"POSITION": 0, | ||
"COLOR_0": 1, | ||
"__BARYCENTRIC": 2 | ||
}, | ||
"indices": 3 | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#import bevy_sprite::mesh2d_view_bindings | ||
#import bevy_sprite::mesh2d_bindings | ||
#import bevy_sprite::mesh2d_functions | ||
|
||
struct Vertex { | ||
@location(0) position: vec3<f32>, | ||
@location(1) color: vec4<f32>, | ||
@location(2) barycentric: vec3<f32>, | ||
}; | ||
|
||
struct VertexOutput { | ||
@builtin(position) clip_position: vec4<f32>, | ||
@location(0) color: vec4<f32>, | ||
@location(1) barycentric: vec3<f32>, | ||
}; | ||
|
||
@vertex | ||
fn vertex(vertex: Vertex) -> VertexOutput { | ||
var out: VertexOutput; | ||
out.clip_position = mesh2d_position_local_to_clip(mesh.model, vec4<f32>(vertex.position, 1.0)); | ||
out.color = vertex.color; | ||
out.barycentric = vertex.barycentric; | ||
return out; | ||
} | ||
|
||
struct FragmentInput { | ||
@location(0) color: vec4<f32>, | ||
@location(1) barycentric: vec3<f32>, | ||
}; | ||
|
||
@fragment | ||
fn fragment(input: FragmentInput) -> @location(0) vec4<f32> { | ||
let d = min(input.barycentric.x, min(input.barycentric.y, input.barycentric.z)); | ||
let t = 0.05 * (0.85 + sin(5.0 * globals.time)); | ||
return mix(vec4(1.0,1.0,1.0,1.0), input.color, smoothstep(t, t+0.01, d)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.