Exemple #1
0
        private void SetProperties(MyObjectBuilder_CubeBlock cube, MyObjectBuilder_CubeBlockDefinition definition)
        {
            Cube     = cube;
            Position = new BindablePoint3DIModel(cube.Min);
            SetColor(cube.ColorMaskHSV);
            BuildPercent = cube.BuildPercent;

            if (definition == null)
            {
                // Obsolete block or Mod not loaded.
                return;
            }

            CubeSize     = definition.CubeSize;
            FriendlyName = SpaceEngineersApi.GetResourceName(definition.DisplayName);

            var identity = SpaceEngineersCore.WorldResource.Checkpoint.Identities.FirstOrDefault(p => p.PlayerId == Owner);
            var dead     = " (dead)";

            if (SpaceEngineersCore.WorldResource.Checkpoint.AllPlayersData != null)
            {
                var player = SpaceEngineersCore.WorldResource.Checkpoint.AllPlayersData.Dictionary.FirstOrDefault(kvp => kvp.Value.IdentityId == Owner);
                dead = player.Value == null ? " (dead)" : "";
            }
            OwnerName = identity == null ? null : identity.DisplayName + dead;
            TypeId    = definition.Id.TypeId;
            SubtypeId = definition.Id.SubtypeId;

            if (Inventory == null)
            {
                Inventory = new ObservableCollection <InventoryEditorModel>();
            }

            foreach (var item in cube.ComponentContainer.GetInventory(definition))
            {
                Inventory.Add(item);
            }

            while (Inventory.Count < 2)
            {
                Inventory.Add(new InventoryEditorModel(false));
            }
        }
Exemple #2
0
        public void InitNavigationInfo(MyObjectBuilder_CubeBlockDefinition blockDef, string infoSubtypeId)
        {
            if (MyPerGameSettings.EnableAi)
            {
                if (infoSubtypeId == "Default")
                {
                    MyDefinitionManager.Static.SetDefaultNavDef(this);
                }
                else
                {
                    MyDefinitionId id = new MyDefinitionId(typeof(MyObjectBuilder_BlockNavigationDefinition), infoSubtypeId);
                    MyDefinitionManager.Static.TryGetDefinition(id, out NavigationDefinition);
                }

                if (NavigationDefinition != null && NavigationDefinition.Mesh != null)
                {
                    NavigationDefinition.Mesh.MakeStatic();
                }
            }
        }
Exemple #3
0
 public CubeBlockDef(MyObjectBuilder_CubeBlockDefinition definition)
     : base(definition)
 {
 }
