예제 #1
0
        public int FillTrackVU3(NF.Collections.Generic.LinkedList <LineInfo> lines, int maxLineCount, Color colorStart, Color colorEnd, ref NativeMeshInfo meshInfo)
        {
            Assert.IsTrue(meshInfo.Vertices.IsCreated);
            Assert.IsTrue(meshInfo.UVs.IsCreated);
            Assert.IsTrue(meshInfo.Colors.IsCreated);

            int line = Math.Min(lines.Count, maxLineCount);

            if (line < 2)
            {
                return(line);
            }
            Assert.IsTrue(meshInfo.Vertices.Length >= line * 3);
            Assert.IsTrue(meshInfo.UVs.Length >= line * 3);
            Assert.IsTrue(meshInfo.Colors.Length >= line * 3);

            float addPerc     = 1f / line;
            float acc         = 0;
            int   recordIndex = 0;

            for (var node = lines.GetHeadNode(); node != null; node = node.Next)
            {
                if (recordIndex >= line)
                {
                    break;
                }
                var     record = node.Item;
                Vector3 p0     = record.BasePosition;
                Vector3 p1     = record.Position;
                Vector3 p2     = record.TipPosition;

                // p0         p1         p2
                // |----------|----------|
                int index = (recordIndex * 3);
                meshInfo.Vertices[index + 0] = p0;
                meshInfo.Vertices[index + 1] = p1;
                meshInfo.Vertices[index + 2] = p2;

                meshInfo.UVs[index + 0] = new Vector2(0, acc);
                meshInfo.UVs[index + 1] = new Vector2(0.5f, acc);
                meshInfo.UVs[index + 2] = new Vector2(1, acc);

                Color c = Color.Lerp(colorStart, colorEnd, acc);
                meshInfo.Colors[index + 0] = c;
                meshInfo.Colors[index + 1] = c;
                meshInfo.Colors[index + 2] = c;

                acc += addPerc;
                recordIndex++;
            }
            return(line);
        }
예제 #2
0
        public void Play(TrailRecordInfo recordInfo, int recordNum)
        {
            TrailMeshObject tmo = recordInfo.tmo;

            NF.Collections.Generic.LinkedList <LineInfo> records = recordInfo.RecordElements;
            SplineMeshInfo    meshInfo = recordInfo.MeshInfo;
            TrailRecordConfig config   = recordInfo.Config;

            switch (config.ELinePerVertexCount)
            {
            case TrailRecordConfig.E_LinePerVertexCount.TWO:
                UpdateMeshObjectWithSpline2(tmo, recordInfo.mMeshModifier, records, meshInfo, config);
                break;

            case TrailRecordConfig.E_LinePerVertexCount.THREE:
                UpdateMeshObjectWithSpline3(tmo, recordInfo.mMeshModifier, records, meshInfo, config);
                break;
            }
        }
예제 #3
0
        public int Refresh(NF.Collections.Generic.LinkedList <LineInfo> lineInfos, int desireRecordFrameCount)
        {
            mSplineControlPoints.Clear();

            if (desireRecordFrameCount == 0)
            {
                return(0);
            }

            int snapshotIndex = 0;

            for (var node = lineInfos.GetHeadNode(); node != null; node = node.Next)
            {
                if (snapshotIndex == desireRecordFrameCount)
                {
                    break;
                }
                if (snapshotIndex == mCache.Count)
                {
                    break;
                }

                LineInfo           lineInfo = node.Item;
                SplineControlPoint cp       = mCache[snapshotIndex];
                cp.Position = lineInfo.Position;
                cp.Normal   = lineInfo.Normal;
                mSplineControlPoints.Add(cp);
                snapshotIndex++;
            }

            // recalculate distance.
            SplineControlPoint prev = mSplineControlPoints[0];

            prev.Distance = 0;
            for (int i = 1; i < mSplineControlPoints.Count; ++i)
            {
                var curr = mSplineControlPoints[i];
                curr.Distance = prev.Distance + (curr.Position - prev.Position).magnitude;
                prev          = curr;
            }
            return(mSplineControlPoints.Count);
        }
예제 #4
0
        public int FillTrackVUCI2(NF.Collections.Generic.LinkedList <LineInfo> lines, int maxLineCount, Color colorStart, Color colorEnd, ref MeshInfo meshInfo)
        {
            Assert.IsNotNull(meshInfo.Vertices);
            Assert.IsNotNull(meshInfo.UVs);
            Assert.IsNotNull(meshInfo.Colors);
            Assert.IsNotNull(meshInfo.Indices);

            int line = Math.Min(lines.Count, maxLineCount);

            if (line < 2)
            {
                return(line);
            }
            Assert.AreEqual(meshInfo.Vertices.Length, line * 2);
            Assert.AreEqual(meshInfo.UVs.Length, line * 2);
            Assert.AreEqual(meshInfo.Colors.Length, line * 2);
            Assert.AreEqual(meshInfo.Indices.Length, (line - 1) * 6);

            float addPerc     = 1f / line;
            float acc         = 0;
            int   recordIndex = 0;

            for (var node = lines.GetHeadNode(); node != null; node = node.Next)
            {
                var record = node.Item;
                if (recordIndex >= line)
                {
                    break;
                }
                Vector3 p0 = record.BasePosition;
                Vector3 p2 = record.TipPosition;

                // p0                    p2
                // |---------------------|
                int index = (recordIndex * 2);
                meshInfo.Vertices[index + 0] = p0;
                meshInfo.Vertices[index + 1] = p2;

                meshInfo.UVs[index + 0] = new Vector2(0, acc);
                meshInfo.UVs[index + 1] = new Vector2(1, acc);

                Color c = Color.Lerp(colorStart, colorEnd, acc);
                meshInfo.Colors[index + 0] = c;
                meshInfo.Colors[index + 1] = c;

                acc += addPerc;
                recordIndex++;
            }

            for (int i = 0; i < line - 1; ++i)
            {
                int ci = i * 2;
                int ni = ci + 2;

                int index = i * 6;

                // c0                    c1
                // 2---------------------|
                // |          |          |
                // 0---------------------1
                // n0                    n1
                meshInfo.Indices[index + 0] = ni + 0;
                meshInfo.Indices[index + 1] = ni + 1;
                meshInfo.Indices[index + 2] = ci + 0;

                // c0                    c1
                // 5---------------------4
                // |          |          |
                // |---------------------3
                // n0                    n1
                meshInfo.Indices[index + 3] = ni + 1;
                meshInfo.Indices[index + 4] = ci + 1;
                meshInfo.Indices[index + 5] = ci + 0;
            }
            return(line);
        }
