/// <inheritdoc /> public override void Dispose() { if (_preview != null) { _preview.Dispose(); _preview = null; } base.Dispose(); }
/// <inheritdoc /> public override void OnThumbnailDrawPrepare(ThumbnailRequest request) { if (_preview == null) { _preview = new PrefabPreview(false); InitAssetPreview(_preview); } // TODO: disable streaming for asset during thumbnail rendering (and restore it after) }
/// <inheritdoc /> public override void OnThumbnailDrawPrepare(ThumbnailRequest request) { if (_preview == null) { _preview = new PrefabPreview(false); _preview.RenderOnlyWithWindow = false; _preview.Task.Enabled = false; _preview.PostFxVolume.Settings.Eye_Technique = EyeAdaptationTechnique.None; _preview.PostFxVolume.Settings.Eye_Exposure = 0.1f; _preview.PostFxVolume.Settings.data.Flags4 |= 0b1001; _preview.Size = new Vector2(PreviewsCache.AssetIconSize, PreviewsCache.AssetIconSize); _preview.SyncBackbufferSize(); } // TODO: disable streaming for asset during thumbnail rendering (and restore it after) }
/// <inheritdoc /> public override void OnThumbnailDrawPrepare(ThumbnailRequest request) { if (_preview == null) { _preview = new PrefabPreview(false); _preview.RenderOnlyWithWindow = false; _preview.Task.Enabled = false; var eyeAdaptation = _preview.PostFxVolume.EyeAdaptation; eyeAdaptation.Mode = EyeAdaptationMode.None; eyeAdaptation.OverrideFlags |= EyeAdaptationSettings.Override.Mode; _preview.PostFxVolume.EyeAdaptation = eyeAdaptation; _preview.Size = new Vector2(PreviewsCache.AssetIconSize, PreviewsCache.AssetIconSize); _preview.SyncBackbufferSize(); } // TODO: disable streaming for asset during thumbnail rendering (and restore it after) }
/// <inheritdoc /> public override void OnThumbnailDrawPrepare(ThumbnailRequest request) { if (_preview == null) { _preview = new PrefabPreview(false) { RenderOnlyWithWindow = false, AnchorPreset = AnchorPresets.StretchAll, Offsets = Margin.Zero, }; _preview.Task.Enabled = false; var eyeAdaptation = _preview.PostFxVolume.EyeAdaptation; eyeAdaptation.Mode = EyeAdaptationMode.None; eyeAdaptation.OverrideFlags |= EyeAdaptationSettingsOverride.Mode; _preview.PostFxVolume.EyeAdaptation = eyeAdaptation; } // TODO: disable streaming for asset during thumbnail rendering (and restore it after) }
private IEnumerable <MeshPreview> GetVisibleMeshPreviews() { var unvisitedPrefabPreviews = new Stack <PrefabPreview>(cachedPrefabPreviewRoots); while (unvisitedPrefabPreviews.Count > 0) { PrefabPreview prefabPreview = unvisitedPrefabPreviews.Pop(); // NOTE: We're not checking activeInHierarchy because // it returns false for prefabs that are not in a scene. // NOTE: Some editor operations (eg. drag-and-drop of components) can // destroy the previewer on an instance without notifying us, so we'll gracefully // ignore all broken references until the prefab-update triggers a cleanup. if ((prefabPreview.SourcePreviewer != null) && prefabPreview.SourcePreviewer.enabled && prefabPreview.SourcePreviewer.gameObject.activeSelf && (prefabPreview.SourcePrefab != null) && prefabPreview.SourcePrefab.activeSelf && (prefabPreview.Instantiator != null) && prefabPreview.Instantiator.enabled) { foreach (MeshPreview meshPreview in prefabPreview.MeshPreviews) { if (meshPreview.SourceMeshRenderer.enabled) { yield return(meshPreview); } } foreach (PrefabPreview childPrefabPreview in prefabPreview.ChildPrefabPreviews) { unvisitedPrefabPreviews.Push(childPrefabPreview); } } } }
private static void AppendPrefabPreviewsRecursive( InstantiationPreviewer previewer, Matrix4x4 simulatedPreviewerLocalToWorldMatrix, List <PrefabPreview> inoutPrefabPreviews) { foreach (PrefabInstantiation prefabInstantiation in previewer.prefabInstantiations) { GameObject prefabSource = prefabInstantiation.Prefab; // We'll build up the matrix from the leaf-transform back to the root. Matrix4x4 instantiationLocalToWorldMatrix; { Vector3 filteredPrefabLocalPosition = ((prefabInstantiation.Flags & PreviewFlags.IgnorePrefabPosition) != 0) ? Vector3.zero : prefabSource.transform.localPosition; Quaternion filteredPrefabLocalRotation = ((prefabInstantiation.Flags & PreviewFlags.IgnorePrefabRotation) != 0) ? Quaternion.identity : prefabSource.transform.localRotation; Vector3 filteredPrefabLocalScale = ((prefabInstantiation.Flags & PreviewFlags.IgnorePrefabScale) != 0) ? Vector3.one : prefabSource.transform.localScale; // NOTE: It's confusing as hell, but we're first undoing the // prefab's local transform, and then redoing the parts of it // we actually want. This is frankly easier than decomposing the // transform and then just applying the portions we actually want included. instantiationLocalToWorldMatrix = Matrix4x4.TRS( filteredPrefabLocalPosition, filteredPrefabLocalRotation, filteredPrefabLocalScale) * Matrix4x4.TRS( prefabSource.transform.localPosition, prefabSource.transform.localRotation, prefabSource.transform.localScale).inverse; // Factor in the additional-transformation. instantiationLocalToWorldMatrix = ( Matrix4x4.TRS( prefabInstantiation.AdditionalTranslation, prefabInstantiation.AdditionalRotation, prefabInstantiation.AdditionalScaling) * instantiationLocalToWorldMatrix); if (prefabInstantiation.InstanceParent != null) { // NOTE: The previewer and instanceParent must either both be // instantiated (aka. in-scene), or both be within the same prefab. // In either case it means it's possible to compare their matrices. Matrix4x4 previewerToInstanceParentMatrix = ( previewer.transform.localToWorldMatrix.inverse * prefabInstantiation.InstanceParent.localToWorldMatrix); instantiationLocalToWorldMatrix = ( simulatedPreviewerLocalToWorldMatrix * previewerToInstanceParentMatrix * instantiationLocalToWorldMatrix); } else { // Since the instantiation is apparently a root-object, we're already // done because it's rejecting the heirarchy's simulated-previewer transform. } } List <MeshPreview> meshPreviews = new List <MeshPreview>(); foreach (MeshRenderer meshRenderer in prefabSource.GetComponentsInChildren <MeshRenderer>(includeInactive: true)) { meshPreviews.Add(new MeshPreview() { SourceMeshRenderer = meshRenderer, Mesh = meshRenderer.GetComponent <MeshFilter>().sharedMesh, LocalToMeshMatrix = (instantiationLocalToWorldMatrix * meshRenderer.transform.localToWorldMatrix), Materials = new List <Material>(meshRenderer.sharedMaterials), }); } PrefabPreview prefabPreview = new PrefabPreview() { SourcePreviewer = previewer, SourcePrefab = prefabInstantiation.Prefab, Instantiator = prefabInstantiation.Instantiator, MeshPreviews = meshPreviews, ChildPrefabPreviews = new List <PrefabPreview>(), }; inoutPrefabPreviews.Add(prefabPreview); foreach (InstantiationPreviewer childPreviewer in prefabSource.GetComponentsInChildren <InstantiationPreviewer>()) { AppendPrefabPreviewsRecursive( childPreviewer, (instantiationLocalToWorldMatrix * childPreviewer.transform.localToWorldMatrix), prefabPreview.ChildPrefabPreviews); } } }