private agxSDK.Simulation GetOrCreateSimulation() { if (m_simulation == null) { NativeHandler.Instance.MakeMainThread(); m_simulation = new agxSDK.Simulation(); m_space = m_simulation.getSpace(); m_system = m_simulation.getDynamicsSystem(); // Since AGXUnity.Simulation is optional in the hierarchy // we have to synchronize fixedDeltaTime here if SimulationTool // never has been seen in the inspector. if (AutoSteppingMode == AutoSteppingModes.FixedUpdate) { TimeStep = Time.fixedDeltaTime; } // Solver settings will assign number of threads. if (m_solverSettings != null) { m_solverSettings.SetSimulation(m_simulation); m_solverSettings.GetInitialized <SolverSettings>(); } // No solver settings - set the default. else { agx.agxSWIG.setNumThreads(Convert.ToUInt32(SolverSettings.DefaultNumberOfThreads)); } StepCallbacks.OnInitialize(m_simulation); } return(m_simulation); }
/// <summary> /// Construct given AGX file info. /// </summary> /// <param name="info">AGX file info.</param> public InputAGXFile(AGXFileInfo info) { if (info == null) { throw new ArgumentNullException("info", "File info object is null."); } else { FileInfo = info; } if (!FileInfo.Exists) { throw new FileNotFoundException("File not found: " + FileInfo.FullName); } if (FileInfo.Type == AGXFileInfo.FileType.Unknown || FileInfo.Type == AGXFileInfo.FileType.AGXPrefab) { throw new AGXUnity.Exception("Unsupported file format: " + FileInfo.FullName); } Successful = false; // Making sure AGX has been initialized before we create a simulation. var nativeHandler = NativeHandler.Instance; Simulation = new agxSDK.Simulation(); }
public static void Start(double dt) { agx.agxSWIG.init(); sim_Instance = new agxSDK.Simulation(); //Initialize the simulation sim_Instance.setUniformGravity(new agx.Vec3(0, -9.80665f, 0)); //set gravity in Y direction sim_Instance.getDynamicsSystem().getTimeGovernor().setTimeStep(dt); // set timestep }
private agxSDK.Simulation GetOrCreateSimulation() { if (m_simulation == null) { NativeHandler.Instance.MakeMainThread(); m_simulation = new agxSDK.Simulation(); m_space = m_simulation.getSpace(); m_system = m_simulation.getDynamicsSystem(); // Solver settings will assign number of threads. if (m_solverSettings != null) { m_solverSettings.SetSimulation(m_simulation); m_solverSettings.GetInitialized <SolverSettings>(); } // No solver settings - set the default. else { agx.agxSWIG.setNumThreads(Convert.ToUInt32(SolverSettings.DefaultNumberOfThreads)); } } return(m_simulation); }
private void OnSimulationPostStep(agxSDK.Simulation simulation) { if (simulation == null) { return; } var gcs = simulation.getSpace().getGeometryContacts(); m_contactList.Clear(); m_contactList.Capacity = 4 * gcs.Count; for (int i = 0; i < gcs.Count; ++i) { var gc = gcs[i]; if (!gc.isEnabled()) { continue; } for (uint j = 0; j < gc.points().size(); ++j) { var p = gc.points().at(j); if (!p.enabled) { continue; } m_contactList.Add(new ContactData() { Point = p.point.ToHandedVector3(), Normal = p.normal.ToHandedVector3() }); } } }
public static void RemoveSimObjects() { if (sim_Instance != null) { sim_Instance.removeAllObjects(); } sim_Instance = null; }
protected override void OnDestroy() { base.OnDestroy(); if (m_simulation != null) { m_simulation.cleanup(); } m_simulation = null; }
private agxSDK.Simulation GetOrCreateSimulation() { if (m_simulation == null) { m_simulation = new agxSDK.Simulation(); } return(m_simulation); }
/// <summary> /// Callback from Simulation when a full update has been executed. /// This method collects contact data if "render contacts" is enabled. /// </summary> /// <param name="simulation">Simulation instance.</param> public static void OnActiveSimulationPostStep(agxSDK.Simulation simulation) { if (!IsActiveForSynchronize) { return; } Instance.OnSimulationPostStep(simulation); }
private agxSDK.Simulation GetOrCreateSimulation() { if (m_simulation == null) { NativeHandler.Instance.MakeMainThread(); m_simulation = new agxSDK.Simulation(); } return(m_simulation); }
public void OnDestroy(agxSDK.Simulation simulation) { if (m_simulationStepEvents == null) { return; } simulation.remove(m_simulationStepEvents); m_simulationStepEvents.Dispose(); m_simulationStepEvents = null; }
protected override void OnDestroy() { base.OnDestroy(); if (m_simulation != null) { if (m_solverSettings != null) { m_solverSettings.SetSimulation(null); } m_simulation.cleanup(); } m_simulation = null; }
/// <summary> /// Assigns default values to a native simulation instance. /// </summary> /// <param name="simulation">Native simulation instance.</param> public static void AssignDefault(agxSDK.Simulation simulation) { if (simulation == null) { return; } var tmp = Create <SolverSettings>(); tmp.SetSimulation(simulation); Utils.PropertySynchronizer.Synchronize(tmp); tmp.SetSimulation(null); ScriptAsset.Destroy(tmp); }
public SolverSettings RestoreLocalDataFrom(agxSDK.Simulation simulation) { var solver = simulation.getSolver(); var config = solver.getNlMcpConfig(); NumberOfThreads = System.Convert.ToInt32(agx.agxSWIG.getNumThreads()); WarmStartDirectContacts = simulation.getDynamicsSystem().getUpdateTask().getSubtask("MatchContactStates").isEnabled(); RestingIterations = System.Convert.ToInt32(solver.getNumRestingIterations()); DryFrictionIterations = System.Convert.ToInt32(solver.getNumDryFrictionIterations()); McpAlgorithm = Convert(config.mcpAlgorithmType); McpInnerIterations = System.Convert.ToInt32(config.numMcpIterations); McpInnerTolerance = System.Convert.ToSingle(config.mcpTolerance); McpOuterIterations = System.Convert.ToInt32(config.numOuterIterations); McpOuterTolerance = System.Convert.ToSingle(config.outerTolerance); return(this); }
private agxSDK.Simulation GetOrCreateSimulation() { if (m_simulation == null) { NativeHandler.Instance.MakeMainThread(); m_simulation = new agxSDK.Simulation(); m_defaultNumDryFrictionIterations = (int)m_simulation.getSolver().getNumDryFrictionIterations(); m_defaultNumRestingIterations = (int)m_simulation.getSolver().getNumRestingIterations(); m_space = m_simulation.getSpace(); m_system = m_simulation.getDynamicsSystem(); m_system.setEnableContactWarmstarting(m_warmStartingDirectContacts); } return(m_simulation); }
public Vehicle(agxSDK.Simulation simulation, Dictionary <string, agx.Hinge> wheelHinges) { m_simulation = simulation; m_wheelHinges = wheelHinges; initVehicleParameters(); initializeDrivetrain(); Clutch.setEfficiency(1.0); Gearbox.setGear(2); m_brakes = new Brakes(); // Initialize the brakes on the wheel hinges foreach (var h in m_wheelHinges) { h.Value.getLock1D().setEnable(false); m_brakes.Add(new Brake(h.Value, m_brakeForceRange)); } }
private void OnSimulationPostStep(agxSDK.Simulation simulation) { if (simulation == null) { return; } // Only collect data for contacts if they are enabled if (m_renderContacts) { var gcs = simulation.getSpace().getGeometryContacts(); m_contactList.Clear(); m_contactList.Capacity = System.Math.Max(m_contactList.Capacity, 4 * gcs.Count); for (int i = 0; i < gcs.Count; ++i) { var gc = gcs[i]; if (gc.isEnabled()) { var contactPoints = gc.points(); for (uint j = 0; j < contactPoints.size(); ++j) { var contactPoint = contactPoints.at(j); if (contactPoint.enabled) { m_contactList.Add(new ContactData() { Point = contactPoint.point.ToHandedVector3(), Normal = contactPoint.normal.ToHandedVector3() }); } contactPoint.ReturnToPool(); } contactPoints.ReturnToPool(); } gc.ReturnToPool(); } } }
/// <summary> /// Construct given AGX file info. /// </summary> /// <param name="info">AGX file info.</param> public InputAGXFile(AGXFileInfo info) { if (info == null) { throw new ArgumentNullException("info", "File info object is null."); } else { FileInfo = info; } if (!FileInfo.Exists) { throw new FileNotFoundException("File not found: " + FileInfo.FullName); } if (FileInfo.Type == AGXFileInfo.FileType.Unknown || FileInfo.Type == AGXFileInfo.FileType.AGXPrefab) { throw new AgXUnity.Exception("Unsupported file format: " + FileInfo.FullName); } Successful = false; Simulation = new agxSDK.Simulation(); }
public void Parse(agxSDK.Simulation simulation, AGXFileInfo fileInfo) { if (simulation == null) { throw new ArgumentNullException("simulation", "agxSDK.Simulation instance is null."); } if (m_roots.Count > 0) { throw new AgXUnity.Exception("Calling InputAGXFileTree::Parse multiple times is not supported."); } // Generating assets first. m_roots.Add(m_materialRoot); m_roots.Add(m_contactMaterialRoot); // RigidBody nodes. foreach (var nativeRb in simulation.getRigidBodies()) { if (!IsValid(nativeRb.get())) { continue; } // TODO: Recursive assembly creation. var assemblyNode = TryGetOrCreateAssembly(nativeRb.getFrame()); var rbNode = GetOrCreateRigidBody(nativeRb.get(), assemblyNode == null); if (assemblyNode != null) { assemblyNode.AddChild(rbNode); } foreach (var nativeGeometry in nativeRb.getGeometries()) { Parse(nativeGeometry.get(), rbNode); } } // Free Geometry nodes. foreach (var nativeGeometry in simulation.getGeometries()) { if (!IsValid(nativeGeometry.get())) { continue; } // We already have a node for this from reading bodies. if (nativeGeometry.getRigidBody() != null) { if (!m_nodeCache.ContainsKey(nativeGeometry.getUuid())) { Debug.LogWarning("Geometry with rigid body ignored but isn't in present in the tree. Name: " + nativeGeometry.getName()); } continue; } // TODO: Recursive assembly creation. Parse(nativeGeometry.get(), TryGetOrCreateAssembly(nativeGeometry.getFrame())); } // Constraint nodes. foreach (var nativeConstraint in simulation.getConstraints()) { if (!IsValid(nativeConstraint.get())) { continue; } var nativeRb1 = nativeConstraint.getBodyAt(0); var nativeRb2 = nativeConstraint.getBodyAt(1); if (!IsValid(nativeRb1)) { continue; } if (nativeRb2 != null && !IsValid(nativeRb2)) { continue; } var rb1Node = nativeRb1 != null?GetNode(nativeRb1.getUuid()) : null; var rb2Node = nativeRb2 != null?GetNode(nativeRb2.getUuid()) : null; // Could be ignored bodies due to Wire and Cable. if (rb1Node == null && rb2Node == null) { continue; } var constraintNode = GetOrCreateConstraint(nativeConstraint.get()); if (rb1Node != null) { constraintNode.AddReference(rb1Node); } if (rb2Node != null) { constraintNode.AddReference(rb2Node); } } var wires = agxWire.Wire.findAll(simulation); foreach (var wire in wires) { // TODO: Handle wires in assemblies? var wireNode = GetOrCreateWire(wire); if (wire.getMaterial() != null) { var materialNode = GetOrCreateMaterial(wire.getMaterial()); wireNode.AddReference(materialNode); } } var cables = agxCable.Cable.getAll(simulation); foreach (var cable in cables) { var cableNode = GetOrCreateCable(cable); if (cable.getMaterial() != null) { var materialNode = GetOrCreateMaterial(cable.getMaterial()); cableNode.AddReference(materialNode); } var groupsCollection = cable.findGroupIdCollection(); foreach (var name in groupsCollection.getNames()) { cableNode.AddReference(new Node() { Type = NodeType.GroupId, Object = name }); } foreach (var id in groupsCollection.getIds()) { cableNode.AddReference(new Node() { Type = NodeType.GroupId, Object = id.ToString() }); } agxCable.CableIterator it = cable.getSegments().begin(); while (!it.EqualWith(cable.getSegments().end())) { var constraint = it.getConstraint(); if (constraint != null && GetConstraint(constraint.getUuid()) != null) { Debug.LogWarning("Cable constraint has a constraint node in the simulation tree."); } foreach (var attachment in it.getAttachments()) { if (attachment.getConstraint() != null && GetConstraint(attachment.getConstraint().getUuid()) != null) { Debug.LogWarning("Cable attachment has a constraint node in the simulation tree."); } } it.inc(); } } var mm = simulation.getMaterialManager(); foreach (var m1 in m_materials.Values) { foreach (var m2 in m_materials.Values) { var cm = mm.getContactMaterial(m1, m2); if (cm == null) { continue; } var cmNode = GetOrCreateContactMaterial(cm); cmNode.AddReference(GetNode(m1.getUuid())); cmNode.AddReference(GetNode(m2.getUuid())); } } // Generating wires, cables and constraints last when all bodies has been generated. m_roots.Add(m_wireRoot); m_roots.Add(m_cableRoot); m_roots.Add(m_constraintRoot); }
public static void Stop() { RemoveSimObjects(); sim_Instance = null; agx.agxSWIG.shutdown(); }
/// <summary> /// Internal. /// </summary> public void SetSimulation(agxSDK.Simulation simulation) { SimulationInstance = simulation; }
public void OnInitialize(agxSDK.Simulation simulation) { m_simulationStepEvents = new SimulationStepEvents(this); simulation.add(m_simulationStepEvents); }