예제 #1
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;
        }
        public static List <MyCubeBlockDefinition.MountPoint> AutogenerateMountpoints(HkShape[] shapes, float gridSize)
        {
            ProfilerShort.Begin("AutogenerateMountpoints");
            HkShapeCutterUtil cutter = new HkShapeCutterUtil();

            List <BoundingBox>[] aabbsPerDirection = new List <BoundingBox> [Base6Directions.EnumDirections.Length];

            var newMountPoints = new List <MyCubeBlockDefinition.MountPoint>();

            foreach (var directionEnum in Base6Directions.EnumDirections)
            {
                int dirEnum = (int)directionEnum;
                //int dirEnum = 2;
                Vector3 direction = Base6Directions.Directions[dirEnum];

                foreach (var shape in shapes)
                {
                    if (shape.ShapeType == HkShapeType.List)
                    {
                        var listShape = (HkListShape)shape;
                        var iterator  = listShape.GetIterator();
                        while (iterator.IsValid)
                        {
                            HkShape childShape = iterator.CurrentValue;

                            if (childShape.ShapeType == HkShapeType.ConvexTransform)
                            {
                                HkConvexTransformShape transformShape = (HkConvexTransformShape)childShape;

                                FindMountPoint(cutter, transformShape.Base, direction, gridSize, newMountPoints);
                            }
                            else
                            if (childShape.ShapeType == HkShapeType.ConvexTranslate)
                            {
                                HkConvexTranslateShape translateShape = (HkConvexTranslateShape)childShape;

                                FindMountPoint(cutter, translateShape.Base, direction, gridSize, newMountPoints);
                            }
                            else
                            {
                                FindMountPoint(cutter, childShape, direction, gridSize, newMountPoints);
                            }

                            iterator.Next();
                        }
                        break;
                    }
                    else
                    if (shape.ShapeType == HkShapeType.Mopp)
                    {
                        var compoundShape = (HkMoppBvTreeShape)shape;
                        for (int s = 0; s < compoundShape.ShapeCollection.ShapeCount; s++)
                        {
                            HkShape childShape = compoundShape.ShapeCollection.GetShape((uint)s, null);

                            if (childShape.ShapeType == HkShapeType.ConvexTranslate)
                            {
                                HkConvexTranslateShape translateShape = (HkConvexTranslateShape)childShape;

                                FindMountPoint(cutter, translateShape.Base, direction, gridSize, newMountPoints);
                            }
                        }
                        break;
                    }
                    else
                    {
                        FindMountPoint(cutter, shape, direction, gridSize, newMountPoints);
                    }
                }
            }
            ProfilerShort.End();
            return(newMountPoints);
        }
