public AABB GetTargetObjectGroupWorldAABB() { if (_targetObjects == null) { return(AABB.GetInvalid()); } var boundsQConfig = GetObjectBoundsQConfig(); AABB targetGroupAABB = AABB.GetInvalid(); foreach (var targetObject in _targetObjects) { AABB targetAABB = ObjectBounds.CalcWorldAABB(targetObject, boundsQConfig); if (targetGroupAABB.IsValid) { targetGroupAABB.Encapsulate(targetAABB); } else { targetGroupAABB = targetAABB; } } return(targetGroupAABB); }
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); }
/// <summary> /// Calculates and returns the AABB that encloses all the 3D shapes which belong to the handle. /// If the handle doesn't contain any 3D shapes or if none of them are marked as visible, an /// invalid AABB will be returned. The 'Is3DVisible' property is ignored. /// </summary> public AABB GetVisible3DShapesAABB() { AABB aabb = AABB.GetInvalid(); if (Num3DShapes == 0) { return(aabb); } foreach (var shape in _3DShapes) { if (!shape.IsVisible) { continue; } AABB shapeAABB = shape.Shape.GetAABB(); if (shapeAABB.IsValid) { if (aabb.IsValid) { aabb.Encapsulate(shapeAABB); } else { aabb = shapeAABB; } } } return(aabb); }
public AABB CalculateBounds() { Scene activeScene = SceneManager.GetActiveScene(); List <GameObject> roots = new List <GameObject>(Mathf.Max(10, activeScene.rootCount)); SceneManager.GetActiveScene().GetRootGameObjects(roots); ObjectBounds.QueryConfig boundsQConfig = new ObjectBounds.QueryConfig(); boundsQConfig.NoVolumeSize = Vector3.zero; boundsQConfig.ObjectTypes = GameObjectType.Mesh | GameObjectType.Sprite; AABB sceneAABB = new AABB(); foreach (GameObject root in roots) { List <GameObject> allChildrenAndSelf = root.GetAllChildrenAndSelf(); foreach (GameObject sceneObject in allChildrenAndSelf) { AABB aabb = ObjectBounds.CalcWorldAABB(sceneObject, boundsQConfig); if (aabb.IsValid) { if (sceneAABB.IsValid) { sceneAABB.Encapsulate(aabb); } else { sceneAABB = aabb; } } } } return(sceneAABB); }
public override AABB GetAABB() { AABB aabb = new AABB(GetBaseExtents()); aabb.Encapsulate(Tip); return(aabb); }
private void OnBorderPointsFoundDirty() { _borderPoints = PrimitiveFactory.Generate3DArcBorderPoints(_origin, _startPoint, _plane, _degreeAngleFromStart, _forceShortestArc, _numBorderPoints); _aabb = new AABB(_borderPoints); _aabb.Encapsulate(_origin); _areBorderPointsDirty = false; }
public void FitBoxToTargets() { if (NumTargetParents == 0) { _boxSize = Vector3.zero; return; } if (ExtrudeSpace == GizmoSpace.Global) { AABB worldAABB = AABB.GetInvalid(); foreach (var parent in _targetParents) { AABB aabb = ObjectBounds.CalcHierarchyWorldAABB(parent, _boundsQConfig); if (aabb.IsValid) { if (worldAABB.IsValid) { worldAABB.Encapsulate(aabb); } else { worldAABB = aabb; } } } SetAABB(worldAABB); UpdateSnapSteps(); } else if (ExtrudeSpace == GizmoSpace.Local) { OBB worldOBB = ObjectBounds.CalcHierarchyWorldOBB(_targetParents[0], _boundsQConfig); for (int parentIndex = 1; parentIndex < NumTargetParents; ++parentIndex) { GameObject parent = _targetParents[parentIndex]; OBB obb = ObjectBounds.CalcHierarchyWorldOBB(parent, _boundsQConfig); if (obb.IsValid) { if (worldOBB.IsValid) { worldOBB.Encapsulate(obb); } else { worldOBB = obb; } } } SetOBB(worldOBB); UpdateSnapSteps(); } }
public void Encapsulate(OBB otherOBB) { var otherPts = BoxMath.CalcBoxCornerPoints(otherOBB.Center, otherOBB.Size, otherOBB.Rotation); Matrix4x4 transformMtx = Matrix4x4.TRS(Center, Rotation, Vector3.one); var modelPts = transformMtx.inverse.TransformPoints(otherPts); AABB modelAABB = new AABB(Vector3.zero, Size); modelAABB.Encapsulate(modelPts); Center = (Rotation * modelAABB.Center) + Center; Size = modelAABB.Size; }
public static AABB CalcObjectCollectionWorldAABB(IEnumerable <GameObject> gameObjectCollection, QueryConfig queryConfig) { AABB aabb = AABB.GetInvalid(); foreach (var gameObject in gameObjectCollection) { AABB worldAABB = CalcWorldAABB(gameObject, queryConfig); if (worldAABB.IsValid) { if (aabb.IsValid) { aabb.Encapsulate(worldAABB); } else { aabb = worldAABB; } } } return(aabb); }
public static AABB CalcHierarchyCollectionWorldAABB(List <GameObject> roots, QueryConfig queryConfig) { AABB aabb = AABB.GetInvalid(); foreach (var root in roots) { AABB hierarchyAABB = CalcHierarchyWorldAABB(root, queryConfig); if (hierarchyAABB.IsValid) { if (aabb.IsValid) { aabb.Encapsulate(hierarchyAABB); } else { aabb = hierarchyAABB; } } } return(aabb); }
public AABB GetVisible3DHandlesAABB() { AABB aabb = AABB.GetInvalid(); int numHandles = _handles.Count; for (int handleIndex = 0; handleIndex < numHandles; ++handleIndex) { var handle = _handles[handleIndex]; AABB handleAABB = handle.GetVisible3DShapesAABB(); if (handleAABB.IsValid) { if (aabb.IsValid) { aabb.Encapsulate(handleAABB); } else { aabb = handleAABB; } } } return(aabb); }
public void FitBoxToTargets() { if (NumTargetParents == 0) { _boxSize = Vector3.zero; return; } if (ExtrudeSpace == GizmoSpace.Global) { AABB worldAABB = AABB.GetInvalid(); foreach (var parent in _targetParents) { if (_ignoredParentObjects.Contains(parent)) { continue; } AABB aabb = ObjectBounds.CalcHierarchyWorldAABB(parent, _boundsQConfig); if (aabb.IsValid) { if (worldAABB.IsValid) { worldAABB.Encapsulate(aabb); } else { worldAABB = aabb; } } } SetAABB(worldAABB); UpdateSnapSteps(); } else if (ExtrudeSpace == GizmoSpace.Local) { int firstParentIndex = 0; while (firstParentIndex < NumTargetParents) { if (_ignoredParentObjects.Contains(_targetParents[firstParentIndex])) { ++firstParentIndex; } else { break; } } if (firstParentIndex == NumTargetParents) { SetOBB(OBB.GetInvalid()); UpdateSnapSteps(); return; } OBB worldOBB = ObjectBounds.CalcHierarchyWorldOBB(_targetParents[firstParentIndex], _boundsQConfig); for (int parentIndex = firstParentIndex; parentIndex < NumTargetParents; ++parentIndex) { GameObject parent = _targetParents[parentIndex]; if (_ignoredParentObjects.Contains(parent)) { continue; } OBB obb = ObjectBounds.CalcHierarchyWorldOBB(parent, _boundsQConfig); if (obb.IsValid) { if (worldOBB.IsValid) { worldOBB.Encapsulate(obb); } else { worldOBB = obb; } } } SetOBB(worldOBB); UpdateSnapSteps(); } }