示例#1
0
        // Don't call remove reference on this, this shape is pooled
        protected virtual HkShape GetPhysicsShape(float mass, float scale, out HkMassProperties massProperties)
        {
            const bool SimpleShape = false;

            Debug.Assert(Model != null, "Invalid floating object model: " + Item.GetDefinitionId());
            if (Model == null)
            {
                MyLog.Default.WriteLine("Invalid floating object model: " + Item.GetDefinitionId());
            }

            Vector3     halfExtents = (Model.BoundingBox.Max - Model.BoundingBox.Min) / 2;
            HkShapeType shapeType;

            if (VoxelMaterial != null)
            {
                shapeType      = HkShapeType.Sphere;
                massProperties = HkInertiaTensorComputer.ComputeSphereVolumeMassProperties(Model.BoundingSphere.Radius * scale, mass);
            }
            else
            {
                shapeType      = HkShapeType.Box;
                massProperties = HkInertiaTensorComputer.ComputeBoxVolumeMassProperties(halfExtents, mass);
                massProperties.CenterOfMass = Model.BoundingBox.Center;
            }

            return(MyDebris.Static.GetDebrisShape(Model, SimpleShape ? shapeType : HkShapeType.ConvexVertices));
        }
示例#2
0
        public override void Init(MyObjectBuilder_EntityBase objectBuilder)
        {
            var builder = objectBuilder as MyObjectBuilder_FloatingObject;

            if (builder.Item.Amount <= 0)
            {
                // I can only prevent creation of entity by throwing exception. This might cause crashes when thrown outside of MyEntities.CreateFromObjectBuilder().
                throw new ArgumentOutOfRangeException("MyPhysicalInventoryItem.Amount", string.Format("Creating floating object with invalid amount: {0}x '{1}'", builder.Item.Amount, builder.Item.PhysicalContent.GetId()));
            }
            base.Init(objectBuilder);

            this.Item           = new MyPhysicalInventoryItem(builder.Item);
            this.m_modelVariant = builder.ModelVariant;

            InitInternal();

            NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;

            UseDamageSystem = true;

            MyPhysicalItemDefinition itemDefinition = null;

            if (!MyDefinitionManager.Static.TryGetPhysicalItemDefinition(Item.GetDefinitionId(), out itemDefinition))
            {
                System.Diagnostics.Debug.Fail("Creating floating object, but it's physical item definition wasn't found! - " + Item.ItemId);
                ItemDefinition = null;
            }
            else
            {
                ItemDefinition = itemDefinition;
            }
            m_timeFromSpawn = MySession.Static.ElapsedPlayTime;
        }
 public static AmountedDefinitionId ToAmountedDefinition(this MyPhysicalInventoryItem i)
 {
     return(new AmountedDefinitionId()
     {
         Amount = i.Amount.ToIntSafe(),
         Id = i.GetDefinitionId().ToDefinitionId(),
     });
 }