Пример #1
0
        public MyObjectBuilder_EntityBase BuildEntity()
        {
            var asteroidCenter = new VRageMath.Vector3D();
            var asteroidSize = new Vector3I();

            string originalFile = null;
            if (IsStockVoxel)
            {
                var stockfile = StockVoxel.SourceFilename;

                if (StockMaterial == null || StockMaterial.Value == null)
                {
                    SourceFile = stockfile;
                    originalFile = SourceFile;
                    var asteroid = new MyVoxelMap();
                    asteroid.Load(stockfile, SpaceEngineersCore.Resources.GetDefaultMaterialName(), false);
                    asteroidCenter = asteroid.BoundingContent.Center;
                    asteroidSize = asteroid.BoundingContent.SizeInt() + 1; // Content size
                }
                else
                {
                    var asteroid = new MyVoxelMap();
                    asteroid.Load(stockfile, StockMaterial.Value);
                    asteroid.ForceBaseMaterial(SpaceEngineersCore.Resources.GetDefaultMaterialName(), StockMaterial.Value);
                    SourceFile = TempfileUtil.NewFilename(MyVoxelMap.V2FileExtension);
                    asteroid.Save(SourceFile);

                    originalFile = StockVoxel.SourceFilename;
                    asteroidCenter = asteroid.BoundingContent.Center;
                    asteroidSize = asteroid.BoundingContent.SizeInt() + 1; // Content size
                }
            }
            else if (IsFileVoxel)
            {
                originalFile = SourceFile;

                var asteroid = new MyVoxelMap();
                asteroid.Load(SourceFile, SpaceEngineersCore.Resources.GetDefaultMaterialName(), false);
                asteroidCenter = asteroid.BoundingContent.Center;
                asteroidSize = asteroid.BoundingContent.SizeInt() + 1; // Content size

                if (StockMaterial != null && StockMaterial.Value != null)
                {
                    asteroid.ForceBaseMaterial(SpaceEngineersCore.Resources.GetDefaultMaterialName(), StockMaterial.Value);
                    SourceFile = TempfileUtil.NewFilename(MyVoxelMap.V2FileExtension);
                    asteroid.Save(SourceFile);
                }
            }
            else if (IsSphere)
            {
                string material;
                if (StockMaterial != null && StockMaterial.Value != null)
                    material = StockMaterial.Value;
                else
                    material = SpaceEngineersCore.Resources.GetDefaultMaterialName();

                originalFile = string.Format("sphere_{0}_{1}_{2}{3}", material.ToLowerInvariant(), SphereRadius, SphereShellRadius, MyVoxelMap.V2FileExtension);

                var asteroid = MyVoxelBuilder.BuildAsteroidSphere(SphereRadius > 32, SphereRadius, material, material, SphereShellRadius != 0, SphereShellRadius);
                // TODO: progress bar.
                asteroidCenter = asteroid.BoundingContent.Center;
                asteroidSize = asteroid.BoundingContent.SizeInt() + 1; // Content size
                SourceFile = TempfileUtil.NewFilename(MyVoxelMap.V2FileExtension);
                asteroid.Save(SourceFile);
            }

            // automatically number all files, and check for duplicate filenames.
            Filename = MainViewModel.CreateUniqueVoxelStorageName(originalFile);

            // Figure out where the Character is facing, and plant the new constrcut right in front.
            // Calculate the hypotenuse, as it will be the safest distance to place in front.
            double distance = Math.Sqrt(Math.Pow(asteroidSize.X, 2) + Math.Pow(asteroidSize.Y, 2) + Math.Pow(asteroidSize.Z, 2)) / 2;

            var vector = new BindableVector3DModel(_dataModel.CharacterPosition.Forward).Vector3D;
            vector.Normalize();
            vector = System.Windows.Media.Media3D.Vector3D.Multiply(vector, distance);
            Position = new BindablePoint3DModel(Point3D.Add(new BindablePoint3DModel(_dataModel.CharacterPosition.Position).Point3D, vector));
            //Forward = new BindableVector3DModel(_dataModel.CharacterPosition.Forward);
            //Up = new BindableVector3DModel(_dataModel.CharacterPosition.Up);
            Forward = new BindableVector3DModel(Vector3.Forward);  // Asteroids currently don't have any orientation.
            Up = new BindableVector3DModel(Vector3.Up);

            var entity = new MyObjectBuilder_VoxelMap
            {
                EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ASTEROID),
                PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene,
                StorageName = Path.GetFileNameWithoutExtension(Filename),
                PositionAndOrientation = new MyPositionAndOrientation
                {
                    Position = Position.ToVector3D() - asteroidCenter,
                    Forward = Forward.ToVector3(),
                    Up = Up.ToVector3()
                }
            };

            return entity;
        }
