Exemple #1
0
 internal float[] CopyTo(float[] array, int index)
 {
     position.CopyTo(array, index + 0);
     normal.CopyTo(array, index + 3);
     texCoord.CopyTo(array, index + 6);
     return(array);
 }
Exemple #2
0
        public void Vector2CopyToSpanTest()
        {
            Vector2      vector      = new Vector2(1.0f, 2.0f);
            Span <float> destination = new float[2];

            Assert.Throws <ArgumentException>(() => vector.CopyTo(new Span <float>(new float[1])));
            vector.CopyTo(destination);

            Assert.Equal(1.0f, vector.X);
            Assert.Equal(2.0f, vector.Y);
            Assert.Equal(vector.X, destination[0]);
            Assert.Equal(vector.Y, destination[1]);
        }
Exemple #3
0
        public void Vector2CopyToTest()
        {
            Vector2 v1 = new Vector2(2.0f, 3.0f);
            Vector2 v2 = new Vector2(4.5f, 6.5f);

            Single[] a = new Single[3];
            Single[] b = new Single[2];
            v1.CopyTo(a, 1);
            v1.CopyTo(b);
            Assert.Equal(0.0, a[0]);
            Assert.Equal(2.0, a[1]);
            Assert.Equal(3.0, a[2]);
            Assert.Equal(2.0, b[0]);
            Assert.Equal(3.0, b[1]);
        }
Exemple #4
0
        public void Vector2CopyToTest()
        {
            Vector2 v1 = new Vector2(2.0f, 3.0f);
            Vector2 v2 = new Vector2(4.5f, 6.5f);

            Single[] a = new Single[3];
            Single[] b = new Single[2];
            v1.CopyTo(a, 1);
            v1.CopyTo(b);
            Assert.Equal(0.0, a[0]);
            Assert.Equal(2.0, a[1]);
            Assert.Equal(3.0, a[2]);
            Assert.Equal(2.0, b[0]);
            Assert.Equal(3.0, b[1]);
        }
Exemple #5
0
        private Vector2[] GetEdgePath()
        {
            List <Vector2> normals = GetEdgeNormals();

            Vector2[] colliderPoints = ((EdgeCollider2D)myCollider).points;
            Vector2[] edgePoints     = new Vector2[colliderPoints.Length];
            Vector2[] innerPoints    = new Vector2[colliderPoints.Length];
            Vector2[] path;
            bool      open = spline.isOpenEnded;

            int index = 0;

            foreach (Vector2 colliderPoint in colliderPoints)
            {
                edgePoints[index]  = colliderPoint;
                innerPoints[index] = colliderPoint - (normals[index] * edgeWidth);
                index++;
            }

            System.Array.Reverse(innerPoints);

            path = new Vector2[edgePoints.Length * 2];
            edgePoints.CopyTo(path, 0);
            innerPoints.CopyTo(path, edgePoints.Length);

            System.Array.Reverse(path);

            return(path);
        }
Exemple #6
0
        /// <summary>
        /// Flattens a <see cref="Vector2"/> into an array of floats, similar to how the <see cref="IFlattenableData{T}"/>
        /// interface works.
        /// </summary>
        /// <param name="vector2">The vector to flatten.</param>
        /// <returns>An array of floats.</returns>
        public static float[] Flatten(this Vector2 vector2)
        {
            float[] outArr = new float[2];
            vector2.CopyTo(outArr);

            return(outArr);
        }
