def setSkeleton(self, skel): prev_skel = self.getSkeleton() self.callEvent('onChanging', events3d.HumanEvent(self, 'skeleton')) animation.AnimatedMesh.setSkeleton(self, skel) self.updateVertexWeights(skel.getVertexWeights() if skel else None) self.callEvent('onChanged', events3d.HumanEvent(self, 'skeleton')) self.refreshPose()
def resetMeshValues(self): self.setDefaultValues() self.targetsDetailStack = {} self.setMaterial(self._defaultMaterial) self.callEvent('onChanging', events3d.HumanEvent(self, 'reset')) self.callEvent('onChanged', events3d.HumanEvent(self, 'reset'))
def resetMeshValues(self): self.setDefaultValues() self.targetsDetailStack = {} self.setTexture("data/textures/texture.png") self.callEvent('onChanging', events3d.HumanEvent(self, 'reset')) self.callEvent('onChanged', events3d.HumanEvent(self, 'reset'))
def resetMeshValues(self): self.setSubdivided(False, update=False) self.setDefaultValues() self.resetBoundMeshes() self._resetProxies() # TODO does not properly take care of calling removeObject self.resetToRestPose(update=False) self.targetsDetailStack = {} self.setMaterial(self._defaultMaterial) self.callEvent('onChanging', events3d.HumanEvent(self, 'reset')) self.callEvent('onChanged', events3d.HumanEvent(self, 'reset'))
def removeClothesProxy(self, uuid): self._swapProxies(self._clothesProxies.get(uuid, None), None) event = events3d.HumanEvent(self, 'proxyChange') if uuid in self._clothesProxies: del self._clothesProxies[uuid] event.proxy = 'clothes' self.callEvent('onChanged', event)
def _onChange(self): import humanmodifier if self.slider.isSliderDown(): # Don't do anything when slider is being clicked or dragged (onRelease triggers it) return value = self.getValue() human = self.modifier.human if self.value is None: self.value = self.modifier.getValue() if self.value != value: G.app.do(humanmodifier.ModifierAction(self.modifier, self.value, value, self.update)) else: # Indicate that onChanging event is ended with onChanged event (type == 'modifier', not 'targets') import events3d event = events3d.HumanEvent(human, self.modifier.eventType) event.modifier = self.modifier.fullName human.callEvent('onChanged', event) if human.isSubdivided(): if human.isProxied(): human.getProxyMesh().setVisibility(0) else: human.getSeedMesh().setVisibility(0) human.getSubdivisionMesh(False).setVisibility(1) self.value = None
def load(self, filename, update=True, progressCallback=None): self.resetMeshValues() f = open(filename, 'r') for data in f.readlines(): lineData = data.split() if len(lineData) > 0 and not lineData[0] == '#': if lineData[0] == 'version': log.message('Version %s', lineData[1]) elif lineData[0] == 'tags': for tag in lineData: log.message('Tag %s', tag) elif lineData[0] in gui3d.app.loadHandlers: gui3d.app.loadHandlers[lineData[0]](self, lineData) else: log.message('Could not load %s', lineData) f.close() self.syncRace() self.callEvent('onChanged', events3d.HumanEvent(self, 'load')) if update: self.applyAllTargets(progressCallback)
def setBreastSize(self, size): size = min(max(size, 0.0), 1.0) if self.breastSize == size: return self.breastSize = size self._setBreastSizeVals() self.callEvent('onChanging', events3d.HumanEvent(self, 'breastSize'))
def setBreastFirmness(self, firmness): firmness = min(max(firmness, 0.0), 1.0) if self.breastFirmness == firmness: return self.breastFirmness = firmness self._setBreastFirmnessVals() self.callEvent('onChanging', events3d.HumanEvent(self, 'breastFirmness'))
def setHeight(self, height): height = min(max(height, 0.0), 1.0) if self.height == height: return self.height = height self._setHeightVals() self.callEvent('onChanging', events3d.HumanEvent(self, 'height'))
def setSubdivided(self, *args, **kwargs): if not guicommon.Object.setSubdivided(self, *args, **kwargs): return for obj in self.getProxyObjects(): if obj: obj.setSubdivided(*args, **kwargs) self.callEvent('onChanged', events3d.HumanEvent(self, 'smooth'))
def addClothesProxy(self, proxy): uuid = proxy.getUuid() self._swapProxies(self._clothesProxies.get(uuid, None), proxy) self._clothesProxies[uuid] = proxy event = events3d.HumanEvent(self, 'proxyChange') event.proxy = 'clothes' self.callEvent('onChanged', event)
def updateValue(self, value, updateNormals=1, skipUpdate=False): if self.verts is None and self.faces is None: self.buildLists() # Update detail state old_detail = [ self.human.getDetail(target[0]) for target in self.targets ] self.setValue(value, skipDependencies=True) new_detail = [ self.human.getDetail(target[0]) for target in self.targets ] # Apply changes for target, old, new in zip(self.targets, old_detail, new_detail): if new == old: continue algos3d.loadTranslationTarget(self.human.meshData, target[0], new - old, None, 0, 0) if skipUpdate: # Used for dependency updates (avoid dependency loops and double updates to human) return # Update dependent modifiers self.propagateUpdate(realtime=True) # Update vertices if updateNormals: self.human.meshData.calcNormals(1, 1, self.verts, self.faces) self.human.meshData.update() event = events3d.HumanEvent(self.human, self.eventType) event.modifier = self.fullName self.human.callEvent('onChanging', event)
def refreshPose(self, updateIfInRest=False): event = events3d.HumanEvent(self, 'poseRefresh') self.callEvent('onChanging', event) super(Human, self).refreshPose(updateIfInRest) if self.isSubdivided(): self.updateSubdivisionMesh() self.mesh.calcNormals() self.mesh.update() self.callEvent('onChanged', event)
def applyAllTargets(self, progressCallback=None, update=True): """ This method applies all targets, in function of age and sex **Parameters:** None. progressCallback will automatically be set to G.app.progress if the progressCallback parameter is left to None. Set it to False to disable progress reporting. """ if progressCallback is None: progressCallback = G.app.progress if progressCallback: progressCallback(0.0) # First call progressCalback (which often processes events) before resetting mesh # so that mesh is not drawn in its reset state algos3d.resetObj(self.meshData) progressVal = 0.0 progressIncr = 0.5 / (len(self.targetsDetailStack) + 1) for (targetPath, morphFactor) in self.targetsDetailStack.iteritems(): algos3d.loadTranslationTarget(self.meshData, targetPath, morphFactor, None, 0, 0) progressVal += progressIncr if progressCallback: progressCallback(progressVal) # Update all verts self.getSeedMesh().update() self.updateProxyMesh() if self.isSubdivided(): self.updateSubdivisionMesh() if progressCallback: progressCallback(0.7) self.mesh.calcNormals() if progressCallback: progressCallback(0.8) if update: self.mesh.update() else: self.meshData.calcNormals(1, 1) if progressCallback: progressCallback(0.8) if update: self.meshData.update() if progressCallback: progressCallback(1.0) #self.traceStack(all=True) #self.traceBuffer(all=True, vertsToList=0) self.callEvent('onChanged', events3d.HumanEvent(self, 'targets'))
def load(self, filename, update=True): from codecs import open log.message("Loading human from MHM file %s.", filename) progress = Progress()(0.0, 0.8) event = events3d.HumanEvent(self, 'load') event.path = filename self.callEvent('onChanging', event) self.resetMeshValues() self.blockEthnicUpdates = True subdivide = False f = open(filename, 'rU', encoding="utf-8") for lh in G.app.loadHandlers.values(): lh(self, ['status', 'started']) lines = f.readlines() fprog = Progress(len(lines)) for data in lines: lineData = data.split() if len(lineData) > 0 and not lineData[0] == '#': if lineData[0] == 'version': log.message('Version %s', lineData[1]) elif lineData[0] == 'tags': for tag in lineData[1:]: log.debug('Tag %s', tag) elif lineData[0] == 'subdivide': subdivide = lineData[1].lower() in ['true', 'yes'] elif lineData[0] in G.app.loadHandlers: G.app.loadHandlers[lineData[0]](self, lineData) else: log.debug('Could not load %s', lineData) fprog.step() log.debug("Finalizing MHM loading.") for lh in set(G.app.loadHandlers.values()): lh(self, ['status', 'finished']) f.close() self.blockEthnicUpdates = False self._setEthnicVals() self.callEvent('onChanged', event) if update: progress(0.8, 0.9) self.applyAllTargets() progress(0.9, 0.99) self.setSubdivided(subdivide) progress(1.0) log.message("Done loading MHM file.")
def setHeight(self, height, updateModifier=True): if updateModifier: modifier = self.getModifier('macrodetails-height/Height') modifier.setValue(height) self.applyAllTargets() return height = min(max(height, 0.0), 1.0) if self.height == height: return self.height = height self._setHeightVals() self.callEvent('onChanging', events3d.HumanEvent(self, 'height'))
def setBreastSize(self, size, updateModifier=True): if updateModifier: modifier = self.getModifier('breast/BreastSize') modifier.setValue(size) self.applyAllTargets() return size = min(max(size, 0.0), 1.0) if self.breastSize == size: return self.breastSize = size self._setBreastSizeVals() self.callEvent('onChanging', events3d.HumanEvent(self, 'breastSize'))
def setBodyProportions(self, proportion, updateModifier = True): if updateModifier: modifier = self.getModifier('macrodetails-proportions/BodyProportions') modifier.setValue(proportion) self.applyAllTargets() return proportion = min(1.0, max(0.0, proportion)) if self.bodyProportions == proportion: return self.bodyProportions = proportion self._setBodyProportionVals() self.callEvent('onChanging', events3d.HumanEvent(self, 'bodyProportions'))
def setBreastFirmness(self, firmness, updateModifier = True): if updateModifier: modifier = self.getModifier('breast/BreastFirmness') modifier.setValue(firmness) self.applyAllTargets() return firmness = min(max(firmness, 0.0), 1.0) if self.breastFirmness == firmness: return self.breastFirmness = firmness self._setBreastFirmnessVals() self.callEvent('onChanging', events3d.HumanEvent(self, 'breastFirmness'))
def resetMeshValues(self): self.childVal = 0.0 self.youngVal = 1.0 self.oldVal = 0.0 self.femaleVal = 0.5 self.maleVal = 0.5 self.flaccidVal = 0.0 self.muscleVal = 0.0 self.overweightVal = 0.0 self.underweightVal = 0.0 self.caucasianVal = 1.0/3 self.asianVal = 1.0/3 self.africanVal = 1.0/3 self.dwarfVal = 0.0 self.giantVal = 0.0 self.breastSize = 0.0 self.breastFirmness = 0.5 self.targetsDetailStack = {} self.setTexture("data/textures/texture.png") self.callEvent('onChanging', events3d.HumanEvent(self, 'reset')) self.callEvent('onChanged', events3d.HumanEvent(self, 'reset'))
def setAsian(self, asian, sync=True): asian = min(max(asian, 0.0), 1.0) old = 1 - self.asianVal self.asianVal = asian if not sync: return new = 1 - self.asianVal if old < 1e-6: self.caucasianVal = new / 2 self.africanVal = new / 2 else: self.caucasianVal *= new / old self.africanVal *= new / old self.callEvent('onChanging', events3d.HumanEvent(self, 'asian'))
def setAsian(self, asian, sync=True, updateModifier = True): if updateModifier: modifier = self.getModifier('macrodetails/Asian') modifier.setValue(asian) self.applyAllTargets() return asian = min(max(asian, 0.0), 1.0) self.asianVal = asian if sync and not self.blockEthnicUpdates: self._setEthnicVals('asian') self.callEvent('onChanging', events3d.HumanEvent(self, 'asian'))
def setSubdivided(self, flag, *args, **kwargs): if flag != self.isSubdivided(): proxies = [obj for obj in self.getProxyObjects() if obj] progress = Progress([len(self.mesh.coord)] + [len(obj.mesh.coord) for obj in proxies]) guicommon.Object.setSubdivided(self, flag, *args, **kwargs) progress.step() for obj in proxies: obj.setSubdivided(flag, *args, **kwargs) progress.step() self.callEvent('onChanged', events3d.HumanEvent(self, 'smooth'))
def load(self, filename, update=True, progressCallback=None): from codecs import open log.message("Loading human from MHM file %s.", filename) event = events3d.HumanEvent(self, 'load') event.path = filename self.callEvent('onChanging', event) self.resetMeshValues() self.blockEthnicUpdates = True subdivide = False # TODO perhaps create progress indicator that depends on line count of mhm file? f = open(filename, 'rU', encoding="utf-8") for lh in G.app.loadHandlers.values(): lh(self, ['status', 'started']) for data in f.readlines(): lineData = data.split() if len(lineData) > 0 and not lineData[0] == '#': if lineData[0] == 'version': log.message('Version %s', lineData[1]) elif lineData[0] == 'tags': for tag in lineData[1:]: log.debug('Tag %s', tag) elif lineData[0] == 'subdivide': subdivide = lineData[1].lower() in ['true', 'yes'] elif lineData[0] in G.app.loadHandlers: G.app.loadHandlers[lineData[0]](self, lineData) else: log.debug('Could not load %s', lineData) log.debug("Finalizing MHM loading.") for lh in set(G.app.loadHandlers.values()): lh(self, ['status', 'finished']) f.close() self.blockEthnicUpdates = False self._setEthnicVals() self.callEvent('onChanged', event) if update: self.applyAllTargets(progressCallback) self.setSubdivided(subdivide) log.message("Done loading MHM file.")
def setGender(self, gender): """ Sets the gender of the model. 0 is female, 1 is male. Parameters ---------- amount: *float*. An amount, usually between 0 and 1, specifying how much of the attribute to apply. """ gender = min(max(gender, 0.0), 1.0) self._setGenderVals(gender) self.callEvent('onChanging', events3d.HumanEvent(self, 'gender'))
def setMuscle(self, muscle): """ Sets the amount of muscle of the model. 0 for flacid, 1 for muscular. Parameters ---------- amount: *float*. An amount, usually between 0 and 1, specifying how much of the attribute to apply. """ muscle = min(max(muscle, 0.0), 1.0) self._setMuscleVals(-1 + 2 * muscle) self.callEvent('onChanging', events3d.HumanEvent(self, 'muscle'))
def setWeight(self, weight): """ Sets the amount of weight of the model. 0 for underweight, 1 for overweight. Parameters ---------- amount: *float*. An amount, usually between 0 and 1, specifying how much of the attribute to apply. """ weight = min(max(weight, 0.0), 1.0) self._setWeightVals(-1 + 2 * weight) self.callEvent('onChanging', events3d.HumanEvent(self, 'weight'))
def loadFinish(self): self.selectedHuman.applyAllTargets(gui3d.app.progress) self.selectedHuman.callEvent('onChanged', events3d.HumanEvent(self.selectedHuman, 'reset')) self.prompt('Warning', 'This is an alpha release, which means that there are still bugs present and features missing. Use at your own risk.', 'OK', helpId='alphaWarning') # self.splash.hide() gui3d.app.setFilenameCaption("Untitled") self.setFileModified(False) #printtree(self) mh.updatePickingBuffer(); self.redraw()
def setProxy(self, proxy): oldPxy = self.getProxy() oldPxyMesh = self.getProxyMesh() # Fit to basemesh in rest pose, then pose proxy super(Human, self).setProxy(proxy) if oldPxyMesh: self.removeBoundMesh(oldPxyMesh.name) if self.proxy: # Add new mesh and vertex weight assignments self._updateMeshVertexWeights(self.getProxyMesh()) self.refreshPose() event = events3d.HumanEvent(self, 'proxyChange') event.proxy = 'human' self.callEvent('onChanged', event)