private Attachment ReadAttachment(Skin skin, String name, Dictionary <String, Object> map) { if (map.ContainsKey("name")) { name = (String)map["name"]; } var type = AttachmentType.region; if (map.ContainsKey("type")) { type = (AttachmentType)Enum.Parse(typeof(AttachmentType), (String)map["type"], false); } String path = name; if (map.ContainsKey("path")) { path = (String)map["path"]; } switch (type) { case AttachmentType.region: RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, name, path); if (region == null) { return(null); } region.Path = path; region.x = GetFloat(map, "x", 0) * Scale; region.y = GetFloat(map, "y", 0) * Scale; region.scaleX = GetFloat(map, "scaleX", 1); region.scaleY = GetFloat(map, "scaleY", 1); region.rotation = GetFloat(map, "rotation", 0); region.width = GetFloat(map, "width", 32) * Scale; region.height = GetFloat(map, "height", 32) * Scale; region.UpdateOffset(); if (map.ContainsKey("color")) { var color = (String)map["color"]; region.r = ToColor(color, 0); region.g = ToColor(color, 1); region.b = ToColor(color, 2); region.a = ToColor(color, 3); } return(region); case AttachmentType.mesh: { MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path); if (mesh == null) { return(null); } mesh.Path = path; mesh.vertices = GetFloatArray(map, "vertices", Scale); mesh.triangles = GetIntArray(map, "triangles"); mesh.regionUVs = GetFloatArray(map, "uvs", 1); mesh.UpdateUVs(); if (map.ContainsKey("color")) { var color = (String)map["color"]; mesh.r = ToColor(color, 0); mesh.g = ToColor(color, 1); mesh.b = ToColor(color, 2); mesh.a = ToColor(color, 3); } mesh.HullLength = GetInt(map, "hull", 0) * 2; if (map.ContainsKey("edges")) { mesh.Edges = GetIntArray(map, "edges"); } mesh.Width = GetInt(map, "width", 0) * Scale; mesh.Height = GetInt(map, "height", 0) * Scale; return(mesh); } case AttachmentType.skinnedmesh: { SkinnedMeshAttachment mesh = attachmentLoader.NewSkinnedMeshAttachment(skin, name, path); if (mesh == null) { return(null); } mesh.Path = path; float[] uvs = GetFloatArray(map, "uvs", 1); float[] vertices = GetFloatArray(map, "vertices", 1); var weights = new List <float>(uvs.Length * 3 * 3); var bones = new List <int>(uvs.Length * 3); float scale = Scale; for (int i = 0, n = vertices.Length; i < n;) { int boneCount = (int)vertices[i++]; bones.Add(boneCount); for (int nn = i + boneCount * 4; i < nn;) { bones.Add((int)vertices[i]); weights.Add(vertices[i + 1] * scale); weights.Add(vertices[i + 2] * scale); weights.Add(vertices[i + 3]); i += 4; } } mesh.bones = bones.ToArray(); mesh.weights = weights.ToArray(); mesh.triangles = GetIntArray(map, "triangles"); mesh.regionUVs = uvs; mesh.UpdateUVs(); if (map.ContainsKey("color")) { var color = (String)map["color"]; mesh.r = ToColor(color, 0); mesh.g = ToColor(color, 1); mesh.b = ToColor(color, 2); mesh.a = ToColor(color, 3); } mesh.HullLength = GetInt(map, "hull", 0) * 2; if (map.ContainsKey("edges")) { mesh.Edges = GetIntArray(map, "edges"); } mesh.Width = GetInt(map, "width", 0) * Scale; mesh.Height = GetInt(map, "height", 0) * Scale; return(mesh); } case AttachmentType.boundingbox: BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name); if (box == null) { return(null); } box.vertices = GetFloatArray(map, "vertices", Scale); return(box); } return(null); }
private Attachment ReadAttachment(Stream input, Skin skin, String attachmentName, bool nonessential) { float scale = Scale; String name = ReadString(input); if (name == null) { name = attachmentName; } switch ((AttachmentType)input.ReadByte()) { case AttachmentType.region: { String path = ReadString(input); if (path == null) { path = name; } RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, name, path); if (region == null) { return(null); } region.Path = path; region.x = ReadFloat(input) * scale; region.y = ReadFloat(input) * scale; region.scaleX = ReadFloat(input); region.scaleY = ReadFloat(input); region.rotation = ReadFloat(input); region.width = ReadFloat(input) * scale; region.height = ReadFloat(input) * scale; int color = ReadInt(input); region.r = ((color & 0xff000000) >> 24) / 255f; region.g = ((color & 0x00ff0000) >> 16) / 255f; region.b = ((color & 0x0000ff00) >> 8) / 255f; region.a = ((color & 0x000000ff)) / 255f; region.UpdateOffset(); return(region); } case AttachmentType.boundingbox: { BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name); if (box == null) { return(null); } box.vertices = ReadFloatArray(input, scale); return(box); } case AttachmentType.mesh: { String path = ReadString(input); if (path == null) { path = name; } MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path); if (mesh == null) { return(null); } mesh.Path = path; mesh.regionUVs = ReadFloatArray(input, 1); mesh.triangles = ReadShortArray(input); mesh.vertices = ReadFloatArray(input, scale); mesh.UpdateUVs(); int color = ReadInt(input); mesh.r = ((color & 0xff000000) >> 24) / 255f; mesh.g = ((color & 0x00ff0000) >> 16) / 255f; mesh.b = ((color & 0x0000ff00) >> 8) / 255f; mesh.a = ((color & 0x000000ff)) / 255f; mesh.HullLength = ReadInt(input, true) * 2; if (nonessential) { mesh.Edges = ReadIntArray(input); mesh.Width = ReadFloat(input) * scale; mesh.Height = ReadFloat(input) * scale; } return(mesh); } case AttachmentType.skinnedmesh: { String path = ReadString(input); if (path == null) { path = name; } SkinnedMeshAttachment mesh = attachmentLoader.NewSkinnedMeshAttachment(skin, name, path); if (mesh == null) { return(null); } mesh.Path = path; float[] uvs = ReadFloatArray(input, 1); int[] triangles = ReadShortArray(input); int vertexCount = ReadInt(input, true); var weights = new List <float>(uvs.Length * 3 * 3); var bones = new List <int>(uvs.Length * 3); for (int i = 0; i < vertexCount; i++) { int boneCount = (int)ReadFloat(input); bones.Add(boneCount); for (int nn = i + boneCount * 4; i < nn; i += 4) { bones.Add((int)ReadFloat(input)); weights.Add(ReadFloat(input) * scale); weights.Add(ReadFloat(input) * scale); weights.Add(ReadFloat(input)); } } mesh.bones = bones.ToArray(); mesh.weights = weights.ToArray(); mesh.triangles = triangles; mesh.regionUVs = uvs; mesh.UpdateUVs(); int color = ReadInt(input); mesh.r = ((color & 0xff000000) >> 24) / 255f; mesh.g = ((color & 0x00ff0000) >> 16) / 255f; mesh.b = ((color & 0x0000ff00) >> 8) / 255f; mesh.a = ((color & 0x000000ff)) / 255f; mesh.HullLength = ReadInt(input, true) * 2; if (nonessential) { mesh.Edges = ReadIntArray(input); mesh.Width = ReadFloat(input) * scale; mesh.Height = ReadFloat(input) * scale; } return(mesh); } } return(null); }
private Attachment ReadAttachment(Skin skin, string name, Dictionary <string, object> map) { if (map.ContainsKey("name")) { name = (string)map.get_Item("name"); } AttachmentType attachmentType = AttachmentType.region; if (map.ContainsKey("type")) { attachmentType = (AttachmentType)((int)Enum.Parse(typeof(AttachmentType), (string)map.get_Item("type"), false)); } string path = name; if (map.ContainsKey("path")) { path = (string)map.get_Item("path"); } switch (attachmentType) { case AttachmentType.region: { RegionAttachment regionAttachment = this.attachmentLoader.NewRegionAttachment(skin, name, path); if (regionAttachment == null) { return(null); } regionAttachment.Path = path; regionAttachment.x = this.GetFloat(map, "x", 0f) * this.Scale; regionAttachment.y = this.GetFloat(map, "y", 0f) * this.Scale; regionAttachment.scaleX = this.GetFloat(map, "scaleX", 1f); regionAttachment.scaleY = this.GetFloat(map, "scaleY", 1f); regionAttachment.rotation = this.GetFloat(map, "rotation", 0f); regionAttachment.width = this.GetFloat(map, "width", 32f) * this.Scale; regionAttachment.height = this.GetFloat(map, "height", 32f) * this.Scale; regionAttachment.UpdateOffset(); if (map.ContainsKey("color")) { string hexString = (string)map.get_Item("color"); regionAttachment.r = this.ToColor(hexString, 0); regionAttachment.g = this.ToColor(hexString, 1); regionAttachment.b = this.ToColor(hexString, 2); regionAttachment.a = this.ToColor(hexString, 3); } return(regionAttachment); } case AttachmentType.boundingbox: { BoundingBoxAttachment boundingBoxAttachment = this.attachmentLoader.NewBoundingBoxAttachment(skin, name); if (boundingBoxAttachment == null) { return(null); } boundingBoxAttachment.vertices = this.GetFloatArray(map, "vertices", this.Scale); return(boundingBoxAttachment); } case AttachmentType.mesh: { MeshAttachment meshAttachment = this.attachmentLoader.NewMeshAttachment(skin, name, path); if (meshAttachment == null) { return(null); } meshAttachment.Path = path; meshAttachment.vertices = this.GetFloatArray(map, "vertices", this.Scale); meshAttachment.triangles = this.GetIntArray(map, "triangles"); meshAttachment.regionUVs = this.GetFloatArray(map, "uvs", 1f); meshAttachment.UpdateUVs(); if (map.ContainsKey("color")) { string hexString2 = (string)map.get_Item("color"); meshAttachment.r = this.ToColor(hexString2, 0); meshAttachment.g = this.ToColor(hexString2, 1); meshAttachment.b = this.ToColor(hexString2, 2); meshAttachment.a = this.ToColor(hexString2, 3); } meshAttachment.HullLength = this.GetInt(map, "hull", 0) * 2; if (map.ContainsKey("edges")) { meshAttachment.Edges = this.GetIntArray(map, "edges"); } meshAttachment.Width = (float)this.GetInt(map, "width", 0) * this.Scale; meshAttachment.Height = (float)this.GetInt(map, "height", 0) * this.Scale; return(meshAttachment); } case AttachmentType.skinnedmesh: { SkinnedMeshAttachment skinnedMeshAttachment = this.attachmentLoader.NewSkinnedMeshAttachment(skin, name, path); if (skinnedMeshAttachment == null) { return(null); } skinnedMeshAttachment.Path = path; float[] floatArray = this.GetFloatArray(map, "uvs", 1f); float[] floatArray2 = this.GetFloatArray(map, "vertices", 1f); List <float> list = new List <float>(floatArray.Length * 3 * 3); List <int> list2 = new List <int>(floatArray.Length * 3); float scale = this.Scale; int i = 0; int num = floatArray2.Length; while (i < num) { int num2 = (int)floatArray2[i++]; list2.Add(num2); int num3 = i + num2 * 4; while (i < num3) { list2.Add((int)floatArray2[i]); list.Add(floatArray2[i + 1] * scale); list.Add(floatArray2[i + 2] * scale); list.Add(floatArray2[i + 3]); i += 4; } } skinnedMeshAttachment.bones = list2.ToArray(); skinnedMeshAttachment.weights = list.ToArray(); skinnedMeshAttachment.triangles = this.GetIntArray(map, "triangles"); skinnedMeshAttachment.regionUVs = floatArray; skinnedMeshAttachment.UpdateUVs(); if (map.ContainsKey("color")) { string hexString3 = (string)map.get_Item("color"); skinnedMeshAttachment.r = this.ToColor(hexString3, 0); skinnedMeshAttachment.g = this.ToColor(hexString3, 1); skinnedMeshAttachment.b = this.ToColor(hexString3, 2); skinnedMeshAttachment.a = this.ToColor(hexString3, 3); } skinnedMeshAttachment.HullLength = this.GetInt(map, "hull", 0) * 2; if (map.ContainsKey("edges")) { skinnedMeshAttachment.Edges = this.GetIntArray(map, "edges"); } skinnedMeshAttachment.Width = (float)this.GetInt(map, "width", 0) * this.Scale; skinnedMeshAttachment.Height = (float)this.GetInt(map, "height", 0) * this.Scale; return(skinnedMeshAttachment); } default: return(null); } }