public void Init(MyObjectBuilder_ConveyorPacket builder, MyEntity parent)
        {
            Item         = new MyPhysicalInventoryItem(builder.Item);
            LinePosition = builder.LinePosition;

            var physicalItem = MyDefinitionManager.Static.GetPhysicalItemDefinition(Item.Content);

            var ore = Item.Content as MyObjectBuilder_Ore;

            string model = physicalItem.Model;
            float  scale = 1.0f;

            if (ore != null)
            {
                foreach (var mat in MyDefinitionManager.Static.GetVoxelMaterialDefinitions())
                {
                    if (mat.MinedOre == ore.SubtypeName)
                    {
                        model = MyDebris.GetRandomDebrisVoxel();
                        scale = (float)Math.Pow((float)Item.Amount * physicalItem.Volume / MyDebris.VoxelDebrisModelVolume, 0.333f);
                        break;
                    }
                }
            }

            if (scale < 0.05f)
            {
                scale = 0.05f;
            }
            else if (scale > 1.0f)
            {
                scale = 1.0f;
            }

            bool entityIdAllocationSuspended = MyEntityIdentifier.AllocationSuspended;

            MyEntityIdentifier.AllocationSuspended = false;
            Init(null, model, parent, null, null);
            MyEntityIdentifier.AllocationSuspended = entityIdAllocationSuspended;
            PositionComp.Scale = scale;

            // Packets are serialized by conveyor lines
            Save = false;
        }
Exemplo n.º 2
0
            private void InitInternal()
            {
                // TODO: This will be fixed and made much more simple once ore models are done
                // https://app.asana.com/0/6594565324126/10473934569658
                var physicalItem = MyDefinitionManager.Static.GetPhysicalItemDefinition(Item.Content);

                var ore = Item.Content as MyObjectBuilder_Ore;

                string model = physicalItem.Model;
                float  scale = 1.0f;

                VoxelMaterial = null;
                if (ore != null)
                {
                    foreach (var mat in MyDefinitionManager.Static.GetVoxelMaterialDefinitions())
                    {
                        if (mat.MinedOre == ore.SubtypeName)
                        {
                            VoxelMaterial = mat;
                            model         = MyDebris.GetRandomDebrisVoxel();
                            scale         = (float)Math.Pow((float)Item.Amount * physicalItem.Volume / MyDebris.VoxelDebrisModelVolume, 0.333f);
                            break;
                        }
                    }
                }

                if (scale < 0.15f)
                {
                    scale = 0.15f;
                }

                var voxelRender = (Entity.Render as MyRenderComponentDebrisVoxel);

                voxelRender.VoxelMaterialIndex = VoxelMaterial.Index;
                voxelRender.TexCoordOffset     = 5;
                voxelRender.TexCoordScale      = 8;
                Entity.Init(new StringBuilder("Meteor"), model, null, null, null);

                Entity.PositionComp.Scale = scale; // Must be set after init

                var           massProperties = HkInertiaTensorComputer.ComputeSphereVolumeMassProperties(Entity.PositionComp.LocalVolume.Radius, (float)(4 / 3f * Math.PI * Math.Pow(Entity.PositionComp.LocalVolume.Radius, 3)) * 3.7f);
                HkSphereShape transform      = new HkSphereShape(Entity.PositionComp.LocalVolume.Radius);

                if (Entity.Physics != null)
                {
                    Entity.Physics.Close();
                }

                Entity.Physics = new MyPhysicsBody(Entity, RigidBodyFlag.RBF_BULLET);
                Entity.Physics.ReportAllContacts = true;
                Entity.GetPhysicsBody().CreateFromCollisionObject(transform, Vector3.Zero, MatrixD.Identity, massProperties, MyPhysics.CollisionLayers.DefaultCollisionLayer);
                Entity.Physics.Enabled = true;
                Entity.Physics.RigidBody.ContactPointCallbackEnabled = true;
                Entity.GetPhysicsBody().ContactPointCallback += RigidBody_ContactPointCallback;
                transform.Base.RemoveReference();
                Entity.Physics.PlayCollisionCueEnabled = true;

                m_timeCreated = MySandboxGame.TotalGamePlayTimeInMilliseconds;

                NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;

                StartLoopSound();
            }
