Esempio n. 1
0
        /// <summary>
        /// Check if the missile does not collide too close to ship
        /// after shooting and correct its starting position if it does.
        /// </summary>
        private Vector3 CorrectPosition(Vector3 position, Vector3 direction, MyEntity viewerEntity)
        {
            //var predictedTrajectory = new MyLine(
            //    position - (MyMissileConstants.DISTANCE_TO_CHECK_MISSILE_CORRECTION) * direction,
            //    position + (MyMissileConstants.DISTANCE_TO_CHECK_MISSILE_CORRECTION) * direction,
            //    true);
            //var intersection = MyEntities.GetIntersectionWithLine(ref predictedTrajectory, this, viewerEntity);


            // This is fix for missles hitting voxels when you are near them (missles do not use per triangle collision as optimalization)
            float radius = MyModels.GetModel(MyModelsEnum.Missile).BoundingSphere.Radius;

            BoundingSphere boundingSphere = viewerEntity.WorldVolume;

            boundingSphere.Center += viewerEntity.WorldMatrix.Up * 1;

            var intersection = MyEntities.GetIntersectionWithSphere(ref boundingSphere, this, viewerEntity);

            if (intersection != null && !(intersection is MyMissile))
            {
                position = viewerEntity.GetPosition() + 2 * Vector3.One;
            }

            return(position);
        }