Exemple #4
0
        public override MyObjectBuilder_DefinitionBase GetObjectBuilder()
        {
            MyObjectBuilder_CubeBlockDefinition ob = (MyObjectBuilder_CubeBlockDefinition)base.GetObjectBuilder();

            ob.Size  = this.Size;
            ob.Model = this.Model;
            ob.UseModelIntersection = this.UseModelIntersection;
            ob.CubeSize             = this.CubeSize;
            ob.ModelOffset          = this.ModelOffset;
            ob.BlockTopology        = this.BlockTopology;
            ob.PhysicsOption        = this.PhysicsOption;
            ob.BlockPairName        = this.BlockPairName;
            ob.Center             = this.m_center;
            ob.MirroringX         = this.m_symmetryX;
            ob.MirroringY         = this.m_symmetryY;
            ob.MirroringZ         = this.m_symmetryZ;
            ob.DeformationRatio   = this.DeformationRatio;
            ob.EdgeType           = this.EdgeType;
            ob.AutorotateMode     = this.AutorotateMode;
            ob.MirroringBlock     = this.m_mirroringBlock;
            ob.MultiBlock         = this.MultiBlock;
            ob.GuiVisible         = this.GuiVisible;
            ob.Rotation           = this.Rotation;
            ob.Direction          = this.Direction;
            ob.Mirrored           = this.Mirrored;
            ob.BuildType          = this.BuildType;
            ob.GeneratedBlockType = this.GeneratedBlockType.ToString();
            ob.DamageEffectId     = this.DamageEffectID.HasValue ? this.DamageEffectID.Value : 0;
            ob.CompoundTemplates  = this.CompoundTemplates;
            ob.Icon = Icon;
            //ob.SubBlockDefinitions = SubBlockDefinitions;
            //ob.BlockVariants = BlockVariants;


            if (Components != null)
            {
                List <MyObjectBuilder_CubeBlockDefinition.CubeBlockComponent> compObs = new List <MyObjectBuilder_CubeBlockDefinition.CubeBlockComponent>();
                foreach (var comp in Components)
                {
                    var compOb = new MyObjectBuilder_CubeBlockDefinition.CubeBlockComponent();
                    compOb.Count   = (ushort)comp.Count;
                    compOb.Type    = comp.Definition.Id.TypeId;
                    compOb.Subtype = comp.Definition.Id.SubtypeName;
                    compObs.Add(compOb);
                }

                ob.Components = compObs.ToArray();
            }

            ob.CriticalComponent = new MyObjectBuilder_CubeBlockDefinition.CriticalPart()
            {
                Index   = 0,
                Subtype = ob.Components[0].Subtype,
                Type    = ob.Components[0].Type
            };

            List <MyObjectBuilder_CubeBlockDefinition.MountPoint> mountPoints = null;

            if (MountPoints != null)
            {
                mountPoints = new List <MyObjectBuilder_CubeBlockDefinition.MountPoint>();
                foreach (var mountPoint in MountPoints)
                {
                    MyObjectBuilder_CubeBlockDefinition.MountPoint mpOb = mountPoint.GetObjectBuilder(Size);
                    mountPoints.Add(mpOb);
                }

                ob.MountPoints = mountPoints.ToArray();
            }

            return(ob);
        }
        private void InitMountPoints(MyObjectBuilder_CubeBlockDefinition def)
        {
            if (MountPoints != null)
            {
                return;
            }

            var center = (Size - 1) / 2;


            if (!Context.IsBaseGame)
            {
                if (def.MountPoints != null && def.MountPoints.Length == 0)
                {
                    def.MountPoints = null;
                    string msg = "Obsolete default definition of mount points in " + def.Id;
                    MyDefinitionErrors.Add(Context, msg, ErrorSeverity.Warning);
                }
            }

            if (def.MountPoints == null)
            {
                // If there are no mount points defined, cover whole walls.
                List <MountPoint> mps = new List <MountPoint>(6);
                Vector3I          normalRight, normalLeft, normalTop, normalBottom, normalFront, normalBack;
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[0], out normalRight);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[1], out normalTop);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[2], out normalFront);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[3], out normalLeft);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[4], out normalBottom);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[5], out normalBack);

                // Right and left walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.Z - OFFSET_CONST, Size.Y - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 0, Size, out s1);
                    TransformMountPointPosition(ref end, 0, Size, out e1);
                    TransformMountPointPosition(ref start, 3, Size, out s2);
                    TransformMountPointPosition(ref end, 3, Size, out e2);
                    mps.Add(new MountPoint()
                    {
                        Start = s1, End = e1, Normal = normalRight, Enabled = true
                    });
                    mps.Add(new MountPoint()
                    {
                        Start = s2, End = e2, Normal = normalLeft, Enabled = true
                    });
                }

                // Top and bottom walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.X - OFFSET_CONST, Size.Z - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 1, Size, out s1);
                    TransformMountPointPosition(ref end, 1, Size, out e1);
                    TransformMountPointPosition(ref start, 4, Size, out s2);
                    TransformMountPointPosition(ref end, 4, Size, out e2);
                    mps.Add(new MountPoint()
                    {
                        Start = s1, End = e1, Normal = normalTop, Enabled = true
                    });
                    mps.Add(new MountPoint()
                    {
                        Start = s2, End = e2, Normal = normalBottom, Enabled = true
                    });
                }

                // Front and back walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.X - OFFSET_CONST, Size.Y - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 2, Size, out s1);
                    TransformMountPointPosition(ref end, 2, Size, out e1);
                    TransformMountPointPosition(ref start, 5, Size, out s2);
                    TransformMountPointPosition(ref end, 5, Size, out e2);
                    mps.Add(new MountPoint()
                    {
                        Start = s1, End = e1, Normal = normalFront, Enabled = true
                    });
                    mps.Add(new MountPoint()
                    {
                        Start = s2, End = e2, Normal = normalBack, Enabled = true
                    });
                }

                MountPoints = mps.ToArray();
                return;
            }
            else
            {
                Debug.Assert(m_tmpMounts.Count == 0);
                SetMountPoints(ref MountPoints, def.MountPoints, m_tmpMounts);

                if (def.BuildProgressModels != null)
                {
                    for (int index = 0; index < def.BuildProgressModels.Count; ++index)
                    {
                        var defBuildProgressModel = BuildProgressModels[index];
                        if (defBuildProgressModel == null)
                        {
                            continue;
                        }

                        var obBuildProgressModel = def.BuildProgressModels[index];
                        if (obBuildProgressModel.MountPoints == null)
                        {
                            continue;
                        }

                        foreach (var mountPoint in obBuildProgressModel.MountPoints)
                        {
                            int sideId = (int)mountPoint.Side;
                            if (!m_tmpIndices.Contains(sideId))
                            {
                                m_tmpMounts.RemoveAll((mount) => { return((int)mount.Side == sideId); });
                                m_tmpIndices.Add(sideId);
                            }
                            m_tmpMounts.Add(mountPoint);
                        }
                        m_tmpIndices.Clear();
                        defBuildProgressModel.MountPoints = new MountPoint[m_tmpMounts.Count];
                        SetMountPoints(ref defBuildProgressModel.MountPoints, m_tmpMounts.ToArray(), null);
                    }
                }
                m_tmpMounts.Clear();
            }
        }
 protected BlockDefinition(MyObjectBuilder_CubeBlockDefinition definition) : base(definition)
 {
 }
        //public static ObservableCollection<InventoryEditorModel> GetInventory(this MyObjectBuilder_EntityBase objectBuilderBase)
        //{
        //    var inventoryEditors = new ObservableCollection<InventoryEditorModel>();

        //    if (objectBuilderBase.ComponentContainer != null)
        //    {
        //        var inventoryBase = objectBuilderBase.ComponentContainer.Components.FirstOrDefault(e => e.TypeId == "MyInventoryBase");

        //        if (inventoryBase != null)
        //        {
        //            var singleInventory = inventoryBase.Component as MyObjectBuilder_Inventory;
        //            if (singleInventory != null)
        //            {
        //                var iem = ParseInventory(singleInventory);
        //                if (iem != null)
        //                    inventoryEditors.Add(iem);
        //            }

        //            var aggregate = inventoryBase.Component as MyObjectBuilder_InventoryAggregate;
        //            if (aggregate != null)
        //                foreach (var field in aggregate.Inventories)
        //                {
        //                    var iem = ParseInventory(field as MyObjectBuilder_Inventory);
        //                    if (iem != null)
        //                        inventoryEditors.Add(iem);
        //                }
        //        }
        //    }
        //    return inventoryEditors;
        //}

        public static ObservableCollection <InventoryEditorModel> GetInventory(this MyObjectBuilder_ComponentContainer componentContainer, MyObjectBuilder_CubeBlockDefinition definition = null)
        {
            var inventoryEditors = new ObservableCollection <InventoryEditorModel>();

            if (componentContainer != null)
            {
                var inventoryBase = componentContainer.Components.FirstOrDefault(e => e.TypeId == "MyInventoryBase");

                if (inventoryBase != null)
                {
                    var singleInventory = inventoryBase.Component as MyObjectBuilder_Inventory;
                    if (singleInventory != null)
                    {
                        var iem = ParseInventory(singleInventory, definition);
                        if (iem != null)
                        {
                            inventoryEditors.Add(iem);
                        }
                    }

                    var aggregate = inventoryBase.Component as MyObjectBuilder_InventoryAggregate;
                    if (aggregate != null)
                    {
                        foreach (var field in aggregate.Inventories)
                        {
                            var iem = ParseInventory(field as MyObjectBuilder_Inventory, definition);
                            if (iem != null)
                            {
                                inventoryEditors.Add(iem);
                            }
                        }
                    }
                }
            }
            return(inventoryEditors);
        }
        private static InventoryEditorModel ParseInventory(MyObjectBuilder_Inventory inventory, MyObjectBuilder_CubeBlockDefinition definition = null)
        {
            if (inventory == null)
            {
                return(null);
            }
            float volumeMultiplier = 1f; // Unsure if there should be a default of 1 if there isn't a InventorySize defined.

            if (definition == null)
            {
                volumeMultiplier = 0.4f;
            }
            else
            {
                var definitionType          = definition.GetType();
                var invSizeField            = definitionType.GetField("InventorySize");
                var inventoryMaxVolumeField = definitionType.GetField("InventoryMaxVolume");
                if (invSizeField != null)
                {
                    var invSize = (Vector3)invSizeField.GetValue(definition);
                    volumeMultiplier = invSize.X * invSize.Y * invSize.Z;
                }
                if (inventoryMaxVolumeField != null)
                {
                    var maxSize = (float)inventoryMaxVolumeField.GetValue(definition);
                    volumeMultiplier = MathHelper.Min(volumeMultiplier, maxSize);
                }
            }

            var settings = SpaceEngineersCore.WorldResource.Checkpoint.Settings;

            return(new InventoryEditorModel(inventory, volumeMultiplier * 1000 * settings.InventorySizeMultiplier, null)
            {
                Name = inventory.InventoryFlags.ToString(), IsValid = true
            });
        }
 public MyObjectBuilder_CubeBlock CreateCube(MyObjectBuilderType typeId, string subTypeId, MyObjectBuilder_CubeBlockDefinition definition)
 {
     return(_dataModel.CreateCube(typeId, subTypeId, definition));
 }
		public AirVentDefinition( MyObjectBuilder_CubeBlockDefinition definition ) : base( definition )
		{
		}
        public void InitNavigationInfo(MyObjectBuilder_CubeBlockDefinition blockDef, string infoSubtypeId)
        {
            if (MyPerGameSettings.EnableAi)
            {
                if (infoSubtypeId == "Default")
                {
                    MyDefinitionManager.Static.SetDefaultNavDef(this);
                }
                else
                {
                    MyDefinitionId id = new MyDefinitionId(typeof(MyObjectBuilder_BlockNavigationDefinition), infoSubtypeId);
                    MyDefinitionManager.Static.TryGetDefinition(id, out NavigationDefinition);
                }

                if (NavigationDefinition != null && NavigationDefinition.Mesh != null)
                    NavigationDefinition.Mesh.MakeStatic();
            }
        }
