public override dNewtonCollision Create(NewtonWorld world) { if (m_Mesh == null) { return(null); } if (m_Mesh.triangles.Length < 3) { return(null); } Vector3 scale = GetBaseScale(); if (m_FreezeScale == false) { scale = new Vector3(1.0f, 1.0f, 1.0f); } Vector3[] vertices = m_Mesh.vertices; float[] triVertices = new float[3 * 3]; IntPtr floatsPtr = Marshal.AllocHGlobal(3 * 3 * Marshal.SizeOf(typeof(float))); dNewtonCollisionMesh collision = new dNewtonCollisionMesh(world.GetWorld()); collision.BeginFace(); for (int i = 0; i < m_Mesh.subMeshCount; i++) { int[] submesh = m_Mesh.GetTriangles(i); for (int j = 0; j < submesh.Length; j += 3) { int k = submesh[j]; triVertices[0] = vertices[k].x * scale.x; triVertices[1] = vertices[k].y * scale.y; triVertices[2] = vertices[k].z * scale.z; k = submesh[j + 1]; triVertices[3] = vertices[k].x * scale.x; triVertices[4] = vertices[k].y * scale.y; triVertices[5] = vertices[k].z * scale.z; k = submesh[j + 2]; triVertices[6] = vertices[k].x * scale.x; triVertices[7] = vertices[k].y * scale.y; triVertices[8] = vertices[k].z * scale.z; Marshal.Copy(triVertices, 0, floatsPtr, triVertices.Length); collision.AddFace(3, floatsPtr, 3 * sizeof(float), i); } } collision.EndFace(m_Optimize); Marshal.FreeHGlobal(floatsPtr); m_IsTrigger = false; SetMaterial(collision); SetLayer(collision); return(collision); }
public override dNewtonCollision Create(NewtonWorld world) { dNewtonCollision collider = new dNewtonCollisionCapsule(world.GetWorld(), m_Radius0, m_Radius1, m_Height); SetMaterial(collider); SetLayer(collider); return(collider); }
public override dNewtonCollision Create(NewtonWorld world) { dNewtonCollision collider = new dNewtonCollisionSphere(world.GetWorld(), m_Radius); SetMaterial(collider); SetLayer(collider); return(collider); }
public override dNewtonCollision Create(NewtonWorld world) { dNewtonCollisionScene collider = new dNewtonCollisionScene(world.GetWorld()); SetMaterial(collider); SetLayer(collider); return(collider); }
public override dNewtonCollision Create(NewtonWorld world) { dNewtonCollision collider = new dNewtonCollisionChamferedCylinder(world.GetWorld(), m_Radius, m_Height); SetMaterial(collider); SetLayer(collider); m_Scale.y = 4.0f; return collider; }
public override dNewtonCollision Create(NewtonWorld world) { dNewtonCollision collider = new dNewtonCollisionBox(world.GetWorld(), m_Size.x, m_Size.y, m_Size.z); SetMaterial(collider); SetLayer(collider); return(collider); }
public override dNewtonCollision Create(NewtonWorld world) { TerrainData data = m_terrain.terrainData; //Debug.Log("xxxx " + data.alphamapWidth + " xxx " + data.detailHeight); //Debug.Log("xxxx " + data.heightmapScale); //Debug.Log("xxxx " + data.size); int resolution = data.heightmapResolution; dVector scale = new dVector(data.size.x, data.size.y, data.size.z, 0.0f); m_oldSize = data.size; m_oldResolution = resolution; data.GetHeights(0, 0, resolution, resolution); int hash = 0; float elevationScale = data.size.y; float[] elevation = new float[resolution * resolution]; for (int z = 0; z < resolution; z++) { for (int x = 0; x < resolution; x++) { float value = data.GetHeight(x, z); elevation[z * resolution + x] = value; hash = Utils.dRand((int)(elevationScale * value), hash); } } m_elevationHash = hash; IntPtr elevationPtr = Marshal.AllocHGlobal(resolution * resolution * Marshal.SizeOf(typeof(float))); Marshal.Copy(elevation, 0, elevationPtr, elevation.Length); dNewtonCollision collider = new dNewtonCollisionHeightField(world.GetWorld(), elevationPtr, resolution, scale); Marshal.FreeHGlobal(elevationPtr); SetDefualtParams(); SetMaterial(collider); SetLayer(collider); return(collider); }
public override dNewtonCollision Create(NewtonWorld world) { if (m_Mesh == null) { return(null); } if (m_Mesh.vertices.Length < 4) { return(null); } float[] array = new float[3 * m_Mesh.vertices.Length]; for (int i = 0; i < m_Mesh.vertices.Length; i++) { array[i * 3 + 0] = m_Mesh.vertices[i].x; array[i * 3 + 1] = m_Mesh.vertices[i].y; array[i * 3 + 2] = m_Mesh.vertices[i].z; } IntPtr floatsPtr = Marshal.AllocHGlobal(array.Length * Marshal.SizeOf(typeof(float))); Marshal.Copy(array, 0, floatsPtr, array.Length); dNewtonCollision collision = new dNewtonCollisionConvexHull(world.GetWorld(), m_Mesh.vertices.Length, floatsPtr, 0.01f * (1.0f - m_Quality)); if (collision.IsValid() == false) { collision.Dispose(); collision = null; } Marshal.FreeHGlobal(floatsPtr); SetMaterial(collision); SetLayer(collision); return(collision); }
public override dNewtonCollision Create(NewtonWorld world) { return(new dNewtonCollisionNull(world.GetWorld())); }