/// <summary> /// Peek at a temporary native instance or the current (if initialized). /// </summary> /// <param name="callback">Callback with temporary or already initialized native instance. Callback signature ( nativeRb, isTemporary ).</param> /// <remarks> /// Always assume the native instance to be temporary. It's never safe to cache an instance to the native object. /// </remarks> public void PeekTemporaryNativeOrGetNative(Action <agx.RigidBody, bool> callback) { if (callback == null) { return; } if (m_rb != null) { callback(m_rb, false); } else { Shape[] shapes = GetComponentsInChildren <Shape>(); using (agx.RigidBody rb = new agx.RigidBody()) { foreach (Shape shape in shapes) { agxCollide.Shape nativeShape = shape.CreateTemporaryNative(); if (nativeShape != null) { agxCollide.Geometry geometry = new agxCollide.Geometry(nativeShape); geometry.setEnable(shape.IsEnabled); if (shape.Material != null) { geometry.setMaterial(shape.Material.CreateTemporaryNative()); } rb.add(geometry, shape.GetNativeRigidBodyOffset(this)); } } // For center of mass position/rotation to be correct we have to // synchronize the native transform given current game object transform. SyncNativeTransform(rb); callback(rb, true); // Hitting "Update" (mass or inertia in the Inspector) several times // will crash agx if we don't remove the geometries and shapes. while (rb.getGeometries().Count > 0) { agxCollide.Geometry geometry = rb.getGeometries()[0].get(); if (geometry.getShapes().Count > 0) { geometry.remove(geometry.getShapes()[0].get()); } rb.remove(geometry); } } } }
public SinkContactListener(agxCollide.Geometry sinkGeometry, List <string> templateGroupNames) : base((int)(ActivationMask.IMPACT | ActivationMask.CONTACT)) { m_sinkGeometry = sinkGeometry; var filter = new agxSDK.CollisionGroupFilter(m_sinkGeometry); foreach (var groupName in templateGroupNames) { filter.addGroup(groupName); } setFilter(filter); }
protected override void OnEnable() { Simulation.Instance.StepCallbacks.PreStepForward += OnPreStepForwardCallback; Simulation.Instance.StepCallbacks.SimulationPre += OnSimulationPre; if (MainCamera != null) { m_camera = MainCamera.GetComponent <Camera>(); } m_lineShape = new agxCollide.Line(new agx.Vec3(), new agx.Vec3(0, 0, 1)); m_lineGeometry = new agxCollide.Geometry(m_lineShape); m_lineGeometry.setEnable(false); m_lineGeometry.setSensor(true); GetSimulation().add(m_lineGeometry); }
public AgX_Primitive(Guid guid, string shape, Vector3 pos, Quaternion rot, Vector3 size, double mass, string materialName, bool isStatic, bool AddToRobot) { this.guid = guid; this.shape = shape; this.size = size; this.materialName = materialName; var dynamicRBGeometry = new agxCollide.Geometry(); switch (this.shape) { case "Box": dynamicRBGeometry.add(new agxCollide.Box(Operations.ToAgxVec3(this.size))); break; case "Sphere": dynamicRBGeometry.add(new agxCollide.Sphere((this.size.x + this.size.y + this.size.z) / 3)); break; default: dynamicRBGeometry.add(new agxCollide.Box(Operations.ToAgxVec3(this.size))); break; } dynamicRBGeometry.setMaterial(new agx.Material(this.materialName)); agx_Object = new agx.RigidBody(); agx_Object.add(dynamicRBGeometry); agx_Object.setLocalPosition(Operations.ToAgxVec3(pos)); ///AgX agx_Object.setLocalRotation(new agx.Quat(rot.x, rot.y, rot.z, rot.w)); ///AgX agx_Object.getMassProperties().setMass(mass); if (isStatic) { agx_Object.setMotionControl(agx.RigidBody.MotionControl.STATIC); } if (AddToRobot) { AddToAssembly(); } else { Agx_Simulation.sim_Instance.add(agx_Object); } }
public AgX_Sensor(Guid guid, string materialName, Vector3 pos, Vector3 scale, double mass) { this.guid = guid; this.scale = scale; var dynamicRBGeometry = new agxCollide.Geometry();///AgX dynamicRBGeometry.add(new agxCollide.Box(Operations.ToAgxVec3(scale))); dynamicRBGeometry.setMaterial(new agx.Material(materialName)); agx_Object = new agx.RigidBody(); agx_Object.add(dynamicRBGeometry); agx_Object.setLocalPosition(Operations.ToAgxVec3(pos)); agx_Object.getMassProperties().setMass(mass); Agx_Simulation.sim_Instance.add(agx_Object); }
protected override void OnDisable() { if (Simulation.HasInstance) { Simulation.Instance.StepCallbacks.PreStepForward -= OnPreStepForwardCallback; Simulation.Instance.StepCallbacks.SimulationPre -= OnSimulationPre; GetSimulation().remove(m_lineGeometry); } if (ConstraintGameObject != null) { Destroy(ConstraintGameObject); } ConstraintGameObject = null; m_distanceFromCamera = -1f; m_camera = null; m_lineShape = null; m_lineGeometry = null; }
/// <summary> /// Removes the native geometry from the simulation. /// </summary> protected override void OnDestroy() { if (m_geometry != null && Simulation.HasInstance) { GetSimulation().remove(m_geometry); } if (Simulation.HasInstance) { Simulation.Instance.StepCallbacks.PostSynchronizeTransforms -= OnPostSynchronizeTransformsCallback; } if (m_geometry != null) { m_geometry.Dispose(); } m_geometry = null; m_transform = null; base.OnDestroy(); }
private void Parse(agxCollide.Geometry geometry, Node parent) { var geometryNode = GetOrCreateGeometry(geometry, parent == null); if (parent != null) { parent.AddChild(geometryNode); } foreach (var shape in geometry.getShapes()) { var shapeNode = GetOrCreateShape(shape.get()); geometryNode.AddChild(shapeNode); } if (geometry.getMaterial() != null) { var materialNode = GetOrCreateMaterial(geometry.getMaterial()); geometryNode.AddReference(materialNode); } var groupsCollection = geometry.findGroupIdCollection(); foreach (var name in groupsCollection.getNames()) { geometryNode.AddReference(new Node() { Type = NodeType.GroupId, Object = name }); } foreach (var id in groupsCollection.getIds()) { geometryNode.AddReference(new Node() { Type = NodeType.GroupId, Object = id.ToString() }); } }
public static bool IsValid(agxCollide.Geometry geometry) { return(geometry != null && agxWire.Wire.getWire(geometry) == null && agxCable.Cable.getCableForGeometry(geometry) == null); }