Beispiel #1
0
        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);
        }
Beispiel #2
0
        public void RefreshPosition()
        {
            if (_targetObjects == null || _gizmo.IsDragged)
            {
                return;
            }

            GizmoTransform gizmoTransform = Gizmo.Transform;

            if (_transformPivot == GizmoObjectTransformPivot.ObjectGroupCenter ||
                _targetPivotObject == null)
            {
                gizmoTransform.Position3D = GetTargetObjectGroupWorldAABB().Center;
            }
            else
            if (_transformPivot == GizmoObjectTransformPivot.ObjectMeshPivot)
            {
                if (_targetPivotObject == null)
                {
                    gizmoTransform.Position3D = GetTargetObjectGroupWorldAABB().Center;
                }
                else
                {
                    gizmoTransform.Position3D = _targetPivotObject.transform.position;
                }
            }
            else
            if (_transformPivot == GizmoObjectTransformPivot.ObjectCenterPivot)
            {
                if (_targetPivotObject == null)
                {
                    gizmoTransform.Position3D = GetTargetObjectGroupWorldAABB().Center;
                }
                else
                {
                    var  boundsQConfig = GetObjectBoundsQConfig();
                    AABB worldAABB     = ObjectBounds.CalcWorldAABB(_targetPivotObject, boundsQConfig);
                    if (worldAABB.IsValid)
                    {
                        gizmoTransform.Position3D = worldAABB.Center;
                    }
                }
            }
            if (_transformPivot == GizmoObjectTransformPivot.CustomWorldPivot)
            {
                gizmoTransform.Position3D = _customWorldPivot;
            }
            else
            if (_transformPivot == GizmoObjectTransformPivot.CustomObjectLocalPivot)
            {
                if (_targetPivotObject == null)
                {
                    gizmoTransform.Position3D = GetTargetObjectGroupWorldAABB().Center;
                }
                else
                {
                    gizmoTransform.Position3D = _targetPivotObject.transform.TransformPoint(GetObjectCustomLocalPivot(_targetPivotObject));
                }
            }
        }
