コード例 #1
0
    public void OnClickAdjustButton()
    {
        MainConsoleView  view           = GetView <MainConsoleView>();
        MainConsoleModel model          = GetModel <MainConsoleModel>();
        BoundingBoxRig   boundingBoxRig = view.GetComponent <BoundingBoxRig>();

        boundingBoxRig.Activate();
        model.State = MainConsoleStateEnum.Manipulation;
        view.StartAdjust();
    }
コード例 #2
0
    public void OnClickDoneButton()
    {
        MainConsoleView  view           = GetView <MainConsoleView>();
        MainConsoleModel model          = GetModel <MainConsoleModel>();
        BoundingBoxRig   boundingBoxRig = view.GetComponent <BoundingBoxRig>();

        boundingBoxRig.Deactivate();
        model.State = MainConsoleStateEnum.Default;
        view.DoneAdjust();
    }
コード例 #3
0
    void Start()
    {
        clipPlaneQuadBbox       = GetComponent <BoundingBoxRig>();
        HandTranslation         = GetComponent <HandDraggable>();
        HandTranslation.enabled = false;

        ButtonClippingPlaneTranslation.gameObject.SetActive(false);
        ButtonClippingPlaneRotation.gameObject.SetActive(false);
        clipPlaneQuadBbox.Deactivate();
    }
コード例 #4
0
    public void CompleteAdjustProtein()
    {
        if (proteinDisplayerGo == null)
        {
            return;
        }
        BoundingBoxRig boundingBoxRig = proteinDisplayerGo.GetComponent <BoundingBoxRig>();

        boundingBoxRig.Deactivate();
        proteinDisplayerGo.GetComponent <HandDraggable>().enabled = false;
    }
コード例 #5
0
        /// <summary>
        /// Disables <see cref="BoundingBoxRig"/>.
        /// </summary>
        private void DisableBoundingBox()
        {
            if (boundingBoxRig != null)
            {
                // TODO: Destroy AppBar

                // Destroy rig
                Destroy(boundingBoxRig);
                boundingBoxRig = null;
            }
        }
コード例 #6
0
    public void StartAdjustProtein()
    {
        if (proteinDisplayerGo == null)
        {
            return;
        }
        BoundingBoxRig boundingBoxRig = proteinDisplayerGo.GetComponent <BoundingBoxRig>();

        boundingBoxRig.Activate();
        proteinDisplayerGo.GetComponent <HandDraggable>().enabled = true;
    }
コード例 #7
0
        public IEnumerator Initialize(BoundingBoxRig rig)
        {
            while (FindObjectsOfType <BoundingBox>().Length == 0)
            {
                yield return(null);
            }

            while (FindObjectsOfType <AppBar>().Length == 0)
            {
                yield return(null);
            }

            Initialized();
        }
コード例 #8
0
ファイル: AncManager.cs プロジェクト: RickyAvina/Hololens
    public void Hide()
    {
        Origin.GetComponent <MeshRenderer>().enabled = false;   // hide the origin
        Origin.GetComponent <BoxCollider>().enabled  = false;   // disable the collider
        BoundingBoxRig bbr = Origin.GetComponent <BoundingBoxRig>();

        if (bbr)
        {
            bbr.Deactivate();
            bbr.appBarInstance.enabled = false;   // hide app bar
            Origin.GetComponent <HandDraggable>().enabled = false;
        }

        foreach (Transform child in transform)
        {
            child.GetComponent <MeshRenderer>().enabled = false; // hide all of the axis
        }
    }
コード例 #9
0
        /// <summary>
        /// Enables <see cref="BoundingBoxRig"/>.
        /// </summary>
        private void EnableBoundingBox()
        {
            // Make sure not already enabled
            if (boundingBoxRig != null)
            {
                return;
            }

            // Instantiate the bounding box rig
            boundingBoxRig = gameObject.AddComponent <BoundingBoxRig>();

            // Setup the prefabs
            boundingBoxRig.AppBarPrefab      = appBarPrefab;
            boundingBoxRig.BoundingBoxPrefab = boundingBoxPrefab;

            // Disable scaling?
            if ((manipulationMode & ManipulationMode.Scale) != ManipulationMode.Scale)
            {
                boundingBoxRig.ScaleRate = 0;
            }

            // TODO: Add menu buttons
        }
