/// <summary> /// Fills the vertexUnit with the quad data. /// </summary> /// <param name="vertexUnit">The vertexUnit to fill with the quad data.</param> /// <param name="index">The start index in the index buffer.</param> public override void FillVertexUnit(Purple.Graphics.VertexUnit vertexUnit, int index) { Vector2 a = this.Position; Vector2 right = QuadManager.Instance.RotateUnit(new Vector2(Size.X * this.Scale.X, 0), this.RotationZ); Vector2 down = QuadManager.Instance.RotateUnit(new Vector2(0, Size.Y * this.Scale.Y), this.RotationZ); if (dirty) { PositionStream2 ps = PositionStream2.From(QuadFactory.VertexUnit); ColorStream cs = ColorStream.From(QuadFactory.VertexUnit); TextureStream ts = TextureStream.From(QuadFactory.VertexUnit); RectangleF tc = Texture.TextureCoordinates; for (int y = 0; y < vertices.GetLength(1); y++) { for (int x = 0; x < vertices.GetLength(0); x++) { MeshVertex vertex = vertices[x, y]; Vector2 pos = a + right * vertex.Position.X + down * vertex.Position.Y; ps[index] = new Vector2((pos.X - 0.5f) * 2, -(pos.Y - 0.5f) * 2); cs[index] = Color.SetAlpha(vertex.Color, (int)(Color.GetAlpha(vertex.Color) * Alpha)); Vector2 texture = new Vector2( tc.Left + tc.Width * (TextureRectangle.Left + TextureRectangle.Width * vertex.Texture.X), tc.Top + tc.Height * (TextureRectangle.Top + TextureRectangle.Height * vertex.Texture.Y)); ts[index] = texture; index++; } } dirty = false; } positionCache.CopyTo(vertexUnit[typeof(PositionStream2)].Data, index); colorCache.CopyTo(vertexUnit[typeof(ColorStream)].Data, index); textureCache.CopyTo(vertexUnit[typeof(TextureStream)].Data, index); }
void LoadFontFile(Stream XMLStream, string FontPath, bool LoadFromContentArchive) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(XMLStream); FileManager.Dispose(); FontName = xmlDoc.SelectSingleNode("font/info").Attributes.GetNamedItem("face").Value; FontSize = int.Parse(xmlDoc.SelectSingleNode("font/info").Attributes.GetNamedItem("size").Value); NewLineHeight = int.Parse(xmlDoc.SelectSingleNode("font/common").Attributes.GetNamedItem("lineHeight").Value); #region Load Bitmap textures List <Bitmap> Bitmaps = new List <Bitmap>(); foreach (XmlNode node in xmlDoc.SelectNodes("font/pages/page")) { MemoryStream TextureStream; try { string BitmapPath = node.Attributes.GetNamedItem("file").Value; TextureStream = FileManager.GetFileMemoryStreamFromArchive(FontPath, BitmapPath); if (TextureStream == null) { throw new Exception("Could not find file \"" + FileManager.ContentFolder + FontPath + "/" + BitmapPath + "\""); } } catch (Exception ex) { throw ex; } Bitmaps.Add(new Bitmap(int.Parse(node.Attributes.GetNamedItem("id").Value), Texture2D.FromStream(Graphics.GraphicsDevice, TextureStream))); TextureStream.Dispose(); FileManager.Dispose(); } #endregion #region Load characters data foreach (XmlNode node in xmlDoc.SelectNodes("font/chars/char")) { int ASCII_ID = int.Parse(node.Attributes.GetNamedItem("id").Value); Rectangle SourceRectangle = new Rectangle(int.Parse(node.Attributes.GetNamedItem("x").Value), int.Parse(node.Attributes.GetNamedItem("y").Value), int.Parse(node.Attributes.GetNamedItem("width").Value), int.Parse(node.Attributes.GetNamedItem("height").Value)); Vector2 OffsetPosition = new Vector2(int.Parse(node.Attributes.GetNamedItem("xoffset").Value), int.Parse(node.Attributes.GetNamedItem("yoffset").Value)); int Spacing = int.Parse(node.Attributes.GetNamedItem("xadvance").Value); int TextureID = int.Parse(node.Attributes.GetNamedItem("page").Value); Texture2D BitmapTexture = null; for (int i = 0; i < Bitmaps.Count; i++) { if (TextureID == Bitmaps[i].ID) { BitmapTexture = Bitmaps[i].Texture; } } characterData.Add(new CharacterData(ASCII_ID, BitmapTexture, SourceRectangle, OffsetPosition, Spacing)); } FileManager.Dispose(); #endregion }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// Generates a heightmap from a Bitmap. /// </summary> /// <param name="bmp">The bitmap to use.</param> public Mesh Generate(Bitmap bmp) { VertexUnit vertexUnit = new VertexUnit(VertexFormat.PositionTexture, bmp.Width * bmp.Height); PositionStream positionStream = (PositionStream)vertexUnit[typeof(PositionStream)]; TextureStream textureStream = (TextureStream)vertexUnit[typeof(TextureStream)]; BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); byte[] data = new byte[bitmapData.Stride * bitmapData.Height]; System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, data, 0, data.Length); int quadsX = bmp.Width - 1; int quadsY = bmp.Height - 1; Vector3 scale = new Vector3(0.1f, 0.02f, 0.1f); //Vector3 scale = new Vector3(5.0f, 0.1f, 5.0f); for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { int byteOffset = x * 4 + y * bitmapData.Stride; byte b = data[byteOffset]; byte g = data[byteOffset + 1]; byte r = data[byteOffset + 2]; byte a = data[byteOffset + 3]; Vector3 vec = Vector3.Scale(new Vector3(x - quadsX * 0.5f, r, -y + quadsY * 0.5f), scale); positionStream[x + y * bmp.Width] = vec; Vector2 texVec = new Vector2((float)x / quadsX, (float)y / quadsY); textureStream[x + y * bmp.Width] = texVec; } } bmp.UnlockBits(bitmapData); IndexStream indexStream = IndexStream.Create(quadsX * quadsY * 6, (quadsX + 1) * (quadsY + 1)); int offset = 0; for (int y = 0; y < quadsY; y++) { for (int x = 0; x < quadsX; x++) { indexStream[offset] = (x + y * bmp.Width); indexStream[offset + 1] = (x + 1 + y * bmp.Width); indexStream[offset + 2] = (x + (y + 1) * bmp.Width); indexStream[offset + 3] = (x + 1 + y * bmp.Width); indexStream[offset + 4] = (x + 1 + (y + 1) * bmp.Width); indexStream[offset + 5] = (x + (y + 1) * bmp.Width); offset += 6; } } Mesh mesh = new Mesh(); mesh.SubSets.Add(new SubSet(vertexUnit, indexStream)); return(mesh); }
public Texture2D LoadAsset(string assetFilePath) { if (GraphicsDevice == null) { throw new InvalidOperationException("Please initialize GraphicsDevice first"); } TextureStream.GraphicsDevice = GraphicsDevice; return(TextureStream.Load(assetFilePath)); }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// Updates the particle system. /// </summary> /// <param name="deltaTime">The time since the last update.</param> public override void Update(float deltaTime) { base.Update(deltaTime); Matrix4 m = Device.Instance.Transformations.View; Vector3 right = m.RightVector; Vector3 up = m.UpVector; // update streams PositionStream posStream = (PositionStream)vertexUnit[typeof(PositionStream)]; ColorStream colorStream = (ColorStream)vertexUnit[typeof(ColorStream)]; TextureStream textureStream = (TextureStream)vertexUnit[typeof(TextureStream)]; // Update all particles for (int i = 0; i < particles.Count; i++) { int offset = i * 4; IParticle particle = particles[i] as IParticle; IParticle3d particle3d = particles[i] as IParticle3d; if (particle3d != null) { Vector3 position = particle3d.Position; posStream[offset] = position - particle.Size.X * right + particle.Size.Y * up; posStream[offset + 1] = position + particle.Size.X * right + particle.Size.Y * up; posStream[offset + 2] = position + particle.Size.X * right - particle.Size.Y * up; posStream[offset + 3] = position - particle.Size.X * right - particle.Size.Y * up; } IParticleColor particleColor = particles[i] as IParticleColor; if (particleColor != null) { colorStream[offset] = particleColor.Color; colorStream[offset + 1] = particleColor.Color; colorStream[offset + 2] = particleColor.Color; colorStream[offset + 3] = particleColor.Color; } IParticleIndex particleIndex = particles[i] as IParticleIndex; System.Drawing.RectangleF tc; if (particleIndex == null || subTextures == null) { tc = (Texture as ITexture2d).TextureCoordinates; } else { tc = subTextures[(int)particleIndex.TextureIndex % subTextures.Length].TextureCoordinates; } textureStream[offset] = new Vector2(tc.Left, tc.Top); textureStream[offset + 1] = new Vector2(tc.Right, tc.Top); textureStream[offset + 2] = new Vector2(tc.Right, tc.Bottom); textureStream[offset + 3] = new Vector2(tc.Left, tc.Bottom); } posStream.Upload(); colorStream.Upload(); textureStream.Upload(); }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// Updates the particle system. /// </summary> /// <param name="deltaTime">The time since the last update.</param> public override void Update(float deltaTime) { UpdateAge(deltaTime); // delete dead particles FixedRoundBuffer buffer = particles as FixedRoundBuffer; while (buffer.Count > 0 && !(buffer[0] as IParticle).IsAlive) { buffer.RemoveFirst(); } UpdateParticles(deltaTime); EmitParticles(deltaTime); ITexture2d texture = Texture; if (particles.Count >= 2) { // update streams PositionStream posStream = (PositionStream)vertexUnit[typeof(PositionStream)]; ColorStream colorStream = (ColorStream)vertexUnit[typeof(ColorStream)]; TextureStream textureStream = (TextureStream)vertexUnit[typeof(TextureStream)]; // Update all particles for (int i = 0; i < particles.Count; i++) { int offset = i * 2; IParticle particle = particles[i] as IParticle; IParticle3d particle3d = particles[i] as IParticle3d; if (particle3d != null) { Vector3 position = particle3d.Position; posStream[offset] = position + particle.Size.X * (particle as IParticleOrientation).Orientation; posStream[offset + 1] = position - particle.Size.X * (particle as IParticleOrientation).Orientation; } IParticleColor particleColor = particles[i] as IParticleColor; if (particleColor != null) { colorStream[offset] = particleColor.Color; colorStream[offset + 1] = particleColor.Color; } float tx = texture.TextureCoordinates.Left + texture.TextureCoordinates.Width * particle.Age / particle.LifeTime; textureStream[offset] = new Vector2(tx, texture.TextureCoordinates.Top); textureStream[offset + 1] = new Vector2(tx, texture.TextureCoordinates.Bottom); } posStream.Upload(); colorStream.Upload(); textureStream.Upload(); } }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- private void Bind() { BinormalStream.Bind(); BoneIndicesStream.Bind(); BoneWeightsStream.Bind(); SoftwareBoneIndicesStream.Bind(); SoftwareBoneWeightsStream.Bind(); ColorStream.Bind(); CompressedNormalStream.Bind(); FloatStream.Bind(); IndexStream16.Bind(); IndexStream32.Bind(); IntStream.Bind(); NormalStream.Bind(); PositionStream.Bind(); PositionStream2.Bind(); PositionStream4.Bind(); TangentStream.Bind(); TextureStream.Bind(); }
public override Texture CreateResource(ResourceManager resourceManager) { var frames = GetFrames(FileName, clone: true, out bool video, out PixelInternalFormat? internalFormat); if (!video) { throw new InvalidOperationException(string.Format( "The image sequence path \"{1}\" cannot be used for the video texture \"{0}\".", Name, FileName)); } frames.Reset(); var bufferLength = BufferLength.GetValueOrDefault(1); var sequence = new TextureStream(frames, internalFormat, bufferLength); ConfigureTexture(sequence, frames.Width, frames.Height); GL.BindTexture(TextureTarget.Texture2D, 0); sequence.PlaybackRate = frames.PlaybackRate; return(sequence); }
/// <summary> /// Import a mesh from a stream. /// </summary> /// <param name="stream">Stream containing mesh data.</param> public void Import(Stream stream) { Profiler.Instance.Begin("Import binary mesh"); // Header BinaryReader reader = new BinaryReader(stream); if (ReadString(reader) != "mesh" || ReadString(reader) != "v0.3") { throw new NotSupportedException("Can't load mesh, file not supported!"); } // Joints int jointNum = ReadInt(reader); Joint[] joints = new Joint[jointNum]; Matrix4[] jointArray = new Matrix4[jointNum]; Hashtable jointTable = new Hashtable(joints.Length); for (int i = 0; i < joints.Length; i++) { string name = ReadString(reader); string parent = ReadString(reader); reader.Read(matrixBytes, 0, matrixBytes.Length); Matrix4 m = Matrix4.From(matrixBytes); Joint parentJoint = null; if (parent != null && jointTable.Contains(parent)) { parentJoint = (Joint)jointTable[parent]; } joints[i] = new Joint(name, i, parentJoint); jointArray[i] = m; jointTable[name] = joints[i]; } skeleton = new Skeleton(jointArray, joints); // SubSet int subSetNum = ReadInt(reader); for (int i = 0; i < subSetNum; i++) { ArrayList streams = new ArrayList(10); // Header if (ReadString(reader) != "subset") { throw new NotSupportedException("Error on loading subSet!"); } string name = ReadString(reader); string parentJoint = ReadString(reader); int attributeCount = ReadInt(reader); StringDictionary attributes = new StringDictionary(); for (int t = 0; t < attributeCount; t++) { attributes.Add(ReadString(reader), ReadString(reader)); } // IndexStream // Todo Replace ushort.MaxValue with size of vertex unit IndexStream indexStream = IndexStream.Create(ReadInt(reader), ushort.MaxValue); byte[] indexBuffer = new byte[indexStream.Size * 4]; reader.Read(indexBuffer, 0, indexStream.Size * 4); for (int t = 0; t < indexStream.Size; t++) { indexStream[t] = BitConverter.ToInt32(indexBuffer, t * 4); } int vertexSize = ReadInt(reader); PositionStream posStream = new PositionStream(vertexSize); streams.Add(posStream); byte[] vertexBuffer = new byte[vertexSize * 12]; reader.Read(vertexBuffer, 0, vertexSize * 12); for (int t = 0; t < vertexSize; t++) { posStream[t] = Vector3.From(vertexBuffer, 12 * t); } NormalStream normalStream = new NormalStream(vertexSize); streams.Add(normalStream); reader.Read(vertexBuffer, 0, vertexSize * 12); for (int t = 0; t < vertexSize; t++) { normalStream[t] = Vector3.From(vertexBuffer, t * 12); } ColorStream colorStream = new ColorStream(vertexSize); streams.Add(colorStream); reader.Read(vertexBuffer, 0, vertexSize * 12); for (int t = 0; t < vertexSize; t++) { int r = Math.Basic.Clamp((int)(System.BitConverter.ToSingle(vertexBuffer, t * 12) * 255 + 0.5f), 0, 255); int g = Math.Basic.Clamp((int)(System.BitConverter.ToSingle(vertexBuffer, 4 + t * 12) * 255 + 0.5f), 0, 255); int b = Math.Basic.Clamp((int)(System.BitConverter.ToSingle(vertexBuffer, 8 + t * 12) * 255 + 0.5f), 0, 255); colorStream[t] = System.Drawing.Color.FromArgb(r, g, b).ToArgb(); } TextureStream[] textureStreams = new TextureStream[ReadInt(reader)]; for (int t = 0; t < textureStreams.Length; t++) { TextureStream texStream = new TextureStream(vertexSize); streams.Add(texStream); reader.Read(vertexBuffer, 0, vertexSize * 8); for (int j = 0; j < vertexSize; j++) { texStream[j] = Vector2.From(vertexBuffer, j * 8); } textureStreams[t] = texStream; } IBoneIndicesStream boneStream = null; IBoneWeightsStream weightsStream = null; int weightNum = ReadInt(reader); if (weightNum != 0) { if (HardwareSkinning) { boneStream = new BoneIndicesStream(vertexSize); weightsStream = new BoneWeightsStream(vertexSize); } else { boneStream = new SoftwareBoneIndicesStream(vertexSize); weightsStream = new SoftwareBoneWeightsStream(vertexSize); } streams.Add(boneStream); streams.Add(weightsStream); ArrayList[] indicesList = new ArrayList[vertexSize]; ArrayList[] weightsList = new ArrayList[vertexSize]; for (int t = 0; t < vertexSize; t++) { indicesList[t] = new ArrayList(8); weightsList[t] = new ArrayList(8); } byte[] weightBuffer = new byte[weightNum * 12]; reader.Read(weightBuffer, 0, weightNum * 12); for (int t = 0; t < weightNum; t++) { int vertexIndex = BitConverter.ToInt32(weightBuffer, t * 12); int jointIndex = BitConverter.ToInt32(weightBuffer, 4 + t * 12); float weight = BitConverter.ToSingle(weightBuffer, 8 + t * 12); indicesList[vertexIndex].Add((byte)jointIndex); weightsList[vertexIndex].Add(weight); } for (int t = 0; t < vertexSize; t++) { boneStream.SetIndices(t, (byte[])indicesList[t].ToArray(typeof(byte))); weightsStream.SetWeights(t, (float[])weightsList[t].ToArray(typeof(float))); } } VertexUnit vertexUnit = new VertexUnit(streams); Mesh mesh = new Mesh(new SubSet(vertexUnit, indexStream)); if (model == null) { if (skeleton.Joints.Length != 0) { model = new Model(new SkinnedMesh(mesh, skeleton), skeleton); } else { model = new Model(mesh, skeleton); } } else { Joint attachTo = skeleton.RootJoint; if (parentJoint != "") { attachTo = (jointTable[parentJoint] as Joint); } model.AttachModel(new Model(mesh, skeleton), attachTo); } } reader.Close(); Profiler.Instance.End("Import binary mesh"); }
void LoadStyleFile(Stream ContentStream, string XmlPath, string ComponentNodeNameInXml, bool LoadFromArchive) { XmlDocument xmlDoc = new XmlDocument(); if (LoadFromArchive) { xmlDoc.Load(ContentStream); ContentStream.Dispose(); FileManager.Dispose(); } else { xmlDoc.Load(FileManager.ContentFolder + XmlPath); } if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures") != null) { if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTexture") != null) { NormalComponentTexture = new ComponentTexture(); if (LoadFromArchive) { MemoryStream TextureStream; try { string TexturePath = xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTexture").Attributes.GetNamedItem("Path").Value; TextureStream = FileManager.GetFileMemoryStreamFromArchive(TexturePath); NormalComponentTexture.OriginalTexture = Texture2D.FromStream(Graphics.GraphicsDevice, TextureStream); if (ContentStream == null) { throw new Exception("Could not find file \"" + FileManager.ContentFolder + FileManager.SourceArchiveFileName + "/" + XmlPath + "\""); } else if (TextureStream == null) { throw new Exception("Could not find file \"" + FileManager.ContentFolder + FileManager.SourceArchiveFileName + "/" + TexturePath + "\""); } } catch (Exception ex) { throw ex; } TextureStream.Dispose(); FileManager.Dispose(); } else { NormalComponentTexture.OriginalTexture = StreamTexture.LoadTextureFromStream(Graphics, xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTexture").Attributes.GetNamedItem("Path").Value); } NormalComponentTexture.Color = new Color(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTextureColor").Attributes.GetNamedItem("Red").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTextureColor").Attributes.GetNamedItem("Green").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTextureColor").Attributes.GetNamedItem("Blue").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/NormalTextureColor").Attributes.GetNamedItem("Alpha").Value)); NormalComponentTexture.Initialize(Graphics); } if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTexture") != null) { HoveredComponentTexture = new ComponentTexture(); if (LoadFromArchive) { MemoryStream TextureStream; try { string TexturePath = xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTexture").Attributes.GetNamedItem("Path").Value; TextureStream = FileManager.GetFileMemoryStreamFromArchive(TexturePath); HoveredComponentTexture.OriginalTexture = Texture2D.FromStream(Graphics.GraphicsDevice, TextureStream); if (TextureStream == null) { throw new Exception("Could not find file \"" + FileManager.ContentFolder + FileManager.SourceArchiveFileName + "/" + TexturePath + "\""); } } catch (Exception ex) { throw ex; } TextureStream.Dispose(); FileManager.Dispose(); } else { HoveredComponentTexture.OriginalTexture = StreamTexture.LoadTextureFromStream(Graphics, xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTexture").Attributes.GetNamedItem("Path").Value); } HoveredComponentTexture.Color = new Color(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTextureColor").Attributes.GetNamedItem("Red").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTextureColor").Attributes.GetNamedItem("Green").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTextureColor").Attributes.GetNamedItem("Blue").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/HoveredTextureColor").Attributes.GetNamedItem("Alpha").Value)); HoveredComponentTexture.Initialize(Graphics); } if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTexture") != null) { PressedComponentTexture = new ComponentTexture(); if (LoadFromArchive) { MemoryStream TextureStream; try { string TexturePath = xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTexture").Attributes.GetNamedItem("Path").Value; TextureStream = FileManager.GetFileMemoryStreamFromArchive(TexturePath); PressedComponentTexture.OriginalTexture = Texture2D.FromStream(Graphics.GraphicsDevice, TextureStream); if (TextureStream == null) { throw new Exception("Could not find file \"" + FileManager.ContentFolder + FileManager.SourceArchiveFileName + "/" + TexturePath + "\""); } } catch (Exception ex) { throw ex; } TextureStream.Dispose(); FileManager.Dispose(); } else { PressedComponentTexture.OriginalTexture = StreamTexture.LoadTextureFromStream(Graphics, xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTexture").Attributes.GetNamedItem("Path").Value); } PressedComponentTexture.Color = new Color(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTextureColor").Attributes.GetNamedItem("Red").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTextureColor").Attributes.GetNamedItem("Green").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTextureColor").Attributes.GetNamedItem("Blue").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Textures/PressedTextureColor").Attributes.GetNamedItem("Alpha").Value)); PressedComponentTexture.Initialize(Graphics); } } if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Rendering") != null) { if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Rendering").Attributes.GetNamedItem("Mode").Value == "None Scalable") { if (NormalComponentTexture != null) { NormalComponentTexture.RendererMode = ComponentTexture.RenderMode.NoneScalable; } if (HoveredComponentTexture != null) { HoveredComponentTexture.RendererMode = ComponentTexture.RenderMode.NoneScalable; } if (PressedComponentTexture != null) { PressedComponentTexture.RendererMode = ComponentTexture.RenderMode.NoneScalable; } } else if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Rendering").Attributes.GetNamedItem("Mode").Value == "Scalable") { if (NormalComponentTexture != null) { NormalComponentTexture.RendererMode = ComponentTexture.RenderMode.Scalable; } if (HoveredComponentTexture != null) { HoveredComponentTexture.RendererMode = ComponentTexture.RenderMode.Scalable; } if (PressedComponentTexture != null) { PressedComponentTexture.RendererMode = ComponentTexture.RenderMode.Scalable; } } else if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Rendering").Attributes.GetNamedItem("Mode").Value == "Scalable RealTime") { if (NormalComponentTexture != null) { NormalComponentTexture.RendererMode = ComponentTexture.RenderMode.ScalableRealTime; } if (HoveredComponentTexture != null) { HoveredComponentTexture.RendererMode = ComponentTexture.RenderMode.ScalableRealTime; } if (PressedComponentTexture != null) { PressedComponentTexture.RendererMode = ComponentTexture.RenderMode.ScalableRealTime; } } } if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions") != null) { borderThickness = new BorderThickness(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/BorderThickness").Attributes.GetNamedItem("Top").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/BorderThickness").Attributes.GetNamedItem("Right").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/BorderThickness").Attributes.GetNamedItem("Bottom").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/BorderThickness").Attributes.GetNamedItem("Left").Value)); CornerSize = new Vector2(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/CornerSize").Attributes.GetNamedItem("X").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/CornerSize").Attributes.GetNamedItem("Y").Value)); if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/DefaultSize") != null) { if (Size.X <= 0 || Size.Y <= 0) { DefaultSize = new Vector2(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/DefaultSize").Attributes.GetNamedItem("X").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Dimensions/DefaultSize").Attributes.GetNamedItem("Y").Value)); } } } if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text") != null) { string alignment = ""; // if (LoadFromArchive) //fontRenderer.LoadContentFromArchive(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/Font").Attributes.GetNamedItem("Path").Value); //else fontRenderer.LoadContent(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/Font").Attributes.GetNamedItem("Path").Value); if (xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultText") != null) { if (String.IsNullOrEmpty(Text)) { Text = xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultText").Attributes.GetNamedItem("Value").Value; } } if (TextAlignment == Alignment.Default) { alignment = xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultAlignment").Attributes.GetNamedItem("Value").Value; if (alignment.ToLowerInvariant() == "left") { TextAlignment = Alignment.Left; } if (alignment.ToLowerInvariant() == "center") { TextAlignment = Alignment.Center; } if (alignment.ToLowerInvariant() == "right") { TextAlignment = Alignment.Right; } } TextOffsetPosition = new Vector2(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/OffsetPosition").Attributes.GetNamedItem("X").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/OffsetPosition").Attributes.GetNamedItem("Y").Value)); if (TextColor == null) { TextColor = new Color(int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultTextColor").Attributes.GetNamedItem("Red").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultTextColor").Attributes.GetNamedItem("Green").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultTextColor").Attributes.GetNamedItem("Blue").Value), int.Parse(xmlDoc.SelectSingleNode(ComponentNodeNameInXml + "/Text/DefaultTextColor").Attributes.GetNamedItem("Alpha").Value)); } } }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// Updates the particle system. /// </summary> /// <param name="deltaTime">The time since the last update.</param> public override void Update(float deltaTime) { base.Update(deltaTime); // update streams PositionStream2 posStream = (PositionStream2)vertexUnit[typeof(PositionStream2)]; ColorStream colorStream = (ColorStream)vertexUnit[typeof(ColorStream)]; TextureStream textureStream = (TextureStream)vertexUnit[typeof(TextureStream)]; // Update all particles for (int i = 0; i < particles.Count; i++) { int offset = i * 4; IParticle particle = particles[i] as IParticle; IParticle2d particle2d = particles[i] as IParticle2d; if (particle2d != null) { Vector2 position = particle2d.Position; posStream[offset] = position + new Vector2(-particle.Size.X, particle.Size.Y); posStream[offset + 1] = position + new Vector2(particle.Size.X, particle.Size.Y); posStream[offset + 2] = position + new Vector2(particle.Size.X, -particle.Size.Y); posStream[offset + 3] = position + new Vector2(-particle.Size.X, -particle.Size.Y); } IParticleColor particleColor = particles[i] as IParticleColor; if (particleColor != null) { colorStream[offset] = particleColor.Color; colorStream[offset + 1] = particleColor.Color; colorStream[offset + 2] = particleColor.Color; colorStream[offset + 3] = particleColor.Color; } IParticleIndex particleIndex = particles[i] as IParticleIndex; System.Drawing.RectangleF tc; if (particleIndex == null || subTextures == null) { tc = (Texture as ITexture2d).TextureCoordinates; } else { tc = subTextures[(int)particleIndex.TextureIndex % subTextures.Length].TextureCoordinates; } textureStream[offset] = new Vector2(tc.Left, tc.Top); textureStream[offset + 1] = new Vector2(tc.Right, tc.Top); textureStream[offset + 2] = new Vector2(tc.Right, tc.Bottom); textureStream[offset + 3] = new Vector2(tc.Left, tc.Bottom); } posStream.Upload(); colorStream.Upload(); textureStream.Upload(); // Render all particles Device.Instance.VertexUnit = vertexUnit; Device.Instance.IndexStream = indexStream; textures.Apply(); int steps = Effect.Begin(); for (int i = 0; i < steps; i++) { Effect.BeginPass(i); Effect.CommitChanges(); // Oct Update BUG!!! Device.Instance.DrawIndexed(vertexUnit.Position, 0, particles.Count * 4, indexStream.Position, particles.Count * 2); Effect.EndPass(); } Effect.End(); }
bool ReadMeshes() { Advance("nummeshes"); int meshNum = int.Parse(NextToken); mesh = new Mesh(); for (int i = 0; i < 1 /*meshNum*/; i++) { Advance("mesh"); // sanity check int num = int.Parse(NextToken); System.Diagnostics.Debug.Assert(num == i, "Invalid mesh num!"); // read mesh data - shader, verts Advance("shader"); string shaderPath = NextToken; FileInfo info = new FileInfo(shaderPath); string localPath = shaderPath.Insert(shaderPath.Length - info.Extension.Length, "_local"); string diffusePath = shaderPath.Insert(shaderPath.Length - info.Extension.Length, "_d"); Textures textures = new Textures(); ITexture texture = null; try { texture = TextureManager.Instance.Load(shaderPath); } catch { texture = TextureManager.Instance.Load(diffusePath); } ITexture normalMap = TextureManager.Instance.Load(localPath); textures["color"] = texture; textures["normal"] = normalMap; if (!ReadVertices()) { return(false); } if (!ReadTriangles()) { return(false); } if (!ReadWeights()) { return(false); } // let's test it VertexUnit vertexUnit = new VertexUnit(VertexFormat.PositionTexture2Tangent, vertices.Length); PositionStream positionStream = (PositionStream)vertexUnit[0]; TextureStream textureStream = (TextureStream)vertexUnit[1]; TextureStream normalStream = (TextureStream)vertexUnit[2]; for (int j = 0; j < vertices.Length; j++) { Vector3 pos = Vector3.Zero; MD5Vertex vertex = vertices[j]; for (int k = 0; k < vertex.WeightCount; k++) { MD5Weight weight = weights[vertex.WeightIndex + k]; MD5Bone bone = bones[weight.BoneIndex]; pos += weight.Vector * bone.Matrix * weight.BiasFactor; } positionStream[j] = pos; textureStream[j] = vertex.UV; normalStream[j] = vertex.UV; } // add tangent space stuff IGraphicsStream[] streams = Util.CalcTangentSpaceStreams(positionStream, textureStream, indexStream); Array.Copy(streams[0].Data, vertexUnit[3].Data, vertices.Length); Array.Copy(streams[1].Data, vertexUnit[4].Data, vertices.Length); Array.Copy(streams[2].Data, vertexUnit[5].Data, vertices.Length); //mesh.SubSets.Add( new SubSet(vertexUnit, indexStream, material)); } return(true); }
/// <summary> /// loads a quake3 level from a stream /// </summary> /// <param name="stream">stream to load from</param> /// <returns>level as a mesh</returns> public Mesh Load(Stream stream) { Mesh mesh = new Mesh(); this.stream = stream; // get header and check if it is ok QuakeHeader header = (QuakeHeader)RawSerializer.Deserialize(stream, typeof(QuakeHeader)); if (header.ID != 1347633737 || header.Version != 0x2e) { return(null); } // get locations of lumps locations = RawSerializer.DeserializeArray(stream, typeof(LumpLocation), (int)QuakeLumps.LumpNumber); // get lumps IList quakeVertices = LoadLump(QuakeLumps.Vertices, typeof(QuakeVertex)); IList quakeFaces = LoadLump(QuakeLumps.Faces, typeof(QuakeFace)); IList quakeTextures = LoadLump(QuakeLumps.Textures, typeof(QuakeTexture)); IList quakeLightMaps = LoadLump(QuakeLumps.Lightmaps, typeof(QuakeLightMap)); // Load all texture images and put into array IList textures = LoadTextures(quakeTextures); // Load lightMaps, create texture and put into array IList lightMaps = LoadLightMaps(quakeLightMaps); // create list from vertices VertexUnit vertexUnit = new VertexUnit(VertexFormat.PositionTexture2, quakeVertices.Count); PositionStream pos = (PositionStream)vertexUnit[typeof(PositionStream)]; TextureStream texStream = (TextureStream)vertexUnit[typeof(TextureStream)]; TextureStream light = (TextureStream)vertexUnit[typeof(TextureStream), 1]; int i = 0; foreach (QuakeVertex v in quakeVertices) { pos[i] = new Math.Vector3(v.Position[0], v.Position[2], -v.Position[1]); texStream[i] = new Math.Vector2(v.TextureCoord[0], v.TextureCoord[1]); light[i] = new Math.Vector2(v.LightmapCoord[0], v.LightmapCoord[1]); i++; } // presort faces Array.Sort(((Array)quakeFaces)); // create mesh int oldLightMap = ((QuakeFace)quakeFaces[0]).LightmapID; int oldTexture = ((QuakeFace)quakeFaces[0]).TextureID; ArrayList indices = new ArrayList(); for (i = 0; i < quakeFaces.Count; ++i) { QuakeFace qf = (QuakeFace)quakeFaces[i]; if (qf.Type == 1) { if (qf.TextureID != oldTexture || qf.LightmapID != oldLightMap) { mesh.SubSets.Add(new SubSet(vertexUnit, IndexStream.Create(indices, vertexUnit.Size))); Textures texs = new Textures("color", (ITexture)textures[oldTexture]); if (oldLightMap == -1) { texs["lightMap"] = null; } else { texs["lightMap"] = (ITexture)lightMaps[oldLightMap]; } mesh.Textures.Add(texs); indices.Clear(); } // add indices => convert from fan to list for (int j = 2; j < qf.NumOfVerts; j++) { indices.Add(qf.VertexIndex); indices.Add(qf.VertexIndex + j - 1); indices.Add(qf.VertexIndex + j); } oldTexture = qf.TextureID; oldLightMap = qf.LightmapID; } } return(mesh); }
private MD3Part LoadMD3(string part) { using (Stream stream = fileSystem.Open(path + part + ".md3")) { // get header and check if it is ok MD3_Header header = (MD3_Header)RawSerializer.Deserialize(stream, typeof(MD3_Header)); if (header.Id != 860898377 || header.Version != 15) { return(null); } // load bone frames MD3_Frame[] frames = (MD3_Frame[])RawSerializer.DeserializeArray(stream, typeof(MD3_Frame), header.NumFrames); // load tags SortedList links = GetLinks((MD3_Tag[])RawSerializer.DeserializeArray(stream, typeof(MD3_Tag), header.NumTags * header.NumFrames)); long meshOffset = stream.Position; // one mesh for every frame BlendMesh mesh = new BlendMesh(header.NumFrames); // load meshes for (int iMesh = 0; iMesh < header.NumMeshes; iMesh++) { stream.Position = meshOffset; MD3_MeshHeader meshHeader = (MD3_MeshHeader)RawSerializer.Deserialize(stream, typeof(MD3_MeshHeader)); MD3_Skin[] skins = (MD3_Skin[])RawSerializer.DeserializeArray(stream, typeof(MD3_Skin), meshHeader.NumSkins); stream.Position = meshOffset + meshHeader.TriangleOffset; MD3_Triangle[] triangles = (MD3_Triangle[])RawSerializer.DeserializeArray(stream, typeof(MD3_Triangle), meshHeader.NumTriangles); stream.Position = meshOffset + meshHeader.TexCoordOffset; MD3_TexCoord[] texCoords = (MD3_TexCoord[])RawSerializer.DeserializeArray(stream, typeof(MD3_TexCoord), meshHeader.NumVertices); stream.Position = meshOffset + meshHeader.VertexOffset; MD3_Vertex[] vertices = (MD3_Vertex[])RawSerializer.DeserializeArray(stream, typeof(MD3_Vertex), meshHeader.NumFrames * meshHeader.NumVertices); float scale = 64.0f; string name = StringHelper.Convert(meshHeader.Name); ITexture tx = (ITexture)textures[name]; Triangle[] tris = new Triangle[triangles.Length]; for (int i = 0; i < triangles.Length; i++) { tris[i].A = (triangles[i]).A; tris[i].B = (triangles[i]).B; tris[i].C = (triangles[i]).C; } IndexStream indexStream = IndexStream16.FromTriangles(tris); int vertCount = meshHeader.NumVertices; // *meshHeader.NumFrames; for (int iFrame = 0; iFrame < meshHeader.NumFrames; iFrame++) { VertexUnit vertexUnit = new VertexUnit(VertexFormat.PositionNormalTexture, vertCount); PositionStream pos = (PositionStream)vertexUnit[typeof(PositionStream)]; NormalStream normal = (NormalStream)vertexUnit[typeof(NormalStream)]; TextureStream tex = (TextureStream)vertexUnit[typeof(TextureStream)]; for (int i = 0; i < vertCount; i++) { int vertIndex = iFrame * meshHeader.NumVertices + i; pos[i] = new Vector3(vertices[vertIndex].X / scale, vertices[vertIndex].Z / scale, -vertices[vertIndex].Y / scale); int texIndex = i % meshHeader.NumVertices; tex[i] = new Vector2(texCoords[texIndex].U, texCoords[texIndex].V); //Normal vector int compressedNormal = ((MD3_Vertex)vertices[vertIndex]).Normal; float lng = (compressedNormal & 0xFF) * Math.Basic.PI / 128; float lat = ((compressedNormal >> 8) & 0xFF) * Math.Basic.PI / 128; normal[i] = new Vector3(Math.Trigonometry.Cos(lat) * Math.Trigonometry.Sin(lng), Math.Trigonometry.Cos(lng), -Math.Trigonometry.Sin(lat) * Math.Trigonometry.Sin(lng)); } if (mesh.Meshes[iFrame] == null) { mesh.Meshes[iFrame] = new Mesh(); } mesh.Meshes[iFrame].SubSets.Add(new SubSet(vertexUnit, indexStream)); mesh.Meshes[iFrame].Textures.Add(new Textures("color", tx)); } // Increase the offset into the file meshOffset += meshHeader.MeshSize; } return(new MD3Part(mesh, links)); } }
/// <summary> /// import a mesh from a stream /// </summary> /// <param name="stream">stream containing mesh data</param> public void Import(Stream stream) { model = null; skeleton = null; IndexStream indexStream = null; IVertexStream currentStream = null; ArrayList streams = new ArrayList(); StringDictionary attributes = new StringDictionary(); XmlTextReader reader = new XmlTextReader(stream); Matrix4[] jointArray = null; Joint[] joints = null; Hashtable jointTable = null; int index = 0; int currentJoint = 0; int vertexCount = 0; int binding = -1; ArrayList[] indicesList = null; ArrayList[] weightsList = null; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { // <mesh> case "mesh": if (model != null) { throw new GraphicsException("Only one mesh allowed in mesh stream!"); } model = new Model(); break; // <subset> case "subset": string parentJoint = reader.GetAttribute("parentJoint"); if (parentJoint != null && parentJoint != "") { binding = (jointTable[parentJoint] as Joint).Index; } else { binding = -1; } break; // <attributes> case "attributes": break; case "attribute": // todo !!! attributes.Add(reader.GetAttribute("name"), reader.GetAttribute("value")); break; //<indexStream> case "indexStream": { index = 0; int size = int.Parse(reader.GetAttribute("size"), culture); indexStream = new IndexStream16(size); } break; //<triangle> case "triangle": { int a = int.Parse(reader.GetAttribute("a"), culture); int b = int.Parse(reader.GetAttribute("b"), culture); int c = int.Parse(reader.GetAttribute("c"), culture); indexStream[index++] = a; indexStream[index++] = b; indexStream[index++] = c; } break; //<positionStream> case "positionStream": { index = 0; vertexCount = int.Parse(reader.GetAttribute("size"), culture); currentStream = new PositionStream(vertexCount); streams.Add(currentStream); } break; //<vector3> case "vector3": { float x = float.Parse(reader.GetAttribute("x"), culture); float y = float.Parse(reader.GetAttribute("y"), culture); float z = float.Parse(reader.GetAttribute("z"), culture); (currentStream as PositionStream)[index++] = new Vector3(x, y, z); } break; //<normalStream> case "normalStream": { index = 0; int size = int.Parse(reader.GetAttribute("size"), culture); currentStream = new NormalStream(size); streams.Add(currentStream); } break; //<colorStream> case "colorStream": { index = 0; int size = int.Parse(reader.GetAttribute("size"), culture); currentStream = new ColorStream(size); streams.Add(currentStream); } break; //<color> case "color": { int r = (int)((float.Parse(reader.GetAttribute("r"), culture)) * 255.0f + 0.5f); int g = (int)((float.Parse(reader.GetAttribute("g"), culture)) * 255.0f + 0.5f); int b = (int)((float.Parse(reader.GetAttribute("b"), culture)) * 255.0f + 0.5f); (currentStream as ColorStream)[index++] = System.Drawing.Color.FromArgb(r, g, b).ToArgb(); } break; //<textureStream> case "textureStream": { index = 0; int size = int.Parse(reader.GetAttribute("size"), culture); currentStream = new TextureStream(size); streams.Add(currentStream); } break; //<vector2> case "vector2": { float x = float.Parse(reader.GetAttribute("x"), culture); float y = float.Parse(reader.GetAttribute("y"), culture); (currentStream as TextureStream)[index++] = new Vector2(x, y); } break; case "joints": { int size = int.Parse(reader.GetAttribute("size"), culture); jointArray = new Matrix4[size]; joints = new Joint[size]; jointTable = new Hashtable(); currentJoint = 0; } break; case "joint": { string jointName = reader.GetAttribute("name"); string parentName = reader.GetAttribute("parent"); Matrix4 m = new Matrix4(float.Parse(reader.GetAttribute("a1"), culture), float.Parse(reader.GetAttribute("a2"), culture), float.Parse(reader.GetAttribute("a3"), culture), float.Parse(reader.GetAttribute("a4"), culture), float.Parse(reader.GetAttribute("b1"), culture), float.Parse(reader.GetAttribute("b2"), culture), float.Parse(reader.GetAttribute("b3"), culture), float.Parse(reader.GetAttribute("b4"), culture), float.Parse(reader.GetAttribute("c1"), culture), float.Parse(reader.GetAttribute("c2"), culture), float.Parse(reader.GetAttribute("c3"), culture), float.Parse(reader.GetAttribute("c4"), culture), float.Parse(reader.GetAttribute("d1"), culture), float.Parse(reader.GetAttribute("d2"), culture), float.Parse(reader.GetAttribute("d3"), culture), float.Parse(reader.GetAttribute("d4"), culture)); jointArray[currentJoint] = m; //new Joint(jointName, m); Joint parent = null; if (parentName != null && jointTable.Contains(parentName)) { parent = (Joint)jointTable[parentName]; } joints[currentJoint] = new Joint(jointName, currentJoint, parent); jointTable[jointName] = joints[currentJoint]; currentJoint++; } break; case "weights": { index = 0; //vertexCount = int.Parse(reader.GetAttribute("size"), culture); indicesList = new ArrayList[vertexCount]; weightsList = new ArrayList[vertexCount]; for (int i = 0; i < vertexCount; i++) { indicesList[i] = new ArrayList(8); weightsList[i] = new ArrayList(8); } } break; case "weight": { int vertexIndex = int.Parse(reader.GetAttribute("vertexIndex")); byte jointIndex = byte.Parse(reader.GetAttribute("jointIndex")); float value = float.Parse(reader.GetAttribute("weight"), culture); indicesList[vertexIndex].Add(jointIndex); weightsList[vertexIndex].Add(value); } break; } } if (reader.NodeType == XmlNodeType.EndElement) { if (reader.Name.Equals("weights")) { IBoneIndicesStream bis = null; IBoneWeightsStream bws = null; if (HardwareSkinning) { bis = new BoneIndicesStream(vertexCount); bws = new BoneWeightsStream(vertexCount); } else { bis = new SoftwareBoneIndicesStream(vertexCount); bws = new SoftwareBoneWeightsStream(vertexCount); } for (int i = 0; i < vertexCount; i++) { bis.SetIndices(i, (byte[])indicesList[i].ToArray(typeof(byte))); bws.SetWeights(i, (float[])weightsList[i].ToArray(typeof(float))); } streams.Add(bis); streams.Add(bws); } else if (reader.Name.Equals("subset")) { VertexUnit vertexUnit = new VertexUnit(streams); if (binding == -1) { model.Mesh = new Mesh(new SubSet(vertexUnit, indexStream)); } else { model.AttachModel(new Model(new Mesh(new SubSet(vertexUnit, indexStream)), null), binding); } streams.Clear(); } } } ; reader.Close(); if (jointArray != null && joints != null) { skeleton = new Skeleton(jointArray, joints); } model.Skeleton = skeleton; }