Exemplo n.º 3
0
        private void InitInternal()
        {
            // TODO: This will be fixed and made much more simple once ore models are done
            // https://app.asana.com/0/6594565324126/10473934569658

            var itemDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(Item.Content);

            m_health = itemDefinition.Health;

            // Setting voxel material (if applicable)
            VoxelMaterial = null;
            if (itemDefinition.VoxelMaterial != MyStringHash.NullOrEmpty)
            {
                VoxelMaterial = MyDefinitionManager.Static.GetVoxelMaterialDefinition(itemDefinition.VoxelMaterial.String);
            }
            else if (Item.Content is MyObjectBuilder_Ore)
            {
                string oreSubTypeId    = itemDefinition.Id.SubtypeName;
                string materialName    = (Item.Content as MyObjectBuilder_Ore).GetMaterialName();
                bool   hasMaterialName = (Item.Content as MyObjectBuilder_Ore).HasMaterialName();

                foreach (var mat in MyDefinitionManager.Static.GetVoxelMaterialDefinitions())
                {
                    if ((hasMaterialName && materialName == mat.Id.SubtypeName) || (hasMaterialName == false && oreSubTypeId == mat.MinedOre))
                    {
                        VoxelMaterial = mat;
                        break;
                    }
                }
            }

            // Setting the item's model
            string model = itemDefinition.Model;

            if (itemDefinition.HasModelVariants)
            {
                int modelNum = itemDefinition.Models.Length;
                Debug.Assert(m_modelVariant >= 0 && m_modelVariant < modelNum, "Model variant overflow. This can happen if model variants changed");
                m_modelVariant = m_modelVariant % modelNum;

                model = itemDefinition.Models[m_modelVariant];
            }
            else if (Item.Content is MyObjectBuilder_Ore && VoxelMaterial != null)
            {
                // Only ores without found voxel material use the defined model (otherwise, the scrap metal does not work)
                model = MyDebris.GetRandomDebrisVoxel();
            }

            // Setting the scale
            float scale = this.Item.Scale;

            if (Item.Content is MyObjectBuilder_Ore)
            {
                scale *= (float)Math.Pow((float)Item.Amount * itemDefinition.Volume / MyDebris.VoxelDebrisModelVolume, 0.333f);
            }
            else
            {
                scale *= (float)Math.Pow(itemDefinition.Volume / itemDefinition.ModelVolume, 0.333f);
            }
            if (scale < 0.05f)
            {
                Close();
            }
            else if (scale < 0.15f)
            {
                scale = 0.15f;
            }

            FormatDisplayName(m_displayedText, Item);
            Debug.Assert(model != null, "Floating object model is null");
            Init(m_displayedText, model, null, null, null);

            PositionComp.Scale = scale; // Must be set after init

            var massProperties = new HkMassProperties();
            var mass           = MyPerGameSettings.Destruction ? MyDestructionHelper.MassToHavok(itemDefinition.Mass) : itemDefinition.Mass;

            mass = mass * (float)Item.Amount;

            HkShape shape       = GetPhysicsShape(mass, scale, out massProperties);
            var     scaleMatrix = Matrix.CreateScale(scale);

            if (Physics != null)
            {
                Physics.Close();
            }
            Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DEBRIS);

            int layer = mass > MyPerGameSettings.MinimumLargeShipCollidableMass ? MyPhysics.CollisionLayers.FloatingObjectCollisionLayer : MyPhysics.CollisionLayers.LightFloatingObjectCollisionLayer;

            if (VoxelMaterial != null || (shape.IsConvex && scale != 1f))
            {
                HkConvexTransformShape transform = new HkConvexTransformShape((HkConvexShape)shape, ref scaleMatrix, HkReferencePolicy.None);

                Physics.CreateFromCollisionObject(transform, Vector3.Zero, MatrixD.Identity, massProperties, layer);

                Physics.Enabled = true;
                transform.Base.RemoveReference();
            }
            else
            {
                Physics.CreateFromCollisionObject(shape, Vector3.Zero, MatrixD.Identity, massProperties, layer);
                Physics.Enabled = true;
            }

            Physics.MaterialType            = this.EvaluatePhysicsMaterial(itemDefinition.PhysicalMaterial);
            Physics.PlayCollisionCueEnabled = true;
            Physics.RigidBody.ContactSoundCallbackEnabled = true;
            m_easeCollisionForce      = new HkEasePenetrationAction(Physics.RigidBody, 2f);
            m_massChangeForCollisions = 0.010f;

            NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;
        }
