private void processVertexBufferPositionsSoftwareSkinned(m3g.VertexBuffer vb) { if (vb.skinVertexDataTransformed == null) { vb.setSkinTransformed(); } int vertexCount = vb.getVertexCount(); Vertex[] vertexDataTransformed = vb.skinVertexDataTransformed; Vertex[] finalVertexData = vb.finalVertexData; for (int index1 = 0; index1 < vertexCount; ++index1) { vertexDataTransformed[index1].position.X = 0.0f; vertexDataTransformed[index1].position.Y = 0.0f; vertexDataTransformed[index1].position.Z = 0.0f; if ((double)vertexDataTransformed[index1].skinWeight.X != 0.0) { int index2 = (int)vertexDataTransformed[index1].skinIndex.X & (int)byte.MaxValue; this.Transform(ref finalVertexData[index1].position, ref this.m_matrixPalette[index2], ref this.tempOutVector); vertexDataTransformed[index1].position.X += vertexDataTransformed[index1].skinWeight.X * this.tempOutVector.X; vertexDataTransformed[index1].position.Y += vertexDataTransformed[index1].skinWeight.X * this.tempOutVector.Y; vertexDataTransformed[index1].position.Z += vertexDataTransformed[index1].skinWeight.X * this.tempOutVector.Z; } if ((double)vertexDataTransformed[index1].skinWeight.Y != 0.0) { int index2 = (int)vertexDataTransformed[index1].skinIndex.Y & (int)byte.MaxValue; this.Transform(ref finalVertexData[index1].position, ref this.m_matrixPalette[index2], ref this.tempOutVector); vertexDataTransformed[index1].position.X += vertexDataTransformed[index1].skinWeight.Y * this.tempOutVector.X; vertexDataTransformed[index1].position.Y += vertexDataTransformed[index1].skinWeight.Y * this.tempOutVector.Y; vertexDataTransformed[index1].position.Z += vertexDataTransformed[index1].skinWeight.Y * this.tempOutVector.Z; } if ((double)vertexDataTransformed[index1].skinWeight.Z != 0.0) { int index2 = (int)vertexDataTransformed[index1].skinIndex.Z & (int)byte.MaxValue; this.Transform(ref finalVertexData[index1].position, ref this.m_matrixPalette[index2], ref this.tempOutVector); vertexDataTransformed[index1].position.X += vertexDataTransformed[index1].skinWeight.Z * this.tempOutVector.X; vertexDataTransformed[index1].position.Y += vertexDataTransformed[index1].skinWeight.Z * this.tempOutVector.Y; vertexDataTransformed[index1].position.Z += vertexDataTransformed[index1].skinWeight.Z * this.tempOutVector.Z; } if ((double)vertexDataTransformed[index1].skinWeight.W != 0.0) { int index2 = (int)vertexDataTransformed[index1].skinIndex.W & (int)byte.MaxValue; this.Transform(ref finalVertexData[index1].position, ref this.m_matrixPalette[index2], ref this.tempOutVector); vertexDataTransformed[index1].position.X += vertexDataTransformed[index1].skinWeight.W * this.tempOutVector.X; vertexDataTransformed[index1].position.Y += vertexDataTransformed[index1].skinWeight.W * this.tempOutVector.Y; vertexDataTransformed[index1].position.Z += vertexDataTransformed[index1].skinWeight.W * this.tempOutVector.Z; } } }
private void renderIndexBuffer( m3g.IndexBuffer primitives, m3g.VertexBuffer vertices, float alphaFactor) { ushort[] stripLengths = primitives.getStripLengths(); short[] explicitIndices = primitives.getExplicitIndices(); bool flag1 = primitives.isStripped(); bool flag2 = primitives.isImplicit(); int primitiveType1 = primitives.getPrimitiveType(); PrimitiveType primitiveType2 = PrimitiveType.TriangleStrip; Vertex[] finalVertices = vertices.getFinalVertices(); Effect effect; if (this.alphaTest) { effect = (Effect)this.alphaTestEffect; this.alphaTestEffect.View = this.viewMat; this.alphaTestEffect.Projection = this.projMat; this.alphaTestEffect.World = this.worldMat; int defaultColor = vertices.getDefaultColor(); this.alphaTestEffect.DiffuseColor = vertices.getXnaDiffuse(); this.alphaTestEffect.Alpha = (float)(defaultColor >> 24 & (int)byte.MaxValue) / (float)byte.MaxValue * alphaFactor; this.alphaTestEffect.VertexColorEnabled = vertices.getColors() != null; } else { effect = (Effect)this.basicEffect; this.basicEffect.View = this.viewMat; this.basicEffect.Projection = this.projMat; this.basicEffect.World = this.worldMat; int defaultColor = vertices.getDefaultColor(); this.basicEffect.DiffuseColor = vertices.getXnaDiffuse(); this.basicEffect.Alpha = (float)(defaultColor >> 24 & (int)byte.MaxValue) / (float)byte.MaxValue * alphaFactor; this.basicEffect.VertexColorEnabled = vertices.getColors() != null && !this.basicEffect.TextureEnabled; } for (int index1 = 0; index1 < effect.CurrentTechnique.Passes.Count; ++index1) { effect.CurrentTechnique.Passes[index1].Apply(); switch (primitiveType1) { case 8: primitiveType2 = !flag1 ? PrimitiveType.TriangleList : PrimitiveType.TriangleStrip; break; case 9: primitiveType2 = !flag1 ? PrimitiveType.LineList : PrimitiveType.LineStrip; break; case 10: primitiveType2 = PrimitiveType.TriangleStrip; if (!flag1) { break; } break; } if (flag1) { int length = stripLengths.Length; ushort[] numArray = stripLengths; if (!flag2) { short[] indexData = explicitIndices; int indexOffset = 0; for (int index2 = 0; index2 < length; ++index2) { int num = (int)numArray[index2]; int primitiveCount = 1 + (num - 3); this.device.DrawUserIndexedPrimitives <Vertex>(primitiveType2, finalVertices, 0, vertices.getVertexCount(), indexData, indexOffset, primitiveCount); indexOffset += num; } } else { int firstIndex = primitives.getFirstIndex(); for (int index2 = 0; index2 < length; ++index2) { int num = (int)numArray[index2]; int primitiveCount = 1 + (num - 3); this.device.DrawUserPrimitives <Vertex>(primitiveType2, finalVertices, firstIndex, primitiveCount); firstIndex += num; } } } else { int primitiveCount = primitives.getPrimitiveCount(); if (!flag2) { short[] indexData = explicitIndices; this.device.DrawUserIndexedPrimitives <Vertex>(primitiveType2, finalVertices, 0, vertices.getVertexCount(), indexData, 0, primitiveCount); } else { int firstIndex = primitives.getFirstIndex(); this.device.DrawUserPrimitives <Vertex>(primitiveType2, finalVertices, firstIndex, primitiveCount); } } } }
public override void render( m3g.VertexBuffer vertices, VertexArray skinIndices, VertexArray skinWeights, Matrix[] matrixPalette, m3g.IndexBuffer primitives, AppearanceBase appearance, float alphaFactor) { this.m_matrixPalette = matrixPalette; this.processVertexBufferPositionsSoftwareSkinned(vertices); if (appearance != this.m_cachedAppearance) { this.processApperance((Appearance)appearance); this.m_cachedAppearance = appearance; } ushort[] stripLengths = primitives.getStripLengths(); short[] explicitIndices = primitives.getExplicitIndices(); bool flag1 = primitives.isStripped(); bool flag2 = primitives.isImplicit(); int primitiveType1 = primitives.getPrimitiveType(); PrimitiveType primitiveType2 = PrimitiveType.TriangleStrip; Vertex[] vertexDataTransformed = vertices.skinVertexDataTransformed; Effect effect; if (this.alphaTest) { effect = (Effect)this.alphaTestEffect; this.alphaTestEffect.View = this.viewMat; this.alphaTestEffect.Projection = this.projMat; this.alphaTestEffect.World = this.worldMat; int defaultColor = vertices.getDefaultColor(); this.alphaTestEffect.DiffuseColor = vertices.getXnaDiffuse(); this.alphaTestEffect.Alpha = (float)(defaultColor >> 24 & (int)byte.MaxValue) / (float)byte.MaxValue * alphaFactor; this.alphaTestEffect.VertexColorEnabled = vertices.getColors() != null; } else { effect = (Effect)this.basicEffect; this.basicEffect.View = this.viewMat; this.basicEffect.Projection = this.projMat; this.basicEffect.World = this.worldMat; int defaultColor = vertices.getDefaultColor(); this.basicEffect.DiffuseColor = vertices.getXnaDiffuse(); this.basicEffect.Alpha = (float)(defaultColor >> 24 & (int)byte.MaxValue) / (float)byte.MaxValue * alphaFactor; this.basicEffect.VertexColorEnabled = vertices.getColors() != null && !this.basicEffect.TextureEnabled; } for (int index1 = 0; index1 < effect.CurrentTechnique.Passes.Count; ++index1) { effect.CurrentTechnique.Passes[index1].Apply(); switch (primitiveType1) { case 8: primitiveType2 = !flag1 ? PrimitiveType.TriangleList : PrimitiveType.TriangleStrip; break; case 9: primitiveType2 = !flag1 ? PrimitiveType.LineList : PrimitiveType.LineStrip; break; case 10: primitiveType2 = PrimitiveType.TriangleStrip; if (!flag1) { break; } break; } if (flag1) { int length = stripLengths.Length; ushort[] numArray = stripLengths; if (!flag2) { short[] indexData = explicitIndices; int indexOffset = 0; for (int index2 = 0; index2 < length; ++index2) { int num = (int)numArray[index2]; int primitiveCount = 1 + (num - 3); this.device.DrawUserIndexedPrimitives <Vertex>(primitiveType2, vertexDataTransformed, 0, vertices.getVertexCount(), indexData, indexOffset, primitiveCount); indexOffset += num; } } else { int firstIndex = primitives.getFirstIndex(); for (int index2 = 0; index2 < length; ++index2) { int num = (int)numArray[index2]; int primitiveCount = 1 + (num - 3); this.device.DrawUserPrimitives <Vertex>(primitiveType2, vertexDataTransformed, firstIndex, primitiveCount); firstIndex += num; } } } else { int primitiveCount = primitives.getPrimitiveCount(); if (!flag2) { short[] indexData = explicitIndices; this.device.DrawUserIndexedPrimitives <Vertex>(primitiveType2, vertexDataTransformed, 0, vertices.getVertexCount(), indexData, 0, primitiveCount); } else { int firstIndex = primitives.getFirstIndex(); this.device.DrawUserPrimitives <Vertex>(primitiveType2, vertexDataTransformed, firstIndex, primitiveCount); } } } }