Exemple #7
0
        public void Vector2CopyToTest()
        {
            Vector2 v1 = new Vector2(2.0f, 3.0f);

            float[] a = new float[3];
            float[] b = new float[2];

            Assert.Throws <NullReferenceException>(() => v1.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => v1.CopyTo(a, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => v1.CopyTo(a, a.Length));

            if (!PlatformDetection.IsNetNative)
            {
                Assert.Throws <ArgumentException>(() => v1.CopyTo(a, 2));
            }
            else
            {
                // The .Net Native code generation optimizer does aggressive optimizations to range checks
                // which result in an ArgumentOutOfRangeException exception being thrown at runtime.
                Assert.ThrowsAny <ArgumentException>(() => v1.CopyTo(a, 2));
            }

            v1.CopyTo(a, 1);
            v1.CopyTo(b);
            Assert.Equal(0.0, a[0]);
            Assert.Equal(2.0, a[1]);
            Assert.Equal(3.0, a[2]);
            Assert.Equal(2.0, b[0]);
            Assert.Equal(3.0, b[1]);
        }
 private void AddTwinsToUvArray()
 {
     Vector2[] OldUvList = mesh.uv;        //what is important here is that there arleady is automaticly-generated uv. We have to ovverride them.
     Vector2[] TwinUv    = new Vector2[OldUvList.Length / 2];
     //int offset = OldUvList.Length/2;
     for (int i = 0; i < OldUvList.Length / 2; i++)
     {
         TwinUv[i] = OldUvList[i];
     }
     TwinUv.CopyTo(OldUvList, OldUvList.Length / 2);
     mesh.uv = OldUvList;
 }
 private static void CheckForResize( Polygon polygon, Vector2[ ] polyCorners, int numberOfCorners ) {
     if( numberOfCorners > polyCorners.Length ) {
         Vector2[ ] newCorners = new Vector2[ numberOfCorners ];
         polyCorners.CopyTo( newCorners, 0 );
         polygon.polygonCorners = newCorners;
     } else if( numberOfCorners < polyCorners.Length ) {
         Vector2[ ] newCorners = new Vector2[ numberOfCorners ];
         for( int i = 0; i < numberOfCorners; i++ ) {
             newCorners[ i ] = polyCorners[ i ];
         }
         polygon.polygonCorners = newCorners;
     }
 }
Exemple #10
0
        public void Vector2CopyToTest()
        {
            Vector2 v1 = new Vector2(2.0f, 3.0f);

            float[] a = new float[3];
            float[] b = new float[2];

            Assert.Throws<NullReferenceException>(() => v1.CopyTo(null, 0));
            Assert.Throws<ArgumentOutOfRangeException>(() => v1.CopyTo(a, -1));
            Assert.Throws<ArgumentOutOfRangeException>(() => v1.CopyTo(a, a.Length));
            Assert.Throws<ArgumentException>(() => v1.CopyTo(a, 2));

            v1.CopyTo(a, 1);
            v1.CopyTo(b);
            Assert.Equal(0.0, a[0]);
            Assert.Equal(2.0, a[1]);
            Assert.Equal(3.0, a[2]);
            Assert.Equal(2.0, b[0]);
            Assert.Equal(3.0, b[1]);
        }
Exemple #11
0
        public void Vector2CopyToTest()
        {
            Vector2 v1 = new Vector2(2.0f, 3.0f);

            float[] a = new float[3];
            float[] b = new float[2];

            Assert.Throws <NullReferenceException>(() => v1.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => v1.CopyTo(a, -1));
            Assert.Throws <ArgumentOutOfRangeException>(() => v1.CopyTo(a, a.Length));
            AssertExtensions.Throws <ArgumentException>(null, () => v1.CopyTo(a, 2));

            v1.CopyTo(a, 1);
            v1.CopyTo(b);
            Assert.Equal(0.0, a[0]);
            Assert.Equal(2.0, a[1]);
            Assert.Equal(3.0, a[2]);
            Assert.Equal(2.0, b[0]);
            Assert.Equal(3.0, b[1]);
        }
Exemple #12
0
    public void Add(string c, OTAtlasData data, Vector3[] verts, Vector2[] uv)
    {
        text+=c;

        int tx = 0;
        string dx = data.GetMeta("dx");
        if (dx=="")
            tx = (int)(data.offset.x + data.size.x);
        else
            tx = System.Convert.ToUInt16(dx);
        txList.Add(tx);
        atlasData.Add(data);

        int tt = 0;
        for (int i=0; i<txList.Count-1; i++)
            tt+=txList[i];

        Matrix4x4 mx = new Matrix4x4();
        mx.SetTRS(new Vector3(tt,0,0), Quaternion.identity, Vector3.one);
        for (int i=0; i<verts.Length; i++)
            verts[i] = mx.MultiplyPoint3x4(verts[i]);

        System.Array.Resize<Vector3>(ref this.verts, this.verts.Length + verts.Length);
        verts.CopyTo(this.verts, this.verts.Length - verts.Length);
        System.Array.Resize<Vector2>(ref this.uv, this.uv.Length + uv.Length);
        uv.CopyTo(this.uv, this.uv.Length - uv.Length);
    }
 public unsafe void CopyTo(float *destination)
 {
     _point1.CopyTo(destination);
     _point2.CopyTo(destination + sizeof(Vector2));
 }
        public static Mesh GenerateConeZ_Radius(float lengthZ, float radiusStart, float radiusEnd, int numSides, int numSegments, bool cap)
        {
            Debug.Assert(lengthZ > 0f);
            Debug.Assert(radiusStart >= 0f);
            Debug.Assert(numSides >= 3);
            Debug.Assert(numSegments >= 0);
            Mesh mesh = new Mesh();
            bool flag = false;

            flag        = (!cap ? false : radiusStart > 0f);
            radiusStart = Mathf.Max(radiusStart, 0.001f);
            int num  = numSides * (numSegments + 2);
            int num1 = num;

            if (flag)
            {
                num1 = num1 + numSides + 1;
            }
            Vector3[] vector3 = new Vector3[num1];
            for (int i = 0; i < numSides; i++)
            {
                float single  = 6.28318548f * (float)i / (float)numSides;
                float single1 = Mathf.Cos(single);
                float single2 = Mathf.Sin(single);
                for (int j = 0; j < numSegments + 2; j++)
                {
                    float single3 = (float)j / (float)(numSegments + 1);
                    Debug.Assert((single3 < 0f ? false : single3 <= 1f));
                    float single4 = Mathf.Lerp(radiusStart, radiusEnd, single3);
                    vector3[i + j * numSides] = new Vector3(single4 * single1, single4 * single2, single3 * lengthZ);
                }
            }
            if (flag)
            {
                int num2 = num;
                vector3[num2] = Vector3.zero;
                num2++;
                for (int k = 0; k < numSides; k++)
                {
                    float single5 = 6.28318548f * (float)k / (float)numSides;
                    float single6 = Mathf.Cos(single5);
                    float single7 = Mathf.Sin(single5);
                    vector3[num2] = new Vector3(radiusStart * single6, radiusStart * single7, 0f);
                    num2++;
                }
                Debug.Assert(num2 == (int)vector3.Length);
            }
            if (MeshGenerator.duplicateBackFaces)
            {
                Vector3[] vector3Array = new Vector3[(int)vector3.Length * 2];
                vector3.CopyTo(vector3Array, 0);
                vector3.CopyTo(vector3Array, (int)vector3.Length);
                mesh.vertices = vector3Array;
            }
            else
            {
                mesh.vertices = vector3;
            }
            Vector2[] vector2 = new Vector2[num1];
            int       num3    = 0;

            for (int l = 0; l < num; l++)
            {
                int num4 = num3;
                num3          = num4 + 1;
                vector2[num4] = Vector2.zero;
            }
            if (flag)
            {
                for (int m = 0; m < numSides + 1; m++)
                {
                    int num5 = num3;
                    num3          = num5 + 1;
                    vector2[num5] = new Vector2(1f, 0f);
                }
            }
            Debug.Assert(num3 == (int)vector2.Length);
            if (MeshGenerator.duplicateBackFaces)
            {
                Vector2[] vector2Array = new Vector2[(int)vector2.Length * 2];
                vector2.CopyTo(vector2Array, 0);
                vector2.CopyTo(vector2Array, (int)vector2.Length);
                for (int n = 0; n < (int)vector2.Length; n++)
                {
                    Vector2 vector21 = vector2Array[n + (int)vector2.Length];
                    vector2Array[n + (int)vector2.Length] = new Vector2(vector21.x, 1f);
                }
                mesh.uv = vector2Array;
            }
            else
            {
                mesh.uv = vector2;
            }
            int num6 = numSides * 2 * Mathf.Max(numSegments + 1, 1) * 3;

            if (flag)
            {
                num6 = num6 + numSides * 3;
            }
            int[] numArray = new int[num6];
            int   num7     = 0;

            for (int o = 0; o < numSides; o++)
            {
                int num8 = o + 1;
                if (num8 == numSides)
                {
                    num8 = 0;
                }
                for (int p = 0; p < numSegments + 1; p++)
                {
                    int num9  = p * numSides;
                    int num10 = num7;
                    num7            = num10 + 1;
                    numArray[num10] = num9 + o;
                    int num11 = num7;
                    num7            = num11 + 1;
                    numArray[num11] = num9 + num8;
                    int num12 = num7;
                    num7            = num12 + 1;
                    numArray[num12] = num9 + o + numSides;
                    int num13 = num7;
                    num7            = num13 + 1;
                    numArray[num13] = num9 + num8 + numSides;
                    int num14 = num7;
                    num7            = num14 + 1;
                    numArray[num14] = num9 + o + numSides;
                    int num15 = num7;
                    num7            = num15 + 1;
                    numArray[num15] = num9 + num8;
                }
            }
            if (flag)
            {
                for (int q = 0; q < numSides - 1; q++)
                {
                    int num16 = num7;
                    num7            = num16 + 1;
                    numArray[num16] = num;
                    int num17 = num7;
                    num7            = num17 + 1;
                    numArray[num17] = num + q + 2;
                    int num18 = num7;
                    num7            = num18 + 1;
                    numArray[num18] = num + q + 1;
                }
                int num19 = num7;
                num7            = num19 + 1;
                numArray[num19] = num;
                int num20 = num7;
                num7            = num20 + 1;
                numArray[num20] = num + 1;
                int num21 = num7;
                num7            = num21 + 1;
                numArray[num21] = num + numSides;
            }
            Debug.Assert(num7 == (int)numArray.Length);
            if (MeshGenerator.duplicateBackFaces)
            {
                int[] numArray1 = new int[(int)numArray.Length * 2];
                numArray.CopyTo(numArray1, 0);
                for (int r = 0; r < (int)numArray.Length; r += 3)
                {
                    numArray1[(int)numArray.Length + r]     = numArray[r] + num1;
                    numArray1[(int)numArray.Length + r + 1] = numArray[r + 2] + num1;
                    numArray1[(int)numArray.Length + r + 2] = numArray[r + 1] + num1;
                }
                mesh.triangles = numArray1;
            }
            else
            {
                mesh.triangles = numArray;
            }
            Bounds bound = new Bounds(new Vector3(0f, 0f, lengthZ * 0.5f), new Vector3(Mathf.Max(radiusStart, radiusEnd) * 2f, Mathf.Max(radiusStart, radiusEnd) * 2f, lengthZ));

            mesh.bounds = bound;
            Debug.Assert(mesh.vertexCount == MeshGenerator.GetVertexCount(numSides, numSegments, flag));
            Debug.Assert((int)mesh.triangles.Length == MeshGenerator.GetIndicesCount(numSides, numSegments, flag));
            return(mesh);
        }
 public void SetUV3(Vector2[] uvs)
 {
     _uv3 = new Vector2[uvs.Length]; uvs.CopyTo(_uv3, 0); Apply();
 }
Exemple #16
0
    protected int stepDir = 1; // The direction we're currently playing the animation (1=forwards (default), -1=backwards)

    #endregion Fields

    #region Methods

    // Appends the specified array of UV coordinates to the
    // existing animation
    public void AppendAnim(Vector2[] anim)
    {
        Vector2[] tempFrames = frames;

        frames = new Vector2[frames.Length + anim.Length];
        tempFrames.CopyTo(frames, 0);
        anim.CopyTo(frames, tempFrames.Length);
    }
Exemple #17
0
        /// <summary>
        /// 平面上の点の群れから、それら全てを内包する最小の多角形を求める
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public static Vector2[] GetMinimamPolygon(Vector2[] p)
        {
            Vector2[] points = new Vector2[p.Length + 1];
            points[0] = new Vector2();
            p.CopyTo(points, 1);
            var index = new List<int>(points.Length);
            var output = new List<Vector2>(points.Length);
            int now = 0;
            float max = 0;
            float l;

            //原点から一番遠い点を探す
            for (int i = 0; i < points.Length; i++)
            {
                l = points[i].LengthSquared();
                if (max < l)
                {
                    max = l;
                    now = i;
                }
            }
            index.Add(now);
            output.Add(points[now]);

            Func<int, bool> checkIn = (int i) =>
                {
                    Vector2 o = points[now] - points[i];
                    if (o.LengthSquared() < 0.1) return false;
                    for (int j = 0; j < points.Length; j++)
                    {
                        if (Cross(o, points[j] - points[i]) < 0) return false;
                    }
                    return true;
                };

            while (true)
            {
            SEARCH_POINT:
                for (int i = 0; i < points.Length; i++)
                {
                    //if (i != now && (!index.Contains(i) || i == index[0]))
                    if (i != now && !index.Contains(i))
                    {
                        /*origin = points[now] - points[i];
                        for (int j = 0; j < points.Length; j++)
                        {
                            if (i != j && j != now)
                            {
                                if (Cross(origin, points[j] - points[i]) < 0) break;
                            }
                            if (j == points.Length - 1)
                            {
                                if (i == index[0])
                                {
                                    goto END;
                                }
                                now = i;
                                index.Add(i);
                                output.Add(points[i]);
                                goto SEARCH_POINT;
                            }
                        }*/
                        if (checkIn(i))
                        {
                            now = i;
                            index.Add(i);
                            output.Add(points[i]);
                            goto SEARCH_POINT;
                        }
                    }
                }
                break;
            }

            return output.ToArray();
        }
        public static Mesh GenerateConeZ_Radius(float lengthZ, float radiusStart, float radiusEnd, int numSides, int numSegments, bool cap, bool doubleSided)
        {
            Debug.Assert(lengthZ > 0f);
            Debug.Assert(radiusStart >= 0f);
            Debug.Assert(numSides >= 3);
            Debug.Assert(numSegments >= 0);

            var  mesh   = new Mesh();
            bool genCap = false;

#if GENERATE_CAP
            genCap = cap && radiusStart > 0f;
#endif
            // We use the XY position of the vertices to compute the cone normal in the shader.
            // With a perfectly sharp cone, we couldn't compute accurate normals at its top.
            radiusStart = Mathf.Max(radiusStart, kMinTruncatedRadius);

            int vertCountSides = numSides * (numSegments + 2);
            int vertCountTotal = vertCountSides;

            if (genCap)
            {
                vertCountTotal += numSides + 1;
            }

            // VERTICES
            {
                float angleOffset = GetAngleOffset(numSides);

                var vertices = new Vector3[vertCountTotal];

                for (int i = 0; i < numSides; i++)
                {
                    float angle    = angleOffset + 2 * Mathf.PI * i / numSides;
                    float angleCos = Mathf.Cos(angle);
                    float angleSin = Mathf.Sin(angle);

                    for (int seg = 0; seg < numSegments + 2; seg++)
                    {
                        float tseg = (float)seg / (numSegments + 1);
                        Debug.Assert(tseg >= 0f && tseg <= 1f);
                        float radius = Mathf.Lerp(radiusStart, radiusEnd, tseg);
                        vertices[i + seg * numSides] = new Vector3(radius * angleCos, radius * angleSin, tseg * lengthZ);
                    }
                }

                if (genCap)
                {
                    int ind = vertCountSides;

                    vertices[ind] = Vector3.zero;
                    ind++;

                    for (int i = 0; i < numSides; i++)
                    {
                        float angle    = angleOffset + 2 * Mathf.PI * i / numSides;
                        float angleCos = Mathf.Cos(angle);
                        float angleSin = Mathf.Sin(angle);
                        vertices[ind] = new Vector3(radiusStart * angleCos, radiusStart * angleSin, 0f);
                        ind++;
                    }

                    Debug.Assert(ind == vertices.Length);
                }

                if (!doubleSided)
                {
                    mesh.vertices = vertices;
                }
                else
                {
                    var vertices2 = new Vector3[vertices.Length * 2];
                    vertices.CopyTo(vertices2, 0);
                    vertices.CopyTo(vertices2, vertices.Length);
                    mesh.vertices = vertices2;
                }
            }

            // UV (used to flags vertices as sides or cap)
            // X: 0 = sides ; 1 = cap
            // Y: 0 = front face ; 1 = back face (doubleSided only)
            {
                var uv  = new Vector2[vertCountTotal];
                int ind = 0;
                for (int i = 0; i < vertCountSides; i++)
                {
                    uv[ind++] = Vector2.zero;
                }

                if (genCap)
                {
                    for (int i = 0; i < numSides + 1; i++)
                    {
                        uv[ind++] = new Vector2(1, 0);
                    }
                }

                Debug.Assert(ind == uv.Length);


                if (!doubleSided)
                {
                    mesh.uv = uv;
                }
                else
                {
                    var uv2 = new Vector2[uv.Length * 2];
                    uv.CopyTo(uv2, 0);
                    uv.CopyTo(uv2, uv.Length);

                    for (int i = 0; i < uv.Length; i++)
                    {
                        var value = uv2[i + uv.Length];
                        uv2[i + uv.Length] = new Vector2(value.x, 1);
                    }

                    mesh.uv = uv2;
                }
            }

            // INDICES
            {
                int triCountSides = numSides * 2 * Mathf.Max(numSegments + 1, 1);
                int indCountSides = triCountSides * 3;
                int indCountTotal = indCountSides;

                if (genCap)
                {
                    indCountTotal += numSides * 3;
                }

                var indices = new int[indCountTotal];
                int ind     = 0;

                for (int i = 0; i < numSides; i++)
                {
                    int ip1 = i + 1;
                    if (ip1 == numSides)
                    {
                        ip1 = 0;
                    }

                    for (int k = 0; k < numSegments + 1; ++k)
                    {
                        var offset = k * numSides;

                        indices[ind++] = offset + i;
                        indices[ind++] = offset + ip1;
                        indices[ind++] = offset + i + numSides;

                        indices[ind++] = offset + ip1 + numSides;
                        indices[ind++] = offset + i + numSides;
                        indices[ind++] = offset + ip1;
                    }
                }

                if (genCap)
                {
                    for (int i = 0; i < numSides - 1; i++)
                    {
                        indices[ind++] = vertCountSides;
                        indices[ind++] = vertCountSides + i + 2;
                        indices[ind++] = vertCountSides + i + 1;
                    }

                    indices[ind++] = vertCountSides;
                    indices[ind++] = vertCountSides + 1;
                    indices[ind++] = vertCountSides + numSides;
                }

                Debug.Assert(ind == indices.Length);

                if (!doubleSided)
                {
                    mesh.triangles = indices;
                }
                else
                {
                    var indices2 = new int[indices.Length * 2];
                    indices.CopyTo(indices2, 0);

                    for (int i = 0; i < indices.Length; i += 3)
                    {
                        indices2[indices.Length + i + 0] = indices[i + 0] + vertCountTotal;
                        indices2[indices.Length + i + 1] = indices[i + 2] + vertCountTotal;
                        indices2[indices.Length + i + 2] = indices[i + 1] + vertCountTotal;
                    }

                    mesh.triangles = indices2;
                }
            }

            var bounds = new Bounds(
                new Vector3(0, 0, lengthZ * 0.5f),
                new Vector3(Mathf.Max(radiusStart, radiusEnd) * 2, Mathf.Max(radiusStart, radiusEnd) * 2, lengthZ)
                );
            mesh.bounds = bounds;

            Debug.Assert(mesh.vertexCount == GetVertexCount(numSides, numSegments, genCap, doubleSided));
            Debug.Assert(mesh.triangles.Length == GetIndicesCount(numSides, numSegments, genCap, doubleSided));

            return(mesh);
        }
        public static Mesh GenerateConeZ_Radius(
            float lengthZ,
            float radiusStart,
            float radiusEnd,
            int numSides,
            int numSegments,
            bool cap)
        {
            Debug.Assert((double)lengthZ > 0.0);
            Debug.Assert((double)radiusStart >= 0.0);
            Debug.Assert(numSides >= 3);
            Debug.Assert(numSegments >= 0);
            Mesh mesh    = new Mesh();
            bool geomCap = cap && (double)radiusStart > 0.0;

            radiusStart = Mathf.Max(radiusStart, 1f / 1000f);
            int num1    = numSides * (numSegments + 2);
            int length1 = num1;

            if (geomCap)
            {
                length1 += numSides + 1;
            }
            Vector3[] vector3Array1 = new Vector3[length1];
            for (int index1 = 0; index1 < numSides; ++index1)
            {
                double num2 = 6.28318548202515 * (double)index1 / (double)numSides;
                float  num3 = Mathf.Cos((float)num2);
                float  num4 = Mathf.Sin((float)num2);
                for (int index2 = 0; index2 < numSegments + 2; ++index2)
                {
                    float num5 = (float)index2 / (float)(numSegments + 1);
                    Debug.Assert((double)num5 >= 0.0 && (double)num5 <= 1.0);
                    float num6 = Mathf.Lerp(radiusStart, radiusEnd, num5);
                    vector3Array1[index1 + index2 * numSides] = new Vector3(num6 * num3, num6 * num4, num5 * lengthZ);
                }
            }
            if (geomCap)
            {
                int index1 = num1;
                vector3Array1[index1] = Vector3.get_zero();
                int index2 = index1 + 1;
                for (int index3 = 0; index3 < numSides; ++index3)
                {
                    double num2 = 6.28318548202515 * (double)index3 / (double)numSides;
                    float  num3 = Mathf.Cos((float)num2);
                    float  num4 = Mathf.Sin((float)num2);
                    vector3Array1[index2] = new Vector3(radiusStart * num3, radiusStart * num4, 0.0f);
                    ++index2;
                }
                Debug.Assert(index2 == vector3Array1.Length);
            }
            if (!MeshGenerator.duplicateBackFaces)
            {
                mesh.set_vertices(vector3Array1);
            }
            else
            {
                Vector3[] vector3Array2 = new Vector3[vector3Array1.Length * 2];
                vector3Array1.CopyTo((Array)vector3Array2, 0);
                vector3Array1.CopyTo((Array)vector3Array2, vector3Array1.Length);
                mesh.set_vertices(vector3Array2);
            }
            Vector2[] vector2Array1 = new Vector2[length1];
            int       num7          = 0;

            for (int index = 0; index < num1; ++index)
            {
                vector2Array1[num7++] = Vector2.get_zero();
            }
            if (geomCap)
            {
                for (int index = 0; index < numSides + 1; ++index)
                {
                    vector2Array1[num7++] = new Vector2(1f, 0.0f);
                }
            }
            Debug.Assert(num7 == vector2Array1.Length);
            if (!MeshGenerator.duplicateBackFaces)
            {
                mesh.set_uv(vector2Array1);
            }
            else
            {
                Vector2[] vector2Array2 = new Vector2[vector2Array1.Length * 2];
                vector2Array1.CopyTo((Array)vector2Array2, 0);
                vector2Array1.CopyTo((Array)vector2Array2, vector2Array1.Length);
                for (int index = 0; index < vector2Array1.Length; ++index)
                {
                    Vector2 vector2 = vector2Array2[index + vector2Array1.Length];
                    vector2Array2[index + vector2Array1.Length] = new Vector2((float)vector2.x, 1f);
                }
                mesh.set_uv(vector2Array2);
            }
            int length2 = numSides * 2 * Mathf.Max(numSegments + 1, 1) * 3;

            if (geomCap)
            {
                length2 += numSides * 3;
            }
            int[] numArray1 = new int[length2];
            int   num8      = 0;

            for (int index1 = 0; index1 < numSides; ++index1)
            {
                int num2 = index1 + 1;
                if (num2 == numSides)
                {
                    num2 = 0;
                }
                for (int index2 = 0; index2 < numSegments + 1; ++index2)
                {
                    int   num3      = index2 * numSides;
                    int[] numArray2 = numArray1;
                    int   index3    = num8;
                    int   num4      = index3 + 1;
                    int   num5      = num3 + index1;
                    numArray2[index3] = num5;
                    int[] numArray3 = numArray1;
                    int   index4    = num4;
                    int   num6      = index4 + 1;
                    int   num9      = num3 + num2;
                    numArray3[index4] = num9;
                    int[] numArray4 = numArray1;
                    int   index5    = num6;
                    int   num10     = index5 + 1;
                    int   num11     = num3 + index1 + numSides;
                    numArray4[index5] = num11;
                    int[] numArray5 = numArray1;
                    int   index6    = num10;
                    int   num12     = index6 + 1;
                    int   num13     = num3 + num2 + numSides;
                    numArray5[index6] = num13;
                    int[] numArray6 = numArray1;
                    int   index7    = num12;
                    int   num14     = index7 + 1;
                    int   num15     = num3 + index1 + numSides;
                    numArray6[index7] = num15;
                    int[] numArray7 = numArray1;
                    int   index8    = num14;
                    num8 = index8 + 1;
                    int num16 = num3 + num2;
                    numArray7[index8] = num16;
                }
            }
            if (geomCap)
            {
                for (int index1 = 0; index1 < numSides - 1; ++index1)
                {
                    int[] numArray2 = numArray1;
                    int   index2    = num8;
                    int   num2      = index2 + 1;
                    int   num3      = num1;
                    numArray2[index2] = num3;
                    int[] numArray3 = numArray1;
                    int   index3    = num2;
                    int   num4      = index3 + 1;
                    int   num5      = num1 + index1 + 2;
                    numArray3[index3] = num5;
                    int[] numArray4 = numArray1;
                    int   index4    = num4;
                    num8 = index4 + 1;
                    int num6 = num1 + index1 + 1;
                    numArray4[index4] = num6;
                }
                int[] numArray5 = numArray1;
                int   index5    = num8;
                int   num9      = index5 + 1;
                int   num10     = num1;
                numArray5[index5] = num10;
                int[] numArray6 = numArray1;
                int   index6    = num9;
                int   num11     = index6 + 1;
                int   num12     = num1 + 1;
                numArray6[index6] = num12;
                int[] numArray7 = numArray1;
                int   index7    = num11;
                num8 = index7 + 1;
                int num13 = num1 + numSides;
                numArray7[index7] = num13;
            }
            Debug.Assert(num8 == numArray1.Length);
            if (!MeshGenerator.duplicateBackFaces)
            {
                mesh.set_triangles(numArray1);
            }
            else
            {
                int[] numArray2 = new int[numArray1.Length * 2];
                numArray1.CopyTo((Array)numArray2, 0);
                for (int index = 0; index < numArray1.Length; index += 3)
                {
                    numArray2[numArray1.Length + index]     = numArray1[index] + length1;
                    numArray2[numArray1.Length + index + 1] = numArray1[index + 2] + length1;
                    numArray2[numArray1.Length + index + 2] = numArray1[index + 1] + length1;
                }
                mesh.set_triangles(numArray2);
            }
            Bounds bounds;

            ((Bounds) ref bounds).\u002Ector(new Vector3(0.0f, 0.0f, lengthZ * 0.5f), new Vector3(Mathf.Max(radiusStart, radiusEnd) * 2f, Mathf.Max(radiusStart, radiusEnd) * 2f, lengthZ));
            mesh.set_bounds(bounds);
            Debug.Assert(mesh.get_vertexCount() == MeshGenerator.GetVertexCount(numSides, numSegments, geomCap));
            Debug.Assert(mesh.get_triangles().Length == MeshGenerator.GetIndicesCount(numSides, numSegments, geomCap));
            return(mesh);
        }
Exemple #20
0
    public void RefreshMesh()
    {
        // indices top and bottom
        Vector2[] temp = new Vector2[LocalPositions.Count];
        for (int i = 0; i < temp.Length; i++)
        {
            temp[i] = new Vector2(LocalPositions[i].x, LocalPositions[i].z);
        }

        int[] indices        = new Triangulator(temp).Triangulate();
        int[] reverseIndices = indices.Reverse().ToArray();
        int[] tempAllIndices = new int[indices.Length * 2];

        reverseIndices.CopyTo(tempAllIndices, 0);
        indices.CopyTo(tempAllIndices, indices.Length);

        for (int i = indices.Length; i < tempAllIndices.Length; i++)
        {
            tempAllIndices[i] += LocalPositions.Count;
        }

        // indices sides
        List <int> tempIntList = tempAllIndices.ToList();

        for (int i = 0; i < LocalPositions.Count; i++)
        {
            List <int> t = new List <int>();
            for (int j = 0; j < 6; j++)
            {
                if (j == 0)
                {
                    t.Add(i);
                }
                else if (j == 1)
                {
                    t.Add(i != LocalPositions.Count - 1 ? LocalPositions.Count + (i + 1) : LocalPositions.Count);
                }
                else if (j == 2)
                {
                    t.Add(LocalPositions.Count + i);
                }
                else if (j == 3)
                {
                    t.Add(i);
                }
                else if (j == 4)
                {
                    t.Add(i != LocalPositions.Count - 1 ? (i + 1) : 0);
                }
                else if (j == 5)
                {
                    t.Add(i != LocalPositions.Count - 1 ? LocalPositions.Count + (i + 1) : LocalPositions.Count);
                }
            }
            tempIntList.AddRange(t);
        }

        // Create the Vector3 vertices
        var vertices = new Vector3[temp.Length * 2];

        Vector2[] tempAllVertices = new Vector2[temp.Length * 2];
        temp.CopyTo(tempAllVertices, 0);
        temp.CopyTo(tempAllVertices, temp.Length);
        for (int i = 0; i < vertices.Length; i++)
        {
            vertices[i] = new Vector3(tempAllVertices[i].x, i < vertices.Length / 2 ? -RadarMeshHeight : RadarMeshHeight, tempAllVertices[i].y);
        }

        // Create the mesh
        Mesh mesh = new Mesh
        {
            vertices  = vertices,
            triangles = tempIntList.ToArray()
        };

        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
        GetComponent <MeshFilter>().sharedMesh = mesh;

        var meshCollider = GetComponent <MeshCollider>();

        if (meshCollider == null)
        {
            meshCollider = gameObject.AddComponent <MeshCollider>();
        }
        meshCollider.sharedMesh = mesh;
        meshCollider.convex     = true;
    }
Exemple #21
0
    public void mbAddToRenderBuffer(ref Vector3[] vertices, ref Vector2[] uvs, ref Color[] colors)
    {
        if (mBufferPtr == mVertices.Length)
            mbEnlargeBuffers(LayerBlocksize);

        vertices.CopyTo(mVertices, mBufferPtr);
        uvs.CopyTo(mUVs, mBufferPtr);
        colors.CopyTo(mColors, mBufferPtr);

        int i = (mBufferPtr / 4) * 6;
        mTriangles[i++] = mBufferPtr;
        mTriangles[i++] = mBufferPtr + 1;
        mTriangles[i++] = mBufferPtr + 2;
        mTriangles[i++] = mBufferPtr + 2;
        mTriangles[i++] = mBufferPtr + 3;
        mTriangles[i++] = mBufferPtr;

        mBufferPtr += 4;
    }
Exemple #22
0
    bool _addToCombined(GameObject[] goToAdd, GameObject[] goToDelete, bool disableRendererInSource)
    {
        if (goToAdd == null)
        {
            goToAdd = empty;
        }
        if (goToDelete == null)
        {
            goToDelete = empty;
        }
        if (_mesh == null)
        {
            _mesh = new Mesh();
        }
        if (mat2rect_map.Keys.Count == 0)
        {
            _initialize();
        }

        int numResultMats = 1;

        if (doMultiMaterial)
        {
            numResultMats = resultMaterials.Length;
        }

        if (VERBOSE)
        {
            Debug.Log("_addToCombined objs adding:" + goToAdd.Length + " objs deleting:" + goToDelete.Length + " fixOutOfBounds:" + fixOutOfBoundsUVs + " doMultiMaterial:" + doMultiMaterial);
        }

        OrderedDictionary sourceMats2submeshIdx_map = null;

        if (doMultiMaterial)
        {
            //build the sourceMats to submesh index map
            sourceMats2submeshIdx_map = new OrderedDictionary();
            for (int i = 0; i < numResultMats; i++)
            {
                MB_MultiMaterial mm = resultMaterials[i];
                for (int j = 0; j < mm.sourceMaterials.Count; j++)
                {
                    if (mm.sourceMaterials[j] == null)
                    {
                        Debug.LogError("Found null material in source materials for combined mesh materials " + i);
                        return(false);
                    }
                    if (!sourceMats2submeshIdx_map.Contains(mm.sourceMaterials[j]))
                    {
                        sourceMats2submeshIdx_map.Add(mm.sourceMaterials[j], i);
                    }
                }
            }
        }

        if (submeshTris.Length == 0)
        {
            submeshTris = new int[numResultMats][];
            for (int i = 0; i < submeshTris.Length; i++)
            {
                submeshTris[i] = new int[0];
            }
        }

        //calculate num to delete
        int totalDeleteVerts = 0;

//		int totalDeleteTris = 0;
        int[] totalDeleteSubmeshTris = new int[numResultMats];
        for (int i = 0; i < goToDelete.Length; i++)
        {
            MB_DynamicGameObject dgo;
            if (instance2combined_map.TryGetValue(goToDelete[i], out dgo))
            {
                totalDeleteVerts += dgo.numVerts;
//				totalDeleteTris += dgo.numTris;
                for (int j = 0; j < dgo.submeshNumTris.Length; j++)
                {
                    totalDeleteSubmeshTris[j] += dgo.submeshNumTris[j];
                }
            }
            else
            {
                Debug.LogWarning("Trying to delete an object that is not in combined mesh");
            }
        }

        //now add
        List <MB_DynamicGameObject> toAddDGOs = new List <MB_DynamicGameObject>();
        int totalAddVerts = 0;

//		int totalAddTris = 0;
        int[] totalAddSubmeshTris = new int[numResultMats];
        for (int i = 0; i < goToAdd.Length; i++)
        {
            if (!instance2combined_map.ContainsKey(goToAdd[i]))
            {
                MB_DynamicGameObject dgo = new MB_DynamicGameObject();

                GameObject go = goToAdd[i];

                Material[] sharedMaterials = MB_Utility.GetGOMaterials(go);

                if (sharedMaterials == null)
                {
                    Debug.LogError("Object " + go.name + " does not have a Renderer");
                    goToAdd[i] = null;
                    continue;
                }

                Mesh m = MB_Utility.GetMesh(go);
                if (m == null)
                {
                    Debug.LogError("Object " + go.name + " MeshFilter or SkinedMeshRenderer had no mesh");
                    goToAdd[i] = null;
                }

                Rect[] uvRects = new Rect[sharedMaterials.Length];
                for (int j = 0; j < sharedMaterials.Length; j++)
                {
                    if (!mat2rect_map.TryGetValue(sharedMaterials[j], out uvRects[j]))
                    {
                        Debug.LogError("Object " + go.name + " has an unknown material " + sharedMaterials[j] + ". Try baking textures");
                        goToAdd[i] = null;
                    }
                }
                if (goToAdd[i] != null)
                {
                    dgo.go         = goToAdd[i];
                    dgo.uvRects    = uvRects;
                    dgo.sharedMesh = m;
                    dgo.numVerts   = m.vertexCount;

                    if (!_collectMaterialTriangles(m, dgo, sharedMaterials, sourceMats2submeshIdx_map))
                    {
                        return(false);
                    }
                    dgo.submeshNumTris = new int[numResultMats];
                    dgo.submeshTriIdxs = new int[numResultMats];

                    if (fixOutOfBoundsUVs)
                    {
                        if (!_collectOutOfBoundsUVRects(m, dgo, sharedMaterials, sourceMats2submeshIdx_map))
                        {
                            return(false);
                        }
                    }
                    toAddDGOs.Add(dgo);
                    totalAddVerts += dgo.numVerts;
//					totalAddTris += dgo.numTris;

                    for (int j = 0; j < dgo._submeshTris.Length; j++)
                    {
                        totalAddSubmeshTris[dgo.targetSubmeshIdxs[j]] += dgo._submeshTris[j].Count;
                    }
                }
            }
            else
            {
                Debug.LogWarning("Object " + goToAdd[i].name + " has already been added to " + name);
                goToAdd[i] = null;
            }
        }

        for (int i = 0; i < goToAdd.Length; i++)
        {
            if (goToAdd[i] != null && disableRendererInSource)
            {
                MB_Utility.DisableRendererInSource(goToAdd[i]);
            }
        }

        int newVertSize = verts.Length + totalAddVerts - totalDeleteVerts;

//		int newTrisSize = tris.Length + totalAddTris - totalDeleteTris;
        int[] newSubmeshTrisSize = new int[numResultMats];
        if (VERBOSE)
        {
            Debug.Log("Verts adding:" + totalAddVerts + " deleting:" + totalDeleteVerts);
        }

        if (VERBOSE)
        {
            Debug.Log("Submeshes:" + newSubmeshTrisSize.Length);
        }
        for (int i = 0; i < newSubmeshTrisSize.Length; i++)
        {
            newSubmeshTrisSize[i] = submeshTris[i].Length + totalAddSubmeshTris[i] - totalDeleteSubmeshTris[i];
            if (VERBOSE)
            {
                Debug.Log("    submesh :" + i + " already contains:" + submeshTris[i].Length + " trisAdded:" + totalAddSubmeshTris[i] + " trisDeleted:" + totalDeleteSubmeshTris[i]);
            }
        }

        if (newVertSize > 65534)
        {
            Debug.LogError("Cannot add objects. Resulting mesh will have more than 64k vertices .");
            return(false);
        }

        Vector3[] nverts    = new Vector3[newVertSize];
        Vector3[] nnormals  = new Vector3[newVertSize];
        Vector4[] ntangents = new Vector4[newVertSize];
        Vector2[] nuvs      = new Vector2[newVertSize];
        Vector2[] nuv1s     = new Vector2[newVertSize];
        Vector2[] nuv2s     = new Vector2[newVertSize];
        Color[]   ncolors   = new Color[newVertSize];
//		int[] ntris = new int[newTrisSize];
        int[][] nsubmeshTris = null;

        nsubmeshTris = new int[numResultMats][];
        for (int i = 0; i < nsubmeshTris.Length; i++)
        {
            nsubmeshTris[i] = new int[newSubmeshTrisSize[i]];
        }

        for (int i = 0; i < goToDelete.Length; i++)
        {
            MB_DynamicGameObject dgo;
            if (instance2combined_map.TryGetValue(goToDelete[i], out dgo))
            {
                dgo._beingDeleted = true;
            }
        }

        objectsInCombinedMesh.Sort();

        //copy existing arrays to narrays gameobj by gameobj omitting deleted ones
        int targVidx = 0;

        int[] targSubmeshTidx       = new int[numResultMats];
        int   triangleIdxAdjustment = 0;

        for (int i = 0; i < objectsInCombinedMesh.Count; i++)
        {
            MB_DynamicGameObject dgo = objectsInCombinedMesh[i];
            if (!dgo._beingDeleted)
            {
                if (VERBOSE)
                {
                    Debug.Log("Copying obj in combined arrays idx:" + i);
                }
                Array.Copy(verts, dgo.vertIdx, nverts, targVidx, dgo.numVerts);
                Array.Copy(normals, dgo.vertIdx, nnormals, targVidx, dgo.numVerts);
                Array.Copy(tangents, dgo.vertIdx, ntangents, targVidx, dgo.numVerts);
                Array.Copy(uvs, dgo.vertIdx, nuvs, targVidx, dgo.numVerts);
                Array.Copy(uv1s, dgo.vertIdx, nuv1s, targVidx, dgo.numVerts);
                Array.Copy(uv2s, dgo.vertIdx, nuv2s, targVidx, dgo.numVerts);
                Array.Copy(colors, dgo.vertIdx, ncolors, targVidx, dgo.numVerts);

                //adjust triangles, then copy them over

                for (int subIdx = 0; subIdx < numResultMats; subIdx++)
                {
                    int[] sTris    = submeshTris[subIdx];
                    int   sTriIdx  = dgo.submeshTriIdxs[subIdx];
                    int   sNumTris = dgo.submeshNumTris[subIdx];
                    if (VERBOSE)
                    {
                        Debug.Log("    Adjusting submesh triangles submesh:" + subIdx + " startIdx:" + sTriIdx + " num:" + sNumTris);
                    }
                    for (int j = sTriIdx; j < sTriIdx + sNumTris; j++)
                    {
                        sTris[j] = sTris[j] - triangleIdxAdjustment;
                    }
                    Array.Copy(sTris, sTriIdx, nsubmeshTris[subIdx], targSubmeshTidx[subIdx], sNumTris);
                }



//				dgo.triIdx = targTidx;
                dgo.vertIdx = targVidx;
//				targTidx += dgo.numTris;

                for (int j = 0; j < targSubmeshTidx.Length; j++)
                {
                    dgo.submeshTriIdxs[j] = targSubmeshTidx[j];
                    targSubmeshTidx[j]   += dgo.submeshNumTris[j];
                }

                targVidx += dgo.numVerts;
            }
            else
            {
                if (VERBOSE)
                {
                    Debug.Log("Not copying obj: " + i);
                }
                triangleIdxAdjustment += dgo.numVerts;
            }
        }

        for (int i = objectsInCombinedMesh.Count - 1; i >= 0; i--)
        {
            if (objectsInCombinedMesh[i]._beingDeleted)
            {
                instance2combined_map.Remove(objectsInCombinedMesh[i].go);
                objectsInCombinedMesh.RemoveAt(i);
            }
        }

        verts    = nverts;
        normals  = nnormals;
        tangents = ntangents;
        uvs      = nuvs;
        uv1s     = nuv1s;
        uv2s     = nuv2s;
        colors   = ncolors;
//		tris = ntris;
        submeshTris = nsubmeshTris;

        //add new
        for (int i = 0; i < toAddDGOs.Count; i++)
        {
            MB_DynamicGameObject dgo = toAddDGOs[i];
            GameObject           go  = dgo.go;
            int vertsIdx             = targVidx;
//			int trisIdx = targTidx;

            Mesh       mesh   = dgo.sharedMesh;
            Matrix4x4  l2wMat = go.transform.localToWorldMatrix;
            Quaternion l2wQ   = go.transform.rotation;
            nverts = mesh.vertices;
            Vector3[] nnorms = mesh.normals;
            Vector4[] ntangs = mesh.tangents;
            for (int j = 0; j < nverts.Length; j++)
            {
                nverts[j] = l2wMat.MultiplyPoint(nverts[j]);
                nnorms[j] = l2wQ * nnorms[j];
                float w = ntangs[j].w;                 //need to preserve the w value
                ntangs[j]   = l2wQ * ntangs[j];
                ntangs[j].w = w;
            }

            int numTriSets = mesh.subMeshCount;
            if (dgo.uvRects.Length < numTriSets)
            {
                Debug.LogWarning("Mesh " + dgo.go.name + " has more submeshes than materials");
                numTriSets = dgo.uvRects.Length;
            }
            else if (dgo.uvRects.Length > numTriSets)
            {
                Debug.LogWarning("Mesh " + dgo.go.name + " has fewer submeshes than materials");
            }
            nuvs = mesh.uv;
            int[] done = new int[nuvs.Length];             //use this to track uvs that have already been adjusted don't adjust twice
            for (int l = 0; l < done.Length; l++)
            {
                done[l] = -1;
            }

            bool triangleArraysOverlap = false;
            Rect obUVRect = new Rect();
            for (int k = 0; k < dgo._submeshTris.Length; k++)
            {
                List <int> subTris = dgo._submeshTris[k];
                Rect       uvRect  = dgo.uvRects[k];
                if (fixOutOfBoundsUVs)
                {
                    obUVRect = dgo.obUVRects[dgo.targetSubmeshIdxs[k]];
                }
                for (int l = 0; l < subTris.Count; l++)
                {
                    int vidx = subTris[l];
                    if (done[vidx] == -1)
                    {
                        done[vidx] = k;                         //prevents a uv from being adjusted twice
                        if (fixOutOfBoundsUVs)
                        {
                            nuvs[vidx].x = nuvs[vidx].x / obUVRect.width - obUVRect.x / obUVRect.width;
                            nuvs[vidx].y = nuvs[vidx].y / obUVRect.height - obUVRect.y / obUVRect.height;
                        }
                        nuvs[vidx].x = uvRect.x + nuvs[vidx].x * uvRect.width;
                        nuvs[vidx].y = uvRect.y + nuvs[vidx].y * uvRect.height;
                    }
                    if (done[vidx] != k)
                    {
                        triangleArraysOverlap = true;
                    }
                }
            }
            if (triangleArraysOverlap)
            {
                Debug.LogWarning(dgo.go.name + "has submeshes which share verticies. Adjusted uvs may not map correctly in combined atlas.");
            }

            nverts.CopyTo(verts, vertsIdx);
            nnorms.CopyTo(normals, vertsIdx);
            ntangs.CopyTo(tangents, vertsIdx);
            nuvs.CopyTo(uvs, vertsIdx);
            mesh.uv1.CopyTo(uv1s, vertsIdx);
            mesh.uv2.CopyTo(uv2s, vertsIdx);
            mesh.colors.CopyTo(colors, vertsIdx);
//			ntris = mesh.triangles;
//			for (int j = 0; j < ntris.Length; j++){
//				ntris[j] = ntris[j] + vertsIdx;
//			}

            for (int combinedMeshIdx = 0; combinedMeshIdx < targSubmeshTidx.Length; combinedMeshIdx++)
            {
                dgo.submeshTriIdxs[combinedMeshIdx] = targSubmeshTidx[combinedMeshIdx];
            }
            for (int j = 0; j < dgo._submeshTris.Length; j++)
            {
                List <int> sts = dgo._submeshTris[j];
                for (int k = 0; k < sts.Count; k++)
                {
                    sts[k] = sts[k] + vertsIdx;
                }
                int combinedMeshIdx = dgo.targetSubmeshIdxs[j];
                sts.CopyTo(submeshTris[combinedMeshIdx], targSubmeshTidx[combinedMeshIdx]);
                dgo.submeshNumTris[combinedMeshIdx] += sts.Count;
                targSubmeshTidx[combinedMeshIdx]    += sts.Count;
            }

            dgo.vertIdx = targVidx;

            instance2combined_map.Add(go, dgo);
            objectsInCombinedMesh.Add(dgo);

            targVidx += nverts.Length;
            for (int j = 0; j < dgo._submeshTris.Length; j++)
            {
                dgo._submeshTris[j].Clear();
            }
            dgo._submeshTris = null;
            if (VERBOSE)
            {
                Debug.Log("Added to combined:" + dgo.go.name + " verts:" + nverts.Length);
            }
        }
        return(true);
    }
        private static void Run()
        {
            #region Near Equality Methods
            var  x            = 1.0;
            var  y            = 2.0;
            bool isItTrueThat = x.IsPracticallySame(y);
            isItTrueThat = x.IsPracticallySame(y);
            Vector2 v2_1 = new Vector2(1.0, 2.0);
            Vector2 v2_2 = new Vector2(1.00000000001, 2.000000000002);
            isItTrueThat = v2_1.IsPracticallySame(v2_2);
            Vector3 v3_1 = new Vector3(1.0, 2.0, 3.0);
            Vector3 v3_2 = new Vector3(1.00000000001, 2.000000000002, 3.0);
            isItTrueThat = v3_1.IsPracticallySame(v3_2);
            isItTrueThat = x.IsNegligible();
            isItTrueThat = v2_1.IsNegligible();
            isItTrueThat = v3_1.IsNegligible();
            isItTrueThat = x.IsGreaterThanNonNegligible(y);
            isItTrueThat = x.IsLessThanNonNegligible(y);

            #endregion

            #region All Vector2 Methods
            v2_1 = new Vector2();
            Vector2  nullVector2  = Vector2.Null;
            Vector2  zeroVector2  = Vector2.Zero;
            Vector2  oneVector2   = Vector2.One;
            Vector2  unitVector2X = Vector2.UnitX;
            Vector2  unitVector2Y = Vector2.UnitY;
            Vector2  copyVector   = v2_1.Copy();
            double[] coordinates  = v2_1.Position;
            x = v2_1.X;
            x = v2_1[0];
            y = v2_1.Y;
            y = v2_1[1];
            double  length          = v2_1.Length();
            double  lengthSquared   = v2_1.LengthSquared();
            double  distance        = v2_1.Distance(zeroVector2);
            double  distanceSquared = v2_1.DistanceSquared(zeroVector2);
            Vector2 normal          = v2_1.Normalize();
            Vector2 reflect         = v2_1.Reflect(unitVector2Y);
            Vector2 clamp           = v2_1.Clamp(zeroVector2, oneVector2);
            Vector2 lerp            = v2_1.Lerp(oneVector2, 0.5);

            v2_2 = v2_1 + v2_1;
            v2_2 = v2_1 - v2_1;
            v2_2 = v2_1 * v2_1; //not dot or cross - basically a
            //component to component product vector whos terms sum to dot product
            v2_2         = v2_1 - v2_1;
            v2_2         = v2_1 / v2_1;
            v2_2         = v2_1 / new double();
            v2_2         = -v2_1;
            isItTrueThat = v2_1.IsNull();
            isItTrueThat = v2_1.IsNegligible();
            v2_1.CopyTo(coordinates);
            isItTrueThat = v2_1 == v2_2;
            isItTrueThat = v2_1 != v2_2;
            double  dot        = v2_1.Dot(v2_2);
            double  cross      = v2_1.Cross(v2_2);
            Vector2 minVector  = Vector2.Min(v2_1, v2_2);
            Vector2 maxVector  = Vector2.Max(v2_1, v2_2);
            Vector2 absVector  = Vector2.Abs(v2_1);
            Vector2 sqrtVector = Vector2.SquareRoot(v2_1);

            Matrix3x3 m3x3 = new Matrix3x3();
            v2_1 = v2_1.Transform(m3x3);
            v2_1 = v2_1.TransformNoTranslate(m3x3);

            Matrix4x4 m4x4 = new Matrix4x4();
            v2_1 = v2_1.Transform(m4x4);
            v2_1 = v2_1.TransformNoTranslate(m4x4);
            v2_1 = v2_1.Transform(new Quaternion());
            #endregion

            #region All Matrix3x3 Methods
            isItTrueThat = m3x3.IsProjectiveTransform;
            double value = m3x3.M11;
            value        = m3x3.M12;
            value        = m3x3.M13;
            value        = m3x3.M21;
            value        = m3x3.M22;
            value        = m3x3.M23;
            value        = m3x3.M31;
            value        = m3x3.M32;
            value        = m3x3.M33;
            m3x3         = Matrix3x3.Identity;
            m3x3         = Matrix3x3.Null;
            isItTrueThat = m3x3.IsIdentity();
            isItTrueThat = m3x3.IsNull();
            Vector2 t = m3x3.Translation;
            m3x3         = Matrix3x3.CreateTranslation(t);
            m3x3         = Matrix3x3.CreateTranslation(x, y);
            m3x3         = Matrix3x3.CreateScale(1.0);
            m3x3         = Matrix3x3.CreateScale(x, y);
            m3x3         = Matrix3x3.CreateScale(Vector2.One);
            m3x3         = Matrix3x3.CreateScale(x, y, v2_2);    //vResult is the center of scaling
            m3x3         = Matrix3x3.CreateSkew(2.0, 2.0);
            m3x3         = Matrix3x3.CreateSkew(2.0, 2.0, v2_2); //vResult is the center of skewing
            m3x3         = Matrix3x3.CreateRotation(1.0);        //in radians
            m3x3         = Matrix3x3.CreateRotation(1.0, v2_2);  //vResult is the center of rotate
            m3x3         = m3x3.Transpose();
            isItTrueThat = Matrix3x3.Invert(m3x3, out Matrix3x3 invM3x3);
            var d = m3x3.GetDeterminant();
            m3x3 = Matrix3x3.Lerp(m3x3, m3x3, 0.5);
            m3x3 = -m3x3;
            var m3x3Another = 4.0 * m3x3;
            m3x3 = m3x3 + m3x3;
            m3x3 = m3x3 - m3x3;
            m3x3 = m3x3 * m3x3;

            isItTrueThat = m3x3 == m3x3Another;
            isItTrueThat = m3x3 != m3x3Another;
            #endregion

            #region All Vector3 Methods

            v3_1 = new Vector3();
            v3_1 = new Vector3(v2_1, 0.0);
            Vector3 nullVector3  = Vector3.Null;
            Vector3 zeroVector3  = Vector3.Zero;
            Vector3 oneVector3   = Vector3.One;
            Vector3 unitVector3X = Vector3.UnitX;
            Vector3 unitVector3Y = Vector3.UnitY;
            Vector3 unitVector3Z = Vector3.UnitZ;
            unitVector3X = Vector3.UnitVector(CartesianDirections.XNegative);
            unitVector3X = Vector3.UnitVector(0);

            Vector3 copyVector3 = v3_1.Copy();
            coordinates = v3_1.Position;
            x           = v3_1.X;
            x           = v3_1[0];
            y           = v3_1.Y;
            y           = v3_1[1];
            double z = v3_1.Z;
            y               = v3_1[2];
            length          = v3_1.Length();
            lengthSquared   = v3_1.LengthSquared();
            distance        = v3_1.Distance(zeroVector3);
            distanceSquared = v3_1.DistanceSquared(zeroVector3);
            Vector3 normal3  = v3_1.Normalize();
            Vector3 reflect3 = v3_1.Reflect(unitVector3Y);
            Vector3 clamp3   = v3_1.Clamp(zeroVector3, oneVector3);
            Vector3 lerp3    = v3_1.Lerp(oneVector3, 0.5);

            v3_2 = v3_1 + v3_1;
            v3_2 = v3_1 - v3_1;
            v3_2 = v3_1 * v3_1; //not dot or cross - basically a
            //component to component product vector whos terms sum to dot product
            v3_2         = v3_1 - v3_1;
            v3_2         = v3_1 / v3_1;
            v3_2         = v3_1 / new double();
            v3_2         = -v3_1;
            isItTrueThat = v3_1.IsNull();
            isItTrueThat = v3_1.IsNegligible();
            v3_1.CopyTo(coordinates);
            isItTrueThat = v3_1 == v3_2;
            isItTrueThat = v3_1 != v3_2;
            double  dot3        = v3_1.Dot(v3_2);
            Vector3 cross3      = v3_1.Cross(v3_2);
            Vector3 minVector3  = Vector3.Min(v3_1, v3_2);
            Vector3 maxVector3  = Vector3.Max(v3_1, v3_2);
            Vector3 absVector3  = Vector3.Abs(v3_1);
            Vector3 sqrtVector3 = Vector3.SquareRoot(v3_1);

            m3x3 = new Matrix3x3();
            v3_1 = v3_1.Multiply(m3x3);

            m4x4 = new Matrix4x4();
            v3_1 = v3_1.Transform(m4x4);
            v3_1 = v3_1.TransformNoTranslate(m4x4);
            v3_1 = v3_1.Transform(new Quaternion());
            #endregion

            #region All Matrix4x4 Methods
            isItTrueThat = m4x4.IsProjectiveTransform;
            value        = m4x4.M11;
            value        = m4x4.M12;
            value        = m4x4.M13;
            value        = m4x4.M14;
            value        = m4x4.M21;
            value        = m4x4.M22;
            value        = m4x4.M23;
            value        = m4x4.M24;
            value        = m4x4.M31;
            value        = m4x4.M32;
            value        = m4x4.M33;
            value        = m4x4.M34;
            value        = m4x4.M41;
            value        = m4x4.M42;
            value        = m4x4.M43;
            value        = m4x4.M44;
            m4x4         = Matrix4x4.Identity;
            m4x4         = Matrix4x4.Null;
            m4x4         = new Matrix4x4(m3x3);
            isItTrueThat = m4x4.IsIdentity();
            isItTrueThat = m4x4.IsNull();
            Vector3 t3 = m4x4.TranslationAsVector;
            m4x4 = Matrix4x4.CreateBillboard(v3_1, v3_1, v3_1, v3_1);
            m4x4 = Matrix4x4.CreateConstrainedBillboard(v3_1, v3_1, v3_1, v3_1, v3_1);


            m4x4 = Matrix4x4.CreateTranslation(t3);
            m4x4 = Matrix4x4.CreateTranslation(x, y, z);
            m4x4 = Matrix4x4.CreateScale(1.0);
            m4x4 = Matrix4x4.CreateScale(x, y, z);
            m4x4 = Matrix4x4.CreateScale(v3_1);
            m4x4 = Matrix4x4.CreateScale(v3_1, v3_2);        //vOther is the center of scaling
            m4x4 = Matrix4x4.CreateScale(x, y, z, v3_2);     //vOther is the center of scaling
            m4x4 = Matrix4x4.CreateRotationX(1.0);           //in radians
            m4x4 = Matrix4x4.CreateRotationX(1.0, v3_2);     //vOther is the center of rotate
            m4x4 = Matrix4x4.CreateRotationY(1.0);           //in radians
            m4x4 = Matrix4x4.CreateRotationY(1.0, v3_2);     //vOther is the center of rotate
            m4x4 = Matrix4x4.CreateRotationZ(1.0);           //in radians
            m4x4 = Matrix4x4.CreateRotationZ(1.0, v3_2);     //vOther is the center of rotate
            m4x4 = Matrix4x4.CreateFromAxisAngle(v3_2, 1.0); //vOther is the center of rotate
            m4x4 = Matrix4x4.CreatePerspectiveFieldOfView(1.0, 2.0, 3.0, 4.0);
            m4x4 = Matrix4x4.CreatePerspective(1.0, 1.0, 1.0, 1.0);
            m4x4 = Matrix4x4.CreatePerspectiveOffCenter(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
            m4x4 = Matrix4x4.CreateOrthographic(1.0, 2.0, 3.0, 4.0);
            m4x4 = Matrix4x4.CreateOrthographicOffCenter(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
            m4x4 = Matrix4x4.CreateLookAt(v3_1, v3_1, v3_2);
            m4x4 = Matrix4x4.CreateWorld(v3_1, v3_1, v3_2);
            m4x4 = Matrix4x4.CreateFromYawPitchRoll(1.0, 2.0, 3.0);
            m4x4 = Matrix4x4.CreateFromQuaternion(new Quaternion());
            m4x4 = Matrix4x4.CreateShadow(v3_1, new Plane(d, v3_2));
            m4x4 = Matrix4x4.CreateReflection(new Plane(d, v3_2));

            m4x4         = m4x4.Transpose();
            isItTrueThat = Matrix4x4.Invert(m4x4, out Matrix4x4 invm4x4);
            d            = m4x4.GetDeterminant();
            isItTrueThat = m4x4.Decompose(out var scale, out var rotQ, out var trans3);

            m4x4 = m4x4.Transform(rotQ);

            m4x4 = Matrix4x4.Lerp(m4x4, m4x4, 0.5);
            m4x4 = -m4x4;
            var m4x4Another = 4.0 * m4x4;
            m4x4 = m4x4 + m4x4;
            m4x4 = m4x4 - m4x4;
            m4x4 = m4x4 * m4x4;

            isItTrueThat = m4x4 == m4x4Another;
            isItTrueThat = m4x4 != m4x4Another;
            #endregion

            #region All Quaternion Methods
            var quat = new Quaternion();
            x = quat.X;
            y = quat.Y;
            z = quat.Z;
            var w         = quat.W;
            var quatOther = new Quaternion(v3_1, w);
            quat         = new Quaternion(x, y, z, w);
            quat         = Quaternion.Identity;
            isItTrueThat = quat.IsIdentity();
            quat         = Quaternion.Null;
            isItTrueThat = quat.IsNull();
            length       = quat.Length();
            length       = quat.LengthSquared();
            quat         = quat.Normalize();
            quat         = quat.Conjugate();
            quat         = quat.Inverse();
            quat         = Quaternion.CreateFromAxisAngle(v3_1, d);
            quat         = Quaternion.CreateFromYawPitchRoll(1.0, 2.0, 3.0);
            quat         = Quaternion.CreateFromRotationMatrix(m4x4);
            dot          = quat.Dot(quat);
            quat         = Quaternion.Lerp(quat, quat, 0.5);
            quat         = Quaternion.Slerp(quat, quat, 0.5);
            quat         = -quat;
            quat         = quat + quat;
            quat         = quat - quat;
            quat         = quat * quat;
            quat         = 4.0 * quat;
            quat         = quat / quat;
            isItTrueThat = quat == quatOther;
            isItTrueThat = quat != quatOther;
            #endregion

            #region All Plane Methods
            var plane = new Plane();
            plane = new Plane(d, v3_1);
            var planeOther = new Plane(d, new Vector3(x, y, z));
            v3_1  = plane.Normal;
            d     = plane.DistanceToOrigin;
            plane = Plane.CreateFromVertices(v3_1, unitVector3X, v3_2);
            plane.Normalize();
            plane.Transform(m4x4);
            plane.Transform(quat);
            dot          = plane.DotCoordinate(v3_1);
            dot          = plane.DotNormal(v3_1);
            isItTrueThat = plane == planeOther;
            isItTrueThat = plane != planeOther;
            #endregion

            #region IEnumerable<double> Statistics
            IEnumerable <double> numbers = new[] { 1.1, 2.2, 3.3 };
            var mean      = numbers.Mean();
            var median    = numbers.Median();
            var nrmse     = numbers.NormalizedRootMeanSquareError();
            var nthMedian = numbers.NthOrderStatistic(3);
            var varMean   = numbers.VarianceFromMean(mean);
            var varMedian = numbers.VarianceFromMedian(median);
            #endregion
        }