public static ClippingAttachment GetClone(this ClippingAttachment o) { ClippingAttachment dest = new ClippingAttachment(o.Name) { endSlot = o.endSlot }; CloneVertexAttachment(o, dest); return(dest); }
public static ClippingAttachment GetClone(this ClippingAttachment o) { ClippingAttachment clippingAttachment = new ClippingAttachment(o.Name); clippingAttachment.endSlot = o.endSlot; ClippingAttachment clippingAttachment2 = clippingAttachment; CloneVertexAttachment(o, clippingAttachment2); return(clippingAttachment2); }
public void ClipEnd() { if (clipAttachment != null) { clipAttachment = null; clippingPolygons = null; clippedVertices.Clear(); clippedTriangles.Clear(); clippingPolygon.Clear(); } }
public int ClipStart(Slot slot, ClippingAttachment clip) { if (clipAttachment != null) { return(0); } clipAttachment = clip; int worldVerticesLength = clip.worldVerticesLength; float[] items = clippingPolygon.Resize(worldVerticesLength).Items; clip.ComputeWorldVertices(slot, 0, worldVerticesLength, items, 0); MakeClockwise(clippingPolygon); clippingPolygons = triangulator.Decompose(clippingPolygon, triangulator.Triangulate(clippingPolygon)); foreach (ExposedList <float> clippingPolygon2 in clippingPolygons) { MakeClockwise(clippingPolygon2); clippingPolygon2.Add(clippingPolygon2.Items[0]); clippingPolygon2.Add(clippingPolygon2.Items[1]); } return(clippingPolygons.Count); }
public static Attachment GetClone(this Attachment o, bool cloneMeshesAsLinked) { RegionAttachment attachment = o as RegionAttachment; if (attachment != null) { return(attachment.GetClone()); } MeshAttachment attachment2 = o as MeshAttachment; if (attachment2 != null) { return(!cloneMeshesAsLinked ? attachment2.GetClone() : attachment2.GetLinkedClone(true)); } BoundingBoxAttachment attachment3 = o as BoundingBoxAttachment; if (attachment3 != null) { return(attachment3.GetClone()); } PathAttachment attachment4 = o as PathAttachment; if (attachment4 != null) { return(attachment4.GetClone()); } PointAttachment attachment5 = o as PointAttachment; if (attachment5 != null) { return(attachment5.GetClone()); } ClippingAttachment attachment6 = o as ClippingAttachment; if (attachment6 != null) { return(attachment6.GetClone()); } return(null); }
public void UpdateSkeletonGeometry() { skeletonGeometry.ClearInstances(); BlendState blend; var drawOrder = Skeleton.DrawOrder; var drawOrderItems = Skeleton.DrawOrder.Items; float skeletonR = Skeleton.R, skeletonG = Skeleton.G, skeletonB = Skeleton.B, skeletonA = Skeleton.A; Color color; for (int i = 0, n = drawOrder.Count; i < n; i++) { Slot slot = drawOrderItems[i]; Attachment attachment = slot.Attachment; blend = slot.Data.BlendMode == BlendMode.Additive ? BlendState.Additive : PremultipliedAlpha ? BlendState.AlphaBlend : BlendState.NonPremultiplied; float attachmentColorR, attachmentColorG, attachmentColorB, attachmentColorA; CCTexture2D texture = null; int verticesCount = 0; //float[] vertices = this.vertices; int indicesCount = 0; int[] indices = null; float[] uvs = null; if (attachment is RegionAttachment) { RegionAttachment regionAttachment = (RegionAttachment)attachment; attachmentColorR = regionAttachment.R; attachmentColorG = regionAttachment.G; attachmentColorB = regionAttachment.B; attachmentColorA = regionAttachment.A; AtlasRegion region = (AtlasRegion)regionAttachment.RendererObject; texture = (CCTexture2D)region.page.rendererObject; verticesCount = 4; regionAttachment.ComputeWorldVertices(slot.Bone, vertices, 0, 2); indicesCount = 6; indices = quadTriangles; uvs = regionAttachment.UVs; } else if (attachment is MeshAttachment) { MeshAttachment mesh = (MeshAttachment)attachment; attachmentColorR = mesh.R; attachmentColorG = mesh.G; attachmentColorB = mesh.B; attachmentColorA = mesh.A; AtlasRegion region = (AtlasRegion)mesh.RendererObject; texture = (CCTexture2D)region.page.rendererObject; int vertexCount = mesh.WorldVerticesLength; if (vertices.Length < vertexCount) { vertices = new float[vertexCount]; } verticesCount = vertexCount >> 1; mesh.ComputeWorldVertices(slot, vertices); indicesCount = mesh.Triangles.Length; indices = mesh.Triangles; uvs = mesh.UVs; } else if (attachment is ClippingAttachment) { ClippingAttachment clip = (ClippingAttachment)attachment; clipper.ClipStart(slot, clip); continue; } else { continue; } // calculate color float a = skeletonA * slot.A * attachmentColorA; if (PremultipliedAlpha) { color = new Color( skeletonR * slot.R * attachmentColorR * a, skeletonG * slot.G * attachmentColorG * a, skeletonB * slot.B * attachmentColorB * a, a); } else { color = new Color( skeletonR * slot.R * attachmentColorR, skeletonG * slot.G * attachmentColorG, skeletonB * slot.B * attachmentColorB, a); } //Color darkColor = new Color(); //if (slot.HasSecondColor) //{ // darkColor = new Color(slot.R2 * a, slot.G2 * a, slot.B2 * a); //} //darkColor.A = PremultipliedAlpha ? (byte)255 : (byte)0; // clip if (clipper.IsClipping) { clipper.ClipTriangles(vertices, verticesCount << 1, indices, indicesCount, uvs); vertices = clipper.ClippedVertices.Items; verticesCount = clipper.ClippedVertices.Count >> 1; indices = clipper.ClippedTriangles.Items; indicesCount = clipper.ClippedTriangles.Count; uvs = clipper.ClippedUVs.Items; } if (verticesCount == 0 || indicesCount == 0) { continue; } // submit to batch var item = skeletonGeometry.CreateGeometryInstance(verticesCount, indicesCount); item.InstanceAttributes.BlendState = blend; item.GeometryPacket.Texture = texture; for (int ii = 0, nn = indicesCount; ii < nn; ii++) { item.GeometryPacket.Indicies[ii] = indices[ii]; } var itemVertices = item.GeometryPacket.Vertices; for (int ii = 0, v = 0, nn = verticesCount << 1; v < nn; ii++, v += 2) { itemVertices[ii].Colors = new CCColor4B(color.R, color.G, color.B, color.A); //itemVertices[ii].Colors2 = new CCColor4B(darkColor.R, darkColor.G, darkColor.B, darkColor.A); itemVertices[ii].Vertices.X = vertices[v]; itemVertices[ii].Vertices.Y = vertices[v + 1]; itemVertices[ii].Vertices.Z = 0; itemVertices[ii].TexCoords.U = uvs[v]; itemVertices[ii].TexCoords.V = uvs[v + 1]; } clipper.ClipEnd(slot); } clipper.ClipEnd(); }
/// <summary> /// 主要逻辑copy SkeletonJson.ReadAttachment /// </summary> /// <param name="sdEX"></param> /// <param name="atlasArray"></param> /// <returns></returns> public Skin GenSkinBySkniDataAsset(SkinDataEx sdEX, Atlas[] atlasArray) { #if SPINE_TK2D throw new NotImplementedException("GenSkinBySkniDataAsset Not Implemented"); #endif float scale = this.skeletonDataAsset.scale; var attachmentLoader = new AtlasAttachmentLoader(atlasArray); var skin = new Skin(sdEX.SkinName); var linkedMeshes = new List <SkeletonJson.LinkedMesh>(); Attachment attachment = null; foreach (var slot in sdEX.AllSlots) { var slotIndex = skeleton.Data.FindSlotIndex(slot.SlotName); foreach (var entry in slot.AllAttachments) { switch (entry.type) { case AttachmentType.Region: { RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, entry.AttachmentName, entry.PathName); if (region == null) { Debug.LogError("RegionAttachment New Fail:" + entry.AttachmentName + "," + entry.PathName); continue; } region.Path = entry.PathName; #region Region数据的填充 CheckRegionData(entry.FloatValues); Single w = 32, h = 32; foreach (var f in entry.FloatValues) { switch (f.Key) { case "x": region.x = f.FloatValue * scale; break; case "y": region.y = f.FloatValue * scale; break; case "scaleX": region.scaleX = f.FloatValue; break; case "scaleY": region.scaleY = f.FloatValue; break; case "rotation": region.rotation = f.FloatValue; break; case "width": w = f.FloatValue; break; case "height": h = f.FloatValue; break; } } region.width = w * scale; region.height = h * scale; if (entry.ColorValues != null && entry.ColorValues.Count > 0) { foreach (var c in entry.ColorValues) { switch (c.Key) { case "color": region.r = c.ColorValue.r; region.g = c.ColorValue.g; region.b = c.ColorValue.b; region.a = c.ColorValue.a; break; } } } #endregion region.UpdateOffset(); attachment = region; } break; case AttachmentType.Boundingbox: { BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, entry.AttachmentName); if (box == null) { Debug.LogError("BoundingBoxAttachment New Fail:" + entry.AttachmentName); continue; } #region Box数据填充 Int32 vertexCount = 0; if (entry.IntValues != null && entry.IntValues.Count > 0) { foreach (var i in entry.IntValues) { if (i.Key.Equals("vertexCount")) { vertexCount = i.IntValue; break; } } } foreach (var fs in entry.FloatArrayValues) { if (fs.Key.Equals("vertices")) { ReadVertices(fs, box, vertexCount << 1, scale); break; } } #endregion attachment = box; } break; case AttachmentType.Mesh: case AttachmentType.Linkedmesh: { MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, entry.AttachmentName, entry.PathName); if (mesh == null) { Debug.LogError("MeshAttachment New Fail:" + entry.AttachmentName + "," + entry.PathName); continue; } #region Mesh数据填充 mesh.Path = entry.PathName; if (entry.ColorValues != null && entry.ColorValues.Count > 0) { foreach (var c in entry.ColorValues) { if (c.Key.Equals("color")) { mesh.r = c.ColorValue.r; mesh.g = c.ColorValue.g; mesh.b = c.ColorValue.b; mesh.a = c.ColorValue.a; break; } } } Single w = 0, h = 0; foreach (var f in entry.FloatValues) { switch (f.Key) { case "width": w = f.FloatValue * scale; break; case "height": h = f.FloatValue * scale; break; } } mesh.Width = w; mesh.Height = h; String parentStr = null, skinStr = null; Boolean deform = true; if (entry.StringValues != null && entry.StringValues.Count > 0) { foreach (var ss in entry.StringValues) { switch (ss.Key) { case "parent": parentStr = ss.StringValue; break; case "skin": skinStr = ss.StringValue; break; } } } if (entry.BoolValues != null && entry.BoolValues.Count > 0) { foreach (var b in entry.BoolValues) { if (b.Key.Equals("deform")) { deform = b.BooleanValue; break; } } } if (parentStr != null) { mesh.InheritDeform = deform; linkedMeshes.Add(new SkeletonJson.LinkedMesh(mesh, skinStr, slotIndex, parentStr)); } KeyFloatArrayPair kfap_Vs = new KeyFloatArrayPair(); Single[] uvs = null; foreach (var fs in entry.FloatArrayValues) { switch (fs.Key) { case "vertices": kfap_Vs = fs; break; case "uvs": uvs = fs.FloatArrayValue.ToArray(); break; } } ReadVertices(kfap_Vs, mesh, uvs.Length, scale); Int32[] triangles = null, edges = null; if (entry.IntArrayValues != null && entry.IntArrayValues.Count > 0) { foreach (var i32s in entry.IntArrayValues) { switch (i32s.Key) { case "triangles": triangles = i32s.IntArrayValue.ToArray(); break; case "edges": edges = i32s.IntArrayValue.ToArray(); break; } } } mesh.triangles = triangles; mesh.regionUVs = uvs; mesh.UpdateUVs(); Int32 hull = 0; if (entry.IntValues != null && entry.IntValues.Count > 0) { foreach (var i in entry.IntValues) { if (i.Key.Equals("hull")) { hull = i.IntValue * 2; break; } } } if (hull != 0) { mesh.HullLength = hull; } if (edges != null) { mesh.Edges = edges; } #endregion attachment = mesh; } break; case AttachmentType.Path: { PathAttachment pathAttachment = attachmentLoader.NewPathAttachment(skin, entry.AttachmentName); if (pathAttachment == null) { Debug.LogError("PathAttachment New Fail:" + entry.AttachmentName); continue; } #region Path填充数据 Boolean closed = false, constantSpeed = false; if (entry.BoolValues != null && entry.BoolValues.Count > 0) { foreach (var b in entry.BoolValues) { switch (b.Key) { case "closed": closed = b.BooleanValue; break; case "constantSpeed": constantSpeed = b.BooleanValue; break; } } } pathAttachment.closed = closed; pathAttachment.constantSpeed = constantSpeed; Int32 vertexCount = 0; if (entry.IntValues != null && entry.IntValues.Count > 0) { foreach (var i in entry.IntValues) { if (i.Key.Equals("vertexCount")) { vertexCount = i.IntValue; break; } } } foreach (var fs in entry.FloatArrayValues) { switch (fs.Key) { case "vertices": ReadVertices(fs, pathAttachment, vertexCount << 1, scale); break; case "lengths": var count = fs.FloatArrayValue.Count; pathAttachment.lengths = new Single[count]; for (var idx = 0; idx < count; idx++) { pathAttachment.lengths[idx] = fs.FloatArrayValue[idx] * scale; } break; } } #endregion attachment = pathAttachment; } break; case AttachmentType.Point: { PointAttachment point = attachmentLoader.NewPointAttachment(skin, entry.AttachmentName); if (point == null) { Debug.LogError("PointAttachment New Fail:" + entry.AttachmentName); continue; } #region Point填充数据 Single x = 0, y = 0, r = 0; if (entry.FloatValues != null && entry.FloatValues.Count > 0) { foreach (var f in entry.FloatValues) { switch (f.Key) { case "x": x = f.FloatValue * scale; break; case "y": y = f.FloatValue * scale; break; case "rotation": r = f.FloatValue; break; } } } point.x = x; point.y = y; point.rotation = r; #endregion attachment = point; } break; case AttachmentType.Clipping: { ClippingAttachment clip = attachmentLoader.NewClippingAttachment(skin, entry.AttachmentName); if (clip == null) { Debug.LogError("ClippingAttachment New Fail:" + entry.AttachmentName); continue; } #region Clipping填充数据 String end = null; if (entry.StringValues != null && entry.StringValues.Count > 0) { foreach (var s in entry.StringValues) { if (s.Key.Equals("end")) { end = s.StringValue; break; } } } if (end != null) { SlotData sd = skeleton.Data.FindSlot(end); if (sd == null) { throw new Exception("Clipping end slot not found: " + end); } clip.EndSlot = sd; } Int32 vertexCount = 0; if (entry.IntValues != null && entry.IntValues.Count > 0) { foreach (var i in entry.IntValues) { if (i.Key.Equals("vertexCount")) { vertexCount = i.IntValue; break; } } } foreach (var fs in entry.FloatArrayValues) { if (fs.Key.Equals("vertices")) { ReadVertices(fs, clip, vertexCount << 1, scale); break; } } #endregion attachment = clip; } break; default: break; } skin.SetAttachment(slot.SlotName, entry.AttachmentName, attachment, skeleton); } } // Linked meshes. for (int i = 0, n = linkedMeshes.Count; i < n; i++) { var linkedMesh = linkedMeshes[i]; Skin sk = linkedMesh.skin == null ? skeleton.Data.defaultSkin : skeleton.Data.FindSkin(linkedMesh.skin); if (sk == null) { throw new Exception("Slot not found: " + linkedMesh.skin); } Attachment parent = sk.GetAttachment(linkedMesh.slotIndex, linkedMesh.parent); if (parent == null) { throw new Exception("Parent mesh not found: " + linkedMesh.parent); } linkedMesh.mesh.ParentMesh = (MeshAttachment)parent; linkedMesh.mesh.UpdateUVs(); } skeleton.Data.Skins.Add(skin); return(skin); }
public void AddSubmesh(SubmeshInstruction instruction, bool updateTriangles = true) { Settings settings = this.settings; if (submeshes.Count - 1 < submeshIndex) { submeshes.Resize(submeshIndex + 1); if (submeshes.Items[submeshIndex] == null) { submeshes.Items[submeshIndex] = new ExposedList <int>(); } } ExposedList <int> exposedList = submeshes.Items[submeshIndex]; exposedList.Clear(clearArray: false); Skeleton skeleton = instruction.skeleton; Slot[] items = skeleton.drawOrder.Items; Color32 color = default(Color32); float num = skeleton.a * 255f; float r = skeleton.r; float g = skeleton.g; float b = skeleton.b; Vector2 vector = meshBoundsMin; Vector2 vector2 = meshBoundsMax; float zSpacing = settings.zSpacing; bool pmaVertexColors = settings.pmaVertexColors; bool tintBlack = settings.tintBlack; bool flag = settings.useClipping && instruction.hasClipping; if (flag && instruction.preActiveClippingSlotSource >= 0) { Slot slot = items[instruction.preActiveClippingSlotSource]; clipper.ClipStart(slot, slot.attachment as ClippingAttachment); } for (int i = instruction.startSlot; i < instruction.endSlot; i++) { Slot slot2 = items[i]; Attachment attachment = slot2.attachment; float z = zSpacing * (float)i; float[] array = tempVerts; Color color2 = default(Color); RegionAttachment regionAttachment = attachment as RegionAttachment; float[] array2; int[] array3; int num2; int num3; if (regionAttachment != null) { regionAttachment.ComputeWorldVertices(slot2.bone, array, 0); array2 = regionAttachment.uvs; array3 = regionTriangles; color2.r = regionAttachment.r; color2.g = regionAttachment.g; color2.b = regionAttachment.b; color2.a = regionAttachment.a; num2 = 4; num3 = 6; } else { MeshAttachment meshAttachment = attachment as MeshAttachment; if (meshAttachment == null) { if (flag) { ClippingAttachment clippingAttachment = attachment as ClippingAttachment; if (clippingAttachment != null) { clipper.ClipStart(slot2, clippingAttachment); } } continue; } int worldVerticesLength = meshAttachment.worldVerticesLength; if (array.Length < worldVerticesLength) { array = (tempVerts = new float[worldVerticesLength]); } meshAttachment.ComputeWorldVertices(slot2, 0, worldVerticesLength, array, 0); array2 = meshAttachment.uvs; array3 = meshAttachment.triangles; color2.r = meshAttachment.r; color2.g = meshAttachment.g; color2.b = meshAttachment.b; color2.a = meshAttachment.a; num2 = worldVerticesLength >> 1; num3 = meshAttachment.triangles.Length; } if (pmaVertexColors) { color.a = (byte)(num * slot2.a * color2.a); color.r = (byte)(r * slot2.r * color2.r * (float)(int)color.a); color.g = (byte)(g * slot2.g * color2.g * (float)(int)color.a); color.b = (byte)(b * slot2.b * color2.b * (float)(int)color.a); if (slot2.data.blendMode == BlendMode.Additive) { color.a = 0; } } else { color.a = (byte)(num * slot2.a * color2.a); color.r = (byte)(r * slot2.r * color2.r * 255f); color.g = (byte)(g * slot2.g * color2.g * 255f); color.b = (byte)(b * slot2.b * color2.b * 255f); } if (flag && clipper.IsClipping()) { clipper.ClipTriangles(array, num2 << 1, array3, num3, array2); array = clipper.clippedVertices.Items; num2 = clipper.clippedVertices.Count >> 1; array3 = clipper.clippedTriangles.Items; num3 = clipper.clippedTriangles.Count; array2 = clipper.clippedUVs.Items; } if (num2 != 0 && num3 != 0) { if (tintBlack) { AddAttachmentTintBlack(slot2.r2, slot2.g2, slot2.b2, num2); } int count = vertexBuffer.Count; int num4 = count + num2; if (num4 > vertexBuffer.Items.Length) { Array.Resize(ref vertexBuffer.Items, num4); Array.Resize(ref uvBuffer.Items, num4); Array.Resize(ref colorBuffer.Items, num4); } vertexBuffer.Count = (uvBuffer.Count = (colorBuffer.Count = num4)); Vector3[] items2 = vertexBuffer.Items; Vector2[] items3 = uvBuffer.Items; Color32[] items4 = colorBuffer.Items; if (count == 0) { for (int j = 0; j < num2; j++) { int num5 = count + j; int num6 = j << 1; float num7 = array[num6]; float num8 = array[num6 + 1]; items2[num5].x = num7; items2[num5].y = num8; items2[num5].z = z; items3[num5].x = array2[num6]; items3[num5].y = array2[num6 + 1]; items4[num5] = color; if (num7 < vector.x) { vector.x = num7; } if (num7 > vector2.x) { vector2.x = num7; } if (num8 < vector.y) { vector.y = num8; } if (num8 > vector2.y) { vector2.y = num8; } } } else { for (int k = 0; k < num2; k++) { int num9 = count + k; int num10 = k << 1; float num11 = array[num10]; float num12 = array[num10 + 1]; items2[num9].x = num11; items2[num9].y = num12; items2[num9].z = z; items3[num9].x = array2[num10]; items3[num9].y = array2[num10 + 1]; items4[num9] = color; if (num11 < vector.x) { vector.x = num11; } else if (num11 > vector2.x) { vector2.x = num11; } if (num12 < vector.y) { vector.y = num12; } else if (num12 > vector2.y) { vector2.y = num12; } } } if (updateTriangles) { int count2 = exposedList.Count; int num13 = count2 + num3; if (num13 > exposedList.Items.Length) { Array.Resize(ref exposedList.Items, num13); } exposedList.Count = num13; int[] items5 = exposedList.Items; for (int l = 0; l < num3; l++) { items5[count2 + l] = array3[l] + count; } } } clipper.ClipEnd(slot2); } clipper.ClipEnd(); meshBoundsMin = vector; meshBoundsMax = vector2; meshBoundsThickness = (float)instruction.endSlot * zSpacing; int[] items6 = exposedList.Items; int m = exposedList.Count; for (int num14 = items6.Length; m < num14; m++) { items6[m] = 0; } submeshIndex++; }
public static void GenerateSkeletonRendererInstruction(SkeletonRendererInstruction instructionOutput, Skeleton skeleton, Dictionary <Slot, Material> customSlotMaterials, List <Slot> separatorSlots, bool generateMeshOverride, bool immutableTriangles = false) { ExposedList <Slot> drawOrder = skeleton.drawOrder; int count = drawOrder.Count; instructionOutput.Clear(); ExposedList <SubmeshInstruction> submeshInstructions = instructionOutput.submeshInstructions; instructionOutput.attachments.Resize(count); Attachment[] items = instructionOutput.attachments.Items; int num = 0; bool hasActiveClipping = false; SubmeshInstruction submeshInstruction = default(SubmeshInstruction); submeshInstruction.skeleton = skeleton; submeshInstruction.preActiveClippingSlotSource = -1; SubmeshInstruction submeshInstruction2 = submeshInstruction; bool flag = customSlotMaterials != null && customSlotMaterials.Count > 0; int num2 = (separatorSlots != null) ? separatorSlots.Count : 0; bool flag2 = num2 > 0; int num3 = -1; int preActiveClippingSlotSource = -1; SlotData slotData = null; int num4 = 0; Slot[] items2 = drawOrder.Items; for (int i = 0; i < count; i++) { Slot slot = items2[i]; Attachment attachment = items[i] = slot.attachment; int num5 = 0; int num6 = 0; object obj = null; bool flag3 = false; RegionAttachment regionAttachment = attachment as RegionAttachment; if (regionAttachment != null) { obj = regionAttachment.RendererObject; num5 = 4; num6 = 6; } else { MeshAttachment meshAttachment = attachment as MeshAttachment; if (meshAttachment != null) { obj = meshAttachment.RendererObject; num5 = meshAttachment.worldVerticesLength >> 1; num6 = meshAttachment.triangles.Length; } else { ClippingAttachment clippingAttachment = attachment as ClippingAttachment; if (clippingAttachment != null) { slotData = clippingAttachment.endSlot; num3 = i; submeshInstruction2.hasClipping = true; hasActiveClipping = true; } flag3 = true; } } if (slotData != null && slot.data == slotData) { slotData = null; num3 = -1; } if (flag2) { submeshInstruction2.forceSeparate = false; for (int j = 0; j < num2; j++) { if (object.ReferenceEquals(slot, separatorSlots[j])) { submeshInstruction2.forceSeparate = true; break; } } } if (flag3) { if (submeshInstruction2.forceSeparate && generateMeshOverride) { submeshInstruction2.endSlot = i; submeshInstruction2.preActiveClippingSlotSource = preActiveClippingSlotSource; submeshInstructions.Resize(num4 + 1); submeshInstructions.Items[num4] = submeshInstruction2; num4++; submeshInstruction2.startSlot = i; preActiveClippingSlotSource = num3; submeshInstruction2.rawTriangleCount = 0; submeshInstruction2.rawVertexCount = 0; submeshInstruction2.rawFirstVertexIndex = num; submeshInstruction2.hasClipping = (num3 >= 0); } continue; } Material value; if (flag) { if (!customSlotMaterials.TryGetValue(slot, out value)) { value = (Material)((AtlasRegion)obj).page.rendererObject; } } else { value = (Material)((AtlasRegion)obj).page.rendererObject; } if (submeshInstruction2.forceSeparate || (submeshInstruction2.rawVertexCount > 0 && !object.ReferenceEquals(submeshInstruction2.material, value))) { submeshInstruction2.endSlot = i; submeshInstruction2.preActiveClippingSlotSource = preActiveClippingSlotSource; submeshInstructions.Resize(num4 + 1); submeshInstructions.Items[num4] = submeshInstruction2; num4++; submeshInstruction2.startSlot = i; preActiveClippingSlotSource = num3; submeshInstruction2.rawTriangleCount = 0; submeshInstruction2.rawVertexCount = 0; submeshInstruction2.rawFirstVertexIndex = num; submeshInstruction2.hasClipping = (num3 >= 0); } submeshInstruction2.material = value; submeshInstruction2.rawTriangleCount += num6; submeshInstruction2.rawVertexCount += num5; submeshInstruction2.rawFirstVertexIndex = num; num += num5; } if (submeshInstruction2.rawVertexCount > 0) { submeshInstruction2.endSlot = count; submeshInstruction2.preActiveClippingSlotSource = preActiveClippingSlotSource; submeshInstruction2.forceSeparate = false; submeshInstructions.Resize(num4 + 1); submeshInstructions.Items[num4] = submeshInstruction2; } instructionOutput.hasActiveClipping = hasActiveClipping; instructionOutput.rawVertexCount = num; instructionOutput.immutableTriangles = immutableTriangles; }
public static void GenerateSingleSubmeshInstruction(SkeletonRendererInstruction instructionOutput, Skeleton skeleton, Material material) { ExposedList <Slot> drawOrder = skeleton.drawOrder; int count = drawOrder.Count; instructionOutput.Clear(); ExposedList <SubmeshInstruction> submeshInstructions = instructionOutput.submeshInstructions; submeshInstructions.Resize(1); instructionOutput.attachments.Resize(count); Attachment[] items = instructionOutput.attachments.Items; int num = 0; SubmeshInstruction submeshInstruction = default(SubmeshInstruction); submeshInstruction.skeleton = skeleton; submeshInstruction.preActiveClippingSlotSource = -1; submeshInstruction.startSlot = 0; submeshInstruction.rawFirstVertexIndex = 0; submeshInstruction.material = material; submeshInstruction.forceSeparate = false; submeshInstruction.endSlot = count; SubmeshInstruction submeshInstruction2 = submeshInstruction; bool hasActiveClipping = false; Slot[] items2 = drawOrder.Items; for (int i = 0; i < count; i++) { Slot slot = items2[i]; Attachment attachment = items[i] = slot.attachment; RegionAttachment regionAttachment = attachment as RegionAttachment; int num2; int num3; if (regionAttachment != null) { num2 = 4; num3 = 6; } else { MeshAttachment meshAttachment = attachment as MeshAttachment; if (meshAttachment != null) { num2 = meshAttachment.worldVerticesLength >> 1; num3 = meshAttachment.triangles.Length; } else { ClippingAttachment clippingAttachment = attachment as ClippingAttachment; if (clippingAttachment != null) { submeshInstruction2.hasClipping = true; hasActiveClipping = true; } num2 = 0; num3 = 0; } } submeshInstruction2.rawTriangleCount += num3; submeshInstruction2.rawVertexCount += num2; num += num2; } instructionOutput.hasActiveClipping = hasActiveClipping; instructionOutput.rawVertexCount = num; submeshInstructions.Items[0] = submeshInstruction2; }