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); }