Esempio n. 1
0
 public void RegisterPaintableObject(PBSPaintableObject paintableObject)
 {
     if (paintableObjs == null)
     {
         paintableObjs = new Dictionary <string, PBSPaintableObject>();
     }
     paintableObjs.Add(paintableObject.paintObjectID, paintableObject);
 }
Esempio n. 2
0
        private void UpdateGBufferToTarget()
        {
            RenderGBuffer();
            posMapCam.Render();
            normalMapCam.Render();

            PBSPaintableObject paintableObject = targetObject.GetComponent <PBSPaintableObject>();
            TextureFormat      format          = (gBufferFormat == GBufferFormat.Half) ? TextureFormat.RGBAHalf : TextureFormat.RGBAFloat;

            paintableObject.PositionMap = FileUtil.RenderTextureToTexture2D(posMapCam.targetTexture, format);
            paintableObject.NormalMap   = FileUtil.RenderTextureToTexture2D(normalMapCam.targetTexture, format);
        }
Esempio n. 3
0
 public void UnRegisterPaintableObject(PBSPaintableObject paintableObject)
 {
     paintableObjs.Remove(paintableObject.paintObjectID);
 }
    private IEnumerator InitCoroutine()
    {
        GameObject tp = Instantiate(WallPrefab);

        model     = tp.GetComponent <MRWallUnit>();
        paintObjs = model.paintObjs;

        startButton = GameStartButton.GetComponent <PaintVR.PBSPaintableObject>();
        startButton.AddOnPaintingListener(TiggerStartEvent);
        generator.targetObject = GameStartButton;
        generator.GBufferGeneratorInit();

        yield return(new WaitForSeconds(0.1f));

        generator.targetObject = wall.gameObject;
        generator.GBufferGeneratorInit();

        yield return(new WaitForSeconds(0.1f));

        foreach (var obj in paintObjs)
        {
            generator.targetObject = obj.gameObject;
            generator.GBufferGeneratorInit();

            yield return(new WaitForSeconds(0.1f));
        }

        PBSRoot = model.coverMesh.gameObject.AddComponent <PaintVR.PBSPaintableObjectRoot>();
        PBSRoot.registerUndoMgr = false;

        Mesh mesh = model.coverMesh.mesh;

        Vector3[] vertexs = new Vector3[4];
        vertexs[0] = new Vector3(-col / 2.0f, -row / 2.0f, 0.0f);
        vertexs[1] = new Vector3(+col / 2.0f, +row / 2.0f, 0.0f);
        vertexs[2] = new Vector3(+col / 2.0f, -row / 2.0f, 0.0f);
        vertexs[3] = new Vector3(-col / 2.0f, +row / 2.0f, 0.0f);

        mesh.vertices        = vertexs;
        model.coverMesh.mesh = mesh;

        generator.targetObject = model.coverMesh.gameObject;
        generator.GBufferGeneratorInit();

        cleaner.srcTexture = PBSRoot.PaintTextureData.AlbedoTexture;

        yield return(new WaitForSeconds(0.1f));

        InitMRWall();

        yield return(new WaitForSeconds(0.1f));

        model.coverMesh.GetComponent <Renderer>().enabled = false;
        model.coverMesh.GetComponent <Collider>().enabled = false;
        model.coverMesh.transform.parent = ARWall.transform;
        Destroy(model.gameObject);

        yield return(new WaitForSeconds(0.1f));

        init = true;
    }
