private void PreparePhysicsBody() { m_activeShape = m_newShape; m_newShape = null; Debug.Assert(m_activeShape != null); if (Physics != null) { Physics.Close(); } Physics = new MyPhysicsBody(this, RigidBodyFlag.RBF_STATIC); var physics = (MyPhysicsBody)Physics; HkMassProperties massProperties = new HkMassProperties(); //MatrixD matrix = MatrixD.CreateTranslation(); physics.CreateFromCollisionObject(m_activeShape.Shape, Vector3.Zero, PositionComp.WorldMatrix, massProperties); physics.ContactPointCallback += Physics_onContactPoint; physics.IsStaticForCluster = true; if (m_contactListeners != null && m_contactListeners.Count != 0) { Physics.RigidBody.ContactPointCallbackEnabled = true; } //shape.RemoveReference(); Physics.Enabled = true; }
private unsafe void BuildShape() { ProfilerShort.Begin("BuildPhysicsShape()"); FetchData(0); ProfilerShort.Begin("CollectInstances"); var shape = new CompoundInstancedShape(); if (m_modelsToShapes == null) { m_modelsToShapes = new Dictionary <int, HkShape>(); } int totalItems = DataView.Items.Count; fixed(ItemInfo *items = DataView.Items.GetInternalArray()) { for (int i = 0; i < totalItems; ++i) { var modelId = items[i].ModelIndex; if (modelId < 0) { continue; } if (Owner.GetModelForId(modelId) == null) { continue; } HkShape modelShape; if (!m_modelsToShapes.TryGetValue(modelId, out modelShape)) { var modelData = MyModels.GetModelOnlyData(Owner.GetModelForId(modelId).Model); var shapes = modelData.HavokCollisionShapes; if (shapes != null) { if (shapes.Length == 0) { MyLog.Default.Warning("Model {0} has an empty list of shapes, something wrong with export?", modelData.AssetName); } else { if (shapes.Length > 1) { MyLog.Default.Warning("Model {0} has multiple shapes, only the first will be used.", modelData.AssetName); } modelShape = shapes[0]; } } m_modelsToShapes[modelId] = modelShape; } shape.AddInstance(i, ref items[i], modelShape); } } ProfilerShort.BeginNextBlock("Bake()"); shape.Bake(); ProfilerShort.End(); m_newShape = shape; ProfilerShort.End(); }