public override void LoadData()
        {
            if (!HkBaseSystem.DestructionEnabled)
            {
                MyLog.Default.WriteLine("Havok Destruction is not availiable in this build.");
                throw new System.InvalidOperationException("Havok Destruction is not availiable in this build.");
            }

            if (Static != null)
            {
                MyLog.Default.WriteLine("Destruction data was not freed. Unloading now...");
                //throw new System.InvalidOperationException("Destruction data was not freed");
                UnloadData();
            }
            Static         = this;
            BlockShapePool = new MyBlockShapePool();

            TemporaryWorld = new HkWorld(true, 50000, MyPhysics.RestingVelocity, MyFakes.ENABLE_HAVOK_MULTITHREADING);
            TemporaryWorld.MarkForWrite();
            TemporaryWorld.DestructionWorld = new HkdWorld(TemporaryWorld);
            TemporaryWorld.UnmarkForWrite();
            Storage = new HkDestructionStorage(TemporaryWorld.DestructionWorld);

            // pre-fracture cube blocks
            if (!MyFakes.LAZY_LOAD_DESTRUCTION)
            {
                foreach (var groupName in MyDefinitionManager.Static.GetDefinitionPairNames())
                {
                    var group = MyDefinitionManager.Static.GetDefinitionGroup(groupName);

                    if (group.Large != null)
                    {
                        bool isGenerated = group.Large.IsGeneratedBlock && (group.Large.GeneratedBlockType == GENERATED_BLOCK_TYPE_PILLAR);
                        LoadModelDestruction(group.Large, isGenerated, group.Large.Size * (MyDefinitionManager.Static.GetCubeSize(group.Large.CubeSize)));
                        if (MyFakes.CHANGE_BLOCK_CONVEX_RADIUS)
                        {
                            var model = MyModels.GetModelOnlyData(group.Large.Model);
                            if (model != null && model.HavokBreakableShapes != null)
                            {
                                var shape = model.HavokBreakableShapes[0].GetShape();
                                if (shape.ShapeType != HkShapeType.Sphere && shape.ShapeType != HkShapeType.Capsule)
                                {
                                    SetConvexRadius(model.HavokBreakableShapes[0], MyDestructionConstants.LARGE_GRID_CONVEX_RADIUS);
                                }
                            }
                        }
                    }

                    if (group.Small != null)
                    {
                        bool isGenerated = group.Small.IsGeneratedBlock && (group.Small.GeneratedBlockType == GENERATED_BLOCK_TYPE_PILLAR);
                        LoadModelDestruction(group.Small, isGenerated, group.Small.Size * (MyDefinitionManager.Static.GetCubeSize(group.Small.CubeSize)));
                        if (MyFakes.CHANGE_BLOCK_CONVEX_RADIUS)
                        {
                            var model = MyModels.GetModelOnlyData(group.Small.Model);
                            if (model != null && model.HavokBreakableShapes != null)
                            {
                                var shape = model.HavokBreakableShapes[0].GetShape();
                                if (shape.ShapeType != HkShapeType.Sphere && shape.ShapeType != HkShapeType.Capsule)
                                {
                                    SetConvexRadius(model.HavokBreakableShapes[0], MyDestructionConstants.LARGE_GRID_CONVEX_RADIUS);
                                }
                            }
                        }
                    }
                }
                BlockShapePool.Preallocate();
            }

            foreach (var enviroment in MyDefinitionManager.Static.GetEnvironmentItemDefinitions())
            {
                LoadModelDestruction(enviroment, false, Vector3.One, false, true);
            }
        }
