Esempio n. 1
0
    private void Init()
    {
        CreatBoundingBoxRoot(flattenAxis);

        BoundingBoxRoot       = new BoundingBoxRoot(this);
        CornerBoundingBoxRoot = new CornerBoundingBoxRoot(this);
        SideBoundingBoxRoot   = new SideBoundingBoxRoot(this);
        FaceBoundingBoxRoot   = new FaceBoundingBoxRoot(this);

        BoundingBoxRoot.Init();
        CornerBoundingBoxRoot.Init();
        SideBoundingBoxRoot.Init();
        FaceBoundingBoxRoot.Init();

        if (BoundingBoxRootList == null)
        {
            BoundingBoxRootList = new List <IBoundingBoxRoot>();
            BoundingBoxRootList.Add(BoundingBoxRoot);
            BoundingBoxRootList.Add(CornerBoundingBoxRoot);
            BoundingBoxRootList.Add(SideBoundingBoxRoot);
            BoundingBoxRootList.Add(FaceBoundingBoxRoot);
        }

        if (ActivationType == BoundingBoxActivationType.ActivateOnStart)
        {
            SetVisibility(true);
        }
        else
        {
            SetVisibility(false);
        }
    }
Esempio n. 2
0
    private void ReCreateVisual()
    {
        if (boundingBox.CornerBoundingBoxRoot == null)
        {
            return;
        }

        handles = new FaceHandle[FACE_NUM];
        for (int i = 0; i < FACE_NUM; i++)
        {
            handles[i] = new FaceHandle();
        }

        CornerBoundingBoxRoot cornerBoundingBoxRoot = boundingBox.CornerBoundingBoxRoot;

        handles[0].localPosition = (cornerBoundingBoxRoot.handles[0].localPosition + cornerBoundingBoxRoot.handles[3].localPosition) * 0.5f;
        handles[1].localPosition = (cornerBoundingBoxRoot.handles[3].localPosition + cornerBoundingBoxRoot.handles[6].localPosition) * 0.5f;
        handles[2].localPosition = (cornerBoundingBoxRoot.handles[5].localPosition + cornerBoundingBoxRoot.handles[6].localPosition) * 0.5f;
        handles[3].localPosition = (cornerBoundingBoxRoot.handles[0].localPosition + cornerBoundingBoxRoot.handles[5].localPosition) * 0.5f;
        handles[4].localPosition = (cornerBoundingBoxRoot.handles[0].localPosition + cornerBoundingBoxRoot.handles[6].localPosition) * 0.5f;
        handles[5].localPosition = (cornerBoundingBoxRoot.handles[1].localPosition + cornerBoundingBoxRoot.handles[7].localPosition) * 0.5f;

        handles[0].axis = BoundingBox.AxisType.NZ;
        handles[1].axis = BoundingBox.AxisType.Y;
        handles[2].axis = BoundingBox.AxisType.Z;
        handles[3].axis = BoundingBox.AxisType.NY;
        handles[4].axis = BoundingBox.AxisType.NX;
        handles[5].axis = BoundingBox.AxisType.X;

        for (int i = 0; i < FACE_NUM; i++)
        {
            string rootName = "FacePointRoot_" + i.ToString();

            Transform existRoot = boundingBox.BoundingBoxContainer.Find(rootName);
            if (existRoot != null)
            {
                GameObject.Destroy(existRoot.gameObject);
            }

            handles[i].root = new GameObject("FacePointRoot_" + i).transform;
            handles[i].root.transform.parent        = boundingBox.BoundingBoxContainer;
            handles[i].root.transform.localPosition = handles[i].localPosition;
            handles[i].root.transform.localRotation = Quaternion.identity;

            handles[i].visual = boundingBox.facePrefab == null?GameObject.CreatePrimitive(PrimitiveType.Cube) : GameObject.Instantiate(boundingBox.facePrefab);

            handles[i].visual.name = "visuals";

            if (handles[i].visual.GetComponent <Collider>())
            {
                GameObject.Destroy(handles[i].visual.GetComponent <Collider>());
            }

            handles[i].bounds = BoundingBoxUtils.GetMaxBounds(handles[i].visual);
            float maxDim   = Mathf.Max(Mathf.Max(handles[i].bounds.size.x, handles[i].bounds.size.y), handles[i].bounds.size.z);
            float invScale = boundingBox.AxisScaleHandleSize / maxDim;

            handles[i].visual.transform.parent        = handles[i].root.transform;
            handles[i].visual.transform.localScale    = new Vector3(invScale, invScale, invScale);
            handles[i].visual.transform.localPosition = Vector3.zero;
            handles[i].visual.transform.localRotation = Quaternion.identity;

            Bounds bounds = new Bounds(handles[i].bounds.center * invScale, handles[i].bounds.size * invScale);

            BoxCollider collider = handles[i].root.gameObject.AddComponent <BoxCollider>();
            collider.size   = bounds.size;
            collider.center = bounds.center;

            handles[i].root.gameObject.AddComponent <NearInterationGrabbable>();

            var cursorBehavoir = handles[i].root.gameObject.AddComponent <CursorBehavoir>();
            cursorBehavoir.positionBehavoir = CursorBehavoir.PositionBehavoir.AnchorPosition3D;
            cursorBehavoir.visualBehavoir   = CursorBehavoir.VisualBehavoir.Scale;
        }
    }
