private void UpdateTransform(Camera camera)
        {
            Vector3            midAxisPos       = _sceneGizmo.SceneGizmoCamera.LookAtPoint;
            RTSceneGizmoCamera sceneGizmoCamera = _sceneGizmo.SceneGizmoCamera;
            Vector3            axisDirection    = _sceneGizmo.Gizmo.Transform.GetAxis3D(_axisDesc);

            _zoomFactorTransform.Position3D = midAxisPos;
            float zoomFactor = _cap.GetZoomFactor(camera);

            Vector3 midCapSize = _sceneGizmo.LookAndFeel.MidCapType == GizmoCap3DType.Box ?
                                 Vector3Ex.FromValue(SceneGizmoLookAndFeel.MidCapBoxSize * zoomFactor) : Vector3Ex.FromValue(SceneGizmoLookAndFeel.MidCapSphereRadius * 2.0f * zoomFactor);
            Vector3 midBoxFaceCenter = BoxMath.CalcBoxFaceCenter(midAxisPos, midCapSize, Quaternion.identity, _midAxisBoxFace);

            _cap.CapSlider3DInvert(axisDirection, midBoxFaceCenter);
        }
Example #2
0
        private void UpdateExtrudeSliderTransforms()
        {
            Vector3    center   = BoxCenter;
            Quaternion rotation = BoxRotation;

            _leftExtrude.StartPosition = BoxMath.CalcBoxFaceCenter(center, _boxSize, rotation, BoxFace.Left);
            _leftExtrude.SetDirection(-BoxRight);

            _rightExtrude.StartPosition = BoxMath.CalcBoxFaceCenter(center, _boxSize, rotation, BoxFace.Right);
            _rightExtrude.SetDirection(BoxRight);

            _upExtrude.StartPosition = BoxMath.CalcBoxFaceCenter(center, _boxSize, rotation, BoxFace.Top);
            _upExtrude.SetDirection(BoxUp);

            _bottomExtrude.StartPosition = BoxMath.CalcBoxFaceCenter(center, _boxSize, rotation, BoxFace.Bottom);
            _bottomExtrude.SetDirection(-BoxUp);

            _backExtrude.StartPosition = BoxMath.CalcBoxFaceCenter(center, _boxSize, rotation, BoxFace.Front);
            _backExtrude.SetDirection(-BoxLook);

            _frontExtrude.StartPosition = BoxMath.CalcBoxFaceCenter(center, _boxSize, rotation, BoxFace.Back);
            _frontExtrude.SetDirection(BoxLook);
        }
        private List <AABB> BuildVertOverlapAABBs(GameObject gameObject, Sprite sprite, RTMesh rtMesh)
        {
            if (sprite == null && rtMesh == null)
            {
                return(new List <AABB>());
            }

            const float overlapAmount     = 0.2f;
            float       halfOverlapAmount = overlapAmount * 0.5f;
            AABB        modelAABB         = sprite != null?ObjectBounds.CalcSpriteModelAABB(gameObject) : rtMesh.AABB;

            Vector3        modelAABBSize  = modelAABB.Size;
            List <BoxFace> modelAABBFaces = BoxMath.AllBoxFaces;

            const float sizeEps = 0.001f;

            Vector3[] overlapAABBSizes = new Vector3[modelAABBFaces.Count];
            overlapAABBSizes[(int)BoxFace.Left]   = new Vector3(overlapAmount, modelAABBSize.y + sizeEps, modelAABBSize.z + sizeEps);
            overlapAABBSizes[(int)BoxFace.Right]  = new Vector3(overlapAmount, modelAABBSize.y + sizeEps, modelAABBSize.z + sizeEps);
            overlapAABBSizes[(int)BoxFace.Bottom] = new Vector3(modelAABBSize.x + sizeEps, overlapAmount, modelAABBSize.z + sizeEps);
            overlapAABBSizes[(int)BoxFace.Top]    = new Vector3(modelAABBSize.x + sizeEps, overlapAmount, modelAABBSize.z + sizeEps);
            overlapAABBSizes[(int)BoxFace.Back]   = new Vector3(modelAABBSize.x + sizeEps, modelAABBSize.y + sizeEps, overlapAmount);
            overlapAABBSizes[(int)BoxFace.Front]  = new Vector3(modelAABBSize.x + sizeEps, modelAABBSize.y + sizeEps, overlapAmount);

            var overlapAABBs = new List <AABB>();

            for (int boxFaceIndex = 0; boxFaceIndex < modelAABBFaces.Count; ++boxFaceIndex)
            {
                BoxFace modelAABBFace = modelAABBFaces[boxFaceIndex];
                Vector3 faceCenter    = BoxMath.CalcBoxFaceCenter(modelAABB.Center, modelAABB.Size, Quaternion.identity, modelAABBFace);
                Vector3 faceNormal    = BoxMath.CalcBoxFaceNormal(modelAABB.Center, modelAABB.Size, Quaternion.identity, modelAABBFace);
                Vector3 overlapCenter = faceCenter - faceNormal * halfOverlapAmount;
                overlapAABBs.Add(new AABB(overlapCenter, overlapAABBSizes[boxFaceIndex]));
            }

            return(overlapAABBs);
        }
