/// <summary> /// Save current simulation/scene to an AGX native file (.agx or .aagx). /// </summary> /// <param name="filename">Filename including path.</param> /// <returns>True if objects were written to file - otherwise false.</returns> public bool SaveToNativeFile(string filename) { if (m_simulation == null) { Debug.LogWarning(Utils.GUI.AddColorTag($"Unable to write {filename}: Simulation isn't active.", Color.yellow), this); return(false); } FileInfo file = new FileInfo(filename); if (!file.Directory.Exists) { Debug.LogWarning(Utils.GUI.AddColorTag($"Unable to write {filename}: Directory doesn't exist.", Color.yellow)); return(false); } if (file.Extension.ToUpper() != ".AGX" && file.Extension.ToUpper() != ".AAGX") { Debug.LogWarning(Utils.GUI.AddColorTag($"Unable to write {filename}: File extension {file.Extension} is unknown. ", Color.yellow) + "Valid extensions are .agx and .aagx."); return(false); } uint numObjects = m_simulation.write(file.FullName); return(numObjects > 0); }
/// <summary> /// Save current simulation/scene to an AGX native file (.agx or .aagx). /// </summary> /// <param name="filename">Filename including path.</param> /// <returns>True if objects were written to file - otherwise false.</returns> public bool SaveToNativeFile(string filename) { if (m_simulation == null) { Debug.LogWarning("Simulation isn't active - ignoring save scene to file: " + filename); return(false); } uint numObjects = m_simulation.write(filename); return(numObjects > 0); }
public void OpenInAgXViewer() { if (m_simulation == null) { Debug.Log("Unable to open simulation in native viewer.\nEditor has to be in play mode (or paused)."); return; } string path = Application.dataPath + @"/AgXUnity/Resources/"; string tmpFilename = "openedInViewer.agx"; string tmpLuaFilename = "openedInViewer.agxLua"; var cameraData = new { Eye = Camera.main.transform.position.ToHandedVec3().ToVector3(), Center = (Camera.main.transform.position + 25.0f * Camera.main.transform.forward).ToHandedVec3().ToVector3(), Up = Camera.main.transform.up.ToHandedVec3().ToVector3(), NearClippingPlane = Camera.main.nearClipPlane, FarClippingPlane = Camera.main.farClipPlane, FOV = Camera.main.fieldOfView }; string luaFileContent = @" assert( requestPlugin( ""agxOSG"" ) ) if not alreadyInitialized then alreadyInitialized = true local app = agxOSG.ExampleApplication() _G[ ""buildScene"" ] = function( sim, app, root ) assert( agxOSG.readFile( """ + path + tmpFilename + @""", sim, root ) ) local cameraData = app:getCameraData() cameraData.eye = agx.Vec3( " + cameraData.Eye.x + ", " + cameraData.Eye.y + ", " + cameraData.Eye.z + @" ) cameraData.center = agx.Vec3( " + cameraData.Center.x + ", " + cameraData.Center.y + ", " + cameraData.Center.z + @" ) cameraData.up = agx.Vec3( " + cameraData.Up.x + ", " + cameraData.Up.y + ", " + cameraData.Up.z + @" ) cameraData.nearClippingPlane = " + cameraData.NearClippingPlane + @" cameraData.farClippingPlane = " + cameraData.FarClippingPlane + @" cameraData.fieldOfView = " + cameraData.FOV + @" app:applyCameraData( cameraData ) return root end app:addScene( arg[ 0 ], ""buildScene"", string.byte( ""1"" ) ) local argParser = agxIO.ArgumentParser() argParser:readArguments( arg ) if app:init( argParser ) then app:run() end end"; uint numObjects = m_simulation.write(path + tmpFilename); if (numObjects == 0) { Debug.Log("Unable to start viewer.", this); return; } System.IO.File.WriteAllText(path + tmpLuaFilename, luaFileContent); System.Diagnostics.Process.Start("luaagx.exe", path + tmpLuaFilename + " -p --renderDebug 1"); }