public void UpdateState()
        {
            if (alreadySelected)
            {
                return;
            }
            List <SelectWall> wallCandidates = ReconstructManager.Instance.GetWallCandidate();

            HTC.UnityPlugin.Utility.RigidPose rightHandPose = VivePose.GetPose(HandRole.RightHand);
            Matrix4x4  matRot       = Matrix4x4.Rotate(rightHandPose.rot);
            Vector3    rightArmPos  = rightHandPose.pos;
            Vector3    rightHandDir = matRot.GetColumn(2);
            RaycastHit hit;
            int        hitLayer = (1 << ARRender.UnityRenderOnTopNoShadowLayer);

            if (Physics.Raycast(rightArmPos, rightHandDir, out hit, 99999, hitLayer))
            {
                foreach (SelectWall wall in wallCandidates)
                {
                    int hashL = wall.selectWall.GetHashCode();
                    int hashH = hit.collider.gameObject.GetHashCode();
                    if (hashL == hashH)
                    {
                        wall.SetSelectColor();

                        bool triggerpress = ViveInput.GetPress(HandRole.RightHand, ControllerButton.Trigger);
                        if (triggerpress)
                        {
                            GameObject finalWall = ReconstructManager.SetPivotInMeshCenter(
                                wall.origWall.transform,
                                wall.origWall.GetComponent <MeshCollider>().sharedMesh,
                                ReconstructManager.Instance.selectedWallRoot.transform,
                                ReconstructManager.Instance.selectWallMaterial,
                                wall.origWall.name + "_convexWall : " + wall.area,
                                wall.normal, wall.center);

                            finalWall.layer = AdvanceRender.ScanLiveMeshLayer;
                            break;
                        }
                    }
                }
            }

            alreadySelected = CheckSelectDone(wallCandidates);
        }
