/// <summary> /// Clears any previous polygons, finds all visible bounding box attachments, /// and computes the world vertices for each bounding box's polygon.</summary> /// <param name="skeleton">The skeleton.</param> /// <param name="updateAabb"> /// If true, the axis aligned bounding box containing all the polygons is computed. /// If false, the SkeletonBounds AABB methods will always return true. /// </param> public void Update(Skeleton skeleton, bool updateAabb) { ExposedList <BoundingBoxAttachment> boundingBoxes = BoundingBoxes; ExposedList <Polygon> polygons = Polygons; ExposedList <Slot> slots = skeleton.slots; int slotCount = slots.Count; boundingBoxes.Clear(); for (int i = 0, n = polygons.Count; i < n; i++) { polygonPool.Add(polygons.Items[i]); } polygons.Clear(); for (int i = 0; i < slotCount; i++) { Slot slot = slots.Items[i]; BoundingBoxAttachment boundingBox = slot.attachment as BoundingBoxAttachment; if (boundingBox == null) { continue; } boundingBoxes.Add(boundingBox); Polygon polygon = null; int poolCount = polygonPool.Count; if (poolCount > 0) { polygon = polygonPool.Items[poolCount - 1]; polygonPool.RemoveAt(poolCount - 1); } else { polygon = new Polygon(); } polygons.Add(polygon); int count = boundingBox.worldVerticesLength; polygon.Count = count; if (polygon.Vertices.Length < count) { polygon.Vertices = new float[count]; } boundingBox.ComputeWorldVertices(slot, polygon.Vertices); } if (updateAabb) { AabbCompute(); } else { minX = int.MinValue; minY = int.MinValue; maxX = int.MaxValue; maxY = int.MaxValue; } }
public void Update(Skeleton skeleton, bool updateAabb) { ExposedList <BoundingBoxAttachment> boundingBoxes = BoundingBoxes; ExposedList <Polygon> polygons = Polygons; ExposedList <Slot> slots = skeleton.slots; int count = slots.Count; boundingBoxes.Clear(); int i = 0; for (int count2 = polygons.Count; i < count2; i++) { polygonPool.Add(polygons.Items[i]); } polygons.Clear(); for (int j = 0; j < count; j++) { Slot slot = slots.Items[j]; BoundingBoxAttachment boundingBoxAttachment = slot.attachment as BoundingBoxAttachment; if (boundingBoxAttachment != null) { boundingBoxes.Add(boundingBoxAttachment); Polygon polygon = null; int count3 = polygonPool.Count; if (count3 > 0) { polygon = polygonPool.Items[count3 - 1]; polygonPool.RemoveAt(count3 - 1); } else { polygon = new Polygon(); } polygons.Add(polygon); int num = polygon.Count = boundingBoxAttachment.worldVerticesLength; if (polygon.Vertices.Length < num) { polygon.Vertices = new float[num]; } boundingBoxAttachment.ComputeWorldVertices(slot, polygon.Vertices); } } if (updateAabb) { AabbCompute(); return; } minX = -2.14748365E+09f; minY = -2.14748365E+09f; maxX = 2.14748365E+09f; maxY = 2.14748365E+09f; }
public ExposedList <int> Triangulate(ExposedList <float> verticesArray) { float[] items = verticesArray.Items; int newSize = verticesArray.Count >> 1; ExposedList <int> indicesArray = this.indicesArray; indicesArray.Clear(true); int[] indices = indicesArray.Resize(newSize).Items; for (int i = 0; i < newSize; i++) { indices[i] = i; } ExposedList <bool> isConcaveArray = this.isConcaveArray; bool[] flagArray = isConcaveArray.Resize(newSize).Items; int index = 0; int num4 = newSize; while (index < num4) { flagArray[index] = IsConcave(index, newSize, items, indices); index++; } ExposedList <int> triangles = this.triangles; triangles.Clear(true); triangles.EnsureCapacity(Math.Max(0, newSize - 2) << 2); while (newSize > 3) { int num5 = newSize - 1; int num6 = 0; int num7 = 1; Label_00B9: if (!flagArray[num6]) { int num8 = indices[num5] << 1; int num9 = indices[num6] << 1; int num10 = indices[num7] << 1; float num11 = items[num8]; float num12 = items[num8 + 1]; float num13 = items[num9]; float num14 = items[num9 + 1]; float num15 = items[num10]; float num16 = items[num10 + 1]; for (int j = (num7 + 1) % newSize; j != num5; j = (j + 1) % newSize) { if (flagArray[j]) { int num18 = indices[j] << 1; float num19 = items[num18]; float num20 = items[num18 + 1]; if ((PositiveArea(num15, num16, num11, num12, num19, num20) && PositiveArea(num11, num12, num13, num14, num19, num20)) && PositiveArea(num13, num14, num15, num16, num19, num20)) { goto Label_0194; } } } goto Label_01D2; } Label_0194: if (num7 == 0) { do { if (!flagArray[num6]) { break; } num6--; }while (num6 > 0); } else { num5 = num6; num6 = num7; num7 = (num7 + 1) % newSize; goto Label_00B9; } Label_01D2: triangles.Add(indices[((newSize + num6) - 1) % newSize]); triangles.Add(indices[num6]); triangles.Add(indices[(num6 + 1) % newSize]); indicesArray.RemoveAt(num6); isConcaveArray.RemoveAt(num6); newSize--; int num21 = ((newSize + num6) - 1) % newSize; int num22 = (num6 != newSize) ? num6 : 0; flagArray[num21] = IsConcave(num21, newSize, items, indices); flagArray[num22] = IsConcave(num22, newSize, items, indices); } if (newSize == 3) { triangles.Add(indices[2]); triangles.Add(indices[0]); triangles.Add(indices[1]); } return(triangles); }
public ExposedList <ExposedList <float> > Decompose(ExposedList <float> verticesArray, ExposedList <int> triangles) { float[] items = verticesArray.Items; ExposedList <ExposedList <float> > convexPolygons = this.convexPolygons; int index = 0; int count = convexPolygons.Count; while (index < count) { this.polygonPool.Free(convexPolygons.Items[index]); index++; } convexPolygons.Clear(true); ExposedList <ExposedList <int> > convexPolygonsIndices = this.convexPolygonsIndices; int num3 = 0; int num4 = convexPolygonsIndices.Count; while (num3 < num4) { this.polygonIndicesPool.Free(convexPolygonsIndices.Items[num3]); num3++; } convexPolygonsIndices.Clear(true); ExposedList <int> item = this.polygonIndicesPool.Obtain(); item.Clear(true); ExposedList <float> list4 = this.polygonPool.Obtain(); list4.Clear(true); int num5 = -1; int num6 = 0; int[] numArray2 = triangles.Items; int num7 = 0; int num8 = triangles.Count; while (num7 < num8) { int num9 = numArray2[num7] << 1; int num10 = numArray2[num7 + 1] << 1; int num11 = numArray2[num7 + 2] << 1; float num12 = items[num9]; float num13 = items[num9 + 1]; float num14 = items[num10]; float num15 = items[num10 + 1]; float num16 = items[num11]; float num17 = items[num11 + 1]; bool flag = false; if (num5 == num9) { int num18 = list4.Count - 4; float[] numArray3 = list4.Items; int num19 = Winding(numArray3[num18], numArray3[num18 + 1], numArray3[num18 + 2], numArray3[num18 + 3], num16, num17); int num20 = Winding(num16, num17, numArray3[0], numArray3[1], numArray3[2], numArray3[3]); if ((num19 == num6) && (num20 == num6)) { list4.Add(num16); list4.Add(num17); item.Add(num11); flag = true; } } if (!flag) { if (list4.Count > 0) { convexPolygons.Add(list4); convexPolygonsIndices.Add(item); } else { this.polygonPool.Free(list4); this.polygonIndicesPool.Free(item); } list4 = this.polygonPool.Obtain(); list4.Clear(true); list4.Add(num12); list4.Add(num13); list4.Add(num14); list4.Add(num15); list4.Add(num16); list4.Add(num17); item = this.polygonIndicesPool.Obtain(); item.Clear(true); item.Add(num9); item.Add(num10); item.Add(num11); num6 = Winding(num12, num13, num14, num15, num16, num17); num5 = num9; } num7 += 3; } if (list4.Count > 0) { convexPolygons.Add(list4); convexPolygonsIndices.Add(item); } int num21 = 0; int num22 = convexPolygons.Count; while (num21 < num22) { item = convexPolygonsIndices.Items[num21]; if (item.Count != 0) { int num23 = item.Items[0]; int num24 = item.Items[item.Count - 1]; list4 = convexPolygons.Items[num21]; int num25 = list4.Count - 4; float[] numArray4 = list4.Items; float num26 = numArray4[num25]; float num27 = numArray4[num25 + 1]; float num28 = numArray4[num25 + 2]; float num29 = numArray4[num25 + 3]; float num30 = numArray4[0]; float num31 = numArray4[1]; float num32 = numArray4[2]; float num33 = numArray4[3]; int num34 = Winding(num26, num27, num28, num29, num30, num31); for (int j = 0; j < num22; j++) { if (j != num21) { ExposedList <int> list5 = convexPolygonsIndices.Items[j]; if (list5.Count == 3) { int num36 = list5.Items[0]; int num37 = list5.Items[1]; int num38 = list5.Items[2]; ExposedList <float> list6 = convexPolygons.Items[j]; float num39 = list6.Items[list6.Count - 2]; float num40 = list6.Items[list6.Count - 1]; if ((num36 == num23) && (num37 == num24)) { int num41 = Winding(num26, num27, num28, num29, num39, num40); int num42 = Winding(num39, num40, num30, num31, num32, num33); if ((num41 == num34) && (num42 == num34)) { list6.Clear(true); list5.Clear(true); list4.Add(num39); list4.Add(num40); item.Add(num38); num26 = num28; num27 = num29; num28 = num39; num29 = num40; j = 0; } } } } } } num21++; } for (int i = convexPolygons.Count - 1; i >= 0; i--) { list4 = convexPolygons.Items[i]; if (list4.Count == 0) { convexPolygons.RemoveAt(i); this.polygonPool.Free(list4); item = convexPolygonsIndices.Items[i]; convexPolygonsIndices.RemoveAt(i); this.polygonIndicesPool.Free(item); } } return(convexPolygons); }
public ExposedList <int> Triangulate(ExposedList <float> verticesArray) { float[] items = verticesArray.Items; int num = verticesArray.Count >> 1; ExposedList <int> exposedList = indicesArray; exposedList.Clear(); int[] items2 = exposedList.Resize(num).Items; for (int i = 0; i < num; i++) { items2[i] = i; } ExposedList <bool> exposedList2 = isConcaveArray; bool[] items3 = exposedList2.Resize(num).Items; int j = 0; for (int num2 = num; j < num2; j++) { items3[j] = IsConcave(j, num, items, items2); } ExposedList <int> exposedList3 = triangles; exposedList3.Clear(); exposedList3.EnsureCapacity(Math.Max(0, num - 2) << 2); while (num > 3) { int num3 = num - 1; int num4 = 0; int num5 = 1; while (true) { if (!items3[num4]) { int num6 = items2[num3] << 1; int num7 = items2[num4] << 1; int num8 = items2[num5] << 1; float num9 = items[num6]; float num10 = items[num6 + 1]; float num11 = items[num7]; float num12 = items[num7 + 1]; float num13 = items[num8]; float num14 = items[num8 + 1]; for (int num15 = (num5 + 1) % num; num15 != num3; num15 = (num15 + 1) % num) { if (!items3[num15]) { continue; } int num16 = items2[num15] << 1; float p3x = items[num16]; float p3y = items[num16 + 1]; if (!PositiveArea(num13, num14, num9, num10, p3x, p3y) || !PositiveArea(num9, num10, num11, num12, p3x, p3y) || !PositiveArea(num11, num12, num13, num14, p3x, p3y)) { continue; } goto IL_0194; } break; } goto IL_0194; IL_0194: if (num5 == 0) { while (items3[num4]) { num4--; if (num4 <= 0) { break; } } break; } num3 = num4; num4 = num5; num5 = (num5 + 1) % num; } exposedList3.Add(items2[(num + num4 - 1) % num]); exposedList3.Add(items2[num4]); exposedList3.Add(items2[(num4 + 1) % num]); exposedList.RemoveAt(num4); exposedList2.RemoveAt(num4); num--; int num17 = (num + num4 - 1) % num; int num18 = (num4 != num) ? num4 : 0; items3[num17] = IsConcave(num17, num, items, items2); items3[num18] = IsConcave(num18, num, items, items2); } if (num == 3) { exposedList3.Add(items2[2]); exposedList3.Add(items2[0]); exposedList3.Add(items2[1]); } return(exposedList3); }
public ExposedList <ExposedList <float> > Decompose(ExposedList <float> verticesArray, ExposedList <int> triangles) { float[] items = verticesArray.Items; ExposedList <ExposedList <float> > exposedList = convexPolygons; int i = 0; for (int count = exposedList.Count; i < count; i++) { polygonPool.Free(exposedList.Items[i]); } exposedList.Clear(); ExposedList <ExposedList <int> > exposedList2 = convexPolygonsIndices; int j = 0; for (int count2 = exposedList2.Count; j < count2; j++) { polygonIndicesPool.Free(exposedList2.Items[j]); } exposedList2.Clear(); ExposedList <int> exposedList3 = polygonIndicesPool.Obtain(); exposedList3.Clear(); ExposedList <float> exposedList4 = polygonPool.Obtain(); exposedList4.Clear(); int num = -1; int num2 = 0; int[] items2 = triangles.Items; int k = 0; for (int count3 = triangles.Count; k < count3; k += 3) { int num3 = items2[k] << 1; int num4 = items2[k + 1] << 1; int num5 = items2[k + 2] << 1; float num6 = items[num3]; float num7 = items[num3 + 1]; float num8 = items[num4]; float num9 = items[num4 + 1]; float num10 = items[num5]; float num11 = items[num5 + 1]; bool flag = false; if (num == num3) { int num12 = exposedList4.Count - 4; float[] items3 = exposedList4.Items; int num13 = Winding(items3[num12], items3[num12 + 1], items3[num12 + 2], items3[num12 + 3], num10, num11); int num14 = Winding(num10, num11, items3[0], items3[1], items3[2], items3[3]); if (num13 == num2 && num14 == num2) { exposedList4.Add(num10); exposedList4.Add(num11); exposedList3.Add(num5); flag = true; } } if (!flag) { if (exposedList4.Count > 0) { exposedList.Add(exposedList4); exposedList2.Add(exposedList3); } else { polygonPool.Free(exposedList4); polygonIndicesPool.Free(exposedList3); } exposedList4 = polygonPool.Obtain(); exposedList4.Clear(); exposedList4.Add(num6); exposedList4.Add(num7); exposedList4.Add(num8); exposedList4.Add(num9); exposedList4.Add(num10); exposedList4.Add(num11); exposedList3 = polygonIndicesPool.Obtain(); exposedList3.Clear(); exposedList3.Add(num3); exposedList3.Add(num4); exposedList3.Add(num5); num2 = Winding(num6, num7, num8, num9, num10, num11); num = num3; } } if (exposedList4.Count > 0) { exposedList.Add(exposedList4); exposedList2.Add(exposedList3); } int l = 0; for (int count4 = exposedList.Count; l < count4; l++) { exposedList3 = exposedList2.Items[l]; if (exposedList3.Count == 0) { continue; } int num15 = exposedList3.Items[0]; int num16 = exposedList3.Items[exposedList3.Count - 1]; exposedList4 = exposedList.Items[l]; int num17 = exposedList4.Count - 4; float[] items4 = exposedList4.Items; float p1x = items4[num17]; float p1y = items4[num17 + 1]; float num18 = items4[num17 + 2]; float num19 = items4[num17 + 3]; float num20 = items4[0]; float num21 = items4[1]; float p3x = items4[2]; float p3y = items4[3]; int num22 = Winding(p1x, p1y, num18, num19, num20, num21); for (int m = 0; m < count4; m++) { if (m == l) { continue; } ExposedList <int> exposedList5 = exposedList2.Items[m]; if (exposedList5.Count != 3) { continue; } int num23 = exposedList5.Items[0]; int num24 = exposedList5.Items[1]; int item = exposedList5.Items[2]; ExposedList <float> exposedList6 = exposedList.Items[m]; float num25 = exposedList6.Items[exposedList6.Count - 2]; float num26 = exposedList6.Items[exposedList6.Count - 1]; if (num23 == num15 && num24 == num16) { int num27 = Winding(p1x, p1y, num18, num19, num25, num26); int num28 = Winding(num25, num26, num20, num21, p3x, p3y); if (num27 == num22 && num28 == num22) { exposedList6.Clear(); exposedList5.Clear(); exposedList4.Add(num25); exposedList4.Add(num26); exposedList3.Add(item); p1x = num18; p1y = num19; num18 = num25; num19 = num26; m = 0; } } } } for (int num29 = exposedList.Count - 1; num29 >= 0; num29--) { exposedList4 = exposedList.Items[num29]; if (exposedList4.Count == 0) { exposedList.RemoveAt(num29); polygonPool.Free(exposedList4); exposedList3 = exposedList2.Items[num29]; exposedList2.RemoveAt(num29); polygonIndicesPool.Free(exposedList3); } } return(exposedList); }