Skip to content

Instantly share code, notes, and snippets.

@cabbibo
Created September 22, 2016 22:59
Show Gist options
  • Save cabbibo/4c1d0726aa4f884065219c867ad345ff to your computer and use it in GitHub Desktop.
Save cabbibo/4c1d0726aa4f884065219c867ad345ff to your computer and use it in GitHub Desktop.
void createVertBuffer(){
_vertBuffer = new ComputeBuffer( triangles.Length , AnchorStructSize * sizeof(float) );
//print( AnchorStructSize );
//print( AnchorStructSize * vc );
float[] inValues = new float[ AnchorStructSize * triangles.Length ];
// Used for assigning to our buffer;
int index = 0;
for (int i = 0; i < triangles.Length/12; i++) {
for( int j = 0; j < 6; j++ ){
int totalID = i * 6 + j;
//float baseTri = Mathf.Floor((float)i / 12);
//int idInTri = i % 3;
//int whichTri = (int)(Mathf.Floor((float)(i % 6)/3));
//int baseID = (int)(baseTri * 12);
int id = triangles[i * 12 + j ];
Vector3 position = transform.TransformPoint(positions[ id ]);
Vector3 normal = transform.TransformDirection(normals[ id ]);
Vector4 tangent = transform.TransformDirection(tangents[ id ]);
Vector3 color = ToV3( Color.white );
if( colors.Length > 0 ){ color = ToV3(colors[id]); }
Vector2 uv = uvs[ id ];
inValues[index++] = position.x;
inValues[index++] = position.y;
inValues[index++] = position.z;
inValues[index++] = normal.x;
inValues[index++] = normal.y;
inValues[index++] = normal.z;
inValues[index++] = tangent.x;
inValues[index++] = tangent.y;
inValues[index++] = tangent.z;
inValues[index++] = color.x;
inValues[index++] = color.y;
inValues[index++] = color.z;
inValues[index++] = uv.x;
inValues[index++] = uv.y;
inValues[index++] = totalID;
inValues[index++] = (float)j % 3;
}
}
_vertBuffer.SetData(inValues);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment