// Remove both if their dot product is -1 (=opposite) or 1 and they have all the same points. // If points are not same thay are different sized quads. In this case remove the smaller quad. public void calculatePrimitiveRemoval (Primitive p,ref bool deleteSelf,ref bool deleteOther) { float dot = Vector3.Dot (avgNormal, p.avgNormal); float diff = Mathf.Abs (dot) + MeshUtils.MAX_ROUND_ERROR.x; if (!distanceFromPrimitivePlane(p) || !intersectWithPrimitive (p) || diff<1.0f) { return; } int samePoints = 0; for (int i=0; i<p.positions.Count; i++) { if (getPointIndexWithMaxError (p.positions [i], MeshUtils.MAX_ROUND_ERROR.x) >= 0) { samePoints++; } } if (samePoints == p.positions.Count) { if(samePoints == positions.Count){ deleteSelf = true; } deleteOther = true; return; } if (containsBounds (p.bounds) && area > p.area) { deleteOther = true; return; } else if (p.containsBounds (bounds) && p.area > area) { deleteSelf = true; } }
bool distanceFromPrimitivePlane(Primitive p){ float distance = 0; for (int i=0; i < p.positions.Count; i++) { distance += plane.GetDistanceToPoint(p.positions[i]); } distance /= p.positions.Count; return distance <= MeshUtils.MAX_ROUND_ERROR.x; }
public bool intersectWithPrimitive (Primitive q) { bool intersects = extendedBounds.Intersects (q.extendedBounds); return intersects; }