Merge pull request #53 from makc/patch-1

null reference fix for mesh with isolated vertices
This commit is contained in:
Andrey Kopysov
2013-01-28 11:23:00 -08:00

View File

@@ -243,6 +243,7 @@ package alternativa.engine3d.resources {
var normalsBufferStride:uint = normalsStream.attributes.length*4; var normalsBufferStride:uint = normalsStream.attributes.length*4;
for (i = 0; i < _numVertices; i++) { for (i = 0; i < _numVertices; i++) {
normal = normals[i]; normal = normals[i];
if (normal == null) continue;
normal.normalize(); normal.normalize();
normalsBuffer.position = i*normalsBufferStride + normalsOffset; normalsBuffer.position = i*normalsBufferStride + normalsOffset;
normalsBuffer.writeFloat(normal.x); normalsBuffer.writeFloat(normal.x);
@@ -254,7 +255,7 @@ package alternativa.engine3d.resources {
var resultByteArray:ByteArray = new ByteArray(); var resultByteArray:ByteArray = new ByteArray();
resultByteArray.endian = Endian.LITTLE_ENDIAN; resultByteArray.endian = Endian.LITTLE_ENDIAN;
for (i = 0; i < _numVertices; i++) { for (i = 0; i < _numVertices; i++) {
normal = normals[i]; normal = normals[i] || new Vector3D(0,0,1);
normal.normalize(); normal.normalize();
resultByteArray.writeBytes(positionsData, i*stride, stride); resultByteArray.writeBytes(positionsData, i*stride, stride);
resultByteArray.writeFloat(normal.x); resultByteArray.writeFloat(normal.x);