Ejemplo n.º 1
0
    int EstimateTotalFrames()
    {
        var scaleFactorRange             = m_ScaleFactorCurve.value;
        var steps                        = m_StepsField.value;
        var stepsPerJob                  = m_StepsPerJobField.value;
        var maxFramesPerJob              = m_MaxFramesField.value;
        var maxForegroundObjectsPerFrame = m_MaxForegroundObjectsPerFrame.value;

        if (steps == 0 || maxFramesPerJob == 0 || stepsPerJob == 0 || maxForegroundObjectsPerFrame == 0)
        {
            return(0);
        }

        var inPlaneRotations    = ObjectPlacementUtilities.GenerateInPlaneRotationCurriculum(Allocator.Temp);
        var outOfPlaneRotations = ObjectPlacementUtilities.GenerateOutOfPlaneRotationCurriculum(Allocator.Temp);

        var framesPerScaleFactorMaxObjects           = inPlaneRotations.Length * outOfPlaneRotations.Length * 64 / maxForegroundObjectsPerFrame;
        var scaleAccountingForBackgroundInForeground = 1 / (1 - m_BackgroundInForegroundChanceField.value);
        var framesPerScaleFactorAtOneScale           = k_EstimatedFramesPerCurriculumStepAtOneScale * scaleAccountingForBackgroundInForeground * inPlaneRotations.Length * outOfPlaneRotations.Length;

        inPlaneRotations.Dispose();
        outOfPlaneRotations.Dispose();

        var stepSize = 1f / (steps + 1);
        var time     = 0f;
        var estimate = 0;

        for (int i = 0; i < steps; i++)
        {
            var scaleFactor  = scaleFactorRange.Evaluate(time);
            var stepEstimate = (int)(framesPerScaleFactorAtOneScale * (scaleFactor * scaleFactor));
            stepEstimate = Math.Max(stepEstimate, framesPerScaleFactorMaxObjects);
            estimate    += stepEstimate;
            time        += stepSize;
        }

        var maxFrames = (m_StepsField.value / stepsPerJob) * maxFramesPerJob;

        return(math.min(maxFrames, estimate));
    }
Ejemplo n.º 2
0
    void Start()
    {
        m_ResourceDirectoriesEntity = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity(typeof(ResourceDirectories));
        World.DefaultGameObjectInjectionWorld.EntityManager.SetComponentData(m_ResourceDirectoriesEntity, new ResourceDirectories
        {
            ForegroundResourcePath = ForegroundObjectResourcesDirectory,
            BackgroundResourcePath = BackgroundObjectResourcesDirectory
        });
        var foregroundObjects = Resources.LoadAll <GameObject>(ForegroundObjectResourcesDirectory);
        var backgroundObjects = Resources.LoadAll <GameObject>(BackgroundObjectResourcesDirectory);
        var backgroundImages  = Resources.LoadAll <Texture2D>(BackgroundImageResourcesDirectory);

        if (foregroundObjects.Length == 0)
        {
            Debug.LogError($"No Prefabs of FBX files found in foreground object directory \"{ForegroundObjectResourcesDirectory}\".");
            return;
        }
        if (backgroundObjects.Length == 0)
        {
            Debug.LogError($"No Prefabs of FBX files found in background object directory \"{BackgroundObjectResourcesDirectory}\".");
            return;
        }
        //TODO: Fill in CurriculumState from app params
        if (TryGetAppParamPathFromCommandLine(out string appParamPath))
        {
            var AppParamsJson = File.ReadAllText(appParamPath);
            AppParameters = JsonUtility.FromJson <AppParams>(AppParamsJson);
        }
        else if (!String.IsNullOrEmpty(Configuration.Instance.SimulationConfig.app_param_uri))
        {
            AppParameters = Configuration.Instance.GetAppParams <AppParams>();
        }

        Debug.Log($"{nameof(ProjectInitialization)}: Starting up. MaxFrames: {AppParameters.MaxFrames}, " +
                  $"scale factors {{{string.Join(", ", AppParameters.ScaleFactors)}}}");

        m_PlacementStatics = new PlacementStatics(
            AppParameters.MaxFrames,
            AppParameters.MaxForegroundObjectsPerFrame,
            AppParameters.ScalingMin,
            AppParameters.ScalingSize,
            AppParameters.OccludingHueMaxOffset,
            foregroundObjects,
            backgroundObjects,
            backgroundImages,
            ObjectPlacementUtilities.GenerateInPlaneRotationCurriculum(Allocator.Persistent),
            ObjectPlacementUtilities.GenerateOutOfPlaneRotationCurriculum(Allocator.Persistent),
            new NativeArray <float>(AppParameters.ScaleFactors, Allocator.Persistent));
        var appParamsMetricDefinition = SimulationManager.RegisterMetricDefinition(
            "app-params", description: "The values from the app-params used in the simulation. Only triggered once per simulation.", id: k_AppParamsMetricGuid);

        SimulationManager.ReportMetric(appParamsMetricDefinition, new[] { AppParameters });
        m_CurriculumStateEntity = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntity();
        World.DefaultGameObjectInjectionWorld.EntityManager.AddComponentData(
            m_CurriculumStateEntity, new CurriculumState());
        World.DefaultGameObjectInjectionWorld.EntityManager.AddComponentObject(
            m_CurriculumStateEntity, m_PlacementStatics);

        ValidateForegroundLabeling(foregroundObjects, PerceptionCamera);

#if !UNITY_EDITOR
        if (Debug.isDebugBuild && EnableProfileLog)
        {
            Debug.Log($"Enabling profile capture");
            m_ProfileLogPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "profileLog.raw");
            if (System.IO.File.Exists(m_ProfileLogPath))
            {
                System.IO.File.Delete(m_ProfileLogPath);
            }

            UnityEngine.Profiling.Profiler.logFile         = m_ProfileLogPath;
            UnityEngine.Profiling.Profiler.enabled         = true;
            UnityEngine.Profiling.Profiler.enableBinaryLog = true;
        }