예제 #5
0
        public int FillTrackVUCI3(NF.Collections.Generic.LinkedList <LineInfo> lines, int maxLineCount, Color colorStart, Color colorEnd, ref NativeMeshInfo meshInfo)
        {
            Assert.IsTrue(meshInfo.Vertices.IsCreated);
            Assert.IsTrue(meshInfo.UVs.IsCreated);
            Assert.IsTrue(meshInfo.Colors.IsCreated);
            Assert.IsTrue(meshInfo.Indices.IsCreated);

            int line = Math.Min(lines.Count, maxLineCount);

            if (line < 2)
            {
                return(line);
            }
            Assert.AreEqual(meshInfo.Vertices.Length, line * 3);
            Assert.AreEqual(meshInfo.UVs.Length, line * 3);
            Assert.AreEqual(meshInfo.Colors.Length, line * 3);
            Assert.AreEqual(meshInfo.Indices.Length, (line - 1) * 12);

            float addPerc     = 1f / line;
            float acc         = 0;
            int   recordIndex = 0;

            for (var node = lines.GetHeadNode(); node != null; node = node.Next)
            {
                if (recordIndex >= line)
                {
                    break;
                }
                var     record = node.Item;
                Vector3 p0     = record.BasePosition;
                Vector3 p1     = record.Position;
                Vector3 p2     = record.TipPosition;

                // p0         p1         p2
                // |----------|----------|
                int index = (recordIndex * 3);
                meshInfo.Vertices[index + 0] = p0;
                meshInfo.Vertices[index + 1] = p1;
                meshInfo.Vertices[index + 2] = p2;

                meshInfo.UVs[index + 0] = new Vector2(0, acc);
                meshInfo.UVs[index + 1] = new Vector2(0.5f, acc);
                meshInfo.UVs[index + 2] = new Vector2(1, acc);

                Color c = Color.Lerp(colorStart, colorEnd, acc);
                meshInfo.Colors[index + 0] = c;
                meshInfo.Colors[index + 1] = c;
                meshInfo.Colors[index + 2] = c;

                acc += addPerc;
                recordIndex++;
            }

            for (int i = 0; i < line - 1; ++i)
            {
                int ci = i * 3;
                int ni = ci + 3;

                int index = i * 12;

                // c0         c1         c2
                // 2---------------------|
                // |          |          |
                // 0----------1----------|
                // n0         n1         n2
                meshInfo.Indices[index + 0] = ni + 0;
                meshInfo.Indices[index + 1] = ni + 1;
                meshInfo.Indices[index + 2] = ci + 0;

                // c0         c1         c2
                // 5----------4----------|
                // |          |          |
                // |----------3----------|
                // n0         n1         n2
                meshInfo.Indices[index + 3] = ni + 1;
                meshInfo.Indices[index + 4] = ci + 1;
                meshInfo.Indices[index + 5] = ci + 0;

                // c0         c1         c2
                // |----------8----------|
                // |          |          |
                // |----------6----------7
                // n0         n1         n2
                meshInfo.Indices[index + 6] = ni + 1;
                meshInfo.Indices[index + 7] = ni + 2;
                meshInfo.Indices[index + 8] = ci + 1;

                // c0         c1         c2
                // |----------11---------10
                // |          |          |
                // |----------|----------9
                // n0         n1         n2
                meshInfo.Indices[index + 9]  = ni + 2;
                meshInfo.Indices[index + 10] = ci + 2;
                meshInfo.Indices[index + 11] = ci + 1;
            }
            return(line);
        }
예제 #6
0
        void UpdateMeshObjectWithSpline2(TrailMeshObject tmo, MeshModifier meshModifier, NF.Collections.Generic.LinkedList <LineInfo> records, SplineMeshInfo meshInfo, TrailRecordConfig config)
        {
            int desireRecordFrameCount = Math.Min(records.Count, config.MaxPlayingRecordLength);

            if (desireRecordFrameCount < 2)
            {
                return;
            }

            var line = mSpliner.Refresh(records, desireRecordFrameCount);

            meshModifier.FillSplineVUC2(mSpliner, config.ColorStart, config.ColorEnd, ref meshInfo.mMeshInfo);
            tmo.UpdateMesh(line, 2, ref meshInfo.mMeshInfo);
        }