File tree Expand file tree Collapse file tree 5 files changed +46
-10
lines changed
Expand file tree Collapse file tree 5 files changed +46
-10
lines changed Original file line number Diff line number Diff line change @@ -21,13 +21,10 @@ class SpatialMaterial extends Material {
2121 'view' ,
2222 'projection' ,
2323 }),
24- UniformSlot .value ('JointMatrices' , {
25- 'joint0' ,
26- 'joint1' ,
27- 'joint2' ,
28- 'joint3' ,
29- 'joint4' ,
30- }),
24+ UniformSlot .value (
25+ 'JointMatrices' ,
26+ List .generate (_maxJoints, (idx) => 'joint$idx ' ).toSet (),
27+ ),
3128 ],
3229 ),
3330 fragmentShader: Shader (
@@ -81,9 +78,9 @@ class SpatialMaterial extends Material {
8178
8279 void _bindJointMatrices (GraphicsDevice device) {
8380 final jointTransforms = device.jointsInfo.jointTransforms;
84- if (jointTransforms.length > 5 ) {
81+ if (jointTransforms.length > _maxJoints ) {
8582 throw Exception (
86- 'At most 5 joints per surface, found ${jointTransforms .length }' ,
83+ 'At most $ _maxJoints joints per surface, found ${jointTransforms .length }' ,
8784 );
8885 }
8986 for (final (idx, transform) in jointTransforms.indexed) {
@@ -113,4 +110,6 @@ class SpatialMaterial extends Material {
113110 static final _library = gpu.ShaderLibrary .fromAsset (
114111 'packages/flame_3d/assets/shaders/spatial_material.shaderbundle' ,
115112 )! ;
113+
114+ static const _maxJoints = 16 ;
116115}
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import 'dart:typed_data';
33
44import 'package:flame_3d/graphics.dart' ;
55import 'package:flame_3d/resources.dart' ;
6+ import 'package:ordered_set/comparing.dart' ;
67
78/// {@template uniform_value}
89/// Instance of a uniform value. Represented by a [ByteBuffer] .
@@ -21,7 +22,9 @@ class UniformValue extends UniformInstance<ByteBuffer> {
2122 if (super .resource == null ) {
2223 var previousIndex = - 1 ;
2324
24- final data = _storage.entries.fold <List <double >>([], (p, e) {
25+ final entries = _storage.entries.toList ()
26+ ..sort (Comparing .on ((c) => c.key));
27+ final data = entries.fold <List <double >>([], (p, e) {
2528 if (previousIndex + 1 != e.key) {
2629 final field =
2730 slot.fields.indexed.firstWhere ((e) => e.$1 == previousIndex + 1 );
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ dependencies:
1818 flutter_gpu :
1919 sdk : flutter
2020 meta : ^1.12.0
21+ ordered_set : ^6.0.1
2122 vector_math : ^2.1.4
2223
2324dev_dependencies :
Original file line number Diff line number Diff line change @@ -24,6 +24,17 @@ uniform JointMatrices {
2424 mat4 joint2;
2525 mat4 joint3;
2626 mat4 joint4;
27+ mat4 joint5;
28+ mat4 joint6;
29+ mat4 joint7;
30+ mat4 joint8;
31+ mat4 joint9;
32+ mat4 joint10;
33+ mat4 joint11;
34+ mat4 joint12;
35+ mat4 joint13;
36+ mat4 joint14;
37+ mat4 joint15;
2738} joints;
2839
2940mat4 jointMat(float jointIndex) {
@@ -37,6 +48,28 @@ mat4 jointMat(float jointIndex) {
3748 return joints.joint3;
3849 } else if (jointIndex == 4.0 ) {
3950 return joints.joint4;
51+ } else if (jointIndex == 5.0 ) {
52+ return joints.joint5;
53+ } else if (jointIndex == 6.0 ) {
54+ return joints.joint6;
55+ } else if (jointIndex == 7.0 ) {
56+ return joints.joint7;
57+ } else if (jointIndex == 8.0 ) {
58+ return joints.joint8;
59+ } else if (jointIndex == 9.0 ) {
60+ return joints.joint9;
61+ } else if (jointIndex == 10.0 ) {
62+ return joints.joint10;
63+ } else if (jointIndex == 11.0 ) {
64+ return joints.joint11;
65+ } else if (jointIndex == 12.0 ) {
66+ return joints.joint12;
67+ } else if (jointIndex == 13.0 ) {
68+ return joints.joint13;
69+ } else if (jointIndex == 14.0 ) {
70+ return joints.joint14;
71+ } else if (jointIndex == 15.0 ) {
72+ return joints.joint15;
4073 } else {
4174 return mat4 (0.0 );
4275 }
You can’t perform that action at this time.
0 commit comments