1
1
part of ldraw;
2
2
3
3
abstract class Drawable3D {
4
- void setColor ( double r, double g, double b, double alpha );
4
+ void setColor ( int r, int g, int b, int alpha );
5
5
void draw_triangles ( Float32List vertices, int amount );
6
6
void draw_lines ( Float32List vertices, int amount );
7
7
}
@@ -79,7 +79,7 @@ class DynamicFloat32List{
79
79
}
80
80
81
81
class MeshColor {
82
- double r,g,b,a;
82
+ int r,g,b,a;
83
83
MeshColor ( this .r, this .g, this .b, this .a );
84
84
void draw ( Drawable3D canvas ) => canvas.setColor ( r, g, b, a );
85
85
@@ -88,10 +88,10 @@ class MeshColor{
88
88
}
89
89
int get hashCode{
90
90
int result = 17 ;
91
- result = 37 * result + (r * 255 ). toInt () ;
92
- result = 37 * result + (g * 255 ). toInt () ;
93
- result = 37 * result + (b * 255 ). toInt () ;
94
- result = 37 * result + (a * 255 ). toInt () ;
91
+ result = 37 * result + r ;
92
+ result = 37 * result + g ;
93
+ result = 37 * result + b ;
94
+ result = 37 * result + a ;
95
95
return result;
96
96
}
97
97
}
@@ -178,14 +178,18 @@ class MeshModel{
178
178
return math.min ( min_z, math.min ( min_y, min_x ) );
179
179
}
180
180
181
- void add_triangle ( Float32List vertices, Matrix4 offset, double r, double g, double b, double a ){
181
+ MeshTriangles last_tri;
182
+ void add_triangle ( Float32List vertices, Matrix4 offset, int r, int g, int b, int a ){
182
183
MeshColor color = new MeshColor ( r, g, b, a );
183
- MeshTriangles tri = triangles.putIfAbsent ( color, () => new MeshTriangles (color) );
184
- tri.vertices.addAll ( vertices, offset );
184
+ if ( last_tri == null || ! (last_tri.color == color) )
185
+ last_tri = triangles.putIfAbsent ( color, () => new MeshTriangles (color) );
186
+ last_tri.vertices.addAll ( vertices, offset );
185
187
}
186
- void add_lines ( Float32List vertices, Matrix4 offset, double r, double g, double b, double a ){
188
+ MeshLines last_line;
189
+ void add_lines ( Float32List vertices, Matrix4 offset, int r, int g, int b, int a ){
187
190
MeshColor color = new MeshColor ( r, g, b, a );
188
- MeshLines line = lines.putIfAbsent ( color, () => new MeshLines (color) );
189
- line.vertices.addAll ( vertices, offset );
191
+ if ( last_line == null || ! (last_line.color == color) )
192
+ last_line = lines.putIfAbsent ( color, () => new MeshLines (color) );
193
+ last_line.vertices.addAll ( vertices, offset );
190
194
}
191
195
}
0 commit comments