public TestScene( RegionInfo regInfo, AgentCircuitManager authen, PhysicsScene physicsScene, SceneCommunicationService sceneGridService, ISimulationDataService simDataService, IEstateDataService estateDataService, IConfigSource config, string simulatorVersion) : base(regInfo, authen, physicsScene, sceneGridService, simDataService, estateDataService, config, simulatorVersion) { }
public Simulation Create(PhysicsProcessor sceneProcessor, PhysicsEngineFlags flags = PhysicsEngineFlags.None) { var scene = new PhysicsScene { Processor = sceneProcessor, Simulation = new Simulation(flags) }; lock (this) { scenes.Add(scene); } return scene.Simulation; }
public void Initialize() { // Loading ODEPlugin cbt = new OdePlugin(); // Loading Zero Mesher imp = new ZeroMesherPlugin(); // Getting Physics Scene ps = cbt.GetScene("test"); // Initializing Physics Scene. ps.Initialise(imp.GetMesher(),null); float[] _heightmap = new float[(int)Constants.RegionSize * (int)Constants.RegionSize]; for (int i = 0; i < ((int)Constants.RegionSize * (int)Constants.RegionSize); i++) { _heightmap[i] = 21f; } ps.SetTerrain(_heightmap); }
public void Initialize() { IConfigSource openSimINI = new IniConfigSource(); IConfig startupConfig = openSimINI.AddConfig("Startup"); startupConfig.Set("physics", "OpenDynamicsEngine"); startupConfig.Set("DecodedSculptMapPath", "j2kDecodeCache"); Vector3 regionExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight); //PhysicsScene pScene = physicsPluginManager.GetPhysicsScene( // "BulletSim", "Meshmerizer", openSimINI, "BSTestRegion", regionExtent); RegionInfo info = new RegionInfo(); info.RegionName = "ODETestRegion"; info.RegionSizeX = info.RegionSizeY = info.RegionSizeZ = Constants.RegionSize; OpenSim.Region.Framework.Scenes.Scene scene = new OpenSim.Region.Framework.Scenes.Scene(info); //IMesher mesher = new OpenSim.Region.PhysicsModules.Meshing.Meshmerizer(); //INonSharedRegionModule mod = mesher as INonSharedRegionModule; //mod.Initialise(openSimINI); //mod.AddRegion(scene); //mod.RegionLoaded(scene); pScene = new OdeScene(); Console.WriteLine("HERE " + (pScene == null ? "Null" : "Not null")); INonSharedRegionModule mod = (pScene as INonSharedRegionModule); Console.WriteLine("HERE " + (mod == null ? "Null" : "Not null")); mod.Initialise(openSimINI); mod.AddRegion(scene); mod.RegionLoaded(scene); // Loading ODEPlugin //cbt = new OdePlugin(); // Getting Physics Scene //ps = cbt.GetScene("test"); // Initializing Physics Scene. //ps.Initialise(imp.GetMesher(TopConfig), null, Vector3.Zero); float[] _heightmap = new float[(int)Constants.RegionSize * (int)Constants.RegionSize]; for (int i = 0; i < ((int)Constants.RegionSize * (int)Constants.RegionSize); i++) { _heightmap[i] = 21f; } pScene.SetTerrain(_heightmap); }
public void Initialize() { IConfigSource TopConfig = new IniConfigSource(); IConfig config = TopConfig.AddConfig("Startup"); config.Set("DecodedSculptMapPath","j2kDecodeCache"); // Loading ODEPlugin cbt = new OdePlugin(); // Loading Zero Mesher imp = new ZeroMesherPlugin(); // Getting Physics Scene ps = cbt.GetScene("test"); // Initializing Physics Scene. ps.Initialise(imp.GetMesher(TopConfig),null); float[] _heightmap = new float[(int)Constants.RegionSize * (int)Constants.RegionSize]; for (int i = 0; i < ((int)Constants.RegionSize * (int)Constants.RegionSize); i++) { _heightmap[i] = 21f; } ps.SetTerrain(_heightmap); }
public PhysicalSpriteUV(TextureInfo textureInfo, PhysicsScene physicsScene, bool circle = false) : base(textureInfo) { // Texture Setup Quad.S = TextureInfo.TextureSizef; Pivot = new Vector2(TextureInfo.Texture.Width / 2f, TextureInfo.Texture.Height / 2f ); // Physics Setup (get the indicies we will be using PhysicsScene = physicsScene; ShapeIndex = PhysicsScene.NumShape; BodyIndex = PhysicsScene.NumBody; JointIndex = -1; // Create shapes (will want to let the programmer pass in things like friction and rotation at some point, AND SPECIFY CIRCLE OR SQUARE SHAPE) PhysicsShape shape; if(!circle) { shape = new PhysicsShape(new Vector2(textureInfo.Texture.Width/2, textureInfo.Texture.Height/2)); } else { shape = new PhysicsShape(textureInfo.Texture.Width/2); } // Why 100? PhysicsBody body = new PhysicsBody(shape, 100); body.ShapeIndex = (uint)ShapeIndex; PhysicsScene.sceneShapes[ShapeIndex] = shape; PhysicsScene.sceneBodies[BodyIndex] = body; //PhysicsScene.sceneBodies[BodyIndex].Rotation = 0.1f; //PhysicsScene.sceneBodies[BodyIndex].AirFriction = 0.01f; PhysicsScene.NumShape++; PhysicsScene.NumBody++; }
// Unhook all the combining that I know about. public void UnCombine(PhysicsScene pScene) { // Just like ODE, we don't do anything yet. DetailLog("{0},BSTerrainManager.UnCombine", BSScene.DetailLogZero); }
// This routine is called two ways: // One with 'offset' and 'pScene' zero and null but 'extents' giving the maximum // extent of the combined regions. This is to inform the parent of the size // of the combined regions. // and one with 'offset' as the offset of the child region to the base region, // 'pScene' pointing to the parent and 'extents' of zero. This informs the // child of its relative base and new parent. public void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) { m_worldOffset = offset; m_worldMax = extents; MegaRegionParentPhysicsScene = pScene; if (pScene != null) { // We are a child. // We want m_worldMax to be the highest coordinate of our piece of terrain. m_worldMax = offset + DefaultRegionSize; } DetailLog("{0},BSTerrainManager.Combine,offset={1},extents={2},wOffset={3},wMax={4}", BSScene.DetailLogZero, offset, extents, m_worldOffset, m_worldMax); }
// High performance detailed logging routine used by the physical objects. protected void DetailLog(string msg, params Object[] args) { //if (PhysicsScene.PhysicsLogging.Enabled) PhysicsScene.DetailLog(msg, args); }
public SceneHelpers(CoreAssetCache cache) { SceneManager = new SceneManager(); m_assetService = StartAssetService(cache); m_authenticationService = StartAuthenticationService(); m_inventoryService = StartInventoryService(); m_gridService = StartGridService(); m_userAccountService = StartUserAccountService(); m_presenceService = StartPresenceService(); m_inventoryService.PostInitialise(); m_assetService.PostInitialise(); m_userAccountService.PostInitialise(); m_presenceService.PostInitialise(); m_cache = cache; m_physicsScene = StartPhysicsScene(); SimDataService = OpenSim.Server.Base.ServerUtils.LoadPlugin<ISimulationDataService>("OpenSim.Tests.Common.dll", null); }
public override void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) { m_worldOffset = offset; WorldExtents = new Vector2(extents.X, extents.Y); m_parentScene = pScene; }
public Scene(RegionInfo regInfo, AgentCircuitManager authen, PhysicsScene physicsScene, SceneCommunicationService sceneGridService, ISimulationDataService simDataService, IEstateDataService estateDataService, IConfigSource config, string simulatorVersion) : this(regInfo, physicsScene) { m_config = config; MinFrameTime = 0.089f; MinMaintenanceTime = 1; SeeIntoRegion = true; Random random = new Random(); m_lastAllocatedLocalId = (uint)(random.NextDouble() * (double)(uint.MaxValue / 2)) + (uint)(uint.MaxValue / 4); m_authenticateHandler = authen; m_sceneGridService = sceneGridService; m_SimulationDataService = simDataService; m_EstateDataService = estateDataService; m_regionHandle = RegionInfo.RegionHandle; m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this); m_asyncSceneObjectDeleter.Enabled = true; m_asyncInventorySender = new AsyncInventorySender(this); #region Region Settings // Load region settings // LoadRegionSettings creates new region settings in persistence if they don't already exist for this region. // However, in this case, the default textures are not set in memory properly, so we need to do it here and // resave. // FIXME: It shouldn't be up to the database plugins to create this data - we should do it when a new // region is set up and avoid these gyrations. RegionSettings rs = simDataService.LoadRegionSettings(RegionInfo.RegionID); m_extraSettings = simDataService.GetExtra(RegionInfo.RegionID); bool updatedTerrainTextures = false; if (rs.TerrainTexture1 == UUID.Zero) { rs.TerrainTexture1 = RegionSettings.DEFAULT_TERRAIN_TEXTURE_1; updatedTerrainTextures = true; } if (rs.TerrainTexture2 == UUID.Zero) { rs.TerrainTexture2 = RegionSettings.DEFAULT_TERRAIN_TEXTURE_2; updatedTerrainTextures = true; } if (rs.TerrainTexture3 == UUID.Zero) { rs.TerrainTexture3 = RegionSettings.DEFAULT_TERRAIN_TEXTURE_3; updatedTerrainTextures = true; } if (rs.TerrainTexture4 == UUID.Zero) { rs.TerrainTexture4 = RegionSettings.DEFAULT_TERRAIN_TEXTURE_4; updatedTerrainTextures = true; } if (updatedTerrainTextures) rs.Save(); RegionInfo.RegionSettings = rs; if (estateDataService != null) RegionInfo.EstateSettings = estateDataService.LoadEstateSettings(RegionInfo.RegionID, false); #endregion Region Settings //Bind Storage Manager functions to some land manager functions for this scene EventManager.OnLandObjectAdded += new EventManager.LandObjectAdded(simDataService.StoreLandObject); EventManager.OnLandObjectRemoved += new EventManager.LandObjectRemoved(simDataService.RemoveLandObject); RegisterDefaultSceneEvents(); // XXX: Don't set the public property since we don't want to activate here. This needs to be handled // better in the future. m_scripts_enabled = !RegionInfo.RegionSettings.DisableScripts; PhysicsEnabled = !RegionInfo.RegionSettings.DisablePhysics; m_simulatorVersion = simulatorVersion + " (" + Util.GetRuntimeInformation() + ")"; #region Region Config // Region config overrides global config // if (m_config.Configs["Startup"] != null) { IConfig startupConfig = m_config.Configs["Startup"]; StartDisabled = startupConfig.GetBoolean("StartDisabled", false); m_defaultDrawDistance = startupConfig.GetFloat("DefaultDrawDistance", m_defaultDrawDistance); UseBackup = startupConfig.GetBoolean("UseSceneBackup", UseBackup); if (!UseBackup) m_log.InfoFormat("[SCENE]: Backup has been disabled for {0}", RegionInfo.RegionName); //Animation states m_useFlySlow = startupConfig.GetBoolean("enableflyslow", false); SeeIntoRegion = startupConfig.GetBoolean("see_into_region", SeeIntoRegion); MaxUndoCount = startupConfig.GetInt("MaxPrimUndos", 20); PhysicalPrims = startupConfig.GetBoolean("physical_prim", PhysicalPrims); CollidablePrims = startupConfig.GetBoolean("collidable_prim", CollidablePrims); m_minNonphys = startupConfig.GetFloat("NonPhysicalPrimMin", m_minNonphys); if (RegionInfo.NonphysPrimMin > 0) { m_minNonphys = RegionInfo.NonphysPrimMin; } m_maxNonphys = startupConfig.GetFloat("NonPhysicalPrimMax", m_maxNonphys); if (RegionInfo.NonphysPrimMax > 0) { m_maxNonphys = RegionInfo.NonphysPrimMax; } m_minPhys = startupConfig.GetFloat("PhysicalPrimMin", m_minPhys); if (RegionInfo.PhysPrimMin > 0) { m_minPhys = RegionInfo.PhysPrimMin; } m_maxPhys = startupConfig.GetFloat("PhysicalPrimMax", m_maxPhys); if (RegionInfo.PhysPrimMax > 0) { m_maxPhys = RegionInfo.PhysPrimMax; } // Here, if clamping is requested in either global or // local config, it will be used // m_clampPrimSize = startupConfig.GetBoolean("ClampPrimSize", m_clampPrimSize); if (RegionInfo.ClampPrimSize) { m_clampPrimSize = true; } m_linksetCapacity = startupConfig.GetInt("LinksetPrims", m_linksetCapacity); if (RegionInfo.LinksetCapacity > 0) { m_linksetCapacity = RegionInfo.LinksetCapacity; } m_useTrashOnDelete = startupConfig.GetBoolean("UseTrashOnDelete", m_useTrashOnDelete); m_trustBinaries = startupConfig.GetBoolean("TrustBinaries", m_trustBinaries); m_allowScriptCrossings = startupConfig.GetBoolean("AllowScriptCrossing", m_allowScriptCrossings); m_dontPersistBefore = startupConfig.GetLong("MinimumTimeBeforePersistenceConsidered", DEFAULT_MIN_TIME_FOR_PERSISTENCE); m_dontPersistBefore *= 10000000; m_persistAfter = startupConfig.GetLong("MaximumTimeBeforePersistenceConsidered", DEFAULT_MAX_TIME_FOR_PERSISTENCE); m_persistAfter *= 10000000; m_defaultScriptEngine = startupConfig.GetString("DefaultScriptEngine", "XEngine"); SpawnPointRouting = startupConfig.GetString("SpawnPointRouting", "closest"); TelehubAllowLandmarks = startupConfig.GetBoolean("TelehubAllowLandmark", false); m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); string[] possibleMapConfigSections = new string[] { "Map", "Startup" }; m_generateMaptiles = Util.GetConfigVarFromSections<bool>(config, "GenerateMaptiles", possibleMapConfigSections, true); if (m_generateMaptiles) { int maptileRefresh = Util.GetConfigVarFromSections<int>(config, "MaptileRefresh", possibleMapConfigSections, 0); m_log.InfoFormat("[SCENE]: Region {0}, WORLD MAP refresh time set to {1} seconds", RegionInfo.RegionName, maptileRefresh); if (maptileRefresh != 0) { m_mapGenerationTimer.Interval = maptileRefresh * 1000; m_mapGenerationTimer.Elapsed += RegenerateMaptileAndReregister; m_mapGenerationTimer.AutoReset = true; m_mapGenerationTimer.Start(); } } else { string tile = Util.GetConfigVarFromSections<string>( config, "MaptileStaticUUID", possibleMapConfigSections, UUID.Zero.ToString()); UUID tileID; if (tile != UUID.Zero.ToString() && UUID.TryParse(tile, out tileID)) { RegionInfo.RegionSettings.TerrainImageID = tileID; } else { RegionInfo.RegionSettings.TerrainImageID = RegionInfo.MaptileStaticUUID; m_log.InfoFormat("[SCENE]: Region {0}, maptile set to {1}", RegionInfo.RegionName, RegionInfo.MaptileStaticUUID.ToString()); } } string[] possibleAccessControlConfigSections = new string[] { "AccessControl", "Startup" }; string grant = Util.GetConfigVarFromSections<string>( config, "AllowedClients", possibleAccessControlConfigSections, ""); if (grant.Length > 0) { foreach (string viewer in grant.Split('|')) { m_AllowedViewers.Add(viewer.Trim().ToLower()); } } grant = Util.GetConfigVarFromSections<string>( config, "BannedClients", possibleAccessControlConfigSections, ""); if (grant.Length > 0) { foreach (string viewer in grant.Split('|')) { m_BannedViewers.Add(viewer.Trim().ToLower()); } } MinFrameTime = startupConfig.GetFloat( "MinFrameTime", MinFrameTime); m_update_backup = startupConfig.GetInt( "UpdateStorageEveryNFrames", m_update_backup); m_update_coarse_locations = startupConfig.GetInt( "UpdateCoarseLocationsEveryNFrames", m_update_coarse_locations); m_update_entitymovement = startupConfig.GetInt( "UpdateEntityMovementEveryNFrames", m_update_entitymovement); m_update_events = startupConfig.GetInt( "UpdateEventsEveryNFrames", m_update_events); m_update_objects = startupConfig.GetInt( "UpdateObjectsEveryNFrames", m_update_objects); m_update_physics = startupConfig.GetInt( "UpdatePhysicsEveryNFrames", m_update_physics); m_update_presences = startupConfig.GetInt( "UpdateAgentsEveryNFrames", m_update_presences); m_update_terrain = startupConfig.GetInt( "UpdateTerrainEveryNFrames", m_update_terrain); m_update_temp_cleaning = startupConfig.GetInt( "UpdateTempCleaningEveryNFrames", m_update_temp_cleaning); } // FIXME: Ultimately this should be in a module. SendPeriodicAppearanceUpdates = true; IConfig appearanceConfig = m_config.Configs["Appearance"]; if (appearanceConfig != null) { SendPeriodicAppearanceUpdates = appearanceConfig.GetBoolean("ResendAppearanceUpdates", SendPeriodicAppearanceUpdates); } #endregion Region Config #region Interest Management IConfig interestConfig = m_config.Configs["InterestManagement"]; if (interestConfig != null) { string update_prioritization_scheme = interestConfig.GetString("UpdatePrioritizationScheme", "Time").Trim().ToLower(); try { UpdatePrioritizationScheme = (UpdatePrioritizationSchemes)Enum.Parse(typeof(UpdatePrioritizationSchemes), update_prioritization_scheme, true); } catch (Exception) { m_log.Warn("[PRIORITIZER]: UpdatePrioritizationScheme was not recognized, setting to default prioritizer Time"); UpdatePrioritizationScheme = UpdatePrioritizationSchemes.Time; } IsReprioritizationEnabled = interestConfig.GetBoolean("ReprioritizationEnabled", IsReprioritizationEnabled); ReprioritizationInterval = interestConfig.GetDouble("ReprioritizationInterval", ReprioritizationInterval); RootReprioritizationDistance = interestConfig.GetDouble("RootReprioritizationDistance", RootReprioritizationDistance); ChildReprioritizationDistance = interestConfig.GetDouble("ChildReprioritizationDistance", ChildReprioritizationDistance); RootTerseUpdatePeriod = interestConfig.GetInt("RootTerseUpdatePeriod", RootTerseUpdatePeriod); ChildTerseUpdatePeriod = interestConfig.GetInt("ChildTerseUpdatePeriod", ChildTerseUpdatePeriod); RootPositionUpdateTolerance = interestConfig.GetFloat("RootPositionUpdateTolerance", RootPositionUpdateTolerance); RootRotationUpdateTolerance = interestConfig.GetFloat("RootRotationUpdateTolerance", RootRotationUpdateTolerance); RootVelocityUpdateTolerance = interestConfig.GetFloat("RootVelocityUpdateTolerance", RootVelocityUpdateTolerance); } m_log.DebugFormat("[SCENE]: Using the {0} prioritization scheme", UpdatePrioritizationScheme); #endregion Interest Management StatsReporter = new SimStatsReporter(this); StatsReporter.OnSendStatsResult += SendSimStatsPackets; StatsReporter.OnStatsIncorrect += m_sceneGraph.RecalculateStats; }
public void InitializePhysics() { engine = new PhysicsEngine("MetaliPhysics"); scene = engine.Factory.PhysicsSceneManager.Create("Scene"); scene.TimeOfSimulation = 0.016f; }
public BSTerrainManager(BSScene physicsScene) { PhysicsScene = physicsScene; m_heightMaps = new Dictionary<Vector2,BulletHeightMapInfo>(); m_terrainModified = false; // Assume one region of default size m_worldOffset = Vector3.Zero; m_worldMax = new Vector3(DefaultRegionSize); MegaRegionParentPhysicsScene = null; }
// Unhook all the combining that I know about. public void UnCombine(PhysicsScene pScene) { // Just like ODE, for the moment a NOP DetailLog("{0},BSTerrainManager.UnCombine", BSScene.DetailLogZero); }
void MainPhysicsScene_PostStep( PhysicsScene scene ) { if( resetYCoordinateForDynamicBodies ) DoResetYCoordinateForDynamicBodies(); }
public static void CreateShapes(Demo demo, PhysicsScene scene) { }
public void Create() { string sceneInstanceIndexName = name + instanceIndexName; if (demo.Engine.Factory.PhysicsSceneManager.Find(sceneInstanceIndexName) != null) { return; } scene = demo.Engine.Factory.PhysicsSceneManager.Create(sceneInstanceIndexName); // Initialize maximum number of solver iterations for the scene scene.MaxIterationCount = 10; // Initialize time of simulation for the scene scene.TimeOfSimulation = 1.0f / 15.0f; Initialize(); // Initialize objects in the scene skyInstance1.Initialize(scene); cursorInstance.Initialize(scene); shotInstance.Initialize(scene); columnInstance1.Initialize(scene); triangleMesh1.Initialize(scene); triangleMesh2.Initialize(scene); torusMesh.Initialize(scene); camera2Instance1.Initialize(scene); lightInstance.Initialize(scene); // Initialize controllers in the scene skyDraw1Instance1.Initialize(scene); cursorDraw1Instance.Initialize(scene); camera2Animation1Instance1.Initialize(scene); camera2Draw1Instance1.Initialize(scene); // Create shapes shared for all physics objects in the scene // These shapes are used by all objects in the scene Demo.CreateSharedShapes(demo, scene); // Create shapes for objects in the scene Sky.CreateShapes(demo, scene); Cursor.CreateShapes(demo, scene); Shot.CreateShapes(demo, scene); Column.CreateShapes(demo, scene); TriangleMesh1.CreateShapes(demo, scene); TriangleMesh2.CreateShapes(demo, scene); TorusMesh.CreateShapes(demo, scene); Camera2.CreateShapes(demo, scene); Lights.CreateShapes(demo, scene); // Create physics objects for objects in the scene skyInstance1.Create(new Vector3(0.0f, 0.0f, 0.0f)); cursorInstance.Create(); shotInstance.Create(); columnInstance1.Create(new Vector3(-500.0f, -20.0f, 1000.0f), Vector3.One, Quaternion.Identity, "Box", 4, new Vector3(8.0f, 8.0f, 8.0f), 1.0f, true, 0.1f, 0.05f); triangleMesh1.Create(new Vector3(0.0f, 60.0f, 0.0f), Vector3.One, Quaternion.Identity, 0.0f); triangleMesh2.Create(new Vector3(0.0f, 60.0f, 0.0f), Vector3.One, Quaternion.Identity, 0.0f); torusMesh.Create(new Vector3(-550.0f, -20.0f, 1000.0f), Vector3.One, Quaternion.Identity, 100000.0f); camera2Instance1.Create(new Vector3(-550.0f, -90.0f, 1020.0f), Quaternion.Identity, Quaternion.FromAxisAngle(Vector3.UnitY, MathHelper.DegreesToRadians(-95.0f)), Quaternion.Identity, true); lightInstance.CreateLightPoint(0, "Glass", new Vector3(-530.0f, -106.0f, 1020.0f), new Vector3(1.0f, 0.7f, 0.0f), 20.0f, 1.0f); lightInstance.CreateLightPoint(1, "Glass", new Vector3(-500.0f, -116.0f, 1040.0f), new Vector3(0.5f, 0.7f, 0.1f), 20.0f, 1.0f); lightInstance.CreateLightPoint(2, "Glass", new Vector3(-470.0f, -124.0f, 1040.0f), new Vector3(1.0f, 0.7f, 0.0f), 20.0f, 1.0f); lightInstance.CreateLightPoint(3, "Glass", new Vector3(45.0f, -275.0f, 380.0f), new Vector3(1.0f, 0.7f, 0.5f), 20.0f, 1.0f); lightInstance.CreateLightPoint(4, "Glass", new Vector3(0.0f, -100.0f, 0.0f), new Vector3(1.0f, 1.0f, 0.5f), 20.0f, 1.0f); lightInstance.CreateLightPoint(5, "Glass", new Vector3(-470.0f, -124.0f, 1020.0f), new Vector3(0.3f, 0.7f, 0.5f), 20.0f, 1.0f); lightInstance.CreateLightSpot(0, "Glass", new Vector3(-530.0f, -104.0f, 1000.0f), new Vector3(0.1f, 0.7f, 1.0f), 20.0f, 1.0f); lightInstance.CreateLightSpot(1, "Glass", new Vector3(-500.0f, -114.0f, 1020.0f), new Vector3(1.0f, 0.5f, 0.2f), 20.0f, 1.0f); lightInstance.CreateLightSpot(2, "Glass", new Vector3(-470.0f, -124.0f, 1000.0f), new Vector3(0.5f, 1.0f, 0.2f), 20.0f, 1.0f); // Set controllers for objects in the scene SetControllers(); }
// Create an OpenSimulator Scene and add enough auxillery services and objects // to it so it will allow the loading of assets. public Scene CreateScene(IAssetService memAssetService, string regionName) { var estateSettings = new EstateSettings { EstateOwner = OMV.UUID.Random() }; RegionInfo regionInfo = new RegionInfo(0, 0, null, regionName) { RegionName = regionName, RegionSizeX = Constants.RegionSize, RegionSizeY = Constants.RegionSize, RegionID = OMV.UUID.Random(), EstateSettings = estateSettings }; Scene scene = new Scene(regionInfo); // Add an in-memory asset service for all the loaded assets to go into scene.RegisterModuleInterface <IAssetService>(memAssetService); ISimulationDataService simulationDataService = new NullDataService(); scene.RegisterModuleInterface <ISimulationDataService>(simulationDataService); IRegionSerialiserModule serializerModule = new SerialiserModule(); scene.RegisterModuleInterface <IRegionSerialiserModule>(serializerModule); IUserAccountService userAccountService = new NullUserAccountService(); scene.RegisterModuleInterface <IUserAccountService>(userAccountService); PhysicsScene physScene = CreateSimplePhysicsEngine(); ((INonSharedRegionModule)physScene).AddRegion(scene); ((INonSharedRegionModule)physScene).RegionLoaded(scene); scene.PhysicsScene = physScene; scene.LandChannel = new TestLandChannel(scene); // simple land with no parcels Nini.Config.IConfigSource config = new Nini.Config.IniConfigSource(); config.AddConfig("Terrain"); config.Configs["Terrain"].Set("InitialTerrain", "flat"); var terrainModule = new TerrainModule(); try { terrainModule.Initialise(config); terrainModule.AddRegion(scene); } catch (ReflectionTypeLoadException e) { // The terrain module loads terrain brushes and they might not all have been included StringBuilder sb = new StringBuilder(); foreach (Exception exSub in e.LoaderExceptions) { sb.AppendLine(exSub.Message); if (exSub is FileNotFoundException exFileNotFound) { if (!string.IsNullOrEmpty(exFileNotFound.FusionLog)) { sb.AppendLine("Fusion Log:"); sb.AppendLine(exFileNotFound.FusionLog); } } sb.AppendLine(); } string errorMessage = sb.ToString(); _log.Error("BConverterOS.CreateScene: exception adding region:"); _log.Error(errorMessage); } catch (Exception e) { _log.Error("BConverterOS.CreateScene: exception adding region: {0}", e); } SceneManager.Instance.Add(scene); return(scene); }
/////////////////////////////////////////// public ODEBody( PhysicsScene scene ) : base( scene ) { this.scene = (ODEPhysicsScene)scene; }
void Transport(SimulateMethodArgs args) { PhysicsScene scene = demo.Engine.Factory.PhysicsSceneManager.Get(args.OwnerSceneIndex); PhysicsObject objectBase = scene.Factory.PhysicsObjectManager.Get(args.OwnerIndex); float time = args.Time; if (panelButton != null) { if ((constraint1 != null) && (constraint2 != null) && (constraint3 != null) && (body != null) && (panel != null) && !constraint1.IsBroken && !constraint2.IsBroken && !constraint3.IsBroken && !body.IsBrokenRigidGroup && !panel.IsBrokenRigidGroup) { if (enableRun) { panelButton.Material.SetAmbient(0.7f, 0.4f, 0.4f); panelButton.Material.SetDiffuse(1.0f, 0.4f, 0.4f); if ((panelLight != null) && (panelLight.Light != null)) { panelLight.Light.SetDiffuse(1.0f, 0.2f, 0.2f); frameCount = (frameCount + 1) % maxFrameCount; if (frameCount == 0) { flipLight = !flipLight; } if (flipLight) { panelLight.Light.Intensity = 1.0f; } else { panelLight.Light.Intensity = 0.2f; } } } else { panelButton.Material.SetAmbient(0.4f, 0.7f, 0.4f); panelButton.Material.SetDiffuse(0.4f, 1.0f, 0.4f); if ((panelLight != null) && (panelLight.Light != null)) { panelLight.Light.SetDiffuse(0.2f, 1.0f, 0.2f); panelLight.Light.Intensity = 1.0f; } } } else { panelButton.Material.SetAmbient(0.4f, 0.7f, 0.4f); panelButton.Material.SetDiffuse(0.4f, 1.0f, 0.4f); if ((panelLight != null) && (panelLight.Light != null)) { panelLight.Light.Enabled = false; } } } if (!enableRun) { return; } if ((constraint2 == null) || (constraint3 == null) || (body == null) || constraint2.IsBroken || constraint3.IsBroken || body.IsBrokenRigidGroup) { return; } if (!flipRotation) { if ((constraint3.ControlDistanceY < constraint3.MaxLimitDistanceY) && (constraint2.ControlDegAngleY <= 0.0)) { constraint3.ControlDistanceY += distanceSpeed; } if ((constraint3.ControlDistanceY > constraint3.MinLimitDistanceY) && (constraint2.ControlDegAngleY >= maxAngle)) { constraint3.ControlDistanceY -= distanceSpeed; } if ((constraint2.ControlDegAngleY < maxAngle) && (constraint3.ControlDistanceY >= constraint3.MaxLimitDistanceY)) { constraint2.ControlDegAngleY += rotationSpeed; } if (constraint3.ControlDistanceY <= constraint3.MinLimitDistanceY) { enableRun = false; } } else { if ((constraint3.ControlDistanceY < constraint3.MaxLimitDistanceY) && (constraint2.ControlDegAngleY >= maxAngle)) { constraint3.ControlDistanceY += distanceSpeed; } if ((constraint3.ControlDistanceY > constraint3.MinLimitDistanceY) && (constraint2.ControlDegAngleY <= 0.0f)) { constraint3.ControlDistanceY -= distanceSpeed; } if ((constraint2.ControlDegAngleY > 0.0f) && (constraint3.ControlDistanceY >= constraint3.MaxLimitDistanceY)) { constraint2.ControlDegAngleY -= rotationSpeed; } if (constraint3.ControlDistanceY <= constraint3.MinLimitDistanceY) { enableRun = false; } } }
protected override void OnDestroyScene( PhysicsScene scene ) { PhysXPhysicsScene scene2 = (PhysXPhysicsScene)scene; scene2.Destroy(); }
public void Initialize(PhysicsScene scene) { this.scene = scene; }
public Scene(RegionInfo regInfo, PhysicsScene physicsScene) : base(regInfo) { m_sceneGraph = new SceneGraph(this); m_sceneGraph.PhysicsScene = physicsScene; // If the scene graph has an Unrecoverable error, restart this sim. // Currently the only thing that causes it to happen is two kinds of specific // Physics based crashes. // // Out of memory // Operating system has killed the plugin m_sceneGraph.UnRecoverableError += () => { m_log.ErrorFormat("[SCENE]: Restarting region {0} due to unrecoverable physics crash", Name); RestartNow(); }; PhysicalPrims = true; CollidablePrims = true; PhysicsEnabled = true; PeriodicBackup = true; UseBackup = true; IsReprioritizationEnabled = true; UpdatePrioritizationScheme = UpdatePrioritizationSchemes.Time; ReprioritizationInterval = 5000; RootRotationUpdateTolerance = 0.1f; RootVelocityUpdateTolerance = 0.001f; RootPositionUpdateTolerance = 0.05f; RootReprioritizationDistance = 10.0; ChildReprioritizationDistance = 20.0; m_eventManager = new EventManager(); m_permissions = new ScenePermissions(this); }
void MainScene_PostStep( PhysicsScene scene ) { if( mainBody != null && !mainBody.Sleeping ) UpdateRotation( false ); }
public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {}
// This call says I am a child to region zero in a mega-region. 'pScene' is that // of region zero, 'offset' is my offset from regions zero's origin, and // 'extents' is the largest XY that is handled in my region. public override void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) { TerrainManager.Combine(pScene, offset, extents); }
public override void UnCombine(PhysicsScene pScene) { IntPtr localGround = IntPtr.Zero; // float[] localHeightfield; bool proceed = false; List<IntPtr> geomDestroyList = new List<IntPtr>(); lock (OdeLock) { if (RegionTerrain.TryGetValue(Vector3.Zero, out localGround)) { foreach (IntPtr geom in TerrainHeightFieldHeights.Keys) { if (geom == localGround) { // localHeightfield = TerrainHeightFieldHeights[geom]; proceed = true; } else { geomDestroyList.Add(geom); } } if (proceed) { m_worldOffset = Vector3.Zero; WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); m_parentScene = null; foreach (IntPtr g in geomDestroyList) { // removingHeightField needs to be done or the garbage collector will // collect the terrain data before we tell ODE to destroy it causing // memory corruption if (TerrainHeightFieldHeights.ContainsKey(g)) { // float[] removingHeightField = TerrainHeightFieldHeights[g]; TerrainHeightFieldHeights.Remove(g); if (RegionTerrain.ContainsKey(g)) { RegionTerrain.Remove(g); } d.GeomDestroy(g); //removingHeightField = new float[0]; } } } else { m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data."); } } } }
static bool GetNearestHitFromPhysicsScene(Ray ray, PhysicsScene physicsScene, int cullingMask, bool ignorePrefabInstance, ref RaycastHit raycastHit) { float maxDist = raycastHit.distance; int numHits = physicsScene.Raycast(ray.origin, ray.direction, s_RaySnapHits, maxDist, cullingMask, QueryTriggerInteraction.Ignore); // We are not sure at this point if the hits returned from RaycastAll are sorted or not, so go through them all float nearestHitDist = maxDist; int nearestHitIndex = -1; if (ignoreRaySnapObjects != null) { for (int i = 0; i < numHits; i++) { if (s_RaySnapHits[i].distance < nearestHitDist) { Transform tr = s_RaySnapHits[i].transform; if (ignorePrefabInstance && GameObjectUtility.IsPrefabInstanceHiddenForInContextEditing(tr.gameObject)) { continue; } bool ignore = false; for (int j = 0; j < ignoreRaySnapObjects.Length; j++) { if (tr == ignoreRaySnapObjects[j]) { ignore = true; break; } } if (ignore) { continue; } nearestHitDist = s_RaySnapHits[i].distance; nearestHitIndex = i; } } } else { for (int i = 0; i < numHits; i++) { if (s_RaySnapHits[i].distance < nearestHitDist) { nearestHitDist = s_RaySnapHits[i].distance; nearestHitIndex = i; } } } if (nearestHitIndex >= 0) { raycastHit = s_RaySnapHits[nearestHitIndex]; return(true); } else { return(false); } }
protected override void OnCreateScene( Mesh[] meshes, MeshObject[] meshObjects, Light[] lights, ColorValue shadowColor, bool calculateShadows ) { //create separated physics scene physicsScene = PhysicsWorld.Instance.CreateScene( "Static Lighting" ); //initialize contact group physicsScene.SpecialContactGroupsEnabled = true; physicsScene.SetupSpecialContactGroups( 1, 1, true ); Dictionary<Mesh, string> meshPhysicsMeshNames = new Dictionary<Mesh, string>(); //register physics custom mesh names foreach( Mesh mesh in meshes ) { string customMeshName = PhysicsWorld.Instance.AddCustomMeshGeometry( mesh.Positions, mesh.Indices, null, MeshShape.MeshTypes.TriangleMesh, 0, 0 ); meshPhysicsMeshNames.Add( mesh, customMeshName ); } //create bodies foreach( MeshObject meshObject in meshObjects ) { Body body = physicsScene.CreateBody(); body.Static = true; body.Position = meshObject.Position; body.Rotation = meshObject.Rotation; body.UserData = meshObject; MeshShape shape = body.CreateMeshShape(); shape.ContactGroup = contactGroup; shape.MeshName = meshPhysicsMeshNames[ meshObject.Mesh ]; shape.MeshScale = meshObject.Scale; body.PushedToWorld = true; } //lights { this.lights = new MyLight[ lights.Length ]; for( int n = 0; n < lights.Length; n++ ) { Light light = lights[ n ]; MyLight myLight = null; PointLight pointLight = light as PointLight; if( pointLight != null ) myLight = new MyPointLight( pointLight ); SpotLight spotLight = light as SpotLight; if( spotLight != null ) myLight = new MySpotLight( spotLight ); DirectionalLight directionalLight = light as DirectionalLight; if( directionalLight != null ) myLight = new MyDirectionalLight( directionalLight ); if( myLight == null ) Log.Fatal( "SimpleStaticLightingCalculationWorld.OnCreateScene: not implemented light type." ); this.lights[ n ] = myLight; this.lights[ n ].Initialize(); } } this.shadowColor = shadowColor; this.calculateShadows = calculateShadows; }
// Tell the object to clean up. public virtual void Destroy() { PhysicalActors.Enable(false); PhysicsScene.TaintedObject("BSPhysObject.Destroy", delegate() { PhysicalActors.Dispose(); }); }
protected override void OnDestroyScene() { if( physicsScene != null ) { List<Body> bodies = new List<Body>( physicsScene.Bodies ); foreach( Body body in bodies ) body.Dispose(); PhysicsWorld.Instance.DestroyNotUsedMeshGeometries(); physicsScene.Dispose(); physicsScene = null; } lights = null; }
public virtual void AddPhysicsStats(UUID RegionID, PhysicsScene scene) { lock (m_currentPhysicsStats) { PhysicsStats stats; if (!m_currentPhysicsStats.TryGetValue(RegionID, out stats)) { stats = new PhysicsStats(); stats.StatAvatarUpdatePosAndVelocity = scene.StatAvatarUpdatePosAndVelocity; stats.StatCollisionOptimizedTime = scene.StatCollisionOptimizedTime; stats.StatPhysicsMoveTime = scene.StatPhysicsMoveTime; stats.StatPhysicsTaintTime = scene.StatPhysicsTaintTime; stats.StatPrimUpdatePosAndVelocity = scene.StatPrimUpdatePosAndVelocity; stats.StatSendCollisionsTime = scene.StatSendCollisionsTime; stats.StatUnlockedArea = scene.StatUnlockedArea; stats.StatFindContactsTime = scene.StatFindContactsTime; stats.StatContactLoopTime = scene.StatContactLoopTime; stats.StatCollisionAccountingTime = scene.StatCollisionAccountingTime; } else { stats.StatAvatarUpdatePosAndVelocity += scene.StatAvatarUpdatePosAndVelocity; stats.StatCollisionOptimizedTime += scene.StatCollisionOptimizedTime; stats.StatPhysicsMoveTime += scene.StatPhysicsMoveTime; stats.StatPhysicsTaintTime += scene.StatPhysicsTaintTime; stats.StatPrimUpdatePosAndVelocity += scene.StatPrimUpdatePosAndVelocity; stats.StatSendCollisionsTime += scene.StatSendCollisionsTime; stats.StatUnlockedArea += scene.StatUnlockedArea; stats.StatFindContactsTime += scene.StatFindContactsTime; stats.StatContactLoopTime += scene.StatContactLoopTime; stats.StatCollisionAccountingTime += scene.StatCollisionAccountingTime; } m_currentPhysicsStats[RegionID] = stats; PhysicsStats ProfilerStats = new PhysicsStats(); ProfilerStats.StatAvatarUpdatePosAndVelocity = scene.StatAvatarUpdatePosAndVelocity; ProfilerStats.StatCollisionOptimizedTime = scene.StatCollisionOptimizedTime; ProfilerStats.StatPhysicsMoveTime = scene.StatPhysicsMoveTime; ProfilerStats.StatPhysicsTaintTime = scene.StatPhysicsTaintTime; ProfilerStats.StatPrimUpdatePosAndVelocity = scene.StatPrimUpdatePosAndVelocity; ProfilerStats.StatSendCollisionsTime = scene.StatSendCollisionsTime; ProfilerStats.StatUnlockedArea = scene.StatUnlockedArea; ProfilerStats.StatFindContactsTime = scene.StatFindContactsTime; ProfilerStats.StatContactLoopTime = scene.StatContactLoopTime; ProfilerStats.StatCollisionAccountingTime = scene.StatCollisionAccountingTime; //Add the stats to the profiler Profiler p = ProfilerManager.GetProfiler(); p.AddStat("CurrentStatAvatarUpdatePosAndVelocity " + RegionID, ProfilerStats.StatAvatarUpdatePosAndVelocity); p.AddStat("CurrentStatCollisionOptimizedTime " + RegionID, ProfilerStats.StatCollisionOptimizedTime); p.AddStat("CurrentStatPhysicsMoveTime " + RegionID, ProfilerStats.StatPhysicsMoveTime); p.AddStat("CurrentStatPhysicsTaintTime " + RegionID, ProfilerStats.StatPhysicsTaintTime); p.AddStat("CurrentStatPrimUpdatePosAndVelocity " + RegionID, ProfilerStats.StatPrimUpdatePosAndVelocity); p.AddStat("CurrentStatSendCollisionsTime " + RegionID, ProfilerStats.StatSendCollisionsTime); p.AddStat("CurrentStatUnlockedArea " + RegionID, ProfilerStats.StatUnlockedArea); p.AddStat("CurrentStatFindContactsTime " + RegionID, ProfilerStats.StatFindContactsTime); p.AddStat("CurrentStatContactLoopTime " + RegionID, ProfilerStats.StatContactLoopTime); p.AddStat("CurrentStatCollisionAccountingTime " + RegionID, ProfilerStats.StatCollisionAccountingTime); } }
public virtual void UnCombine(PhysicsScene pScene) {}
public BSTerrainManager(BSScene physicsScene) { PhysicsScene = physicsScene; m_terrains = new Dictionary<Vector3,BSTerrainPhys>(); // Assume one region of default size m_worldOffset = Vector3.Zero; m_worldMax = new Vector3(DefaultRegionSize); MegaRegionParentPhysicsScene = null; }
// Unhook all the combining that I know about. public override void UnCombine(PhysicsScene pScene) { TerrainManager.UnCombine(pScene); }