Exemple #1
0
 //  Checks if cell didn't change to FULL and if is, we set it to null
 public void CheckIfCellChangedToFull(MyVoxelContentCell voxelCell, ref MyMwcVector3Int cellCoord)
 {
     if (voxelCell.CellType == MyVoxelCellType.FULL)
     {
         m_voxelContentCells[cellCoord.X][cellCoord.Y][cellCoord.Z] = null;
     }
 }
Exemple #2
0
        //  This method initializes voxel map (size, position, etc) but doesn't load voxels
        //  It only presets all materials to values specified in 'defaultMaterial' - so it will become material everywhere.
        void InitVoxelMap(Vector3 position, MyMwcVector3Int size, MyMwcVoxelMaterialsEnum material)
        {
            MyMwcLog.WriteLine("MyVoxelMap.InitVoxelMap() - Start");
            MyMwcLog.IncreaseIndent();

            VoxelMaterial = material;

            VoxelMapId = MyVoxelMaps.GetUniqueVoxelMapId();

            MyMwcLog.WriteLine("ID: " + VoxelMapId, LoggingOptions.VOXEL_MAPS);
            MyMwcLog.WriteLine("Size: " + MyUtils.GetFormatedVector3Int(size), LoggingOptions.VOXEL_MAPS);

            //  If you need more voxel maps, enlarge this constant.
            MyCommonDebugUtils.AssertRelease(VoxelMapId <= MyVoxelConstants.MAX_VOXEL_MAP_ID);

            Size = size;
            SizeMinusOne = new MyMwcVector3Int(Size.X - 1, Size.Y - 1, Size.Z - 1);

            SizeInMetres = GetVoxelSizeInMetres(ref size);
            SizeInMetresHalf = SizeInMetres / 2.0f;

            LocalAABB = new BoundingBox(-SizeInMetresHalf, SizeInMetresHalf);

            PositionLeftBottomCorner = position;
            SetWorldMatrix(Matrix.CreateTranslation(PositionLeftBottomCorner + SizeInMetresHalf));

            Flags |= EntityFlags.EditableInEditor;

            //  If you need larged voxel maps, enlarge this constant.
            MyCommonDebugUtils.AssertRelease(Size.X <= MyVoxelConstants.MAX_VOXEL_MAP_SIZE_IN_VOXELS);
            MyCommonDebugUtils.AssertRelease(Size.Y <= MyVoxelConstants.MAX_VOXEL_MAP_SIZE_IN_VOXELS);
            MyCommonDebugUtils.AssertRelease(Size.Z <= MyVoxelConstants.MAX_VOXEL_MAP_SIZE_IN_VOXELS);

            //  Voxel map size must be multiple of a voxel data cell size.
            MyCommonDebugUtils.AssertRelease((Size.X & MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
            MyCommonDebugUtils.AssertRelease((Size.Y & MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
            MyCommonDebugUtils.AssertRelease((Size.Z & MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_MASK) == 0);
            DataCellsCount.X = Size.X >> MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS;
            DataCellsCount.Y = Size.Y >> MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS;
            DataCellsCount.Z = Size.Z >> MyVoxelConstants.VOXEL_DATA_CELL_SIZE_IN_VOXELS_BITS;
            DataCellsCountMinusOne = new MyMwcVector3Int(DataCellsCount.X - 1, DataCellsCount.Y - 1, DataCellsCount.Z - 1);

            //  Voxel map size must be multiple of a voxel data cell size.
            MyCommonDebugUtils.AssertRelease((Size.X % MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_VOXELS) == 0);
            MyCommonDebugUtils.AssertRelease((Size.Y % MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_VOXELS) == 0);
            MyCommonDebugUtils.AssertRelease((Size.Z % MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_VOXELS) == 0);
            RenderCellsCount.X = Size.X / MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_VOXELS;
            RenderCellsCount.Y = Size.Y / MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_VOXELS;
            RenderCellsCount.Z = Size.Z / MyVoxelConstants.VOXEL_RENDER_CELL_SIZE_IN_VOXELS;
            RenderCellsCountMinusOne = new MyMwcVector3Int(RenderCellsCount.X - 1, RenderCellsCount.Y - 1, RenderCellsCount.Z - 1);

            m_fakeVoxelMaterial.DrawTechnique = MyMeshDrawTechnique.VOXEL_MAP;
            //  Array of voxel cells in this voxel map
            m_voxelContentCells = new MyVoxelContentCell[DataCellsCount.X][][];
            for (int x = 0; x < m_voxelContentCells.Length; x++)
            {
                m_voxelContentCells[x] = new MyVoxelContentCell[DataCellsCount.Y][];
                for (int y = 0; y < m_voxelContentCells[x].Length; y++)
                {
                    m_voxelContentCells[x][y] = new MyVoxelContentCell[DataCellsCount.Z];
                }
            }

            CastShadows = true;

            InitRenderObjects();

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //  Materials
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////

            byte defaultIndestructibleContents = GetIndestructibleContentByMaterial(material);

            m_voxelMaterialCells = new MyVoxelMaterialCell[DataCellsCount.X][][];
            for (int x = 0; x < DataCellsCount.X; x++)
            {
                m_voxelMaterialCells[x] = new MyVoxelMaterialCell[DataCellsCount.Y][];
                for (int y = 0; y < DataCellsCount.Y; y++)
                {
                    m_voxelMaterialCells[x][y] = new MyVoxelMaterialCell[DataCellsCount.Z];
                    for (int z = 0; z < DataCellsCount.Z; z++)
                    {
                        m_voxelMaterialCells[x][y][z] = new MyVoxelMaterialCell(material, defaultIndestructibleContents);
                    }
                }
            }


            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //  Voxel map as phys object
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////            

            //initialize list of voxelHandShapes used for editor purpose
            m_voxelHandShapes = new List<MyVoxelHandShape>(100);

            //initialize list of explosions, to save cutted spheres fast, before we convert them to voxel hands
            m_explosions = new List<BoundingSphere>(1000);

            MyPhysicsObjects physobj = MyPhysics.physicsSystem.GetPhysicsObjects();
            MyRBVoxelElementDesc voxelDesc = physobj.GetRBVoxelElementDesc();
            MyMaterialType materialType = MyMaterialType.ROCK;

            voxelDesc.SetToDefault();
            voxelDesc.m_Size = SizeInMetres;
            voxelDesc.m_RBMaterial = MyMaterialsConstants.GetMaterialProperties(materialType).PhysicsMaterial;

            MyRBVoxelElement voxEl = (MyRBVoxelElement)physobj.CreateRBElement(voxelDesc);

            this.Physics = new MyPhysicsBody(this, 100000, RigidBodyFlag.RBF_RBO_STATIC) { MaterialType = materialType };
            this.Physics.Enabled = true;
            this.Physics.AddElement(voxEl, true);

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyVoxelMap.InitVoxelMap() - End");
        }
Exemple #3
0
        //  Allocates cell from a buffer, store reference to dictionary and return reference to the cell
        //  Use it when changing cell type from full to empty or mixed.
        public MyVoxelContentCell AddCell(ref MyMwcVector3Int cellCoord)
        {
            //  Adding or creating cell can be made only once
            Debug.Assert(m_voxelContentCells[cellCoord.X][cellCoord.Y][cellCoord.Z] == null);

            MyVoxelContentCell ret = new MyVoxelContentCell();
            m_voxelContentCells[cellCoord.X][cellCoord.Y][cellCoord.Z] = ret;

            return ret;
        }