浏览代码

Merge pull request #133 from Unity-Technologies/inspector-preview-mesh

Inspector preview mesh
/main
GitHub 7 年前
当前提交
1f3752d8
共有 5 个文件被更改,包括 21 次插入65 次删除
  1. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  3. 15
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs
  4. 34
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Scrollable.cs
  5. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Scrollable.cs.meta

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs


#endregion
[NonSerialized]
[SerializeField]
InspectorPreviewData m_PreviewData = new InspectorPreviewData();
public InspectorPreviewData previewData

}
}
}
[Serializable]
public Mesh mesh;
public SerializableMesh serializedMesh = new SerializableMesh();
[NonSerialized]
public float scale = 1f;
}
}

16
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs


m_PreviewTextureView = new PreviewTextureView { name = "preview", image = Texture2D.blackTexture };
m_PreviewTextureView.AddManipulator(new Draggable(OnMouseDrag, true));
m_PreviewTextureView.AddManipulator(new Scrollable(OnMouseScroll));
bottomContainer.Add(m_PreviewTextureView);
m_PreviewScrollPosition = new Vector2(0f, 0f);

m_PreviewRenderHandle = previewManager.masterRenderData;
m_PreviewRenderHandle.onPreviewChanged += OnPreviewChanged;
m_PreviewMeshPicker.SetValueAndNotify(m_Graph.previewData.mesh);
m_PreviewMeshPicker.SetValueAndNotify(m_Graph.previewData.serializedMesh.mesh);
foreach (var property in m_Graph.properties)
m_PropertyItems.Add(new ShaderPropertyView(m_Graph, property));

masterNode.onModified(masterNode, ModificationScope.Node);
}
void OnMouseScroll(float scrollDelta)
{
m_Graph.previewData.scale -= scrollDelta * .01f;
m_Graph.previewData.scale = Mathf.Clamp(m_Graph.previewData.scale, .1f, 4f);
masterNode.onModified(masterNode, ModificationScope.Node);
}
void OnAddProperty()
{
var gm = new GenericMenu();

masterNode.onModified(masterNode, ModificationScope.Node);
if (m_Graph.previewData.mesh != changedMesh)
if (m_Graph.previewData.serializedMesh.mesh != changedMesh)
m_Graph.previewData.scale = 1f;
m_Graph.previewData.mesh = changedMesh;
m_Graph.previewData.serializedMesh.mesh = changedMesh;
}
public void UpdateSelection(IEnumerable<INode> nodes)

15
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs


RenderTexture.active = renderData.renderTexture;
GL.Clear(true, true, Color.black);
Graphics.Blit(Texture2D.whiteTexture, renderData.renderTexture, m_SceneResources.checkerboardMaterial);
var mesh = (renderData == masterRenderData && m_Graph.previewData.mesh) ? m_Graph.previewData.mesh : m_SceneResources.sphere;
var mesh = (renderData == masterRenderData && m_Graph.previewData.serializedMesh.mesh) ? m_Graph.previewData.serializedMesh.mesh : m_SceneResources.sphere;
float scale = (renderData == masterRenderData) ? m_Graph.previewData.scale : 1f;
Graphics.DrawMesh(mesh, Matrix4x4.TRS(-mesh.bounds.center, rotation, Vector3.one * scale), m_PreviewMaterial, 1, m_SceneResources.camera, 0, m_PreviewPropertyBlock, ShadowCastingMode.Off, false, null, false);
Matrix4x4 previewTransform = Matrix4x4.identity;
if (renderData == masterRenderData)
{
previewTransform *= Matrix4x4.Rotate(rotation);
previewTransform *= Matrix4x4.Scale(Vector3.one * (Vector3.one).magnitude / mesh.bounds.size.magnitude);
previewTransform *= Matrix4x4.Translate(-mesh.bounds.center);
}
Graphics.DrawMesh(mesh, previewTransform, m_PreviewMaterial, 1, m_SceneResources.camera, 0, m_PreviewPropertyBlock, ShadowCastingMode.Off, false, null, false);
var previousUseSRP = Unsupported.useScriptableRenderPipeline;
Unsupported.useScriptableRenderPipeline = renderData.shaderData.node is IMasterNode;
m_SceneResources.camera.Render();

34
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Scrollable.cs


using System;
using UnityEngine.Experimental.UIElements;
namespace UnityEditor.ShaderGraph.Drawing
{
public class Scrollable : MouseManipulator
{
Action<float> m_Handler;
public Scrollable(Action<float> handler)
{
m_Handler = handler;
activators.Add(new ManipulatorActivationFilter()
{
button = MouseButton.LeftMouse
});
}
protected override void RegisterCallbacksOnTarget()
{
target.RegisterCallback(new EventCallback<WheelEvent>(OnMouseWheel), Capture.NoCapture);
}
protected override void UnregisterCallbacksFromTarget()
{
target.UnregisterCallback(new EventCallback<WheelEvent>(OnMouseWheel), Capture.NoCapture);
}
void OnMouseWheel(WheelEvent evt)
{
m_Handler(evt.delta.y);
}
}
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Scrollable.cs.meta


fileFormatVersion: 2
guid: 1fde0872f0455304bb082dbee731fabf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存