Page 1 of 1

Change Clothes via Script

PostPosted: Thu Mar 23, 2017 10:03 am
by DarkAeon54
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.

Re: Change Clothes via Script

PostPosted: Wed Jun 07, 2017 8:41 am
by markchang
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)

Re: Change Clothes via Script

PostPosted: Wed Aug 09, 2017 9:20 am
by mlang
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.