Exemplo n.º 4
0
        private void InitInternal()
        {
            // TODO: This will be fixed and made much more simple once ore models are done
            // https://app.asana.com/0/6594565324126/10473934569658

            var physicalItem = MyDefinitionManager.Static.GetPhysicalItemDefinition(Item.Content);

            m_health = physicalItem.Health;

            string model = physicalItem.Model;

            VoxelMaterial = null;
            float scale = 1.0f;

            if (Item.Content is MyObjectBuilder_Ore)
            {
                string oreSubTypeId = physicalItem.Id.SubtypeId.ToString();
                foreach (var mat in MyDefinitionManager.Static.GetVoxelMaterialDefinitions())
                {
                    if (oreSubTypeId == mat.MinedOre)
                    {
                        VoxelMaterial = mat;
                        model         = MyDebris.GetRandomDebrisVoxel();
                        scale         = (float)Math.Pow((float)Item.Amount * physicalItem.Volume / MyDebris.VoxelDebrisModelVolume, 0.333f);
                        break;
                    }
                }

                scale = (float)Math.Pow((float)Item.Amount * physicalItem.Volume / MyDebris.VoxelDebrisModelVolume, 0.333f);
            }

            if (scale < 0.05f)
            {
                Close();
            }
            else if (scale < 0.15f)
            {
                scale = 0.15f;
            }

            FormatDisplayName(m_displayedText, Item);
            Init(m_displayedText, model, null, null, null);

            PositionComp.Scale = scale; // Must be set after init


            var massProperties = new HkMassProperties();
            var mass           = MyPerGameSettings.Destruction ? MyDestructionHelper.MassToHavok(physicalItem.Mass) : physicalItem.Mass;

            HkShape shape       = GetPhysicsShape(mass * (float)Item.Amount, scale, out massProperties);
            var     scaleMatrix = Matrix.CreateScale(scale);

            if (Physics != null)
            {
                Physics.Close();
            }
            Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DEBRIS);

            if (VoxelMaterial != null)
            {
                HkConvexTransformShape transform = new HkConvexTransformShape((HkConvexShape)shape, ref scaleMatrix, HkReferencePolicy.None);

                Physics.CreateFromCollisionObject(transform, Vector3.Zero, MatrixD.Identity, massProperties, MyPhysics.FloatingObjectCollisionLayer);

                Physics.Enabled = true;
                transform.Base.RemoveReference();
            }
            else
            {
                Physics.CreateFromCollisionObject(shape, Vector3.Zero, MatrixD.Identity, massProperties, MyPhysics.FloatingObjectCollisionLayer);
                Physics.Enabled = true;
            }

            Physics.MaterialType            = VoxelMaterial != null ? MyMaterialType.ROCK : MyMaterialType.METAL;
            Physics.PlayCollisionCueEnabled = true;

            NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;
        }
