void Initialize()
    {
        var light = GameObject.Find("Directional Light");

        if (light == null)
        {
            return;
        }

        m_LightingInfoDefinition = DatasetCapture.RegisterMetricDefinition("lighting info", "Per-frame light color and orientation", id: k_LightingInfoGuid);
        m_Light = light.GetComponent <Light>();
        // To simulate phong shading we turn off shadows
        m_Light.shadows = LightShadows.None;
        m_IsInitialized = true;


        // Try to find game object here because scene may not be initialized on Create()
        if (m_InitParams == null)
        {
            m_InitParams = GameObject.Find("Management")?.GetComponentInChildren <ProjectInitialization>();
            if (m_InitParams == null)
            {
                Debug.LogWarning("Unable to find Management object. Will not randomize lighting.");
                return;
            }
        }
    }
Beispiel #2
0
        /// <inheritdoc/>
        protected override void OnStart()
        {
            var randomSeedMetricDefinition = DatasetCapture.RegisterMetricDefinition(
                "random-seed",
                "The random seed used to initialize the random state of the simulation. Only triggered once per simulation.",
                Guid.Parse("14adb394-46c0-47e8-a3f0-99e754483b76"));

            DatasetCapture.ReportMetric(randomSeedMetricDefinition, new[] { genericConstants.randomSeed });
        }
 public override void Create()
 {
     m_RenderPass = new RandomizedPostProcessingPass();
     if (Application.isPlaying)
     {
         m_PostProcessValuesMetric = DatasetCapture.RegisterMetricDefinition(
             "random post processing",
             description: "Some post-processing parameters are randomized each frame. These are the per-frame values used.",
             id: k_PostProcessValuesMetricId);
     }
 }
    // Initialize your operator here
    protected override void OnCreate()
    {
        m_Rand                         = new Random(1);
        m_ForegroundLayer              = LayerMask.NameToLayer("Foreground");
        m_ParentForeground             = new GameObject("ForegroundContainer");
        m_ParentBackgroundInForeground = new GameObject("BackgroundInForegroundContainer");
        m_OccludingLayer               = LayerMask.NameToLayer("Occluding");
        m_ParentOccluding              = new GameObject("OccludingContainer");

        m_CurriculumQuery = EntityManager.CreateEntityQuery(typeof(CurriculumState));
        m_ForegroundPlacementInfoDefinition = DatasetCapture.RegisterMetricDefinition("foreground placement info", description: "Info about each object placed in the foreground layer. Currently only includes label and orientation.", id: new Guid(k_ForegroundPlacementInfoMetricGuid));
    }
 public void Start()
 {
     //Metrics and annotations are registered up-front
     lightMetricDefinition = DatasetCapture.RegisterMetricDefinition(
         "Light position",
         "The world-space position of the light",
         Guid.Parse("1F6BFF46-F884-4CC5-A878-DB987278FE35"));
     boundingBoxAnnotationDefinition = DatasetCapture.RegisterAnnotationDefinition(
         "Target bounding box",
         "The position of the target in the camera's local space",
         id: Guid.Parse("C0B4A22C-0420-4D9F-BAFC-954B8F7B35A7"));
 }
Beispiel #6
0
        /// <summary>
        /// Start is called after Awake but before the first Update method call
        /// </summary>
        protected virtual void Start()
        {
            var randomSeedMetricDefinition = DatasetCapture.RegisterMetricDefinition(
                "random-seed",
                "The random seed used to initialize the random state of the simulation. Only triggered once per simulation.",
                Guid.Parse("14adb394-46c0-47e8-a3f0-99e754483b76"));

            DatasetCapture.ReportMetric(randomSeedMetricDefinition, new[] { genericConstants.randomSeed });
#if !UNITY_EDITOR
            DeserializeFromFile();
#endif
        }
 protected override void OnAwake()
 {
     m_ForegroundObjectPlacementMetricDefinition = DatasetCapture.RegisterMetricDefinition("Per Frame Foreground Object Placement Info", $"Reports the world position, scale, rotation, and label id of objects carrying a {nameof(ForegroundObjectMetricReporterTag)} component.", new Guid(k_LayerOneForegroundObjectPlacementInfoMetricGuid));
     m_LabelingComponentsCache = new Dictionary <GameObject, Labeling>();
     if (labelConfigForObjectPlacementMetrics == null)
     {
         var perceptionCamera = Object.FindObjectOfType <PerceptionCamera>();
         if (perceptionCamera && perceptionCamera.labelers.Count > 0 && perceptionCamera.labelers[0] is BoundingBox2DLabeler boundingBox2DLabeler)
         {
             labelConfigForObjectPlacementMetrics = boundingBox2DLabeler.idLabelConfig;
         }
     }
 }
Beispiel #8
0
        /// <summary>
        /// Awake is called when this scenario MonoBehaviour is created or instantiated
        /// </summary>
        protected virtual void Awake()
        {
            activeScenario = this;
            foreach (var randomizer in m_Randomizers)
            {
                randomizer.Create();
            }
            ValidateParameters();

            // Don't skip the first frame if executing on Unity Simulation
            if (Configuration.Instance.IsSimulationRunningInCloud())
            {
                m_SkipFrame = false;
            }

            m_IterationMetricDefinition = DatasetCapture.RegisterMetricDefinition("scenario_iteration", "Iteration information for dataset sequences",
                                                                                  Guid.Parse(k_ScenarioIterationMetricDefinitionId));
        }
