public void InitalizePhysics() { // Construct engine objects this.Camera = new Camera(this); // Construct physics objects ErrorOutput errorOutput = new ErrorOutput(); Foundation foundation = new Foundation(errorOutput); this.Physics = new Physics(foundation, checkRuntimeFiles: true); var sceneDesc = new SceneDesc() { Gravity = new Math.Vector3(0, -9.81f, 0) }; this.Scene = this.Physics.CreateScene(sceneDesc); this.Scene.SetVisualizationParameter(VisualizationParameter.Scale, 2.0f); this.Scene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true); this.Scene.SetVisualizationParameter(VisualizationParameter.JointLocalFrames, true); this.Scene.SetVisualizationParameter(VisualizationParameter.JointLimits, true); this.Scene.SetVisualizationParameter(VisualizationParameter.ParticleSystemPosition, true); this.Scene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true); // Connect to the remote debugger if it's there Physics.RemoteDebugger.Connect("localhost"); CreateGroundPlane(); }
public bool Initiliase() { this.physics = Physics.Create(); this.physics.Parameters.SkinWidth = 0.0025f; this.physics.RemoteDebugger.Connect("localhost"); this.physics.Parameters.ContinuousCd = 1; this.physics.Parameters.CcdEpsilon = 0.01f; SceneDesc sceneDesc = new SceneDesc(); sceneDesc.SetToDefault(); sceneDesc.Gravity = new Vector3(0, -9.8f, 0); sceneDesc.UpAxis = NX_Y; sceneDesc.TimeStepMethod = TimeStepMethods.Fixed; this.scene = physics.CreateScene(sceneDesc); this.scene.ActorGroupPairFlags[0, 0] = ContactPairFlags.NotifyOnStartTouch | ContactPairFlags.NotifyForces; this.scene.UserContactReport = this; // default material scene.Materials[0].Restitution = 0.2f; scene.Materials[0].StaticFriction = 0.8f; scene.Materials[0].DynamicFriction = 0.8f; // begin simulation this.scene.Simulate(0); return(true); }
public PhysxPhysicWorld(Vector3 gravity, bool connectToRemoteDebugger = false) { physix = new PhysX.Physics(new ErrorCallbackImp(), true); var sceneDesc = new SceneDesc() { Gravity = gravity.AsPhysX() }; scene = physix.CreateScene(sceneDesc); this.scene.SetVisualizationParameter(VisualizationParameter.Scale, 1.0f); this.scene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true); this.scene.SetVisualizationParameter(VisualizationParameter.JointLocalFrames, true); this.scene.SetVisualizationParameter(VisualizationParameter.JointLimits, true); this.scene.SetVisualizationParameter(VisualizationParameter.ParticleSystemPosition, true); this.scene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true); // Connect to the remote debugger if it's there if (connectToRemoteDebugger) { physix.ConnectToRemoteDebugger("localhost"); } objs = new List<IPhysicObject>(); ctns = new List<IPhysicConstraint>(); cooking = physix.CreateCooking(); }
public PhysxPhysicWorld(Vector3 gravity, bool connectToRemoteDebugger = false) { physix = new PhysX.Physics(new ErrorCallbackImp(), true); var sceneDesc = new SceneDesc() { Gravity = gravity.AsPhysX() }; scene = physix.CreateScene(sceneDesc); this.scene.SetVisualizationParameter(VisualizationParameter.Scale, 1.0f); this.scene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true); this.scene.SetVisualizationParameter(VisualizationParameter.JointLocalFrames, true); this.scene.SetVisualizationParameter(VisualizationParameter.JointLimits, true); this.scene.SetVisualizationParameter(VisualizationParameter.ParticleSystemPosition, true); this.scene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true); // Connect to the remote debugger if it's there if (connectToRemoteDebugger) { physix.ConnectToRemoteDebugger("localhost"); } objs = new List <IPhysicObject>(); ctns = new List <IPhysicConstraint>(); cooking = physix.CreateCooking(); }
public GameWorld(ModData modData) { this.modData = modData; physics = Physics.Create(); SceneDesc physicsSceneDesc = new SceneDesc(); physicsSceneDesc.Gravity = new Mogre.Vector3(0, -9.8f, 0); physicsSceneDesc.UpAxis = 1; physicsScene = physics.CreateScene(physicsSceneDesc); physicsScene.Materials[0].Restitution = 0.5f; physicsScene.Materials[0].StaticFriction = 0.5f; physicsScene.Materials[0].DynamicFriction = 0.5f; physicsScene.Simulate(0); teamRelationship = new List <Tuple <string, string, int> >(); globalVarMap = new Dictionary <string, string>(); globalVarMap.Add("reg0", "0"); globalVarMap.Add("reg1", "0"); globalVarMap.Add("reg2", "0"); globalVarMap.Add("reg3", "0"); globalVarMap.Add("reg4", "0"); globalValueTable = ScriptValueRegister.Instance.GlobalValueTable; /*Physx Debugger*/ if (physics.RemoteDebugger.IsConnected) { physics.RemoteDebugger.Connect("127.0.0.1", 5425); } else { physics.RemoteDebugger.Disconnect(); physics.RemoteDebugger.Connect("127.0.0.1", 5425); } }
public static RegionDesc ReadFromDat() { // Check the FileCache so we don't need to hit the FileSystem repeatedly if (DatManager.PortalDat.FileCache.ContainsKey(REGION_ID)) { return((RegionDesc)DatManager.PortalDat.FileCache[REGION_ID]); } else { DatReader datReader = DatManager.PortalDat.GetReaderForFile(REGION_ID); RegionDesc region = new RegionDesc(); region.FileId = datReader.ReadUInt32(); region.BLoaded = datReader.ReadUInt32(); region.TimeStamp = datReader.ReadUInt32(); region.RegionName = datReader.ReadPString(); // "Dereth" datReader.AlignBoundary(); region.PartsMask = datReader.ReadUInt32(); // There are 7 x 4 byte entries here that are "unknown". We will just skip them. datReader.Offset += (7 * 4); region.LandDefs = LandDefs.Read(datReader); region.GameTime = GameTime.Read(datReader); region.PNext = datReader.ReadUInt32(); if ((region.PNext & 0x10) > 0) { region.SkyInfo = SkyDesc.Read(datReader); } if ((region.PNext & 0x01) > 0) { region.SoundInfo = SoundDesc.Read(datReader); } if ((region.PNext & 0x02) > 0) { region.SceneInfo = SceneDesc.Read(datReader); } region.TerrainInfo = TerrainDesc.Read(datReader); if ((region.PNext & 0x0200) > 0) { region.RegionMisc = RegionMisc.Read(datReader); } DatManager.PortalDat.FileCache[REGION_ID] = region; return(region); } }
public void SceneDescFlagsAreMaintained() { var sceneDesc = new SceneDesc { Flags = SceneFlag.EnableActiveTransforms }; using (var physics = new Physics(new Foundation())) { var scene = physics.CreateScene(sceneDesc); Assert.IsTrue(scene.Flags.HasFlag(SceneFlag.EnableActiveTransforms)); } }
public void CreateSceneWithTemporalGaussSeidelSolver() { using (var physics = CreatePhysics()) { var sceneDesc = new SceneDesc { SolverType = SolverType.TGS }; using (var scene = physics.CreateScene(sceneDesc)) { } } }
public static SceneDesc Read(StreamReader data, StreamWriter outputData, bool write = true) { SceneDesc obj = new SceneDesc(); uint num_scene_types = Utils.readAndWriteUInt32(data, outputData, write); obj.SceneTypes = new List <SceneType>(); for (uint i = 0; i < num_scene_types; i++) { obj.SceneTypes.Add(SceneType.Read(data, outputData, write)); } return(obj); }
public void SceneDescFlagsAreMaintained() { using (var physics = new Physics(new Foundation())) { var sceneDesc = new SceneDesc { Flags = SceneFlag.EnableGpuDynamics | SceneFlag.EnableStabilization }; var scene = physics.CreateScene(sceneDesc); Assert.IsTrue(scene.Flags.HasFlag(SceneFlag.EnableGpuDynamics)); Assert.IsTrue(scene.Flags.HasFlag(SceneFlag.EnableStabilization)); } }
public PhysxBasicCubeState() { rnd = new Random(); physx = Physics.Create(); SceneDesc desc = new SceneDesc(); scene = physx.CreateScene(desc); scene.Gravity = new Mogre.Vector3(0, -9.81f, 0); var defm = scene.Materials[0]; defm.Restitution = 0.5f; defm.DynamicFriction = defm.StaticFriction = 0.6f; trayMgr = AdvancedMogreFramework.instance.m_pTrayMgr; cubes = new List <Entity>(); cubeActors = new List <Actor>(); }
public static void InitSDK() { Foundation fd = new Foundation(new ECB()); pvd = new Pvd(fd); py = new PhysX.Physics(fd, true, pvd); SceneD = new SceneDesc { Gravity = new System.Numerics.Vector3(0, 0, 0) }; Scene = py.CreateScene(SceneD); Scene.SetVisualizationParameter(VisualizationParameter.Scale, 2.0f); Scene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true); Scene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true); py.Pvd.Connect("localhost"); // Scene.Gravity = new System.Numerics.Vector3(0, 0, 0); //PhysX.Material dm = Scene.get }
public GameState() { m_MoveSpeed = 0.1f; m_RotateSpeed = 0.3f; m_bLMouseDown = false; m_bRMouseDown = false; m_bQuit = false; m_bSettingsMode = false; m_pDetailsPanel = null; physx = Physics.Create(); SceneDesc desc = new SceneDesc(); desc.Gravity = new Mogre.Vector3(0, -9.8f, 0); physxScene = physx.CreateScene(desc); paused = false; }
public void CreateAndDisposeSceneInstance() { using (var foundation = new Foundation()) { using (var physics = new Physics(foundation)) { var sceneDesc = new SceneDesc(); Scene scene; using (scene = physics.CreateScene(sceneDesc)) { GC.Collect(); Assert.IsFalse(scene.Disposed); } Assert.IsFalse(physics.Disposed); Assert.IsTrue(scene.Disposed); } } }
public void FromSceneDescToScene() { if (Physics.Instantiated) { Assert.Fail("Physics is still created"); } using (var foundation = new Foundation()) { var physics = new Physics(foundation, checkRuntimeFiles: true); var bpc = new TestBroadPhaseCallback(); var sceneDesc = new SceneDesc { BroadPhaseCallback = bpc }; var scene = physics.CreateScene(sceneDesc); Assert.AreEqual(bpc, scene.BroadPhaseCallback); } }
protected virtual SceneDesc CreateSceneDesc(Foundation foundation) { #if GPU var cudaContext = new CudaContextManager(foundation); #endif var sceneDesc = new SceneDesc { Gravity = new Vector3(0, -9.81f, 0), #if GPU GpuDispatcher = cudaContext.GpuDispatcher, #endif FilterShader = new SampleFilterShader() }; #if GPU sceneDesc.Flags |= SceneFlag.EnableGpuDynamics; sceneDesc.BroadPhaseType |= BroadPhaseType.Gpu; #endif _sceneDescCallback?.Invoke(sceneDesc); return(sceneDesc); }
public override void enter() { AdvancedMogreFramework.Singleton.m_pLog.LogMessage("Entering SinbadState..."); AdvancedMogreFramework.lastState = "SinbadState"; m_pSceneMgr = AdvancedMogreFramework.Singleton.m_pRoot.CreateSceneManager(SceneType.ST_GENERIC, "SinbadSceneMgr"); m_pCamera = m_pSceneMgr.CreateCamera("MainCamera"); AdvancedMogreFramework.Singleton.m_pViewport.Camera = m_pCamera; m_pCamera.AspectRatio = (float)AdvancedMogreFramework.Singleton.m_pViewport.ActualWidth / (float)AdvancedMogreFramework.Singleton.m_pViewport.ActualHeight; m_pCamera.NearClipDistance = 5; m_pCameraMan = new SdkCameraMan(m_pCamera); AdvancedMogreFramework.Singleton.m_pMouse.MouseMoved += mouseMoved; AdvancedMogreFramework.Singleton.m_pMouse.MousePressed += mousePressed; AdvancedMogreFramework.Singleton.m_pMouse.MouseReleased += mouseReleased; AdvancedMogreFramework.Singleton.m_pKeyboard.KeyPressed += keyPressed; AdvancedMogreFramework.Singleton.m_pKeyboard.KeyReleased += keyReleased; AdvancedMogreFramework.Singleton.m_pRoot.FrameRenderingQueued += FrameRenderingQueued; buildGUI(); physics = Physics.Create(); SceneDesc physicsSceneDesc = new SceneDesc(); physicsSceneDesc.Gravity = new Mogre.Vector3(0.0f, -9.8f, 0.0f); physicsSceneDesc.UpAxis = 1; physicsScene = physics.CreateScene(physicsSceneDesc); physicsScene.Materials[0].Restitution = 0.5f; physicsScene.Materials[0].StaticFriction = 0.5f; physicsScene.Materials[0].DynamicFriction = 0.5f; physicsScene.Simulate(0); createScene(); }
//Entities entities = new Entities(); //SceneNodes nodes = new SceneNodes(); private void SceneCreating() { SceneManager sm = OgreWindow.Instance.mSceneMgr; Root root = OgreWindow.Instance.mRoot; Camera camera = OgreWindow.Instance.mCamera; Viewport vp = OgreWindow.Instance.mViewport; OgreWindow.Instance.mSceneMgr.SetShadowUseInfiniteFarPlane(true); sm.AmbientLight = ColourValue.Black; #region shadows //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_ADDITIVE; //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_MODULATIVE; sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_NONE; //skyx breaks when shadows are enabled! //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_ADDITIVE; //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED; //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE; //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED; #endregion camera.FarClipDistance = 30000; camera.NearClipDistance = .25f; //camera.SetPosition(20000, 500, 20000); //camera.SetDirection(1, 0, 0); skyManager = new SkyManager(sm, OgreWindow.Instance.mCamera); skyManager.Create(); //manager.GPUManager.AddGroundPass(material.GetTechnique(0).CreatePass(), 5000, SceneBlendType.SBT_TRANSPARENT_COLOUR); skyManager.CloudsManager.Add(new CloudLayer.LayerOptions()); #region MHydrax if (!DISABLE_MHYDRAX) { //hydrax = new MHydrax.MHydrax(sm, camera, vp); // Hydrax initialization code --------------------------------------------- // ------------------------------------------------------------------------ // Create Hydrax object hydrax = new MHydrax.MHydrax(sm, camera, vp); // Set hydrax components. hydrax.Components = MHydrax.MHydraxComponent.HYDRAX_COMPONENT_CAUSTICS | MHydrax.MHydraxComponent.HYDRAX_COMPONENT_DEPTH | MHydrax.MHydraxComponent.HYDRAX_COMPONENT_FOAM | MHydrax.MHydraxComponent.HYDRAX_COMPONENT_SMOOTH | MHydrax.MHydraxComponent.HYDRAX_COMPONENT_SUN | MHydrax.MHydraxComponent.HYDRAX_COMPONENT_UNDERWATER | MHydrax.MHydraxComponent.HYDRAX_COMPONENT_UNDERWATER_GODRAYS | MHydrax.MHydraxComponent.HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS; //' Create our projected grid module //' Parameters: //' Hydrax parent pointer //' Noise module //' Base plane //' Normal mode //' Projected grid options MHydrax.MProjectedGrid m = new MHydrax.MProjectedGrid(hydrax, new MHydrax.MPerlin(new MHydrax.MPerlin.MOptions(8, 0.085f, 0.49f, 1.4f, 1.27f, 2f, new Mogre.Vector3(0.5f, 50f, 150000f))), new Plane(new Mogre.Vector3(0, 1, 0), new Mogre.Vector3(0, 0, 0)), MHydrax.MMaterialManager.MNormalMode.NM_VERTEX, new MHydrax.MProjectedGrid.MOptions(256, 35f, 50f, false, false, true, 3.75f)); //' Set our module hydrax.SetModule(m); //' Set all parameters instead of loading all parameters from config file: //'hydrax.LoadCfg("ProjectedGridDemo.hdx") //' #Main options hydrax.Position = new Mogre.Vector3(5000, 0, -5000); hydrax.PlanesError = 10.5f; hydrax.ShaderMode = MHydrax.MMaterialManager.MShaderMode.SM_HLSL; hydrax.FullReflectionDistance = 100000000000; hydrax.GlobalTransparency = 0; hydrax.NormalDistortion = 0.075f; hydrax.WaterColor = new Mogre.Vector3(0.139765f, 0.359464f, 0.425373f); //' #Sun parameters hydrax.SunPosition = new Mogre.Vector3(0, 10000, 0); hydrax.SunStrength = 1.75f; hydrax.SunArea = 150; hydrax.SunColor = new Mogre.Vector3(1f, 0.9f, 0.6f); //' #Foam parameters hydrax.FoamMaxDistance = 75000000; hydrax.FoamScale = 0.0075f; hydrax.FoamStart = 0; hydrax.FoamTransparency = 1; //' #Depth parameters hydrax.DepthLimit = 90; //' #Smooth transitions parameters hydrax.SmoothPower = 5; //' #Caustics parameters hydrax.CausticsScale = 135; hydrax.CausticsPower = 10.5f; hydrax.CausticsEnd = 0.8f; //' #God rays parameters hydrax.GodRaysExposure = new Mogre.Vector3(0.76f, 2.46f, 2.29f); hydrax.GodRaysIntensity = 0.015f; hydrax.GodRaysManager.SimulationSpeed = 5; hydrax.GodRaysManager.NumberOfRays = 100; hydrax.GodRaysManager.RaysSize = 0.03f; hydrax.GodRaysManager.ObjectsIntersectionsEnabled = false; //' #Rtt quality field(0x0 = Auto) //' TODO: RTTManager not wrapped yet. //'<size>Rtt_Quality_Reflection=0x0 //'<size>Rtt_Quality_Refraction=0x0 //'<size>Rtt_Quality_Depth=0x0 //'<size>Rtt_Quality_URDepth=0x0 //'<size>Rtt_Quality_GPUNormalMap=0x0 //' Create water hydrax.Create(); //' Hydrax initialization code end ----------------------------------------- //' ------------------------------------------------------------------------ //sm.AmbientLight = new ColourValue(1, 1, 1); //camera.FarClipDistance = 99999 * 6; //camera.Position = new Mogre.Vector3(312.902f, 206.419f, 1524.02f); //camera.Orientation = new Quaternion(0.998f, -0.0121f, -0.0608f, -0.00074f); } #endregion #region physics // create the root object OgreWindow.Instance.physics = Physics.Create(); OgreWindow.Instance.physics.Parameters.SkinWidth = 0.0025f; // setup default scene params SceneDesc sceneDesc = new SceneDesc(); sceneDesc.SetToDefault(); sceneDesc.Gravity = new Mogre.Vector3(0, -9.8f, 0); sceneDesc.UpAxis = 1; // NX_Y in c++ (I couldn't find the equivilent enum for C#) // your class should implement IUserContactReport to use this //sceneDesc.UserContactReport = this; OgreWindow.Instance.scene = OgreWindow.Instance.physics.CreateScene(sceneDesc); // default material OgreWindow.Instance.scene.Materials[0].Restitution = 0.5f; OgreWindow.Instance.scene.Materials[0].StaticFriction = 0.5f; OgreWindow.Instance.scene.Materials[0].DynamicFriction = 0.5f; // begin simulation OgreWindow.Instance.scene.Simulate(0); #endregion OgreWindow.Instance.SceneReady = true; }
private static void SetupFilters(SceneDesc sceneDesc) { sceneDesc.SimulationFilterCallback = new CollisionDisabledSimulationFilterCallback(); sceneDesc.FilterShader = new CollisionDisabledFilterShader(); }
static public void convert(string filename) { StreamReader inputFile = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read)); if (inputFile == null) { Console.WriteLine("Unable to open {0}", filename); return; } StreamWriter outputFile = new StreamWriter(new FileStream("./Region/13000000 - World Info - Winter.bin", FileMode.Create, FileAccess.Write)); if (outputFile == null) { Console.WriteLine("Unable to open 13000000 - World Info - Winter.bin"); return; } Console.WriteLine("Converting region file to winter..."); uint fileHeader; uint loaded; uint timeStamp; string regionName; uint partsMask; uint unknown1; uint unknown2; uint unknown3; uint unknown4; uint unknown5; uint unknown6; uint unknown7; LandDefs landDef; GameTime gameTime; uint next; SkyDesc skyInfo; SoundDesc soundInfo; SceneDesc sceneInfo; TerrainDesc terrainInfo; RegionMisc regionMisc; fileHeader = Utils.readAndWriteUInt32(inputFile, outputFile); if (fileHeader != 0x13000000) { Console.WriteLine("Invalid header, aborting."); return; } loaded = Utils.readAndWriteUInt32(inputFile, outputFile); timeStamp = Utils.readAndWriteUInt32(inputFile, outputFile); regionName = Utils.readAndWriteString(inputFile, outputFile); partsMask = Utils.readAndWriteUInt32(inputFile, outputFile); unknown1 = Utils.readAndWriteUInt32(inputFile, outputFile); unknown2 = Utils.readAndWriteUInt32(inputFile, outputFile); unknown3 = Utils.readAndWriteUInt32(inputFile, outputFile); unknown4 = Utils.readAndWriteUInt32(inputFile, outputFile); unknown5 = Utils.readAndWriteUInt32(inputFile, outputFile); unknown6 = Utils.readAndWriteUInt32(inputFile, outputFile); unknown7 = Utils.readAndWriteUInt32(inputFile, outputFile); landDef = LandDefs.Read(inputFile, outputFile); gameTime = GameTime.Read(inputFile, outputFile); next = Utils.readAndWriteUInt32(inputFile, outputFile); if ((next & 0x10) > 0) { skyInfo = SkyDesc.Read(inputFile, outputFile); } if ((next & 0x01) > 0) { soundInfo = SoundDesc.Read(inputFile, outputFile); } if ((next & 0x02) > 0) { sceneInfo = SceneDesc.Read(inputFile, outputFile); } terrainInfo = TerrainDesc.Read(inputFile, outputFile); if ((next & 0x0200) > 0) { regionMisc = RegionMisc.Read(inputFile, outputFile); } //StreamWriter outputFile2 = new StreamWriter(new FileStream("./13000000 - Terrain Textures -ToD.txt", FileMode.Create, FileAccess.Write)); //if (outputFile2 == null) //{ // Console.WriteLine("Unable to open 13000000 - Terrain Textures - ToD.txt"); // return; //} //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.CornerTerrainMaps.Count; i++) //{ // TerrainAlphaMap cornerTerrainMap = terrainInfo.LandSurfaces.texMerge.CornerTerrainMaps[i]; // outputFile2.WriteLine("{0}", cornerTerrainMap.TexGID.ToString("x8")); // outputFile2.Flush(); //} //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.SideTerrainMaps.Count; i++) //{ // TerrainAlphaMap sideTerrainMap = terrainInfo.LandSurfaces.texMerge.SideTerrainMaps[i]; // outputFile2.WriteLine("{0}", sideTerrainMap.TexGID.ToString("x8")); // outputFile2.Flush(); //} //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.RoadMaps.Count; i++) //{ // RoadAlphaMap roadMap = terrainInfo.LandSurfaces.texMerge.RoadMaps[i]; // outputFile2.WriteLine("{0}", roadMap.RoadTexGID.ToString("x8")); // outputFile2.Flush(); //} //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.TerrainDescription.Count; i++)//ignore first entry as it's a repeat of the second //{ // TMTerrainDesc desc = terrainInfo.LandSurfaces.texMerge.TerrainDescription[i]; // string terrainName = "Unknown"; // uint terrainColor = 0; // if (i < terrainInfo.TerrainTypes.Count) // { // terrainName = terrainInfo.TerrainTypes[(int)desc.terrainType].TerrainName; // terrainColor = terrainInfo.TerrainTypes[(int)desc.terrainType].TerrainColor; // } // else if (i == 32) // { // terrainName = "Road"; // terrainColor = 0; // } // terrainName = terrainName.PadLeft(20); // outputFile2.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}", desc.terrainType, terrainName, desc.terrainTex.TexGID.ToString("x8"), desc.terrainTex.TexTiling, desc.terrainTex.DetailTexGID.ToString("x8"), // desc.terrainTex.DetailTexTiling, desc.terrainTex.MaxVertBright, desc.terrainTex.MaxVertHue, desc.terrainTex.MaxVertSaturate, desc.terrainTex.MinVertBright, // desc.terrainTex.MinVertHue, desc.terrainTex.MinVertSaturate); // //outputFile2.WriteLine("TextureConverter.toBin(\"Landscape Texture Conversion/DM/Textures/Upscaled/xxx.png\", 0x{0}, 21);//{1}",desc.terrainTex.TexGID.ToString("x8"),terrainName); // //outputFile2.WriteLine("writedat client_portal.dat -f {0}={0}.bin", desc.terrainTex.TexGID.ToString("x8")); // outputFile2.Flush(); //} //outputFile2.Close(); inputFile.Close(); outputFile.Flush(); outputFile.Close(); Console.WriteLine("Done"); }
public PhysxPhysicsSystem(World world) : base(world) { // Setup PhysX infra here this.physxFoundation = new PxFoundation(new ConsoleErrorCallback()); this.physxScale = new PxTolerancesScale() { Length = 0.1f, Speed = 98.1f }; #if DEBUG pvd = new Pvd(this.physxFoundation); pvd.Connect("localhost", 5425, TimeSpan.FromSeconds(2), InstrumentationFlag.Debug); this.physxPhysics = new PxPhysics(this.physxFoundation, this.physxScale, false, pvd); #else this.physxPhysics = new PxPhysics(this.physxFoundation, this.physxScale); #endif this.defaultMat = this.physxPhysics.CreateMaterial(0.5f, 0.5f, 0.1f); this.characterControlMat = this.physxPhysics.CreateMaterial(0.5f, 0.5f, 0f); this.characterControlMat.RestitutionCombineMode = CombineMode.Minimum; this.frictionlessMat = this.physxPhysics.CreateMaterial(0f, 0f, 0f); this.frictionlessMat.RestitutionCombineMode = CombineMode.Minimum; this.frictionlessMat.Flags = MaterialFlags.DisableFriction; var sceneDesc = new SceneDesc(this.physxScale) { BroadPhaseType = BroadPhaseType.SweepAndPrune, Gravity = world.Gravity, Flags = SceneFlag.EnableStabilization, SolverType = SolverType.TGS, FilterShader = new DefaultFilterShader(), BounceThresholdVelocity = 0.2f * world.Gravity.Length() }; this.physxScene = this.physxPhysics.CreateScene(sceneDesc); #if DEBUG this.physxScene.SetVisualizationParameter(VisualizationParameter.ContactPoint, true); this.physxScene.SetVisualizationParameter(VisualizationParameter.ContactNormal, true); this.physxScene.SetVisualizationParameter(VisualizationParameter.ContactForce, true); this.physxScene.SetVisualizationParameter(VisualizationParameter.ContactError, true); var pvdClient = this.physxScene.GetPvdSceneClient(); pvdClient.SetScenePvdFlags(SceneVisualizationFlags.TransmitContacts | SceneVisualizationFlags.TransmitConstraints | SceneVisualizationFlags.TransmitSceneQueries); #endif var cookingParams = new CookingParams() { Scale = this.physxScale, AreaTestEpsilon = 0.001f, MidphaseDesc = new MidphaseDesc() { Bvh33Desc = new Bvh33MidphaseDesc() { MeshCookingHint = MeshCookingHint.SimulationPerformance } }, BuildTriangleAdjacencies = true, MeshCookingHint = MeshCookingHint.SimulationPerformance, MeshWeldTolerance = 0.001f }; this.cooker = this.physxPhysics.CreateCooking(cookingParams); this.controllerManager = this.physxScene.CreateControllerManager(); var contactProv = new ContactModifyProxy(); this.contactProvider = contactProv; this.physxScene.ContactModifyCallback = contactProv; this.simCallback = new SimulationCallback(); this.physxScene.SetSimulationEventCallback(simCallback); }
/// <summary> /// 导出 /// </summary> static public void Export(SceneTree[] trees, List <MeshCollider> meshColliders, bool exportRes, bool compress) { // 收集依赖 var sb = new StringBuilder(); int depsCount = 0; var resCollector = new ResDescCollector(); var dictRes = new Dictionary <string, ResExportDesc>(); // 光照图(不能卸载第一张光照图,否则unity_Lightmap_HDR会置为1) var lightMaps = LightmapSettings.lightmaps; if (null != lightMaps && lightMaps.Length > 0 && null != lightMaps[0].lightmapColor) { var resName = ResDepBase.GetResName(lightMaps[0].lightmapColor); resCollector.AddLightMap(resName, 0, true); } // 场景 for (int i = 0; i < trees.Length; ++i) { var tree = trees[i]; if (null != tree && tree.settings.objType == SceneTreeObjType.Renderer) { var n = tree.CollectDeps(dictRes); sb.AppendFormat("Tree {0} deps count is {1}\n", tree.settings.name, n); depsCount += n; } } sb.AppendFormat("All tree deps count is {0}\n", depsCount); Debug.Log(sb.ToString()); // 生成节点数据 var prefabCollection = new ScenePrefabCollection(); var treeDatas = new List <SceneTreeData>(); for (int i = 0; i < trees.Length; ++i) { var tree = trees[i]; if (null != tree) { var data = tree.BuildData(prefabCollection, dictRes); treeDatas.Add(data); } } // LightMap这里要置空一下,仅清空LightmapSettings.lightmaps仍然有依赖 Lightmapping.lightingDataAsset = null; // 只留一盏主光源 var lights = Light.GetLights(LightType.Directional, 0); Light mainLight = null; if (lights.Length > 0) { mainLight = lights[0]; for (int i = 1; i < lights.Length; ++i) { GameObject.DestroyImmediate(lights[i].gameObject); } } // MeshCollider var deps = new List <ResDepBase>(); ResDepBase.CollectColliderDependencies(meshColliders, deps); for (int n = 0, cn = deps.Count; n < cn; ++n) { var dep = deps[n]; dep.CollectRes(resCollector, dictRes); dep.RemoveDependencies(); } // 场景描述 var goSceneDesc = new GameObject("scene_desc"); SceneDesc desc = goSceneDesc.AddComponent <SceneDesc>(); desc.mainLight = mainLight; desc.lightMapCount = LightmapSettings.lightmaps.Length; desc.resCollection = resCollector.Export(); desc.trees = treeDatas.ToArray(); desc.prefabs = prefabCollection.Export(); // 移除编辑脚本 var cfgs = UnityEngine.Object.FindObjectsOfType <EditorSceneObject>(); for (int i = 0; i < cfgs.Length; ++i) { UnityEngine.Object.DestroyImmediate(cfgs[i]); } // 资源 if (exportRes) { var sbExport = new StringBuilder(); sbExport.AppendFormat("Resources Count[{0}]\n", dictRes.Count); sbExport.Append("---------------------------------------------------------------\n"); foreach (var pair in dictRes) { var resDesc = pair.Value; ResExportUtil.ExportRes(resDesc, compress); sbExport.AppendFormat("{0}/{1} - {2}\n", resDesc.resDir, resDesc.resName, resDesc.refCount); } sbExport.Append("---------------------------------------------------------------\n"); Debug.Log(sbExport.ToString()); } }
public bool Initiliase() { this.physics = Physics.Create(); this.physics.Parameters.SkinWidth = 0.0025f; this.physics.RemoteDebugger.Connect("localhost"); this.physics.Parameters.ContinuousCd = 1; this.physics.Parameters.CcdEpsilon = 0.01f; SceneDesc sceneDesc = new SceneDesc(); sceneDesc.SetToDefault(); sceneDesc.Gravity = new Vector3(0, -9.8f, 0); sceneDesc.UpAxis = NX_Y; sceneDesc.TimeStepMethod = TimeStepMethods.Fixed; this.scene = physics.CreateScene(sceneDesc); this.scene.ActorGroupPairFlags[0, 0] = ContactPairFlags.NotifyOnStartTouch | ContactPairFlags.NotifyForces; this.scene.UserContactReport = this; // default material scene.Materials[0].Restitution = 0.2f; scene.Materials[0].StaticFriction = 0.8f; scene.Materials[0].DynamicFriction = 0.8f; // begin simulation this.scene.Simulate(0); return true; }
public void InitalizePhysics() { // Construct engine objects this.Camera = new Camera(this); // Construct physics objects ErrorOutput errorOutput = new ErrorOutput(); Foundation foundation = new Foundation(errorOutput); this.Physics = new Physics(foundation, checkRuntimeFiles: true); #if GPU var cudaContext = new CudaContextManager(foundation); #endif var sceneDesc = new SceneDesc() { Gravity = new Math.Vector3(0, -9.81f, 0), #if GPU GpuDispatcher = cudaContext.GpuDispatcher #endif }; this.Scene = this.Physics.CreateScene(sceneDesc); this.Scene.SetVisualizationParameter(VisualizationParameter.Scale, 2.0f); this.Scene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true); this.Scene.SetVisualizationParameter(VisualizationParameter.JointLocalFrames, true); this.Scene.SetVisualizationParameter(VisualizationParameter.JointLimits, true); this.Scene.SetVisualizationParameter(VisualizationParameter.ParticleSystemPosition, true); this.Scene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true); // Connect to the remote debugger if it's there if (this.Physics.RemoteDebugger != null) { this.Physics.RemoteDebugger.Connect("localhost"); } CreateGroundPlane(); }
public void Awake() { Console.WriteLine("StartGame"); //初始化物理 ErrorOutput errorOutput = new ErrorOutput(); Foundation foundation = new Foundation(errorOutput); //var pvd = new PhysX.VisualDebugger.ConnectionManager Physics = new Physics(foundation); var sceneDesc = new SceneDesc { Gravity = new System.Numerics.Vector3(0, -9.81f, 0), FilterShader = new SampleFilterShader() }; Scene = Physics.CreateScene(sceneDesc); this.Scene.SetVisualizationParameter(VisualizationParameter.Scale, 2.0f); this.Scene.SetVisualizationParameter(VisualizationParameter.CollisionShapes, true); this.Scene.SetVisualizationParameter(VisualizationParameter.JointLocalFrames, true); this.Scene.SetVisualizationParameter(VisualizationParameter.JointLimits, true); this.Scene.SetVisualizationParameter(VisualizationParameter.ActorAxes, true); Physics.PvdConnectionManager.Connect("localhost", 5425); //创建平面 var groundPlaneMaterial = this.Scene.Physics.CreateMaterial(0.1f, 0.1f, 0.1f); var groundPlane = this.Scene.Physics.CreateRigidStatic(); groundPlane.GlobalPose = Matrix4x4.CreateFromAxisAngle(new System.Numerics.Vector3(0, 0, 1), (float)System.Math.PI / 2); groundPlane.Name = "Ground Plane"; var planeGeom = new PlaneGeometry(); groundPlane.CreateShape(planeGeom, groundPlaneMaterial); this.Scene.AddActor(groundPlane); //创建角色 var material = Scene.Physics.CreateMaterial(0.1f, 0.1f, 0.1f); var controllerManager = Scene.CreateControllerManager(); { var desc = new CapsuleControllerDesc() { Height = 4, Radius = 1, Material = material, UpDirection = new Vector3(0, 1, 0), Position = new Vector3(0, 3, 0), ReportCallback = new ControllerHitReport() }; _controller = controllerManager.CreateController <CapsuleController>(desc); } //再来一个不动的 { var desc = new CapsuleControllerDesc() { Height = 4, Radius = 1, Material = material, UpDirection = new Vector3(0, 1, 0), Position = new Vector3(15, 3, 15) }; controllerManager.CreateController <CapsuleController>(desc); } }
//In DM the 130F0000 is the equivalent of ToD 13000000 and the DM's 13000000 is possibly used for software rendering static public void convert(string filename) { StreamReader inputFile = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read)); if (inputFile == null) { Console.WriteLine("Unable to open {0}", filename); return; } StreamWriter outputFile = new StreamWriter(new FileStream("./130F0000 - World Info - DM.bin", FileMode.Create, FileAccess.Write)); if (outputFile == null) { Console.WriteLine("Unable to open 130F0000 - World Info - Winter.bin"); return; } Console.WriteLine("Converting region file to winter..."); byte[] buffer = new byte[1024]; uint fileHeader; uint loaded; uint timeStamp; string regionName; uint partsMask; uint unknown1; uint unknown2; uint unknown3; uint unknown4; uint unknown5; uint unknown6; uint unknown7; LandDefs landDef; GameTime gameTime; uint next; SkyDesc skyInfo; SoundDesc soundInfo; SceneDesc sceneInfo; TerrainDesc terrainInfo; RegionMisc regionMisc; fileHeader = Utils.readAndWriteUInt32(inputFile, outputFile); if (fileHeader != 0x13000000 && fileHeader != 0x130F0000) { Console.WriteLine("Invalid header, aborting."); return; } loaded = Utils.readAndWriteUInt32(inputFile, outputFile); timeStamp = Utils.readAndWriteUInt32(inputFile, outputFile); regionName = Utils.readAndWriteString(inputFile, outputFile); partsMask = Utils.readAndWriteUInt32(inputFile, outputFile); unknown1 = Utils.readAndWriteUInt32(inputFile, outputFile); unknown2 = Utils.readAndWriteUInt32(inputFile, outputFile); unknown3 = Utils.readAndWriteUInt32(inputFile, outputFile); unknown4 = Utils.readAndWriteUInt32(inputFile, outputFile); unknown5 = Utils.readAndWriteUInt32(inputFile, outputFile); unknown6 = Utils.readAndWriteUInt32(inputFile, outputFile); unknown7 = Utils.readAndWriteUInt32(inputFile, outputFile); landDef = LandDefs.Read(inputFile, outputFile); gameTime = GameTime.Read(inputFile, outputFile); next = Utils.readAndWriteUInt32(inputFile, outputFile); if ((next & 0x10) > 0) { skyInfo = SkyDesc.Read(inputFile, outputFile); } if ((next & 0x01) > 0) { soundInfo = SoundDesc.Read(inputFile, outputFile); } if ((next & 0x02) > 0) { sceneInfo = SceneDesc.Read(inputFile, outputFile); } terrainInfo = TerrainDesc.Read(inputFile, outputFile); if ((next & 0x0200) > 0) { regionMisc = RegionMisc.Read(inputFile, outputFile); } StreamWriter outputFile2 = new StreamWriter(new FileStream("./130F0000 - Terrain Textures - DM.txt", FileMode.Create, FileAccess.Write)); if (outputFile2 == null) { Console.WriteLine("Unable to open 130F0000 - Terrain Textures - DM.txt"); return; } //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.CornerTerrainMaps.Count; i++) //{ // TerrainAlphaMap cornerTerrainMap = terrainInfo.LandSurfaces.texMerge.CornerTerrainMaps[i]; // outputFile2.WriteLine("{0}", cornerTerrainMap.TexGID.ToString("x")); // outputFile2.Flush(); //} //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.SideTerrainMaps.Count; i++) //{ // TerrainAlphaMap sideTerrainMap = terrainInfo.LandSurfaces.texMerge.SideTerrainMaps[i]; // outputFile2.WriteLine("{0}", sideTerrainMap.TexGID.ToString("x")); // outputFile2.Flush(); //} //for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.RoadMaps.Count; i++) //{ // RoadAlphaMap roadMap = terrainInfo.LandSurfaces.texMerge.RoadMaps[i]; // outputFile2.WriteLine("{0}", roadMap.RoadTexGID.ToString("x")); // outputFile2.Flush(); //} for (int i = 0; i < terrainInfo.LandSurfaces.texMerge.TerrainDescription.Count; i++) { TMTerrainDesc desc = terrainInfo.LandSurfaces.texMerge.TerrainDescription[i]; string terrainName = "Unknown"; uint terrainColor = 0; if (i < terrainInfo.TerrainTypes.Count) { terrainName = terrainInfo.TerrainTypes[(int)desc.terrainType].TerrainName; terrainColor = terrainInfo.TerrainTypes[(int)desc.terrainType].TerrainColor; } else if (i == 31) { terrainName = "Unused"; terrainColor = 0; } else if (i == 32) { terrainName = "Road"; terrainColor = 0; } terrainName = terrainName.PadLeft(20); outputFile2.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}", desc.terrainType, terrainName, desc.terrainTex.TexGID.ToString("x8"), desc.terrainTex.TexTiling, desc.terrainTex.DetailTexGID.ToString("x8"), desc.terrainTex.DetailTexTiling, desc.terrainTex.MaxVertBright, desc.terrainTex.MaxVertHue, desc.terrainTex.MaxVertSaturate, desc.terrainTex.MinVertBright, desc.terrainTex.MinVertHue, desc.terrainTex.MinVertSaturate); //outputFile2.WriteLine("{0}\t{1}", terrainName, desc.terrainTex.TexGID.ToString("x8")); outputFile2.Flush(); } outputFile2.Close(); inputFile.Close(); outputFile.Flush(); outputFile.Close(); Console.WriteLine("Done"); }