コード例 #1
0
        private void CreateLandSurface()
        {
            DiffuseMaterial _landMaterial     = (DiffuseMaterial)this.FindResource("LandMaterial");
            DiffuseMaterial _landBackMaterial = (DiffuseMaterial)this.FindResource("LandBackMaterial");
            GeometryModel3D _landModel        = new GeometryModel3D();

            _landModel.Material     = _landMaterial;
            _landModel.BackMaterial = _landBackMaterial;

            double         _landSize      = JsdTile.GetProfileXSize(this.ViewModel.Structure.IsHighDefenition) * 5;
            MeshGeometry3D _landGeometry  = new MeshGeometry3D();
            List <Point3D> _landPositions = new List <Point3D>(4);
            double         _landLevel     = -this.ViewModel.Center.Z;

            _landPositions.Add(new Point3D(-_landSize, _landLevel, -_landSize));
            _landPositions.Add(new Point3D(-_landSize, _landLevel, _landSize));
            _landPositions.Add(new Point3D(_landSize, _landLevel, _landSize));
            _landPositions.Add(new Point3D(_landSize, _landLevel, -_landSize));

            List <int> _landIndeces = new List <int>()
            {
                0, 1, 2, 2, 3, 0
            };

            _landGeometry.Positions       = new Point3DCollection(_landPositions);
            _landGeometry.TriangleIndices = new Int32Collection(_landIndeces);
            _landModel.Geometry           = _landGeometry;
            this.mgShape.Children.Add(_landModel);
        }
コード例 #2
0
        private void AddTile(TileViewModel aTile)
        {
            GeometryModel3D _tileGeometry = new GeometryModel3D();

            _tileGeometry.Geometry     = new MeshGeometry3D();
            _tileGeometry.Material     = this.FTileMaterial;
            _tileGeometry.BackMaterial = this.FBackTileMaterial;

            TileGeometry _tile = new TileGeometry(
                aTile,
                _tileGeometry,
                null,
                this.ViewModel.Structure.IsHighDefenition,
                this.ViewModel.Center);

            this.FTiles.Add(_tile);

            int _tileSize   = JsdTile.GetProfileXSize(aTile.IsHighDefenition);
            int _tileBottom = aTile.TileIsOnRoof ? JsdTile.GetProfileZSize(aTile.IsHighDefenition) : 0;

            foreach (LayerCellViewModel _cell in aTile.ShapeViewModel.Cells)
            {
                if (_cell.LayerCellValue)
                {
                    _tile.AttachCube(_cell.X, _cell.Y, _cell.Z * 2, false, _tileSize, _tileBottom, false);
                }
            }

            //_tile.JoinCubeSides();

            _tile.UpdateTileGeometry();

            this.mgShape.Children.Add(_tileGeometry);
        }
コード例 #3
0
        private void CreateLandSurface()
        {
            DiffuseMaterial _landMaterial     = (DiffuseMaterial)this.FindResource("LandMaterial");
            DiffuseMaterial _landBackMaterial = (DiffuseMaterial)this.FindResource("LandBackMaterial");
            GeometryModel3D _landModel        = new GeometryModel3D();

            _landModel.Material     = _landMaterial;
            _landModel.BackMaterial = _landBackMaterial;

            int     _landSize   = 5;
            Point3D _tileCenter = this.ViewModel.TileCenter;
            Point3D _center     = this.ViewModel.Center;
            double  _shiftX     = 2 * _tileCenter.X - _center.X;
            double  _shiftY     = 2 * _tileCenter.Y - _center.Y;
            double  _landLevel  = -_center.Z;

            double         _tileSize      = JsdTile.GetProfileXSize(this.ViewModel.Structure.IsHighDefenition);
            MeshGeometry3D _landGeometry  = new MeshGeometry3D();
            List <Point3D> _landPositions = new List <Point3D>(_landSize * _landSize * 4 * 4);
            List <int>     _landIndeces   = new List <int>(_landSize * _landSize * 4 * 6);

            int _tileCount   = 0;
            int _xStartIndex = (int)(-_landSize - _shiftX / _tileSize);
            int _xEndIndex   = _xStartIndex + 2 * _landSize;
            int _yStartIndex = (int)(-_landSize - _shiftY / _tileSize);
            int _yEndIndex   = _yStartIndex + 2 * _landSize;

            for (int i = _xStartIndex; i < _xEndIndex; i++)
            {
                for (int j = _yStartIndex; j < _yEndIndex; j++)
                {
                    if ((i + j) % 2 == 0)
                    {
                        continue;
                    }

                    _landPositions.Add(new Point3D(
                                           _tileSize * (i - 1) + _shiftX, _landLevel, _tileSize * (j - 1) + _shiftY));
                    _landPositions.Add(new Point3D(
                                           _tileSize * i + _shiftX, _landLevel, _tileSize * (j - 1) + _shiftY));
                    _landPositions.Add(new Point3D(
                                           _tileSize * i + _shiftX, _landLevel, _tileSize * j + _shiftY));
                    _landPositions.Add(new Point3D(
                                           _tileSize * (i - 1) + _shiftX, _landLevel, _tileSize * j + _shiftY));

                    int _startIndex = _tileCount * 4;
                    _landIndeces.AddRange(new List <int>()
                    {
                        _startIndex + 0, _startIndex + 3, _startIndex + 2,
                        _startIndex + 2, _startIndex + 1, _startIndex + 0
                    });
                    _tileCount++;
                }
            }

            _landGeometry.Positions       = new Point3DCollection(_landPositions);
            _landGeometry.TriangleIndices = new Int32Collection(_landIndeces);
            _landModel.Geometry           = _landGeometry;
            this.mgShape.Children.Add(_landModel);
        }