コード例 #10
0
    /// <summary>
    /// Makes any hologram into an interactible one
    /// You can now move, rotate or scale it with your hands
    /// </summary>
    public void MakeBoundingBoxInteractible(GameObject obj)
    {
        Rigidbody body = obj.AddComponent <Rigidbody>();

        body.mass        = 100;
        body.useGravity  = false;
        body.isKinematic = true;

        //Set all the boundingBox rig's settings
        bbRig = obj.AddComponent <BoundingBoxRig>();
        bbRig.ScaleHandleMaterial  = handle;
        bbRig.RotateHandleMaterial = handle;
        bbRig.InteractingMaterial  = handleGrabbed;
        bbRig.BoundingBoxPrefab    = BoundingBoxPrefab;
        bbRig.AppBarPrefab         = AppBarPrefab;

        TwoHandManipulatable twoHand = obj.AddComponent <TwoHandManipulatable>();

        twoHand.HostTransform     = obj.transform;
        twoHand.BoundingBoxPrefab = BoundingBoxPrefab;

        obj.tag = "BoundingBox";
    }
コード例 #11
0
ファイル: AncManager.cs プロジェクト: RickyAvina/Hololens
    public void Show()
    {
        Origin.GetComponent <MeshRenderer>().enabled = true;   // hide the origin
        Origin.GetComponent <BoxCollider>().enabled  = true;   // disable the collider

        BoundingBoxRig bbr = Origin.GetComponent <BoundingBoxRig>();

        if (bbr)
        {
            bbr.Activate();
            bbr.appBarInstance.enabled = false;   // hide app bar
            Origin.GetComponent <HandDraggable>().enabled = true;
        }

        //Origin.GetComponent<BoundingBoxRig>().appBarInstance.enabled = false;   // show app bar. Has been proven to work with false here too
        //Origin.GetComponent<BoundingBoxRig>().Activate();
        //Origin.GetComponent<HandDraggable>().enabled = true;


        foreach (Transform child in transform)
        {
            child.GetComponent <MeshRenderer>().enabled = true; // show all of the axis
        }
    }
