Exemplo n.º 1
0
        void InitPVSMeshes()
        {
            m_PVSItemIDS.Clear();

            m_GlobalNodeId = 0;
            m_BoundsArray  = null;
            if (m_PVSMeshRoot != null)
            {
                MeshRenderer[] mss = m_PVSMeshRoot.GetComponentsInChildren <MeshRenderer> (true);
                if (mss != null)
                {
                    System.Array.Sort(mss, (MeshRenderer m1, MeshRenderer m2) => {
                        var p1   = m1.transform.position;
                        var p2   = m2.transform.position;
                        float vv = p1.z - p2.z;
                        if (Mathf.Abs(vv) > float.Epsilon)
                        {
                            if (p1.z < p2.z)
                            {
                                return(-1);
                            }
                            return(1);
                        }
                        vv = p1.x - p2.x;
                        if (Mathf.Abs(vv) > float.Epsilon)
                        {
                            if (p1.x < p2.x)
                            {
                                return(-1);
                            }
                            return(1);
                        }
                        return(0);
                    }
                                      );
                    m_BoundsArray = new PVSBounds[mss.Length];
                    for (int i = 0; i < mss.Length; ++i)
                    {
                        var       ms     = mss [i];
                        PVSBounds bounds = new PVSBounds();
                        var       b      = ms.bounds;
                        bounds.min        = ms.bounds.min;
                        bounds.max        = ms.bounds.max;
                        bounds.forward    = ms.transform.forward;
                        bounds.up         = ms.transform.up;
                        bounds.id         = GeneratorNodeId();
                        m_BoundsArray [i] = bounds;
                        m_PVSItemIDS.AddIDs(bounds.id, ms.transform);
                    }
                }
            }

            m_PVSItemIDS.m_BakerRoot = m_PVSMeshRoot;
        }
Exemplo n.º 2
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.º 3
0
        internal static bool sdPVSCell(ref Ray ray, PVSBounds bounds, ref float tutDistance)
        {
            float distance = sdPVSCell(ray.origin, bounds);

            if (distance <= Vector3.kEpsilon)
            {
                return(true);
            }
            tutDistance += distance;
            ray.origin  += distance * ray.direction;

            return(false);
        }
Exemplo n.º 4
0
        internal static float sdPVSCell(Vector3 pt, PVSBounds bounds)
        {
            Matrix4x4 mat = Matrix4x4.identity;

            Vector3 center = bounds.center;
            Vector3 size   = bounds.size;
            Vector3 up     = bounds.up;
            Vector3 zz     = bounds.forward;
            Vector3 right  = Vector3.Cross(up, zz);

            mat.m00 = right.x; mat.m01 = right.y; mat.m02 = right.z;
            mat.m10 = up.x; mat.m11 = up.y; mat.m12 = up.z;
            mat.m20 = zz.x; mat.m21 = zz.y; mat.m22 = zz.z;

            pt -= center;

            pt = mat.MultiplyPoint(pt);

            float ret = sdBox(pt, size);

            return(ret);
        }