コード例 #4
0
        private void AddTile(TileViewModel aTile)
        {
            GeometryModel3D _tileGeometry = new GeometryModel3D();

            _tileGeometry.Geometry = new MeshGeometry3D();

            GeometryModel3D _altTileGeometry = new GeometryModel3D();

            _altTileGeometry.Geometry = new MeshGeometry3D();

            if (aTile.IsSelected)
            {
                _tileGeometry.Material        = this.FSelectedTileMaterial;
                _tileGeometry.BackMaterial    = this.FSelectedBackTileMaterial;
                _altTileGeometry.Material     = this.FAltSelectedTileMaterial;
                _altTileGeometry.BackMaterial = this.FAltSelectedTileMaterial;
            }
            else
            {
                _tileGeometry.Material        = this.FTileMaterial;
                _tileGeometry.BackMaterial    = this.FBackTileMaterial;
                _altTileGeometry.Material     = this.FAltTileMaterial;
                _altTileGeometry.BackMaterial = this.FAltTileMaterial;
            }

            TileGeometry _tile = new TileGeometry(
                aTile,
                _tileGeometry,
                _altTileGeometry,
                this.ViewModel.Structure.IsHighDefenition,
                this.ViewModel.Center);

            this.FTiles.Add(_tile);

            int _tileSize   = JsdTile.GetProfileXSize(aTile.IsHighDefenition);
            int _tileBottom = aTile.TileIsOnRoof ? JsdTile.GetProfileZSize(aTile.IsHighDefenition) : 0;

            foreach (LayerCellViewModel _cell in aTile.ShapeViewModel.Cells)
            {
                if (_cell.LayerCellValue)
                {
                    _tile.AddCube(_cell.X, _cell.Y, _cell.Z, _tileSize, _tileBottom);
                    this.ViewModel.FilledPositionCount++;
                }
                _cell.AttachHandler(this, Cell_PropertyChanged);
            }

            _tile.UpdateTileGeometry();

            this.mgShape.Children.Add(_tileGeometry);
            this.mgShape.Children.Add(_altTileGeometry);
        }
コード例 #5
0
        private void ProcessCell(LayerCellViewModel aCell, TileViewModel aTile)
        {
            TileGeometry _tile       = this.FTiles.Where(x => x.Tile == aTile).SingleOrDefault();
            int          _tileSize   = JsdTile.GetProfileXSize(aTile.IsHighDefenition);
            int          _tileBottom = aTile.TileIsOnRoof ? JsdTile.GetProfileZSize(aTile.IsHighDefenition) : 0;

            if (aCell.LayerCellValue)
            {
                _tile.AddCube(aCell.X, aCell.Y, aCell.Z, _tileSize, _tileBottom);
                this.ViewModel.FilledPositionCount++;
            }
            else
            {
                _tile.RemoveCube(aCell.X, aCell.Y, aCell.Z, _tileSize, _tileBottom);
                this.ViewModel.FilledPositionCount--;
            }

            _tile.UpdateTileGeometry();
        }
コード例 #6
0
        private GeometryModel3D AddTile(JsdTile aTile)
        {
            int _tileSize   = JsdTile.GetProfileXSize(aTile.IsHighDefenition);
            int _tileBottom = (aTile.Flags & JsdTile.JsdTileFlags.TILE_ON_ROOF) > 0 ?
                              JsdTile.GetProfileZSize(aTile.IsHighDefenition) : 0;

            GeometryModel3D _tileGeometry = new GeometryModel3D();

            _tileGeometry.Geometry     = new MeshGeometry3D();
            _tileGeometry.Material     = this.FTileMaterial;
            _tileGeometry.BackMaterial = this.FBackTileMaterial;

            TileGeometry _tile = new TileGeometry(
                aTile,
                _tileGeometry,
                aTile.IsHighDefenition,
                this.ViewModel.Center);

            for (int i = 0; i < aTile.ProfileSize; i++)
            {
                int y = i % aTile.ProfileXSize;
                int x = i / aTile.ProfileXSize;
                for (int z = 0; z < aTile.ProfileZSize; z++)
                {
                    int _mask = 1 << z;
                    if ((aTile.Shape[i] & _mask) > 0)
                    {
                        _tile.AttachCube(x, y, z * 2, false, _tileSize, _tileBottom);
                    }
                }
            }

            //_tile.JoinCubeSides();
            _tile.UpdateTileGeometry();
            this.mgShape.Children.Add(_tileGeometry);
            return(_tileGeometry);
        }