Beispiel #1
0
    public float SignificanceFunction(ManagedObjectInfo objectInfo, Transform transform)
    {
        Transform significanceActor = (Transform)objectInfo.GetObject();
        float     distance          = Vector3.Distance(transform.position, significanceActor.position);

        //distance、visibility、screen size
        //TODO occlusionCulling

        if (distance < significanceDistance)
        {
            Collider collider = significanceActor.GetComponent <Collider>();
            if (collider)
            {
                Plane[] planes = GeometryUtility.CalculateFrustumPlanes(mainCamera);
                if (GeometryUtility.TestPlanesAABB(planes, collider.bounds))
                {
                    float diameter             = collider.bounds.extents.magnitude;
                    float distanceToCamera     = Vector3.Distance(mainCamera.transform.position, significanceActor.position);
                    float angularSize          = (diameter / distanceToCamera) * Mathf.Rad2Deg;
                    float pixelSize            = ((angularSize * Screen.height) / mainCamera.fieldOfView);
                    float distanceSignificance = 1f - distance / significanceDistance;
                    pixelSize = pixelSize > significancePixelSize ? significancePixelSize : pixelSize;
                    float pixelSignificance = (1 - distanceSignificance) * pixelSize / significancePixelSize;//能量守恒

                    return(distanceSignificance + pixelSignificance);
                }
            }
        }
        return(0.0f);
    }
    protected void RegisterManagedObject(ManagedObjectInfo objectInfo)
    {
        UnityEngine.Object Object = objectInfo.GetObject();
        if (objectInfo.GetPostSignificanceType() == PostSignificanceType.Sequntial)
        {
            ++managedObjectsWithSequentialPostWork;
        }
        if (viewpoints.Count > 0)
        {
            objectInfo.UpdateSignificance(viewpoints, bSortSignificanceAscending);

            if (objectInfo.GetPostSignificanceType() == PostSignificanceType.Sequntial)
            {
                FManagedObjectPostSignificanceFunction PostSignificanceFunction = objectInfo.GetPostSignificanceFunction();
                PostSignificanceFunction(objectInfo, 1.0f, objectInfo.GetSignificance(), false);
            }
        }

        managedObjects.Add(Object, objectInfo);

        List <ManagedObjectInfo> managedObjectInfos = FindOrAdd(objectInfo.GetTag(), managedObjectsByTag);

        if (managedObjectInfos.Count > 0)
        {
            int LowIndex  = 0;
            int HighIndex = managedObjectInfos.Count - 1;
            while (true)
            {
                int MidIndex = LowIndex + (HighIndex - LowIndex) / 2;
                if (CompareBySignificanceAscending(objectInfo, managedObjectInfos[MidIndex]))
                {
                    if (LowIndex == MidIndex)
                    {
                        managedObjectInfos.Insert(LowIndex, objectInfo);
                        break;
                    }
                    else
                    {
                        HighIndex = MidIndex - 1;
                    }
                }
                else if (LowIndex == HighIndex)
                {
                    managedObjectInfos.Insert(LowIndex + 1, objectInfo);
                    break;
                }
                else
                {
                    LowIndex = MidIndex + 1;
                }
            }
        }
        else
        {
            managedObjectInfos.Add(objectInfo);
        }
    }
Beispiel #3
0
    public void PostSignificanceFunction(ManagedObjectInfo objectInfo, float oldSignificance, float significance, bool bUnregistered)
    {
        if (significance > 0f)
        {
            //提高 AI tick 频率,设置粒子发射器等等
            //设置 lod level
        }
        else
        {
            //关闭 AI tick,关闭粒子等
            //关闭 lod
        }

#if UNITY_EDITOR
        Transform significanceActor = (Transform)objectInfo.GetObject();
        DebugHUD  textMesh          = significanceActor.GetComponentInChildren <DebugHUD>();
        textMesh.ShowDebugView(significance, debugDisplayInfo.ShouldDisplayDebug);
#endif
    }
    public float SignificanceFunction(ManagedObjectInfo objectInfo, Transform transform)
    {
        Transform significanceActor = (Transform)objectInfo.GetObject();
        float     distance          = Vector3.Distance(transform.position, significanceActor.position);

        //distance、visibility
        //TODO screen size...
        //TODO occlusionCulling
        if (distance < significanceDistance)
        {
            Collider collider = significanceActor.GetComponent <Collider>();
            if (collider)
            {
                Plane[] planes = GeometryUtility.CalculateFrustumPlanes(mainCamera);
                if (GeometryUtility.TestPlanesAABB(planes, collider.bounds))
                {
                    float significance = 1f - distance / significanceDistance;
                    return(significance);
                }
            }
        }
        return(0f);
    }