Пример #1
0
        private static Color GetShapeColor(HkShapeType shapeType, ref int shapeIndex, bool isPhantom)
        {
            if (isPhantom)
            {
                return(Color.LightGreen);
            }
            switch (shapeType)
            {
            case HkShapeType.Sphere:
                return(Color.White);

            case HkShapeType.Cylinder:
                return(Color.Orange);

            case HkShapeType.Capsule:
                return(Color.Yellow);

            case HkShapeType.ConvexVertices:
                return(Color.Red);
            }
            int num = shapeIndex + 1;

            shapeIndex = num;
            return(boxColors[num % (boxColors.Length - 1)]);
        }
Пример #2
0
        static Color GetShapeColor(HkShapeType shapeType, ref int shapeIndex, bool isPhantom)
        {
            if (isPhantom)
            {
                return(Color.LightGreen);
            }

            switch (shapeType)
            {
            case HkShapeType.Sphere:
                return(Color.White);

            case HkShapeType.Capsule:
                return(Color.Yellow);

            case HkShapeType.Cylinder:
                return(Color.Orange);

            case HkShapeType.ConvexVertices:
                return(Color.Red);

            default:
            case HkShapeType.Box:
                return(boxColors[(++shapeIndex) % (boxColors.Length - 1)]);
            }
        }
Пример #3
0
        HkShape CreateShape(MyModel model, HkShapeType shapeType)
        {
            if (model.HavokCollisionShapes != null && model.HavokCollisionShapes.Length > 0)
            {
                HkShape sh = model.HavokCollisionShapes[0];
                sh.AddReference();
                return(sh);
            }

            switch (shapeType)
            {
            case HkShapeType.Box:
                Vector3 halfExtents = (model.BoundingBox.Max - model.BoundingBox.Min) / 2;
                return(new HkBoxShape(Vector3.Max(halfExtents - 0.1f, new Vector3(0.05f)), 0.02f));

                break;

            case HkShapeType.Sphere:
                return(new HkSphereShape(model.BoundingSphere.Radius));

                break;

            case HkShapeType.ConvexVertices:
                m_tmpVerts.Clear();
                for (int i = 0; i < model.GetVerticesCount(); i++)
                {
                    m_tmpVerts.Add(model.GetVertex(i));
                }

                return(new HkConvexVerticesShape(m_tmpVerts.GetInternalArray(), m_tmpVerts.Count, true, 0.1f));

                break;
            }
            throw new InvalidOperationException("This shape is not supported");
        }
Пример #4
0
        // Don't call remove reference on this, this shape is pooled
        public HkShape GetDebrisShape(MyModel model, HkShapeType shapeType)
        {
            MyModelShapeInfo info = new MyModelShapeInfo();

            info.Model     = model;
            info.ShapeType = shapeType;

            HkShape shape;

            if (!m_shapes.TryGetValue(info, out shape))
            {
                shape = CreateShape(model, shapeType);
                m_shapes.Add(info, shape);
            }
            return(shape);
        }
Пример #5
0
        public HkShape GetDebrisShape(MyModel model, HkShapeType shapeType, float scale)
        {
            HkShape          shape;
            MyModelShapeInfo key = new MyModelShapeInfo {
                Model     = model,
                ShapeType = shapeType,
                Scale     = scale
            };

            if (!this.m_shapes.TryGetValue(key, out shape))
            {
                shape = this.CreateShape(model, shapeType, scale);
                this.m_shapes.TryAdd(key, shape);
            }
            return(shape);
        }
Пример #6
0
        static Color GetShapeColor(HkShapeType shapeType, ref int shapeIndex, bool isPhantom)
        {
            if (isPhantom)
                return Color.LightGreen;

            switch (shapeType)
            {
                case HkShapeType.Sphere:
                    return Color.White;
                case HkShapeType.Capsule:
                    return Color.Yellow;
                case HkShapeType.Cylinder:
                    return Color.Orange;
                case HkShapeType.ConvexVertices:
                    return Color.Red;

                default:
                case HkShapeType.Box:
                    return boxColors[(++shapeIndex) % (boxColors.Length - 1)];
            }
        }