Esempio n. 3
0
    private void ReCreateVisual()
    {
        if (boundingBox.CornerBoundingBoxRoot == null)
        {
            return;
        }

        handles = new SideHandle[SIDE_NUM];
        for (int i = 0; i < SIDE_NUM; i++)
        {
            handles[i] = new SideHandle();
        }

        CornerBoundingBoxRoot cornerBoundingBoxRoot = boundingBox.CornerBoundingBoxRoot;

        handles[0].localPosition = (cornerBoundingBoxRoot.handles[0].localPosition + cornerBoundingBoxRoot.handles[1].localPosition) * 0.5f;
        handles[1].localPosition = (cornerBoundingBoxRoot.handles[0].localPosition + cornerBoundingBoxRoot.handles[2].localPosition) * 0.5f;
        handles[2].localPosition = (cornerBoundingBoxRoot.handles[3].localPosition + cornerBoundingBoxRoot.handles[2].localPosition) * 0.5f;
        handles[3].localPosition = (cornerBoundingBoxRoot.handles[3].localPosition + cornerBoundingBoxRoot.handles[1].localPosition) * 0.5f;

        handles[4].localPosition = (cornerBoundingBoxRoot.handles[4].localPosition + cornerBoundingBoxRoot.handles[5].localPosition) * 0.5f;
        handles[5].localPosition = (cornerBoundingBoxRoot.handles[4].localPosition + cornerBoundingBoxRoot.handles[6].localPosition) * 0.5f;
        handles[6].localPosition = (cornerBoundingBoxRoot.handles[7].localPosition + cornerBoundingBoxRoot.handles[6].localPosition) * 0.5f;
        handles[7].localPosition = (cornerBoundingBoxRoot.handles[7].localPosition + cornerBoundingBoxRoot.handles[5].localPosition) * 0.5f;

        handles[8].localPosition  = (cornerBoundingBoxRoot.handles[0].localPosition + cornerBoundingBoxRoot.handles[4].localPosition) * 0.5f;
        handles[9].localPosition  = (cornerBoundingBoxRoot.handles[1].localPosition + cornerBoundingBoxRoot.handles[5].localPosition) * 0.5f;
        handles[10].localPosition = (cornerBoundingBoxRoot.handles[2].localPosition + cornerBoundingBoxRoot.handles[6].localPosition) * 0.5f;
        handles[11].localPosition = (cornerBoundingBoxRoot.handles[3].localPosition + cornerBoundingBoxRoot.handles[7].localPosition) * 0.5f;

        handles[0].axis  = BoundingBox.AxisType.X;
        handles[1].axis  = BoundingBox.AxisType.Y;
        handles[2].axis  = BoundingBox.AxisType.X;
        handles[3].axis  = BoundingBox.AxisType.Y;
        handles[4].axis  = BoundingBox.AxisType.X;
        handles[5].axis  = BoundingBox.AxisType.Y;
        handles[6].axis  = BoundingBox.AxisType.X;
        handles[7].axis  = BoundingBox.AxisType.Y;
        handles[8].axis  = BoundingBox.AxisType.Z;
        handles[9].axis  = BoundingBox.AxisType.Z;
        handles[10].axis = BoundingBox.AxisType.Z;
        handles[11].axis = BoundingBox.AxisType.Z;

        for (int i = 0; i < SIDE_NUM; i++)
        {
            string rootName = "MidpointRoot_" + i.ToString();

            Transform existRoot = boundingBox.BoundingBoxContainer.Find(rootName);
            if (existRoot != null)
            {
                GameObject.Destroy(existRoot.gameObject);
            }

            handles[i].root = new GameObject("MidpointRoot_" + i).transform;
            handles[i].root.transform.parent        = boundingBox.BoundingBoxContainer;
            handles[i].root.transform.localPosition = handles[i].localPosition;
            handles[i].root.transform.localRotation = Quaternion.identity;

            handles[i].visual = boundingBox.SidePrefab == null?GameObject.CreatePrimitive(PrimitiveType.Sphere) : GameObject.Instantiate(boundingBox.SidePrefab);

            handles[i].visual.name = "visuals";

            handles[i].bounds = BoundingBoxUtils.GetMaxBounds(handles[i].visual);
            float maxDim   = Mathf.Max(Mathf.Max(handles[i].bounds.size.x, handles[i].bounds.size.y), handles[i].bounds.size.z);
            float invScale = boundingBox.RotationHandleSize / maxDim;

            handles[i].visual.transform.parent        = handles[i].root.transform;
            handles[i].visual.transform.localScale    = new Vector3(invScale, invScale, invScale);
            handles[i].visual.transform.localPosition = Vector3.zero;
            handles[i].visual.transform.localRotation = Quaternion.identity;

            if (handles[i].axis == BoundingBox.AxisType.X)
            {
                Quaternion realignment = Quaternion.FromToRotation(Vector3.up, Vector3.right);
                handles[i].visual.transform.localRotation = realignment * handles[i].visual.transform.localRotation;
            }
            else if (handles[i].axis == BoundingBox.AxisType.Z)
            {
                Quaternion realignment = Quaternion.FromToRotation(Vector3.up, Vector3.forward);
                handles[i].visual.transform.localRotation = realignment * handles[i].visual.transform.localRotation;
            }

            Bounds bounds = new Bounds(handles[i].bounds.center * invScale, handles[i].bounds.size * invScale);
            if (handles[i].axis == BoundingBox.AxisType.X)
            {
                bounds.size = new Vector3(bounds.size.y, bounds.size.x, bounds.size.z);
            }
            else if (handles[i].axis == BoundingBox.AxisType.Z)
            {
                bounds.size = new Vector3(bounds.size.x, bounds.size.z, bounds.size.y);
            }

            BoxCollider collider = handles[i].root.gameObject.AddComponent <BoxCollider>();
            collider.size   = bounds.size + new Vector3(0.02f, 0.02f, 0.02f);
            collider.center = bounds.center;

            handles[i].root.gameObject.AddComponent <NearInterationGrabbable>();

            var cursorBehavoir = handles[i].root.gameObject.AddComponent <CursorBehavoir>();
            cursorBehavoir.positionBehavoir = CursorBehavoir.PositionBehavoir.AnchorPosition3D;
            cursorBehavoir.visualBehavoir   = CursorBehavoir.VisualBehavoir.Scale;
        }
    }