浏览代码

Center rotationin of preveiw mesh and fix serialization of preview mesh

/main
Jens Holm 7 年前
当前提交
8454398a
共有 3 个文件被更改,包括 22 次插入8 次删除
  1. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/AbstractMaterialGraph.cs
  2. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/GraphInspectorView.cs
  3. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/PreviewManager.cs

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


[NonSerialized]
List<Guid> m_RemovedProperties = new List<Guid>();
[NonSerialized]
[SerializeField]
InspectorPreviewData m_PreviewData = new InspectorPreviewData();
public InspectorPreviewData previewData

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

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


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);
if (m_Graph.previewData.mesh != changedMesh)
if (m_Graph.previewData.serializedMesh.mesh != changedMesh)
m_Graph.previewData.mesh = changedMesh;
m_Graph.previewData.serializedMesh.mesh = changedMesh;
}
public void UpdateSelection(IEnumerable<INode> nodes)

14
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;
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 * scale * .75f / mesh.bounds.extents.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();

正在加载...
取消
保存