Exemplo n.º 1
0
        void DrawSelectMeshObjLineCheck()
        {
            if (m_TargetCamera == null)
            {
                return;
            }

            if (m_BakerMode == PVSSceneBakerMode.CameraRTComputeMode || m_BakerMode == PVSSceneBakerMode.CameraRTCpuMode)
            {
                return;
            }

            var selTrans = Selection.activeTransform;

            if (selTrans != null)
            {
                var ms = selTrans.GetComponent <MeshRenderer>();
                if (ms != null)
                {
                    var b = ms.bounds;
                    Handles.color = Color.black;
                    Handles.DrawLine(m_TargetCamInfo.position, b.center);

                    if (GUILayout.Button("检测是否选中碰撞"))
                    {
                        Vector3 dir = b.center - m_TargetCamInfo.position;
                        dir = dir.normalized;
                        Ray       ray   = new Ray(m_TargetCamInfo.position, dir);
                        PVSBounds bound = new PVSBounds();
                        bound.min     = b.min;
                        bound.max     = b.max;
                        bound.up      = ms.transform.up;
                        bound.forward = ms.transform.forward;

                        float tutDistance = 0f;
                        while (true)
                        {
                            if (PVSRayTrack.sdPVSCell(ref ray, bound, ref tutDistance))
                            {
                                Debug.Log("有碰撞");
                                break;
                            }
                            if (tutDistance > m_TargetCamInfo.far)
                            {
                                Debug.Log("无碰撞");
                                break;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void CellRays(int cellIdx, Vector3 cellPos, PVSBounds[] bounds, PVSCameraInfo camInfo, bool isOriCam)
        {
            var cell = m_Results[cellIdx];

            cell.ResetVisible();

            Vector3 right  = camInfo.right;
            Vector3 up     = camInfo.up;
            Vector3 lookAt = camInfo.lookAt;

            if (isOriCam)
            {
                // 正交攝影機
                var width  = camInfo.CameraWidth;
                var height = camInfo.CameraHeight;

                float   perX   = GetPerX(width);
                float   perY   = GetPerY(height);
                Vector3 halfV  = (right * width / 2.0f + up * height / 2.0f);
                Vector3 minVec = cellPos - halfV;

                float stepY = 0;

                while (stepY <= height)
                {
                    float   stepX = 0;
                    Vector3 yy    = stepY * up;
                    while (stepX <= width)
                    {
                        Vector3 startPt     = minVec + stepX * right + yy + lookAt * camInfo.near;
                        Ray     ray         = new Ray(startPt, lookAt);
                        float   tutDistance = 0;
                        while (true)
                        {
                            int collisionIdx = PVSRayTrack.sdPVSCells(ref ray, bounds, ref tutDistance);
                            if (collisionIdx >= 0)
                            {
                                var b = m_Bounds[collisionIdx];
                                cell.SetVisible(b.id, true);
                                break;
                            }
                            if (tutDistance > (camInfo.far - camInfo.near))
                            {
                                break;
                            }
                        }

                        stepX += perX;
                    }
                    stepY += perY;
                }

                lock (cell) {
                    cell.isEditorDone = true;
                }
            }
            else
            {
                // 透視攝影機
                var     width  = camInfo.farWidth;
                var     height = camInfo.farHeight;
                float   perX   = GetPerX(width);
                float   perY   = GetPerY(height);
                Vector3 halfV  = (right * width / 2.0f + up * height / 2.0f);
                Vector3 minVec = cellPos - halfV;
                float   d      = camInfo.far;

                float stepY = 0;

                while (stepY < height)
                {
                    float   stepX = 0;
                    Vector3 yy    = stepY * up;
                    while (stepX < width)
                    {
                        Vector3 endPt       = minVec + stepX * right + yy + lookAt * d;
                        Vector3 dir         = (endPt - camInfo.position).normalized;
                        Ray     ray         = new Ray(camInfo.position, dir);
                        float   tutDistance = 0;
                        while (true)
                        {
                            int collisionIdx = PVSRayTrack.sdPVSCells(ref ray, bounds, ref tutDistance);
                            if (collisionIdx >= 0)
                            {
                                var b = m_Bounds[collisionIdx];
                                cell.SetVisible(b.id, true);
                                break;
                            }
                            if (tutDistance > camInfo.far)
                            {
                                break;
                            }
                        }

                        stepX += perX;
                    }
                    stepY += perY;
                }

                lock (cell) {
                    cell.isEditorDone = true;
                }
            }
        }