How to pass a MaxScript bitmap to C++ using function-publishing

How to pass a MaxScript bitmap to C++ using function-publishing

Anonymous
Not applicable
865 Views
7 Replies
Message 1 of 8

How to pass a MaxScript bitmap to C++ using function-publishing

Anonymous
Not applicable

Greetings,

 

I have a question regarding how to pass a MaxScript bitmap to C++ using function-publishing?

 

I use the following definition for my function-published interface

 

void SetImage(PBBitmap &bmap);
PBBitmap& GetImage();

PROP_FNS(IFP_OpenVINO::em_getBmap, GetImage, IFP_OpenVINO::em_setBmap, SetImage, TYPE_BITMAP_BV)

And on the MaxScript side I use

 

myBitmap = openBitmap <some-path to an image>

fp.Image = myBitmap

showproperties myBitmap

 

My expectation is that on the C++ side my GetImage has received by-value a MXS Bitmap object that I can work with.  This is not working as I am getting trash.  Might anyone be so kind as to pointing me to working samples or how-tos that demonstrate proper usage of function-publishing and bitmaps?

 

 

0 Likes
866 Views
7 Replies
Replies (7)
Message 2 of 8

istan
Advisor
Advisor

not sure, but have you also tried "by reference" instead of "by value"?

0 Likes
Message 3 of 8

Anonymous
Not applicable

Greetings Istan -

 

I have approached the problem both ways - taking the Bitmap objects from Maxscript to C++ both by-value and by-reference.  In both cases I get clean builds - so no insight from the compiler - and Maxscript seems perfectly happy in passing the Bitmap object to the C++ layer.  However, when I set a breakpoint in my C++ getter I am still getting trash.

 

I have reviewed the HowTo.sln and specifically the FunctionPublishing project for guidance and that is where I am coming from.  What I really would like is a bit of code-sample - either from the samples or from elsewhere - that demonstrate either thru FnPub or through traditional paramblock2 how to pass a Bitmap from MXS to C++ layer.

 

Let me know if you have additional questions ... RudyC

0 Likes
Message 4 of 8

klvnk
Collaborator
Collaborator

MXS will pass it as a MAXBitMap value not a Bitmap so you could try it as a TYPE_VALUE not TYPE_BITMAP

 

then do something like...

void SetImage(Value* val)
{
if(val->tag == class_tag(MAXBitMap)) //maxscript.h/value.h { MAXBitMap* maxbitmap = (MAXBitMap*)val; Bitmap* bm = maxbitmap->bm; if(bm)......

 

0 Likes
Message 5 of 8

klvnk
Collaborator
Collaborator

you could also try is like this

 

void SetImage(Bitmap *bmap);
Bitmap* GetImage();

PROP_FNS(IFP_OpenVINO::em_getBmap, GetImage, IFP_OpenVINO::em_setBmap, SetImage, TYPE_BITMAP)
0 Likes
Message 6 of 8

klvnk
Collaborator
Collaborator

the value version works as expected

the other method partially...

though it should be

void SetImage(PBBitmap *bmap);
PBBitmap * GetImage();

PROP_FNS(IFP_OpenVINO::em_getBmap, GetImage, IFP_OpenVINO::em_setBmap, SetImage, TYPE_BITMAP)

unfortunately only the bitmapinfo ptr of the PBBitmap is valid the Bitmap is a null pointer and you can only pass "saved"/loaded bitmaps which is odd though it could be bug in the version i use

 

 

0 Likes
Message 7 of 8

Anonymous
Not applicable

Thanks klvnk - 

 

I tried your approach and can see the situation in Max 2019 ... the PBBitmap has data and the ptr to Bitmap is null.  It indeed might be a bug.

 

RudyC

0 Likes
Message 8 of 8

klvnk
Collaborator
Collaborator

the value version works ok though, you could get it to throw typical max script errors so from the mxs side theres no difference.

0 Likes