Skip to content

Commit 663ea64

Browse files
committed
added support for binormals (untested)
1 parent a7c73fb commit 663ea64

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

lib/src/mesh.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Mesh extends Node {
1313
Texture texture;
1414
Texture texture2;
1515

16-
Buffer verticesBuffer, colorsBuffer, textureCoordBuffer, normalsBuffer, vertexIndexBuffer;
16+
Buffer verticesBuffer, colorsBuffer, textureCoordBuffer, normalsBuffer, binormalsBuffer, vertexIndexBuffer;
1717

1818
int numItems;
1919

@@ -45,6 +45,12 @@ class Mesh extends Node {
4545
gl.bufferDataTyped(ARRAY_BUFFER, meshData.normals as Float32List, STATIC_DRAW);
4646
}
4747

48+
if( meshData.binormals != null ) {
49+
binormalsBuffer = gl.createBuffer();
50+
gl.bindBuffer(ARRAY_BUFFER, binormalsBuffer);
51+
gl.bufferDataTyped(ARRAY_BUFFER, meshData.binormals as Float32List, STATIC_DRAW);
52+
}
53+
4854
if( meshData.vertexIndices != null ) {
4955
numItems = meshData.vertexIndices.length;
5056
vertexIndexBuffer = gl.createBuffer();
@@ -67,6 +73,9 @@ class Mesh extends Node {
6773
if( normalsBuffer != null ) {
6874
gl.deleteBuffer( normalsBuffer);
6975
}
76+
if( binormalsBuffer != null ) {
77+
gl.deleteBuffer( binormalsBuffer);
78+
}
7079
if( vertexIndexBuffer != null ) {
7180
gl.deleteBuffer( vertexIndexBuffer);
7281
}
@@ -109,6 +118,11 @@ class Mesh extends Node {
109118
gl.vertexAttribPointer(program.normalAttribute, 3, FLOAT, false, 0, 0);
110119
}
111120

121+
if( program.shaderObject.binormalAttribute != null) {
122+
gl.bindBuffer(ARRAY_BUFFER, binormalsBuffer);
123+
gl.vertexAttribPointer(program.binormalAttribute, 3, FLOAT, false, 0, 0);
124+
}
125+
112126
if( program.shaderObject.textureSamplerUniform != null) {
113127
gl.activeTexture(TEXTURE0);
114128
gl.bindTexture(TEXTURE_2D, texture);

lib/src/mesh_data.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@ class MeshData {
55
List<double> vertices;
66
List<double> colors;
77
List<double> normals;
8+
List<double> binormals;
89
List<double> textureCoords;
910
List<int> vertexIndices;
1011
Texture texture;
1112
Texture texture2;
1213

13-
MeshData({this.vertices, this.colors, this.textureCoords, this.normals, this.vertexIndices, this.texture, this.texture2});
14+
MeshData({this.vertices, this.colors, this.textureCoords, this.normals, this.binormals, this.vertexIndices, this.texture, this.texture2});
1415

1516
MeshData.empty() {
1617
vertices = new List<double>();
1718
colors = new List<double>();
1819
textureCoords = new List<double>();
1920
normals = new List<double>();
21+
binormals = new List<double>();
2022
vertexIndices = new List<int>();
2123
}
2224

@@ -29,6 +31,8 @@ class MeshData {
2931

3032
if ( normals != null && !(normals is Float32List)) normals = new Float32List.fromList(normals);
3133

34+
if ( binormals != null && !(binormals is Float32List)) binormals = new Float32List.fromList(binormals);
35+
3236
if (!(vertexIndices is Uint16List)) vertexIndices = new Uint16List.fromList(vertexIndices);
3337
}
3438

lib/src/shader_program.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ShaderObject {
99
String colorsAttribute;
1010
String textureCoordinatesAttribute;
1111
String normalAttribute;
12+
String binormalAttribute;
1213
String transformationMatrixUniform;
1314
String modelViewMatrixUniform;
1415
String perpectiveMatrixUniform;
@@ -34,6 +35,7 @@ class ShaderProgram implements Drawable {
3435
int colorsAttribute;
3536
int textureCoordAttribute;
3637
int normalAttribute;
38+
int binormalAttribute;
3739
UniformLocation pMatrixUniform;
3840
UniformLocation mvMatrixUniform;
3941
UniformLocation samplerUniform;
@@ -69,6 +71,9 @@ class ShaderProgram implements Drawable {
6971
if( shaderObject.normalAttribute != null)
7072
normalAttribute = gl.getAttribLocation(program, shaderObject.normalAttribute);
7173

74+
if( shaderObject.binormalAttribute != null)
75+
binormalAttribute = gl.getAttribLocation(program, shaderObject.binormalAttribute);
76+
7277
pMatrixUniform = getUniformLocation( shaderObject.perpectiveMatrixUniform);
7378
mvMatrixUniform = getUniformLocation( shaderObject.modelViewMatrixUniform);
7479

@@ -160,6 +165,8 @@ class ShaderProgram implements Drawable {
160165
gl.enableVertexAttribArray(textureCoordAttribute);
161166
if( shaderObject.normalAttribute != null)
162167
gl.enableVertexAttribArray(normalAttribute);
168+
if( shaderObject.binormalAttribute != null)
169+
gl.enableVertexAttribArray(binormalAttribute);
163170
//print( "error: ${gl.getError()}" );
164171

165172
//print( "pM: ${pMatrix} ${pMatrixUniform}" );
@@ -201,6 +208,8 @@ class ShaderProgram implements Drawable {
201208
gl.disableVertexAttribArray(textureCoordAttribute);
202209
if( shaderObject.normalAttribute != null)
203210
gl.disableVertexAttribArray(normalAttribute);
211+
if( shaderObject.binormalAttribute != null)
212+
gl.disableVertexAttribArray(binormalAttribute);
204213
}
205214

206215

0 commit comments

Comments
 (0)