Exemplo n.º 5
0
        private void InitInternal()
        {
            MyPhysicalItemDefinition physicalItemDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(this.Item.Content);

            this.m_health      = physicalItemDefinition.Health;
            this.VoxelMaterial = null;
            if (physicalItemDefinition.VoxelMaterial != MyStringHash.NullOrEmpty)
            {
                this.VoxelMaterial = MyDefinitionManager.Static.GetVoxelMaterialDefinition(physicalItemDefinition.VoxelMaterial.String);
            }
            else if (this.Item.Content is MyObjectBuilder_Ore)
            {
                string subtypeName  = physicalItemDefinition.Id.SubtypeName;
                string materialName = (this.Item.Content as MyObjectBuilder_Ore).GetMaterialName();
                bool   flag         = (this.Item.Content as MyObjectBuilder_Ore).HasMaterialName();
                foreach (MyVoxelMaterialDefinition definition2 in MyDefinitionManager.Static.GetVoxelMaterialDefinitions())
                {
                    if ((flag && (materialName == definition2.Id.SubtypeName)) || (!flag && (subtypeName == definition2.MinedOre)))
                    {
                        this.VoxelMaterial = definition2;
                        break;
                    }
                }
            }
            if ((this.VoxelMaterial != null) && (this.VoxelMaterial.DamagedMaterial != MyStringHash.NullOrEmpty))
            {
                this.VoxelMaterial = MyDefinitionManager.Static.GetVoxelMaterialDefinition(this.VoxelMaterial.DamagedMaterial.ToString());
            }
            string model = physicalItemDefinition.Model;

            if (physicalItemDefinition.HasModelVariants)
            {
                int length = physicalItemDefinition.Models.Length;
                this.m_modelVariant = this.m_modelVariant % length;
                model = physicalItemDefinition.Models[this.m_modelVariant];
            }
            else if ((this.Item.Content is MyObjectBuilder_Ore) && (this.VoxelMaterial != null))
            {
                float num5 = 50f;
                model = MyDebris.GetAmountBasedDebrisVoxel(Math.Max((float)this.Item.Amount, num5));
            }
            float scale = 0.7f;

            this.FormatDisplayName(this.m_displayedText, this.Item);
            float?nullable = null;

            this.Init(this.m_displayedText, model, null, nullable, null);
            HkMassProperties massProperties = new HkMassProperties();
            float            mass           = MathHelper.Clamp((float)((MyPerGameSettings.Destruction ? MyDestructionHelper.MassToHavok(physicalItemDefinition.Mass) : physicalItemDefinition.Mass) * ((float)this.Item.Amount)), (float)3f, (float)100000f);
            HkShape          shape          = this.GetPhysicsShape(mass, scale, out massProperties);

            massProperties.Mass = mass;
            Matrix identity = Matrix.Identity;

            if (this.Physics != null)
            {
                this.Physics.Close();
            }
            this.Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_DEBRIS);
            int collisionFilter = (mass > MyPerGameSettings.MinimumLargeShipCollidableMass) ? 0x17 : 10;

            this.Physics.LinearDamping  = 0.1f;
            this.Physics.AngularDamping = 2f;
            if (!shape.IsConvex || (shape.ShapeType == HkShapeType.Sphere))
            {
                this.Physics.CreateFromCollisionObject(shape, Vector3.Zero, MatrixD.Identity, new HkMassProperties?(massProperties), collisionFilter);
                this.Physics.Enabled = true;
            }
            else
            {
                HkConvexTransformShape shape2 = new HkConvexTransformShape((HkConvexShape)shape, ref identity, HkReferencePolicy.None);
                this.Physics.CreateFromCollisionObject((HkShape)shape2, Vector3.Zero, MatrixD.Identity, new HkMassProperties?(massProperties), collisionFilter);
                this.Physics.Enabled = true;
                shape2.Base.RemoveReference();
            }
            this.Physics.Friction                = 2f;
            this.Physics.MaterialType            = this.EvaluatePhysicsMaterial(physicalItemDefinition.PhysicalMaterial);
            this.Physics.PlayCollisionCueEnabled = true;
            this.Physics.RigidBody.ContactSoundCallbackEnabled = true;
            base.NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;
            this.Physics.RigidBody.SetProperty(HkCharacterRigidBody.FLOATING_OBJECT, 0f);
            this.Physics.RigidBody.CenterOfMassLocal = Vector3.Zero;
            HkMassChangerUtil.Create(this.Physics.RigidBody, 0x10200, 1f, 0f);
        }
Exemplo n.º 6
0
 private void Release()
 {
     this.Context = null;
     this.m_pieces.Clear();
     m_pool.Push(this);
 }