예제 #3
0
        private unsafe void DebugDrawShape(string blockName, HkShape shape, MatrixD worldMatrix)
        {
            float num  = 1.05f;
            float num2 = 0.02f;

            if (MyPerGameSettings.Game == GameEnum.SE_GAME)
            {
                num2 = 0.1f;
            }
            switch (shape.ShapeType)
            {
            case HkShapeType.Box:
                MyRenderProxy.DebugDrawOBB(MatrixD.CreateScale((((HkBoxShape)shape).HalfExtents * 2f) + new Vector3(num2)) * worldMatrix, Color.Red, 0f, true, false, true, false);
                return;

            case HkShapeType.Capsule:
            case HkShapeType.TriSampledHeightFieldCollection:
            case HkShapeType.TriSampledHeightFieldBvTree:
                break;

            case HkShapeType.ConvexVertices:
            {
                GeometryCenterPair    pair;
                HkConvexVerticesShape shape7 = (HkConvexVerticesShape)shape;
                if (!this.m_cachedGeometry.TryGetValue(blockName, out pair))
                {
                    Vector3    vector;
                    HkGeometry geometry = new HkGeometry();
                    shape7.GetGeometry(geometry, out vector);
                    GeometryCenterPair pair1 = new GeometryCenterPair();
                    pair1.Geometry = geometry;
                    pair1.Center   = vector;
                    pair           = pair1;
                    if (!string.IsNullOrEmpty(blockName))
                    {
                        this.m_cachedGeometry.Add(blockName, pair);
                    }
                }
                Vector3D vectord = Vector3D.Transform(pair.Center, worldMatrix.GetOrientation());
                MatrixD  xd      = worldMatrix;
                xd = MatrixD.CreateScale((double)num) * xd;
                MatrixD *xdPtr1 = (MatrixD *)ref xd;
                xdPtr1.Translation -= vectord * (num - 1f);
                this.DrawGeometry(pair.Geometry, xd, Color.Olive, false, false);
                break;
            }

            case HkShapeType.List:
            {
                HkShapeContainerIterator iterator = ((HkListShape)shape).GetIterator();
                int num3 = 0;
                while (iterator.IsValid)
                {
                    num3++;
                    this.DebugDrawShape(blockName + num3, iterator.CurrentValue, worldMatrix);
                    iterator.Next();
                }
                return;
            }

            case HkShapeType.Mopp:
            {
                HkMoppBvTreeShape shape4 = (HkMoppBvTreeShape)shape;
                this.DebugDrawShape(blockName, (HkShape)shape4.ShapeCollection, worldMatrix);
                return;
            }

            case HkShapeType.ConvexTranslate:
            {
                HkConvexTranslateShape shape6 = (HkConvexTranslateShape)shape;
                this.DebugDrawShape(blockName, (HkShape)shape6.ChildShape, Matrix.CreateTranslation(shape6.Translation) * worldMatrix);
                return;
            }

            case HkShapeType.ConvexTransform:
            {
                HkConvexTransformShape shape5 = (HkConvexTransformShape)shape;
                this.DebugDrawShape(blockName, (HkShape)shape5.ChildShape, shape5.Transform * worldMatrix);
                return;
            }

            default:
                return;
            }
        }
예제 #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);

            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();
            HkShape shape = GetPhysicsShape(physicalItem.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;
        }
예제 #5
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;
        }
        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;
        }
예제 #7
0
        private unsafe void AddPhysicalShape(HkShape shape, Matrix rdWorldMatrix)
        {
            switch (shape.ShapeType)
            {
            case HkShapeType.Sphere:
            {
                HkSphereShape shape7 = (HkSphereShape)shape;
                m_icosphereMesh.AddTrianglesToWorldVertices(rdWorldMatrix.Translation, shape7.Radius);
                return;
            }

            case HkShapeType.Cylinder:
            case HkShapeType.Triangle:
            case HkShapeType.TriSampledHeightFieldCollection:
            case HkShapeType.TriSampledHeightFieldBvTree:
                break;

            case HkShapeType.Box:
            {
                HkBoxShape   shape2 = (HkBoxShape)shape;
                Vector3D     min    = new Vector3D((double)-shape2.HalfExtents.X, (double)-shape2.HalfExtents.Y, (double)-shape2.HalfExtents.Z);
                Vector3D     max    = new Vector3D((double)shape2.HalfExtents.X, (double)shape2.HalfExtents.Y, (double)shape2.HalfExtents.Z);
                BoundingBoxD bbox   = new BoundingBoxD(min, max);
                this.BoundingBoxToTranslatedTriangles(bbox, rdWorldMatrix);
                return;
            }

            case HkShapeType.Capsule:
                return;

            case HkShapeType.ConvexVertices:
            {
                Vector3 vector;
                HkConvexVerticesShape shape9   = (HkConvexVerticesShape)shape;
                HkGeometry            geometry = new HkGeometry();
                shape9.GetGeometry(geometry, out vector);
                int triangleIndex = 0;
                while (true)
                {
                    int num2;
                    int num3;
                    int num4;
                    int num5;
                    if (triangleIndex >= geometry.TriangleCount)
                    {
                        int vertexIndex = 0;
                        while (true)
                        {
                            if (vertexIndex >= geometry.VertexCount)
                            {
                                WorldVerticesInfo worldVertices = m_worldVertices;
                                worldVertices.VerticesMaxValue += geometry.VertexCount;
                                break;
                            }
                            Vector3  vertex     = geometry.GetVertex(vertexIndex);
                            Vector3 *vectorPtr1 = (Vector3 *)ref vertex;
                            Vector3.Transform(ref (Vector3) ref vectorPtr1, ref rdWorldMatrix, out vertex);
                            m_worldVertices.Vertices.Add(vertex);
                            vertexIndex++;
                        }
                        break;
                    }
                    geometry.GetTriangle(triangleIndex, out num2, out num3, out num4, out num5);
                    m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + num2);
                    m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + num3);
                    m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + num4);
                    triangleIndex++;
                }
                break;
            }

            case HkShapeType.List:
            {
                HkShapeContainerIterator iterator = ((HkListShape)shape).GetIterator();
                while (iterator.IsValid)
                {
                    this.AddPhysicalShape(iterator.CurrentValue, rdWorldMatrix);
                    iterator.Next();
                }
                return;
            }

            case HkShapeType.Mopp:
            {
                HkMoppBvTreeShape shape4 = (HkMoppBvTreeShape)shape;
                this.AddPhysicalShape((HkShape)shape4.ShapeCollection, rdWorldMatrix);
                return;
            }

            case HkShapeType.ConvexTranslate:
            {
                HkConvexTranslateShape shape6 = (HkConvexTranslateShape)shape;
                Matrix matrix = Matrix.CreateTranslation(shape6.Translation);
                this.AddPhysicalShape((HkShape)shape6.ChildShape, matrix * rdWorldMatrix);
                return;
            }

            case HkShapeType.ConvexTransform:
            {
                HkConvexTransformShape shape5 = (HkConvexTransformShape)shape;
                this.AddPhysicalShape((HkShape)shape5.ChildShape, shape5.Transform * rdWorldMatrix);
                return;
            }

            default:
                return;
            }
        }