Beispiel #2
0
        public override void LoadData()
        {
            if (!HkBaseSystem.DestructionEnabled)
            {
                MyLog.Default.WriteLine("Havok Destruction is not availiable in this build.");
                throw new System.InvalidOperationException("Havok Destruction is not availiable in this build.");
            }

            if (Static != null)
            {
                MyLog.Default.WriteLine("Destruction data was not freed. Unloading now...");
                //throw new System.InvalidOperationException("Destruction data was not freed");
                UnloadData();
            }
            Static         = this;
            BlockShapePool = new MyBlockShapePool();

            TemporaryWorld = new HkWorld(true, 50000, MyPhysics.RestingVelocity, MyFakes.ENABLE_HAVOK_MULTITHREADING, 4);
            TemporaryWorld.MarkForWrite();
            TemporaryWorld.DestructionWorld = new HkdWorld(TemporaryWorld);
            TemporaryWorld.UnmarkForWrite();
            Storage = new HkDestructionStorage(TemporaryWorld.DestructionWorld);

            // pre-fracture cube blocks
            {
                foreach (var groupName in MyDefinitionManager.Static.GetDefinitionPairNames())
                {
                    var group = MyDefinitionManager.Static.GetDefinitionGroup(groupName);

                    if (group.Large != null)
                    {
                        var model = VRage.Game.Models.MyModels.GetModel(group.Large.Model);
                        if (model == null)
                        {
                            continue;
                        }

                        if (!MyFakes.LAZY_LOAD_DESTRUCTION || (model != null && model.HavokBreakableShapes != null)) //reload materials
                        {
                            LoadModelDestruction(group.Large.Model, group.Large, group.Large.Size * (MyDefinitionManager.Static.GetCubeSize(group.Large.CubeSize)));
                        }

                        foreach (var progress in group.Large.BuildProgressModels)
                        {
                            model = VRage.Game.Models.MyModels.GetModel(progress.File);
                            if (model == null)
                            {
                                continue;
                            }

                            if (!MyFakes.LAZY_LOAD_DESTRUCTION || (model != null && model.HavokBreakableShapes != null)) //reload materials
                            {
                                LoadModelDestruction(progress.File, group.Large, group.Large.Size * (MyDefinitionManager.Static.GetCubeSize(group.Large.CubeSize)));
                            }
                        }


                        if (MyFakes.CHANGE_BLOCK_CONVEX_RADIUS)
                        {
                            if (model != null && model.HavokBreakableShapes != null)
                            {
                                var shape = model.HavokBreakableShapes[0].GetShape();
                                if (shape.ShapeType != HkShapeType.Sphere && shape.ShapeType != HkShapeType.Capsule)
                                {
                                    SetConvexRadius(model.HavokBreakableShapes[0], MyDestructionConstants.LARGE_GRID_CONVEX_RADIUS);
                                }
                            }
                        }
                    }

                    if (group.Small != null)
                    {
                        var model = VRage.Game.Models.MyModels.GetModel(group.Small.Model);
                        if (model == null)
                        {
                            continue;
                        }

                        if (!MyFakes.LAZY_LOAD_DESTRUCTION || (model != null && model.HavokBreakableShapes != null)) //reload materials
                        {
                            LoadModelDestruction(group.Small.Model, group.Small, group.Small.Size * (MyDefinitionManager.Static.GetCubeSize(group.Small.CubeSize)));
                        }

                        foreach (var progress in group.Small.BuildProgressModels)
                        {
                            model = VRage.Game.Models.MyModels.GetModel(progress.File);
                            if (model == null)
                            {
                                continue;
                            }
                            if (!MyFakes.LAZY_LOAD_DESTRUCTION || (model != null && model.HavokBreakableShapes != null)) //reload materials
                            {
                                LoadModelDestruction(progress.File, group.Small, group.Large.Size * (MyDefinitionManager.Static.GetCubeSize(group.Large.CubeSize)));
                            }
                        }

                        if (MyFakes.CHANGE_BLOCK_CONVEX_RADIUS)
                        {
                            if (model != null && model.HavokBreakableShapes != null)
                            {
                                var shape = model.HavokBreakableShapes[0].GetShape();
                                if (shape.ShapeType != HkShapeType.Sphere && shape.ShapeType != HkShapeType.Capsule)
                                {
                                    SetConvexRadius(model.HavokBreakableShapes[0], MyDestructionConstants.LARGE_GRID_CONVEX_RADIUS);
                                }
                            }
                        }
                    }
                }
                if (!MyFakes.LAZY_LOAD_DESTRUCTION)
                {
                    BlockShapePool.Preallocate();
                }
            }

            foreach (var def in MyDefinitionManager.Static.GetAllDefinitions <MyPhysicalModelDefinition>())
            {
                LoadModelDestruction(def.Model, def, Vector3.One, false, true);
            }
        }