Custom Inspector (material)

Hi all, I am trying to create a custom inspector for an object similar to the one that comes with unity for materials / mesh’s.

Unity preview pane:

I have spent a few hours trying to throw something together that would work for this but I am coming up blank. My current test bed is an EditorWindow (as in I am trying to simply render a sphere with a material into an editor window).

I have tried a few methods

Handles.DrawCamera( new Rect( 0, 0, Screen.width, Screen.height), previewCamera );
		Handles.ClearCamera( new Rect( 0, 0, Screen.width, Screen.height), previewCamera );
		for( var i = 0; i < material.passCount; i++ )
		{
			material.SetPass( i );
			Handles.SphereCap( 0, Vector3.zero, Quaternion.identity, 2.0f );
		}

and I have also tried using ‘draw mesh’.

Does anyone have any idea of a way that I could achieve this effect?

After doing some more experimentation it seems like I need a way to render an arbitrary mesh illuminated by an arbitrary array of lights to a texture / render texture. I don’t think there are any currently exposed ways to do this without massive hackery.

Anyone have any ideas?

I tried reflecting the DLL and something renders, but I don’t know enough about how it’s meant to be used to actually render anything :frowning:

object renderUtility = Activator.CreateInstance( renderUtilityType );

FieldInfo cameraField = renderUtilityType.GetField( "m_Camera" );
Camera c = (Camera)cameraField.GetValue( renderUtility );
c.backgroundColor = Color.red;
c.clearFlags = CameraClearFlags.SolidColor;

renderUtilityType.InvokeMember("BeginStaticPreview", 
                     BindingFlags.InvokeMethod | 
			         BindingFlags.Instance | 
			         BindingFlags.Public,
					 null,
                     renderUtility, 
                     new object[]{ new Rect( 0,0,200,200)} );

renderUtilityType.InvokeMember("DrawMesh", 
                     BindingFlags.InvokeMethod | 
			         BindingFlags.Instance | 
			         BindingFlags.Public,
					 null, 
                     renderUtility, 
                     new object[]{ sphere, Vector3.zero, Quaternion.identity, material, 0 } );

result = (RenderTexture)renderUtilityType.InvokeMember("EndPreview", 
                     BindingFlags.InvokeMethod | 
			         BindingFlags.Instance | 
			         BindingFlags.Public,
					 null, 
                     renderUtility, 
                     null );

Any ideas?