@@ -8,7 +8,7 @@ use bevy::{
88
99use crate :: error:: { ProcessingError , Result } ;
1010
11- use super :: { hash_attr_name , Geometry } ;
11+ use super :: { Geometry , hash_attr_name } ;
1212
1313fn clamp_range ( range : Range < usize > , len : usize ) -> Range < usize > {
1414 range. start . min ( len) ..range. end . min ( len)
@@ -168,7 +168,11 @@ impl Attribute {
168168 let name: & ' static str = Box :: leak ( name. into ( ) . into_boxed_str ( ) ) ;
169169 let id = hash_attr_name ( name) ;
170170 let inner = MeshVertexAttribute :: new ( name, id, format. to_vertex_format ( ) ) ;
171- Self { name, format, inner }
171+ Self {
172+ name,
173+ format,
174+ inner,
175+ }
172176 }
173177
174178 pub fn from_builtin ( inner : MeshVertexAttribute , format : AttributeFormat ) -> Self {
@@ -195,31 +199,50 @@ pub struct BuiltinAttributes {
195199impl FromWorld for BuiltinAttributes {
196200 fn from_world ( world : & mut World ) -> Self {
197201 let position = world
198- . spawn ( Attribute :: from_builtin ( Mesh :: ATTRIBUTE_POSITION , AttributeFormat :: Float3 ) )
202+ . spawn ( Attribute :: from_builtin (
203+ Mesh :: ATTRIBUTE_POSITION ,
204+ AttributeFormat :: Float3 ,
205+ ) )
199206 . id ( ) ;
200207 let normal = world
201- . spawn ( Attribute :: from_builtin ( Mesh :: ATTRIBUTE_NORMAL , AttributeFormat :: Float3 ) )
208+ . spawn ( Attribute :: from_builtin (
209+ Mesh :: ATTRIBUTE_NORMAL ,
210+ AttributeFormat :: Float3 ,
211+ ) )
202212 . id ( ) ;
203213 let color = world
204- . spawn ( Attribute :: from_builtin ( Mesh :: ATTRIBUTE_COLOR , AttributeFormat :: Float4 ) )
214+ . spawn ( Attribute :: from_builtin (
215+ Mesh :: ATTRIBUTE_COLOR ,
216+ AttributeFormat :: Float4 ,
217+ ) )
205218 . id ( ) ;
206219 let uv = world
207- . spawn ( Attribute :: from_builtin ( Mesh :: ATTRIBUTE_UV_0 , AttributeFormat :: Float2 ) )
220+ . spawn ( Attribute :: from_builtin (
221+ Mesh :: ATTRIBUTE_UV_0 ,
222+ AttributeFormat :: Float2 ,
223+ ) )
208224 . id ( ) ;
209225
210- Self { position, normal, color, uv }
226+ Self {
227+ position,
228+ normal,
229+ color,
230+ uv,
231+ }
211232 }
212233}
213234
214- pub fn create_attribute (
235+ pub fn create (
215236 In ( ( name, format) ) : In < ( String , AttributeFormat ) > ,
216237 mut commands : Commands ,
217- ) -> Entity {
218- commands. spawn ( Attribute :: new ( name, format) ) . id ( )
238+ ) -> Result < Entity > {
239+ // TODO: validation?
240+ Ok ( commands. spawn ( Attribute :: new ( name, format) ) . id ( ) )
219241}
220242
221- pub fn destroy_attribute ( In ( entity) : In < Entity > , mut commands : Commands ) {
243+ pub fn destroy ( In ( entity) : In < Entity > , mut commands : Commands ) -> Result < ( ) > {
222244 commands. entity ( entity) . despawn ( ) ;
245+ Ok ( ( ) )
223246}
224247
225248pub fn get_attribute (
@@ -277,18 +300,22 @@ pub fn get_attributes(
277300 } ) ?;
278301
279302 match attr {
280- VertexAttributeValues :: Float32 ( v) => {
281- Ok ( v[ clamp_range ( range, v. len ( ) ) ] . iter ( ) . map ( |& x| AttributeValue :: Float ( x) ) . collect ( ) )
282- }
283- VertexAttributeValues :: Float32x2 ( v) => {
284- Ok ( v[ clamp_range ( range, v. len ( ) ) ] . iter ( ) . map ( |& x| AttributeValue :: Float2 ( x) ) . collect ( ) )
285- }
286- VertexAttributeValues :: Float32x3 ( v) => {
287- Ok ( v[ clamp_range ( range, v. len ( ) ) ] . iter ( ) . map ( |& x| AttributeValue :: Float3 ( x) ) . collect ( ) )
288- }
289- VertexAttributeValues :: Float32x4 ( v) => {
290- Ok ( v[ clamp_range ( range, v. len ( ) ) ] . iter ( ) . map ( |& x| AttributeValue :: Float4 ( x) ) . collect ( ) )
291- }
303+ VertexAttributeValues :: Float32 ( v) => Ok ( v[ clamp_range ( range, v. len ( ) ) ]
304+ . iter ( )
305+ . map ( |& x| AttributeValue :: Float ( x) )
306+ . collect ( ) ) ,
307+ VertexAttributeValues :: Float32x2 ( v) => Ok ( v[ clamp_range ( range, v. len ( ) ) ]
308+ . iter ( )
309+ . map ( |& x| AttributeValue :: Float2 ( x) )
310+ . collect ( ) ) ,
311+ VertexAttributeValues :: Float32x3 ( v) => Ok ( v[ clamp_range ( range, v. len ( ) ) ]
312+ . iter ( )
313+ . map ( |& x| AttributeValue :: Float3 ( x) )
314+ . collect ( ) ) ,
315+ VertexAttributeValues :: Float32x4 ( v) => Ok ( v[ clamp_range ( range, v. len ( ) ) ]
316+ . iter ( )
317+ . map ( |& x| AttributeValue :: Float4 ( x) )
318+ . collect ( ) ) ,
292319 _ => Err ( ProcessingError :: InvalidArgument (
293320 "Unsupported attribute format" . into ( ) ,
294321 ) ) ,
@@ -346,9 +373,7 @@ pub fn set_attribute(
346373 }
347374}
348375
349- pub fn to_attribute_values (
350- values : & [ AttributeValue ] ,
351- ) -> Option < VertexAttributeValues > {
376+ pub fn to_attribute_values ( values : & [ AttributeValue ] ) -> Option < VertexAttributeValues > {
352377 macro_rules! convert {
353378 ( $variant: ident, $bevy: ident, $default: expr) => {
354379 Some ( VertexAttributeValues :: $bevy(
0 commit comments