private void SetFrameDipendentValues(int index, GameObject thePrefab) { // set the plane texture (the cameraFeed recorded) string screenshotPath = Path.Combine(_folderPath, _folderName, _data.screenshotsInfo[index].screenShotName); byte[] img = File.ReadAllBytes(screenshotPath); _currentScreenShot.LoadImage(img); _planeBackgroundMaterial.SetTexture("_MainTex", _currentScreenShot); // set camera transform correctly _cameraParent.transform.position = _data.screenshotsInfo[index].camPosition; _cameraParent.transform.rotation = _data.screenshotsInfo[index].camRotation; if (thePrefab == null) { thePrefab = _prefabToPlace; } _go = Instantiate(thePrefab); _go.transform.position = _data.screenshotsInfo[index].objectPosition; _go.transform.rotation = _data.screenshotsInfo[index].objectRotation; _go.GetComponent <SetMaterialProperties>().SetCameraTexture(_currentScreenShot); _sunManager.SetSunDirectionZenith(_data.screenshotsInfo[index].sunPosition.zen, _data.screenshotsInfo[index].sunPosition.az); _lightingManager.SetSunDirection(_go); Vector3 s = _lightEstimation.ComputeS(_data.screenshotsInfo[index].sunPosition); float entireimageAverage; if (useARKitIntensity) { _lightEstimation._albedoAVG = 0.7f; entireimageAverage = _data.screenshotsInfo[index].arkitLightEstimationIntensity / 2000; } else { _lightEstimation._albedoAVG = 0.3f; entireimageAverage = (_data.screenshotsInfo[index].entireImageRGB.r + _data.screenshotsInfo[index].entireImageRGB.g + _data.screenshotsInfo[index].entireImageRGB.b) / 3; } _lightEstimation.ComputeIrradiances(_data.screenshotsInfo[index].litRGB[0], _data.screenshotsInfo[index].shadowRGB[0], entireimageAverage, _data.screenshotsInfo[index].aoLit, _data.screenshotsInfo[index].aoShadow, _data.screenshotsInfo[index].aoWhiteBalance, Vector3.up, s, Vector3.up); _lightingManager.SetIrradiances(_data.screenshotsInfo[index].skyIrradiance, _data.screenshotsInfo[index].sunIrradiance, _go); Debug.Log("Estimated Sun Irr " + _lightEstimation.GetSunIrradiance().ToString()); Debug.Log("Saved Sun Irr: " + _data.screenshotsInfo[index].sunIrradiance.ToString()); Debug.Log("Estimated Sky Irr" + _lightEstimation.GetSkyIrradiance().ToString()); Debug.Log("Saved Sky Irr: " + _data.screenshotsInfo[index].skyIrradiance.ToString()); _backgroundImage.texture = _currentScreenShot; }
public void AddScreenshot(RawImage img) { string sessionDirPath = Path.Combine(Application.persistentDataPath, sessionNameText.text); if (!Directory.Exists(sessionDirPath)) { Directory.CreateDirectory(sessionDirPath); } ScreenshotData newScreenshotData = new ScreenshotData(); newScreenshotData.aoLit = _lightEstimationManager.GetAoLit(); newScreenshotData.aoShadow = _lightEstimationManager.GetAoShadow(); newScreenshotData.aoWhiteBalance = _lightEstimationManager.GetAoWhiteBalance(); newScreenshotData.arkitLightEstimationIntensity = _arkitLightEstimation.GetARKitLightEstimationIntensity(); newScreenshotData.arkitLightEstimationColorTemperature = _arkitLightEstimation.GetARKitLightEstimationColorTemperature(); newScreenshotData.camPosition = _mainCamera.transform.position; newScreenshotData.camRotation = _mainCamera.transform.rotation; newScreenshotData.colorSpace = QualitySettings.activeColorSpace.ToString(); newScreenshotData.litRGB = _lightEstimationManager.GetAvgLit(); newScreenshotData.shadowRGB = _lightEstimationManager.GetAvgShadow(); newScreenshotData.entireImageRGB = _lightEstimationManager.GetAvgEntireImage(); if (_objectSpawnerManager.HasSpawnedAnObject()) { Transform objTransform = _objectSpawnerManager.GetObjectTransform(); newScreenshotData.objectPosition = objTransform.position; newScreenshotData.objectRotation = objTransform.rotation; } newScreenshotData.skyIrradiance = _lightEstimationManager.GetSkyIrradiance(); newScreenshotData.sunIrradiance = _lightEstimationManager.GetSunIrradiance(); List <Texture2D> litPatches = _lightEstimationManager.GetLitPatches(); List <Texture2D> shadowPatches = _lightEstimationManager.GetShadowPatches(); Texture2D tempTex; byte[] bytes; newScreenshotData.timestamp = DateTime.Now; newScreenshotData.screenShotName = newScreenshotData.timestamp.ToString("dd-MM-yyyyTHH:mm:ss_ffff") + ".png"; /* * for (int i = 0; i < litPatches.Count; i++) * { * tempTex = litPatches[i]; * bytes = tempTex.EncodeToPNG(); * string litName = newScreenshotData.timestamp.ToString("mm:ss_LitPatch") + i.ToString() + ".png"; * string litPath = Path.Combine(sessionDirPath, litName); * // For testing purposes, also write to a file in the project folder * * //string sunPositionFilePath = Path.Combine(Application.streamingAssetsPath, "SunPositionFiles/"); * File.WriteAllBytes(litPath, bytes); * * } * for (int i = 0; i < shadowPatches.Count; i++) * { * tempTex = shadowPatches[i]; * bytes = tempTex.EncodeToPNG(); * string shadowName = newScreenshotData.timestamp.ToString("mm:ss_ShadowPatch") + i.ToString() + ".png"; * string shadowPath = Path.Combine(sessionDirPath, shadowName); * // For testing purposes, also write to a file in the project folder * * //string sunPositionFilePath = Path.Combine(Application.streamingAssetsPath, "SunPositionFiles/"); * File.WriteAllBytes(shadowPath, bytes); * } */ newScreenshotData.sunPosition = _lightingManager.GetSunPos(); tempTex = (Texture2D)img.texture; bytes = tempTex.EncodeToPNG(); Destroy(tempTex); string screenshotPath = Path.Combine(sessionDirPath, newScreenshotData.screenShotName); // For testing purposes, also write to a file in the project folder //string sunPositionFilePath = Path.Combine(Application.streamingAssetsPath, "SunPositionFiles/"); File.WriteAllBytes(screenshotPath, bytes); //File.WriteAllBytes(Application.dataPath + "/SavedScreen.png", bytes); _data.screenshotsInfo.Add(newScreenshotData); string jsonString = JsonUtility.ToJson(_data, true); string jsonPath = Path.Combine(sessionDirPath, "info.json"); if (File.Exists(jsonPath)) { File.Delete(jsonPath); } File.WriteAllText(jsonPath, jsonString); }