public void Go(MeshExploder.MeshExplosionPreparation prep, float minSpeed, float maxSpeed, float minRotationSpeed, float maxRotationSpeed, bool useGravity, Vector3 scale) { preparation = prep; var frontTriangles = prep.totalFrontTriangles; triangleRotationAxes = new Vector3[frontTriangles]; triangleSpeeds = new float[frontTriangles]; triangleRotationSpeeds = new float[frontTriangles]; var deltaSpeed = maxSpeed - minSpeed; var deltaRotationSpeed = maxRotationSpeed - minRotationSpeed; var fixedSpeed = minSpeed == maxSpeed; var fixedRotationSpeed = minRotationSpeed == maxRotationSpeed; this.useGravity = useGravity; explosionTime = 0; thisTransform = transform; for (var triangleNumber = 0; triangleNumber < frontTriangles; ++triangleNumber) { triangleRotationAxes[triangleNumber] = Random.onUnitSphere; triangleSpeeds[triangleNumber] = fixedSpeed ? minSpeed : minSpeed + Random.value * deltaSpeed; triangleRotationSpeeds[triangleNumber] = fixedRotationSpeed ? minRotationSpeed : minRotationSpeed + Random.value * deltaRotationSpeed; } GetComponent<MeshFilter>().mesh = mesh = (Mesh)Object.Instantiate(prep.startMesh); triangleCurrentCentroids = (Vector3[])prep.triangleCentroids.Clone(); // It might seem like a waste of memory to keep a copy of these arrays, but actually // retrieving them allocates new garbage collected memory every time so it's much better to // just retrieve them once rather than retrieving them every frame and creating lots of // garbage. vertices = mesh.vertices; normals = mesh.normals; tangents = mesh.tangents; if (scale != Vector3.one) { { var n = vertices.Length; for (var i = 0; i < n; ++i) { vertices[i] = Vector3.Scale(vertices[i], scale); } } { var n = triangleCurrentCentroids.Length; for (var i = 0; i < n; ++i) { triangleCurrentCentroids[i] = Vector3.Scale(triangleCurrentCentroids[i], scale); } } } // Do one frame of explosion to start it off. Update(); }
public void Go(MeshExploder.MeshExplosionPreparation prep, float minSpeed, float maxSpeed, float minRotationSpeed, float maxRotationSpeed, bool useGravity) { preparation = prep; var frontTriangles = prep.totalFrontTriangles; triangleRotationAxes = new Vector3[frontTriangles]; triangleSpeeds = new float[frontTriangles]; triangleRotationSpeeds = new float[frontTriangles]; var deltaSpeed = maxSpeed - minSpeed; var deltaRotationSpeed = maxRotationSpeed - minRotationSpeed; var fixedSpeed = minSpeed == maxSpeed; var fixedRotationSpeed = minRotationSpeed == maxRotationSpeed; this.useGravity = useGravity; explosionTime = 0; thisTransform = transform; for (var triangleNumber = 0; triangleNumber < frontTriangles; ++triangleNumber) { triangleRotationAxes[triangleNumber] = Random.onUnitSphere; triangleSpeeds[triangleNumber] = fixedSpeed ? minSpeed : minSpeed + Random.value * deltaSpeed; triangleRotationSpeeds[triangleNumber] = fixedRotationSpeed ? minRotationSpeed : minRotationSpeed + Random.value * deltaRotationSpeed; } GetComponent <MeshFilter>().mesh = mesh = (Mesh)Object.Instantiate(prep.startMesh); triangleCurrentCentroids = (Vector3[])prep.triangleCentroids.Clone(); // It might seem like a waste of memory to keep a copy of these arrays, but actually // retrieving them allocates new garbage collected memory every time so it's much better to // just retrieve them once rather than retrieving them every frame and creating lots of // garbage. vertices = mesh.vertices; normals = mesh.normals; tangents = mesh.tangents; // Do one frame of explosion to start it off. Update(); }
// Token: 0x06002F6E RID: 12142 RVA: 0x000E6714 File Offset: 0x000E4B14 public void Go(MeshExploder.MeshExplosionPreparation prep, float minSpeed, float maxSpeed, float minRotationSpeed, float maxRotationSpeed, bool useGravity, Vector3 scale) { this.preparation = prep; int totalFrontTriangles = prep.totalFrontTriangles; this.triangleRotationAxes = new Vector3[totalFrontTriangles]; this.triangleSpeeds = new float[totalFrontTriangles]; this.triangleRotationSpeeds = new float[totalFrontTriangles]; float num = maxSpeed - minSpeed; float num2 = maxRotationSpeed - minRotationSpeed; bool flag = minSpeed == maxSpeed; bool flag2 = minRotationSpeed == maxRotationSpeed; this.useGravity = useGravity; this.explosionTime = 0f; this.thisTransform = base.transform; for (int i = 0; i < totalFrontTriangles; i++) { this.triangleRotationAxes[i] = UnityEngine.Random.onUnitSphere; this.triangleSpeeds[i] = ((!flag) ? (minSpeed + UnityEngine.Random.value * num) : minSpeed); this.triangleRotationSpeeds[i] = ((!flag2) ? (minRotationSpeed + UnityEngine.Random.value * num2) : minRotationSpeed); } base.GetComponent <MeshFilter>().mesh = (this.mesh = UnityEngine.Object.Instantiate <Mesh>(prep.startMesh)); this.triangleCurrentCentroids = (Vector3[])prep.triangleCentroids.Clone(); this.vertices = this.mesh.vertices; this.normals = this.mesh.normals; this.tangents = this.mesh.tangents; if (scale != Vector3.one) { int num3 = this.vertices.Length; for (int j = 0; j < num3; j++) { this.vertices[j] = Vector3.Scale(this.vertices[j], scale); } int num4 = this.triangleCurrentCentroids.Length; for (int k = 0; k < num4; k++) { this.triangleCurrentCentroids[k] = Vector3.Scale(this.triangleCurrentCentroids[k], scale); } } this.Update(); }
private void Prepare(Mesh oldMesh, bool cachePreparation = true) { if (!oldMesh.isReadable) { Debug.LogError((object)"The mesh is not readable. Switch on the \"Read/Write Enabled\" option on the mesh's import settings."); } else { bool flag1 = this.type == MeshExploder.ExplosionType.Physics; MeshExploder.MeshExplosionPreparation explosionPreparation; if (MeshExploder.cache.TryGetValue(oldMesh, out explosionPreparation) && (flag1 && explosionPreparation.physicsMeshes != null || !flag1 && (Object)explosionPreparation.startMesh != (Object)null)) { this.preparation = explosionPreparation; } else { Vector3[] vertices1 = oldMesh.vertices; Vector3[] normals1 = oldMesh.normals; Vector4[] tangents1 = oldMesh.tangents; Vector2[] uv = oldMesh.uv; Vector2[] uv2 = oldMesh.uv2; Color[] colors = oldMesh.colors; int subMeshCount = oldMesh.subMeshCount; int[][] numArray1 = new int[subMeshCount][]; int[] numArray2 = !flag1 ? (int[])null : (explosionPreparation.frontMeshTrianglesPerSubMesh = new int[subMeshCount]); int length1 = 0; for (int submesh = 0; submesh < subMeshCount; ++submesh) { int num = (numArray1[submesh] = oldMesh.GetTriangles(submesh)).Length / 3; if (flag1) { numArray2[submesh] = num; } length1 += num; } explosionPreparation.totalFrontTriangles = length1; int num1 = length1 * 2; int length2 = !flag1 ? num1 * 3 : 6; if (length2 > 65534) { Debug.LogError((object)("The mesh has too many triangles to explode. It must have " + (object)10922 + " or fewer triangles.")); } else { Vector3[] vertices2 = new Vector3[length2]; Vector3[] normals2 = normals1 == null || normals1.Length == 0 ? (Vector3[])null : new Vector3[length2]; Vector4[] tangents2 = tangents1 == null || tangents1.Length == 0 ? (Vector4[])null : new Vector4[length2]; Vector2[] vector2Array1 = uv == null || uv.Length == 0 ? (Vector2[])null : new Vector2[length2]; Vector2[] vector2Array2 = uv2 == null || uv2.Length == 0 ? (Vector2[])null : new Vector2[length2]; Color[] colorArray = colors == null || colors.Length == 0 ? (Color[])null : new Color[length2]; Vector3[] vector3Array1 = explosionPreparation.triangleCentroids = new Vector3[length1]; Mesh[] meshArray = explosionPreparation.physicsMeshes = !flag1 ? (Mesh[])null : new Mesh[length1]; Quaternion[] quaternionArray = explosionPreparation.rotations = !flag1 ? (Quaternion[])null : new Quaternion[length1]; int[] numArray3; if (flag1) { numArray3 = new int[6] { 0, 1, 2, 3, 4, 5 } } ; else { numArray3 = (int[])null; } int[] numArray4 = numArray3; int index1 = 0; int index2 = 0; Quaternion quaternion = Quaternion.identity; for (int index3 = 0; index3 < subMeshCount; ++index3) { int[] numArray5 = numArray1[index3]; int length3 = numArray5.Length; int num2 = 0; while (num2 < length3) { int num3 = num2; Vector3 vector3_1 = Vector3.zero; for (int index4 = 0; index4 < 2; ++index4) { num2 = num3; bool flag2 = index4 == 1; while (num2 < length3) { int index5 = numArray5[!flag2 ? num2 : num3 + (2 - (num2 - num3))]; if (flag1 && index1 % 6 == 0) { Vector3 vector3_2 = vertices1[index5]; Vector3 vector3_3 = vertices1[numArray5[num2 + 1]]; Vector3 vector3_4 = vertices1[numArray5[num2 + 2]]; Vector3 vector3_5 = Vector3.Cross(vector3_3 - vector3_2, vector3_4 - vector3_2); quaternionArray[index2] = Quaternion.FromToRotation(Vector3.up, vector3_5); quaternion = Quaternion.FromToRotation(vector3_5, Vector3.up); vector3Array1[index2] = vector3_1 = (vector3_2 + vector3_3 + vector3_4) / 3f; } if (!flag2) { vertices2[index1] = quaternion * (vertices1[index5] - vector3_1); if (normals2 != null) { normals2[index1] = quaternion * normals1[index5]; } if (tangents2 != null) { tangents2[index1] = (Vector4)(quaternion * (Vector3)tangents1[index5]); } } if (vector2Array1 != null) { vector2Array1[index1] = uv[index5]; } if (vector2Array2 != null) { vector2Array2[index1] = uv2[index5]; } if (colorArray != null) { colorArray[index1] = colors[index5]; } ++num2; ++index1; if (index1 % 6 == 0) { if (flag1) { MeshExplosion.SetBackTriangleVertices(vertices2, normals2, tangents2, 1); Mesh mesh = new Mesh(); mesh.vertices = vertices2; if (normals2 != null) { mesh.normals = normals2; } if (tangents2 != null) { mesh.tangents = tangents2; } if (vector2Array1 != null) { mesh.uv = vector2Array1; } if (vector2Array2 != null) { mesh.uv2 = vector2Array2; } if (colorArray != null) { mesh.colors = colorArray; } mesh.triangles = numArray4; meshArray[index2] = mesh; index1 = 0; break; } break; } if (index1 % 3 == 0 && !flag2) { break; } } } ++index2; } } Vector3 vector3_6 = Vector3.zero; if (!flag1) { Mesh mesh = explosionPreparation.startMesh = new Mesh(); mesh.MarkDynamic(); mesh.vertices = vertices2; if (normals2 != null) { mesh.normals = normals2; } if (tangents2 != null) { mesh.tangents = tangents2; } if (vector2Array1 != null) { mesh.uv = vector2Array1; } if (vector2Array2 != null) { mesh.uv2 = vector2Array2; } if (colorArray != null) { mesh.colors = colorArray; } mesh.subMeshCount = subMeshCount; int num2 = 0; for (int submesh = 0; submesh < subMeshCount; ++submesh) { int length3 = numArray1[submesh].Length * 2; int[] triangles = new int[length3]; int index3 = 0; while (index3 < length3) { triangles[index3] = num2; ++index3; ++num2; } mesh.SetTriangles(triangles, submesh); } if (this.useMeshBoundsCenter) { vector3_6 = mesh.bounds.center; } } Vector3[] vector3Array2 = explosionPreparation.triangleNormals = new Vector3[length1]; int index6 = 0; int index7 = 0; while (index7 < length1) { Vector3 vector3_1; if (flag1) { vector3_1 = vector3Array1[index7]; } else { vector3_1 = (vertices2[index6] + vertices2[index6 + 1] + vertices2[index6 + 2]) / 3f; vector3Array1[index7] = vector3_1; } Vector3 vector3_2; if (this.useNormals && normals2 != null) { if (flag1) { normals2 = meshArray[index7].normals; index6 = 0; } vector3_2 = ((normals2[index6] + normals2[index6 + 1] + normals2[index6 + 2]) / 3f).normalized; } else { vector3_2 = vector3_1; if (this.useMeshBoundsCenter) { vector3_2 -= vector3_6; } vector3_2.Normalize(); } vector3Array2[index7] = vector3_2; ++index7; index6 += 6; } this.preparation = explosionPreparation; if (cachePreparation) { MeshExploder.cache[oldMesh] = explosionPreparation; } if ((double)this.fadeTime == 0.0 || this.shadersAlreadyHandleTransparency) { return; } foreach (Material sharedMaterial in this.GetComponent <Renderer>().sharedMaterials) { Shader shader = sharedMaterial.shader; Shader replacementFor = Fade.GetReplacementFor(shader); if ((Object)replacementFor == (Object)null || !replacementFor.name.StartsWith("Transparent/")) { Debug.LogWarning((object)("Couldn't find an explicitly transparent version of shader '" + shader.name + "' so fading may not work. If the shader does support transparency then this warning can be avoided by enabling the 'Shaders Already Handle Transparency' option.")); } } } } } }