/*--------------------------------------------------Creating terrain--------------------------------------------------*/ //public void Create_Terrain(Guid guid, string heightmap, Vector3 position, string materialName, double restitution, double friction, double height) public AgX_Scene(Guid guid, List <Vector3> vertices, List <int> triangles, Vector3 position, string materialName) { this.guid = guid; //AgX: agx.Vec3Vector agx_vertices = new agx.Vec3Vector(); agx.UInt32Vector agx_indices = new agx.UInt32Vector(); for (int i = 0; i < vertices.Count; i++) { agx_vertices.Add(Operations.ToAgxVec3(vertices[i])); } for (int i = 0; i < triangles.Count; i++) { agx_indices.Add((uint)triangles[i]); } terrain = new agx.RigidBody(); //uint optionsMask = (uint)agxCollide.Trimesh.TrimeshOptionsFlags.TERRAIN; var terrain_trimesh = new agxCollide.Trimesh(agx_vertices, agx_indices, "handmade terrain");//, optionsMask, height); var geometry = new agxCollide.Geometry(); geometry.add(terrain_trimesh); geometry.setMaterial(new agx.Material(materialName)); terrain.add(geometry); terrain.setMotionControl(agx.RigidBody.MotionControl.STATIC); //position.y -= height; terrain.setLocalPosition(Operations.ToAgxVec3(position));//move right and -height for global 0 ///Adds terrain to simulation //simulation.add(terrain); Agx_Simulation.sim_Instance.add(terrain); }
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; 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)); agx_Object = new agx.RigidBody(); ///Adds selected geometry to the 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); } AddToAssembly(); }
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(); }