public async Task <ActionResult> Create([Bind(Include = "ID,TEN,HINHANH")] SKIN skin, IEnumerable <HttpPostedFileBase> HINHANH) { if (ModelState.IsValid) { if (HINHANH != null) { List <string> lstFilePath = new List <string>(); foreach (var file in HINHANH) { // Some browsers send file names with full path. This needs to be stripped. var fileName = Path.GetFileName(file.FileName); fileName = Guid.NewGuid().ToString() + file.FileName; var physicalPath = Path.Combine(Server.MapPath("~/Upload"), fileName); // The files are not actually saved in this demo file.SaveAs(physicalPath); lstFilePath.Add("Upload/" + fileName); } if (lstFilePath.Count > 0) { skin.HINHANH = string.Join(";", lstFilePath); } } skin.ID = Guid.NewGuid().ToString(); db.SKINs.Add(skin); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(skin)); }
public ActionResult DeleteConfirmed(int id) { SKIN sKIN = db.SKINs.Find(id); db.SKINs.Remove(sKIN); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> DeleteConfirmed(string id) { SKIN skin = await db.SKINs.FindAsync(id); db.SKINs.Remove(skin); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "id,logo,comercial,comercial_link,googlemap,fanpage,footer,youtube,aboutus,shopinfo,deliveryinfo")] SKIN sKIN) { if (ModelState.IsValid) { db.SKINs.Add(sKIN); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sKIN)); }
public static void Export_SKIN(this StreamWriter w, MyProgressBar mpb, SKIN skin, MLOD.Mesh mesh) { if (skin == null) { w.WriteLine("; skin is null"); w.WriteLine("skin 0"); return; } if (!mesh.JointReferences.TrueForAll(x => skin.Bones.Exists(y => y.NameHash == x))) { w.WriteLine("; mesh.JointReferences references unknown bone."); w.WriteLine("skin 0"); return; } List<uint> seen = new List<uint>(); if (!mesh.JointReferences.TrueForAll(x => { if (seen.Contains(x)) return false; seen.Add(x); return true; })) { w.WriteLine("; mesh.JointReferences contains non-unique references."); w.WriteLine("skin 0"); return; } seen = null; w.WriteLine(string.Format("skin {0}", skin.Bones.Count)); mpb.Init("Export SKIN...", skin.Bones.Count); int i = 0; //Referenced bones //pre-20120601: foreach (var bone in skin.Bones.FindAll(x => mesh.JointReferences.Contains(x.NameHash))) foreach (var bone in ((IEnumerable<uint>)mesh.JointReferences).Select(hash => skin.Bones.Find(x => x.NameHash == hash))) { w.WriteLine(string.Format( //"{0} {1:X8} {2:R} {3:R} {4:R} {5:R} {6:R} {7:R} {8:R} {9:R} {10:R} {11:R} {12:R} {13:R}", "{0} {1:X8} {2:F6} {3:F6} {4:F6} {5:F6} {6:F6} {7:F6} {8:F6} {9:F6} {10:F6} {11:F6} {12:F6} {13:F6}", i++, bone.NameHash, bone.InverseBindPose.Right.X, bone.InverseBindPose.Right.Y, bone.InverseBindPose.Right.Z, bone.InverseBindPose.Translate.X, bone.InverseBindPose.Up.X, bone.InverseBindPose.Up.Y, bone.InverseBindPose.Up.Z, bone.InverseBindPose.Translate.Y, bone.InverseBindPose.Back.X, bone.InverseBindPose.Back.Y, bone.InverseBindPose.Back.Z, bone.InverseBindPose.Translate.Z)); mpb.Value++; } //Unreferenced bones foreach (var bone in skin.Bones.FindAll(x => !mesh.JointReferences.Contains(x.NameHash))) { w.WriteLine(string.Format( //"{0} {1:X8} {2:R} {3:R} {4:R} {5:R} {6:R} {7:R} {8:R} {9:R} {10:R} {11:R} {12:R} {13:R}", "{0} {1:X8} {2:F6} {3:F6} {4:F6} {5:F6} {6:F6} {7:F6} {8:F6} {9:F6} {10:F6} {11:F6} {12:F6} {13:F6}", i++, bone.NameHash, bone.InverseBindPose.Right.X, bone.InverseBindPose.Right.Y, bone.InverseBindPose.Right.Z, bone.InverseBindPose.Translate.X, bone.InverseBindPose.Up.X, bone.InverseBindPose.Up.Y, bone.InverseBindPose.Up.Z, bone.InverseBindPose.Translate.Y, bone.InverseBindPose.Back.X, bone.InverseBindPose.Back.Y, bone.InverseBindPose.Back.Z, bone.InverseBindPose.Translate.Z)); mpb.Value++; } w.Flush(); mpb.Done(); }
public async Task <ActionResult> Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SKIN skin = await db.SKINs.FindAsync(id); if (skin == null) { return(HttpNotFound()); } return(View(skin)); }
// GET: admin/SKINs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SKIN sKIN = db.SKINs.Find(id); if (sKIN == null) { return(HttpNotFound()); } return(View(sKIN)); }
/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { var hashCode = 41; // Suitable nullity checks etc, of course :) if (SKIN != null) { hashCode = hashCode * 59 + SKIN.GetHashCode(); } if (CAPE != null) { hashCode = hashCode * 59 + CAPE.GetHashCode(); } return(hashCode); } }
public EnemyMongo(SKIN skin, Color color, Vector2 origin) : base(color, origin) { mSkin = skin; if (color == Color.Red) { if (mSkin == SKIN.Normal) { mSpriteWalking = new Sprite(ExtraFunctions.fillArrayWithImages2(9, "enemies\\Mongo\\red\\01\\mongo_red"), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, 2, 100, 100, false, false); } if (mSkin == SKIN.Pirate) { mSpriteWalking = new Sprite(ExtraFunctions.fillArrayWithImages2(9, "enemies\\Mongo\\red\\02\\mongo_red"), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, 2, 100, 100, false, false); } } if (color == Color.Blue) { if (mSkin == SKIN.Normal) { mSpriteWalking = new Sprite(ExtraFunctions.fillArrayWithImages2(9, "enemies\\Mongo\\blue\\01\\mongo_blue"), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, 2, 100, 100, false, false); } if (mSkin == SKIN.Pirate) { mSpriteWalking = new Sprite(ExtraFunctions.fillArrayWithImages2(9, "enemies\\Mongo\\blue\\02\\mongo_blue"), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, 2, 100, 100, false, false); } } if (color == Color.Green) { if (mSkin == SKIN.Normal) { mSpriteWalking = new Sprite(ExtraFunctions.fillArrayWithImages2(9, "enemies\\Mongo\\green\\01\\mongo_green"), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, 2, 100, 100, false, false); } if (mSkin == SKIN.Pirate) { mSpriteWalking = new Sprite(ExtraFunctions.fillArrayWithImages2(9, "enemies\\Mongo\\green\\02\\mongo_green"), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1, 0 }, 2, 100, 100, false, false); } } addSprite(mSpriteWalking, sSTATE_WALKING); changeToSprite(sSTATE_WALKING); setCollisionRect(15, 15, 70, 70); setLocation(origin); }
public ActionResult Edit([Bind(Include = "id,logo,comercial,comercial_link,googlemap,fanpage,footer,youtube,aboutus,shopinfo,deliveryinfo")] SKIN sKIN, HttpPostedFileBase logo, HttpPostedFileBase comercial) { try { var path = ""; var filename = ""; var date = DateTime.Now.ToString(); date = date.Replace(" ", "_"); date = date.Replace("/", "_"); date = date.Replace(":", "_"); date = date + "_"; if (ModelState.IsValid) { if (logo != null) { filename = date + logo.FileName; path = Path.Combine(Server.MapPath("~/Content/images/"), filename); logo.SaveAs(path); sKIN.logo = filename; } if (comercial != null) { filename = date + comercial.FileName; path = Path.Combine(Server.MapPath("~/Content/images/"), filename); comercial.SaveAs(path); sKIN.comercial = filename; } db.Entry(sKIN).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DbEntityValidationException e) { throw e; } catch (Exception ex) { throw ex; } return(View(sKIN)); }
/// <summary> /// Returns true if PlayerTexture instances are equal /// </summary> /// <param name="other">Instance of PlayerTexture to be compared</param> /// <returns>Boolean</returns> public bool Equals(PlayerTexture other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return (( SKIN == other.SKIN || SKIN != null && SKIN.Equals(other.SKIN) ) && ( CAPE == other.CAPE || CAPE != null && CAPE.Equals(other.CAPE) )); }
public EnemyMongo(SKIN skin, Color color) : this(skin, color, new Vector2(0, 0)) { }
public static void Export_SKIN(this StreamWriter w, MyProgressBar mpb, SKIN skin, MLOD.Mesh mesh) { if (skin == null) { w.WriteLine("; skin is null"); w.WriteLine("skin 0"); return; } if (!mesh.JointReferences.TrueForAll(x => skin.Bones.Exists(y => y.NameHash == x))) { w.WriteLine("; mesh.JointReferences references unknown bone."); w.WriteLine("skin 0"); return; } List <uint> seen = new List <uint>(); if (!mesh.JointReferences.TrueForAll(x => { if (seen.Contains(x)) { return(false); } seen.Add(x); return(true); })) { w.WriteLine("; mesh.JointReferences contains non-unique references."); w.WriteLine("skin 0"); return; } seen = null; w.WriteLine(string.Format("skin {0}", skin.Bones.Count)); mpb.Init("Export SKIN...", skin.Bones.Count); int i = 0; //Referenced bones //pre-20120601: foreach (var bone in skin.Bones.FindAll(x => mesh.JointReferences.Contains(x.NameHash))) foreach (var bone in ((IEnumerable <uint>)mesh.JointReferences).Select(hash => skin.Bones.Find(x => x.NameHash == hash))) { w.WriteLine(string.Format( //"{0} {1:X8} {2:R} {3:R} {4:R} {5:R} {6:R} {7:R} {8:R} {9:R} {10:R} {11:R} {12:R} {13:R}", "{0} {1:X8} {2:F6} {3:F6} {4:F6} {5:F6} {6:F6} {7:F6} {8:F6} {9:F6} {10:F6} {11:F6} {12:F6} {13:F6}", i++, bone.NameHash, bone.InverseBindPose.Right.X, bone.InverseBindPose.Right.Y, bone.InverseBindPose.Right.Z, bone.InverseBindPose.Translate.X, bone.InverseBindPose.Up.X, bone.InverseBindPose.Up.Y, bone.InverseBindPose.Up.Z, bone.InverseBindPose.Translate.Y, bone.InverseBindPose.Back.X, bone.InverseBindPose.Back.Y, bone.InverseBindPose.Back.Z, bone.InverseBindPose.Translate.Z)); mpb.Value++; } //Unreferenced bones foreach (var bone in skin.Bones.FindAll(x => !mesh.JointReferences.Contains(x.NameHash))) { w.WriteLine(string.Format( //"{0} {1:X8} {2:R} {3:R} {4:R} {5:R} {6:R} {7:R} {8:R} {9:R} {10:R} {11:R} {12:R} {13:R}", "{0} {1:X8} {2:F6} {3:F6} {4:F6} {5:F6} {6:F6} {7:F6} {8:F6} {9:F6} {10:F6} {11:F6} {12:F6} {13:F6}", i++, bone.NameHash, bone.InverseBindPose.Right.X, bone.InverseBindPose.Right.Y, bone.InverseBindPose.Right.Z, bone.InverseBindPose.Translate.X, bone.InverseBindPose.Up.X, bone.InverseBindPose.Up.Y, bone.InverseBindPose.Up.Z, bone.InverseBindPose.Translate.Y, bone.InverseBindPose.Back.X, bone.InverseBindPose.Back.Y, bone.InverseBindPose.Back.Z, bone.InverseBindPose.Translate.Z)); mpb.Value++; } w.Flush(); mpb.Done(); }
public static void Import_SKIN(this StreamReader r, MyProgressBar mpb, SKIN skin) { string tagLine = r.ReadTag(); string[] split = tagLine.Split(new char[] { ' ', }, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 2) { throw new InvalidDataException("Invalid tag line read for 'skin'."); } if (split[0] != "skin") { throw new InvalidDataException("Expected line tag 'skin' not found."); } int count; if (!int.TryParse(split[1], out count)) { throw new InvalidDataException("'skin' line has invalid count."); } if (count == 0) { return; } skin.Bones = new SKIN.BoneList(null); mpb.Init("Import SKIN...", count); for (int b = 0; b < count; b++) { split = r.ReadLine().Split(new char[] { ' ', }, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 14) { throw new InvalidDataException(string.Format("'skin' line {0} has invalid format.", b)); } int index; if (!int.TryParse(split[0], out index)) { throw new InvalidDataException(string.Format("'skin' line {0} has invalid line index.", b)); } if (index != b) { throw new InvalidDataException(string.Format("'vrtf' line {0} has incorrect line index value {1}.", b, index)); } uint name; if (!uint.TryParse(split[1], System.Globalization.NumberStyles.HexNumber, null, out name)) { throw new InvalidDataException(string.Format("'skin' line {0} has invalid name hash.", b)); } //if (name != mesh.JointReferences[b]) //throw new InvalidDataException(string.Format("'skin' line {0} name 0x{1:X8} does not match mesh joint reference 0x{2:X8}.", b, name, mesh.JointReferences[b])); float[] values = split.ConvertAll <Single>(2); if (values.Length != 12) { throw new InvalidDataException(string.Format("'skin' line {0} has incorrect number of float values {1}.", b, values.Length)); } SKIN.Bone bone = new SKIN.Bone(0, null) { NameHash = name, InverseBindPose = new Matrix43(0, null), }; bone.InverseBindPose.Right.X = values[0]; bone.InverseBindPose.Right.Y = values[1]; bone.InverseBindPose.Right.Z = values[2]; bone.InverseBindPose.Translate.X = values[3]; bone.InverseBindPose.Up.X = values[4]; bone.InverseBindPose.Up.Y = values[5]; bone.InverseBindPose.Up.Z = values[6]; bone.InverseBindPose.Translate.Y = values[7]; bone.InverseBindPose.Back.X = values[8]; bone.InverseBindPose.Back.Y = values[9]; bone.InverseBindPose.Back.Z = values[10]; bone.InverseBindPose.Translate.Z = values[11]; skin.Bones.Add(bone); mpb.Value++; } mpb.Done(); }
//-- public void Import_Mesh(StreamReader r, MLOD.Mesh mesh, GenericRCOLResource rcolResource, MLOD mlod, IResourceKey defaultRK, out meshExpImp.ModelBlocks.Vertex[] mverts) { #region Import VRTF bool isDefaultVRTF = false; VRTF defaultForMesh = VRTF.CreateDefaultForMesh(mesh); VRTF vrtf = new VRTF(rcolResource.RequestedApiVersion, null) { Version = 2, Layouts = null, }; r.Import_VRTF(mpb, vrtf); IResourceKey vrtfRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.VertexFormatIndex); if (vrtfRK == null) { vrtfRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.SkinControllerIndex); if (vrtfRK == null) { vrtfRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.ScaleOffsetIndex); } if (vrtfRK == null) { vrtfRK = new TGIBlock(0, null, 0, 0, System.Security.Cryptography.FNV64.GetHash(DateTime.UtcNow.ToString() + defaultRK.ToString())); } vrtfRK = new TGIBlock(0, null, vrtfRK) { ResourceType = vrtf.ResourceType, }; } if (vrtf.Equals(defaultForMesh)) { isDefaultVRTF = true; mesh.VertexFormatIndex = new GenericRCOLResource.ChunkReference(0, null, 0);//Clear the reference } else { rcolResource.ReplaceChunk(mesh, "VertexFormatIndex", vrtfRK, vrtf); } #endregion #region Import SKIN // we need to read the data in the file... SKIN skin = new SKIN(rcolResource.RequestedApiVersion, null) { Version = 1, Bones = null, }; r.Import_SKIN(mpb, skin); // However, we do *NOT* want to update the RCOL with what we read - we are not replacing the object skeleton here #if UNDEF if (skin.Bones != null) { IResourceKey skinRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.SkinControllerIndex); if (skinRK == null) { skinRK = new TGIBlock(0, null, vrtfRK) { ResourceType = skin.ResourceType, } } ; rcolResource.ReplaceChunk(mesh, "SkinControllerIndex", skinRK, skin); } #endif #endregion mverts = Import_VBUF_Main(r, mlod, mesh, vrtf, isDefaultVRTF); #region Import IBUF IBUF ibuf = GenericRCOLResource.ChunkReference.GetBlock(rcolResource, mesh.IndexBufferIndex) as IBUF; if (ibuf == null) { ibuf = new IBUF(rcolResource.RequestedApiVersion, null) { Version = 2, Flags = IBUF.FormatFlags.DifferencedIndices, DisplayListUsage = 0, } } ; Import_IBUF_Main(r, mlod, mesh, ibuf); IResourceKey ibufRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.IndexBufferIndex); if (ibufRK == null) { ibufRK = new TGIBlock(0, null, defaultRK) { ResourceType = ibuf.ResourceType, } } ; rcolResource.ReplaceChunk(mesh, "IndexBufferIndex", ibufRK, ibuf); #endregion #region Update the JointReferences UIntList joints = CreateJointReferences(mesh, mverts, skin); List <uint> added = new List <uint>(joints); List <uint> removed = new List <uint>(); foreach (var j in mesh.JointReferences) { if (joints.Contains(j)) { added.Remove(j); } else { removed.Add(j); } } // Remove root removed.Remove(0xCD68F001); if (added.Count != 0) { mesh.JointReferences.AddRange(added); System.Windows.Forms.CopyableMessageBox.Show(String.Format("Mesh: 0x{0:X8}\nJointReferences with newly assigned (via BlendIndex) vertex: {1}\n({2})", mesh.Name, added.Count, String.Join(", ", added.ConvertAll <string>(a => "0x" + a.ToString("X8")).ToArray())), "Warning", System.Windows.Forms.CopyableMessageBoxButtons.OK, System.Windows.Forms.CopyableMessageBoxIcon.Warning); } // with the 20120601 change to export, this warning on import has lost its severity... and been dropped. #if UNDEF if (removed.Count != 0) { //#if UNDEF // http://dino.drealm.info/den/denforum/index.php?topic=394.msg3876#msg3876 removed.ForEach(j => mesh.JointReferences[mesh.JointReferences.IndexOf(j)] = 0); //#endif // However, OM felt more comfortable if there was some indication something a little odd was going on. System.Windows.Forms.CopyableMessageBox.Show(String.Format("Mesh: 0x{0:X8}\nJointReferences with no assigned (via BlendIndex) vertex: {1}\n({2})", mesh.Name, removed.Count, String.Join(", ", removed.ConvertAll <string>(a => "0x" + a.ToString("X8")).ToArray())), "Warning", System.Windows.Forms.CopyableMessageBoxButtons.OK, System.Windows.Forms.CopyableMessageBoxIcon.Warning); } #endif #endregion } ModelBlocks.Vertex[] Import_VBUF_Main(StreamReader r, MLOD mlod, MLOD.Mesh mesh, VRTF vrtf, bool isDefaultVRTF) { string tagLine = r.ReadTag(); string[] split = tagLine.Split(new char[] { ' ', }, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 2) { throw new InvalidDataException("Invalid tag line read for 'vbuf'."); } if (split[0] != "vbuf") { throw new InvalidDataException("Expected line tag 'vbuf' not found."); } int count; if (!int.TryParse(split[1], out count)) { throw new InvalidDataException("'vbuf' line has invalid count."); } //Wes's MilkShape plug-in sends back the first line in all subsequent lines of a dropShadow. return(r.Import_VBUF(mpb, count, vrtf, (mesh.Flags & MeshFlags.ShadowCaster) == 0)); } void Import_IBUF_Main(StreamReader r, MLOD mlod, MLOD.Mesh mesh, IBUF ibuf) { string tagLine = r.ReadTag(); string[] split = tagLine.Split(new char[] { ' ', }, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 2) { throw new InvalidDataException("Invalid tag line read for 'ibuf'."); } if (split[0] != "ibuf") { throw new InvalidDataException("Expected line tag 'ibuf' not found."); } int count; if (!int.TryParse(split[1], out count)) { throw new InvalidDataException("'ibuf' line has invalid count."); } ibuf.SetIndices(mlod, mesh, r.Import_IBUF(mpb, IBUF.IndexCountFromPrimitiveType(mesh.PrimitiveType), count)); } UIntList CreateJointReferences(MLOD.Mesh mesh, ModelBlocks.Vertex[] mverts, SKIN skin) { if (skin == null || skin.Bones == null) { return(new UIntList(null)); } int maxReference = -1; foreach (var vert in mverts) { if (vert.BlendIndices != null) { foreach (var reference in vert.BlendIndices) { if ((sbyte)reference > maxReference) { maxReference = reference; } } } } return(maxReference > -1 ? new UIntList(null, skin.Bones.GetRange(0, maxReference + 1).ConvertAll <uint>(x => x.NameHash)) : new UIntList(null)); }
UIntList CreateJointReferences(MLOD.Mesh mesh, ModelBlocks.Vertex[] mverts, SKIN skin) { if (skin == null || skin.Bones == null) return new UIntList(null); int maxReference = -1; foreach (var vert in mverts) if (vert.BlendIndices != null) foreach (var reference in vert.BlendIndices) if ((sbyte)reference > maxReference) maxReference = reference; return maxReference > -1 ? new UIntList(null, skin.Bones.GetRange(0, maxReference + 1).ConvertAll<uint>(x => x.NameHash)) : new UIntList(null); }
//-- public void Import_Mesh(StreamReader r, MLOD.Mesh mesh, GenericRCOLResource rcolResource, MLOD mlod, IResourceKey defaultRK, out meshExpImp.ModelBlocks.Vertex[] mverts) { #region Import VRTF bool isDefaultVRTF = false; VRTF defaultForMesh = VRTF.CreateDefaultForMesh(mesh); VRTF vrtf = new VRTF(rcolResource.RequestedApiVersion, null) { Version = 2, Layouts = null, }; r.Import_VRTF(mpb, vrtf); IResourceKey vrtfRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.VertexFormatIndex); if (vrtfRK == null) { vrtfRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.SkinControllerIndex); if (vrtfRK == null) vrtfRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.ScaleOffsetIndex); if (vrtfRK == null) vrtfRK = new TGIBlock(0, null, 0, 0, System.Security.Cryptography.FNV64.GetHash(DateTime.UtcNow.ToString() + defaultRK.ToString())); vrtfRK = new TGIBlock(0, null, vrtfRK) { ResourceType = vrtf.ResourceType, }; } if (vrtf.Equals(defaultForMesh)) { isDefaultVRTF = true; mesh.VertexFormatIndex = new GenericRCOLResource.ChunkReference(0, null, 0);//Clear the reference } else rcolResource.ReplaceChunk(mesh, "VertexFormatIndex", vrtfRK, vrtf); #endregion #region Import SKIN // we need to read the data in the file... SKIN skin = new SKIN(rcolResource.RequestedApiVersion, null) { Version = 1, Bones = null, }; r.Import_SKIN(mpb, skin); // However, we do *NOT* want to update the RCOL with what we read - we are not replacing the object skeleton here #if UNDEF if (skin.Bones != null) { IResourceKey skinRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.SkinControllerIndex); if (skinRK == null) skinRK = new TGIBlock(0, null, vrtfRK) { ResourceType = skin.ResourceType, }; rcolResource.ReplaceChunk(mesh, "SkinControllerIndex", skinRK, skin); } #endif #endregion mverts = Import_VBUF_Main(r, mlod, mesh, vrtf, isDefaultVRTF); #region Import IBUF IBUF ibuf = GenericRCOLResource.ChunkReference.GetBlock(rcolResource, mesh.IndexBufferIndex) as IBUF; if (ibuf == null) ibuf = new IBUF(rcolResource.RequestedApiVersion, null) { Version = 2, Flags = IBUF.FormatFlags.DifferencedIndices, DisplayListUsage = 0, }; Import_IBUF_Main(r, mlod, mesh, ibuf); IResourceKey ibufRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.IndexBufferIndex); if (ibufRK == null) ibufRK = new TGIBlock(0, null, defaultRK) { ResourceType = ibuf.ResourceType, }; rcolResource.ReplaceChunk(mesh, "IndexBufferIndex", ibufRK, ibuf); #endregion #region Update the JointReferences UIntList joints = CreateJointReferences(mesh, mverts, skin); List<uint> added = new List<uint>(joints); List<uint> removed = new List<uint>(); foreach (var j in mesh.JointReferences) { if (joints.Contains(j)) added.Remove(j); else removed.Add(j); } // Remove root removed.Remove(0xCD68F001); if (added.Count != 0) { mesh.JointReferences.AddRange(added); System.Windows.Forms.CopyableMessageBox.Show(String.Format("Mesh: 0x{0:X8}\nJointReferences with newly assigned (via BlendIndex) vertex: {1}\n({2})", mesh.Name, added.Count, String.Join(", ", added.ConvertAll<string>(a => "0x" + a.ToString("X8")).ToArray())), "Warning", System.Windows.Forms.CopyableMessageBoxButtons.OK, System.Windows.Forms.CopyableMessageBoxIcon.Warning); } // with the 20120601 change to export, this warning on import has lost its severity... and been dropped. #if UNDEF if (removed.Count != 0) { //#if UNDEF // http://dino.drealm.info/den/denforum/index.php?topic=394.msg3876#msg3876 removed.ForEach(j => mesh.JointReferences[mesh.JointReferences.IndexOf(j)] = 0); //#endif // However, OM felt more comfortable if there was some indication something a little odd was going on. System.Windows.Forms.CopyableMessageBox.Show(String.Format("Mesh: 0x{0:X8}\nJointReferences with no assigned (via BlendIndex) vertex: {1}\n({2})", mesh.Name, removed.Count, String.Join(", ", removed.ConvertAll<string>(a => "0x" + a.ToString("X8")).ToArray())), "Warning", System.Windows.Forms.CopyableMessageBoxButtons.OK, System.Windows.Forms.CopyableMessageBoxIcon.Warning); } #endif #endregion }
//-- public void Import_Mesh(StreamReader r, MLOD.Mesh mesh, GenericRCOLResource rcolResource, MLOD mlod, IResourceKey defaultRK, out meshExpImp.ModelBlocks.Vertex[] mverts, out List <meshExpImp.ModelBlocks.Vertex[]> lverts) { #region Import VRTF bool isDefaultVRTF = false; VRTF defaultForMesh = VRTF.CreateDefaultForMesh(mesh); VRTF vrtf = new VRTF(rcolResource.RequestedApiVersion, null) { Version = 2, Layouts = null, }; r.Import_VRTF(mpb, vrtf); IResourceKey vrtfRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.VertexFormatIndex); if (vrtfRK == null) { vrtfRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.SkinControllerIndex); if (vrtfRK == null) { vrtfRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.ScaleOffsetIndex); } if (vrtfRK == null) { vrtfRK = new TGIBlock(0, null, 0, 0, System.Security.Cryptography.FNV64.GetHash(DateTime.UtcNow.ToString() + defaultRK.ToString())); } vrtfRK = new TGIBlock(0, null, vrtfRK) { ResourceType = vrtf.ResourceType, }; } if (vrtf.Equals(defaultForMesh)) { isDefaultVRTF = true; mesh.VertexFormatIndex = new GenericRCOLResource.ChunkReference(0, null, 0);//Clear the reference } else { rcolResource.ReplaceChunk(mesh, "VertexFormatIndex", vrtfRK, vrtf); } #endregion #region Import SKIN // we need to read the data in the file... SKIN skin = new SKIN(rcolResource.RequestedApiVersion, null) { Version = 1, Bones = null, }; r.Import_SKIN(mpb, skin); // However, we do *NOT* want to update the RCOL with what we read - we are not replacing the object skeleton here #if UNDEF if (skin.Bones != null) { IResourceKey skinRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.SkinControllerIndex); if (skinRK == null) { skinRK = new TGIBlock(0, null, vrtfRK) { ResourceType = skin.ResourceType, } } ; rcolResource.ReplaceChunk(mesh, "SkinControllerIndex", skinRK, skin); } #endif #endregion mverts = Import_VBUF_Main(r, mlod, mesh, vrtf, isDefaultVRTF); #region Import IBUF IBUF ibuf = GenericRCOLResource.ChunkReference.GetBlock(rcolResource, mesh.IndexBufferIndex) as IBUF; if (ibuf == null) { ibuf = new IBUF(rcolResource.RequestedApiVersion, null) { Version = 2, Flags = IBUF.FormatFlags.DifferencedIndices, DisplayListUsage = 0, } } ; Import_IBUF_Main(r, mlod, mesh, ibuf); IResourceKey ibufRK = GenericRCOLResource.ChunkReference.GetKey(rcolResource, mesh.IndexBufferIndex); if (ibufRK == null) { ibufRK = new TGIBlock(0, null, defaultRK) { ResourceType = ibuf.ResourceType, } } ; rcolResource.ReplaceChunk(mesh, "IndexBufferIndex", ibufRK, ibuf); #endregion // This reads both VBUF Vertex[]s and the ibufs; but the ibufs just go straight in quite happily lverts = Import_MeshGeoStates(r, mlod, mesh, vrtf, isDefaultVRTF, ibuf); #region Update the JointReferences UIntList joints = CreateJointReferences(mesh, mverts, lverts ?? new List <meshExpImp.ModelBlocks.Vertex[]>(), skin); List <uint> added = new List <uint>(joints); List <uint> removed = new List <uint>(); foreach (var j in mesh.JointReferences) { if (joints.Contains(j)) { added.Remove(j); } else { removed.Add(j); } } // Remove root removed.Remove(0xCD68F001); if (added.Count != 0) { mesh.JointReferences.AddRange(added); System.Windows.Forms.CopyableMessageBox.Show(String.Format("Mesh: 0x{0:X8}\nJointReferences with newly assigned (via BlendIndex) vertex: {1}\n({2})", mesh.Name, added.Count, String.Join(", ", added.ConvertAll <string>(a => "0x" + a.ToString("X8")).ToArray())), "Warning", System.Windows.Forms.CopyableMessageBoxButtons.OK, System.Windows.Forms.CopyableMessageBoxIcon.Warning); } // with the 20120601 change to export, this warning on import has lost its severity... and been dropped. #if UNDEF if (removed.Count != 0) { //#if UNDEF // http://dino.drealm.info/den/denforum/index.php?topic=394.msg3876#msg3876 removed.ForEach(j => mesh.JointReferences[mesh.JointReferences.IndexOf(j)] = 0); //#endif // However, OM felt more comfortable if there was some indication something a little odd was going on. System.Windows.Forms.CopyableMessageBox.Show(String.Format("Mesh: 0x{0:X8}\nJointReferences with no assigned (via BlendIndex) vertex: {1}\n({2})", mesh.Name, removed.Count, String.Join(", ", removed.ConvertAll <string>(a => "0x" + a.ToString("X8")).ToArray())), "Warning", System.Windows.Forms.CopyableMessageBoxButtons.OK, System.Windows.Forms.CopyableMessageBoxIcon.Warning); } #endif #endregion } meshExpImp.ModelBlocks.Vertex[] Import_VBUF_Main(StreamReader r, MLOD mlod, MLOD.Mesh mesh, VRTF vrtf, bool isDefaultVRTF) { string tagLine = r.ReadTag(); string[] split = tagLine.Split(new char[] { ' ', }, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 2) { throw new InvalidDataException("Invalid tag line read for 'vbuf'."); } if (split[0] != "vbuf") { throw new InvalidDataException("Expected line tag 'vbuf' not found."); } int count; if (!int.TryParse(split[1], out count)) { throw new InvalidDataException("'vbuf' line has invalid count."); } return(r.Import_VBUF(mpb, count, vrtf)); } void Import_IBUF_Main(StreamReader r, MLOD mlod, MLOD.Mesh mesh, IBUF ibuf) { string tagLine = r.ReadTag(); string[] split = tagLine.Split(new char[] { ' ', }, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 2) { throw new InvalidDataException("Invalid tag line read for 'ibuf'."); } if (split[0] != "ibuf") { throw new InvalidDataException("Expected line tag 'ibuf' not found."); } int count; if (!int.TryParse(split[1], out count)) { throw new InvalidDataException("'ibuf' line has invalid count."); } ibuf.SetIndices(mlod, mesh, r.Import_IBUF(mpb, IBUF.IndexCountFromPrimitiveType(mesh.PrimitiveType), count)); } List <meshExpImp.ModelBlocks.Vertex[]> Import_MeshGeoStates(StreamReader r, MLOD mlod, MLOD.Mesh mesh, VRTF vrtf, bool isDefaultVRTF, IBUF ibuf) { MLOD.GeometryStateList oldGeos = new MLOD.GeometryStateList(null, mesh.GeometryStates); r.Import_GEOS(mpb, mesh); if (mesh.GeometryStates.Count <= 0) { return(null); } List <meshExpImp.ModelBlocks.Vertex[]> lverts = new List <meshExpImp.ModelBlocks.Vertex[]>(); for (int g = 0; g < mesh.GeometryStates.Count; g++) { lverts.Add(Import_VBUF_Geos(r, mlod, mesh, g, vrtf, isDefaultVRTF)); Import_IBUF_Geos(r, mlod, mesh, g, ibuf); } return(lverts); } UIntList CreateJointReferences(MLOD.Mesh mesh, meshExpImp.ModelBlocks.Vertex[] mverts, List <meshExpImp.ModelBlocks.Vertex[]> lverts, SKIN skin) { if (skin == null || skin.Bones == null) { return(new UIntList(null)); } int maxReference = -1; lverts.Insert(0, mverts); foreach (var vertices in lverts) { if (vertices != null) { foreach (var vert in vertices) { if (vert.BlendIndices != null) { foreach (var reference in vert.BlendIndices) { if ((sbyte)reference > maxReference) { maxReference = reference; } } } } } } lverts.Remove(mverts); return(maxReference > -1 ? new UIntList(null, skin.Bones.GetRange(0, maxReference + 1).ConvertAll <uint>(x => x.NameHash)) : new UIntList(null)); } meshExpImp.ModelBlocks.Vertex[] Import_VBUF_Geos(StreamReader r, MLOD mlod, MLOD.Mesh mesh, int geoStateIndex, VRTF vrtf, bool isDefaultVRTF) { //w.WriteLine(string.Format("vbuf {0} {1} {2}", geoStateIndex, mesh.GeometryStates[geoStateIndex].MinVertexIndex, mesh.GeometryStates[geoStateIndex].VertexCount)); string tagLine = r.ReadTag(); string[] split = tagLine.Split(new char[] { ' ', }, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 4) { throw new InvalidDataException(string.Format("Invalid tag line read for geoState {0} 'vbuf'.", geoStateIndex)); } if (split[0] != "vbuf") { throw new InvalidDataException("Expected line tag 'vbuf' not found."); } int lineIndex; if (!int.TryParse(split[1], out lineIndex)) { throw new InvalidDataException(string.Format("geoState {0} 'vbuf' line has invalid geoStateIndex.", geoStateIndex)); } if (lineIndex != geoStateIndex) { throw new InvalidDataException(string.Format("geoState {0} 'vbuf' line has incorrect geoStateIndex value {1}.", geoStateIndex, lineIndex)); } int minVertexIndex; if (!int.TryParse(split[2], out minVertexIndex)) { throw new InvalidDataException(string.Format("geoState {0} 'vbuf' line has invalid MinVertexIndex.", geoStateIndex)); } int vertexCount; if (!int.TryParse(split[3], out vertexCount)) { throw new InvalidDataException(string.Format("geoState {0} 'vbuf' line has invalid VertexCount.", geoStateIndex)); } if (minVertexIndex + vertexCount <= mesh.MinVertexIndex + mesh.VertexCount) { mesh.GeometryStates[geoStateIndex].MinVertexIndex = minVertexIndex; mesh.GeometryStates[geoStateIndex].VertexCount = vertexCount; return(null); } if (minVertexIndex != mesh.GeometryStates[geoStateIndex].MinVertexIndex) { throw new InvalidDataException(string.Format("geoState {0} 'vbuf' line has unexpected MinVertexIndex {1}; expected {2}.", geoStateIndex, minVertexIndex, mesh.GeometryStates[geoStateIndex].MinVertexIndex)); } return(r.Import_VBUF(mpb, vertexCount, vrtf)); } void Import_IBUF_Geos(StreamReader r, MLOD mlod, MLOD.Mesh mesh, int geoStateIndex, IBUF ibuf) { //w.WriteLine(string.Format("ibuf {0} {1} {2}", geoStateIndex, mesh.GeometryStates[geoStateIndex].StartIndex, mesh.GeometryStates[geoStateIndex].PrimitiveCount)); string tagLine = r.ReadTag(); string[] split = tagLine.Split(new char[] { ' ', }, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 4) { throw new InvalidDataException("Invalid tag line read for 'ibuf'."); } if (split[0] != "ibuf") { throw new InvalidDataException("Expected line tag 'ibuf' not found."); } int lineIndex; if (!int.TryParse(split[1], out lineIndex)) { throw new InvalidDataException(string.Format("geoState {0} 'ibuf' line has invalid geoStateIndex.", geoStateIndex)); } if (lineIndex != geoStateIndex) { throw new InvalidDataException(string.Format("geoState {0} 'ibuf' line has incorrect geoStateIndex value {1}.", geoStateIndex, lineIndex)); } int startIndex; if (!int.TryParse(split[2], out startIndex)) { throw new InvalidDataException(string.Format("geoState {0} 'ibuf' line has invalid StartIndex.", geoStateIndex)); } int primitiveCount; if (!int.TryParse(split[3], out primitiveCount)) { throw new InvalidDataException(string.Format("geoState {0} 'ibuf' line has invalid PrimitiveCount.", geoStateIndex)); } int sizePerPrimitive = IBUF.IndexCountFromPrimitiveType(mesh.PrimitiveType); if (startIndex + primitiveCount * sizePerPrimitive <= mesh.StartIndex + mesh.PrimitiveCount * sizePerPrimitive) { mesh.GeometryStates[geoStateIndex].StartIndex = startIndex; mesh.GeometryStates[geoStateIndex].PrimitiveCount = primitiveCount; return; } if (startIndex != mesh.GeometryStates[geoStateIndex].StartIndex) { throw new InvalidDataException(string.Format("geoState {0} 'ibuf' line has unexpected StartIndex {1}; expected {2}.", geoStateIndex, startIndex, mesh.GeometryStates[geoStateIndex].StartIndex)); } ibuf.SetIndices(mlod, mesh, geoStateIndex, r.Import_IBUF(mpb, IBUF.IndexCountFromPrimitiveType(mesh.PrimitiveType), primitiveCount)); }
public static void Import_SKIN(this StreamReader r, MyProgressBar mpb, SKIN skin) { string tagLine = r.ReadTag(); string[] split = tagLine.Split(new char[] { ' ', }, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 2) throw new InvalidDataException("Invalid tag line read for 'skin'."); if (split[0] != "skin") throw new InvalidDataException("Expected line tag 'skin' not found."); int count; if (!int.TryParse(split[1], out count)) throw new InvalidDataException("'skin' line has invalid count."); if (count == 0) return; skin.Bones = new SKIN.BoneList(null); mpb.Init("Import SKIN...", count); for (int b = 0; b < count; b++) { split = r.ReadLine().Split(new char[] { ' ', }, StringSplitOptions.RemoveEmptyEntries); if (split.Length != 14) throw new InvalidDataException(string.Format("'skin' line {0} has invalid format.", b)); int index; if (!int.TryParse(split[0], out index)) throw new InvalidDataException(string.Format("'skin' line {0} has invalid line index.", b)); if (index != b) throw new InvalidDataException(string.Format("'vrtf' line {0} has incorrect line index value {1}.", b, index)); uint name; if (!uint.TryParse(split[1], System.Globalization.NumberStyles.HexNumber, null, out name)) throw new InvalidDataException(string.Format("'skin' line {0} has invalid name hash.", b)); //if (name != mesh.JointReferences[b]) //throw new InvalidDataException(string.Format("'skin' line {0} name 0x{1:X8} does not match mesh joint reference 0x{2:X8}.", b, name, mesh.JointReferences[b])); float[] values = split.ConvertAll<Single>(2); if (values.Length != 12) throw new InvalidDataException(string.Format("'skin' line {0} has incorrect number of float values {1}.", b, values.Length)); SKIN.Bone bone = new SKIN.Bone(0, null) { NameHash = name, InverseBindPose = new Matrix43(0, null), }; bone.InverseBindPose.Right.X = values[0]; bone.InverseBindPose.Right.Y = values[1]; bone.InverseBindPose.Right.Z = values[2]; bone.InverseBindPose.Translate.X = values[3]; bone.InverseBindPose.Up.X = values[4]; bone.InverseBindPose.Up.Y = values[5]; bone.InverseBindPose.Up.Z = values[6]; bone.InverseBindPose.Translate.Y = values[7]; bone.InverseBindPose.Back.X = values[8]; bone.InverseBindPose.Back.Y = values[9]; bone.InverseBindPose.Back.Z = values[10]; bone.InverseBindPose.Translate.Z = values[11]; skin.Bones.Add(bone); mpb.Value++; } mpb.Done(); }