private static void GUI_Draw_Render(SceneView sceneView) { if (frameBuffer) { if (fullScreen) { if (!waitForNextFrame) { GUI.DrawTexture(new Rect(0, 0, sceneView.camera.pixelWidth, sceneView.camera.pixelHeight), frameBuffer, ScaleMode.ScaleAndCrop); } if (GUI.Button(new Rect(sceneView.position.width - 18, sceneView.position.height - 40, 18, 18), texRestore)) { fullScreen = false; cameraSettings._transparent = false; BocsCyclesAPI.UpdateSettings(camera, cameraSettings, width, height, samples); } } else { Rect renderRect = new Rect(10 - 2, sceneView.position.height - 145 - 24 - 2, 256 + 4, 145 + 4); EditorGUI.DrawRect(renderRect, Color.black); Rect previewRect = new Rect(10, sceneView.position.height - 145 - 24, 256, 145); GUI.DrawTexture(previewRect, frameBuffer, ScaleMode.ScaleAndCrop); if (GUI.Button(new Rect(10 + 256 - 18, sceneView.position.height - 24 - 18, 18, 18), texFullScreen)) { fullScreen = true; cameraSettings._transparent = true; BocsCyclesAPI.UpdateSettings(camera, cameraSettings, width, height, samples); } } GUI_Draw_Updatebar(sceneView); } }
private static void Startup() { if (started) { return; } if (Application.isPlaying) { return; } if (Camera.main == null) { Debug.Log("No MainCamera Found!"); return; } if (SceneView.lastActiveSceneView == null) { Debug.Log("No SceneView Active!"); return; } camera = SceneView.lastActiveSceneView.camera; if (camera == null) { Debug.Log("No SceneView Camera Found!"); return; } cameraSettings = Camera.main.GetComponent <BocsCyclesCamera>(); if (cameraSettings == null) { cameraSettings = Camera.main.gameObject.AddComponent <BocsCyclesCamera>(); } if (fullScreen) { cameraSettings._transparent = true; } else { cameraSettings._transparent = false; } lastPosition = camera.transform.position; lastRotation = camera.transform.rotation; //Debug.Log("Startup..."); StartSync(); EditorApplication.update += Update; EditorApplication.playmodeStateChanged += PlaymodeStateChanged; EditorApplication.hierarchyWindowChanged += HierarchyWindowChanged; SceneView.onSceneGUIDelegate += OnSceneView; Selection.selectionChanged += SelectionChanged; GameObject o = GameObject.Find("<HDO>"); if (o == null) { o = new GameObject("<HDO>"); } o.hideFlags = HideFlags.HideInHierarchy; sceneID = o.GetInstanceID(); started = true; BocsCyclesAPI.Cycles_reset(); BocsCyclesAPI.Cycles_set_active(); BocsCyclesAPI.UpdateSettings(camera, cameraSettings, width, height, samples); }
private static void SyncScene() { SceneView view = SceneView.lastActiveSceneView; if (view == null) { return; } cameraSettings._fov = camera.fieldOfView; int w = 256; int h = 145; if (fullScreen) { w = view.camera.pixelWidth / 2; h = view.camera.pixelHeight / 2; } //hack..size keeps toggling by 1 pixel wtf???? if (Mathf.Abs(w - width) > 2 || Mathf.Abs(h - height) > 2) { //Debug.Log("resize: " + w + "," + h); width = w; height = h; frameBuffer = null; updateCamera = true; BocsCyclesAPI.Cycles_request_reset(); hasUpdated = true; waitForNextFrame = true; nextUpdate = Time.realtimeSinceStartup + .25f; } if (frameBuffer == null) { UpdateFramebuffer(); hasUpdated = true; waitForNextFrame = true; nextUpdate = Time.realtimeSinceStartup + .25f; } if (camera.transform.position != lastPosition || camera.transform.rotation != lastRotation) { lastPosition = camera.transform.position; lastRotation = camera.transform.rotation; updateCamera = true; BocsCyclesAPI.Cycles_request_reset(); waitForNextFrame = true; hasUpdated = true; nextUpdate = Time.realtimeSinceStartup + .25f; } if (BocsCyclesAPI.Cycles_need_reset()) { hasUpdated = true; waitForNextFrame = true; nextUpdate = Time.realtimeSinceStartup + .25f; } if (hasUpdated && Time.realtimeSinceStartup > nextUpdate) { if (BocsCyclesAPI.Cycles_need_settings()) { BocsCyclesAPI.UpdateSettings(camera, cameraSettings, width, height, samples); } else if (updateCamera) { BocsCyclesAPI.UpdateCameraPositon(camera, cameraSettings, width, height); } BocsCyclesAPI.Cycles_render_async(); hasUpdated = false; updateCamera = false; } }