#353282
The following issue was tested in max2012, maxwell 2.6.1, win7 64

I'm creating a script to convert vray scenes to maxwell. The issue is that if you assign a texture trough maxscript apparently it has worked fine but once you save the max file and try to re-open it the file is damaged.

It turns out that I can create the maxwell bitmap and it will not damage the file but if I assign a filename then it does damage the file.

You can try it with the following code.

Create an object assign a vray material with a texture in the diffuse slot, select it and run the following code.
You will see that it gets converted correctly but after saving the file you will not be able to open it again.
Now try it again but remove the line (theBitmap.FileName = mtl.texmap_diffuse.filename) and the file will open just fine.

-- Maxscript --

mtl = $.material

newmtl = Maxwell_Material ()
newmtl.Layers[2] = MaxwellLayer()
newmtl.Layers[2].name = newmtl.name + "_base"

theBitmap = maxwellbitmap()
theBitmap.FileName = mtl.texmap_diffuse.filename

newmtl.Layers[2].Bsdfs[1] = MaxwellBsdf()
newmtl.Layers[2].Bsdfs[1].ReflectedColorTexture = theBitmap

$.material = newmtl

Is this a known issue? Is there any work around?

Thanks
Guillermo Leal.
#353291
What happens is simply retarded. Somehow having a = b, while b points to "some_string" is different than doing directly a = "some_string". In your case if you take the value of mtl.texmap_diffuse.filename and directly assign it to theBitmap.FileName it will work, and no crash. Amazing.
#353302
It still crashes,

In the above code i'm assigning the string directly . theBitmap.FileName = mtl.texmap_diffuse.filename

The only way to make it work is like this
theBitmap.FileName = "carpet.jpg"

I have tried this options all of them crash.

theBitmap = maxwellbitmap()
str = mtl.texmap_diffuse.filename
theBitmap.FileName = str
newmtl.Layers[2].Bsdfs[1] = MaxwellBsdf()
newmtl.Layers[2].Bsdfs[1].ReflectedColorTexture = theBitmap
----------

newmtl.Layers[2].Bsdfs[1] = MaxwellBsdf()
newmtl.Layers[2].Bsdfs[1].ReflectedColorTexture = maxwellbitmap filename:mtl.texmap_diffuse.filename

------------
theBitmap = maxwellbitmap()
newmtl.Layers[2].Bsdfs[1] = MaxwellBsdf()
newmtl.Layers[2].Bsdfs[1].ReflectedColorTexture = theBitmap
newmtl.Layers[2].Bsdfs[1].ReflectedColorTexture.FileName = mtl.texmap_diffuse.filename

Any other suggestion?
#353303
Sorry for the confusion, I wasn't giving a suggestion in my last post. I was just expressing my disappointment regarding Maxscript, since something like this:

theBitmap.FileName = "carpet.jpg" // works fine

is different than something like this (even tho all 3 are string variables):

mtl.texmap_diffuse.filename = "carpet.jpg"
theBitmap.FileName = mtl.texmap_diffuse.filename
// crashes

Only Maxscript can achieve this level of retardation. Anyway, I'll keep you posted if we find a workaround.
#353305
I found a strange workaround, its seems maxwell likes lowercase strings, if i convert the script it works fine.

This works.

newmtl = Maxwell_Material ()
newmtl.Layers[2] = MaxwellLayer()

theBitmap = Maxwell_Bitmap()
theBitmap.FileName = toLower mtl.texmap_diffuse.filename

newmtl.Layers[2].Bsdfs[1] = MaxwellBsdf()
newmtl.Layers[2].Bsdfs[1].ReflectedColorTexture = theBitmap

Thanks Bogdan,
#353335
That sounds like a reference counting problem on the string object. I guess that when you do theBitmap.FileName = mtl.texmap_diffuse.filename, both objects end up thinking they own the string and both try to free it. When you assign a string constant or when you do a toLower, a new string object is created and the double free doesn't happen anymore (or is postponed until it doesn't matter anymore). We'll check to see if it's something we've done wrong in the MxBitmap node, though I doubt it.
Help with swimming pool water

Hi Andreas " I would say the above "fake[…]

render engines and Maxwell

Other rendering engines are evolving day by day, m[…]