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."); } // 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() }); } var 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())); } } foreach (var observerFrame in simulation.getObserverFrames()) { if (observerFrame.getRigidBody() == null) { continue; } var rbNode = GetNode(observerFrame.getRigidBody().getUuid()); if (rbNode == null) { continue; } var observerFrameNode = GetOrCreateObserverFrame(observerFrame.get()); observerFrameNode.AddReference(rbNode); } // 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); m_roots.Add(m_observerFrameRoot); // Generating assets last since we have to know the references. // Materials aren't parsed, they are generated on the fly when // objects references them. m_roots.Add(m_materialRoot); m_roots.Add(m_contactMaterialRoot); }