protected override bool Initialize() { GetOrCreateSimulation(); m_stepForwardTimer = new agx.Timer(); return(base.Initialize()); }
/// <summary> /// Engage the clutch so that the connection between the engine and the gear box is active /// </summary> public void engageClutch() { if (m_clutchEngaged) { return; } m_clutchTimer = new agx.Timer(true); m_clutch.setEfficiency(0.0); }
private void PreStepForward() { bool savePreFirstTimeStep = Application.isEditor && SavePreFirstStep && SavePreFirstStepPath != string.Empty && m_simulation.getTimeStamp() == 0.0; if (savePreFirstTimeStep) { var saveSuccess = SaveToNativeFile(SavePreFirstStepPath); if (saveSuccess) { Debug.Log(Utils.GUI.AddColorTag("Successfully wrote initial state to: ", Color.green) + new FileInfo(SavePreFirstStepPath).FullName); } } agx.Timer timer = null; if (DisplayStatistics) { timer = new agx.Timer(true); } if (TrackMemoryAllocations) { MemoryAllocations.Snap(MemoryAllocations.Section.Begin); } if (StepCallbacks.PreStepForward != null) { StepCallbacks.PreStepForward.Invoke(); } if (TrackMemoryAllocations) { MemoryAllocations.Snap(MemoryAllocations.Section.PreStepForward); } if (StepCallbacks.PreSynchronizeTransforms != null) { StepCallbacks.PreSynchronizeTransforms.Invoke(); } if (TrackMemoryAllocations) { MemoryAllocations.Snap(MemoryAllocations.Section.PreSynchronizeTransforms); } if (timer != null) { timer.stop(); } }
/// <summary> /// Animate the engagement of the clutch between 0..1 over some time /// </summary> public void update() { m_brakes.update(); if (m_clutchTimer != null) { m_clutchEngaged = true; // Interpolate the clutch value from 0 to 1 var now = m_clutchTimer.getTime(); float t = (float)(now / 1000.0f / m_clutchDuration); var value = UnityEngine.Mathf.Lerp(0, 1, t); m_clutch.setEfficiency(value); Debug.Log(string.Format("Clutch {0}", value)); if (t >= 1.0f) { m_clutchTimer = null; } } }
private void PostStepForward() { agx.Timer timer = null; if (DisplayStatistics) { timer = new agx.Timer(true); } if (TrackMemoryAllocations) { MemoryAllocations.Snap(MemoryAllocations.Section.StepForward); } if (StepCallbacks.PostSynchronizeTransforms != null) { StepCallbacks.PostSynchronizeTransforms.Invoke(); } if (TrackMemoryAllocations) { MemoryAllocations.Snap(MemoryAllocations.Section.PostSynchronizeTransforms); } if (StepCallbacks.PostStepForward != null) { StepCallbacks.PostStepForward.Invoke(); } if (TrackMemoryAllocations) { MemoryAllocations.Snap(MemoryAllocations.Section.PostStepForward); } Rendering.DebugRenderManager.OnActiveSimulationPostStep(m_simulation); if (timer != null) { timer.stop(); m_statisticsWindowData.ManagedStepForward = Convert.ToSingle(timer.getTime()); } }
/// <summary> /// Reads and instantiates URDF file at given <paramref name="urdfFilePath"/>. If /// <paramref name="resourceLoader"/> is null, the default resource loader is used. /// In case of errors, the error is printed in the Console and null is returned. /// </summary> /// <see cref="CreateDefaultResourceLoader(string)"/> /// <param name="urdfFilePath">Path and filename to the URDF file to instantiate.</param> /// <param name="resourceLoader">Resource loader callback - default is used if null.</param> /// <param name="silent">True to print progress into the Console. Default: true, silent.</param> /// <returns>Game object instance if successful, otherwise null.</returns> public static GameObject Instantiate(string urdfFilePath, Func <string, AGXUnity.IO.URDF.Model.ResourceType, GameObject> resourceLoader = null, bool silent = true) { GameObject instance = null; agx.Timer timer = null; var pColor = InspectorGUISkin.BrandColorBlue; try { if (!silent) { Debug.Log($"Reading URDF: '{AddColor( urdfFilePath, pColor )}'..."); timer = new agx.Timer(true); } // Reading model, will throw if anything goes wrong. var model = AGXUnity.IO.URDF.Model.Read(urdfFilePath); if (!silent) { Debug.Log($"Successfully read " + $"{AddColor( $"{model.Links.Count()} links", pColor )}, " + $"{AddColor( $"{model.Joints.Count()} joints", pColor )} and " + $"{AddColor( $"{model.Materials.Count()} materials", pColor )} in " + $"{AddColor( timer.getTime().ToString("0.00"), pColor )} ms."); } // Open "select folder" panel if the model requires resources // and no resource loader callback is provided. var dataDirectory = string.Empty; if (resourceLoader == null && model.RequiresResourceLoader) { var resourcePath = model.RequiredResources.First(); var sugestedDirectory = System.IO.Path.GetDirectoryName(urdfFilePath).Replace('\\', '/'); var packageRootFound = false; // Finding package root directory. if (resourcePath.StartsWith("package://")) { resourcePath = resourcePath.Substring("package://".Length); try { var files = (from filename in System.IO.Directory.GetFiles("Assets", System.IO.Path.GetFileName(resourcePath), System.IO.SearchOption.AllDirectories) select filename.Replace('\\', '/')).ToArray(); var numFound = 0; foreach (var file in files) { var startIndex = file.IndexOf(resourcePath); if (startIndex >= 0) { // Selecting first found if many as sugestedDirectory for folder panel. if (numFound == 0) { sugestedDirectory = file.Substring(0, startIndex - 1); } ++numFound; } } packageRootFound = numFound == 1; } catch (System.IO.IOException) { } } // Assuming path is relative to the URDF file. else { packageRootFound = System.IO.File.Exists(sugestedDirectory + '/' + resourcePath); } if (packageRootFound) { dataDirectory = sugestedDirectory; } else { dataDirectory = EditorUtility.OpenFolderPanel($"Select '{urdfFilePath}' root data folder.", sugestedDirectory, ""); if (!string.IsNullOrEmpty(dataDirectory)) { dataDirectory = Utils.MakeRelative(dataDirectory, Application.dataPath); } } if (!AssetDatabase.IsValidFolder(dataDirectory)) { Debug.LogWarning($"Unable to find given '{dataDirectory}' in the project Assets folder."); dataDirectory = string.Empty; } else if (!silent) { Debug.Log($"Using data directory: '{AddColor( dataDirectory, pColor )}'."); } } if (!silent) { timer.reset(true); } // Instantiating the model, will throw if anything goes wrong. using (new AGXUnityEditor.Utils.UndoCollapseBlock($"Instantiating model {model.Name}")) instance = model.Instantiate(resourceLoader ?? CreateDefaultResourceLoader(dataDirectory), obj => Undo.RegisterCreatedObjectUndo(obj, $"Created: {obj.name}")); if (!silent) { Debug.Log($"Successfully instantiated URDF robot: '{AddColor( instance.name, pColor )}' in " + $"{AddColor( timer.getTime().ToString( "0.00" ), pColor )} ms."); } } catch (System.Xml.XmlException e) { Debug.LogException(e); return(null); } return(instance); }
protected void FixedUpdate() { if (!NativeHandler.Instance.HasValidLicense) { return; } if (m_simulation != null) { bool savePreFirstTimeStep = Application.isEditor && SavePreFirstStep && SavePreFirstStepPath != string.Empty && m_simulation.getTimeStamp() == 0.0; if (savePreFirstTimeStep) { var saveSuccess = SaveToNativeFile(SavePreFirstStepPath); if (saveSuccess) { Debug.Log("Successfully wrote initial state to: " + SavePreFirstStepPath); } } agx.Timer timer = null; if (DisplayStatistics) { timer = new agx.Timer(true); } MemoryAllocations.Snap(MemoryAllocations.Section.Begin); StepCallbacks.PreStepForward?.Invoke(); MemoryAllocations.Snap(MemoryAllocations.Section.PreStepForward); StepCallbacks.PreSynchronizeTransforms?.Invoke(); MemoryAllocations.Snap(MemoryAllocations.Section.PreSynchronizeTransforms); if (timer != null) { timer.stop(); } m_simulation.stepForward(); if (timer != null) { timer.start(); } MemoryAllocations.Snap(MemoryAllocations.Section.StepForward); StepCallbacks.PostSynchronizeTransforms?.Invoke(); MemoryAllocations.Snap(MemoryAllocations.Section.PostSynchronizeTransforms); StepCallbacks.PostStepForward?.Invoke(); MemoryAllocations.Snap(MemoryAllocations.Section.PostStepForward); Rendering.DebugRenderManager.OnActiveSimulationPostStep(m_simulation); if (timer != null) { timer.stop(); m_statisticsWindowData.ManagedStepForward = Convert.ToSingle(timer.getTime()); } } }
public TimerBlock(string name) { Name = name; Native = new agx.Timer(true); }