Everything related to SDK.
User avatar
By wahn
#377400
Hi,

I'm having difficulties to replicate what's happening in the Maxwell Material Editor [Mxed] (Maxwell version 3) from within the Python API. I can store a MXS scene containing for example a simple 'Transparent' material (Global Properties -> Type = Transparent in the Mxed) and load the material extension from there like this:
Code: Select all
# scene
scene = pymaxwell.Cmaxwell(pymaxwell.mwcallback)
ok = scene.readMXS('Transparent.mxs')
if ok:
    mit = pymaxwell.CmaxwellMaterialIterator()
    mat = mit.first(scene)
    paramList, ok = mat.getMaterialModifierExtensionParams()
    param = paramList.getByIndex(3)
    paramList.setDouble('Ior', 1.4)
But what I really would like to do is to use mat.setMaterialModifierExtensionParams() and somehow make the Python interpreter aware of the material extension. I found files like this:

/Applications/Maxwell 3/extensions/Transparent.xui
/Applications/Maxwell 3/extensions/presets/Transparent.xpr

Can I load those files somehow and use it to create the paramList and change settings from there?
By JDHill
#377458
wahn wrote:Can I load those files somehow and use it to create the paramList and change settings from there?
There's no SDK function for handling these automatically -- you would need to parse them manually, use the values to set up an MXparamList, then give that to Cmaterial::applyMaterialModifierExtension.
User avatar
By wahn
#377473
I ended up using layers and brdfs like in this example:
Code: Select all
# scene
scene = pymaxwell.Cmaxwell(pymaxwell.mwcallback)
# blue_plastic
blue_plastic = scene.createMaterial('blue_plastic', True)
layer = blue_plastic.addLayer()
layer.setEnabled(True)
attr = pymaxwell.Cattribute()
attr.type = pymaxwell.MAP_TYPE_VALUE
attr.value = 89.99999985098839
layer.setWeight(attr)
bsdf = layer.addBSDF()
reflectance = bsdf.getReflectance()
reflectance.setActiveIorMode(0)
color = pymaxwell.Crgb()
color.assign(0.10000000149011612, 0.10000000149011612, 0.6000000238418579)
attr.type = pymaxwell.MAP_TYPE_RGB
attr.rgb.assign(color)
reflectance.setAttribute('color', attr)
reflectance.setAttribute('color.tangential', attr)
color.assign(0.5, 0.5, 0.5)
attr.rgb.assign(color)
reflectance.setAttribute('scattering', attr)
attr.type = pymaxwell.MAP_TYPE_VALUE
attr.value = 100.0
bsdf.setAttribute('roughness', attr)
bsdf.setState(True)
layer2 = blue_plastic.addLayer()
layer2.setEnabled(True)
bsdf2 = layer2.addBSDF()
reflectance2 = bsdf2.getReflectance()
reflectance2.setActiveIorMode(0)
color = pymaxwell.Crgb()
color.assign(1.0, 1.0, 1.0)
attr = pymaxwell.Cattribute()
attr.type = pymaxwell.MAP_TYPE_RGB
attr.rgb.assign(color)
reflectance2.setAttribute('color', attr)
reflectance2.setAttribute('color.tangential', attr)
color.assign(0.5, 0.5, 0.5)
attr.rgb.assign(color)
reflectance2.setAttribute('scattering', attr)
attr.type = pymaxwell.MAP_TYPE_VALUE
attr.value = 10.000000149011612
bsdf2.setAttribute('roughness', attr)
bsdf2.setState(True)
scene.writeMXS("untitled.mxs")
If I load the resulting MXS file into Studio I have to go through each material (in this case there is only one) and change something in the GUI (even if I simply put in the same value(s)), otherwise the material ends up rendering black. Am I missing some function I need to call?
By JDHill
#377481
The problem is that what was Cmap::type in V2 has become Cattribute::activeType in V3, such that with the code above, the activeType read from the resulting file ends up being MAP_TYPE_SPECTRUM_FILE (not sure why, but that's what happens), which explains why maxwell.exe reports "ERROR: - Spectral file not found ( ) in Material 'blue_plastic'," if you attempt to render using the material.
User avatar
By wahn
#377560
Hi JDHill,

Thanks for your answer ... that helped a lot. So I simply added for each attr.type line a corresponding attr.activeType line and that seems to fix the problem:
Code: Select all
...
attr.type = pymaxwell.MAP_TYPE_VALUE
attr.activeType = pymaxwell.MAP_TYPE_VALUE
...
attr.type = pymaxwell.MAP_TYPE_RGB
attr.activeType = pymaxwell.MAP_TYPE_RGB
...

...and 3 Days later, 82.528 Views !!! ...NL, every[…]

Hello dear customers, We have just released a new[…]

grass generator extension

Just downloaded MWR5 for Rhino 6 and want to use g[…]

Hello everyone, I have a new bug with the latest M[…]