Пример #1
0
        public override void OnStart()
        {
            base.OnStart();
            Current     = this;
            _terrainMap = new VoxelTerrainMap();

            // Build material set
            VoxelMaterials = new VoxelMaterialSet.VoxelMaterial[ushort.MaxValue];

            foreach (var entry in ((VoxelMaterialSet)MaterialSet.CreateInstance()).Materials)
            {
                var material = entry.Material;
                if (material != null)
                {
                    VoxelMaterials[material.Id] = material;
                }
            }

            // Build initial chunks
            for (var y = 0; y < 4; y++)
            {
                for (var x = -8; x < 8; x++)
                {
                    for (var z = -8; z < 8; z++)
                    {
                        _terrainMap.CreateChunk(new Vector3Int(x * 16, y * 16, z * 16));
                    }
                }
            }
        }
Пример #2
0
        internal VoxelTerrainChunk(VoxelTerrainMap terrainMap, Vector3Int worldPosition)
        {
            State = VoxelTerrainChunkState.Uncompleted;

            WorldPosition  = worldPosition;
            OffsetPosition = new Vector3Int(worldPosition.X / Width, worldPosition.Y / Height,
                                            worldPosition.Z / Length);

            _terrainMap = terrainMap;
            _voxels     = new Voxel[Width, Height, Length];

            // Create model
            Model = Content.CreateVirtualAsset <Model>();

            // Create chunk actor
            Actor                     = VoxelTerrainManager.Current.Actor.AddChild <StaticModel>();
            Actor.Name                = "VoxelTerrain Chunk";
            Actor.Model               = Model;
            Actor.LocalScale          = new Vector3(100);
            Actor.LocalPosition       = new Vector3(worldPosition.X, worldPosition.Y, worldPosition.Z) * 100.0f;
            Actor.Entries[0].Material = VoxelTerrainManager.Current.DefaultMaterial;

            // Add mesh collider
            Collider = Actor.AddChild <MeshCollider>();
        }