#endif
        Manager.Instance.ShutdownNotification += CleanupState;

        //PerceptionCamera.renderedObjectInfosCalculated += OnRenderedObjectInfosCalculated;
    }
Ejemplo n.º 3
0
    // Start is called before the first frame update
    void Start()
    {
        var outOfPlaneParent    = new GameObject("Out of plane test");
        var outOfPlaneRotations = ObjectPlacementUtilities.GenerateOutOfPlaneRotationCurriculum(Allocator.Temp);

        foreach (var rotation in outOfPlaneRotations)
        {
            var instance = Instantiate(prefab, outOfPlaneParent.transform);
            instance.transform.localRotation = rotation;
        }


        var inPlaneParent    = new GameObject("In plane test");
        var inPlaneRotations = ObjectPlacementUtilities.GenerateInPlaneRotationCurriculum(Allocator.Persistent);

        for (var index = 0; index < inPlaneRotations.Length; index++)
        {
            var rotation = inPlaneRotations[index];
            var cube     = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cube.transform.localScale = new Vector3(.2f, .2f, .2f);
            cube.transform.Translate(Vector3.down * index + Vector3.right * 5);
            cube.transform.localRotation = rotation;
            cube.transform.parent        = inPlaneParent.transform;
        }

        var combinedParent = new GameObject("Combined Test Grouped By In Plane");

        combinedParent.transform.localPosition = new Vector3(0, 0, 10);

        for (var iInPlane = 0; iInPlane < inPlaneRotations.Length; iInPlane++)
        {
            var inPlaneCombinedParent = new GameObject("In Plane #" + iInPlane);
            inPlaneCombinedParent.transform.parent        = combinedParent.transform;
            inPlaneCombinedParent.transform.localPosition = Vector3.right * (iInPlane * 2);
            for (var iOutOfPlane = 0; iOutOfPlane < outOfPlaneRotations.Length; iOutOfPlane++)
            {
                var rotation = ObjectPlacementUtilities.ComposeForegroundRotation(new CurriculumState()
                {
                    InPlaneRotationIndex    = iInPlane,
                    OutOfPlaneRotationIndex = iOutOfPlane
                }, outOfPlaneRotations, inPlaneRotations);
                var instance = Instantiate(prefab, inPlaneCombinedParent.transform);
                instance.transform.localPosition = Vector3.zero;
                instance.transform.localRotation = rotation;
            }
        }
        var combinedOutOfPlane = new GameObject("Combined Test Grouped By Out of Plane");

        combinedOutOfPlane.transform.localPosition = new Vector3(0, 0, 20);

        for (var iOutOfPlane = 0; iOutOfPlane < outOfPlaneRotations.Length; iOutOfPlane++)
        {
            var outOfPlaneCombinedParent = new GameObject("Out of Plane #" + iOutOfPlane);
            outOfPlaneCombinedParent.transform.parent        = combinedOutOfPlane.transform;
            outOfPlaneCombinedParent.transform.localPosition = Vector3.right * (iOutOfPlane * 2);
            for (var iInPlane = 0; iInPlane < inPlaneRotations.Length; iInPlane++)
            {
                var rotation = ObjectPlacementUtilities.ComposeForegroundRotation(new CurriculumState()
                {
                    InPlaneRotationIndex    = iInPlane,
                    OutOfPlaneRotationIndex = iOutOfPlane
                }, outOfPlaneRotations, inPlaneRotations);
                var instance = Instantiate(prefab, outOfPlaneCombinedParent.transform);
                instance.transform.localPosition = Vector3.zero;
                instance.transform.localRotation = rotation;
            }
        }

        var combinedHeirParent = new GameObject("Combined Test Using Heirarchy");

        combinedHeirParent.transform.localPosition = new Vector3(0, 0, 40);

        for (var iInPlane = 0; iInPlane < inPlaneRotations.Length; iInPlane++)
        {
            var inPlaneCombinedParent = new GameObject("In Plane #" + iInPlane);
            inPlaneCombinedParent.transform.parent        = combinedHeirParent.transform;
            inPlaneCombinedParent.transform.localPosition = Vector3.right * (iInPlane * 2);
            inPlaneCombinedParent.transform.localRotation = inPlaneRotations[iInPlane];
            for (var iOutOfPlane = 0; iOutOfPlane < outOfPlaneRotations.Length; iOutOfPlane++)
            {
                var instance = Instantiate(prefab, inPlaneCombinedParent.transform);
                instance.transform.localPosition = Vector3.zero;
                instance.transform.localRotation = outOfPlaneRotations[iOutOfPlane];
            }
        }

        var combinedHeirInvParent = new GameObject("Combined Test Using Heirarchy");

        combinedHeirInvParent.transform.localPosition = new Vector3(0, 0, 60);

        for (var iOutOfPlane = 0; iOutOfPlane < outOfPlaneRotations.Length; iOutOfPlane++)
        {
            var outOfPlaneCombinedParent = new GameObject("Out of Plane #" + iOutOfPlane);
            outOfPlaneCombinedParent.transform.parent        = combinedHeirInvParent.transform;
            outOfPlaneCombinedParent.transform.localPosition = Vector3.right * (iOutOfPlane * 2);
            outOfPlaneCombinedParent.transform.localRotation = outOfPlaneRotations[iOutOfPlane];
            for (var iInPlane = 0; iInPlane < inPlaneRotations.Length; iInPlane++)
            {
                var instance = Instantiate(prefab, outOfPlaneCombinedParent.transform);
                instance.transform.localPosition = Vector3.zero;
                instance.transform.localRotation = inPlaneRotations[iInPlane];
            }
        }


        var combinedStackedParent = new GameObject("Combined Test All Stacked");

        combinedStackedParent.transform.localPosition = new Vector3(0, 0, 70);

        for (var iInPlane = 0; iInPlane < inPlaneRotations.Length; iInPlane++)
        {
            for (var iOutOfPlane = 0; iOutOfPlane < outOfPlaneRotations.Length; iOutOfPlane++)
            {
                var rotation = ObjectPlacementUtilities.ComposeForegroundRotation(new CurriculumState()
                {
                    InPlaneRotationIndex    = iInPlane,
                    OutOfPlaneRotationIndex = iOutOfPlane
                }, outOfPlaneRotations, inPlaneRotations);
                var instance = Instantiate(prefab, combinedStackedParent.transform, true);
                instance.name = $"InPlane: {iInPlane} OutOfPlane: {iOutOfPlane}";
                instance.transform.localRotation = rotation;
                instance.transform.localPosition = Vector3.zero;
            }
        }

        outOfPlaneRotations.Dispose();
        inPlaneRotations.Dispose();
    }