static int Resize(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); Spine.ExposedList <Spine.Animation> obj = (Spine.ExposedList <Spine.Animation>)ToLua.CheckObject <Spine.ExposedList <Spine.Animation> >(L, 1); int arg0 = (int)LuaDLL.luaL_checknumber(L, 2); Spine.ExposedList <Spine.Animation> o = obj.Resize(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
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 void ClipTriangles(float[] vertices, int verticesLength, int[] triangles, int trianglesLength, float[] uvs) { ExposedList <float> clipOutput = this.clipOutput; ExposedList <float> clippedVertices = this.clippedVertices; ExposedList <int> clippedTriangles = this.clippedTriangles; ExposedList <float>[] items = this.clippingPolygons.Items; int count = this.clippingPolygons.Count; int num2 = 0; clippedVertices.Clear(true); this.clippedUVs.Clear(true); clippedTriangles.Clear(true); for (int i = 0; i < trianglesLength; i += 3) { int index = triangles[i] << 1; float num5 = vertices[index]; float num6 = vertices[index + 1]; float num7 = uvs[index]; float num8 = uvs[index + 1]; index = triangles[i + 1] << 1; float num9 = vertices[index]; float num10 = vertices[index + 1]; float num11 = uvs[index]; float num12 = uvs[index + 1]; index = triangles[i + 2] << 1; float num13 = vertices[index]; float num14 = vertices[index + 1]; float num15 = uvs[index]; float num16 = uvs[index + 1]; for (int j = 0; j < count; j++) { int num18 = clippedVertices.Count; if (this.Clip(num5, num6, num9, num10, num13, num14, items[j], clipOutput)) { int num19 = clipOutput.Count; if (num19 != 0) { float num20 = num10 - num14; float num21 = num13 - num9; float num22 = num5 - num13; float num23 = num14 - num6; float num24 = 1f / ((num20 * num22) + (num21 * (num6 - num14))); int num25 = num19 >> 1; float[] numArray = clipOutput.Items; float[] numArray2 = clippedVertices.Resize(num18 + (num25 * 2)).Items; float[] numArray3 = this.clippedUVs.Resize(num18 + (num25 * 2)).Items; for (int k = 0; k < num19; k += 2) { float num27 = numArray[k]; float num28 = numArray[k + 1]; numArray2[num18] = num27; numArray2[num18 + 1] = num28; float num29 = num27 - num13; float num30 = num28 - num14; float num31 = ((num20 * num29) + (num21 * num30)) * num24; float num32 = ((num23 * num29) + (num22 * num30)) * num24; float num33 = (1f - num31) - num32; numArray3[num18] = ((num7 * num31) + (num11 * num32)) + (num15 * num33); numArray3[num18 + 1] = ((num8 * num31) + (num12 * num32)) + (num16 * num33); num18 += 2; } num18 = clippedTriangles.Count; int[] numArray4 = clippedTriangles.Resize(num18 + (3 * (num25 - 2))).Items; num25--; for (int m = 1; m < num25; m++) { numArray4[num18] = num2; numArray4[num18 + 1] = num2 + m; numArray4[num18 + 2] = (num2 + m) + 1; num18 += 3; } num2 += num25 + 1; } } else { float[] numArray5 = clippedVertices.Resize(num18 + 6).Items; float[] numArray6 = this.clippedUVs.Resize(num18 + 6).Items; numArray5[num18] = num5; numArray5[num18 + 1] = num6; numArray5[num18 + 2] = num9; numArray5[num18 + 3] = num10; numArray5[num18 + 4] = num13; numArray5[num18 + 5] = num14; numArray6[num18] = num7; numArray6[num18 + 1] = num8; numArray6[num18 + 2] = num11; numArray6[num18 + 3] = num12; numArray6[num18 + 4] = num15; numArray6[num18 + 5] = num16; num18 = clippedTriangles.Count; int[] numArray7 = clippedTriangles.Resize(num18 + 3).Items; numArray7[num18] = num2; numArray7[num18 + 1] = num2 + 1; numArray7[num18 + 2] = num2 + 2; num2 += 3; break; } } } }
internal bool Clip(float x1, float y1, float x2, float y2, float x3, float y3, ExposedList <float> clippingArea, ExposedList <float> output) { ExposedList <float> list = output; bool flag = false; ExposedList <float> scratch = null; if ((clippingArea.Count % 4) >= 2) { scratch = output; output = this.scratch; } else { scratch = this.scratch; } scratch.Clear(true); scratch.Add(x1); scratch.Add(y1); scratch.Add(x2); scratch.Add(y2); scratch.Add(x3); scratch.Add(y3); scratch.Add(x1); scratch.Add(y1); output.Clear(true); float[] items = clippingArea.Items; int num = clippingArea.Count - 4; int index = 0; while (true) { float num3 = items[index]; float num4 = items[index + 1]; float num5 = items[index + 2]; float num6 = items[index + 3]; float num7 = num3 - num5; float num8 = num4 - num6; float[] numArray2 = scratch.Items; int num9 = scratch.Count - 2; int count = output.Count; for (int i = 0; i < num9; i += 2) { float num12 = numArray2[i]; float num13 = numArray2[i + 1]; float item = numArray2[i + 2]; float num15 = numArray2[i + 3]; bool flag2 = ((num7 * (num15 - num6)) - (num8 * (item - num5))) > 0f; if (((num7 * (num13 - num6)) - (num8 * (num12 - num5))) > 0f) { if (flag2) { output.Add(item); output.Add(num15); continue; } float num16 = num15 - num13; float num17 = item - num12; float num18 = ((num17 * (num4 - num13)) - (num16 * (num3 - num12))) / ((num16 * (num5 - num3)) - (num17 * (num6 - num4))); output.Add(num3 + ((num5 - num3) * num18)); output.Add(num4 + ((num6 - num4) * num18)); } else if (flag2) { float num19 = num15 - num13; float num20 = item - num12; float num21 = ((num20 * (num4 - num13)) - (num19 * (num3 - num12))) / ((num19 * (num5 - num3)) - (num20 * (num6 - num4))); output.Add(num3 + ((num5 - num3) * num21)); output.Add(num4 + ((num6 - num4) * num21)); output.Add(item); output.Add(num15); } flag = true; } if (count == output.Count) { list.Clear(true); return(true); } output.Add(output.Items[0]); output.Add(output.Items[1]); if (index == num) { break; } ExposedList <float> list3 = output; output = scratch; output.Clear(true); scratch = list3; index += 2; } if (list != output) { list.Clear(true); int num22 = 0; int num23 = output.Count - 2; while (num22 < num23) { list.Add(output.Items[num22]); num22++; } return(flag); } list.Resize(list.Count - 2); return(flag); }
public void ClipTriangles(float[] vertices, int verticesLength, int[] triangles, int trianglesLength, float[] uvs) { ExposedList <float> clipOutput = this.clipOutput, clippedVertices = this.clippedVertices; var clippedTriangles = this.clippedTriangles; var polygons = clippingPolygons.Items; int polygonsCount = clippingPolygons.Count; int index = 0; clippedVertices.Clear(); clippedUVs.Clear(); clippedTriangles.Clear(); //outer: // libgdx for (int i = 0; i < trianglesLength; i += 3) { int vertexOffset = triangles[i] << 1; float x1 = vertices[vertexOffset], y1 = vertices[vertexOffset + 1]; float u1 = uvs[vertexOffset], v1 = uvs[vertexOffset + 1]; vertexOffset = triangles[i + 1] << 1; float x2 = vertices[vertexOffset], y2 = vertices[vertexOffset + 1]; float u2 = uvs[vertexOffset], v2 = uvs[vertexOffset + 1]; vertexOffset = triangles[i + 2] << 1; float x3 = vertices[vertexOffset], y3 = vertices[vertexOffset + 1]; float u3 = uvs[vertexOffset], v3 = uvs[vertexOffset + 1]; for (int p = 0; p < polygonsCount; p++) { int s = clippedVertices.Count; if (Clip(x1, y1, x2, y2, x3, y3, polygons[p], clipOutput)) { int clipOutputLength = clipOutput.Count; if (clipOutputLength == 0) { continue; } float d0 = y2 - y3, d1 = x3 - x2, d2 = x1 - x3, d4 = y3 - y1; float d = 1 / (d0 * d2 + d1 * (y1 - y3)); int clipOutputCount = clipOutputLength >> 1; float[] clipOutputItems = clipOutput.Items; float[] clippedVerticesItems = clippedVertices.Resize(s + clipOutputCount * 2).Items; float[] clippedUVsItems = clippedUVs.Resize(s + clipOutputCount * 2).Items; for (int ii = 0; ii < clipOutputLength; ii += 2) { float x = clipOutputItems[ii], y = clipOutputItems[ii + 1]; clippedVerticesItems[s] = x; clippedVerticesItems[s + 1] = y; float c0 = x - x3, c1 = y - y3; float a = (d0 * c0 + d1 * c1) * d; float b = (d4 * c0 + d2 * c1) * d; float c = 1 - a - b; clippedUVsItems[s] = u1 * a + u2 * b + u3 * c; clippedUVsItems[s + 1] = v1 * a + v2 * b + v3 * c; s += 2; } s = clippedTriangles.Count; int[] clippedTrianglesItems = clippedTriangles.Resize(s + 3 * (clipOutputCount - 2)).Items; clipOutputCount--; for (int ii = 1; ii < clipOutputCount; ii++) { clippedTrianglesItems[s] = index; clippedTrianglesItems[s + 1] = index + ii; clippedTrianglesItems[s + 2] = index + ii + 1; s += 3; } index += clipOutputCount + 1; } else { float[] clippedVerticesItems = clippedVertices.Resize(s + 3 * 2).Items; float[] clippedUVsItems = clippedUVs.Resize(s + 3 * 2).Items; clippedVerticesItems[s] = x1; clippedVerticesItems[s + 1] = y1; clippedVerticesItems[s + 2] = x2; clippedVerticesItems[s + 3] = y2; clippedVerticesItems[s + 4] = x3; clippedVerticesItems[s + 5] = y3; clippedUVsItems[s] = u1; clippedUVsItems[s + 1] = v1; clippedUVsItems[s + 2] = u2; clippedUVsItems[s + 3] = v2; clippedUVsItems[s + 4] = u3; clippedUVsItems[s + 5] = v3; s = clippedTriangles.Count; int[] clippedTrianglesItems = clippedTriangles.Resize(s + 3).Items; clippedTrianglesItems[s] = index; clippedTrianglesItems[s + 1] = index + 1; clippedTrianglesItems[s + 2] = index + 2; index += 3; break; //continue outer; } } } }
private float[] ComputeWorldPositions(PathAttachment path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing) { Slot slot = target; float num = position; float[] items = spaces.Items; float[] items2 = positions.Resize(spacesCount * 3 + 2).Items; bool closed = path.Closed; int worldVerticesLength = path.WorldVerticesLength; int num2 = worldVerticesLength / 6; int num3 = -1; float[] items3; float num4; if (!path.ConstantSpeed) { float[] array = path.Lengths; num2 -= (closed ? 1 : 2); num4 = array[num2]; if (percentPosition) { num *= num4; } if (percentSpacing) { for (int i = 0; i < spacesCount; i++) { items[i] *= num4; } } items3 = world.Resize(8).Items; int j = 0; int k = 0; int num5 = 0; for (; j < spacesCount; j++, k += 3) { float num6 = items[j]; num += num6; float num7 = num; if (closed) { num7 %= num4; if (num7 < 0f) { num7 += num4; } num5 = 0; } else { if (num7 < 0f) { if (num3 != -2) { num3 = -2; path.ComputeWorldVertices(slot, 2, 4, items3, 0); } AddBeforePosition(num7, items3, 0, items2, k); continue; } if (num7 > num4) { if (num3 != -3) { num3 = -3; path.ComputeWorldVertices(slot, worldVerticesLength - 6, 4, items3, 0); } AddAfterPosition(num7 - num4, items3, 0, items2, k); continue; } } float num8; while (true) { num8 = array[num5]; if (!(num7 > num8)) { break; } num5++; } if (num5 == 0) { num7 /= num8; } else { float num9 = array[num5 - 1]; num7 = (num7 - num9) / (num8 - num9); } if (num5 != num3) { num3 = num5; if (closed && num5 == num2) { path.ComputeWorldVertices(slot, worldVerticesLength - 4, 4, items3, 0); path.ComputeWorldVertices(slot, 0, 4, items3, 4); } else { path.ComputeWorldVertices(slot, num5 * 6 + 2, 8, items3, 0); } } AddCurvePosition(num7, items3[0], items3[1], items3[2], items3[3], items3[4], items3[5], items3[6], items3[7], items2, k, tangents || (j > 0 && num6 == 0f)); } return(items2); } if (closed) { worldVerticesLength += 2; items3 = world.Resize(worldVerticesLength).Items; path.ComputeWorldVertices(slot, 2, worldVerticesLength - 4, items3, 0); path.ComputeWorldVertices(slot, 0, 2, items3, worldVerticesLength - 4); items3[worldVerticesLength - 2] = items3[0]; items3[worldVerticesLength - 1] = items3[1]; } else { num2--; worldVerticesLength -= 4; items3 = world.Resize(worldVerticesLength).Items; path.ComputeWorldVertices(slot, 2, worldVerticesLength, items3, 0); } float[] items4 = curves.Resize(num2).Items; num4 = 0f; float num10 = items3[0]; float num11 = items3[1]; float num12 = 0f; float num13 = 0f; float num14 = 0f; float num15 = 0f; float num16 = 0f; float num17 = 0f; int num18 = 0; int num19 = 2; while (num18 < num2) { num12 = items3[num19]; num13 = items3[num19 + 1]; num14 = items3[num19 + 2]; num15 = items3[num19 + 3]; num16 = items3[num19 + 4]; num17 = items3[num19 + 5]; float num20 = (num10 - num12 * 2f + num14) * 0.1875f; float num21 = (num11 - num13 * 2f + num15) * 0.1875f; float num22 = ((num12 - num14) * 3f - num10 + num16) * (3f / 32f); float num23 = ((num13 - num15) * 3f - num11 + num17) * (3f / 32f); float num24 = num20 * 2f + num22; float num25 = num21 * 2f + num23; float num26 = (num12 - num10) * 0.75f + num20 + num22 * (355f / (678f * (float)Math.PI)); float num27 = (num13 - num11) * 0.75f + num21 + num23 * (355f / (678f * (float)Math.PI)); num4 += (float)Math.Sqrt(num26 * num26 + num27 * num27); num26 += num24; num27 += num25; num24 += num22; num25 += num23; num4 += (float)Math.Sqrt(num26 * num26 + num27 * num27); num26 += num24; num27 += num25; num4 += (float)Math.Sqrt(num26 * num26 + num27 * num27); num26 += num24 + num22; num27 += num25 + num23; num4 = (items4[num18] = num4 + (float)Math.Sqrt(num26 * num26 + num27 * num27)); num10 = num16; num11 = num17; num18++; num19 += 6; } if (percentPosition) { num *= num4; } if (percentSpacing) { for (int l = 0; l < spacesCount; l++) { items[l] *= num4; } } float[] array2 = segments; float num28 = 0f; int m = 0; int n = 0; int num29 = 0; int num30 = 0; for (; m < spacesCount; m++, n += 3) { float num31 = items[m]; num += num31; float num32 = num; if (closed) { num32 %= num4; if (num32 < 0f) { num32 += num4; } num29 = 0; } else { if (num32 < 0f) { AddBeforePosition(num32, items3, 0, items2, n); continue; } if (num32 > num4) { AddAfterPosition(num32 - num4, items3, worldVerticesLength - 4, items2, n); continue; } } float num33; while (true) { num33 = items4[num29]; if (!(num32 > num33)) { break; } num29++; } if (num29 == 0) { num32 /= num33; } else { float num34 = items4[num29 - 1]; num32 = (num32 - num34) / (num33 - num34); } if (num29 != num3) { num3 = num29; int num35 = num29 * 6; num10 = items3[num35]; num11 = items3[num35 + 1]; num12 = items3[num35 + 2]; num13 = items3[num35 + 3]; num14 = items3[num35 + 4]; num15 = items3[num35 + 5]; num16 = items3[num35 + 6]; num17 = items3[num35 + 7]; float num20 = (num10 - num12 * 2f + num14) * 0.03f; float num21 = (num11 - num13 * 2f + num15) * 0.03f; float num22 = ((num12 - num14) * 3f - num10 + num16) * 0.006f; float num23 = ((num13 - num15) * 3f - num11 + num17) * 0.006f; float num24 = num20 * 2f + num22; float num25 = num21 * 2f + num23; float num26 = (num12 - num10) * 0.3f + num20 + num22 * (355f / (678f * (float)Math.PI)); float num27 = (num13 - num11) * 0.3f + num21 + num23 * (355f / (678f * (float)Math.PI)); num28 = (array2[0] = (float)Math.Sqrt(num26 * num26 + num27 * num27)); for (num35 = 1; num35 < 8; num35++) { num26 += num24; num27 += num25; num24 += num22; num25 += num23; num28 = (array2[num35] = num28 + (float)Math.Sqrt(num26 * num26 + num27 * num27)); } num26 += num24; num27 += num25; num28 = (array2[8] = num28 + (float)Math.Sqrt(num26 * num26 + num27 * num27)); num26 += num24 + num22; num27 += num25 + num23; num28 = (array2[9] = num28 + (float)Math.Sqrt(num26 * num26 + num27 * num27)); num30 = 0; } num32 *= num28; float num36; while (true) { num36 = array2[num30]; if (!(num32 > num36)) { break; } num30++; } if (num30 == 0) { num32 /= num36; } else { float num37 = array2[num30 - 1]; num32 = (float)num30 + (num32 - num37) / (num36 - num37); } AddCurvePosition(num32 * 0.1f, num10, num11, num12, num13, num14, num15, num16, num17, items2, n, tangents || (m > 0 && num31 == 0f)); } return(items2); }
public void Update() { PathAttachment pathAttachment = target.Attachment as PathAttachment; if (pathAttachment == null) { return; } float num = rotateMix; float num2 = translateMix; bool flag = num2 > 0f; bool flag2 = num > 0f; if (!flag && !flag2) { return; } PathConstraintData pathConstraintData = data; SpacingMode spacingMode = pathConstraintData.spacingMode; bool flag3 = spacingMode == SpacingMode.Length; RotateMode rotateMode = pathConstraintData.rotateMode; bool flag4 = rotateMode == RotateMode.Tangent; bool flag5 = rotateMode == RotateMode.ChainScale; int count = bones.Count; int num3 = (!flag4) ? (count + 1) : count; Bone[] items = bones.Items; ExposedList <float> exposedList = spaces.Resize(num3); ExposedList <float> exposedList2 = null; float num4 = spacing; if (flag5 || flag3) { if (flag5) { exposedList2 = lengths.Resize(count); } int num5 = 0; int num6 = num3 - 1; while (num5 < num6) { Bone bone = items[num5]; float num7 = bone.data.length; if (num7 == 0f) { num7 = 1E-09f; } float num8 = num7 * bone.a; float num9 = num7 * bone.c; float num10 = (float)Math.Sqrt(num8 * num8 + num9 * num9); if (flag5) { exposedList2.Items[num5] = num7; } exposedList.Items[++num5] = ((!flag3) ? num4 : Math.Max(0f, num7 + num4)) * num10 / num7; } } else { for (int i = 1; i < num3; i++) { exposedList.Items[i] = num4; } } float[] array = ComputeWorldPositions(pathAttachment, num3, flag4, pathConstraintData.positionMode == PositionMode.Percent, spacingMode == SpacingMode.Percent); float num11 = array[0]; float num12 = array[1]; float num13 = pathConstraintData.offsetRotation; bool flag6; if (num13 == 0f) { flag6 = (rotateMode == RotateMode.Chain); } else { flag6 = false; Bone bone2 = target.bone; num13 *= ((!(bone2.a * bone2.d - bone2.b * bone2.c > 0f)) ? (-(float)Math.PI / 180f) : ((float)Math.PI / 180f)); } int num14 = 0; int num15 = 3; while (num14 < count) { Bone bone3 = items[num14]; bone3.worldX += (num11 - bone3.worldX) * num2; bone3.worldY += (num12 - bone3.worldY) * num2; float num16 = array[num15]; float num17 = array[num15 + 1]; float num18 = num16 - num11; float num19 = num17 - num12; if (flag5) { float num20 = exposedList2.Items[num14]; if (num20 != 0f) { float num21 = ((float)Math.Sqrt(num18 * num18 + num19 * num19) / num20 - 1f) * num + 1f; bone3.a *= num21; bone3.c *= num21; } } num11 = num16; num12 = num17; if (flag2) { float a = bone3.a; float b = bone3.b; float c = bone3.c; float d = bone3.d; float num22 = flag4 ? array[num15 - 1] : ((exposedList.Items[num14 + 1] != 0f) ? MathUtils.Atan2(num19, num18) : array[num15 + 2]); num22 -= MathUtils.Atan2(c, a); float num23; float num24; if (flag6) { num23 = MathUtils.Cos(num22); num24 = MathUtils.Sin(num22); float length = bone3.data.length; num11 += (length * (num23 * a - num24 * c) - num18) * num; num12 += (length * (num24 * a + num23 * c) - num19) * num; } else { num22 += num13; } if (num22 > (float)Math.PI) { num22 -= (float)Math.PI * 2f; } else if (num22 < -(float)Math.PI) { num22 += (float)Math.PI * 2f; } num22 *= num; num23 = MathUtils.Cos(num22); num24 = MathUtils.Sin(num22); bone3.a = num23 * a - num24 * c; bone3.b = num23 * b - num24 * d; bone3.c = num24 * a + num23 * c; bone3.d = num24 * b + num23 * d; } bone3.appliedValid = false; num14++; num15 += 3; } }