{
norBytes = subMeshMap.get("Normal").asBinary();
}
// UV texture map
Vector2 texPosMax = Vector2.Zero;
Vector2 texPosMin = Vector2.Zero;
byte[] texBytes = null;
if (subMeshMap.containsKey("TexCoord0"))
{
texBytes = subMeshMap.get("TexCoord0").asBinary();
texPosMax = ((OSDMap)subMeshMap.get("TexCoord0Domain")).get("Max").asVector2();
texPosMin = ((OSDMap)subMeshMap.get("TexCoord0Domain")).get("Min").asVector2();
}
// Extract the vertex position data
// If present normals and texture coordinates too
for (int i = 0; i < posBytes.length; i += 6)
{
int uX = Utils.bytesToUInt16(posBytes, i);
int uY = Utils.bytesToUInt16(posBytes, i + 2);
int uZ = Utils.bytesToUInt16(posBytes, i + 4);
Vertex vx = new Vertex();
vx.Position = new Vector3(
Utils.uint16ToFloat(uX, posMin.X, posMax.X),
Utils.uint16ToFloat(uY, posMin.Y, posMax.Y),
Utils.uint16ToFloat(uZ, posMin.Z, posMax.Z));
if (norBytes != null && norBytes.length >= i + 4)
{
int nX = Utils.bytesToUInt16(norBytes, i);
int nY = Utils.bytesToUInt16(norBytes, i + 2);
int nZ = Utils.bytesToUInt16(norBytes, i + 4);
vx.Normal = new Vector3(
Utils.uint16ToFloat(nX, posMin.X, posMax.X),
Utils.uint16ToFloat(nY, posMin.Y, posMax.Y),
Utils.uint16ToFloat(nZ, posMin.Z, posMax.Z));
}
int vertexIndexOffset = oface.Vertices.size() * 4;
if (texBytes != null && texBytes.length >= vertexIndexOffset + 4)
{
int tX = Utils.bytesToUInt16(texBytes, vertexIndexOffset);
int tY = Utils.bytesToUInt16(texBytes, vertexIndexOffset + 2);
vx.TexCoord = new Vector2(
Utils.uint16ToFloat(tX, texPosMin.X, texPosMax.X),
Utils.uint16ToFloat(tY, texPosMin.Y, texPosMax.Y));
}
oface.Vertices.add(vx);