Пример #7
0
        private HkShape CreateShape(MyModel model, HkShapeType shapeType, float scale)
        {
            if ((model.HavokCollisionShapes != null) && (model.HavokCollisionShapes.Length != 0))
            {
                HkShape shape;
                if (model.HavokCollisionShapes.Length != 1)
                {
                    shape = (HkShape) new HkListShape(model.HavokCollisionShapes, HkReferencePolicy.None);
                }
                else
                {
                    shape = model.HavokCollisionShapes[0];
                    shape.AddReference();
                }
                return(shape);
            }
            if (shapeType == HkShapeType.Sphere)
            {
                return((HkShape) new HkSphereShape(scale * model.BoundingSphere.Radius));
            }
            if (shapeType == HkShapeType.Box)
            {
                return((HkShape) new HkBoxShape(Vector3.Max((Vector3)(((scale * (model.BoundingBox.Max - model.BoundingBox.Min)) / 2f) - 0.05f), new Vector3(0.025f)), 0.02f));
            }
            if (shapeType != HkShapeType.ConvexVertices)
            {
                throw new InvalidOperationException("This shape is not supported");
            }
            List <Vector3> list = new List <Vector3>();

            for (int i = 0; i < model.GetVerticesCount(); i++)
            {
                list.Add((Vector3)(scale * model.GetVertex(i)));
            }
            return((HkShape) new HkConvexVerticesShape(list.GetInternalArray <Vector3>(), list.Count, true, 0.1f));
        }
Пример #8
0
        // Don't call remove reference on this, this shape is pooled
        public HkShape GetDebrisShape(MyModel model, HkShapeType shapeType)
        {
            MyModelShapeInfo info = new MyModelShapeInfo();
            info.Model = model;
            info.ShapeType = shapeType;

            HkShape shape;
            if (!m_shapes.TryGetValue(info, out shape))
            {
                shape = CreateShape(model, shapeType);
                m_shapes.Add(info, shape);
            }
            return shape;
        }
Пример #9
0
        HkShape CreateShape(MyModel model, HkShapeType shapeType)
        {
            switch(shapeType)
            {
                case HkShapeType.Box:
                    Vector3 halfExtents = (model.BoundingBox.Max - model.BoundingBox.Min) / 2;
                    return new HkBoxShape(Vector3.Max(halfExtents - 0.1f, new Vector3(0.05f)), 0.02f);
                    break;

                case HkShapeType.Sphere:
                    return new HkSphereShape(model.BoundingSphere.Radius);
                    break;

                case HkShapeType.ConvexVertices:
                    m_tmpVerts.Clear();
                    for (int i = 0; i < model.GetVerticesCount(); i++)
                    {
                        m_tmpVerts.Add(model.GetVertex(i));
                    }

                    return new HkConvexVerticesShape(m_tmpVerts.GetInternalArray(), m_tmpVerts.Count, true, 0.1f);
                    break;
            }
            throw new InvalidOperationException("This shape is not supported");
        }
Пример #10
0
        HkShape CreateShape(MyModel model, HkShapeType shapeType)
        {
            if (model.HavokCollisionShapes != null && model.HavokCollisionShapes.Length > 0)
            {
                HkShape sh;
                if (model.HavokCollisionShapes.Length == 1)
                {
                    sh = model.HavokCollisionShapes[0];
                    sh.AddReference();
                }
                else
                {
                    sh = new HkListShape(model.HavokCollisionShapes,HkReferencePolicy.None);
                }
                return sh;          
            }

            switch(shapeType)
            {
                case HkShapeType.Box:
                    Vector3 halfExtents = (model.BoundingBox.Max - model.BoundingBox.Min) / 2;
                    return new HkBoxShape(Vector3.Max(halfExtents - 0.1f, new Vector3(0.05f)), 0.02f);
                    break;

                case HkShapeType.Sphere:
                    return new HkSphereShape(model.BoundingSphere.Radius);
                    break;

                case HkShapeType.ConvexVertices:
                    m_tmpVerts.Clear();
                    for (int i = 0; i < model.GetVerticesCount(); i++)
                    {
                        m_tmpVerts.Add(model.GetVertex(i));
                    }

                    return new HkConvexVerticesShape(m_tmpVerts.GetInternalArray(), m_tmpVerts.Count, true, 0.1f);
                    break;
            }
            throw new InvalidOperationException("This shape is not supported");
        }
Пример #11
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);
            }
        }