Esempio n. 1
0
    private List <Vector2> GetArchimePoints(float a, Vector2 center)
    {
        List <Vector2> archimeList = new List <Vector2>();

        _originPoints = CurvesTools.GetArchimedesPoint(a, 0.1f, 360 * 3 + 90);
        float length = 0;

        for (int i = 0; i < _originPoints.Count; i++)
        {
            Vector2 v = new Vector2(_moveVector3.x, _moveVector3.z);
            if (i == 0)
            {
                length = 0;
            }
            else
            {
                length += (_originPoints[i] - _originPoints[i - 1]).magnitude;
            }
            Vector2 v1 = center + v * length;
            archimeList.Add(v1);
        }
        return(archimeList);
    }
Esempio n. 2
0
    private void UpdateMesh(List <Vector3> cutPoints)
    {
        int            index = 0;
        List <Vector3> plane = new List <Vector3>();

        foreach (var item in _cutTopCache)
        {
            Vector3 dir = cutPoints[item.Key + 1] - cutPoints[item.Key];

            for (int i = 0; i < item.Value.Count; i++)
            {
                float   x = _offsetsCache[item.Key][i].x;
                float   y = _offsetsCache[item.Key][i].y;
                Vector3 t = x * _dirVector3 + y * dir.normalized;
                _referenceVerticles[i + index] = t + cutPoints[item.Key];
                plane.Add(_referenceVerticles[i + index]);
            }

            Vector3 normal = CurvesTools.GetPolygonNormal(plane);
            _normalCache[item.Key] = normal;
            plane.Clear();

            for (int i = 0; i < item.Value.Count; i++)
            {
                if (item.Value[i].IsCutPoint)
                {
                    if (item.Value[i].CutIndex == 0)
                    {
                        _topVerticles[i + index]    = _referenceVerticles[i + index] + _normalCache[0] * _thickness;
                        _bottomVerticles[i + index] = _referenceVerticles[i + index] - _normalCache[0] * _thickness;
                    }
                    else
                    {
                        int k = item.Value[i].CutIndex - 1;
                        _topVerticles[i + index]    = _referenceVerticles[i + index] + _normalCache[k] * _thickness;
                        _bottomVerticles[i + index] = _referenceVerticles[i + index] - _normalCache[k] * _thickness;
                    }
                }
                else
                {
                    _topVerticles[i + index]    = _referenceVerticles[i + index] + _normalCache[item.Key] * _thickness;
                    _bottomVerticles[i + index] = _referenceVerticles[i + index] - _normalCache[item.Key] * _thickness;
                }
            }

            index += item.Value.Count;
        }


        for (int i = 0; i < _rightInts.Count; i++)
        {
            _surroundVerticles[i * 2]     = _bottomVerticles[_rightInts[i]];
            _surroundVerticles[i * 2 + 1] = _topVerticles[_rightInts[i]];
        }

        _bottomMesh.vertices  = _bottomVerticles.ToArray();
        _bottomMesh.triangles = _bottomTriangles.ToArray();

        _topMesh.vertices  = _topVerticles.ToArray();
        _topMesh.triangles = _topTriangles.ToArray();

        _surroundMesh.vertices  = _surroundVerticles.ToArray();
        _surroundMesh.triangles = _surroundTriangles.ToArray();
    }
