public AgX_Frame(Guid guid, string shape, Vector3[] vertices, Vector2[] uvs, int[] triangles, double size, Vector3 pos, Quaternion rot, double mass, bool isStatic, string materialName) { this.guid = guid; this.shape = shape; this.size = size; this.materialName = materialName; //scale by 2, to fit unity. /* Vector3[] tmp_verts = vertices; * for (int i = 0; i < tmp_verts.Length; i++) * { * tmp_verts[i].x *= 2; * tmp_verts[i].y *= 2; * tmp_verts[i].z *= 2; * }*/ var tri = new agxCollide.Trimesh(Operations.ToAgxVec3Vector(vertices), Operations.ToAgxIntVector(triangles), "stdFrame"); ///Creates a geometry var dynamicRBGeometry = new agxCollide.Geometry(); dynamicRBGeometry.add(tri); dynamicRBGeometry.setMaterial(new agx.Material(materialName)); ///Creates the selected shape /*switch (shape) * { * case "Box": dynamicRBGeometry.add(new agxCollide.Box(Operations.ToAgxVec3(size))); break; * case "Sphere": dynamicRBGeometry.add(new agxCollide.Sphere((size.x + size.y + size.z) / 3)); break; * }*/ agx_Object = new agx.RigidBody(); ///Adds selected geometry to the rigidbody agx_Object.add(dynamicRBGeometry); agx_Object.setLocalPosition(Operations.ToAgxVec3(pos));///AgX //var y = new agx.EulerAngles(Operations.ToAgxVec3(rot)); //UnityEngine.Debug.Log("x: " + y.x + ", y: " + y.y + ", z: " + y.z); agx_Object.setLocalRotation(new agx.Quat(rot.x, rot.y, rot.z, rot.w));///AgX //agx_Object.setLocalRotation(new agx.EulerAngles(Operations.ToAgxVec3(rot)));///AgX //UnityEngine.Debug.Log("x: " +agx_Object.getLocalPosition().x + ", y: " + agx_Object.getLocalPosition().y + ", z: " + agx_Object.getLocalPosition().z); agx_Object.getMassProperties().setMass(mass); if (isStatic) { agx_Object.setMotionControl(agx.RigidBody.MotionControl.STATIC); } AddToSim(); }
/// <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 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); }