Example #1
0
        public void Initialize(VoxelMap map, int resolution)
        {
            mCollider = GetComponent <PolygonCollider2D>();
            mFilter   = GetComponent <MeshFilter>();
            this.map  = map;

            mFilter.mesh    = mesh = new Mesh();
            mesh.name       = "VoxelGridSurface Mesh";
            vertices        = new List <Vector3>();
            triangles       = new List <int>();
            uvs             = new List <Vector2>();
            cornersMax      = new int[resolution + 1];
            cornersMin      = new int[resolution + 1];
            xEdgesMin       = new int[resolution];
            xEdgesMax       = new int[resolution];
            voxelResolution = resolution;
        }
Example #2
0
        public void Initialize(VoxelMap map, int resolution, int chunkResolution, Vector2Int chunkPos, float size, float maxFeatureAngle)
        {
            this.map             = map;
            this.chunkPos        = chunkPos;
            this.chunkResolution = chunkResolution;
            sharpFeatureLimit    = Mathf.Cos(maxFeatureAngle * Mathf.Deg2Rad);
            this.resolution      = resolution;
            gridSize             = size;
            voxelSize            = size / resolution;
            voxels = new Voxel[resolution * resolution];

            dummyX = new Voxel();
            dummyY = new Voxel();
            dummyT = new Voxel();

            for (int i = 0, y = 0; y < resolution; y++)
            {
                for (int x = 0; x < resolution; x++, i++)
                {
                    CreateVoxel(i, x, y);
                }
            }

            boundsTrigger.size   = Vector2.one * voxelSize * resolution + Vector2.one * voxelSize * 2;
            boundsTrigger.offset = Vector2.one * voxelSize * resolution * 0.5f;

            surface = Instantiate(surfacePrefab) as VoxelGridSurface;
            surface.transform.parent        = transform;
            surface.transform.localPosition = Vector3.zero;
            surface.Initialize(map, resolution);
            if (map.overrideMaterial)
            {
                surface.GetComponent <Renderer>().sharedMaterial = map.overrideMaterial;
            }

            RefreshIfDirty();
        }
Example #3
0
 private void Awake()
 {
     voxelMap = GetComponent <VoxelMap>();
 }
 private void Awake()
 {
     boxCollider = GetComponent <BoxCollider>();
     voxelMap    = GetComponent <VoxelMap>();
 }