Пример #2
0
        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;
        }
Пример #3
0
        private void ProcessFilename(string filename)
        {
            IsBusy = true;

            if (File.Exists(filename))
            {
                // TODO: validate file is a real image.

                // TODO: read image properties.

                if (_sourceImage != null)
                {
                    _sourceImage.Dispose();
                }

                _sourceImage = Image.FromFile(filename);
                OriginalImageSize = new Size(_sourceImage.Width, _sourceImage.Height);

                NewImageSize = new BindableSizeModel(_sourceImage.Width, _sourceImage.Height);
                NewImageSize.PropertyChanged += (sender, e) => ProcessImage();

                // 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, 10);
                Position = new BindablePoint3DModel(Point3D.Add(new BindablePoint3DModel(_dataModel.CharacterPosition.Position).Point3D, vector));
                Forward = new BindableVector3DModel(_dataModel.CharacterPosition.Forward).Negate();
                Up = new BindableVector3DModel(_dataModel.CharacterPosition.Up);

                ClassType = ImportImageClassType.SmallShip;
                ArmorType = ImportArmorType.Light;

                IsValidImage = true;
            }
            else
            {
                IsValidImage = false;
                Position = new BindablePoint3DModel(0, 0, 0);
                OriginalImageSize = new Size(0, 0);
                NewImageSize = new BindableSizeModel(0, 0);
            }

            IsBusy = false;
        }
Пример #4
0
        private void ProcessModelScale()
        {
            if (IsValidModel)
            {
                if (IsMaxLengthScale)
                {
                    var factor = MaxLengthScale / Math.Max(Math.Max(OriginalModelSize.Height, OriginalModelSize.Width), OriginalModelSize.Depth);

                    NewModelSize.Height = (int)(factor * OriginalModelSize.Height);
                    NewModelSize.Width = (int)(factor * OriginalModelSize.Width);
                    NewModelSize.Depth = (int)(factor * OriginalModelSize.Depth);
                }
                else if (IsMultipleScale)
                {
                    NewModelSize.Height = (int)(MultipleScale * OriginalModelSize.Height);
                    NewModelSize.Width = (int)(MultipleScale * OriginalModelSize.Width);
                    NewModelSize.Depth = (int)(MultipleScale * OriginalModelSize.Depth);
                }

                double vectorDistance = BuildDistance;
                double scaleMultiplyer = 1;

                switch (ClassType)
                {
                    case ImportModelClassType.SmallShip: scaleMultiplyer = MyCubeSize.Small.ToLength(); break;
                    case ImportModelClassType.LargeShip: scaleMultiplyer = MyCubeSize.Large.ToLength(); break;
                    case ImportModelClassType.Station: scaleMultiplyer = MyCubeSize.Large.ToLength(); break;
                    case ImportModelClassType.Asteroid: scaleMultiplyer = 1; break;
                }
                vectorDistance += NewModelSize.Depth * scaleMultiplyer;
                NewModelScale = new BindablePoint3DModel(NewModelSize.Width * scaleMultiplyer, NewModelSize.Height * scaleMultiplyer, NewModelSize.Depth * scaleMultiplyer);

                // Figure out where the Character is facing, and plant the new construct right in front, by "10" units, facing the Character.
                var vector = new BindableVector3DModel(_dataModel.CharacterPosition.Forward).Vector3D;
                vector.Normalize();
                vector = Vector3D.Multiply(vector, vectorDistance);
                Position = new BindablePoint3DModel(Point3D.Add(new BindablePoint3DModel(_dataModel.CharacterPosition.Position).Point3D, vector));
                Forward = new BindableVector3DModel(_dataModel.CharacterPosition.Forward);
                Up = new BindableVector3DModel(_dataModel.CharacterPosition.Up);
            }
        }