Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Maxscript: get the Material Editor thumbnail for an arbitrary material
-- Reads the 88x88 thumbnail from Material Editor for an arbitrary material.
-- Note that it renders faster when the material editor is closed,
-- so you could call `MatEditor.Close()` first.
--
-- Parameters:
-- mat: a material instance (StandardMaterial, Universal_Material, etc..)
--
-- Returns:
-- a Bitmap or `undefined`
--
fn getMaterialThumbnail mat = (
local thumb = undefined
local iGlobal = (dotnetClass "Autodesk.Max.GlobalInterface").Instance
if iGlobal != undefined then (
local IntPtr = dotnetClass "System.IntPtr"
local pStampSize = (dotnetclass "Autodesk.Max.PostageStampSize").Large
local backupMat = meditMaterials[1]
meditMaterials[1] = mat
local matRef = iGlobal.CoreInterface.GetMtlSlot 0
local pStamp = matRef.CreatePStamp pStampSize true
local bytes = pStamp.Image
local size = pStamp.Width
thumb = bitmap size size gamma:0.5
local step = size * 3
for y = 1 to bytes.count by step do (
local row = for x = y to (y + step - 1) by 3 collect [bytes[x + 2], bytes[x + 1], bytes[x]]
setpixels thumb [0, size -= 1] row
)
pStamp.Dispose()
matRef.Dispose()
meditMaterials[1] = backupMat
)
return thumb
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.