Example #4
0
        public override void OnGizmoAttemptHandleDragBegin(int handleId)
        {
            if (OwnsHandle(handleId))
            {
                _scaleFromCenter = Hotkeys.EnableCenterPivot.IsActive();
                _scaleDragWorkData.DragOrigin = BoxCenter;

                if (handleId == _leftTick.HandleId)
                {
                    _scaleDragWorkData.Axis        = -BoxRight;
                    _scaleDragWorkData.AxisIndex   = 0;
                    _scaleDragWorkData.SnapStep    = Settings3D.XSnapStep;
                    _scaleDragWorkData.EntityScale = _targetHierarchyTransform.lossyScale.x;
                    _scalePivot = BoxMath.CalcBoxFaceCenter(BoxCenter, _boxSize, BoxRotation, BoxFace.Right);
                }
                else
                if (handleId == _rightTick.HandleId)
                {
                    _scaleDragWorkData.Axis        = BoxRight;
                    _scaleDragWorkData.AxisIndex   = 0;
                    _scaleDragWorkData.SnapStep    = Settings3D.XSnapStep;
                    _scaleDragWorkData.EntityScale = _targetHierarchyTransform.lossyScale.x;
                    _scalePivot = BoxMath.CalcBoxFaceCenter(BoxCenter, _boxSize, BoxRotation, BoxFace.Left);
                }
                else
                if (handleId == _topTick.HandleId)
                {
                    _scaleDragWorkData.Axis        = BoxUp;
                    _scaleDragWorkData.AxisIndex   = 1;
                    _scaleDragWorkData.SnapStep    = Settings3D.YSnapStep;
                    _scaleDragWorkData.EntityScale = _targetHierarchyTransform.lossyScale.y;
                    _scalePivot = BoxMath.CalcBoxFaceCenter(BoxCenter, _boxSize, BoxRotation, BoxFace.Bottom);
                }
                else
                if (handleId == _bottomTick.HandleId)
                {
                    _scaleDragWorkData.Axis        = -BoxUp;
                    _scaleDragWorkData.AxisIndex   = 1;
                    _scaleDragWorkData.SnapStep    = Settings3D.YSnapStep;
                    _scaleDragWorkData.EntityScale = _targetHierarchyTransform.lossyScale.y;
                    _scalePivot = BoxMath.CalcBoxFaceCenter(BoxCenter, _boxSize, BoxRotation, BoxFace.Top);
                }
                else
                if (handleId == _frontTick.HandleId)
                {
                    _scaleDragWorkData.Axis        = -BoxLook;
                    _scaleDragWorkData.AxisIndex   = 2;
                    _scaleDragWorkData.SnapStep    = Settings3D.ZSnapStep;
                    _scaleDragWorkData.EntityScale = _targetHierarchyTransform.lossyScale.z;
                    _scalePivot = BoxMath.CalcBoxFaceCenter(BoxCenter, _boxSize, BoxRotation, BoxFace.Back);
                }
                else
                if (handleId == _backTick.HandleId)
                {
                    _scaleDragWorkData.Axis        = BoxLook;
                    _scaleDragWorkData.AxisIndex   = 2;
                    _scaleDragWorkData.SnapStep    = Settings3D.ZSnapStep;
                    _scaleDragWorkData.EntityScale = _targetHierarchyTransform.lossyScale.z;
                    _scalePivot = BoxMath.CalcBoxFaceCenter(BoxCenter, _boxSize, BoxRotation, BoxFace.Front);
                }

                if (_scaleFromCenter)
                {
                    _scalePivot = BoxCenter;
                }
                _scaleDrag.SetWorkData(_scaleDragWorkData);

                if (BoxUsage == Usage.ObjectScale && _targetHierarchyTransform != null)
                {
                    _dragBeginTargetTransformSnapshot.Snapshot(_targetHierarchyTransform);
                }
            }
        }