コード例 #12
0
    private void ProcessPicture(List <byte> rawbytes)
    {
        MessageParser parser = new MessageParser(rawbytes);

        switch (parser.MessageType)
        {
        case (int)BinaryMessageType.VideoStreamWithCameraTransform:
        {
            GameObject tempCam = new GameObject();
            tempCam.transform.position = new Vector3(parser.CameraPosition.X, parser.CameraPosition.Y, parser.CameraPosition.Z);
            tempCam.transform.rotation = new Quaternion(parser.CameraRotation.X, parser.CameraRotation.Y, parser.CameraRotation.Z, parser.CameraRotation.W);

            float pictureDistance = Camera.main.nearClipPlane + 0.01f;

            RaycastHit spatialMapHit;

            if (SpatialMappingRaycast(tempCam.transform.position, tempCam.transform.forward, out spatialMapHit))
            {
                pictureDistance = spatialMapHit.distance;          //0.05 is a magic number to adjust the real distance
            }

            ShowDrawing(parser.Payload, tempCam.transform, pictureDistance);
        }
        break;

        case (int)BinaryMessageType.Picture:
        {
            ShowPicture(parser.Payload);
        }

        break;

        case (int)BinaryMessageType.SpatialIndicator:
        {
            Vector3    CamPosition = new Vector3(parser.CameraPosition.X, parser.CameraPosition.Y, parser.CameraPosition.Z);
            Quaternion CamRotation = new Quaternion(parser.CameraRotation.X, parser.CameraRotation.Y, parser.CameraRotation.Z, parser.CameraRotation.W);

            int width  = parser.ImageWidth;
            int height = parser.ImageHeight;

            Debug.Log("width: " + width + "  height: " + height);

            GameObject temp = new GameObject();

            temp.transform.position = CamPosition;
            temp.transform.rotation = CamRotation;

            float scaleFactor = 0.001f;

            //float realDistance = height / (2.0f * Mathf.Tan(0.5f * Camera.main.fieldOfView * Mathf.Deg2Rad)) * scaleFactor; //0.001 is the scale of the

            //Debug.Log("realDistance: " + realDistance);

            //realDistance += 0.4f; //magic number to adjust the positon
            float realDistance = 1.50f;

            temp.transform.Translate(Vector3.forward * realDistance, Space.Self);
            Vector3 central = temp.transform.position;

            foreach (RemoteAssistControl.Numerics.Point point in parser.IndicatorPostions)
            {
                Debug.Log("point.x: " + point.x + " point.y: " + point.y);
                temp.transform.position = central;         //reset to central

                //need to compensate indicator's position, 40 is the size of the indicator
                RemoteAssistControl.Numerics.Point realPoint = new RemoteAssistControl.Numerics.Point(point.x, point.y);

                //the origin of the picture if at topleft
                Vector3 translation = new Vector3(((float)realPoint.x + 103 - width / 2) * scaleFactor, (height / 2 - 118 - (float)realPoint.y) * scaleFactor, 0);

                temp.transform.Translate(translation, Space.Self);

                //Debug.Log(" originalCamPosition " + originalCamPosition + " central: " + central + " realpoint: " + realPoint + " translation: " + translation + " new position: " + temp.transform.position);

                //Debug.Log(" cast direction " + (temp.transform.position - originalCamPosition).normalized + " camera forward: " + temp.transform.forward);

                RaycastHit spatialMapHit;
                if (SpatialMappingRaycast(CamPosition, (temp.transform.position - CamPosition).normalized, out spatialMapHit))
                {
                    GameObject indicator = Instantiate(Resources.Load <GameObject>("Prefabs/Arrow"));
                    indicator.transform.position = spatialMapHit.point;
                    indicator.transform.up       = spatialMapHit.normal;

                    indicator.AddComponent <WorldAnchor>();

                    Debug.Log("hitPostioin: " + spatialMapHit.point + " hitNormal: " + spatialMapHit.normal);
                }
            }
        }
        break;

        case (int)BinaryMessageType.Model:
        {
            string fileExtension = parser.FileExtension;

            using (var assetLoaderAsync = new AssetLoaderAsync())
            {
                assetLoaderAsync.LoadFromMemory(parser.Payload, fileExtension, null, null, (loadedGameObject) =>
                    {
                        GameObject BBParent                 = Instantiate(Resources.Load <GameObject>("Prefabs/BBParent"));
                        BBParent.transform.position         = Vector3.zero;
                        loadedGameObject.transform.position = Vector3.zero;
                        loadedGameObject.transform.SetParent(BBParent.transform);

                        BoundingBoxRig bbr = BBParent.GetComponent <BoundingBoxRig>();
                        BoundingBox bb     = bbr.BoundingBoxPrefab;
                        bb.Target          = BBParent;
                        //force BoundingBox to call RefreshTargetBounds, ideally the function should be public
                        bb.RefreshTargetBounds();

                        Vector3 position = bb.TargetBoundsCenter;
                        Vector3 size     = bb.TargetBoundsLocalScale;

                        Debug.Log("TargetBoundsCenter: " + position + "TargetBoundsScale: " + size);

                        //this is tricky, we get the box collider center, and then we need move the bbparent to the position.
                        //in order not to affect the model, we disconnect the bbparent temporarily

                        loadedGameObject.transform.parent = null;
                        BBParent.transform.position       = position;

                        BoxCollider bc = BBParent.EnsureComponent <BoxCollider>();
                        bc.center      = Vector3.zero;
                        bc.size        = size;
                        loadedGameObject.transform.SetParent(BBParent.transform);

                        //scale the model to fit in the fov at the 2 meter position
                        float desiredHeight = 1.5f / (2.0f * Mathf.Tan(0.5f * Camera.main.fieldOfView * Mathf.Deg2Rad));

                        //divide another 2 is because that the RGB camer FOV is 2 times bigger than the real fov
                        float scaleFactor = desiredHeight / Mathf.Max(new float[] { size.x, size.y, size.z }) / 2 / 4;

                        BBParent.transform.position = Camera.main.transform.position;
                        BBParent.transform.rotation = Camera.main.transform.rotation;
                        BBParent.transform.Translate(Vector3.forward * 1.5f, Space.Self);
                        Vector3 directionToTarget   = Camera.main.transform.position - BBParent.transform.position;
                        BBParent.transform.rotation = Quaternion.LookRotation(-directionToTarget);

                        BBParent.transform.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);
                    });
            }
        }
        break;

        default:
            break;
        }
    }
