public Mesh Clone() { Mesh result = new Mesh(); #if COLLIDER_ODE result.PBS = PBS; #endif foreach (Vertex v in vertices) { if (v == null) result.vertices.Add(null); else result.vertices.Add(v.Clone()); } foreach (Triangle t in triangles) { int iV1, iV2, iV3; iV1 = vertices.IndexOf(t.v1); iV2 = vertices.IndexOf(t.v2); iV3 = vertices.IndexOf(t.v3); Triangle newT = new Triangle(result.vertices[iV1], result.vertices[iV2], result.vertices[iV3]); result.Add(newT); } return result; }
public void Append(Mesh newMesh) { Mesh newMesh2; if (newMesh is Mesh) { newMesh2 = (Mesh)newMesh; } else { return; } foreach (Vertex v in newMesh2.vertices) vertices.Add(v); foreach (Triangle t in newMesh2.triangles) Add(t); }
public static Mesh ToMesh( #if (COLLIDER_ODE) PrimitiveBaseShape pbs, #endif List<Coord> coords, List<Face> faces, List<ViewerFace> viewerFaces, bool isSphere) { Mesh mesh = new Mesh( #if COLLIDER_ODE pbs #endif ); int numCoords = coords.Count; int numFaces = faces.Count; for (int i = 0; i < numCoords; i++) { Coord c = coords[i]; mesh.vertices.Add(new Vertex(c.X, c.Y, c.Z)); } List<Vertex> vertices = mesh.vertices; for (int i = 0; i < numFaces; i++) { Face f = faces[i]; mesh.triangles.Add(new Triangle(vertices[f.v1], vertices[f.v2], vertices[f.v3])); } if (UseViewerMode && viewerFaces != null) { int numViewerFaces = viewerFaces.Count; for (uint i = 0; i < numViewerFaces; i++) { ViewerFace vf = viewerFaces[(int)i]; if (isSphere) { vf.uv1.U = (vf.uv1.U - 0.5f) * 2.0f; vf.uv2.U = (vf.uv2.U - 0.5f) * 2.0f; vf.uv3.U = (vf.uv3.U - 0.5f) * 2.0f; } } } return mesh; }
/// <summary> /// Convert a PrimMesher.PrimMesh to OpenSim.Region.Physics.Meshing.Mesh /// </summary> /// <param name="meshIn"></param> /// <returns></returns> public static Mesh PrimMeshToMesh(PrimMesh meshIn) { Mesh mesh = new Mesh(); #if COLLIDER_ODE mesh.PBS = meshIn.PBS #endif mesh.primMesh = meshIn; { List<Coord> coords = meshIn.coords; List<Face> faces = meshIn.faces; int numCoords = coords.Count; int numFaces = faces.Count; for (int i = 0; i < numCoords; i++) { Coord c = coords[i]; mesh.vertices.Add(new Vertex(c.X, c.Y, c.Z)); } List<Vertex> vertices = mesh.vertices; for (int i = 0; i < numFaces; i++) { Face f = faces[i]; mesh.triangles.Add(new Triangle(vertices[f.v1], vertices[f.v2], vertices[f.v3])); } } return mesh; }
void CalcBoxesFromMeshes(Mesh M, IList<Box3Fill> innerBoxes) { #if COLLIDER_TRIANGLE triangles = M.triangles; #endif SimPathStore.TrianglesToBoxes(M.triangles, OuterBox, PadXYZ, innerBoxes); }
public override sealed bool Update(SimPosition simObject) { //if (!WorldObjects.MaintainCollisions) return false; if (!simObject.IsRegionAttached) return false; if (MeshOnlySolids && !((MeshableObject) simObject).IsSolid) return false; Quaternion Rotation = simObject.SimRotation; Vector3 Scale = Prim.Scale; //.GetSimScale(); Vector3 Position = simObject.SimPosition; #if COLLIDER_ODE LastSize = new PhysicsVector(1, 1, 1); // we scaled the PrimMesh already! LastRotation = Quaternion.Identity; // we rotated the PrimMesh already! LastPosition = ToPhysicsVector(Position); // we hadn't done position though #endif //pbs. //List<Mesh> MeshList = new List<Mesh>(); //PrimMesh primMesh; //if (false) //{ // // Add Low PrimMesh (IdealistViewer code) // primMesh = PrimitiveToPrimMesh(simObject.thePrim, LevelOfDetail.Low, Scale, Rotation); // AddMesh(primMesh); //} // Add High PrimMesh (IdealistViewer code) Mesh mesh = PrimitiveToMesh(Prim, Scale, Rotation); #if COLLIDER_ODE this.mesh = mesh; if (!RootObject.IsPhantom) physicsActor = GetPhysicsActor(); #endif //MeshList.Add(mesh); //if (false) //{ // // Add based on PrimitiveBaseShape (OpenSim Meshmerizer code) // PrimitiveBaseShape primShape = PrimToBaseShape(simObject.thePrim); // Mesh mesh = CreateMesh(simObject.ToString(), primShape, // new PhysicsVector(Scale.X, Scale.Y, Scale.Z), 32f, Object.IsPhysical, QuaternionToQuat(Rotation)); // why 32? // AddMesh(mesh); // // i am going to see if i can make simple bounding mox meshes for unhollow cubes // if (primShape.ProfileShape == ProfileShape.Square && primShape.HollowShape == HollowShape.Same) // { // Mesh extramesh = Meshmerizer.CreateBoundingBoxMesh(mesh); // AddMesh(extramesh); // } //} if (InnerBoxes == null) InnerBoxes = new List<Box3Fill>(); else InnerBoxes.Clear(); OuterBox.Reset(); CalcBoxesFromMeshes(mesh, InnerBoxes); bool verySmall = OuterBox.EdgeSize < WorldPathSystem.MinEdgeSizeOfSimplify; if (verySmall) { int b = InnerBoxes.Count; InnerBoxes.Clear(); AddPos(Position); InnerBoxes.Add(OuterBox); DLRConsole.DebugWriteLine("Simplfy EdgeSize {0} -> 1 ", b, InnerBoxes.Count + " " + OuterBox.EdgeSize + " " + this.GetObjectName()); } else { if (SimplifyBoxes) { int b = InnerBoxes.Count; InnerBoxes = Box3Fill.Simplify((List<Box3Fill>)InnerBoxes); if (DebugMesh) if (b > 2000 || InnerBoxes.Count * 4 < b) DLRConsole.DebugWriteLine("Simplfy mesh {0} -> {1} ", b, InnerBoxes.Count + " " + OuterBox.Mass + " " + this.GetObjectName()); } AddPos(Position); } #if COLLIDER_TRIANGLE triangles = mesh.triangles; #endif return true; }