Generate a bitmap texture from script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am writing a Python script that, among other things, generates bitmaps derived from some data. It then sets them as distribution maps on ForestPack. See the example code below.
The bitmap is successfully created and Display()ed properly (See attachment Bitmap_Display.png)
However, when I create a BitmapTex and use SetBitmap to set the previously created bitmap, the texture appears blank (black), both in the material editor and when applying it (as a distribution map for ForestPack), see attachment BitmapTex_Material_Library.png.
Any clues? The only remotely related post I found was this one, and it says that SetBitmap is "no use".
The only relevant documentation example just creates a bitmap, but it does nothing with BitmapTex. However, ForestPack expects a Texmap or subclass as input for its density map.
Edit: is it at all expected that setting a bitmap from memory works? Is it required to reside in a file? It is not an absolute requirement for me to use a bitmap in memory, but it is preferable.
BMM_GRAY_8 = 3 # 8-bit grayscale bitmap. BMM_FLOAT_GRAY_32 = 18 # 32-bit floating-point (non-compressed), monochrome/grayscale BMM_OPEN_W = 2 width = 256 height = 256 data = [[random.random() for i in range(width)] for j in range(height)] bm_name = "python_noise" storage = MaxPlus.Factory.CreateStorage(BMM_GRAY_8) info = storage.GetBitmapInfo() info.SetWidth(width) info.SetHeight(height) info.SetName(bm_name) info.SetGamma(2.2) info.SetBitmapType(BMM_GRAY_8) storage.Allocate(info, BMM_OPEN_W) # now set the data on the bitmap storage for x in range(width): for y in range(height): storage.Put16GrayFloat(x, y, data[x][y]) bm = MaxPlus.Factory.CreateBitmap(info) bm.SetStorage(storage) bm.Display(bm_name) # this works bt = MaxPlus.Factory.CreateDefaultBitmapTex() bt.SetMapName(bm_name, True) # wtf, isUIAction has to be true for Display to work... bt.SetBitmap(bm) # add it to material library MaxPlus.MaterialLibrary.GetCurrentLibrary().Add(bt) # now the bitmap texture is blank