Beispiel #1
0
    protected override void Start()
    {
        base.Start();

        _outline.Color = 2;

        Initialize();
        GenerateMesh();
        _mesh = Combine();
        AutoWeld(_mesh, .01f, .02f);
        AddNoise();
        _vertexManager.Initialize();
        _zoneManager.Initialize();

        _originalVertices = _vertexManager.Vertices;
        _newVertices      = new Dictionary <Guid, Vector3>();

        for (int i = 0; i < _originalVertices.Length; i++)
        {
            _newVertices.Add(Utils.IntToGuid(i), _vertexManager.GetPosition(_originalVertices[i]));
        }
        _deformedVertices = new Dictionary <Guid, Vector3>();

        _objectGenerator.Generate();
    }
    public void Initialize()
    {
        _planetMesh = GetComponent <MeshFilter>().mesh;
        _triangles  = _planetMesh.triangles;
        _nbVertex   = _planetMesh.vertexCount;

        var tempZones = new List <Zone>();

        int triangleIndex = 0;

        for (int i = 0; i < _triangles.Length; i++)
        {
            if (triangleIndex + 2 >= _triangles.Length)
            {
                continue;
            }

            Zone zone = null;
            try
            {
                var v1 = Utils.IntToGuid(_triangles[triangleIndex]);
                var v2 = Utils.IntToGuid(_triangles[triangleIndex + 1]);
                var v3 = Utils.IntToGuid(_triangles[triangleIndex + 2]);

                var pos1 = _vertexManager.GetPosition(v1);
                var pos2 = _vertexManager.GetPosition(v2);
                var pos3 = _vertexManager.GetPosition(v3);

                zone = Instantiate(_zonePrefab, (pos1 + pos2 + pos3) / 3, Quaternion.identity, transform);

                zone.VerticeIds = new List <Guid> {
                    v1, v2, v3
                };

                triangleIndex += 3;
            }
            catch (Exception e)
            {
                Debug.Log($"Impossible to create zone at vertexIndex {i}: " + e);
            }

            tempZones.Add(zone);
        }

        _zoneDictionary = tempZones.ToDictionary(x => x.Id, x => x);
        Zones           = tempZones.ToArray();
        SetZoneInfos();
        //InitTriangles();
        FindNeighbours();
        _initialized = true;
    }