コード例 #13
0
 // Use this for initialization
 void Awake()
 {
     boundingBoxRig     = gameObject.GetComponent <BoundingBoxRig>();
     placeRotateConfirm = gameObject.GetComponent <PlaceRotateConfirm>();
 }
コード例 #14
0
ファイル: PrefabSpawnManager.cs プロジェクト: ntmk/arpdrs
        /// <summary>
        /// Create a prefab instance in the scene, in reaction to data being added to the data model.
        /// </summary>
        /// <param name="dataModel">Object to spawn's data model.</param>
        /// <param name="prefabToInstantiate">Prefab to instantiate.</param>
        /// <param name="parentObject">Parent object under which the prefab should be.</param>
        /// <param name="objectName">Name of the object.</param>
        /// <returns></returns>
        protected virtual GameObject CreatePrefabInstance(SyncSpawnedObject dataModel, GameObject prefabToInstantiate, GameObject parentObject, string objectName)
        {
            GameObject instance = Instantiate(prefabToInstantiate, dataModel.Transform.Position.Value, dataModel.Transform.Rotation.Value);

            instance.transform.localScale = dataModel.Transform.Scale.Value;
            instance.transform.SetParent(parentObject.transform, false);
            instance.gameObject.name = objectName;

            // **************************
            // ****** START BMR CODE ****
            // **************************


            // Find the empty prototypes manager
            GameObject prototypes = GameObject.Find("Prototypes") as GameObject;

            // Close Menu
            menuController.GetComponent <MenuController>().CloseMenu();

            // Load the Bounding box with app bar
            instance.AddComponent <BoundingBoxRig>();

            // Fetch the bounding box script attached to game object
            BoundingBoxRig bbr = instance.GetComponent <BoundingBoxRig>();

            // Set the prefab and materials with the reference attached to load script
            bbr.ScaleHandleMaterial  = scaleHandleMaterial;
            bbr.RotateHandleMaterial = rotateHandleMaterial;
            bbr.InteractingMaterial  = interactingMaterial;
            bbr.BoundingBoxPrefab    = boundingBoxPrefab;
            bbr.AppBarPrefab         = appBarPrefab;

            // Adds the two hand manip script on load
            instance.AddComponent <TwoHandManipulatable>();

            // Adds box collider which allows the model to be selected and moved
            instance.AddComponent <BoxCollider>();

            // Adds Default Values
            instance.AddComponent <DefaultValues>();

            // Handles deleting related objects when networked
            instance.AddComponent <GarbageCollector>();

            //*****Network Debugging Tool*****//
            //instance.AddComponent<NetworkPositionDebugClient>().manager = GameObject.Find("NetworkDebug").GetComponent<NetworkPositionDebugManager>();

            /** TAP TO PLACE DISABLED DUE TO NETWORKING BUG SEE #32 **/
            //instance.AddComponent<TapToPlace>();
            //instance.GetComponent<TapToPlace>().IsBeingPlaced = false;
            //instance.GetComponent<TapToPlace>().AllowMeshVisualizationControl = false;

            // Setup Heiarchy to make deletion easier later on
            GameObject prototype = new GameObject();

            prototype.name = "Prototype";

            instance.transform.parent  = prototype.transform;
            prototype.transform.parent = prototypes.transform;

            // Match the world stage matrix
            prototype.transform.localPosition = new Vector3(0, 0, 3);
            prototype.transform.rotation      = prototypes.transform.rotation;

            // **************************
            // ***** END BMR CODE *******
            // **************************


            // Makes the loaded model a child of prototypes manager
            //instance.transform.parent = prototypes.transform;

            dataModel.GameObject = instance;

            // Set the data model on the various ISyncModelAccessor components of the spawned GameObject
            ISyncModelAccessor[] syncModelAccessors = instance.GetComponentsInChildren <ISyncModelAccessor>(true);
            if (syncModelAccessors.Length <= 0)
            {
                // If no ISyncModelAccessor component exists, create a default one that gives access to the SyncObject instance
                ISyncModelAccessor defaultAccessor = instance.EnsureComponent <DefaultSyncModelAccessor>();
                defaultAccessor.SetSyncModel(dataModel);
            }

            for (int i = 0; i < syncModelAccessors.Length; i++)
            {
                syncModelAccessors[i].SetSyncModel(dataModel);
            }

            // Setup the transform synchronization
            TransformSynchronizer transformSynchronizer = instance.EnsureComponent <TransformSynchronizer>();

            transformSynchronizer.TransformDataModel = dataModel.Transform;

            return(instance);
        }