Esempio n. 5
0
        // Protected Class Methods.
        // ---------------------------------------------------------------
        public void SimulateSpray()
        {
            // Detect whether the spray button is pressed.
            if (
                (GetComponent <StickyGrabbable>() != null && GetComponent <StickyGrabbable>().isGrabbed&& ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Trigger)) ||
                (GetComponent <VivePoseTracker>() != null && GetComponent <VivePoseTracker>().enabled&& ViveInput.GetPressDown(HandRole.RightHand, ControllerButton.Trigger)) ||
                (Input.GetKeyDown(KeyCode.Space) && GameObject.FindObjectOfType <ARRender>() == null)
                )
            {
                Ray ray = new Ray(spraySourceObj.transform.position, spraySourceObj.transform.forward);
                ViveInput.TriggerHapticPulse(HandRole.RightHand, 500);
#if UNITY_EDITOR
                // DebugUtil.DrawVisRay(ray, 1000.0f, Color.white);
#endif

                //float triggerValue = ViveInput.GetTriggerValue(HandRole.RightHand, false);
                //float mappedPressAmount = 1;
                // float sprayAngle = PaintUtil.ComputeSprayAngle(mappedPressAmount, ParameterManager.instance.CurrentSprayAngle, ParameterManager.instance.minSprayAngleRatio);
                // float sprayDist = PaintUtil.ComputeSprayDistance(mappedPressAmount, ParameterManager.instance.sprayDistMappingCurve, ParameterManager.instance.CurrentMaxSprayDist);
                float sprayAngle = ParameterManager.instance.CurrentSprayAngle;
                float sprayDist  = 200;
                //float sprayAlpha = ComputeSprayAlpha(mappedPressAmount, ParameterManager.instance.sprayAlphaMappingCurve);

                // int layer = 1 << PaintComponentDefine.PaintObjectLayer;
                RaycastHit hitInfo;
                if (Physics.Raycast(ray, out hitInfo, sprayDist, hitLayerMask) && hitInfo.transform.tag == PaintComponentDefine.PaintMeshTag)
                {
                    sprayDist = Vector3.Distance(ray.origin, hitInfo.point);

                    pbsPaintObjController = hitInfo.collider.gameObject.GetComponent <PBSPaintableObject>();
                    if (pbsPaintObjController == null)
                    {
                        Debug.LogWarning("hitInfo.collider not has PBSPaintableObject : " + hitInfo.collider.name);
                    }
                    else
                    {
                        TextureSpaceData paintTextureData = pbsPaintObjController.PaintTextureData;
                        pbsPaintObjController.InvokeOnPaintingEvent();

                        if (useGBufferRT)
                        {
                            GBufferGenerator posTexGen = gBufferGen;
                            sprayMaterial.SetTexture("_PosMap", posTexGen.PositionMap);
                            sprayMaterial.SetTexture("_NormalMap", posTexGen.NormalMap);
                        }
                        else
                        {
                            sprayMaterial.SetTexture("_PosMap", pbsPaintObjController.PositionMap);
                            sprayMaterial.SetTexture("_NormalMap", pbsPaintObjController.NormalMap);
                        }

                        Vector3 hitPos = hitInfo.point;
                        sprayMaterial.SetVector("_SprayCenter", new Vector4(hitPos.x, hitPos.y, hitPos.z, 1.0f));

                        // Set spray color.
                        sprayMaterial.SetColor("_SprayColor", ParameterManager.instance.CurrentPaintColor);

                        // Set spray source.
                        //Vector3 spraySrc = spraySourceObj.transform.position;
                        Vector3 spraySrc = hitInfo.point - ray.direction * hitPointToCamera;
                        sprayMaterial.SetVector("_SpraySource", new Vector4(spraySrc.x, spraySrc.y, spraySrc.z, 1.0f));

                        // Compute spray cutoff.
                        float ratio = ParameterManager.instance.sprayAngleHalfRatioCurve.Evaluate(sprayAngle);
                        sprayMaterial.SetFloat("_SprayInnerAngle", Mathf.Cos(Mathf.Deg2Rad * sprayAngle * ratio));
                        sprayMaterial.SetFloat("_SprayOuterAngle", Mathf.Cos(Mathf.Deg2Rad * sprayAngle));

                        // Set spray alpha.
                        sprayMaterial.SetFloat("_SprayAlpha", 1f);

                        Matrix4x4 worldMat  = hitInfo.collider.gameObject.GetComponent <Renderer>().localToWorldMatrix;
                        Matrix4x4 normalMat = worldMat.inverse.transpose;
                        sprayMaterial.SetMatrix("_WorldMatrix", worldMat);
                        sprayMaterial.SetMatrix("_NormalMatrix", normalMat);

                        // Update depth map.
                        float distance = Vector3.Distance(spraySourceObj.transform.position, spraySrc);
                        UpdateDepthCam(sprayAngle, distance);
                        sprayMaterial.SetTexture("_DepthMap", depthRT);

                        // Build light matrix.
                        Matrix4x4 lightViewProjMat = depthCam.projectionMatrix * depthCam.worldToCameraMatrix;
                        sprayMaterial.SetMatrix("_LightViewProjMatrix", lightViewProjMat);
                        sprayMaterial.SetMatrix("_LightViewMatrix", depthCam.worldToCameraMatrix);

                        // Set brush pattern mask.
                        sprayMaterial.SetTexture("_CookieMap", defaultPattern);

                        RenderTexture rt = RenderTexture.GetTemporary(paintTextureData.AlbedoTexture.width, paintTextureData.AlbedoTexture.height, 0, paintTextureData.AlbedoTexture.format);
                        Graphics.Blit(paintTextureData.AlbedoTexture, rt);
                        Graphics.Blit(rt, paintTextureData.AlbedoTexture, sprayMaterial);
                        RenderTexture.ReleaseTemporary(rt);

                        // Update color history.
                        EventManager.TriggerUpdateColorHistoryEvent(ParameterManager.instance.CurrentPaintColor);
                        EnableShotEffect(spraySourceObj.transform.position, hitInfo.point);
                    }
                }
                else
                {
                    hitInfo.point = ray.origin + sprayDist * ray.direction;
                    if (ScoreManager.instance != null)
                    {
                        ScoreManager.instance.ShotEvent(false);
                    }
                }

                EnableShotEffect(spraySourceObj.transform.position, hitInfo.point);
                particle.Play();
                RandomColorSelect();
            }
        }
Esempio n. 6
0
 public void AddCancelComboObj(PaintVR.PBSPaintableObject obj)
 {
     obj.AddOnPaintingListener(CancelCombo);
     cancelComboObj.Add(obj);
 }