Change Clothes via Script

MakeHuman python API, python plugins, etc

Moderator: joepal

Change Clothes via Script

Postby DarkAeon54 » Thu Mar 23, 2017 10:03 am

Does anyone know the python to change the clothes (Geometries>Clothes>Clothes)? I want to randomize and export humans with clothes so I need a script that can change this property.
DarkAeon54
 
Posts: 1
Joined: Thu Mar 23, 2017 10:00 am

Re: Change Clothes via Script

Postby markchang » Wed Jun 07, 2017 8:41 am

import proxy
import numpy as np
import events3d
human = G.app.selectedHuman
mhclofile = u'data/clothes/male_casualsuit01/male_casualsuit01.mhpxy'
pxy = proxy.loadProxy(human, mhclofile, type='Clothes')
mesh,obj = pxy.loadMeshAndObject(human)
mesh.setPickable(True)
gui3d.app.addObject(obj)
mesh2 = obj.getSeedMesh()
fit_to_posed = False
pxy.update(mesh2, fit_to_posed)
mesh2.update()
obj.setSubdivided(human.isSubdivided())
human.addClothesProxy(pxy)
vertsMask = np.ones(human.meshData.getVertexCount(), dtype=bool)
proxyVertMask = proxy.transferVertexMaskToProxy(vertsMask, pxy)
# Apply accumulated mask from previous clothes layers on this clothing piece
obj.changeVertexMask(proxyVertMask)
if pxy.deleteVerts is not None and len(pxy.deleteVerts > 0):
log.debug("Loaded %s deleted verts (%s faces) from %s proxy.", np.count_nonzero(pxy.deleteVerts), len(human.meshData.getFacesForVertices(np.argwhere(pxy.deleteVerts)[...,0])),pxy.name)
# Modify accumulated (basemesh) verts mask
verts = np.argwhere(pxy.deleteVerts)[...,0]
vertsMask[verts] = False
human.changeVertexMask(vertsMask)
event = events3d.HumanEvent(human, 'proxy')
event.pxy = 'clothes'
human.callEvent('onChanged', event)
markchang
 
Posts: 1
Joined: Wed Jun 07, 2017 8:40 am

Re: Change Clothes via Script

Postby mlang » Wed Aug 09, 2017 9:20 am

this works great, unfortunately removing the added clothes doesn't.

Code: Select all
human.removeClothesProxy(pxy.uuid)
removes the proxy from the
Code: Select all
clothesProxies
property, the clothes don't get removed from the human though.
mlang
 
Posts: 4
Joined: Tue May 23, 2017 2:51 pm


Return to Python scripts

Who is online

Users browsing this forum: No registered users and 1 guest