Пример #1
0
        void _createRenderOnTopCamera()
        {
            //Create None DepthTest Camera, which is clear the depth buffer ,and render mesh on screen top.
            GameObject camObj = new GameObject(VRCamera.name + "_RenderOnTop +" + _UnityRenderOnTopCamOrder);

            camObj.transform.parent = null;
            Vive.Plugin.SR.ViveSR_HMDCameraShifter shifter = camObj.AddComponent <Vive.Plugin.SR.ViveSR_HMDCameraShifter>();

            GameObject eyeObj = new GameObject("eye");

            eyeObj.transform.parent        = camObj.transform;
            eyeObj.transform.localPosition = Vector3.zero;
            eyeObj.transform.localRotation = Quaternion.identity;
            _UnityRenderOnTopCamera        = eyeObj.AddComponent <Camera>();
            _UnityRenderOnTopCamera.CopyFrom(VRCamera);
            _UnityRenderOnTopCamera.cullingMask = (1 << UnityRenderOnTopLayer | 1 << UnityRenderOnTopNoShadowLayer);
            _UnityRenderOnTopCamera.clearFlags  = CameraClearFlags.Depth;
            _UnityRenderOnTopCamera.depth       = VRCamera.depth + _UnityRenderOnTopCamOrder;
            //shifter.TargetCamera = _UnityRenderOnTopCamera;
            bool setTargetCam = MyReflection.SetMemberVariable(shifter, "TargetCamera", _UnityRenderOnTopCamera);

            if (!setTargetCam)
            {
                Debug.LogError("shifter.TargetCamera set fail..._UnityRenderOnTopCamera");
            }

#if ADVANCE_RENDER
            VRCamera.cullingMask = MyHelpLayer.RemoveMaskLayer(VRCamera.cullingMask, UnityRenderOnTopLayer);
            VRCamera.cullingMask = MyHelpLayer.RemoveMaskLayer(VRCamera.cullingMask, UnityRenderOnTopNoShadowLayer);
#else
            //We render AR top model on both camera(VRCamera&UnityRenderOnTopCamera), to produce shadow on VRCamera,
            //and render on top layer to prevent culled by scanned mesh.
            //So, we don't remove VRCamera's UnityRenderOnTop Layer
#endif
        }
Пример #2
0
        public void InitRenderSystem()
        {
            //Get realworld camera image
            DualCameraL.clearFlags      = CameraClearFlags.SolidColor;
            DualCameraL.backgroundColor = Color.clear;
            _dualCameraLRT = DualCameraL.gameObject.AddComponent <CopyCameraImage>();
            _dualCameraLRT.rtRefreshCallback = LDualCamRTRefreshCallback;

            DualCameraR.clearFlags      = CameraClearFlags.SolidColor;
            DualCameraR.backgroundColor = Color.clear;
            _dualCameraRRT = DualCameraR.gameObject.AddComponent <CopyCameraImage>();
            _dualCameraRRT.rtRefreshCallback = RDualCamRTRefreshCallback;

            //Create None DepthTest Camera, which is clear the depth buffer ,and render mesh on screen top.
            _createRenderOnTopCamera();

#if ADVANCE_RENDER
            advanceRender.InitRenderSystem(_dualCameraLRT, _dualCameraRRT);
#endif

            foreach (Transform t in unityrenderWithDepthObject)
            {
                MyHelpLayer.SetSceneLayer(t, ARRender.UnityRenderWithDepthLayer);
            }
            foreach (Transform t in unityrenderWithDepthNoShadowObject)
            {
                MyHelpLayer.SetSceneLayer(t, ARRender.UnityRenderWithDepthNoShadowLayer);
            }
        }
Пример #3
0
 public void RecoverUnityrenderWithDepthLayer()
 {
     foreach (Transform t in unityrenderWithDepthObject)
     {
         MyHelpLayer.SetSceneLayer(t, UnityRenderWithDepthLayer);
     }
 }
Пример #4
0
 public void SetUnityrenderWithDepthToTopLayer()
 {
     foreach (Transform t in unityrenderWithDepthObject)
     {
         MyHelpLayer.SetSceneLayer(t, UnityRenderOnTopLayer);
     }
 }