Esempio n. 3
0
    private void InitiFace()
    {
        GameObject bottom = new GameObject("Bottom");

        bottom.transform.SetParent(transform);
        bottom.transform.localPosition = Vector3.zero;
        bottom.transform.localScale    = Vector3.one;
        bottom.AddComponent <MeshRenderer>().material = _bottomMaterial;
        _bottomMeshFilter = bottom.AddComponent <MeshFilter>();
        _bottomMesh       = new Mesh();

        GameObject top = new GameObject("Top");

        top.transform.SetParent(transform);
        top.transform.localPosition = Vector3.zero;
        top.transform.localScale    = Vector3.one;
        top.AddComponent <MeshRenderer>().material = _topMaterial;
        _topMeshFilter = top.AddComponent <MeshFilter>();
        _topMesh       = new Mesh();

        GameObject surround = new GameObject("Surround");

        surround.transform.SetParent(transform);
        surround.transform.localPosition = Vector3.zero;
        surround.transform.localScale    = Vector3.one;
        surround.AddComponent <MeshRenderer>().material = _surroundMaterial;
        _surroundMeshFilter = surround.AddComponent <MeshFilter>();
        _surroundMesh       = new Mesh();



        int        index         = 0;
        int        verticleCount = 0;
        List <int> tempInts      = new List <int>();

        foreach (var item in _cutTopCache)
        {
            List <Vector3> points  = new List <Vector3>();
            var            list    = item.Value;
            int            start   = GetCutPointFirstIndex(list);
            bool           isRight = true;
            for (int i = 0; i < list.Count; i++)
            {
                int cutIndex = (i + start) % list.Count;
                int t1       = 0;
                if (list[cutIndex].IsCutPoint)
                {
                    t1 = list[cutIndex].CutSegmentIndex;
                    if (t1 < 0 && isRight)
                    {
                        isRight = false;
                    }
                }
                if (isRight)
                {
                    if (list[cutIndex].IsCutPoint)
                    {
                        if (!tempInts.Contains(t1))
                        {
                            tempInts.Add(t1);
                            _rightInts.Add(cutIndex + verticleCount);
                        }
                    }
                    else
                    {
                        _rightInts.Add(cutIndex + verticleCount);
                    }
                }
                else
                {
                    if (list[cutIndex].IsCutPoint)
                    {
                        if (!tempInts.Contains(t1))
                        {
                            tempInts.Add(t1);
                            _leftInts.Add(cutIndex + verticleCount);
                        }
                    }
                    else
                    {
                        _leftInts.Add(cutIndex + verticleCount);
                    }
                }
                points.Add(list[i].ToVector3());
            }

            verticleCount += points.Count;
            _offsetsCache.Add(item.Key, new List <Vector3>());

            Vector3 normal = CurvesTools.GetPolygonNormal(points);
            for (int i = 0; i < points.Count; i++)
            {
                _referenceVerticles.Add(points[i]);

                _bottomVerticles.Add(points[i] - normal * _thickness);
                _topVerticles.Add(points[i] + normal * _thickness);
                Vector3 offset = points[i] - _cutPoints[item.Key];
                Vector3 weights;
                CurvesTools.SetAxisWeight(out weights, _dirVector3, _moveVector3, Vector3.up, offset);
                _offsetsCache[item.Key].Add(weights);
            }
            _normalCache.Add(item.Key, Vector3.zero);

            var t = CurvesTools.GetTriByPoins(points).ToList();
            t.Reverse();
            for (int i = 0; i < t.Count; i++)
            {
                t[i] += index;
            }
            index += points.Count;
            _bottomTriangles.AddRange(t);
        }

        _bottomMesh.vertices   = _bottomVerticles.ToArray();
        _bottomMesh.triangles  = _bottomTriangles.ToArray();
        _bottomMeshFilter.mesh = _bottomMesh;

        for (int i = 0; i < _bottomTriangles.Count; i++)
        {
            _topTriangles.Add(_bottomTriangles[i]);
        }

        _topTriangles.Reverse();
        _topMesh.vertices   = _topVerticles.ToArray();
        _topMesh.triangles  = _topTriangles.ToArray();
        _topMeshFilter.mesh = _topMesh;


        int temp = _leftInts[0];

        _leftInts.RemoveAt(0);
        _leftInts.Insert(1, temp);
        _leftInts.Reverse();
        _rightInts.AddRange(_leftInts);
        for (int i = 0; i < _rightInts.Count; i++)
        {
            _surroundVerticles.Add(_bottomVerticles[_rightInts[i]]);
            _surroundVerticles.Add(_topVerticles[_rightInts[i]]);
        }
        for (int i = 0; i < _rightInts.Count - 1; i++)
        {
            _surroundTriangles.Add(i * 2); _surroundTriangles.Add((i + 1) * 2 + 1); _surroundTriangles.Add(i * 2 + 1);
            _surroundTriangles.Add(i * 2); _surroundTriangles.Add((i + 1) * 2); _surroundTriangles.Add((i + 1) * 2 + 1);
        }

        _surroundVerticles.Reverse();
        _surroundMesh.vertices   = _surroundVerticles.ToArray();
        _surroundMesh.triangles  = _surroundTriangles.ToArray();
        _surroundMeshFilter.mesh = _surroundMesh;
    }