public override int OnGUI(PreviewRenderUtility context, BaseParam[] param) { OnPUI("Camera", false, () => { Vector3 lookAtPositionValue = EditorGUILayout.Vector3Field("LookAt", lookAtPosition); if (lookAtPosition.Equals(lookAtPositionValue) == false) { Record("Change LookAt"); lookAtPosition = lookAtPositionValue; } Vector3 localPositionValue = EditorGUILayout.Vector3Field("Position", localPosition); if (localPosition.Equals(localPositionValue) == false) { Record("Change Position"); localPosition = localPositionValue; } Vector3 localRotationValue = EditorGUILayout.Vector3Field("Rotation", localRotation); if (localRotation.Equals(localRotationValue) == false) { Record("Change Rotation"); localRotation = localRotationValue; } Color backgroundColorValue = EditorGUILayout.ColorField("Background", backgroundColor); if (backgroundColor.Equals(backgroundColorValue) == false) { Record("Change Background"); backgroundColor = backgroundColorValue; } int projection = orthographic ? 1 : 0; projection = EditorGUILayout.Popup("Projection", projection, kProjections); bool orthographicValue = (projection == 0) ? false : true; if (orthographic.Equals(orthographicValue) == false) { Record("Change Projection"); orthographic = orthographicValue; } if (orthographic == false) { float fieldOfViewValue = EditorGUILayout.Slider(" Field of View", fieldOfView, 1e-5f, 179.0f); if (fieldOfView.Equals(fieldOfViewValue) == false) { Record("Change Field of View"); fieldOfView = fieldOfViewValue; } } else { float orthographicSizeValue = EditorGUILayout.FloatField("Size", orthographicSize); if (orthographicSize.Equals(orthographicSizeValue) == false) { Record("Change Size"); orthographicSize = orthographicSizeValue; } } float nearClipPlaneValue = EditorGUILayout.FloatField("Near Clipping Planes", nearClipPlane); if (nearClipPlaneValue < 0.1f) { nearClipPlaneValue = 0.1f; } if (nearClipPlaneValue >= 3.402823e+37f) { nearClipPlaneValue = 3.402823e+37f; } if (nearClipPlane.Equals(nearClipPlaneValue) == false) { Record("Change Near Clipping Planes"); nearClipPlane = nearClipPlaneValue; } float farClipPlaneValue = EditorGUILayout.FloatField("Far Clipping Planes", farClipPlane); if (farClipPlaneValue < nearClipPlane) { farClipPlaneValue = nearClipPlane + 0.01f; } if (farClipPlane.Equals(farClipPlaneValue) == false) { Record("Change Far Clipping Planes"); farClipPlane = farClipPlaneValue; } Rect viewportRectValue = EditorGUILayout.RectField("Viewport Rect", viewportRect); if (viewportRect.Equals(viewportRectValue) == false) { Record("Change Far Clipping Planes"); viewportRect = viewportRectValue; } }); return(0); }
public static void OnInteractivePreviewGUI(ref PreviewRenderUtility _mPrevRender, ref Vector2 _drag, Mesh mesh, Material[] mats, Rect r, GUIStyle background, float radius, Mesh _plane = null, Material _blueprintMaterial = null) { }
void previewInit() { if (bPrefab) { return; } if (previewRenderUtility != null) { return; } previewRenderUtility = new PreviewRenderUtility(true); Camera previewCam = PreviewCam; previewCam.backgroundColor = Color.black; // previewCam.projectionMatrix = Camera.main.projectionMatrix; previewCam.orthographic = true; previewCam.orthographicSize = Camera.main.orthographicSize * 0.5f; previewCam.farClipPlane = 100; previewCam.nearClipPlane = 0.01f; GameObject targetObj = _tile_Inspector.gameObject; Bounds bounds; if (IsEditorMode && _tile_Inspector.gameObject.activeSelf) { IsoTile _isoTile = Editor.Instantiate(_tile_Inspector); previewObject = _isoTile.gameObject; previewObject.transform.position = Vector3.zero; _isoTile.Copycat(_tile_Inspector.GetComponent <IsoTile>(), true, false); previewObject.hideFlags = HideFlags.HideAndDontSave; previewObject.SetActive(false); var flags = BindingFlags.Static | BindingFlags.NonPublic; var propInfo = typeof(Camera).GetProperty("PreviewCullingLayer", flags); int previewLayer = (int)propInfo.GetValue(null, new object[0]); previewObject.layer = previewLayer; foreach (Transform _transform in previewObject.transform.GetComponentsInChildren <Transform>()) { _transform.gameObject.layer = previewLayer; } previewCam.cullingMask = 1 << previewLayer; targetObj = previewObject; // callbacks.Add(clearPreviewInstance); // EditorApplication.playmodeStateChanged += clearPreviewInstance; } bounds = new Bounds(targetObj.transform.position, Vector3.zero); foreach (var renderer in targetObj.GetComponentsInChildren <Renderer>()) { bounds.Encapsulate(renderer.bounds); } float distance = Util.CustomEditorGUI.FrameBounds(previewCam, bounds); previewCam.transform.eulerAngles = IsoMap.instance.TileAngle; previewCam.transform.position = bounds.center - previewCam.transform.forward * distance; }
void OnEnable() { if (m_VisualEffectGO == null) { m_PreviewUtility = new PreviewRenderUtility(); m_PreviewUtility.camera.fieldOfView = 60.0f; m_PreviewUtility.camera.allowHDR = true; m_PreviewUtility.camera.allowMSAA = false; m_PreviewUtility.camera.farClipPlane = 10000.0f; m_PreviewUtility.ambientColor = new Color(.1f, .1f, .1f, 1.0f); m_PreviewUtility.lights[0].intensity = 1.4f; m_PreviewUtility.lights[0].transform.rotation = Quaternion.Euler(40f, 40f, 0); m_PreviewUtility.lights[1].intensity = 1.4f; m_VisualEffectGO = new GameObject("VisualEffect (Preview)"); m_VisualEffectGO.hideFlags = HideFlags.DontSave; m_VisualEffect = m_VisualEffectGO.AddComponent <VisualEffect>(); m_PreviewUtility.AddManagedGO(m_VisualEffectGO); m_VisualEffectGO.transform.localPosition = Vector3.zero; m_VisualEffectGO.transform.localRotation = Quaternion.identity; m_VisualEffectGO.transform.localScale = Vector3.one; m_VisualEffect.visualEffectAsset = target as VisualEffectAsset; m_CurrentBounds = new Bounds(Vector3.zero, Vector3.one); m_FrameCount = 0; m_Distance = 10; m_Angles = Vector3.forward; if (s_CubeWireFrame == null) { s_CubeWireFrame = new Mesh(); var vertices = new Vector3[] { new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, -0.5f) }; var indices = new int[] { 0, 1, 0, 3, 0, 4, 6, 2, 6, 5, 6, 7, 1, 2, 1, 5, 3, 7, 3, 2, 4, 5, 4, 7 }; s_CubeWireFrame.vertices = vertices; s_CubeWireFrame.SetIndices(indices, MeshTopology.Lines, 0); } } resourceObject = new SerializedObject(targets.Cast <VisualEffectAsset>().Select(t => t.GetResource()).Where(t => t != null).ToArray()); resourceUpdateModeProperty = resourceObject.FindProperty("m_Infos.m_UpdateMode"); cullingFlagsProperty = resourceObject.FindProperty("m_Infos.m_CullingFlags"); motionVectorRenderModeProperty = resourceObject.FindProperty("m_Infos.m_RendererSettings.motionVectorGenerationMode"); }
protected virtual void OnEnable() { m_previewRender = new PreviewRenderUtility(); m_previewRender.cameraFieldOfView = 30.0f; }
void DrawPreview(bool save = false) { float iconPreviewBrightness = mIconPreviewBrightness.floatValue; Vector3 iconPreviewOffset = mIconPreviewOffset.vector3Value; Vector3 iconPreviewAngles = mIconPreviewAngles.vector3Value; Vector3 iconPreviewPosition = mIconPreviewPosition.vector3Value; Vector3 iconPreviewRotation = mIconPreviewRotation.vector3Value; Vector3 iconPreviewScale = mIconPreviewScale.vector3Value; if (mShouldRefresh || mCurrentPreviewBrightness != iconPreviewBrightness || mCurrentPreviewOffset != iconPreviewOffset || mCurrentPreviewAngles != iconPreviewAngles || mCurrentPreviewPosition != iconPreviewPosition || mCurrentPreviewRotation != iconPreviewRotation || mCurrentPreviewScale != iconPreviewScale || save || ShouldRefreshPreviewObject()) { DestroyPreview(); mShouldRefresh = false; mCurrentPreviewBrightness = iconPreviewBrightness; mCurrentPreviewOffset = iconPreviewOffset; mCurrentPreviewAngles = iconPreviewAngles; mCurrentPreviewPosition = iconPreviewPosition; mCurrentPreviewRotation = iconPreviewRotation; mCurrentPreviewScale = iconPreviewScale; mPreviewGameObject = CreatePreviewObject(); if (mPreviewGameObject != null) { mPreviewGameObject.hideFlags = HideFlags.HideAndDontSave; } } if (mPreviewGameObject == null && !save) { return; } if (mPreviewRenderUtility == null) { mPreviewRenderUtility = new PreviewRenderUtility(); mPreviewRenderUtility.camera.fieldOfView = 30.0f; mPreviewRenderUtility.camera.allowHDR = false; mPreviewRenderUtility.camera.allowMSAA = false; mPreviewRenderUtility.ambientColor = new Color(1.0f, 1.0f, 1.0f, 0.0f); mPreviewRenderUtility.lights[0].intensity = iconPreviewBrightness; mPreviewRenderUtility.lights[0].transform.position = iconPreviewOffset; mPreviewRenderUtility.lights[0].transform.eulerAngles = iconPreviewAngles; mPreviewRenderUtility.lights[1].intensity = iconPreviewBrightness; mPreviewRenderUtility.camera.transform.position = iconPreviewOffset; mPreviewRenderUtility.camera.transform.eulerAngles = iconPreviewAngles; mPreviewRenderUtility.camera.nearClipPlane = 0.1f; mPreviewRenderUtility.camera.farClipPlane = 10.0f; mPreviewRenderUtility.AddSingleGO(mPreviewGameObject); } mPreviewGameObject.transform.position = iconPreviewPosition; mPreviewGameObject.transform.eulerAngles = iconPreviewRotation; mPreviewGameObject.transform.localScale = iconPreviewScale; Rect previewRect = EditorGUILayout.GetControlRect(false, 200.0f); int previewID = GUIUtility.GetControlID(PreviewControlID, FocusType.Passive, previewRect); Event e = Event.current; EventType eventType = e.GetTypeForControl(previewID); bool repaint = eventType == EventType.Repaint; if (repaint || save) { Texture texture = null; mPreviewRenderUtility.BeginPreview(new Rect(0, 0, IconSize, IconSize), mGUIStyle); try { mPreviewRenderUtility.Render(false); } finally { texture = mPreviewRenderUtility.EndPreview(); } if (save) { UnityEngine.Object obj = serializedObject.targetObject; string path = $"Sprites/Inventory/{Category}/{obj.name}.png"; var rt = (RenderTexture)texture; int width = rt.width; int height = rt.height; RenderTexture.active = rt; try { var tex2D = new Texture2D(width, height, TextureFormat.RGB24, false); try { tex2D.ReadPixels(new Rect(0, 0, width, height), 0, 0); File.WriteAllBytes($"{Application.dataPath}/{path}", tex2D.EncodeToPNG()); } finally { DestroyImmediate(tex2D); } } finally { RenderTexture.active = null; } AssetDatabase.Refresh(); path = $"Assets/{path}"; TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter; importer.textureType = TextureImporterType.Sprite; importer.sRGBTexture = false; importer.alphaIsTransparency = true; importer.alphaSource = TextureImporterAlphaSource.None; importer.spritePixelsPerUnit = 100.0f; importer.mipmapEnabled = false; importer.maxTextureSize = IconSize; EditorUtility.SetDirty(importer); importer.SaveAndReimport(); mIcon.objectReferenceValue = AssetDatabase.LoadAssetAtPath(path, typeof(Sprite)); } if (repaint) { GUI.DrawTexture(previewRect, texture, ScaleMode.ScaleToFit, false); } } }
void OnEnable() { VisualEffectAsset target = this.target as VisualEffectAsset; m_OutputContexts.Clear(); m_OutputContexts.AddRange(target.GetResource().GetOrCreateGraph().children.OfType <IVFXSubRenderer>().OrderBy(t => t.sortPriority)); m_ReorderableList = new ReorderableList(m_OutputContexts, typeof(IVFXSubRenderer)); m_ReorderableList.displayRemove = false; m_ReorderableList.displayAdd = false; m_ReorderableList.onReorderCallback = OnReorder; m_ReorderableList.drawHeaderCallback = DrawHeader; m_ReorderableList.drawElementCallback = DrawOutputContextItem; if (m_VisualEffectGO == null) { m_PreviewUtility = new PreviewRenderUtility(); m_PreviewUtility.camera.fieldOfView = 60.0f; m_PreviewUtility.camera.allowHDR = true; m_PreviewUtility.camera.allowMSAA = false; m_PreviewUtility.camera.farClipPlane = 10000.0f; m_PreviewUtility.ambientColor = new Color(.1f, .1f, .1f, 1.0f); m_PreviewUtility.lights[0].intensity = 1.4f; m_PreviewUtility.lights[0].transform.rotation = Quaternion.Euler(40f, 40f, 0); m_PreviewUtility.lights[1].intensity = 1.4f; m_VisualEffectGO = new GameObject("VisualEffect (Preview)"); m_VisualEffectGO.hideFlags = HideFlags.DontSave; m_VisualEffect = m_VisualEffectGO.AddComponent <VisualEffect>(); m_PreviewUtility.AddManagedGO(m_VisualEffectGO); m_VisualEffectGO.transform.localPosition = Vector3.zero; m_VisualEffectGO.transform.localRotation = Quaternion.identity; m_VisualEffectGO.transform.localScale = Vector3.one; m_VisualEffect.visualEffectAsset = target; m_CurrentBounds = new Bounds(Vector3.zero, Vector3.one); m_FrameCount = 0; m_Distance = 10; m_Angles = Vector3.forward; if (s_CubeWireFrame == null) { s_CubeWireFrame = new Mesh(); var vertices = new Vector3[] { new Vector3(-0.5f, -0.5f, -0.5f), new Vector3(-0.5f, -0.5f, 0.5f), new Vector3(-0.5f, 0.5f, 0.5f), new Vector3(-0.5f, 0.5f, -0.5f), new Vector3(0.5f, -0.5f, -0.5f), new Vector3(0.5f, -0.5f, 0.5f), new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0.5f, 0.5f, -0.5f) }; var indices = new int[] { 0, 1, 0, 3, 0, 4, 6, 2, 6, 5, 6, 7, 1, 2, 1, 5, 3, 7, 3, 2, 4, 5, 4, 7 }; s_CubeWireFrame.vertices = vertices; s_CubeWireFrame.SetIndices(indices, MeshTopology.Lines, 0); } } resourceObject = new SerializedObject(targets.Cast <VisualEffectAsset>().Select(t => t.GetResource()).Where(t => t != null).ToArray()); resourceUpdateModeProperty = resourceObject.FindProperty("m_Infos.m_UpdateMode"); cullingFlagsProperty = resourceObject.FindProperty("m_Infos.m_CullingFlags"); motionVectorRenderModeProperty = resourceObject.FindProperty("m_Infos.m_RendererSettings.motionVectorGenerationMode"); prewarmDeltaTime = resourceObject.FindProperty("m_Infos.m_PreWarmDeltaTime"); prewarmStepCount = resourceObject.FindProperty("m_Infos.m_PreWarmStepCount"); }
static CustomIcon() { m_previewUtility = new PreviewRenderUtility(); EditorApplication.projectWindowItemOnGUI += DrawCustomIcon; }
/// <summary> /// Callback called on the Implemented IESImporterEditor (currently on HDRP Only) /// </summary> /// <param name="setupRenderPipelinePreviewCamera">Delegate provided by the Render pipeline to setup the Preview Camera</param> /// <param name="setupRenderPipelinePreviewFloorRenderer">Delegate provided by the Render pipeline to setup the Preview Light</param> /// <param name="setupRenderPipelinePreviewLight">Delegate provided by the Render pipeline to setup the Preview Wall</param> /// <param name="setupRenderPipelinePreviewWallRenderer">Delegate provided by the Render pipeline to setup the Preview Floor</param> /// <returns>true to specified IES has a Preview</returns> public bool CommonHasPreviewGUI(SetupRenderPipelinePreviewCamera setupRenderPipelinePreviewCamera, SetupRenderPipelinePreviewLight setupRenderPipelinePreviewLight, SetupRenderPipelinePreviewWallRenderer setupRenderPipelinePreviewWallRenderer, SetupRenderPipelinePreviewFloorRenderer setupRenderPipelinePreviewFloorRenderer) { if (m_PreviewRenderUtility == null) { m_PreviewRenderUtility = new PreviewRenderUtility(); m_PreviewRenderUtility.ambientColor = Color.black; m_PreviewRenderUtility.camera.fieldOfView = 60f; m_PreviewRenderUtility.camera.nearClipPlane = 0.1f; m_PreviewRenderUtility.camera.farClipPlane = 10f; m_PreviewRenderUtility.camera.transform.localPosition = new Vector3(1.85f, 0.71f, 0f); m_PreviewRenderUtility.camera.transform.localEulerAngles = new Vector3(15f, -90f, 0f); setupRenderPipelinePreviewCamera(m_PreviewRenderUtility.camera); m_PreviewRenderUtility.lights[0].type = (m_PrefabLightTypeProp.enumValueIndex == (int)IESLightType.Point) ? LightType.Point : LightType.Spot; m_PreviewRenderUtility.lights[0].color = Color.white; m_PreviewRenderUtility.lights[0].intensity = 1f; m_PreviewRenderUtility.lights[0].range = 10f; m_PreviewRenderUtility.lights[0].spotAngle = m_SpotAngleProp.floatValue; m_PreviewRenderUtility.lights[0].transform.localPosition = new Vector3(0.14f, 1f, 0f); m_PreviewRenderUtility.lights[0].transform.localEulerAngles = new Vector3(90f, 0f, -90f); setupRenderPipelinePreviewLight(m_PreviewRenderUtility.lights[0]); m_PreviewRenderUtility.lights[1].intensity = 0f; GameObject previewWall = GameObject.CreatePrimitive(PrimitiveType.Plane); previewWall.name = "IESPreviewWall"; previewWall.hideFlags = HideFlags.HideAndDontSave; previewWall.transform.localPosition = new Vector3(0f, 4f, 0f); previewWall.transform.localEulerAngles = new Vector3(0f, 0f, -90f); previewWall.transform.localScale = new Vector3(1f, 1f, 10f); MeshRenderer previewWallRenderer = previewWall.GetComponent <MeshRenderer>(); previewWallRenderer.lightProbeUsage = LightProbeUsage.Off; previewWallRenderer.reflectionProbeUsage = ReflectionProbeUsage.Off; previewWallRenderer.material = AssetDatabase.GetBuiltinExtraResource <Material>("Default-Material.mat"); setupRenderPipelinePreviewWallRenderer(previewWallRenderer); m_PreviewRenderUtility.AddSingleGO(previewWall); GameObject previewFloor = GameObject.CreatePrimitive(PrimitiveType.Plane); previewFloor.name = "IESPreviewFloor"; previewFloor.hideFlags = HideFlags.HideAndDontSave; previewFloor.transform.localPosition = new Vector3(4f, 0f, 0f); previewFloor.transform.localEulerAngles = new Vector3(0f, 0f, 0f); previewFloor.transform.localScale = new Vector3(1f, 1f, 10f); MeshRenderer previewFloorRenderer = previewFloor.GetComponent <MeshRenderer>(); previewFloorRenderer.lightProbeUsage = LightProbeUsage.Off; previewFloorRenderer.reflectionProbeUsage = ReflectionProbeUsage.Off; previewFloorRenderer.material = AssetDatabase.GetBuiltinExtraResource <Material>("Default-Diffuse.mat"); setupRenderPipelinePreviewFloorRenderer(previewFloorRenderer); m_PreviewRenderUtility.AddSingleGO(previewFloor); } return(true); }
public virtual int OnGUI(PreviewRenderUtility context, BaseParam[] param) { return(0); }
/// <summary> /// Create a Texture2D icon of a SVG image (editor only version). /// </summary> /// <param name="svg">String containing svg content.</param> /// <param name="renderUtil">PreviewRenderUtility to use for drawing</param> /// <remarks> /// Standard header and footer will be included if not found in svgContent /// </remarks> public static Texture2D GetIcon(string svgContent, PreviewRenderUtility renderUtil) { string svg; if (svgContent.StartsWith("<?xml version = \"1.0\" encoding=\"UTF - 8\"?>")) { svg = svgContent; } else { svg = svgIconHeader + svgContent; } if (!svg.EndsWith(svgIconFooter)) { svg = svg + svgIconFooter; } // Parse the SVG SVGParser.SceneInfo sceneInfo = SVGParser.ImportSVG(new System.IO.StringReader(svg)); int width = Mathf.CeilToInt(sceneInfo.SceneViewport.width); int height = Mathf.CeilToInt(sceneInfo.SceneViewport.height); if ((width > 64) || (height > 64)) { Debug.LogWarning("SVG icon of unusual size!"); } // Save the render state and get a temporary render texture RenderTexture activeTexture = RenderTexture.active; renderUtil.camera.targetTexture = RenderTexture.GetTemporary(width * 2, height * 2, 8, RenderTextureFormat.ARGB32); renderUtil.camera.backgroundColor = Color.clear; // Generate the mesh Mesh iconMesh = new Mesh(); List <VectorUtils.Geometry> iconGeometry = VectorUtils.TessellateScene(sceneInfo.Scene, tessellationOptions); VectorUtils.FillMesh(iconMesh, iconGeometry, 1f); // Activate the render texture and draw the mesh into it RenderTexture.active = renderUtil.camera.targetTexture; float cameraSize = renderUtil.camera.orthographicSize; Vector3 cameraPosition = renderUtil.camera.transform.position; renderUtil.camera.orthographicSize = sceneInfo.SceneViewport.height / 2; renderUtil.camera.transform.position = new Vector3(sceneInfo.SceneViewport.center.x, sceneInfo.SceneViewport.center.y, -1); // HACK until FillMesh() flpYAxis is fixed renderUtil.camera.transform.Rotate(0, 0, 180f); renderUtil.DrawMesh(iconMesh, Matrix4x4.identity, renderMaterial, 0); renderUtil.camera.Render(); renderUtil.camera.transform.Rotate(0, 0, 180f); renderUtil.camera.orthographicSize = cameraSize; renderUtil.camera.transform.position = cameraPosition; Texture2D iconTexture = new Texture2D(width * 2, height * 2); iconTexture.ReadPixels(new Rect(0, 0, width * 2, height * 2), 0, 0); iconTexture.Apply(); // Restore the render state and release the temporary objects RenderTexture.active = activeTexture; RenderTexture.ReleaseTemporary(renderUtil.camera.targetTexture); UnityEngine.Object.DestroyImmediate(iconMesh); return(iconTexture); }
public static void DrawPreview(PreviewRenderUtility previewUtil, Material mat, Mesh mesh, PreviewType previewType, Vector2 scroll, ref Quaternion camRot) { const string uPosition = "dr_LightPosition"; const string uColor = "dr_LightColor"; const string uAtten = "dr_LightAtten"; // reset position and rotation previewUtil.m_Camera.transform.position = -Vector3.forward * 4.25f; previewUtil.m_Camera.transform.rotation = Quaternion.identity; Quaternion orientation = Quaternion.identity; if (previewType == PreviewType.kInteractive) { orientation = Quaternion.AngleAxis(scroll.y, Vector3.right) * Quaternion.AngleAxis(scroll.x, Vector3.up); if (Quaternion.Dot(camRot, orientation) < 0f) { orientation = Quaternion.Inverse(orientation); orientation.w *= -1; } camRot = Quaternion.Lerp(camRot, orientation, 0.25f); orientation = Quaternion.Inverse(camRot); } // apply camera orientation and position previewUtil.m_Camera.transform.position = orientation * previewUtil.m_Camera.transform.position; previewUtil.m_Camera.transform.LookAt(Vector3.zero, orientation * Vector3.up); bool staticLit = mat.IsKeywordEnabled("STATIC_LIGHTING"); Vector4 posSave = Vector4.zero; Vector4 colorSave = Vector4.zero; Vector4 attenSave = Vector4.zero; Debug.logger.logEnabled = false; if (!staticLit) { if (mat.HasProperty(uPosition)) { posSave = mat.GetVector(uPosition); colorSave = mat.GetColor(uColor); attenSave = mat.GetVector(uAtten); } Vector4 dir = new Vector4(-0.707f, 0.0f, 0.707f, 0.0f); Vector4 atten = new Vector4(-1f, 1f, 1f, 625f); Vector3 color = new Vector4(1f, 1f, 1f, 1f); mat.SetVector(uPosition, dir); mat.SetVector(uColor, color); mat.SetVector(uAtten, atten); } Debug.logger.logEnabled = true; if (mesh != null) { previewUtil.DrawMesh(mesh, Vector3.zero, Quaternion.identity, mat, 0); } previewUtil.m_Camera.Render(); if (!staticLit) { mat.SetVector(uPosition, posSave); mat.SetVector(uColor, colorSave); mat.SetVector(uAtten, attenSave); } }
private void OnDisable() { previewRenderUtility?.Cleanup(); EditorSceneManager.ClosePreviewScene(previewScene); previewRenderUtility = null; }
public override int OnGUI(PreviewRenderUtility context, BaseParam[] param) { int refreshCount = 0; if (Enabled != false) { if (param[(int)PreParamType.kMesh] is MeshParam meshParam) { if (meshParam.meshType != MeshType.kPrefab) { return(0); } if (meshParam.gameObject != null && animator == null) { var output = meshParam.gameObject.GetComponent <Animator>(); if (output == null) { output = meshParam.gameObject.AddComponent <Animator>(); } if (output != null && object.ReferenceEquals(output, null) == false) { AnimationClip[] clips = null; clipIndex = 0; if (output.runtimeAnimatorController != null) { clips = output.runtimeAnimatorController.animationClips; } animator = new SimpleAnimator(output, clips, clipIndex); animator.SetTimeUpdateMode(DirectorUpdateMode.Manual); if (clip != null) { animator.SetClip(clip); } if (animator.CurrentClip != null) { if (animationSeek > animator.CurrentClip.length) { animationSeek = animator.CurrentClip.length; } animator.EvaluateTime(animationSeek); refreshCount = 2; } } } } } OnPUI("Animation", true, () => { var clipValue = EditorGUILayout.ObjectField("Clip", clip, typeof(AnimationClip), false) as AnimationClip; if (object.ReferenceEquals(clip, clipValue) == false) { Record("Change Clip"); animator?.SetClip(clipValue); clip = clipValue; } if (animator != null) { if ((animator.Clips?.Length ?? 0) > 0 && clip == null) { int clipIndexValue = EditorGUILayout.Popup("Clips", clipIndex, animator.Clips.Select(x => x.name).ToArray()); if (clipIndex.Equals(clipIndexValue) == false) { Record("Change Clips"); clipIndex = clipIndexValue; animator.SetClip(clipIndex); if (animationSeek > animator.CurrentClip.length) { animationSeek = animator.CurrentClip.length; } refreshCount = 2; } } if (animator.CurrentClip != null) { float animationSeekValue = EditorGUILayout.Slider("Seconds", animationSeek, 0.0f, animator.CurrentClip.length); if (animationSeek.Equals(animationSeekValue) == false) { Record("Change Seconds"); animationSeek = animationSeekValue; } } } }); return(refreshCount); }
private static void RenderMeshPreviewSkipCameraAndLighting(RoseMapObjectData mapObj, Matrix4x4[] mats, Bounds bounds, PreviewRenderUtility previewUtility, MaterialPropertyBlock customProperties, Vector2 direction) { bool fog = RenderSettings.fog; Unsupported.SetRenderSettingsUseFogNoDirty(false); Quaternion quaternion = Quaternion.Euler(direction.y, 0f, 0f) * Quaternion.Euler(0f, direction.x, 0f); Vector3 pos = quaternion * -bounds.center; Matrix4x4 rootTRS = new Matrix4x4(); rootTRS.SetTRS(pos, quaternion, Vector3.one); for (var i = 0; i < mapObj.subObjects.Count; ++i) { var subObj = mapObj.subObjects[i]; previewUtility.DrawMesh(subObj.mesh, rootTRS * mats[i], subObj.material, 0); } previewUtility.m_Camera.Render(); Unsupported.SetRenderSettingsUseFogNoDirty(fog); }
public PreviewData(UnityObject targetObject) { renderUtility = new PreviewRenderUtility(); renderUtility.camera.fieldOfView = 30.0f; UpdateGameObject(targetObject); }
protected virtual void OnEnable() { generator = target as _EZMeshGenerator; preview = new PreviewRenderUtility(); }
public override int OnGUI(PreviewRenderUtility context, BaseParam[] param) { int refreshCount = 0; OnPUI("Mesh", false, () => { var meshTypeValue = (MeshType)EditorGUILayout.EnumPopup("Type", meshType); if (meshType.Equals(meshTypeValue) == false) { Record("Change Mesh Type"); if (param[(int)PreParamType.kAnimation] is AnimationParam animationParam) { animationParam.Dispose(); } if (gameObject != null) { GameObject.DestroyImmediate(gameObject); gameObject = null; } if (boundsObject != null) { GameObject.DestroyImmediate(boundsObject); boundsObject = null; } meshType = meshTypeValue; } if (meshType == MeshType.kAssets) { var assetMeshValue = EditorGUILayout.ObjectField("Mesh", assetMesh, typeof(Mesh), false) as Mesh; if (assetMesh != assetMeshValue) { Record("Change Mesh Assets"); assetMesh = assetMeshValue; } } else if (meshType == MeshType.kDynamic) { Color vertexColorValue = EditorGUILayout.ColorField("Vertex Color", vertexColor); if (vertexColor.Equals(vertexColorValue) == false) { Record("Change Vertex Color"); dynamicMesh.colors = new Color[] { vertexColorValue, vertexColorValue, vertexColorValue, vertexColorValue }; vertexColor = vertexColorValue; } List <Vector4> texcoord; Vector4 uv; Vector2 texcoordZW = new Vector2(texcoords0.z, texcoords0.w); Vector2 uvZW = EditorGUILayout.Vector2Field("TexCoord0.zw", texcoordZW); if (texcoordZW.Equals(uvZW) == false) { Record("Change TexCoord0"); texcoord = new List <Vector4>(); texcoord.Add(new Vector4(0, 0, uvZW.x, uvZW.y)); texcoord.Add(new Vector4(0, 1, uvZW.x, uvZW.y)); texcoord.Add(new Vector4(1, 0, uvZW.x, uvZW.y)); texcoord.Add(new Vector4(1, 1, uvZW.x, uvZW.y)); dynamicMesh.SetUVs(0, texcoord); texcoords0 = new Vector4(0, 0, uvZW.x, uvZW.y); } uv = EditorGUILayout.Vector4Field("TexCoord1", texcoords1); if (texcoords1.Equals(uv) == false) { Record("Change TexCoord1"); texcoord = new List <Vector4>(); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); dynamicMesh.SetUVs(1, texcoord); texcoords1 = uv; } uv = EditorGUILayout.Vector4Field("TexCoord2", texcoords2); if (texcoords2.Equals(uv) == false) { Record("Change TexCoord2"); texcoord = new List <Vector4>(); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); dynamicMesh.SetUVs(2, texcoord); texcoords2 = uv; } uv = EditorGUILayout.Vector4Field("TexCoord3", texcoords3); if (texcoords3.Equals(uv) == false) { Record("Change TexCoord3"); texcoord = new List <Vector4>(); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); dynamicMesh.SetUVs(3, texcoord); texcoords3 = uv; } uv = EditorGUILayout.Vector4Field("TexCoord4", texcoords4); if (texcoords4.Equals(uv) == false) { Record("Change TexCoord4"); texcoord = new List <Vector4>(); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); dynamicMesh.SetUVs(4, texcoord); texcoords4 = uv; } uv = EditorGUILayout.Vector4Field("TexCoord5", texcoords5); if (texcoords5.Equals(uv) == false) { Record("Change TexCoord5"); texcoord = new List <Vector4>(); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); dynamicMesh.SetUVs(5, texcoord); texcoords5 = uv; } uv = EditorGUILayout.Vector4Field("TexCoord6", texcoords6); if (texcoords6.Equals(uv) == false) { Record("Change TexCoord6"); texcoord = new List <Vector4>(); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); dynamicMesh.SetUVs(6, texcoord); texcoords6 = uv; } uv = EditorGUILayout.Vector4Field("TexCoord7", texcoords7); if (texcoords7.Equals(uv) == false) { Record("Change TexCoord7"); texcoord = new List <Vector4>(); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); texcoord.Add(uv); dynamicMesh.SetUVs(7, texcoord); texcoords7 = uv; } } else if (meshType == MeshType.kPrefab) { var prefabValue = EditorGUILayout.ObjectField("Prefab", prefab, typeof(GameObject), false) as GameObject; if (requestPrefab != null) { prefabValue = requestPrefab; requestPrefab = null; GUI.changed = true; } if (prefab != prefabValue) { Record("Change Prefab"); if (param[(int)PreParamType.kAnimation] is AnimationParam animationParam) { animationParam.Dispose(); } if (gameObject != null) { GameObject.DestroyImmediate(gameObject); gameObject = null; } if (boundsObject != null) { GameObject.DestroyImmediate(boundsObject); boundsObject = null; } prefab = prefabValue; } bool autoViewFitValue = EditorGUILayout.Toggle("Auto view fit", autoViewFit); if (autoViewFit.Equals(autoViewFitValue) == false) { autoViewFit = autoViewFitValue; } bool showBoundsValue = EditorGUILayout.Toggle("Show BoundingBox", showBounds); if (showBounds.Equals(showBoundsValue) == false) { boundsObject.SetActive(showBoundsValue); showBounds = showBoundsValue; } } if (prefab != null) { if (gameObject == null) { gameObject = context.InstantiatePrefabInScene(prefab); if (param[(int)PreParamType.kCamera] is CameraParam cameraParam) { if (param[(int)PreParamType.kTexture] is TextureParam textureParam) { if (param[(int)PreParamType.kTransform] is TransformParam transformParam) { if (autoViewFit != false) { cameraParam.ToPreset(CameraPreset.kFit, textureParam, transformParam, this); } } } } } if (boundsObject == null) { boundsObject = new GameObject("Bounds", typeof(MeshFilter), typeof(MeshRenderer)); context.AddSingleGO(boundsObject); boundsObject.GetComponent <MeshFilter>().sharedMesh = boundsMesh; boundsObject.GetComponent <MeshRenderer>().sharedMaterial = boundsMaterial; boundsObject.transform.SetParent(gameObject.transform, false); boundsObject.SetActive(showBounds); } } }); return(refreshCount); }
protected void EndPreview(PreviewRenderUtility util, Rect rect) { GUI.DrawTexture(rect, EndPreview(util)); }
void OnDisable() { DestroyImmediate(previewObject); previewRenderUtility.Cleanup(); previewRenderUtility = null; }
void OnEnable() { m_target = (VRMLookAtHead)target; m_previewRenderUtility = new PreviewRenderUtility(true); }
public void Draw([NotNull] SerializedProperty property, [CanBeNull] SerializedProperty mask) { var modeProperty = property.FindPropertyRelative(_channelModeProperty); using (new VerticalStripContext(_color, lineWidth: 2)) { // Show mode property and show no more UI if it's disabled if (modeProperty != null) { EditorGUILayout.PropertyField(modeProperty); if ((DecalLayerChannel.DecalChannelMode)modeProperty.enumValueIndex == DecalLayerChannel.DecalChannelMode.Disabled) { return; } } using (new EditorGUI.IndentLevelScope()) { // Show advanced settings if we're explicitly in advanced mode (or we can't tell what the mode is) var mode = modeProperty != null ? (DecalLayerChannel.DecalChannelMode)modeProperty.enumValueIndex : DecalLayerChannel.DecalChannelMode.AdvancedRangeRemap; var inThreshold = property.FindPropertyRelative(_inputThresholdProperty); var inSoftness = property.FindPropertyRelative(_inputSoftnessProperty); var outRange = property.FindPropertyRelative(_outputRangeProperty); // Show basic settings var showInputRange = mode == DecalLayerChannel.DecalChannelMode.SimpleRangeRemap || mode == DecalLayerChannel.DecalChannelMode.AdvancedRangeRemap; if (showInputRange) { EditorGUILayout.PropertyField(inThreshold); EditorGUILayout.PropertyField(inSoftness); } // Show advanced settings if in advanced mode var showOutputRange = mode == DecalLayerChannel.DecalChannelMode.AdvancedRangeRemap; if (showOutputRange) { EditorGUILayout.PropertyField(outRange); } // If we were given no mask then no preview can be rendered, early exit if (mask == null) { return; } // Create a list of reasons the visualiser cannot be displayed var reasons = new List <string>(); if (mask.hasMultipleDifferentValues) { reasons.Add("'Layer Mask'"); } if (showInputRange) { if (inThreshold.hasMultipleDifferentValues) { reasons.Add("'Input Threshold'"); } if (inSoftness.hasMultipleDifferentValues) { reasons.Add("'Input Softness'"); } } if (showOutputRange) { if (outRange.hasMultipleDifferentValues) { reasons.Add("'Output Range'"); } } if (reasons.Count > 0) { EditorGUILayout.HelpBox(string.Format("Levels Visualiser unavailable with mixed {0} values", string.Join(", ", reasons.ToArray())), MessageType.Warning); } else { // Show a foldout section for the preview if (modeProperty == null || (DecalLayerChannel.DecalChannelMode)modeProperty.enumValueIndex != DecalLayerChannel.DecalChannelMode.Disabled) { _showPreview = EditorGUILayout.Foldout(_showPreview, "Levels Visualizer"); } else { _showPreview = false; } // Show the preview if (_showPreview) { // Can't initialise this in a field initialiser because Unity won't less this be called in certan contexts if (_renderUtility == null) { _renderUtility = new PreviewRenderUtility(false); } // Calculate the area to draw the preview in const float aspectRatio = 2.2f; var width = EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth; var height = width / aspectRatio; var area = EditorGUILayout.GetControlRect(false, height); area.yMax -= EditorGUIUtility.singleLineHeight / 2; area.xMin += EditorGUIUtility.labelWidth; var iRange = DecalLayerChannel.EvaluateInputRange(mode, inThreshold.floatValue, inSoftness.floatValue); var oRange = DecalLayerChannel.EvaluateOutputRange(mode, outRange.vector2Value); DrawLayerPreview(area, _renderUtility, LayerPreview, (Texture2D)mask.objectReferenceValue, iRange, oRange, _weights); } } } } }
private void OnDisable() { preview.Cleanup(); preview = null; }
public static void DoRenderPreview(SVGAsset targetObject, PreviewRenderUtility previewUtility) { if (targetObject == null) { return; } bool hasGradients = targetObject.hasGradients; Mesh tempMesh = GetMesh(targetObject); if (tempMesh == null) { return; } Material[] sharedMaterials = targetObject.sharedMaterials; Material[] outputMaterials = sharedMaterials; if (tempMesh == null || sharedMaterials == null || sharedMaterials.Length == 0) { return; } Texture2D gradientAtlas = null; if (hasGradients) { gradientAtlas = SVGAtlas.GenerateGradientAtlasTexture(targetObject.sharedGradients, SVGAtlas.defaultGradientWidth, SVGAtlas.defaultGradientHeight); outputMaterials = new Material[sharedMaterials.Length]; for (int i = 0; i < sharedMaterials.Length; i++) { if (sharedMaterials[i] == null) { continue; } outputMaterials[i] = Instantiate(sharedMaterials[i]) as Material; if (outputMaterials[i].HasProperty("_Params")) { outputMaterials[i].SetVector("_Params", new Vector4(gradientAtlas.width, gradientAtlas.height, SVGAtlas.defaultGradientWidth, SVGAtlas.defaultGradientHeight)); } if (outputMaterials[i].HasProperty("_GradientColor")) { outputMaterials[i].SetTexture("_GradientColor", gradientAtlas); } if (outputMaterials[i].HasProperty("_GradientShape")) { outputMaterials[i].SetTexture("_GradientShape", SVGAtlas.gradientShapeTexture); } } } RenderMeshPreviewSkipCameraAndLighting(tempMesh, previewUtility, outputMaterials); if (hasGradients) { for (int i = 0; i < outputMaterials.Length; i++) { if (outputMaterials[i] == null) { continue; } DestroyImmediate(outputMaterials[i]); } } if (gradientAtlas != null) { DestroyImmediate(gradientAtlas); } }
protected virtual void OnDisable() { m_previewRender.Cleanup(); m_previewRender = null; }
private void InitPreview() { if (m_Loaded) { return; } m_Loaded = true; if (m_PreviewUtility == null) { m_PreviewUtility = new PreviewRenderUtility(true); #if UNITY_2017_1_OR_NEWER m_PreviewUtility.cameraFieldOfView = 30f; #else m_PreviewUtility.m_CameraFieldOfView = 30f; #endif GetPreviewCamera().cullingMask = 1 << PreviewCullingLayer; #if UNITY_5_6_OR_NEWER GetPreviewCamera().allowHDR = false; GetPreviewCamera().allowMSAA = false; #endif CreatePreviewInstances(); } if (m_FloorPlane == null) { m_FloorPlane = (Resources.GetBuiltinResource(typeof(Mesh), "New-Plane.fbx") as Mesh); } if (m_FloorTexture == null) { m_FloorTexture = (Texture2D)EditorGUIUtility.Load("Avatar/Textures/AvatarFloor.png"); } if (m_FloorMaterial == null) { Shader shader = EditorGUIUtility.LoadRequired("Previews/PreviewPlaneWithShadow.shader") as Shader; m_FloorMaterial = new Material(shader); m_FloorMaterial.mainTexture = m_FloorTexture; m_FloorMaterial.mainTextureScale = Vector2.one * 5f * 4f; m_FloorMaterial.SetVector("_Alphas", new Vector4(0.5f, 0.3f, 0f, 0f)); m_FloorMaterial.hideFlags = HideFlags.HideAndDontSave; } if (m_ReferenceInstance == null) { GameObject original = (GameObject)EditorGUIUtility.Load("Avatar/dial_flat.prefab"); m_ReferenceInstance = (GameObject)UnityEngine.Object.Instantiate(original, Vector3.zero, Quaternion.identity); InitInstantiatedPreviewRecursive(m_ReferenceInstance); AddSingleGO(m_ReferenceInstance); } if (m_DirectionInstance == null) { GameObject original2 = (GameObject)EditorGUIUtility.Load("Avatar/arrow.fbx"); m_DirectionInstance = (GameObject)UnityEngine.Object.Instantiate(original2, Vector3.zero, Quaternion.identity); InitInstantiatedPreviewRecursive(m_DirectionInstance); AddSingleGO(m_DirectionInstance); } if (m_PivotInstance == null) { GameObject original3 = (GameObject)EditorGUIUtility.Load("Avatar/root.fbx"); m_PivotInstance = (GameObject)UnityEngine.Object.Instantiate(original3, Vector3.zero, Quaternion.identity); InitInstantiatedPreviewRecursive(m_PivotInstance); AddSingleGO(m_PivotInstance); } if (m_RootInstance == null) { GameObject original4 = (GameObject)EditorGUIUtility.Load("Avatar/root.fbx"); m_RootInstance = (GameObject)UnityEngine.Object.Instantiate(original4, Vector3.zero, Quaternion.identity); InitInstantiatedPreviewRecursive(m_RootInstance); AddSingleGO(m_RootInstance); } m_ShowReference = EditorPrefs.GetBool("AvatarpreviewShowReference", true); SetPreviewCharacterEnabled(false, false); }
private void OnDisable() { m_previewRenderUtility.Cleanup(); m_previewRenderUtility = null; }
void OnDisable() { previewRenderUtility.Cleanup(); previewRenderUtility = null; previewObject = null; }
public static void InitPreview(Rect r, PreviewRenderUtility previewUtility) { typeof(PreviewRenderUtility).GetMethod("InitPreview", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(previewUtility, new object[] { r }); }
static void RenderMeshPreview(Mesh mesh, PreviewRenderUtility previewUtility, Material litMaterial, Material wireMaterial, Vector2 direction, int meshSubset) { RenderMeshPreviewInfo.Invoke(null, new object[] { mesh, previewUtility, litMaterial, wireMaterial, direction, meshSubset }); }