Code for/replicate VisualTreeAsset's ObjectPreview

I have an asset which I want to provide an ObjectPreview for, and my asset render’s as a VisualElement.

I noticed the VisualTreeAsset has an ObjectPreview (texture I assume)…

I’m hoping to make use of this (I presume) UIToolkit off-screen render.

Is the code for this availiable anywhere? With Rider’s decompiler, I couldn’t really find an ObjectPreview implementation

As a side note, I’ve tried to use the VisualElement CreateInspectorGUI() overload, but that seems to mess up with my visual element render of my asset (Maybe because it makes heavy use of Painter2D)

Edit: using unity 2022.3.14

It looks like I could use

Painter2D Painter;
MyThing.RenderToPainter(Painter);
var Vector = Painter.SaveToVectorImage;
var Texure = VectorUtils.RenderVectorImageToTexture2D( Vector );

But alas, all the vector util functions are internal.
So close!

I have accomplished this, by copy+pasta all the VectorUtils code to render a vectorimage’s contents to a texture.

  • I had to copy all the code, as it’s internal in VectorUtils
  • Unity’s VectorImage internals are all locked down too, so I serialise the VectorImage to json, then back to an identical type which has all it’s members exposed