Exemple #12
0
        public MyObjectBuilder_CubeBlock CreateCube(MyObjectBuilderType typeId, string subTypeId, MyObjectBuilder_CubeBlockDefinition definition)
        {
            var newCube = SpaceEngineersCore.Resources.CreateNewObject <MyObjectBuilder_CubeBlock>(typeId, subTypeId);

            newCube.BlockOrientation = Cube.BlockOrientation;
            newCube.ColorMaskHSV     = Cube.ColorMaskHSV;
            newCube.BuildPercent     = Cube.BuildPercent;
            newCube.EntityId         = Cube.EntityId;
            newCube.IntegrityPercent = Cube.IntegrityPercent;
            newCube.Min = Cube.Min;

            SetProperties(newCube, definition);

            return(newCube);
        }
		private void SetMountPoints(ref MountPoint[] mountPoints, MyObjectBuilder_CubeBlockDefinition.MountPoint[] mpBuilders, List<MyObjectBuilder_CubeBlockDefinition.MountPoint> addedMounts)
		{
			if(mountPoints == null)
				mountPoints = new MountPoint[mpBuilders.Length];
			for (int i = 0; i < mountPoints.Length; ++i)
			{
				var mpBuilder = mpBuilders[i];
				if(addedMounts != null)
					addedMounts.Add(mpBuilder);
				// shrink mount points a little to avoid overlaps when they are very close.
				var mpStart = new Vector3((Vector2)mpBuilder.Start + OFFSET_CONST, THICKNESS_HALF);
				var mpEnd = new Vector3((Vector2)mpBuilder.End - OFFSET_CONST, -THICKNESS_HALF);
				var sideIdx = (int)mpBuilder.Side;
				var mpNormal = Vector3I.Forward;
				TransformMountPointPosition(ref mpStart, sideIdx, Size, out mpStart);
				TransformMountPointPosition(ref mpEnd, sideIdx, Size, out mpEnd);
				Vector3I.TransformNormal(ref mpNormal, ref m_mountPointTransforms[sideIdx], out mpNormal);
				mountPoints[i].Start = mpStart;
				mountPoints[i].End = mpEnd;
				mountPoints[i].Normal = mpNormal;
				mountPoints[i].ExclusionMask = mpBuilder.ExclusionMask;
				mountPoints[i].PropertiesMask = mpBuilder.PropertiesMask;
				mountPoints[i].Enabled = mpBuilder.Enabled;
			}
		}
        private void InitMountPoints(MyObjectBuilder_CubeBlockDefinition def)
        {
            if (MountPoints != null)
                return;

            var center = (Size - 1) / 2;


            if (!Context.IsBaseGame)
            {
                if (def.MountPoints != null && def.MountPoints.Length == 0)
                {
                    def.MountPoints = null;
                    string msg = "Obsolete default definition of mount points in " + def.Id;
                    MyDefinitionErrors.Add(Context, msg, TErrorSeverity.Warning);
                }
            }

            if (def.MountPoints == null)
            {
                // If there are no mount points defined, cover whole walls.
                List<MountPoint> mps = new List<MountPoint>(6);
                Vector3I normalRight, normalLeft, normalTop, normalBottom, normalFront, normalBack;
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[0], out normalRight);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[1], out normalTop);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[2], out normalFront);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[3], out normalLeft);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[4], out normalBottom);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[5], out normalBack);

                // Right and left walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.Z - OFFSET_CONST, Size.Y - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 0, Size, out s1);
                    TransformMountPointPosition(ref end, 0, Size, out e1);
                    TransformMountPointPosition(ref start, 3, Size, out s2);
                    TransformMountPointPosition(ref end, 3, Size, out e2);
                    mps.Add(new MountPoint() { Start = s1, End = e1, Normal = normalRight, Enabled = true });
                    mps.Add(new MountPoint() { Start = s2, End = e2, Normal = normalLeft, Enabled = true });
                }

                // Top and bottom walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.X - OFFSET_CONST, Size.Z - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 1, Size, out s1);
                    TransformMountPointPosition(ref end, 1, Size, out e1);
                    TransformMountPointPosition(ref start, 4, Size, out s2);
                    TransformMountPointPosition(ref end, 4, Size, out e2);
					mps.Add(new MountPoint() { Start = s1, End = e1, Normal = normalTop, Enabled = true });
					mps.Add(new MountPoint() { Start = s2, End = e2, Normal = normalBottom, Enabled = true });
                }

                // Front and back walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.X - OFFSET_CONST, Size.Y - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 2, Size, out s1);
                    TransformMountPointPosition(ref end, 2, Size, out e1);
                    TransformMountPointPosition(ref start, 5, Size, out s2);
                    TransformMountPointPosition(ref end, 5, Size, out e2);
					mps.Add(new MountPoint() { Start = s1, End = e1, Normal = normalFront, Enabled = true });
					mps.Add(new MountPoint() { Start = s2, End = e2, Normal = normalBack, Enabled = true });
                }

                MountPoints = mps.ToArray();
                return;
            }
            else
            {
				Debug.Assert(m_tmpMounts.Count == 0);
				SetMountPoints(ref MountPoints, def.MountPoints, m_tmpMounts);

				if (def.BuildProgressModels != null)
				{
					for (int index = 0; index < def.BuildProgressModels.Count; ++index)
					{
						var defBuildProgressModel = BuildProgressModels[index];
						if (defBuildProgressModel == null)
							continue;

						var obBuildProgressModel = def.BuildProgressModels[index];
						if (obBuildProgressModel.MountPoints == null)
							continue;

						foreach (var mountPoint in obBuildProgressModel.MountPoints)
						{
							int sideId = (int)mountPoint.Side;
							if(!m_tmpIndices.Contains(sideId))
							{
								m_tmpMounts.RemoveAll((mount) => { return (int)mount.Side == sideId; });
								m_tmpIndices.Add(sideId);
							}
							m_tmpMounts.Add(mountPoint);
						}
						m_tmpIndices.Clear();
						defBuildProgressModel.MountPoints = new MountPoint[m_tmpMounts.Count];
						SetMountPoints(ref defBuildProgressModel.MountPoints, m_tmpMounts.ToArray(), null);
					}
				}
				m_tmpMounts.Clear();
            }
        }
        private void InitEntityComponents(MyObjectBuilder_CubeBlockDefinition.EntityComponentDefinition[] entityComponentDefinitions)
        {
            if (entityComponentDefinitions == null) return;

            EntityComponents = new Dictionary<string, MyObjectBuilder_ComponentBase>(entityComponentDefinitions.Length);
            for (int i = 0; i < entityComponentDefinitions.Length; ++i)
            {
                var definition = entityComponentDefinitions[i];

                MyObjectBuilderType componentObType = MyObjectBuilderType.Parse(definition.BuilderType);
                Debug.Assert(!componentObType.IsNull, "Could not parse object builder type of component: " + definition.BuilderType);

                if (!componentObType.IsNull)
                {
                    var componentBuilder = MyObjectBuilderSerializer.CreateNewObject(componentObType) as MyObjectBuilder_ComponentBase;
                    Debug.Assert(componentBuilder != null, "Could not create object builder of type " + componentObType);
                    if (componentBuilder != null)
                    {
                        EntityComponents.Add(definition.ComponentType, componentBuilder);
                    }
                }
            }
        }
