helix-toolkit/helix-toolkit — pull request #54 by dermeister0 (2014-09-13 07:14:09+00:00)
Title: HelixToolkit.Wpf.SharpDX: Fix IndexOutOfRange exception in CreateDefaultVertexArray.

I loaded 2 test models using OBJ reader. These arrays had different length for me:

private DefaultVertex[] CreateDefaultVertexArray()
{
// ...

var normals = geometry.Normals != null ? geometry.Normals.Array : null;
var tangents = geometry.Tangents != null ? geometry.Tangents.Array : null;
var bitangents = geometry.BiTangents != null ? geometry.BiTangents.Array : null;
var positions = geometry.Positions.Array;

**Model 1**
positions: 8192
normals, tangents, bitangents: 5034

**Model 2**
positions: 32768
normals, tangents, bitangents: 32094

That's why original code produces an exception here:

Normal = normals != null ? normals[i] : Vector3.Zero,
Tangent = tangents != null ? tangents[i] : Vector3.Zero,
BiTangent = bitangents != null ? bitangents[i] : Vector3.Zero,

I just created a work-around. Probably somebody knows a correct solution.