Beispiel #9
0
        void Start()
        {
            var randomSeedMetricDefinition = DatasetCapture.RegisterMetricDefinition(
                "random-seed",
                "The random seed used to initialize the random state of the simulation. Only triggered once per simulation.",
                Guid.Parse("14adb394-46c0-47e8-a3f0-99e754483b76"));

            DatasetCapture.ReportMetric(randomSeedMetricDefinition, new[] { genericConstants.randomSeed });
#if !UNITY_EDITOR
            if (File.Exists(defaultConfigFilePath))
            {
                DeserializeFromFile();
            }
            else
            {
                Debug.Log($"No configuration file found at {defaultConfigFilePath}. " +
                          "Proceeding with built in scenario constants and randomizer settings.");
            }
#endif
        }
Beispiel #10
0
    protected void Initialize()
    {
        m_Rand            = new Random(2);
        m_CurriculumQuery = EntityManager.CreateEntityQuery(typeof(CurriculumState));

        const string globalInitParamsName      = "Management";
        var          globalInitParamsContainer = GameObject.Find(globalInitParamsName);

        if (globalInitParamsContainer == null)
        {
            Debug.Log($"Cannot find a {globalInitParamsName} object to init parameters from.");
            return;
        }

        var init = globalInitParamsContainer.GetComponent <ProjectInitialization>();

        m_AppParams = init.AppParameters;
        var perceptionCamera = init.PerceptionCamera;

        camera             = perceptionCamera.GetComponentInParent <Camera>();
        m_ForegroundCenter =
            camera.transform.position + m_CameraForward * ForegroundObjectPlacer.k_ForegroundLayerDistance;
        // Compute the bottom left corner of the view frustum
        // IMPORTANT: We're assuming the camera is facing along the positive z-axis
        container = new GameObject("BackgroundContainer");
        container.transform.SetPositionAndRotation(
            m_CameraForward * k_PlacementDistance + camera.transform.position,
            Quaternion.identity);
        var statics = EntityManager.GetComponentObject <PlacementStatics>(m_CurriculumQuery.GetSingletonEntity());

        objectCache = new GameObjectOneWayCache(container.transform, statics.BackgroundPrefabs);

        backgroundHueMaxOffset = init.AppParameters.BackgroundHueMaxOffset;
        initialized            = true;

        m_ScaleRangeMetric = DatasetCapture.RegisterMetricDefinition("background scale range", "The range of scale factors used to place background objects each frame", k_BackgroundScaleMetricId);
    }
Beispiel #11
0
 public void RegisterMetricDefinition_InEditMode_Throws()
 {
     Assert.Throws <InvalidOperationException>(() => DatasetCapture.RegisterMetricDefinition(""));
 }
    void Start()
    {
        var backgroundObjects = Resources.LoadAll <GameObject>(BackgroundObjectResourcesDirectory);
        var backgroundImages  = Resources.LoadAll <Texture2D>(BackgroundImageResourcesDirectory);

        if (foregroundObjects.Length == 0)
        {
            Debug.LogError($"No Prefabs given in Foreground Objects list.");
            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,
            AppParameters.BackgroundObjectInForegroundChance,
            foregroundObjects,
            backgroundObjects,
            backgroundImages,
            ObjectPlacementUtilities.GenerateInPlaneRotationCurriculum(Allocator.Persistent),
            ObjectPlacementUtilities.GenerateOutOfPlaneRotationCurriculum(Allocator.Persistent),
            new NativeArray <float>(AppParameters.ScaleFactors, Allocator.Persistent),
            idLabelconfig);
        var appParamsMetricDefinition = DatasetCapture.RegisterMetricDefinition(
            "app-params", description: "The values from the app-params used in the simulation. Only triggered once per simulation.", id: k_AppParamsMetricGuid);

        DatasetCapture.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;
    }
Beispiel #13
0
 /// <inheritdoc/>
 protected override void OnAwake()
 {
     m_IterationMetricDefinition = DatasetCapture.RegisterMetricDefinition(
         "scenario_iteration", "Iteration information for dataset sequences",
         Guid.Parse(k_ScenarioIterationMetricDefinitionId));
 }
Beispiel #14
0
 protected override void OnAwake()
 {
     m_CameraPostProcessingMetricDefinition = DatasetCapture.RegisterMetricDefinition("Per Frame Camera Post Processing Info", $"Reports post-processing effects of cameras (or other objects with a Volume) carrying a {nameof(CameraPostProcessingMetricReporter)} component.", new Guid(k_CameraPostProcessingMetricGuid));
     m_PostProcessingVolumeCache            = new Dictionary <GameObject, Volume>();
 }
 protected override void OnAwake()
 {
     m_LightingInfoMetricDefinition = DatasetCapture.RegisterMetricDefinition("Per Frame Lighting Info", $"Reports the enabled state, intensity, colour, and rotation of lights carrying a {nameof(LightingInfoMetricReporterTag)} component.", new Guid(k_LightingInfoMetricGuid));
 }