/// <summary> /// Reads an <see cref="MDXVertex"/> from the data stream. /// </summary> /// <param name="binaryReader">The reader.</param> /// <returns>The value.</returns> public static MDXVertex ReadMDXVertex(this BinaryReader binaryReader) { return(new MDXVertex(binaryReader.ReadBytes(MDXVertex.GetSize()))); }
/// <inheritdoc /> public void Initialize() { ThrowIfDisposed(); if (this.IsInitialized) { return; } this.Shader = this.Cache.GetShader(EverlookShader.GameModel) as GameModelShader; if (this.Shader == null) { throw new ShaderNullException(typeof(GameModelShader)); } this.VertexBuffer = new Buffer <byte>(BufferTarget.ArrayBuffer, BufferUsageHint.StaticDraw) { Data = this.Model.Vertices.Select(v => v.PackForOpenGL()).SelectMany(b => b).ToArray() }; var attributePointers = new[] { // Position new VertexAttributePointer(0, 3, VertexAttribPointerType.Float, MDXVertex.GetSize(), 0), // Bone weights new VertexAttributePointer(1, 4, VertexAttribPointerType.UnsignedByte, MDXVertex.GetSize(), 12), // Bone indexes new VertexAttributePointer(2, 4, VertexAttribPointerType.UnsignedByte, MDXVertex.GetSize(), 16), // Normal new VertexAttributePointer(3, 3, VertexAttribPointerType.Float, MDXVertex.GetSize(), 20), // UV1 new VertexAttributePointer(4, 2, VertexAttribPointerType.Float, MDXVertex.GetSize(), 32), // UV2 new VertexAttributePointer(5, 2, VertexAttribPointerType.Float, MDXVertex.GetSize(), 40) }; this.VertexBuffer.AttachAttributePointers(attributePointers); this.BoundingBox = new RenderableBoundingBox(this.Model.BoundingBox, this.ActorTransform); this.BoundingBox.Initialize(); foreach (MDXTexture texture in this.Model.Textures) { if (!this.TextureLookup.ContainsKey(texture.Filename)) { this.TextureLookup.Add ( texture.Filename, this.Cache.GetTexture(texture, this.GameContext) ); } } foreach (MDXSkin skin in this.Model.Skins) { ushort[] absoluteTriangleVertexIndexes = skin.Triangles.Select(relativeIndex => skin.VertexIndices[relativeIndex]).ToArray(); var skinIndexBuffer = new Buffer <ushort>(BufferTarget.ElementArrayBuffer, BufferUsageHint.StaticDraw) { Data = absoluteTriangleVertexIndexes }; this.SkinIndexArrayBuffers.Add(skin, skinIndexBuffer); if (this.Model.Version <= WarcraftVersion.Wrath) { // In models earlier than Cata, we need to calculate the shader selector value at runtime. foreach (var renderBatch in skin.RenderBatches) { ushort shaderSelector = MDXShaderHelper.GetRuntimeShaderID(renderBatch.ShaderID, renderBatch, this.Model); renderBatch.ShaderID = shaderSelector; } } } // Cache the default display info if (this.CurrentDisplayInfo != null) { CacheDisplayInfo(this.CurrentDisplayInfo); } this.IsInitialized = true; }