static Material BuildMaterial(byte[] bytes, int startIndex) { Material mat = new Material(); byte matType = bytes[startIndex]; mat.Type = matType; if (matType == (byte)MaterialType.MaterialColor) { MaterialColor mColor = new MaterialColor(); mColor.Red = bytes[startIndex + 1]; mColor.Green = bytes[startIndex + 2]; mColor.Blue = bytes[startIndex + 3]; mat.Data = mColor; } else if (matType == (byte)MaterialType.MaterialTextureMap) { MaterialTextureMap mTexMap = new MaterialTextureMap(); mTexMap.Bpp = bytes[startIndex + 1]; mTexMap.Width = BitConverter.ToInt16(bytes, startIndex + 2); mTexMap.Height = BitConverter.ToInt16(bytes, startIndex + 4); mTexMap.Size = BitConverter.ToInt32(bytes, startIndex + 6); mTexMap.TCType = BitConverter.ToInt32(bytes, startIndex + 10); mTexMap.TexBuff = BuildBytes(bytes, startIndex + 14, mTexMap.Size); mat.Data = mTexMap; } else if (matType == (byte)MaterialType.MaterialTransparency) { MaterialTransparency mTrans = new MaterialTransparency(); mTrans.Transparency = bytes[startIndex + 1]; mat.Data = mTrans; } else if (matType == (byte)MaterialType.MaterialShininess) { MaterialShininess mShin = new MaterialShininess(); mShin.Shininess = bytes[startIndex + 1]; mat.Data = mShin; } else if (matType == (byte)MaterialType.MaterialSharedTexture) { MaterialSharedTexture mSharedTex = new MaterialSharedTexture(); mSharedTex.MaterialIndex = BitConverter.ToInt32(bytes, startIndex + 1); mat.Data = mSharedTex; } else if (matType == (byte)MaterialType.MaterialCullBackFaces) { MaterialCullBackFaces mCullBackFaces = new MaterialCullBackFaces(); mat.Data = mCullBackFaces; } else if (matType == (byte)MaterialType.MaterialEdgeColor) { MaterialEdgeColor mEdgeColor = new MaterialEdgeColor(); mEdgeColor.Red = bytes[startIndex + 1]; mEdgeColor.Green = bytes[startIndex + 2]; mEdgeColor.Blue = bytes[startIndex + 3]; mat.Data = mEdgeColor; } else if (matType == (byte)MaterialType.MaterialEdgeWidth) { MaterialEdgeWidth mEdgeWidth = new MaterialEdgeWidth(); mEdgeWidth.Width = bytes[startIndex + 1]; mat.Data = mEdgeWidth; } else if (matType == (byte)MaterialType.MaterialLast) { } return(mat); }
static Material BuildMaterial(byte[] bytes, int startIndex) { Material mat = new Material(); byte matType = bytes[startIndex]; mat.Type = matType; if (matType == (byte)MaterialType.MaterialColor) { MaterialColor mColor = new MaterialColor(); mColor.Red = bytes[startIndex + 1]; mColor.Green = bytes[startIndex + 2]; mColor.Blue = bytes[startIndex + 3]; mat.Data = mColor; } else if (matType == (byte)MaterialType.MaterialTextureMap) { MaterialTextureMap mTexMap = new MaterialTextureMap(); mTexMap.Bpp = bytes[startIndex + 1]; mTexMap.Width = BitConverter.ToInt16(bytes, startIndex + 2); mTexMap.Height = BitConverter.ToInt16(bytes, startIndex + 4); mTexMap.Size = BitConverter.ToInt32(bytes, startIndex + 6); mTexMap.TCType = BitConverter.ToInt32(bytes, startIndex + 10); mTexMap.TexBuff = BuildBytes(bytes, startIndex + 14, mTexMap.Size); mat.Data = mTexMap; } else if (matType == (byte)MaterialType.MaterialTransparency) { MaterialTransparency mTrans = new MaterialTransparency(); mTrans.Transparency = bytes[startIndex + 1]; mat.Data = mTrans; } else if (matType == (byte)MaterialType.MaterialShininess) { MaterialShininess mShin = new MaterialShininess(); mShin.Shininess = bytes[startIndex + 1]; mat.Data = mShin; } else if (matType == (byte)MaterialType.MaterialSharedTexture) { MaterialSharedTexture mSharedTex = new MaterialSharedTexture(); mSharedTex.MaterialIndex = BitConverter.ToInt32(bytes, startIndex + 1); mat.Data = mSharedTex; } else if (matType == (byte)MaterialType.MaterialCullBackFaces) { MaterialCullBackFaces mCullBackFaces = new MaterialCullBackFaces(); mat.Data = mCullBackFaces; } else if (matType == (byte)MaterialType.MaterialEdgeColor) { MaterialEdgeColor mEdgeColor = new MaterialEdgeColor(); mEdgeColor.Red = bytes[startIndex + 1]; mEdgeColor.Green = bytes[startIndex + 2]; mEdgeColor.Blue = bytes[startIndex + 3]; mat.Data = mEdgeColor; } else if (matType == (byte)MaterialType.MaterialEdgeWidth) { MaterialEdgeWidth mEdgeWidth = new MaterialEdgeWidth(); mEdgeWidth.Width = bytes[startIndex + 1]; mat.Data = mEdgeWidth; } else if (matType == (byte)MaterialType.MaterialLast) { } return mat; }