Itoo Software Forum

Author Topic: Problem setting distmap by script  (Read 244 times)

monomon

  • Newbie
  • *
  • Posts: 3
Problem setting distmap by script
« on: January 23, 2018, 11:33:17 AM »
Hi, I am trying to set a ForestPack instance's distribution map with a python script in 3ds max and I am having problems with it.

First, I create a MaxPlus.Bitmap in which I load an existing file from disk. Then, a MaxPlus.BitmapTex and set my bitmap on it. Finally, I set this BitmapTex on the "distmap" property of Forestpack.

When the script completes, the forest appears empty (though the distmap button in the sidebar indicates my distmap).
If I now manually click to reselect the map from the material editor it works!  ???
I am not sure what changes when I do this, like some weird conversions or setting missing properties... or do I just need to trigger some kind of update?

Here's example code:
Code: [Select]
BMM_GRAY_8 = 3  # 8-bit grayscale bitmap.
# Bitmap open mode flags
BMM_NOT_OPEN = 0
BMM_OPEN_R = 1
BMM_OPEN_W = 2

node_name = "forest_flowers"
conf = {
    "width": 32,
    "height": 32,
    "name": "bla" + str(random.randint(1, 15000))
}


def create_bitmaptex(bm, conf):
    bt = MaxPlus.Factory.CreateDefaultBitmapTex()
    bt.SetBitmap(bm)
    bt.SetFilterType(0)
    # wtf, isUIAction has to be true for Display to work...
    bt.SetMapName(bm.GetStorage().GetBitmapInfo().GetName(), True)
    return bt


def load_bitmap(bmpath, conf):
    width = conf["width"]
    height = conf["height"]

    storage = MaxPlus.Factory.CreateStorage(BMM_GRAY_8)

    info = storage.GetBitmapInfo()
    info.SetWidth(width)
    info.SetHeight(height)
    info.SetName(conf["name"] )
    info.SetPath(bmpath)
    info.SetGamma(2.2)
    info.SetBitmapType(BMM_GRAY_8)

    storage.Allocate(info, BMM_OPEN_R)
    bm = MaxPlus.BitmapManager.Load(info)
    bm.SetStorage(storage)
    return bm


def add_to_current_library(mat):
    MaxPlus.MaterialLibrary.GetCurrentLibrary().Add(mat)


try:
    forest_pack = MaxPlus.INode.GetINodeByName(node_name)

    # use one of the forestpack distmaps for example
    bmpath = os.path.join(
        "C:/",
        "Program Files (x86)",
        "Itoo Software",
        "Forest Pack Pro",
        "distmaps",
        "images",
        "spread2.bmp"
    )

    print("bitmap path", bmpath)
    bm = load_bitmap(bmpath, conf)
    print("bitmap", bm)
    bm.Display()

    bt = create_bitmaptex(bm, conf)
    print("bitmaptex", bt)
    add_to_current_library(bt)

    forest_pack.Object.GetParameterBlock()\
                      .GetParamByName("distmap")\
                      .SetValue(bt)

    MaxPlus.ViewportManager.ForceCompleteRedraw()

    # The value of distmap is now of type MaxPlus.Texmap
    print("distmap value", forest_pack.Object.GetParameterBlock()\
          .GetParamByName("distmap")\
          .Value)

except Exception as e:
    traceback.print_exc()


As an aside, initially I wanted to make this work with procedurally generated bitmaps, but that failed worse - manual reselection did not fix it, (I am guessing) because the bitmap's in-memory storage doesn't persist.
« Last Edit: January 23, 2018, 11:45:18 AM by monomon »

iToo

  • Administrator
  • Hero Member
  • *****
  • Posts: 3148
    • iToo Software
Re: Problem setting distmap by script
« Reply #1 on: January 24, 2018, 01:14:42 PM »
I'm sorry, but Lite support is limited, as described here:

https://forum.itoosoft.com/forest-lite/forest-pack-lite-support-policy/

Thanks for your understanding.
Carlos Quintero
iToo Software