Exemple #16
0
        private void InitMountPoints(MyObjectBuilder_CubeBlockDefinition def)
        {
            if (MountPoints != null)
            {
                return;
            }

            var center = (Size - 1) / 2;

            // Order of block sides: right, top, front, left, bottom, back
            // Right = +X;    Top = +Y; Front = +Z
            //  Left = -X; Bottom = -Y;  Back = -Z
            // Side origins are always in lower left when looking at the side from outside.
            const float OFFSET_CONST   = 0.001f;
            const float THICKNESS_HALF = 0.0004f;

            if (!Context.IsBaseGame)
            {
                if (def.MountPoints != null && def.MountPoints.Length == 0)
                {
                    def.MountPoints = null;
                    string msg = "Obsolete default definition of mount points in " + def.Id;
                    MyDefinitionErrors.Add(Context, msg, ErrorSeverity.Warning);
                }
            }

            if (def.MountPoints == null)
            {
                // If there are no mount points defined, cover whole walls.
                List <MountPoint> mps = new List <MountPoint>(6);
                Vector3I          normalRight, normalLeft, normalTop, normalBottom, normalFront, normalBack;
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[0], out normalRight);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[1], out normalTop);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[2], out normalFront);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[3], out normalLeft);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[4], out normalBottom);
                Vector3I.TransformNormal(ref Vector3I.Forward, ref m_mountPointTransforms[5], out normalBack);

                // Right and left walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.Z - OFFSET_CONST, Size.Y - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 0, Size, out s1);
                    TransformMountPointPosition(ref end, 0, Size, out e1);
                    TransformMountPointPosition(ref start, 3, Size, out s2);
                    TransformMountPointPosition(ref end, 3, Size, out e2);
                    mps.Add(new MountPoint()
                    {
                        Start = s1, End = e1, Normal = normalRight
                    });
                    mps.Add(new MountPoint()
                    {
                        Start = s2, End = e2, Normal = normalLeft
                    });
                }

                // Top and bottom walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.X - OFFSET_CONST, Size.Z - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 1, Size, out s1);
                    TransformMountPointPosition(ref end, 1, Size, out e1);
                    TransformMountPointPosition(ref start, 4, Size, out s2);
                    TransformMountPointPosition(ref end, 4, Size, out e2);
                    mps.Add(new MountPoint()
                    {
                        Start = s1, End = e1, Normal = normalTop
                    });
                    mps.Add(new MountPoint()
                    {
                        Start = s2, End = e2, Normal = normalBottom
                    });
                }

                // Front and back walls
                {
                    Vector3 start = new Vector3(OFFSET_CONST, OFFSET_CONST, THICKNESS_HALF);
                    Vector3 end = new Vector3(Size.X - OFFSET_CONST, Size.Y - OFFSET_CONST, -THICKNESS_HALF);
                    Vector3 s1, s2, e1, e2;
                    TransformMountPointPosition(ref start, 2, Size, out s1);
                    TransformMountPointPosition(ref end, 2, Size, out e1);
                    TransformMountPointPosition(ref start, 5, Size, out s2);
                    TransformMountPointPosition(ref end, 5, Size, out e2);
                    mps.Add(new MountPoint()
                    {
                        Start = s1, End = e1, Normal = normalFront
                    });
                    mps.Add(new MountPoint()
                    {
                        Start = s2, End = e2, Normal = normalBack
                    });
                }

                MountPoints = mps.ToArray();
                return;
            }
            else
            {
                var mpBuilders = def.MountPoints;
                MountPoints = new MountPoint[mpBuilders.Length];
                for (int i = 0; i < MountPoints.Length; ++i)
                {
                    var mpBuilder = mpBuilders[i]; // 'mp' stands for mount point
                    // I shrink mounts points a little to avoid overlaps when they are very close.
                    var mpStart  = new Vector3((Vector2)mpBuilder.Start + OFFSET_CONST, THICKNESS_HALF);
                    var mpEnd    = new Vector3((Vector2)mpBuilder.End - OFFSET_CONST, -THICKNESS_HALF);
                    var sideIdx  = (int)mpBuilder.Side;
                    var mpNormal = Vector3I.Forward;
                    TransformMountPointPosition(ref mpStart, sideIdx, Size, out mpStart);
                    TransformMountPointPosition(ref mpEnd, sideIdx, Size, out mpEnd);
                    Vector3I.TransformNormal(ref mpNormal, ref m_mountPointTransforms[sideIdx], out mpNormal);
                    MountPoints[i].Start          = mpStart;
                    MountPoints[i].End            = mpEnd;
                    MountPoints[i].Normal         = mpNormal;
                    MountPoints[i].ExclusionMask  = mpBuilder.ExclusionMask;
                    MountPoints[i].PropertiesMask = mpBuilder.PropertiesMask;
                }
            }
        }
Exemple #17
0
 public CubeItemModel(MyObjectBuilder_CubeBlock cube, MyObjectBuilder_CubeBlockDefinition definition)
 {
     SetProperties(cube, definition);
 }
Exemple #18
0
 public AirVentDefinition(MyObjectBuilder_CubeBlockDefinition definition) : base(definition)
 {
 }
		protected BlockDefinition(MyObjectBuilder_CubeBlockDefinition definition): base(definition)
		{ }