Пример #5
0
 public void AddUnityrenderWithDepth(Transform t)
 {
     if (unityrenderWithDepthObject.IndexOf(t) < 0)
     {
         unityrenderWithDepthObject.Add(t);
         MyHelpLayer.SetSceneLayer(t, UnityRenderWithDepthLayer);
     }
 }
        IEnumerator _closeRenderAlphaWall()
        {
            yield return(new WaitForSeconds(4));

            for (int a = 0; a < selectedWallRoot.transform.childCount; a++)
            {
                Transform child = selectedWallRoot.transform.GetChild(a);
                ARRender.Instance.RemoveUnityrenderWithDepth(child);
                MyHelpLayer.SetSceneLayer(child, ARRender.MRReconstructObjectLayer);
            }
        }
Пример #7
0
        public void StartGarageSetting()
        {
            VivePoseTracker tracker = LiftMachine.GetComponent <VivePoseTracker>();

            if (tracker.isPoseValid)
            {
                LiftMachine.position = tracker.transform.position;
            }
            //else if (recontructFloor != null && recontructFloor.transform.childCount > 0)
            //    LiftMachinePosition = recontructFloor.transform.GetChild(0).position;
            else
            {
                LiftMachine.position = Vector3.zero;
            }

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

            FixedWorldPosCover[] fwpcs = LiftMachine.GetComponentsInChildren <FixedWorldPosCover>();
            foreach (FixedWorldPosCover fwpc in fwpcs)
            {
                fwpc.UpdateWorldMatrix();
                //    fwpc.GetComponent<Renderer>().sharedMaterial.SetTexture("_LeftEyeTexture", dualCameraLRT.GetRT());
                //    fwpc.GetComponent<Renderer>().sharedMaterial.SetTexture("_RightEyeTexture", dualCameraRRT.GetRT());
                fwpc.GetComponent <Renderer>().sharedMaterial.SetFloat("_Transparent", 1);
            }
            Renderer[] renders = LiftMachine.GetComponentsInChildren <Renderer>(true);
            foreach (Renderer r in renders)
            {
                r.enabled = true;
            }
        }
        void RenderSystemUpdate()
        {
            if (deferredLightMap != null)
            {
                deferredLightMap.ClearAllLights();
                foreach (GameObject lightObj in PointLightObjList)
                {
                    if (!lightObj.activeSelf)
                    {
                        continue;
                    }

                    {
                        Light[] lights = lightObj.GetComponentsInChildren <Light>();
                        foreach (Light l in lights)
                        {
                            deferredLightMap.AddPointLight(l);
                        }
                    }

                    ParticleLights[] particleLights = lightObj.GetComponentsInChildren <ParticleLights>();
                    foreach (ParticleLights pl in particleLights)
                    {
                        if (pl.particleLightNode == null || !pl.particleLightNode.activeSelf)
                        {
                            continue;
                        }
                        Light[] lights = pl.particleLightNode.GetComponentsInChildren <Light>();
                        foreach (Light l in lights)
                        {
                            deferredLightMap.AddPointLight(l);
                        }
                    }
                }
                foreach (GameObject lightObj in SpotLightObjList)
                {
                    if (!lightObj.activeInHierarchy)
                    {
                        continue;
                    }
                    Light[] lights = lightObj.GetComponentsInChildren <Light>();
                    foreach (Light l in lights)
                    {
                        deferredLightMap.AddSpotLight(l);
                    }
                }
            }

            //Alpha blend object render with depth
            if (_UnityRenderWithDepthCamera == null)
            {
                GameObject camObj = new GameObject(ARRender.Instance.VRCamera.name + "_WithDetpth +" + _UnityRenderWithDepthCamOrder);
                camObj.transform.parent = null;
                Vive.Plugin.SR.ViveSR_HMDCameraShifter shifter = camObj.AddComponent <Vive.Plugin.SR.ViveSR_HMDCameraShifter>();

                GameObject eyeObj = new GameObject("eye");
                eyeObj.transform.parent        = camObj.transform;
                eyeObj.transform.localPosition = Vector3.zero;
                eyeObj.transform.localRotation = Quaternion.identity;
                _UnityRenderWithDepthCamera    = eyeObj.AddComponent <Camera>();
                _UnityRenderWithDepthCamera.CopyFrom(ARRender.Instance.VRCamera);
                _UnityRenderWithDepthCamera.cullingMask = 1 << ARRender.UnityRenderWithDepthLayer | 1 << ARRender.UnityRenderWithDepthNoShadowLayer;
                _UnityRenderWithDepthCamera.clearFlags  = CameraClearFlags.Nothing;
                _UnityRenderWithDepthCamera.depth       = ARRender.Instance.VRCamera.depth + _UnityRenderWithDepthCamOrder;
                ARRender.Instance.VRCamera.cullingMask  =
                    MyHelpLayer.RemoveMaskLayer(ARRender.Instance.VRCamera.cullingMask, ARRender.UnityRenderWithDepthLayer);
                ARRender.Instance.VRCamera.cullingMask =
                    MyHelpLayer.RemoveMaskLayer(ARRender.Instance.VRCamera.cullingMask, ARRender.UnityRenderWithDepthNoShadowLayer);
                //shifter.TargetCamera = _UnityRenderWithDepthCamera;
                bool setTargetCam = MyReflection.SetMemberVariable(shifter, "TargetCamera", _UnityRenderWithDepthCamera);
                if (!setTargetCam)
                {
                    Debug.LogError("shifter.TargetCamera set fail..._UnityRenderWithDepthCamera");
                }
            }
        }
        public void InitRenderSystem(CopyCameraImage _dualCameraLRT, CopyCameraImage _dualCameraRRT)
        {
            //Set reconstruct mesh to ScanLiveMeshLayer if exist
            Material reconMeshMat = new Material(Shader.Find("Unlit/Color"));

            reconMeshMat.color = Color.white * 0.5f;
            MeshRenderer[] reconMeshes = SRWorkControl.Instance.GetReconstructStaticMeshes();
            if (reconMeshes != null)
            {
                foreach (MeshRenderer r in reconMeshes)
                {
                    r.gameObject.layer = ScanLiveMeshLayer;
                    r.gameObject.GetComponent <MeshRenderer>().sharedMaterial = reconMeshMat;
                    r.GetComponent <MeshFilter>().mesh.RecalculateNormals();//must RecalculateNormals since original normal is wrong
                }
            }

            //-------------------------------------------------------------------------------------------------
            //Add culling processor
            //-------------------------------------------------------------------------------------------------
            _renderLivemeshDepthN               = ARRender.Instance.VRCamera.gameObject.AddComponent <CameraRenderRT>();
            _renderLivemeshDepthN.RTType        = CameraRenderRT.RTTYPE.FLOAT4;
            _renderLivemeshDepthN.RenderShader  = ScanLiveMeshShaderDepthNormal;
            _renderLivemeshDepthN.cullMask      = 1 << ScanLiveMeshLayer;
            _renderLivemeshDepthN.clearColor    = Color.white;
            _renderLivemeshDepthN.blurHMaterial = new Material(blurHMaterial);
            _renderLivemeshDepthN.blurVMaterial = new Material(blurVMaterial);
            _renderLivemeshDepthN.BlurFactor    = 3f;// 2.7f;//0 turn off blur
            _renderLivemeshDepthN.Init();

            //VRCamera.cullingMask = VRCamera.cullingMask & ~(1 << ScanLiveMeshLayer);//Not render 'LiveMesh' in vr camera
            ARRender.Instance.VRCamera.cullingMask     = MyHelpLayer.RemoveMaskLayer(ARRender.Instance.VRCamera.cullingMask, ScanLiveMeshLayer);
            ARRender.Instance.VRCamera.clearFlags      = CameraClearFlags.Color;
            ARRender.Instance.VRCamera.backgroundColor = new Color(0, 0, 0, 0);

            //Add dilation for later pass 'DownSample' not sample outter edge's black color.
            Dilation dilation = ARRender.Instance.VRCamera.gameObject.AddComponent <Dilation>();

            dilation.dilateCount         = 2;
            dilation.dilateMaskShader    = dilateMaskShader;
            dilation.genBinaryMaskShader = genBinaryMaskShader;
            dilation.refineGBufferShader = refineGBufferShader;

            //Add down sample for matching the low resolution see through camera.
            RTDownSample downsample = _createCameraFilter <RTDownSample>() as RTDownSample;

            downsample.DownScale = 3;

            //Render block pattern for simulate noise for matching low resolution see through camera.
            CamFilterDrawBlocks drawblocks = _createCameraFilter <CamFilterDrawBlocks>() as CamFilterDrawBlocks;

            drawblocks.Fade = 0.003f;

            CopyCameraDepthColor vrdepth = ARRender.Instance.VRCamera.gameObject.AddComponent <CopyCameraDepthColor>();

            vrdepth.CopyCameraDepthColorMaterial = CopyCameraDepthColorMaterial;

#if USE_MERGE_DEPTH
            MergeDepth mergeDepth = ARRender.Instance.VRCamera.gameObject.AddComponent <MergeDepth>();
            mergeDepth.cameraRenderRT       = _renderLivemeshDepthN.RT;
            mergeDepth.mergeDepthMat        = MergeDepthMat;
            mergeDepth.copyCameraColorDepth = vrdepth;
#endif

            SoftEdgeWeight softEdgeWeight = ARRender.Instance.VRCamera.gameObject.AddComponent <SoftEdgeWeight>();
            softEdgeWeight.renderDepth            = _renderLivemeshDepthN;
            softEdgeWeight.SoftEdgeWeightMaterial = softEdgeWeightMaterial;
            softEdgeWeight.factor = 2f;

            RenderWithARDepth renderWithARDepth = ARRender.Instance.VRCamera.gameObject.AddComponent <RenderWithARDepth>();
            renderWithARDepth.RenderWithARDepthMaterial = RenderWithARDepthMaterial;
            renderWithARDepth.MRDepthNormal             = _renderLivemeshDepthN.RT;
            renderWithARDepth.VRCamera       = vrdepth;
            renderWithARDepth.softCullLength = 0.0001f;
            renderWithARDepth.glowAmount     = 0.018f;
            renderWithARDepth.coefAmount     = 0.062f;
            renderWithARDepth.seeThroughL    = _dualCameraLRT;
            renderWithARDepth.seeThroughR    = _dualCameraRRT;
            renderWithARDepth.softEdgeWeight = softEdgeWeight;
            renderWithARDepth.CullingBaise   = 0.000017f;//1.7e-05

            //-------------------------------------------------------------------------------------------------
            //Add shadow processor
            //-------------------------------------------------------------------------------------------------
            ARRender.Instance.shadowCastDirLight.transform.position = ARRender.Instance.VRCamera.transform.position;

            ShadowRecieve shadowRecieve = ARRender.Instance.VRCamera.gameObject.AddComponent <ShadowRecieve>();
            shadowRecieve.ScreenMapScale   = 0.5f;
            shadowRecieve.shadowLight      = ARRender.Instance.shadowCastDirLight;
            shadowRecieve.screenShadowBlit = screenShadowBlit;
            // shadowRecieve.blurMaterial = shadowBlur;
            shadowRecieve.blurHMaterial = new Material(blurHMaterial);
            shadowRecieve.blurVMaterial = new Material(blurVMaterial);
            shadowRecieve.BlurFactor    = 3;
            shadowRecieve.ShadowFactor  = 10;
            shadowRecieve.VRDepthColor  = vrdepth;//set VR scene depth for screen shadow culling (no need recieve mesh's depth)

            shadowRecieve.cameraDepthN = _renderLivemeshDepthN.RT;
            //shadowRecieve.recieveShadowLayer = (1 << ScanLiveMeshLayer);

            GameObject shadowCastCameraObj = Instantiate(shadowCastCameraPrefab);
            shadowCastCameraObj.transform.parent = ARRender.Instance.shadowCastDirLight.transform;
            ShadowCastCamera shadowCastCamera = shadowCastCameraObj.GetComponent <ShadowCastCamera>();
            shadowCastCamera.GetComponent <Camera>().orthographicSize = 4; //4 is enough
            shadowCastCamera.shadowMapSize = 400;

            //cast shadow for default layer
            shadowCastCamera.shadowRenderMask = shadowCastMask;

            //shadowRecieve.shadowColor = Color.white * 50f / 255f;
            shadowRecieve.bais           = 0;
            shadowRecieve.shadowBlitBais = 0;

            //-------------------------------------------------------------------------------------------------
            //Add point light processor
            //-------------------------------------------------------------------------------------------------
            deferredLightMap = ARRender.Instance.VRCamera.gameObject.AddComponent <DeferredLightMap>();
            deferredLightMap.DeferredPointLightMapMaterial = DeferredPointLightMapMaterial;
            deferredLightMap.DeferredSpotLightMapMaterial  = DeferredSpotLightMapMaterial;
            deferredLightMap.BlitLightMapMaterial          = BlitLightMapMaterial;
            deferredLightMap.LightMapFactor = 0.2f;

            //deferredLightMap.mergeDepth = mergeDepth;
            deferredLightMap.cameraRenderDepthNormal = _renderLivemeshDepthN.RT; //not use merge depth, since game objects use unity lighting.

            deferredLightMap.TurnOffUnityLight = false;                          //Dont' turn off unity light, because current time my deferred lighting is not concern normal, and I need unity lighting to render object.


            //-------------------------------------------------------------------------------------------------
            //write Depth Camera and render alpha object
            //-------------------------------------------------------------------------------------------------
            GameObject writeDepthCameraRoot = new GameObject(ARRender.Instance.VRCamera.name + "_writeDepth +" + _writeDepthCamLOrder);
            writeDepthCameraRoot.transform.parent = null;
            Vive.Plugin.SR.ViveSR_HMDCameraShifter shifter = writeDepthCameraRoot.AddComponent <Vive.Plugin.SR.ViveSR_HMDCameraShifter>();
            writeDepthCameraRoot.transform.position = Vector3.zero;
            writeDepthCameraRoot.transform.rotation = Quaternion.identity;

            GameObject writeDepthCameraObj = Instantiate(writeDepthCameraPrefab);
            writeDepthCameraObj.transform.parent        = writeDepthCameraRoot.transform;
            writeDepthCameraObj.transform.localPosition = Vector3.zero;
            writeDepthCameraObj.transform.localRotation = Quaternion.identity;
            _writeDepthCamera       = writeDepthCameraObj.GetComponent <Camera>();
            _writeDepthCamera.depth = ARRender.Instance.VRCamera.depth + _writeDepthCamLOrder;
            _writeDepthCamera.name  = _writeDepthCamera.name + " +" + _writeDepthCamLOrder;
            _writeDepth             = _writeDepthCamera.GetComponent <WriteDepthPerspective>();
            _writeDepth.mainCam     = ARRender.Instance.VRCamera;
            _writeDepth.addShiftR   = 0.00145f;   //0.00807f;
            _writeDepth.addShiftUP  = -0.00005f;; // -0.0001f;
            _writeDepth.Init(0);
            //_writeDepth.IsRenderRightEye = null;
            //shifter.TargetCamera = _writeDepthCamera;
            bool setTargetCam = MyReflection.SetMemberVariable(shifter, "TargetCamera", _writeDepthCamera);
            if (!setTargetCam)
            {
                Debug.LogError("shifter.TargetCamera set fail..._writeDepthCamera");
            }
#if USE_MERGE_DEPTH
            _writeDepth.mergeDepth = mergeDepth;
#else
            _writeDepth.cameraDepth = renderLiveMeshDepthN.RT;
#endif

            ARRender.Instance.shadowCastDirLight.shadowBias = 0.02f;
        }
        public static GameObject SetPivotInMeshCenter(Transform tran, Mesh mesh,
                                                      Transform parentNode, Material colliderMaterial, string name, Vector3 normal, Vector3 position)
        {
            //Duplicate my wall
            GameObject wall = new GameObject(name);// current.colliderMesh.name + " : " + current.area);

            wall.isStatic         = true;
            wall.transform.parent = parentNode;

            //Set pivot in mesh center
            // Transform tran = current.colliderMesh.transform;
            //  Mesh mesh = current.colliderMesh.sharedMesh;

            /*Vector3[] newVert = new Vector3[mesh.vertices.Length];
             * for (int b = 0; b < mesh.vertices.Length; b++)
             * {
             *  newVert[b] = tran.TransformPoint(mesh.vertices[b]) - current.meshCenter;//move pos in world space
             *  newVert[b] = tran.InverseTransformPoint(newVert[b]);//set vertex to local space
             * }*/

            Matrix4x4 origMatrix = tran.localToWorldMatrix;

            wall.transform.position   = position;// current.meshCenter;
            wall.transform.rotation   = (normal == Vector3.zero) ? Quaternion.identity : Quaternion.LookRotation(normal /*current.avgNormalWorld*/, Vector3.up);
            wall.transform.localScale = Vector3.one;
            Matrix4x4 newMatrix = wall.transform.localToWorldMatrix;

            Matrix4x4 offsetMat = Matrix4x4.Inverse(origMatrix) * newMatrix;

            Vector3[] newVert = new Vector3[mesh.vertices.Length];
            for (int b = 0; b < mesh.vertices.Length; b++)
            {
                newVert[b] = offsetMat.inverse.MultiplyPoint(mesh.vertices[b]);
            }

            ////Set normal for collider
            //Vector3[] newVertNormal = new Vector3[newVert.Length];
            //for (int b = 0; b < mesh.triangles.Length; b++)
            //{
            //    newVertNormal[mesh.triangles[b]] += current.triNormal[b % 3];
            //    newVertNormal[mesh.triangles[b]] *= 0.5f;
            //    newVertNormal[mesh.triangles[b]].Normalize();
            //}

            Mesh newM = new Mesh();

            newM.name     = mesh.name;
            newM.vertices = newVert;
            // newM.normals = newVertNormal;//The supplied array needs to be the same size as the Mesh.vertices array.
            newM.uv = null;
            newM.SetTriangles(mesh.triangles, 0);
            newM.RecalculateNormals();

            MeshFilter newMF = wall.AddComponent <MeshFilter>();

            newMF.sharedMesh = newM;
            //MeshCollider newMC = wall.AddComponent<MeshCollider>();
            //newMC.convex = true;
            //newMC.gameObject.isStatic = true;

            if (colliderMaterial != null)
            {
                MeshRenderer newMR = wall.AddComponent <MeshRenderer>();
                newMR.material = colliderMaterial;
            }

            wall.layer = ARRender.MRReconstructObjectLayer;
            ARRender.Instance.VRCamera.cullingMask = MyHelpLayer.RemoveMaskLayer(ARRender.Instance.VRCamera.cullingMask, ARRender.MRReconstructObjectLayer);
            return(wall);
        }
        public void AutoPickFloor()
        {
            List <MeshSizeData> meshSizeDataList;
            List <MeshCollider> ignoreList;

            _getPlanesByMaxArea(reconstructConvexCollidersHorizontal, out meshSizeDataList, out ignoreList);

            //if (recontructTable != null)
            //    Destroy(recontructTable);
            //recontructTable = new GameObject("RecontructTable");

            if (recontructFloor != null)
            {
                Destroy(recontructFloor);
            }
            recontructFloor = new GameObject("RecontructFloor");

            if (floorPlaneObj != null)
            {
                Destroy(floorPlaneObj);
            }
            if (floorPlaneObjCollider != null)
            {
                Destroy(floorPlaneObjCollider);
            }

            //Get the lowest is the floor and y must -0.5~0.5
            MeshSizeData lowestMesh = null;
            float        lowestD    = 9999f;

            for (int a = 0; a < meshSizeDataList.Count; a++)
            {
                if (a >= 3)
                {
                    break;
                }
                MeshSizeData current = meshSizeDataList[a];

                if (current.meshCenterWorld.y < lowestD)
                {
                    //if (-0.6f < current.meshCenterWorld.y && current.meshCenterWorld.y < 0.6f)
                    {
                        lowestD    = current.meshCenterWorld.y;
                        lowestMesh = current;
                    }
                }
            }
            if (lowestMesh != null)
            {
                GameObject floorConvexObj = SetPivotInMeshCenter(
                    lowestMesh.colliderMesh.transform,
                    lowestMesh.colliderMesh.sharedMesh,
                    recontructFloor.transform,
                    null,
                    lowestMesh.colliderMesh.name + "_convex : " + lowestMesh.area,
                    lowestMesh.avgNormalWorld,
                    lowestMesh.meshCenterWorld);
                meshSizeDataList.Remove(lowestMesh);

                //Add floor quad for shadow rendering
                foreach (MeshCollider mc in reconstructQuadCollidersHorizontal)
                {
                    string namesQuad   = mc.name.Remove(0, mc.name.IndexOf('_') + 1);
                    string namesConvex = lowestMesh.colliderMesh.name.Remove(0, lowestMesh.colliderMesh.name.IndexOf('_') + 1);
                    if (namesQuad == namesConvex)
                    {
                        //Vector3[] planeTriNormal;
                        //Vector3 AVGNormalWorld = -_getAVGNormalLocal(mc.sharedMesh, mc.transform, out planeTriNormal);
                        Vector3 center = mc.transform.TransformPoint(_getMeshCenter(mc.sharedMesh));
                        //GameObject floorPlaneObj = SetPivotInMeshCenter(mc.transform, mc.sharedMesh,
                        //                                              floorConvexObj.transform, floorColliderMaterial,
                        //                                              lowestMesh.colliderMesh.name + "_quadFloor",
                        //                                              AVGNormalWorld, center);
                        floorPlaneObj                      = GameObject.CreatePrimitive(PrimitiveType.Plane);
                        floorPlaneObj.name                 = lowestMesh.colliderMesh.name + "_quadFloor";
                        floorPlaneObj.transform.parent     = floorConvexObj.transform;
                        floorPlaneObj.transform.position   = center;
                        floorPlaneObj.transform.rotation   = Quaternion.identity;
                        floorPlaneObj.transform.localScale = Vector3.one * 2;

                        //SRWork 0.7.5.0 use scan mesh collider
                        floorPlaneObj.isStatic = true;

                        floorPlaneObj.layer = AdvanceRender.ScanLiveMeshLayer;
                        if (ARRender.ADVANCE_RENDER)
                        {
                            //In advance render floorPlaneObj is for render, so, we clone a new one for collision
                            floorPlaneObjCollider       = GameObject.Instantiate(floorPlaneObj);
                            floorPlaneObjCollider.layer = AdvanceRender.MRCollisionFloorLayer;
                            floorPlaneObjCollider.transform.position = floorPlaneObj.transform.position;
                            floorPlaneObjCollider.transform.rotation = floorPlaneObj.transform.rotation;
                            ARRender.Instance.VRCamera.cullingMask   = MyHelpLayer.RemoveMaskLayer(ARRender.Instance.VRCamera.cullingMask, AdvanceRender.MRCollisionFloorLayer);
                        }
                        else
                        {
                            floorPlaneObj.GetComponent <MeshRenderer>().sharedMaterial = new Material(Shader.Find("ViveSR/MeshCuller, Shadowed, Stencil"));
                            //floorPlaneObj.GetComponent<MeshRenderer>().enabled = false;
                        }
                        break;
                    }
                }

                //SRWork0.7.5.0 ConvexColliders default is turn off
                //turn off the original convex mesh's collider
                //foreach (MeshCollider mc in reconstructConvexCollidersHorizontal)
                //{
                //    string namesA = mc.name.Remove(0, mc.name.IndexOf('_') + 1);
                //    string namesB = lowestMesh.colliderMesh.name.Remove(0, lowestMesh.colliderMesh.name.IndexOf('_') + 1);
                //    //namesA = namesA.Remove(0, namesA.IndexOf('_'));//srwork 0.7 without '_' again
                //    //namesB = namesB.Remove(0, namesB.IndexOf('_'));
                //    if (namesA == namesB)
                //    {
                //        mc.transform.gameObject.SetActive(false);
                //    }
                //}
            }
            else
            {
                Debug.LogWarning("[reconstructPickFloor] there are no reconstruct floor picked...");
            }

            /*
             *      //Get the highest is the table
             *      MeshSizeData highestMesh = null;
             *      float highestD = -9999f;
             *      for (int a = 0; a < meshSizeDataList.Count; a++)
             *      {
             *          if (a >= 10)
             *              break;
             *          MeshSizeData current = meshSizeDataList[a];
             *          if (current.meshCenterWorld.y > highestD &&
             *              current.meshCenterWorld.y < VRCamera.transform.position.y//must not higher then player's head
             *              )
             *          {
             *              highestD = current.meshCenterWorld.y;
             *              highestMesh = current;
             *          }
             *      }
             *      if (highestMesh != null)
             *      {
             *          SetPivotInMeshCenter(highestMesh.colliderMesh.transform, highestMesh.colliderMesh.sharedMesh,
             *              recontructTable.transform, tableColliderMaterial,
             *              highestMesh.colliderMesh.name + "_convex : " + highestMesh.area,
             *              highestMesh.avgNormalWorld,
             *              highestMesh.meshCenterWorld);
             *          meshSizeDataList.Remove(highestMesh);
             *      }
             *      else
             *          Debug.LogWarning("[reconstructPickFloor] there are no reconstruct table picked...");
             */
        }
        public void UpdateState()
        {
            if (manager.PadTouchL)
            {
                robotController.TurnLeft();
            }
            else if (manager.PadTouchR)
            {
                robotController.TurnRight();
            }

            if (manager.PadKeyUp)
            {
                robotController.Stop();
            }

            if (manager.PadPressL && manager.PadIsFirstPress ||
                manager.PadPressR && manager.PadIsFirstPress)
            {
                robotController.SwitchDiscoLight();
            }

            if (robotController.GetDiscoLightRoot().gameObject.activeSelf)
            {
                MyHelpLayer.SetSceneLayer(robotController.GetDiscoLightRoot(), ARRender.UnityRenderWithDepthNoShadowLayer);
            }

            if (manager.PadPressUpward)
            {
                //robotController.MoveForwrad();
                robotController.stallHigh += Time.deltaTime * 0.9f;
                robotController.stallHigh  = Mathf.Clamp(robotController.stallHigh, 0.5f, 10);
            }
            else if (manager.PadPressDownward)
            {
                //robotController.MoveBack();
                robotController.stallHigh -= Time.deltaTime * 0.9f;
                robotController.stallHigh  = Mathf.Clamp(robotController.stallHigh, 0.5f, 10);
            }

            float triggerRatio = ViveInput.GetTriggerValue(HandRole.RightHand);

            if (triggerRatio > 0)
            {
                if (robotController != null)
                {
                    robotController.MoveForwrad(triggerRatio);
                }
                //Debug.Log("tvalue : " + tvalue);
            }

            if (GameManager.Instance.ViveIsGrip())
            {
                manager.SwitchState(GameStateManager.GameState.GARAGE);
            }

            //Recover to idle state
            if (ViveInput.GetPressUp(HandRole.RightHand, ControllerButton.Trigger) ||
                triggerRatio < 0.01f)
            {
                robotController.Stop();
            }
        }
Пример #13
0
 public void RecoverFishToDefaultLayer()
 {
     MyHelpLayer.ReplaceSceneLayer(fishAI.transform, ARRender.UnityRenderOnTopNoShadowLayer, LayerMask.NameToLayer("Default"));
     MyHelpLayer.ReplaceSceneLayer(fishAI.transform, ARRender.UnityRenderOnTopLayer, LayerMask.NameToLayer("PaintObject"));
     ARRender.Instance.RecoverUnityrenderWithDepthLayer();
 }
Пример #14
0
 public void SetFishToRenderTop()
 {
     MyHelpLayer.ReplaceSceneLayer(fishAI.transform, LayerMask.NameToLayer("Default"), ARRender.UnityRenderOnTopNoShadowLayer);
     MyHelpLayer.ReplaceSceneLayer(fishAI.transform, LayerMask.NameToLayer("PaintObject"), ARRender.UnityRenderOnTopLayer);
     ARRender.Instance.SetUnityrenderWithDepthToTopLayer();
 }
Пример #15
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);
        }