- Fri May 01, 2020 8:36 pm
#399670
Hello, i remember that the script worked fine years ago when i made it for maxwell v3 but i don't know why it didn't work now,
the new material added to the new scene but for grass nothing change.
What i miss here?
the new material added to the new scene but for grass nothing change.
What i miss here?
Code: Select all
def MXMchangeMaterialFromMXM(self):
oldMatName = str(self.chosen_material.text())
newMatFolder = str(self.input_load_mxm.text())
matName = str(self.input_mxm.currentText())
newMatPath = str(newMatFolder + '/' + str(matName))
mxsList = [self.input_mxs_scene.text()]
outPath = self.output_save_scene.text()
scene = Cmaxwell(mwcallback)
if not len(self.input_mxs_scene.text()) == 0:
if len(outPath) > 0:
if not len(oldMatName) == 0:
if self.input_mxm.count() > 0:
for mxs in mxsList:
scene.readMXS(str(mxs))
newMatName, descr, im, ok = CmaxwellMaterial.getMxmInfo(newMatPath)
newMat = scene.createMaterial(newMatName)
newMat.read(newMatPath)
it = CmaxwellObjectIterator()
obj = it.first(scene)
while not obj.isNull():
objMat1 = obj.getMaterial()[0]
objMat2 = obj.getBackfaceMaterial()[0]
if not objMat1.isNull():
if objMat1.getName() == oldMatName:
obj.setMaterial(newMat)
if not objMat2.isNull():
if objMat2.getName() == oldMatName:
obj.setBackfaceMaterial(newMat)
ismesh, ok = obj.isMesh()
if ismesh:
itGroup = CmaxwellObjectTrianglesGroupIterator()
group = itGroup.first(obj)
while not group.isNull():
triangles = group.getTriangles()
groupMat = obj.getTriangleMaterial(triangles[0])[0]
if groupMat.getName() == oldMatName:
group.setMaterial(newMat)
group = itGroup.next()
if obj.isGeometryProcedural()[0]: # hair
proceduralParams, ok = obj.getGeometryProceduralExtensionParams()
name, ok = proceduralParams.getString('EXTENSION_NAME')
if objMat1.getName() == oldMatName:
if name == 'MaxwellHair':
obj.setMaterial(newMat)
nModifiers, ok = obj.getGeometryModifierExtensionsNumber() # grass
for i in range(nModifiers):
modifierParams, ok = obj.getGeometryModifierExtensionParamsAtIndex(i)
name, ok = modifierParams.getString('EXTENSION_NAME')
if name == 'MaxwellGrass':
for j in range(modifierParams.getNumItems()):
param = modifierParams.getByIndex(j)
par1 = modifierParams.getString('Material')
par2 = modifierParams.getString('Double Sided Material')
if par1[0] == oldMatName:
if param[0] == 'Material':
modifierParams.setString('Material', newMat.getName())
elif par2[0] == oldMatName:
if param[0] == 'Double Sided Material':
modifierParams.setString('Double Sided Material',newMat.getName())
obj = it.next()
scene.writeMXS(str(outPath))