Exemplo n.º 2
0
        public void StartPaintBallWallGame()
        {
            //if (PaintBallWallGameSizePlaneOrigScale == null)
            //    PaintBallWallGameSizePlaneOrigScale = PaintBallWallGameSizePlane.lossyScale.z;
            float origW = measureSizeQuad.transform.lossyScale.x; //2.8f;// original W, H is 2.8 , 1.6

            origW = origW * 3f / 7f;                              // 3x2 block size of 7x4 size
            Vector3 newNearPoint, newFarPoint;

            //PaintBallWallGameObj.SetActive(true);

            Debug.LogWarning("[StartPaintBallWallGame]");

            float     localScale     = 1;
            Transform fishHidingWall = fishAI.fishHidingWall;

            if (fishHidingWall == null)
            {
                fishHidingWall = ReconstructManager.Instance.selectedWallRoot.transform.GetChild(0);
            }

            //float areaQuadMax, areaQuadMin;
            //Mesh quadMesh = fishHidingWall.GetChild(0).GetComponent<MeshFilter>().sharedMesh;
            Mesh      quadMesh      = fishHidingWall.GetComponent <MeshFilter>().sharedMesh;
            Transform quadTransform = fishHidingWall;//.GetChild(0);
            float     destW         = 0;

            if (fishHidingWall != null)
            {
                PaintBallWallGameLocation.position = fishHidingWall.position;
                //PaintBallWallGameLocation.rotation = fishHidingWall.rotation;

                PaintBallWallGameLocation.LookAt(
                    fishHidingWall.position + GetFaceToPlayerNormal(fishHidingWall.position, fishHidingWall.forward),
                    Vector3.up);

                //Fit quad align with height
                //Because the game quad is W:(10m*0.7), H:(10m*0.4), so fit the height with quadMesh's height

                /*areaQuadMax = -9999;
                 * areaQuadMin = 9999f;
                 * foreach (Vector3 vec in quadMesh.vertices)
                 * {
                 *  //Z is the width
                 *  Vector3 vecWorld = fishHidingWall.TransformPoint(vec);
                 *  if (vecWorld.z > areaQuadMax)
                 *      areaQuadMax = vecWorld.z;
                 *  if (vecWorld.z < areaQuadMin)
                 *      areaQuadMin = vecWorld.z;
                 * }*/
                List <Vector3> widthList = new List <Vector3>();
                for (int a = 0; a < quadMesh.vertices.Length; a++)// ( in quadMesh.vertices)
                {
                    Vector3 vec = quadMesh.vertices[a];
                    vec   = quadTransform.TransformPoint(vec);
                    vec.y = 0;
                    widthList.Add(vec);
                }

                MyHelpMesh.GetLongestLineFromVertices(widthList, null, out newNearPoint, out newFarPoint);

                destW      = (newNearPoint - newFarPoint).magnitude;
                localScale = destW / origW; //Z is the width

                //Furthermore consider the area ratio
                float areaQuad   = ReconstructManager.GetMeshArea(quadMesh);
                float areaConvex = ReconstructManager.GetMeshArea(fishHidingWall.GetComponent <MeshFilter>().sharedMesh);
                localScale *= areaConvex / areaQuad;
            }
            trackerOfMRWall.position = PaintBallWallGameLocation.position + PaintBallWallGameLocation.forward * 0.01f;
            Vector3 lookForward = PaintBallWallGameLocation.forward;

            lookForward.y = 0;
            trackerOfMRWall.LookAt(PaintBallWallGameLocation.position + lookForward.normalized, Vector3.up);

            localScale = Mathf.Clamp(localScale * 0.8f, 0.1f, 1.2f);//limit the max size
            trackerOfMRWall.localScale = Vector3.one * localScale;

            //Get the top offset to align with top edge
            //areaQuadMax = -9999;
            //areaQuadMin = 9999f;
            //foreach (Vector3 vec in quadMesh.vertices)
            //{
            //    //X is the height
            //    Vector3 vecWorld = quadTransform.TransformPoint(vec);
            //    if (vecWorld.y > areaQuadMax)
            //        areaQuadMax = vecWorld.y;
            //    if (vecWorld.y < areaQuadMin)
            //        areaQuadMin = vecWorld.y;
            //}
            List <Vector3> heightList = new List <Vector3>();

            for (int a = 0; a < quadMesh.vertices.Length; a++)// ( in quadMesh.vertices)
            {
                Vector3 vec = quadMesh.vertices[a];
                vec   = quadTransform.TransformPoint(vec);
                vec.x = 0;
                vec.z = 0;
                heightList.Add(vec);
            }
            //float destH = areaQuadMax - areaQuadMin;
            MyHelpMesh.GetLongestLineFromVertices(heightList, null, out newNearPoint, out newFarPoint);
            float destH = (newNearPoint - newFarPoint).magnitude;

            float origH = measureSizeQuad.transform.lossyScale.y; //1.6f * localScale;// original W, H is 2.8 , 1.6

            origH = origH * 2f / 4f;                              // 3x2 block size of 7x4 size
            float offsetH = (destH - origH) * 0.5f;

            //float ratio = destH / destW;
            trackerOfMRWall.position = new Vector3(trackerOfMRWall.position.x, trackerOfMRWall.position.y + offsetH * 0.6f, trackerOfMRWall.position.z);

            //set health position
            Vector3 dir = PaintBallWallGameLocation.position - ARRender.Instance.VRCamera.transform.position;

            dir.y = 0;
            dir.Normalize();
            // float length = dir.magnitude;
            trackerOfHealth.position = ARRender.Instance.VRCamera.transform.position + dir * 1f;
            trackerOfHealth.LookAt(ARRender.Instance.VRCamera.transform, Vector3.up);

            ARRender.Instance.AddUnityrenderWithDepth(trackerOfHealth);
            if (ARRender.ADVANCE_RENDER)
            {
                //We only set PaintObject to render shadow to save shadow render performance
                MyHelpLayer.ReplaceSceneLayer(trackerOfMRWall, LayerMask.NameToLayer("Default"), ARRender.UnityRenderOnTopNoShadowLayer);
                MyHelpLayer.ReplaceSceneLayer(trackerOfMRWall, LayerMask.NameToLayer("PaintObject"), ARRender.UnityRenderOnTopLayer);
            }
            else
            {
                MyHelpLayer.SetSceneLayer(trackerOfMRWall, ARRender.UnityRenderOnTopLayer);
            }

            paintBallStateManger.SetState((int)PaintBallStateManager.PaintBallStateEnum.WAIT_USER_TRIGGER);

            MRWallManager.instance.ResetMRWall();

            //Set directional light
            ARRender.Instance.SetDirectionalLight(fishHidingWall);
        }