Example #5
0
        public void SetFaceCenter(BoxFace boxFace, Vector3 newCenter)
        {
            Vector3 currentFaceCenter = BoxMath.CalcBoxFaceCenter(_center, _size, _rotation, boxFace);

            Center = newCenter + (_center - currentFaceCenter);
        }
Example #6
0
 public Vector3 GetFaceCenter(BoxFace boxFace)
 {
     return(BoxMath.CalcBoxFaceCenter(_center, _size, _rotation, boxFace));
 }
Example #7
0
        public static List <Vector3> CollectHierarchyVerts(GameObject root, BoxFace collectFace, float collectBoxScale, float collectEps)
        {
            List <GameObject> meshObjects   = root.GetMeshObjectsInHierarchy();
            List <GameObject> spriteObjects = root.GetSpriteObjectsInHierarchy();

            if (meshObjects.Count == 0 && spriteObjects.Count == 0)
            {
                return(new List <Vector3>());
            }

            ObjectBounds.QueryConfig boundsQConfig = new ObjectBounds.QueryConfig();
            boundsQConfig.ObjectTypes = GameObjectType.Mesh | GameObjectType.Sprite;

            OBB hierarchyOBB = ObjectBounds.CalcHierarchyWorldOBB(root, boundsQConfig);

            if (!hierarchyOBB.IsValid)
            {
                return(new List <Vector3>());
            }

            int     faceAxisIndex = BoxMath.GetFaceAxisIndex(collectFace);
            Vector3 faceCenter    = BoxMath.CalcBoxFaceCenter(hierarchyOBB.Center, hierarchyOBB.Size, hierarchyOBB.Rotation, collectFace);
            Vector3 faceNormal    = BoxMath.CalcBoxFaceNormal(hierarchyOBB.Center, hierarchyOBB.Size, hierarchyOBB.Rotation, collectFace);

            float   sizeEps         = collectEps * 2.0f;
            Vector3 collectAABBSize = hierarchyOBB.Size;

            collectAABBSize[faceAxisIndex]            = (hierarchyOBB.Size[faceAxisIndex] * collectBoxScale) + sizeEps;
            collectAABBSize[(faceAxisIndex + 1) % 3] += sizeEps;
            collectAABBSize[(faceAxisIndex + 2) % 3] += sizeEps;

            OBB collectOBB = new OBB(faceCenter + faceNormal * (-collectAABBSize[faceAxisIndex] * 0.5f + collectEps), collectAABBSize);

            collectOBB.Rotation = hierarchyOBB.Rotation;

            List <Vector3> collectedVerts = new List <Vector3>(80);

            foreach (GameObject meshObject in meshObjects)
            {
                Mesh   mesh   = meshObject.GetMesh();
                RTMesh rtMesh = RTMeshDb.Get.GetRTMesh(mesh);
                if (rtMesh == null)
                {
                    continue;
                }

                List <Vector3> verts = rtMesh.OverlapVerts(collectOBB, meshObject.transform);
                if (verts.Count != 0)
                {
                    collectedVerts.AddRange(verts);
                }
            }

            foreach (GameObject spriteObject in spriteObjects)
            {
                List <Vector3> verts = CollectWorldSpriteVerts(spriteObject.GetSprite(), spriteObject.transform, collectOBB);
                if (verts.Count != 0)
                {
                    collectedVerts.AddRange(verts);
                }
            }

            return(collectedVerts);
        }