예제 #8
0
        public static unsafe void DrawCollisionShape(HkShape shape, MatrixD worldMatrix, float alpha, ref int shapeIndex, string customText = null, bool isPhantom = false)
        {
            Color color = GetShapeColor(shape.ShapeType, ref shapeIndex, isPhantom);

            if (isPhantom)
            {
                alpha *= alpha;
            }
            color.A = (byte)(alpha * 255f);
            bool        smooth    = true;
            float       num       = 0.02f;
            float       num2      = 1.035f;
            bool        flag2     = false;
            HkShapeType shapeType = shape.ShapeType;

            switch (shapeType)
            {
            case HkShapeType.Sphere:
            {
                float radius = ((HkSphereShape)shape).Radius;
                MyRenderProxy.DebugDrawSphere(worldMatrix.Translation, radius, color, alpha, true, smooth, true, false);
                if (isPhantom)
                {
                    MyRenderProxy.DebugDrawSphere(worldMatrix.Translation, radius, color, 1f, true, false, true, false);
                    MyRenderProxy.DebugDrawSphere(worldMatrix.Translation, radius, color, 1f, true, false, false, false);
                }
                flag2 = true;
                goto TR_0003;
            }

            case HkShapeType.Cylinder:
            {
                HkCylinderShape shape4 = (HkCylinderShape)shape;
                MyRenderProxy.DebugDrawCylinder(worldMatrix, shape4.VertexA, shape4.VertexB, shape4.Radius, color, alpha, true, smooth, false);
                flag2 = true;
                goto TR_0003;
            }

            case HkShapeType.Triangle:
            {
                HkTriangleShape shape12 = (HkTriangleShape)shape;
                MyRenderProxy.DebugDrawTriangle(shape12.Pt0, shape12.Pt1, shape12.Pt2, Color.Green, false, false, false);
                goto TR_0003;
            }

            case HkShapeType.Box:
            {
                HkBoxShape shape5 = (HkBoxShape)shape;
                MyRenderProxy.DebugDrawOBB(MatrixD.CreateScale((shape5.HalfExtents * 2f) + new Vector3(num)) * worldMatrix, color, alpha, true, smooth, true, false);
                if (isPhantom)
                {
                    MyRenderProxy.DebugDrawOBB(Matrix.CreateScale((shape5.HalfExtents * 2f) + new Vector3(num)) * worldMatrix, color, 1f, true, false, true, false);
                    MyRenderProxy.DebugDrawOBB(Matrix.CreateScale((shape5.HalfExtents * 2f) + new Vector3(num)) * worldMatrix, color, 1f, true, false, false, false);
                }
                flag2 = true;
                goto TR_0003;
            }

            case HkShapeType.Capsule:
            {
                HkCapsuleShape shape3 = (HkCapsuleShape)shape;
                MyRenderProxy.DebugDrawCapsule(Vector3.Transform(shape3.VertexA, worldMatrix), Vector3.Transform(shape3.VertexB, worldMatrix), shape3.Radius, color, true, smooth, false);
                flag2 = true;
                goto TR_0003;
            }

            case HkShapeType.ConvexVertices:
            {
                Vector3 vector;
                ((HkConvexVerticesShape)shape).GetGeometry(DebugGeometry, out vector);
                Vector3D vectord2 = Vector3D.Transform(vector, worldMatrix.GetOrientation());
                MatrixD  xd       = worldMatrix;
                xd = MatrixD.CreateScale((double)num2) * xd;
                MatrixD *xdPtr1 = (MatrixD *)ref xd;
                xdPtr1.Translation -= vectord2 * (num2 - 1f);
                DrawGeometry(DebugGeometry, xd, color, true, true);
                flag2 = true;
                goto TR_0003;
            }

            case HkShapeType.TriSampledHeightFieldCollection:
            case HkShapeType.TriSampledHeightFieldBvTree:
            case HkShapeType.SampledHeightField:
            case HkShapeType.ExtendedMesh:
            case HkShapeType.Transform:
            case HkShapeType.CompressedMesh:
            case HkShapeType.Collection:
            case HkShapeType.User0:
            case HkShapeType.User1:
            case HkShapeType.User2:
                goto TR_0003;

            case HkShapeType.List:
            {
                HkShapeContainerIterator iterator = ((HkListShape)shape).GetIterator();
                while (iterator.IsValid)
                {
                    DrawCollisionShape(iterator.CurrentValue, worldMatrix, alpha, ref shapeIndex, customText, false);
                    iterator.Next();
                }
                goto TR_0003;
            }

            case HkShapeType.Mopp:
                DrawCollisionShape((HkShape)((HkMoppBvTreeShape)shape).ShapeCollection, worldMatrix, alpha, ref shapeIndex, customText, false);
                goto TR_0003;

            case HkShapeType.ConvexTranslate:
            {
                HkConvexTranslateShape shape7 = (HkConvexTranslateShape)shape;
                DrawCollisionShape((HkShape)shape7.ChildShape, Matrix.CreateTranslation(shape7.Translation) * worldMatrix, alpha, ref shapeIndex, customText, false);
                goto TR_0003;
            }

            case HkShapeType.ConvexTransform:
            {
                HkConvexTransformShape shape8 = (HkConvexTransformShape)shape;
                DrawCollisionShape((HkShape)shape8.ChildShape, shape8.Transform * worldMatrix, alpha, ref shapeIndex, customText, false);
                goto TR_0003;
            }

            case HkShapeType.StaticCompound:
            {
                HkStaticCompoundShape shape11 = (HkStaticCompoundShape)shape;
                if (DebugDrawFlattenHierarchy)
                {
                    HkShapeContainerIterator iterator2 = shape11.GetIterator();
                    while (iterator2.IsValid)
                    {
                        if (shape11.IsShapeKeyEnabled(iterator2.CurrentShapeKey))
                        {
                            object[] objArray1 = new object[4];
                            object[] objArray2 = new object[4];
                            objArray2[0] = customText ?? string.Empty;
                            object[] local2 = objArray2;
                            local2[1] = "-";
                            local2[2] = iterator2.CurrentShapeKey;
                            local2[3] = "-";
                            string str = string.Concat(local2);
                            DrawCollisionShape(iterator2.CurrentValue, worldMatrix, alpha, ref shapeIndex, str, false);
                        }
                        iterator2.Next();
                    }
                }
                else
                {
                    for (int i = 0; i < shape11.InstanceCount; i++)
                    {
                        string str2;
                        bool   flag3 = shape11.IsInstanceEnabled(i);
                        if (flag3)
                        {
                            object[] objArray3 = new object[4];
                            object[] objArray4 = new object[4];
                            objArray4[0] = customText ?? string.Empty;
                            object[] local4 = objArray4;
                            local4[1] = "<";
                            local4[2] = i;
                            local4[3] = ">";
                            str2      = string.Concat(local4);
                        }
                        else
                        {
                            object[] objArray5 = new object[4];
                            object[] objArray6 = new object[4];
                            objArray6[0] = customText ?? string.Empty;
                            object[] local6 = objArray6;
                            local6[1] = "(";
                            local6[2] = i;
                            local6[3] = ")";
                            str2      = string.Concat(local6);
                        }
                        if (flag3)
                        {
                            DrawCollisionShape(shape11.GetInstance(i), shape11.GetInstanceTransform(i) * worldMatrix, alpha, ref shapeIndex, str2, false);
                        }
                    }
                }
                goto TR_0003;
            }

            case HkShapeType.BvCompressedMesh:
                break;

            case HkShapeType.BvTree:
            {
                HkGridShape shape13 = (HkGridShape)shape;
                if (HkGridShapeCellDebugDraw && !shape13.Base.IsZero)
                {
                    float cellSize       = shape13.CellSize;
                    int   shapeInfoCount = shape13.GetShapeInfoCount();
                    for (int i = 0; i < shapeInfoCount; i++)
                    {
                        try
                        {
                            Vector3S vectors;
                            Vector3S vectors2;
                            shape13.GetShapeInfo(i, out vectors, out vectors2, m_tmpShapeList);
                            Vector3 position = (Vector3)(((vectors2 * cellSize) + (vectors * cellSize)) / 2f);
                            Color   color2   = color;
                            if (vectors == vectors2)
                            {
                                color2 = new Color(1f, 0.2f, 0.1f);
                            }
                            MyRenderProxy.DebugDrawOBB((Matrix.CreateScale((((vectors2 * cellSize) - (vectors * cellSize)) + (Vector3.One * cellSize)) + new Vector3(num)) * Matrix.CreateTranslation(position)) * worldMatrix, color2, alpha, true, smooth, true, false);
                        }
                        finally
                        {
                            m_tmpShapeList.Clear();
                        }
                    }
                }
                else
                {
                    MyRenderMessageDebugDrawTriangles msgInterface = MyRenderProxy.PrepareDebugDrawTriangles();
                    try
                    {
                        using (HkShapeBuffer buffer = new HkShapeBuffer())
                        {
                            HkShapeContainerIterator iterator3 = ((HkBvTreeShape)shape).GetIterator(buffer);
                            while (iterator3.IsValid)
                            {
                                HkShape currentValue = iterator3.CurrentValue;
                                if (currentValue.ShapeType != HkShapeType.Triangle)
                                {
                                    DrawCollisionShape(currentValue, worldMatrix, alpha, ref shapeIndex, null, false);
                                }
                                else
                                {
                                    HkTriangleShape shape17 = (HkTriangleShape)currentValue;
                                    msgInterface.AddTriangle(shape17.Pt0, shape17.Pt1, shape17.Pt2);
                                }
                                iterator3.Next();
                            }
                            goto TR_0003;
                        }
                    }
                    finally
                    {
                        msgInterface.Color = color;
                        MyRenderProxy.DebugDrawTriangles(msgInterface, new MatrixD?(worldMatrix), false, false, false, false);
                    }
                    break;
                }
                goto TR_0003;
            }

            default:
                if (shapeType == HkShapeType.Bv)
                {
                    HkBvShape shape19 = (HkBvShape)shape;
                    DrawCollisionShape(shape19.BoundingVolumeShape, worldMatrix, alpha, ref shapeIndex, null, true);
                    DrawCollisionShape(shape19.ChildShape, worldMatrix, alpha, ref shapeIndex, null, false);
                }
                else if (shapeType == HkShapeType.PhantomCallback)
                {
                    MyRenderProxy.DebugDrawText3D(worldMatrix.Translation, "Phantom", Color.Green, 0.75f, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, -1, false);
                }
                goto TR_0003;
            }
            if (MyDebugDrawSettings.DEBUG_DRAW_TRIANGLE_PHYSICS)
            {
                ((HkBvCompressedMeshShape)shape).GetGeometry(DebugGeometry);
                DrawGeometry(DebugGeometry, worldMatrix, Color.Green, false, false);
                flag2 = true;
            }
TR_0003:
            if (flag2 && (customText != null))
            {
                color.A = 0xff;
                MyRenderProxy.DebugDrawText3D(worldMatrix.Translation, customText, color, 0.8f, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, -1, false);
            }
        }
예제 #9
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);
        }