Created
January 3, 2019 14:35
-
-
Save cecilemuller/057d5ccdcbe8964d9babc6b339986bf5 to your computer and use it in GitHub Desktop.
Maxscript: get the Material Editor thumbnail for an arbitrary material
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 | |
) |
Any way to generate larger bitmaps?
88x88 is kind of useless
No, 88x88 is a hard limit imposed by this interface. Most people seem to instead set up background rendering in this situation.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I converted this to python, if that is useful to anyone.