浏览代码

Add zoom/scale to preview mesh and refactor preview data into seperate class

/main
Jens Holm 7 年前
当前提交
682d177b
共有 4 个文件被更改,包括 30 次插入13 次删除
  1. 16
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 15
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  3. 7
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Draggable.cs
  4. 5
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs

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


[NonSerialized]
List<Guid> m_RemovedProperties = new List<Guid>();
[SerializeField]
SerializableMesh m_PreviewMesh;
[NonSerialized]
public InspectorPreviewData previewData = new InspectorPreviewData();
get { return m_PreviewMesh.mesh; }
set { m_PreviewMesh.mesh = value; }
get { return previewData.mesh; }
set { previewData.mesh = value; }
}
public IEnumerable<IShaderProperty> properties

configuredTextures = shaderProperties.GetConfiguredTexutres();
return finalShader.GetShaderString(0);
}
}
public class InspectorPreviewData
{
public Mesh mesh;
public Quaternion rotation = Quaternion.identity;
public float scale = 1f;
}
}

15
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_PreviewScrollPosition -= deltaMouse * (Event.current.shift ? 3f : 1f) / Mathf.Min(previewSize.x, previewSize.y) * 140f;
m_PreviewScrollPosition.y = Mathf.Clamp(m_PreviewScrollPosition.y, -90f, 90f);
Quaternion previewRotation = Quaternion.Euler(m_PreviewScrollPosition.y, 0, 0) * Quaternion.Euler(0, m_PreviewScrollPosition.x, 0);
m_Graph.previewRotation = previewRotation;
m_Graph.previewData.rotation = previewRotation;
}
void OnMouseScroll(float scrollDelta)
{
m_Graph.previewData.scale -= scrollDelta * .01f;
m_Graph.previewData.scale = Mathf.Clamp(m_Graph.previewData.scale, .1f, 4f);
}
void OnAddProperty()

Mesh changedMesh = changeEvent.newValue as Mesh;
masterNode.onModified(masterNode, ModificationScope.Node);
if (m_Graph.previewMesh != changedMesh)
{
m_Graph.previewData.rotation = Quaternion.identity;
m_Graph.previewData.scale = 1f;
}
m_Graph.previewMesh = changedMesh;
}

7
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Manipulators/Draggable.cs


bool m_OutputDeltaMovement;
Vector2 m_PreviousMousePosition;
public Draggable(Action<Vector2> handler, bool outputDeltaMovement = false)
{
m_Handler = handler;

void OnMouseDown(MouseDownEvent evt)
{
m_PreviousMousePosition = evt.localMousePosition;
target.TakeMouseCapture();
m_Active = true;
evt.StopPropagation();

{
if (m_OutputDeltaMovement)
{
Vector2 deltaMouse = evt.localMousePosition - m_PreviousMousePosition;
m_PreviousMousePosition = evt.localMousePosition;
m_Handler(deltaMouse);
m_Handler(evt.mouseDelta);
}
else
{

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


GL.Clear(true, true, Color.black);
Graphics.Blit(Texture2D.whiteTexture, renderData.renderTexture, m_SceneResources.checkerboardMaterial);
var mesh = (renderData == masterRenderData && m_Graph.previewMesh) ? m_Graph.previewMesh : m_SceneResources.sphere;
Quaternion rotation = (renderData == masterRenderData) ? m_Graph.previewRotation : Quaternion.identity;
Graphics.DrawMesh(mesh, Matrix4x4.TRS(-mesh.bounds.center, rotation, Vector3.one), m_PreviewMaterial, 1, m_SceneResources.camera, 0, m_PreviewPropertyBlock, ShadowCastingMode.Off, false, null, false);
Quaternion rotation = (renderData == masterRenderData) ? m_Graph.previewData.rotation : Quaternion.identity;
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);
var previousUseSRP = Unsupported.useScriptableRenderPipeline;
Unsupported.useScriptableRenderPipeline = renderData.shaderData.node is IMasterNode;
m_SceneResources.camera.Render();

正在加载...
取消
保存