private MyObjectBuilder_CubeGrid BuildShipEntity()
        {
            var entity = new MyObjectBuilder_CubeGrid
            {
                EntityId        = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY),
                PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene,
                Skeleton        = new System.Collections.Generic.List <BoneInfo>(),
                LinearVelocity  = new VRageMath.Vector3(0, 0, 0),
                AngularVelocity = new VRageMath.Vector3(0, 0, 0)
            };

            var blockPrefix = "";

            switch (ClassType)
            {
            case ImportModelClassType.SmallShip:
                entity.GridSizeEnum = MyCubeSize.Small;
                blockPrefix        += "Small";
                entity.IsStatic     = false;
                break;

            case ImportModelClassType.SmallStation:
                entity.GridSizeEnum = MyCubeSize.Small;
                blockPrefix        += "Small";
                entity.IsStatic     = true;
                Position            = Position.RoundOff(MyCubeSize.Small.ToLength());
                Forward             = Forward.RoundToAxis();
                Up = Up.RoundToAxis();
                break;

            case ImportModelClassType.LargeShip:
                entity.GridSizeEnum = MyCubeSize.Large;
                blockPrefix        += "Large";
                entity.IsStatic     = false;
                break;

            case ImportModelClassType.LargeStation:
                entity.GridSizeEnum = MyCubeSize.Large;
                blockPrefix        += "Large";
                entity.IsStatic     = true;
                Position            = Position.RoundOff(MyCubeSize.Large.ToLength());
                Forward             = Forward.RoundToAxis();
                Up = Up.RoundToAxis();
                break;
            }

            switch (ArmorType)
            {
            case ImportArmorType.Heavy: blockPrefix += "HeavyBlockArmor"; break;

            case ImportArmorType.Light: blockPrefix += "BlockArmor"; break;

                // TODO: Rounded Armor.
                // Currently in development, and only specified as 'Light' on the 'Large' structures.
                //case ImportArmorType.Round: blockPrefix += "RoundArmor_"; break;
            }

            // Large|BlockArmor|Corner
            // Large|RoundArmor_|Corner
            // Large|HeavyBlockArmor|Block,
            // Small|BlockArmor|Slope,
            // Small|HeavyBlockArmor|Corner,

            var blockType              = (SubtypeId)Enum.Parse(typeof(SubtypeId), blockPrefix + "Block");
            var slopeBlockType         = (SubtypeId)Enum.Parse(typeof(SubtypeId), blockPrefix + "Slope");
            var cornerBlockType        = (SubtypeId)Enum.Parse(typeof(SubtypeId), blockPrefix + "Corner");
            var inverseCornerBlockType = (SubtypeId)Enum.Parse(typeof(SubtypeId), blockPrefix + "CornerInv");

            entity.CubeBlocks = new System.Collections.Generic.List <MyObjectBuilder_CubeBlock>();

            double multiplier;

            if (IsMultipleScale)
            {
                multiplier = MultipleScale;
            }
            else
            {
                multiplier = MaxLengthScale / Math.Max(Math.Max(OriginalModelSize.Height, OriginalModelSize.Width), OriginalModelSize.Depth);
            }

            var ccubic = Modelling.ReadModelVolmetic(Filename, multiplier, null, TraceType, MainViewModel.ResetProgress, MainViewModel.IncrementProgress);

            Modelling.BuildStructureFromCubic(entity, ccubic, FillObject, blockType, slopeBlockType, cornerBlockType, inverseCornerBlockType);

            MainViewModel.ClearProgress();

            entity.PositionAndOrientation = new MyPositionAndOrientation
            {
                // TODO: reposition based scale.
                Position = Position.ToVector3D(),
                Forward  = Forward.ToVector3(),
                Up       = Up.ToVector3()
            };

            IsValidModel = entity.CubeBlocks.Count > 0;

            return(entity);
        }
        public MyObjectBuilder_CubeGrid BuildTestEntity()
        {
            var entity = new MyObjectBuilder_CubeGrid
            {
                EntityId        = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY),
                PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene,
                Skeleton        = new System.Collections.Generic.List <BoneInfo>(),
                LinearVelocity  = new VRageMath.Vector3(0, 0, 0),
                AngularVelocity = new VRageMath.Vector3(0, 0, 0),
                GridSizeEnum    = MyCubeSize.Large
            };

            var blockPrefix       = entity.GridSizeEnum.ToString();
            var cornerBlockPrefix = entity.GridSizeEnum.ToString();

            entity.IsStatic    = false;
            blockPrefix       += "BlockArmor"; // HeavyBlockArmor|BlockArmor;
            cornerBlockPrefix += "BlockArmor"; // HeavyBlockArmor|BlockArmor|RoundArmor_;

            // Figure out where the Character is facing, and plant the new constrcut right in front, by "10" units, facing the Character.
            var vector = new BindableVector3DModel(_dataModel.CharacterPosition.Forward).Vector3D;

            vector.Normalize();
            vector   = Vector3D.Multiply(vector, 6);
            Position = new BindablePoint3DModel(Point3D.Add(new BindablePoint3DModel(_dataModel.CharacterPosition.Position).Point3D, vector));
            Forward  = new BindableVector3DModel(_dataModel.CharacterPosition.Forward);
            Up       = new BindableVector3DModel(_dataModel.CharacterPosition.Up);

            entity.PositionAndOrientation = new MyPositionAndOrientation
            {
                Position = Position.ToVector3D(),
                Forward  = Forward.ToVector3(),
                Up       = Up.ToVector3()
            };

            // Large|BlockArmor|Corner
            // Large|RoundArmor_|Corner
            // Large|HeavyBlockArmor|Block,
            // Small|BlockArmor|Slope,
            // Small|HeavyBlockArmor|Corner,

            var blockType              = (SubtypeId)Enum.Parse(typeof(SubtypeId), blockPrefix + "Block");
            var slopeBlockType         = (SubtypeId)Enum.Parse(typeof(SubtypeId), cornerBlockPrefix + "Slope");
            var cornerBlockType        = (SubtypeId)Enum.Parse(typeof(SubtypeId), cornerBlockPrefix + "Corner");
            var inverseCornerBlockType = (SubtypeId)Enum.Parse(typeof(SubtypeId), cornerBlockPrefix + "CornerInv");

            entity.CubeBlocks = new System.Collections.Generic.List <MyObjectBuilder_CubeBlock>();

            //var smoothObject = true;

            // Read in voxel and set main cube space.
            //var ccubic = TestCreateSplayedDiagonalPlane();
            //var ccubic = TestCreateSlopedDiagonalPlane();
            //var ccubic = TestCreateStaggeredStar();
            var ccubic = Modelling.TestCreateTrayShape();
            //var ccubic = ReadModelVolmetic(@"..\..\..\..\..\..\building 3D\models\Rhino_corrected.obj", 10, null, ModelTraceVoxel.ThickSmoothedDown);

            var fillObject = false;

            //if (smoothObject)
            //{
            //    CalculateAddedInverseCorners(ccubic);
            //    CalculateAddedSlopes(ccubic);
            //    CalculateAddedCorners(ccubic);
            //}

            Modelling.BuildStructureFromCubic(entity, ccubic, fillObject, blockType, slopeBlockType, cornerBlockType, inverseCornerBlockType);

            return(entity);
        }