private static void AddTrianglesV1(IList<Triangle> ts, int len, Box3Fill OuterBox, Vector3 padXYZ, IList<Box3Fill> InnerBoxes) { int len1 = len - 1; OuterBox.AddTriangle(ts[len1], padXYZ); for (int i = 0; i < len1; i++) { Triangle t1 = ts[i]; bool used = false; OuterBox.AddTriangle(t1, padXYZ); for (int ii = i + 1; ii < len; ii++) { Triangle t2 = ts[ii]; int shared = SharedVertexs(t1, t2); if (shared == 3) continue; if (shared == 2) { Box3Fill B = new Box3Fill(t1, t2, padXYZ); InnerBoxes.Add(B); used = true; } } if (!used) { Box3Fill B = new Box3Fill(true); B.AddTriangle(t1, padXYZ); InnerBoxes.Add(B); } } }
private void EnsureInnerBoxesSimplied() { if (!InnerBoxesSimplified) { int b = InnerBoxes.Count; if (b < 2) { InnerBoxesSimplified = true; return; } if (b < 100) { InnerBoxes = Box3Fill.SimplifyZ(InnerBoxes); } else { InnerBoxes = Box3Fill.SimplifyZ(InnerBoxes); } if (false) { if (b > 100 || InnerBoxes.Count * 4 < b) { Console.Error.WriteLine("Simplfy CI {0} -> {1} ", b, InnerBoxes.Count + " " + this); } } InnerBoxesSimplified = true; } }
internal bool ChangeConstraints(Vector3 loc, float BumpConstraint) { Box3Fill B = new Box3Fill(true); B.AddPoint(loc.X, loc.Y, loc.Z, new Vector3(2f, 2f, 5f)); RefreshMatrix(B, BumpConstraint); //GlobalBumpConstraint = BumpConstraint; BumpConstraintPurple = BumpConstraint; return(true); }
public void RemeshObjects() { Box3Fill changed = new Box3Fill(true); foreach (List <CollisionObject> MOL in MeshedObjectIndexes()) { lock (MOL) foreach (CollisionObject O in new List <CollisionObject>(MOL)) { if (O is IMeshedObject) { ((IMeshedObject)O).RemeshObject(changed); } } } PathStore.Refresh(changed); }
private void RefreshMatrix(Box3Fill changed, float BumpConstraint) { changed.Constrain(OuterBox); byte[,] ToMatrix = ByteMatrix; float[,] Heights = HeightMap; float[,] GroundPlane = PathStore.GroundPlane; CollisionIndex[,] MeshIndex = PathStore.MeshIndex; int xs = PathStore.ARRAY_X(changed.MinX); int xe = PathStore.ARRAY_X(changed.MaxX); int ys = PathStore.ARRAY_Y(changed.MinY); int ye = PathStore.ARRAY_Y(changed.MaxY); if (xs < 1) { xs = 1; } int xend = MaxXPt - 2; if (xe > xend) { xe = xend; } if (ys < 1) { ys = 1; } int yend = MaxYPt - 2; if (ye > yend) { ye = yend; } for (int x = xs; x <= xe; x++) { for (int y = ys; y <= ye; y++) { ToMatrix[x, y] = DefaultCollisionValue(x, y, BumpConstraint, GroundPlane, ToMatrix[x, y], Heights, MeshIndex); } } AddEdgeBlocking(ToMatrix); }
protected void RemoveCollisions(SimPathStore simPathStore) { if (simPathStore != PathStore) return; if (PathStore == null) IsSolid = false; else { Box3Fill changed = new Box3Fill(true); RemoveFromWaypoints(changed); simPathStore.Refresh(changed); } }
/// <summary> /// Build the Boxes /// </summary> abstract public void RemeshObject(Box3Fill changed);
public override void RemeshObject(Box3Fill changed) { RemoveFromWaypoints(changed); Update(RootObject); UpdateOccupied(PathStore); }
public void RemeshObject(Box3Fill changed) { throw new NotImplementedException(); }
public RuntimeMesh(IComparable id, Box3Fill outer, IList <Box3Fill> inners, SimPathStore paths) : base(outer, inners, paths) { ID = id; }
public void RemoveBoxes(IComparable id) { IMeshedObject MO = meshedObjects[id];//.Remove(id); Box3Fill changed = new Box3Fill(true); MO.RemoveFromWaypoints(changed); RecomputeMatrix(); meshedObjects.Remove(id); }
public void Refresh(Box3Fill changed, float BumpConstraint) { foreach (CollisionPlane CP in CollisionPlanesFor(changed.MinZ, changed.MaxZ)) CP.Refresh(changed, BumpConstraint); }
/// <summary> /// Constructor. /// </summary> public SimPathStore(String simName, Vector2 pos, Vector3d globalPos, Vector3 endTop) { RegisterPathStore(pos, this); RegionName = simName; RegionLocation = pos; Start = Vector3.Zero; GlobalStart = globalPos; GlobalEnd = globalPos; Size = endTop; _XY256 = Size.X; _OuterBounds = new Box3Fill(true); OuterBounds.AddPoint(Start.X, Start.Y, Start.Z, Vector3.Zero); OuterBounds.AddPoint(endTop.X, endTop.Y, endTop.Z, Vector3.Zero); //TheSimZMinMaxLevel = new SimZMinMaxLevel(MinMaxLevel); StepSize = 1f/POINTS_PER_METER; _Max256 = XY256 - StepSize; MAPSPACE = (int) XY256*((int) POINTS_PER_METER); RegisterHttp(); if (Size.X != Size.Y) throw new Exception("X and Y must be the same for " + this); #if COLLIDER_ODE odeScene = (OdeScene) odePhysics.GetScene(RegionName); odeScene.Initialise(meshMerizer, null); float[] _heightmap = new float[256*256]; for (int i = 0; i < (256*256); i++) { _heightmap[i] = 21f; } odeScene.SetTerrain(_heightmap); #endif //CreateDefaultRoutes(); // CurrentPlane = new CollisionPlane(MAPSPACE,MAPSPACE,0); }
private static void AddTrianglesV13(IList<Triangle> ts, int len, Box3Fill OuterBox, Vector3 padXYZ, IList<Box3Fill> InnerBoxes) { Vertex[] unsharedV = new Vertex[6]; Vertex[] sharedV = new Vertex[3]; //int len1 = len - 1; //OuterBox.AddTriangle(ts[len1], padXYZ); for (int i = 0; i < len; i++) { Triangle t1 = ts[i]; if (t1 == null) continue; bool used = false; OuterBox.AddTriangle(t1, padXYZ); for (int ii = i + 1; ii < len; ii++) { Triangle t2 = ts[ii]; if (t2 == null) continue; int shared = SharedVertexs(t1, t2,sharedV,unsharedV); if (shared == 3) continue; if (shared == 2) { Vertex u1 = unsharedV[0]; Vertex u2 = unsharedV[1]; Vertex s1 = sharedV[0]; Vertex s2 = sharedV[1]; float ZDiff = u1.Z - u2.Z; if (ZDiff < 0) ZDiff = -ZDiff; if (ZDiff < 3) { Box3Fill B = new Box3Fill(t1, t2, padXYZ); InnerBoxes.Add(B); used = true; } else { } } } if (!used) { AddThreeFour(2, t1.v1, t1.v2, t1.v3, InnerBoxes, padXYZ); } } }
protected SimMesh(Box3Fill o, IList <Box3Fill> i, SimPathStore R) : base(o, i, R) { }
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); }
public IList<Box3Fill> InnerBoxes { get; set; }// = new List<Box3Fill>(); public MeshedObject(Box3Fill o, IList<Box3Fill> i, SimPathStore R) { OuterBox = o; InnerBoxes = i; PathStore = null;// R; }
public RuntimeMesh(IComparable id, Box3Fill outer, IList<Box3Fill> inners, SimPathStore paths) : base(outer, inners, paths) { ID = id; }
internal void TaintCollisionPlanes(Box3Fill OuterBox) { foreach (CollisionPlane list in Matrixes) { if (OuterBox.IsZInside(list.MinZ,list.MaxZ)) { list.HeightMapNeedsUpdate = true; } } }
public SimZLevel GroundLevelDelegate = null;//delegate(float x, float y) { return 10; }; // setup void AddBoxes(IComparable id, IList<Box3Fill> boxes) { Box3Fill Outer = new Box3Fill(true); foreach (Box3Fill B in boxes) { Outer.Expand(B); } IMeshedObject MO = new RuntimeMesh(id, Outer, boxes, this); //MeshedObject simMesh = new MeshedObject(boxes); meshedObjects.Add(id, MO); AddCollisions(MO); }
private static void AddTrianglesV2(IList<Triangle> ts, int len, Box3Fill OuterBox, Vector3 padXYZ, IList<Box3Fill> InnerBoxes) { foreach (Triangle t1 in ts) { Box3Fill B = new Box3Fill(true); OuterBox.AddTriangle(t1, padXYZ); B.AddTriangle(t1, padXYZ); InnerBoxes.Add(B); } }
// util static public void TrianglesToBoxes(IList<Triangle> tl, Box3Fill OuterBox, Vector3 padXYZ, IList<Box3Fill> InnerBoxes) { int tc = tl.Count; AddTrianglesV3S(tl, tc, OuterBox, padXYZ, InnerBoxes); // Debug(InnerBoxes.Count); }
private void RefreshMatrix(Box3Fill changed, float BumpConstraint) { changed.Constrain(OuterBox); byte[,] ToMatrix = ByteMatrix; float[,] Heights = HeightMap; float[,] GroundPlane = PathStore.GroundPlane; CollisionIndex[,] MeshIndex = PathStore.MeshIndex; int xs = PathStore.ARRAY_X(changed.MinX); int xe = PathStore.ARRAY_X(changed.MaxX); int ys = PathStore.ARRAY_Y(changed.MinY); int ye = PathStore.ARRAY_Y(changed.MaxY); if (xs < 1) xs = 1; int xend = MaxXPt - 2; if (xe > xend) xe = xend; if (ys < 1) ys = 1; int yend = MaxYPt - 2; if (ye > yend) ye = yend; for (int x = xs; x <= xe; x++) for (int y = ys; y <= ye; y++) ToMatrix[x, y] = DefaultCollisionValue(x, y, BumpConstraint, GroundPlane, ToMatrix[x, y], Heights, MeshIndex); AddEdgeBlocking(ToMatrix); }
internal void Refresh(Box3Fill changed) { Refresh(changed,CollisionIndex.MaxBumpInOpenPath); }
public override void RemeshObject(Box3Fill changed) { return; }
internal bool ChangeConstraints(Vector3 loc, float BumpConstraint) { Box3Fill B = new Box3Fill(true); B.AddPoint(loc.X,loc.Y,loc.Z,new Vector3(2f,2f,5f)); RefreshMatrix(B, BumpConstraint); //GlobalBumpConstraint = BumpConstraint; BumpConstraintPurple = BumpConstraint; return true; }
private static void AddTrianglesV321(IList<Triangle> ts, int len, Box3Fill OuterBox, Vector3 padXYZ, IList<Box3Fill> InnerBoxes) { int len2 = len - 2; int len1 = len - 1; OuterBox.AddTriangle(ts[len - 1], padXYZ); for (int i = 0; i < len2; i += 2) { Triangle t1 = ts[i]; if (t1 == null) continue; OuterBox.AddTriangle(t1, padXYZ); Triangle t2 = ts[i + 1]; if (t2 != null) { OuterBox.AddTriangle(t2, padXYZ); InnerBoxes.Add(new Box3Fill(t1, t2, padXYZ)); } bool used = false; int until = i + 1; for (int ii = len1; ii > until;ii-- ) { t2 = ts[ii]; if (t2 == null) continue; int shared = SharedVertexs(t1, t2); if (shared == 3) continue; if (shared == 2) { InnerBoxes.Add(new Box3Fill(t1, t2, padXYZ)); ts[ii] = null; used = true; } } if (!used) { Box3Fill B = new Box3Fill(true); B.AddTriangle(t1, padXYZ); InnerBoxes.Add(B); } } }
protected SimMesh(Box3Fill o, IList<Box3Fill> i, SimPathStore R) : base(o, i, R) { }
private static void AddTrianglesV32(IList<Triangle> ts, int len, Box3Fill OuterBox, Vector3 padXYZ, IList<Box3Fill> InnerBoxes) { Triangle t1 = ts[0]; Triangle t2 = ts[len - 1]; OuterBox.AddTriangle(t1, padXYZ); OuterBox.AddTriangle(t2, padXYZ); Box3Fill B;// = new Box3Fill(t1, t2, padXYZ); //InnerBoxes.Add(B); int len2 = len - 2; OuterBox.AddTriangle(ts[len - 1], padXYZ); for (int i = 0; i < len2; i += 1) { t1 = ts[i]; if (t1 == null) continue; t2 = ts[i + 1]; if (t2 == null) continue; OuterBox.AddTriangle(t1, padXYZ); OuterBox.AddTriangle(t2, padXYZ); B = new Box3Fill(t1, t2, padXYZ); InnerBoxes.Add(B); bool used = false; for (int ii = i + 2; ii < len; ii++) { t2 = ts[ii]; if (t2 == null) continue; int shared = SharedVertexs(t1, t2); if (shared == 3) continue; if (shared == 2) { B = new Box3Fill(t1, t2, padXYZ); InnerBoxes.Add(B); // ts[ii] = null; used = true; } } if (!used) { B = new Box3Fill(true); B.AddTriangle(t1, padXYZ); InnerBoxes.Add(B); } } }
internal void Refresh(Box3Fill changed) { // throw new NotImplementedException(); }
private static void AddTrianglesV34(IList<Triangle> ts, int len, Box3Fill OuterBox, Vector3 padXYZ, IList<Box3Fill> InnerBoxes) { //int len1 = len - 2; //OuterBox.AddTriangle(ts[len - 1], padXYZ); for (int i = 0; i < len; i += 1) { Triangle t1 = ts[i]; if (t1 == null) continue; OuterBox.AddTriangle(t1, padXYZ); Box3Fill B;// = new Box3Fill(t1, t2, padXYZ); //InnerBoxes.Add(B); bool used = false; for (int ii = i + 1; ii < len; ii++) { Triangle t2 = ts[ii]; if (t2 == null) continue; int shared = SharedVertexs(t1, t2); if (shared == 3) continue; if (shared == 2) { ts[ii] = null; B = new Box3Fill(t1, t2, padXYZ); InnerBoxes.Add(B); used = true; } } if (!used) { AddThreeFour(2, t1.v1, t1.v2, t1.v3, InnerBoxes, padXYZ); } } }
public void RemeshObject() { Box3Fill changed = new Box3Fill(true); RemeshObject(changed); PathStore.Refresh(changed); }
private static void AddTrianglesV4(IEnumerable<Triangle> ts, int len, Box3Fill OuterBox, Vector3 padXYZ, IList<Box3Fill> InnerBoxes) { foreach (Triangle t1 in ts) { OuterBox.AddTriangle(t1, padXYZ); Vertex v1 = t1.v1; Vertex v2 = t1.v2; Vertex v3 = t1.v3; AddThreeTwo(v1, v2, v3,InnerBoxes, padXYZ); } }
public void RemoveFromWaypoints(Box3Fill changed) { float detail = PathStore.StepSize;// -0.001f; float MinX = OuterBox.MinX; float MaxX = OuterBox.MaxX; float MinY = OuterBox.MinY; float MaxY = OuterBox.MaxY; float MinZ = OuterBox.MinZ; float MaxZ = OuterBox.MaxZ; changed.AddPoint(MinX, MinY, MinZ, Vector3.Zero); changed.AddPoint(MaxX, MaxY, MaxZ, Vector3.Zero); for (float x = MinX; x <= MaxX; x += detail) { for (float y = MinY; y <= MaxY; y += detail) { RemoveFromWaypoint(x, y, MinZ, MaxZ); } } RemoveFromWaypoint(MaxX, MaxY, MinZ, MaxZ); }
private static void AddTrianglesV4S(IList<Triangle> ts, int len, Box3Fill OuterBox, Vector3 padXYZ, IList<Box3Fill> InnerBoxes) { List<Vertex> Shared; List<Vertex> UnShared; Box3Fill B;// = new Box3Fill(t1, t2, padXYZ); for (int i = 0; i < len; i += 1) { Triangle t1 = ts[i]; if (t1 == null) continue; OuterBox.AddTriangle(t1, padXYZ); //InnerBoxes.Add(B); bool used = false; for (int ii = i + 1; ii < len; ii++) { Triangle t2 = ts[ii]; if (t2 == null) continue; List<Vertex> verts = AddedVertexs(t1, t2,out Shared,out UnShared); // if (Shared.Count == 0) continue; if (Shared.Count == 2) { // ts[ii] = null; B = new Box3Fill(t1, t2, padXYZ); InnerBoxes.Add(B); used = true; // break; } } if (!used) { Vertex v1 = t1.v1; Vertex v2 = t1.v2; Vertex v3 = t1.v3; AddThreeTwo(v1, v2, v3, InnerBoxes, padXYZ); } } }
public void RemeshObjects() { Box3Fill changed = new Box3Fill(true); foreach (List<CollisionObject> MOL in MeshedObjectIndexes()) { lock (MOL) foreach (CollisionObject O in new List<CollisionObject>(MOL)) { if (O is IMeshedObject) ((IMeshedObject)O).RemeshObject(changed); } } PathStore.Refresh(changed); }
private static void AddThree(Vertex v1, Vertex v2, Vertex v3, ICollection<Box3Fill> InnerBoxes, Vector3 padXYZ) { Box3Fill B = new Box3Fill(true); B.AddVertex(v1, padXYZ); B.AddVertex(v2, padXYZ); B.AddVertex(v3, padXYZ); InnerBoxes.Add(B); }
private static void AddTwo(Vertex v1, Vertex v2, ICollection<Box3Fill> InnerBoxes, Vector3 padXYZ) { Vertex v4 = new Vertex((v1.X + v2.X) / 2, (v1.Y + v2.Y ) / 2, (v1.Z + v2.Z ) / 2); Box3Fill B = new Box3Fill(true); B.AddVertex(v1, padXYZ); B.AddVertex(v4, padXYZ); InnerBoxes.Add(B); B = new Box3Fill(true); B.AddVertex(v2, padXYZ); B.AddVertex(v4, padXYZ); InnerBoxes.Add(B); }