コード例 #15
0
    public void ActivateBoundingBoxRig()
    {
        BoundingBoxRig boundingBoxRig = proteinDisplayerGo.GetComponent <BoundingBoxRig>();

        boundingBoxRig.Activate();
    }
コード例 #16
0
    private void config(GameObject[] models, NetworkManager nw)
    {
        foreach (GameObject prefab in models)
        {
            if (prefab)
            {
                if (!prefab.GetComponent <NetworkIdentity>())
                {
                    // add network identity
                    NetworkIdentity ni = prefab.AddComponent <NetworkIdentity>();
                    ni.localPlayerAuthority = true;
                }
                // add network tranform

                if (!prefab.GetComponent <NetworkTransform>())
                {
                    NetworkTransform nt = prefab.AddComponent <NetworkTransform>();
                    nt.transformSyncMode = NetworkTransform.TransformSyncMode.SyncTransform;
                    nt.sendInterval      = 0.05f;
                }

                /*
                 * // add Authority
                 * if (!prefab.GetComponent<Authority>()) {
                 *  prefab.AddComponent<Authority>();
                 * }
                 */

                // add rigidbody
                Rigidbody rb = prefab.GetComponent <Rigidbody>();
                if (rb)
                {
                    rb.useGravity  = true;
                    rb.isKinematic = true;
                }
                else
                {
                    rb             = prefab.AddComponent <Rigidbody>();
                    rb.useGravity  = true;
                    rb.isKinematic = true;
                }

                // GazeResponder
                if (prefab.GetComponent <GazeResponder>() == null)
                {
                    prefab.AddComponent <GazeResponder>();
                }

                // MeshRenderer
                if (prefab.GetComponent <MeshRenderer>() == null)
                {
                    prefab.AddComponent <MeshRenderer>();
                }

                // add coilder
                if (!CheckColliderExist(prefab))
                {
                    AddCollider(prefab);
                }

                // TapResponder
                if (prefab.GetComponent <TapResponder>() == null)
                {
                    prefab.AddComponent <TapResponder>();
                }

                // AudioSource
                if (prefab.GetComponent <AudioSource>() == null)
                {
                    AudioSource source = prefab.AddComponent <AudioSource>();
                    source.clip = clip;
                }


                // keywords
                if (prefab.GetComponent <Keywords>() == null)
                {
                    prefab.AddComponent <Keywords>();
                }

                // TwoHandManipulatable
                if (prefab.GetComponent <TwoHandManipulatable>() == null)
                {
                    TwoHandManipulatable twoHand = prefab.AddComponent <TwoHandManipulatable>();
                    twoHand.ManipulationMode  = ManipulationMode.RotateAndScale;
                    twoHand.BoundingBoxPrefab = BoxPrefabs;
                }

                // BoundingBoxRig
                if (prefab.GetComponent <BoundingBoxRig>() == null)
                {
                    BoundingBoxRig box = prefab.AddComponent <BoundingBoxRig>();
                    box.ScaleHandleMaterial  = scaleMaterial;
                    box.RotateHandleMaterial = rotateMaterial;
                    box.InteractingMaterial  = interactMaterial;
                    box.BoundingBoxPrefab    = BoxPrefabs;
                    box.appBarPrefab         = barPrefabs;
                    box.scaleRate            = 3.0f;
                    box.maxScale             = 100.0f;
                }
            }
            nw.spawnPrefabs.Add(prefab);
            ClientScene.RegisterPrefab(prefab);
        }
    }
コード例 #17
0
ファイル: MainConsoleView.cs プロジェクト: WeiyaChen/Proteins
 private void Awake()
 {
     boundingBoxRig = GetComponent <BoundingBoxRig>();
     handDraggable  = GetComponent <HandDraggable>();
     solverHandler  = GetComponent <SolverHandler>();
 }