private void Awake()
    {
        currentManPos  = transform.position;
        chunkRenderers = new MeshRenderer[terrainTotalX * terrainTotalY * terrainTotalZ];
        centerOfMeshes = new Vector3((chunkSize * terrainTotalX) * 0.5f, (chunkSize * terrainTotalY) * 0.5f, (chunkSize * terrainTotalZ) * 0.5f) + currentManPos;

        // Add all cubes to aabb array for later comparisons
        foreach (Transform child in transform)
        {
            Vector3 halfScale = new Vector3(child.localScale.x / 2.0f + 1, child.localScale.y / 2.0f + 1, child.localScale.z / 2.0f + 1);
            aabb    newAABB   = new aabb(child.position + halfScale, child.position - halfScale, child.position, child.localScale);
            fillSpots.Add(newAABB);
            child.gameObject.SetActive(false);
        }

        if (CheckIfCacheExists())
        {
            if (fillSpots.Count > 0)
            {
                if (CheckIfAABBCacheExists())
                {
                    LoadMesh(false);

                    if (fillSpots.Count * 6 == fillSpotsMatched - 3)
                    {
                        readFromFile = true;
                    }
                    else
                    {
                        changedAABB = true;
                        SaveMesh(false);
                        updateReadFile = true;
                    }
                }
                else
                {
                    SaveMesh(false);
                    updateReadFile = true;
                }
            }
        }
        else
        {
            SaveMesh(false);
            updateReadFile = true;
        }
    }
Exemple #2
0
 public bool boundingBox(ref aabb box)
 {
     box = this.box;
     return(true);
 }
Exemple #3
0
 public Cube(Vec3 center, MaterialData material)
 {
     this.center   = center;
     this.material = material;
     box           = new aabb(center - new Vec3(0.5, 0.5, 0.5), center + new Vec3(0.5, 0.5, 0.5));
 }
Exemple #4
0
        public TriangulationResult2 Triangulate()
        {
            //trivial check
            if (Count < 3)
            {
                return(new TriangulationResult2 {
                    code = TriangulationCode.insufficientVertices
                });
            }

            if (!IsSimple())
            {
                return(new TriangulationResult2 {
                    code = TriangulationCode.notSimple
                });
            }

            if (this.Winding != WindingDir.ccw)
            {
                return(new TriangulationResult2 {
                    code = TriangulationCode.incorrectWinding
                });
            }
            else
            {
                if (this.Count == 3)
                {
                    return(new TriangulationResult2 {
                        data = new Primitive2[] { new Primitive2(this[0], this[1], this[2]) }
                    });
                }
                else
                {
                    Loop _verts             = Clone();
                    List <Primitive2> _tris = new List <Primitive2>(_verts.Count - 2);

                    int index = 0;

                    int attemptedVertices = 0;
                    while (_verts.Count > 3)
                    {
                        attemptedVertices++;

                        //wrap indices around
                        int v0Index = (index - 1 + _verts.Count) % _verts.Count;
                        int v1Index = (index + 0) % _verts.Count;
                        int v2Index = (index + 1) % _verts.Count;

                        gvec2 v0 = _verts[v0Index];
                        gvec2 v1 = _verts[v1Index];
                        gvec2 v2 = _verts[v2Index];


                        bool anyInside = false;
                        if (((v1.x - v0.x) * (v1.y + v0.y) + (v2.x - v1.x) * (v2.y + v1.y) + (v0.x - v2.x) * (v0.y + v2.y)) <= 0)
                        {
                            for (int j = 0; j < _verts.Count; j++)
                            {
                                if (j != v0Index && j != v1Index && j != v2Index)
                                {
                                    //this is hacky and is only used because of reducing simple with holes to simple
                                    gvec2 vj = _verts[j];
                                    if (!vj.Identical(v0) && !vj.Identical(v1) && !vj.Identical(v2))
                                    {
                                        if (Math2.PointInCCWTriangle(_verts[j], v0, v1, v2))
                                        {
                                            anyInside = true;
                                            break;
                                        }
                                    }
                                }
                            }

                            if (!anyInside)
                            {
                                _tris.Add(new Primitive2(v0, v1, v2));
                                _verts.Remove(index % _verts.Count);
                                attemptedVertices = 0;
                            }
                        }

                        if (attemptedVertices == _verts.Count)
                        {
                            return new TriangulationResult2 {
                                       code = TriangulationCode.robustnessFailure
                            }
                        }
                        ;

                        index = (index + 1) % _verts.Count;
                    }
                    _tris.Add(new Primitive2(_verts[0], _verts[1], _verts[2]));
                    return(new TriangulationResult2 {
                        data = _tris.ToArray(), code = TriangulationCode.operationSuccess
                    });
                }
            }
        }

        Loop(List <gvec2> data, bool _integralccw_needsUpdate, double _integralccw, bool _bounds_needsUpdate, aabb _bounds)
        {
            this.data = data;
            this._integralccw_needsUpdate = _integralccw_needsUpdate;
            this._integralccw             = _integralccw;
            this._bounds_needsUpdate      = _bounds_needsUpdate;
            this._bounds = _bounds;
        }