Esempio n. 2
0
        private void ReloadAnimations()
        {
            if (MySession.Static.LocalCharacter != null)
            {
                foreach (var animPlayer in MySession.Static.LocalCharacter.GetAllAnimationPlayers())
                {
                    MySession.Static.LocalCharacter.PlayerStop(animPlayer.Key, 0.0f);
                }
            }

            foreach (var animationDefinition in MyDefinitionManager.Static.GetAnimationDefinitions())
            {
                MyModel model = MyModels.GetModel(animationDefinition.AnimationModel);
                if (model != null)
                {
                    model.UnloadData();
                }
                MyModel modelFps = MyModels.GetModel(animationDefinition.AnimationModelFPS);
                if (modelFps != null)
                {
                    modelFps.UnloadData();
                }
            }

            MySessionComponentAnimationSystem.Static.ReloadMwmTracks();
        }
 private static void DebugDrawBareBlockInfo(MySlimBlock block, ref int row)
 {
     row += 2;
     MyRenderProxy.DebugDrawText2D(new Vector2(20, row++ *10),
                                   String.Format("Display Name: {0}", block.BlockDefinition.DisplayNameText), Color.Yellow, DEBUG_SCALE);
     MyRenderProxy.DebugDrawText2D(new Vector2(20, row++ *10),
                                   String.Format("Cube type: {0}", block.BlockDefinition.CubeDefinition.CubeTopology), Color.Yellow, DEBUG_SCALE);
     foreach (string modelName in block.BlockDefinition.CubeDefinition.Model.Distinct().OrderBy(s => s, StringComparer.InvariantCultureIgnoreCase))
     {
         MyRenderProxy.DebugDrawText2D(new Vector2(20, row++ *10), String.Format("Asset: {0}", modelName), Color.Yellow, DEBUG_SCALE);
         MyModel model = MyModels.GetModel(modelName);
         DebugDrawTexturesInfo(model, ref row);
     }
 }
        void onClick_Save(MyGuiControlButton sender)
        {
            foreach (var def in MyDefinitionManager.Static.GetAllDefinitions())
            {
                MyCubeBlockDefinition cubeDef = def as MyCubeBlockDefinition;
                if (cubeDef != null)
                {
                    if (!string.IsNullOrEmpty(cubeDef.Model))
                    {
                        var model          = MyModels.GetModel(cubeDef.Model);
                        var newMountpoints = MyCubeBuilder.AutogenerateMountpoints(model, MyDefinitionManager.Static.GetCubeSize(cubeDef.CubeSize));
                        cubeDef.MountPoints = newMountpoints.ToArray();
                    }
                }
            }

            MyDefinitionManager.Static.Save("CubeBlocks_*.*");
        }
        public static void DrawMountPoints(float cubeSize, MyCubeBlockDefinition def, ref MatrixD drawMatrix)
        {
            var mountPoints = def.MountPoints;

            if (mountPoints == null)
            {
                return;
            }

            if (!MyDebugDrawSettings.DEBUG_DRAW_MOUNT_POINTS_AUTOGENERATE)
            {
                DrawMountPoints(cubeSize, def, drawMatrix, mountPoints);
            }
            else
            {   //Generate mount points from model collisions and draw them
                if (def.Model != null)
                {
                    int     index = 0;
                    MyModel model = MyModels.GetModel(def.Model);

                    foreach (var shape in model.HavokCollisionShapes)
                    {
                        MyPhysicsBody.DrawCollisionShape(shape, drawMatrix, 0.2f, ref index);
                    }

                    var newMountPoints = AutogenerateMountpoints(model, cubeSize);

                    DrawMountPoints(cubeSize, def, drawMatrix, newMountPoints.ToArray());
                }
            }

            if (MyDebugDrawSettings.DEBUG_DRAW_MOUNT_POINTS_AXIS_HELPERS)
            {
                DrawMountPointsAxisHelpers(def, ref drawMatrix, cubeSize);
            }
        }
        void FractureBreakableShape(HkdBreakableShape bShape, MyModelFractures modelFractures, string modPath)
        {
            HkdFracture       fracture = null;
            HkReferenceObject geometry = null;

            if (modelFractures.Fractures[0] is RandomSplitFractureSettings)
            {
                var settings = (RandomSplitFractureSettings)modelFractures.Fractures[0];
                fracture = new HkdRandomSplitFracture()
                {
                    NumObjectsOnLevel1 = settings.NumObjectsOnLevel1,
                    NumObjectsOnLevel2 = settings.NumObjectsOnLevel2,
                    RandomRange        = settings.RandomRange,
                    RandomSeed1        = settings.RandomSeed1,
                    RandomSeed2        = settings.RandomSeed2,
                    SplitGeometryScale = Vector4.One
                };

                if (!string.IsNullOrEmpty(settings.SplitPlane))
                {
                    var splitPlane = settings.SplitPlane;
                    if (!string.IsNullOrEmpty(modPath))
                    {
                        splitPlane = Path.Combine(modPath, settings.SplitPlane);
                    }

                    geometry = CreateGeometryFromSplitPlane(splitPlane);
                    if (geometry != null)
                    {
                        ((HkdRandomSplitFracture)fracture).SetGeometry(geometry);
                        VRageRender.MyRenderProxy.PreloadMaterials(splitPlane);
                    }
                }
            }
            if (modelFractures.Fractures[0] is VoronoiFractureSettings)
            {
                var settings = (VoronoiFractureSettings)modelFractures.Fractures[0];
                fracture = new HkdVoronoiFracture()
                {
                    Seed = settings.Seed,
                    NumSitesToGenerate = settings.NumSitesToGenerate,
                    NumIterations      = settings.NumIterations
                };

                if (!string.IsNullOrEmpty(settings.SplitPlane))
                {
                    var splitPlane = settings.SplitPlane;
                    if (!string.IsNullOrEmpty(modPath))
                    {
                        splitPlane = Path.Combine(modPath, settings.SplitPlane);
                    }

                    geometry = CreateGeometryFromSplitPlane(splitPlane);

                    var pspm = MyModels.GetModel(splitPlane);

                    if (geometry != null)
                    {
                        ((HkdVoronoiFracture)fracture).SetGeometry(geometry);
                        VRageRender.MyRenderProxy.PreloadMaterials(splitPlane);
                    }
                }
            }
            //if (woodButton.IsChecked)
            //{
            //    fracture = new HkdWoodFracture()
            //    {
            //        RandomSeed = 123456,
            //        BoardSplittingData = new HkdWoodFracture.SplittingData()
            //        {
            //        },
            //        SplinterSplittingData = new HkdWoodFracture.SplittingData()
            //        {
            //        }
            //    };
            //}

            if (fracture != null)
            {
                Storage.FractureShape(bShape, fracture);
                fracture.Dispose();
            }

            if (geometry != null)
            {
                geometry.Dispose();
            }
        }
Esempio n. 7
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 = MyModels.GetModel(group.Large.Model);
                        if (model == null)
                        {
                            continue;
                        }

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

                        foreach (var progress in group.Large.BuildProgressModels)
                        {
                            model = 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, isGenerated, 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 = MyModels.GetModel(group.Small.Model);
                        if (model == null)
                        {
                            continue;
                        }
                        bool isGenerated = group.Small.IsGeneratedBlock && (group.Small.GeneratedBlockType == GENERATED_BLOCK_TYPE_PILLAR);
                        if (!MyFakes.LAZY_LOAD_DESTRUCTION || (model != null && model.HavokBreakableShapes != null)) //reload materials
                        {
                            LoadModelDestruction(group.Small.Model, group.Small, isGenerated, group.Small.Size * (MyDefinitionManager.Static.GetCubeSize(group.Small.CubeSize)));
                        }

                        foreach (var progress in group.Small.BuildProgressModels)
                        {
                            model = 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, isGenerated, 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 enviroment in MyDefinitionManager.Static.GetEnvironmentItemDefinitions())
            {
                LoadModelDestruction(enviroment.Model, enviroment, false, Vector3.One, false, true);
            }
        }