Beispiel #3
0
        public static List <GameObject> GetVisibleObjects(this Camera camera, CameraViewVolume viewVolume)
        {
            // Retrieve the objects which are overlapped by the camera volume's OBB
            List <GameObject> overlappedObjects = RTScene.Get.OverlapBox(viewVolume.WorldOBB);

            if (overlappedObjects.Count == 0)
            {
                return(new List <GameObject>());
            }

            // Loop through each overlapped object
            var boundsQConfig = new ObjectBounds.QueryConfig();

            boundsQConfig.ObjectTypes  = GameObjectTypeHelper.AllCombined;
            boundsQConfig.NoVolumeSize = Vector3Ex.FromValue(1e-5f);

            var visibleObjects = new List <GameObject>(overlappedObjects.Count);

            foreach (var gameObject in overlappedObjects)
            {
                // Retrieve the object's world AABB
                AABB worldAABB = ObjectBounds.CalcWorldAABB(gameObject, boundsQConfig);

                // If the AABB is valid and if the camera's view volume intersects the AABB,
                // it means we are dealing with a visible object so we store it inside the
                // output list.
                if (worldAABB.IsValid && viewVolume.CheckAABB(worldAABB))
                {
                    visibleObjects.Add(gameObject);
                }
            }

            return(visibleObjects);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
 private void ScaleObjects(Vector3 scaleFactor)
 {
     if (TransformPivot == GizmoObjectTransformPivot.ObjectGroupCenter)
     {
         foreach (var trParent in _transformableParents)
         {
             ScaleObject(trParent, scaleFactor, _targetGroupAABBOnDragBegin.Center);
         }
     }
     else
     if (TransformPivot == GizmoObjectTransformPivot.ObjectMeshPivot)
     {
         foreach (var trParent in _transformableParents)
         {
             ScaleObject(trParent, scaleFactor, trParent.transform.position);
         }
     }
     else
     if (TransformPivot == GizmoObjectTransformPivot.CustomWorldPivot)
     {
         foreach (var trParent in _transformableParents)
         {
             ScaleObject(trParent, scaleFactor, CustomWorldPivot);
         }
     }
     else
     if (TransformPivot == GizmoObjectTransformPivot.ObjectCenterPivot)
     {
         var boundsQConfig = GetObjectBoundsQConfig();
         foreach (var trParent in _transformableParents)
         {
             AABB worldAABB = ObjectBounds.CalcWorldAABB(trParent, boundsQConfig);
             if (worldAABB.IsValid)
             {
                 ScaleObject(trParent, scaleFactor, worldAABB.Center);
             }
         }
     }
     else
     if (TransformPivot == GizmoObjectTransformPivot.CustomObjectLocalPivot)
     {
         foreach (var trParent in _transformableParents)
         {
             Transform objectTransform = trParent.transform;
             Vector3   worldPivot      = objectTransform.TransformPoint(GetObjectCustomLocalPivot(trParent));
             ScaleObject(trParent, scaleFactor, worldPivot);
         }
     }
 }
 private void RotateObjects(Quaternion rotation)
 {
     if (TransformPivot == GizmoObjectTransformPivot.ObjectGroupCenter)
     {
         foreach (GameObject trParent in _transformableParents)
         {
             RotateObject(trParent, rotation, _targetGroupAABBOnDragBegin.Center);
         }
     }
     else
     if (TransformPivot == GizmoObjectTransformPivot.ObjectMeshPivot)
     {
         foreach (GameObject trParent in _transformableParents)
         {
             RotateObject(trParent, rotation, trParent.transform.position);
         }
     }
     else
     if (TransformPivot == GizmoObjectTransformPivot.CustomWorldPivot)
     {
         foreach (GameObject trParent in _transformableParents)
         {
             RotateObject(trParent, rotation, CustomWorldPivot);
         }
     }
     else
     if (TransformPivot == GizmoObjectTransformPivot.ObjectCenterPivot)
     {
         ObjectBounds.QueryConfig boundsQConfig = GetObjectBoundsQConfig();
         foreach (GameObject trParent in _transformableParents)
         {
             AABB worldAABB = ObjectBounds.CalcWorldAABB(trParent, boundsQConfig);
             if (worldAABB.IsValid)
             {
                 RotateObject(trParent, rotation, worldAABB.Center);
             }
         }
     }
     else
     if (TransformPivot == GizmoObjectTransformPivot.CustomObjectLocalPivot)
     {
         foreach (GameObject trParent in _transformableParents)
         {
             Transform objectTransform = trParent.transform;
             Vector3   worldPivot      = objectTransform.TransformPoint(GetObjectCustomLocalPivot(trParent));
             RotateObject(trParent, rotation, worldPivot);
         }
     }
 }
Beispiel #7
0
        public void OnObjectTransformChanged(Transform objectTransform)
        {
            ObjectBounds.QueryConfig boundsQConfig = new ObjectBounds.QueryConfig();
            boundsQConfig.ObjectTypes  = GameObjectTypeHelper.AllCombined;
            boundsQConfig.NoVolumeSize = Vector3Ex.FromValue(RTScene.Get.Settings.NonMeshObjectSize);

            AABB   worldAABB   = ObjectBounds.CalcWorldAABB(objectTransform.gameObject, boundsQConfig);
            Sphere worldSphere = new Sphere(worldAABB);

            SphereTreeNode <GameObject> objectNode = _objectToNode[objectTransform.gameObject];

            objectNode.Sphere = worldSphere;

            _objectTree.OnNodeSphereUpdated(objectNode);
            RTFocusCamera.Get.SetObjectVisibilityDirty();
        }
Beispiel #8
0
        public void RegisterObject(GameObject gameObject)
        {
            if (!CanRegisterObject(gameObject))
            {
                return;
            }

            ObjectBounds.QueryConfig boundsQConfig = new ObjectBounds.QueryConfig();
            boundsQConfig.ObjectTypes  = GameObjectTypeHelper.AllCombined;
            boundsQConfig.NoVolumeSize = Vector3Ex.FromValue(RTScene.Get.Settings.NonMeshObjectSize);

            AABB   worldAABB   = ObjectBounds.CalcWorldAABB(gameObject, boundsQConfig);
            Sphere worldSphere = new Sphere(worldAABB);

            SphereTreeNode <GameObject> objectNode = _objectTree.AddNode(gameObject, worldSphere);

            _objectToNode.Add(gameObject, objectNode);

            RTFocusCamera.Get.SetObjectVisibilityDirty();
        }