public static AABB CalcHierarchyModelAABB(GameObject root, QueryConfig queryConfig) { Matrix4x4 rootTransform = root.transform.localToWorldMatrix; AABB finalAABB = CalcModelAABB(root, queryConfig, root.GetGameObjectType()); List <GameObject> allChildren = root.GetAllChildren(); foreach (var child in allChildren) { AABB modelAABB = CalcModelAABB(child, queryConfig, child.GetGameObjectType()); if (modelAABB.IsValid) { // All children must have their AABBs calculated in the root local space, so we must // first calculate a matrix that transforms the child object in the local space of the // root. We will use this matrix to transform the child's AABB in root space. Matrix4x4 rootRelativeTransform = child.transform.localToWorldMatrix.GetRelativeTransform(rootTransform); modelAABB.Transform(rootRelativeTransform); if (finalAABB.IsValid) { finalAABB.Encapsulate(modelAABB); } else { finalAABB = modelAABB; } } } return(finalAABB); }
public static AABB CalcCylAABB(Vector3 torusCenter, float torusCoreRadius, float torusHrzRadius, float torusVertRadius, Quaternion torusRotation) { AABB aabb = CalcCylModelAABB(torusCoreRadius, torusHrzRadius, torusVertRadius); aabb.Transform(Matrix4x4.TRS(torusCenter, torusRotation, Vector3.one)); return(aabb); }
public override AABB GetAABB() { AABB aabb = GetModelAABB(); aabb.Transform(Matrix4x4.TRS(_baseCenter, _rotation, Vector3.one)); return(aabb); }
public static AABB GetMeshWorldAABB(GameObject gameObject) { AABB modelAABB = CalcMeshModelAABB(gameObject); if (!modelAABB.IsValid) { return(modelAABB); } modelAABB.Transform(gameObject.transform.localToWorldMatrix); return(modelAABB); }
public static AABB CalcWorldAABB(GameObject gameObject, QueryConfig queryConfig) { AABB modelAABB = CalcModelAABB(gameObject, queryConfig, gameObject.GetGameObjectType()); if (!modelAABB.IsValid) { return(modelAABB); } modelAABB.Transform(gameObject.transform.localToWorldMatrix); return(modelAABB); }
public static AABB CalcHierarchyWorldAABB(GameObject root, QueryConfig queryConfig) { AABB modelAABB = CalcHierarchyModelAABB(root, queryConfig); if (!modelAABB.IsValid) { return(AABB.GetInvalid()); } modelAABB.Transform(root.transform.localToWorldMatrix); return(modelAABB); }
public List <MeshVertexChunk> GetWorldChunksHoveredByPoint(Vector3 hoverPoint, Matrix4x4 worldMtx, Camera camera) { var hoveredChunks = new List <MeshVertexChunk>(); foreach (var chunk in _vertexChunks) { AABB chunkAABB = chunk.ModelSpaceAABB; chunkAABB.Transform(worldMtx); Rect screenrect = chunkAABB.GetScreenRectangle(camera); if (screenrect.Contains(hoverPoint, true)) { hoveredChunks.Add(chunk); } } return(hoveredChunks); }
public MeshVertexChunk GetWorldVertChunkClosestToScreenPt(Vector2 screenPoint, Matrix4x4 worldMtx, Camera camera) { float minDistSqr = float.MaxValue; MeshVertexChunk closestChunk = null; foreach (var chunk in _vertexChunks) { AABB chunkAABB = chunk.ModelSpaceAABB; chunkAABB.Transform(worldMtx); List <Vector2> screenPts = chunkAABB.GetScreenCenterAndCornerPoints(camera); foreach (var pt in screenPts) { float distSqr = (pt - screenPoint).sqrMagnitude; if (distSqr < minDistSqr) { minDistSqr = distSqr; closestChunk = chunk; } } } return(closestChunk); }