private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog OpenFDiag = new OpenFileDialog(); OpenFDiag.Filter = "Mesh file|*.mesh"; OpenFDiag.Title = "Select a mesh to open..."; if (OpenFDiag.ShowDialog() == DialogResult.OK) { //WARNING: Unable to load body meshes! m_CurrentMesh = new Mesh(OpenFDiag.FileName, false); LoadMesh(m_CurrentMesh); string TextureName = OpenFDiag.FileName.Replace("meshes", "textures").Replace("mesh", "jpg"). Replace("fah", "").Replace("fa", "falgt").Replace("-head-head", ""); m_Tex = Texture2D.FromFile(this.Device, TextureName); m_LoadComplete = true; } }
/// <summary> /// User clicked on an item in the list containing available appearances. /// </summary> private void LstAppearances_SelectedIndexChanged(object sender, EventArgs e) { if (m_Skeleton == null) { m_Skeleton = new Skeleton(this.Device, ContentManager.GetResourceFromLongID(0x100000005)); m_Skeleton.AssignChildren(ref m_Skeleton); } m_CurrentAppearance = new Appearance(ContentManager.GetResourceFromLongID( (ulong)LstAppearances.SelectedItem)); List<Binding> Bindings = new List<Binding>(); foreach (ulong BindingID in m_CurrentAppearance.BindingIDs) Bindings.Add(new Binding(ContentManager.GetResourceFromLongID(BindingID))); m_Tex = Texture2D.FromFile(this.Device, new MemoryStream( ContentManager.GetResourceFromLongID(Bindings[0].TextureAssetID))); string SelectedStr = (string)LstHeads.SelectedItem; if (SelectedStr.Contains("bodies")) { m_CurrentMesh = new Mesh(ContentManager.GetResourceFromLongID(Bindings[0].MeshAssetID), true); m_CurrentMesh.TransformVertices2(m_Skeleton.Bones[0], ref mSimpleEffect); m_CurrentMesh.BlendVertices2(); } else m_CurrentMesh = new Mesh(ContentManager.GetResourceFromLongID(Bindings[0].MeshAssetID), false); LoadMesh(m_CurrentMesh); }
/// <summary> /// User clicked on an item in the list containing available heads and bodies. /// </summary> private void LstHeads_SelectedIndexChanged(object sender, EventArgs e) { if (m_Skeleton == null) { m_Skeleton = new Skeleton(this.Device, ContentManager.GetResourceFromLongID(0x100000005)); m_Skeleton.AssignChildren(ref m_Skeleton); } foreach(KeyValuePair<ulong, string> Pair in ContentManager.Resources) { if ((string)LstHeads.SelectedItem == Pair.Value) { //HAndGroup files are used to group together different hand meshes and textures. if (Pair.Value.Contains(".hag")) { Hag HandGroup = new Hag(ContentManager.GetResourceFromLongID(Pair.Key)); m_CurrentAppearance = new Appearance(ContentManager.GetResourceFromLongID( HandGroup.Appearances[0])); LstAppearances.Items.Clear(); foreach (ulong AppearanceID in HandGroup.Appearances) LstAppearances.Items.Add(AppearanceID); List<Binding> Bindings = new List<Binding>(); foreach (ulong BindingID in m_CurrentAppearance.BindingIDs) Bindings.Add(new Binding(ContentManager.GetResourceFromLongID(BindingID))); m_Tex = Texture2D.FromFile(this.Device, new MemoryStream( ContentManager.GetResourceFromLongID(Bindings[0].TextureAssetID))); m_CurrentMesh = new Mesh(ContentManager.GetResourceFromLongID(Bindings[0].MeshAssetID), false); LoadMesh(m_CurrentMesh); } else { PurchasableObject PO = new PurchasableObject(ContentManager.GetResourceFromLongID(Pair.Key)); m_CurrentOutfit = new Outfit(ContentManager.GetResourceFromLongID(PO.OutfitID)); m_CurrentAppearance = new Appearance( ContentManager.GetResourceFromLongID(m_CurrentOutfit.LightAppearanceID)); LstAppearances.Items.Clear(); LstAppearances.Items.Add(m_CurrentOutfit.LightAppearanceID); LstAppearances.Items.Add(m_CurrentOutfit.MediumAppearanceID); LstAppearances.Items.Add(m_CurrentOutfit.DarkAppearanceID); List<Binding> Bindings = new List<Binding>(); foreach (ulong BindingID in m_CurrentAppearance.BindingIDs) Bindings.Add(new Binding(ContentManager.GetResourceFromLongID(BindingID))); m_Tex = Texture2D.FromFile(this.Device, new MemoryStream( ContentManager.GetResourceFromLongID(Bindings[0].TextureAssetID))); //The file selected was most likely a body-mesh, so apply the adult skeleton to it. if (Pair.Value.Contains("bodies")) { m_CurrentMesh = new Mesh(ContentManager.GetResourceFromLongID(Bindings[0].MeshAssetID), true); m_CurrentMesh.TransformVertices2(m_Skeleton.Bones[0], ref mSimpleEffect); m_CurrentMesh.BlendVertices2(); LoadMesh(m_CurrentMesh); } else { m_CurrentMesh = new Mesh(ContentManager.GetResourceFromLongID(Bindings[0].MeshAssetID), false); LoadMesh(m_CurrentMesh); } } m_LoadComplete = true; } } }
private void LoadMesh(Mesh MeshToLoad) { if (!MeshToLoad.IsBodyMesh) { m_NormVerticies = new VertexPositionNormalTexture[MeshToLoad.VertexCount]; for (int i = 0; i < MeshToLoad.VertexCount; i++) { m_NormVerticies[i] = new VertexPositionNormalTexture(); m_NormVerticies[i].Position.X = MeshToLoad.VertexData[i, 0]; m_NormVerticies[i].Position.Y = MeshToLoad.VertexData[i, 1]; m_NormVerticies[i].Position.Z = MeshToLoad.VertexData[i, 2]; m_NormVerticies[i].Normal.X = MeshToLoad.VertexData[i, 3]; m_NormVerticies[i].Normal.Y = MeshToLoad.VertexData[i, 4]; m_NormVerticies[i].Normal.Z = MeshToLoad.VertexData[i, 5]; //Not really sure why this is important, but I think it has something to do //with being able to see the texture. //m_NormVerticies[i].Normal.Normalize(); } for (int i = 0; i < MeshToLoad.TexVertexCount; i++) { m_NormVerticies[i].TextureCoordinate.X = MeshToLoad.TextureVertData[i, 1]; m_NormVerticies[i].TextureCoordinate.Y = MeshToLoad.TextureVertData[i, 2]; } } else { m_NormVerticies = new VertexPositionNormalTexture[MeshToLoad.VertexCount]; for (int i = 0; i < MeshToLoad.VertexCount; i++) { m_NormVerticies[i] = new VertexPositionNormalTexture(); m_NormVerticies[i].Position.X = MeshToLoad.TransformedVertices[i].Coord.X; m_NormVerticies[i].Position.Y = MeshToLoad.TransformedVertices[i].Coord.Y; m_NormVerticies[i].Position.Z = MeshToLoad.TransformedVertices[i].Coord.Z; m_NormVerticies[i].Normal.X = MeshToLoad.TransformedVertices[i].Normal.X; m_NormVerticies[i].Normal.Y = MeshToLoad.TransformedVertices[i].Normal.Y; m_NormVerticies[i].Normal.Z = MeshToLoad.TransformedVertices[i].Normal.Z; //Not really sure why this is important, but I think it has something to do //with being able to see the texture. //m_NormVerticies[i].Normal.Normalize(); } for (int i = 0; i < MeshToLoad.TexVertexCount; i++) { m_NormVerticies[i].TextureCoordinate.X = MeshToLoad.TextureVertData[i, 1]; m_NormVerticies[i].TextureCoordinate.Y = MeshToLoad.TextureVertData[i, 2]; } } }