def addRig(human, rigfile): if not os.path.isfile(rigfile): rigfile = getpath.findFile( rigfile, searchPaths=[getpath.getSysDataPath(), getpath.getSysPath()]) if not os.path.isfile(rigfile): #log.error("Rig file %s does not exist.", mhclofile) #return raise RuntimeError('Rig file "%s" does not exist.' % rigfile) import skeleton if not human.getBaseSkeleton(): # TODO when starting in GUI mode, base skeleton will be loaded twice base_skel = skeleton.load( getpath.getSysDataPath('rigs/default.mhskel'), human.meshData) human.setBaseSkeleton(base_skel) referenceRig = human.getBaseSkeleton() # TODO update skeleton library when in gui mode skel = skeleton.load(rigfile, human.meshData) skel.autoBuildWeightReferences(referenceRig) vertexWeights = skel.getVertexWeights(referenceRig.getVertexWeights()) skel.addReferencePlanes( referenceRig ) # Not strictly needed for the new way in which we determine bone normals human.setSkeleton(skel)
def addRig(human, rigfile): if not os.path.isfile(rigfile): rigfile = getpath.findFile(rigfile, searchPaths = [getpath.getSysDataPath(), getpath.getSysPath()]) if not os.path.isfile(rigfile): #log.error("Rig file %s does not exist.", mhclofile) #return raise RuntimeError('Rig file "%s" does not exist.' % rigfile) import skeleton if not human.getBaseSkeleton(): # TODO when starting in GUI mode, base skeleton will be loaded twice base_skel = skeleton.load(getpath.getSysDataPath('rigs/default.mhskel'), human.meshData) human.setBaseSkeleton(base_skel) referenceRig = human.getBaseSkeleton() # TODO update skeleton library when in gui mode skel = skeleton.load(rigfile, human.meshData) skel.autoBuildWeightReferences(referenceRig) vertexWeights = skel.getVertexWeights(referenceRig.getVertexWeights()) skel.addReferencePlanes(referenceRig) # Not strictly needed for the new way in which we determine bone normals human.setSkeleton(skel)
def chooseSkeleton(self, filename): log.debug("Loading skeleton from %s", filename) self.selectedRig = filename if self.referenceRig is None: log.message("Loading reference skeleton for weights remapping.") self.referenceRig = skeleton.load(REF_RIG_PATH, self.human.meshData) if not filename: if self.human.getSkeleton(): # Unload current skeleton self.human.setSkeleton(None) if self.skelObj: # Remove old skeleton mesh self.removeObject(self.skelObj) self.human.removeBoundMesh(self.skelObj.name) self.skelObj = None self.skelMesh = None self.boneCountLbl.setTextFormat(["Bones",": %s"], "") self.descrLbl.setText("") self.filechooser.selectItem(None) return if getpath.isSamePath(filename, REF_RIG_PATH): skel = self.referenceRig.clone() vertexWeights = self.referenceRig.getVertexWeights() else: # Load skeleton definition from options skel = skeleton.load(filename, self.human.meshData) # Ensure vertex weights of skel are initialized skel.autoBuildWeightReferences(self.referenceRig) # correct weights references if only (pose) references were defined vertexWeights = skel.getVertexWeights(self.referenceRig.getVertexWeights()) log.message("Skeleton %s has %s weights per vertex.", skel.name, vertexWeights.getMaxNumberVertexWeights()) # Remap bone orientation planes from reference rig skel.addReferencePlanes(self.referenceRig) # Update description descr = skel.description self.descrLbl.setText(descr) self.boneCountLbl.setTextFormat(["Bones",": %s"], skel.getBoneCount()) # (Re-)draw the skeleton (before setting skeleton on human so it is automatically re-posed) self.drawSkeleton(skel) # Assign to human self.human.setSkeleton(skel) self.filechooser.selectItem(filename)
def chooseSkeleton(self, filename): log.debug("Loading skeleton from %s", filename) self.selectedRig = filename if self.referenceRig is None: log.message("Loading reference skeleton for weights remapping.") self.referenceRig = skeleton.load(getpath.getSysDataPath('rigs/default.json'), self.human.meshData) if not filename: if self.human.getSkeleton(): # Unload current skeleton self.human.setSkeleton(None) if self.skelObj: # Remove old skeleton mesh self.removeObject(self.skelObj) self.human.removeBoundMesh(self.skelObj.name) self.skelObj = None self.skelMesh = None self.boneCountLbl.setTextFormat(["Bones",": %s"], "") self.descrLbl.setText("") self.filechooser.selectItem(None) return # Load skeleton definition from options skel = skeleton.load(filename, self.human.meshData) # Ensure vertex weights of skel are initialized skel.autoBuildWeightReferences(self.referenceRig) # correct weights references if only (pose) references were defined vertexWeights = skel.getVertexWeights(self.referenceRig.getVertexWeights()) log.message("Skeleton %s has %s weights per vertex.", skel.name, vertexWeights.getMaxNumberVertexWeights()) # Update description descr = skel.description self.descrLbl.setText(descr) self.boneCountLbl.setTextFormat(["Bones",": %s"], skel.getBoneCount()) # (Re-)draw the skeleton (before setting skeleton on human so it is automatically re-posed) self.drawSkeleton(skel) # Assign to human self.human.setSkeleton(skel) self.filechooser.selectItem(filename)
def resetAll(): """ Resets Human With Base CMU Skeleton :return: """ import skeleton global cmu_skel_file # Reset Human G.app._resetHuman() # Set Skeleton cmu_skel = skeleton.load(cmu_skel_file, human.meshData) G.app.selectedHuman.setSkeleton(cmu_skel) return
def chooseSkeleton(self, filename): log.debug("Loading skeleton from %s", filename) self.selectedRig = filename if not filename: if self.human.skeleton: # Unload current skeleton self.human.setSkeleton(None) if self.skelObj: # Remove old skeleton mesh self.removeObject(self.skelObj) self.human.removeBoundMesh(self.skelObj.name) self.skelObj = None self.skelMesh = None self.boneCountLbl.setTextFormat(["Bones",": %s"], "") self.descrLbl.setText("") self.filechooser.selectItem(None) return if getpath.isSamePath(filename, REF_RIG_PATH): skel = self.referenceRig.createFromPose() else: # Load skeleton definition from options skel = skeleton.load(filename, self.human.meshData) # Ensure vertex weights of skel are initialized skel.autoBuildWeightReferences(self.referenceRig) # correct weights references if only (pose) references were defined vertexWeights = skel.getVertexWeights(self.referenceRig.getVertexWeights(), force_remap=False) log.message("Skeleton %s has %s weights per vertex.", skel.name, vertexWeights.getMaxNumberVertexWeights()) # Remap bone orientation planes from reference rig skel.addReferencePlanes(self.referenceRig) # Not strictly needed for the new way in which we determine bone normals # Update description descr = skel.description self.descrLbl.setText(descr) self.boneCountLbl.setTextFormat(["Bones",": %s"], skel.getBoneCount()) # Assign to human self.human.setSkeleton(skel) # (Re-)draw the skeleton self.drawSkeleton() self.filechooser.selectItem(filename)
def fetch(event, result): for data in kinect.data(ip = ip): if data: event.set() result['data'] = data source = {} ready = threading.Event() thread = threading.Thread( target = fetch, args = (ready, source) ) thread.daemon = True thread.start() definition = skeleton.load( 'skeleton.json') body, joint = skeleton.create( definition ) dofs = Rigid3.array( len(body) ) def inertia(dofs): return skeleton.inertia(body, dofs) def skeleton_constraints(dofs, **kwargs): return skeleton.constraints(joint, dofs, compliance = 1e-8) dt = 1e-1 eps = 1e-2 print 'building skeleton...' for d, mu in solver.step(dofs, inertia,
def generateSpecificHuman(age, gender, race): """age is a string 'young', 'middleage', 'old' gender is a string 'male', 'female' race is a string 'caucasian', 'african', 'asian'""" import numpy as np import os G.app._resetHuman() import skeleton defaultSkeleton = skeleton.load("data/rigs/default.mhskel") rand_weight = np.random.uniform(0.0, 0.8) if gender == 'male': rand_gender = 0.9 + np.random.uniform(0.0,0.1) elif gender == 'female': rand_gender = np.random.uniform(0.0,0.1) male_indicator = rand_gender > 0.5 # True - male # age from 0.5 to 1.0 where 0.5 is 25y 1.0 is 90y if age == 'young': rand_age = np.random.uniform(0.5, 0.6) elif age == 'middleage': rand_age = np.random.uniform(0.7, 0.8) elif age == 'old': rand_age = np.random.uniform(0.9, 1.0) rand_muscle = np.random.uniform(0.2, 0.7) rand_height = np.random.uniform(0.45, 0.8) rand_body_proportions = np.random.uniform(0.2, 0.7) rand_race = np.random.uniform(0.8, 1.0) # race_indicator = np.argmax(rand_race) # 0 - white, 1 - black, 2 - asian human = G.app.selectedHuman human.setSkeleton(defaultSkeleton) human.setWeight(rand_weight) human.setGender(rand_gender) human.setAge(rand_age) human.setBodyProportions(rand_body_proportions) human.setHeight(rand_height) human.setMuscle(rand_muscle) if race == 'caucasian': human.setCaucasian(rand_race) elif race == 'african': human.setAfrican(rand_race) elif race == 'asian': human.setAsian(rand_race) RNG.randomize(human, 0.5, False, False, True, True) # randomize face and body age_str = None race_str = race gender_str = None if male_indicator: gender_str = 'male' else: gender_str = 'female' # if race_indicator == 0: # race_str = 'caucasian' # elif race_indicator == 1: # race_str = 'african' # else: # race_str = 'asian' if rand_age <= 0.6: age_str = 'young' elif rand_age <= 0.8: age_str = 'middleage' else: age_str = 'old' # assign material mat = material.fromFile('data/skins/'+age_str +'_'+race_str+'_'+gender_str+'/'+age_str+'_'+race_str+'_'+gender_str+'.mhmat') human.material = mat # set teeth teeth_plugin = G.app.getPlugin('3_libraries_teeth') teeth_plugin.taskview.proxyFileSelected('data/teeth/teeth_base/teeth_base.mhpxy') # set tongue tongue_plugin = G.app.getPlugin('3_libraries_tongue') tongue_plugin.taskview.proxyFileSelected('data/tongue/tongue01/tongue01.mhpxy') # set ['eyebrows', 'eyelashes', 'hair'] categories_list = ['eyebrows', 'eyelashes', 'hair', 'clothes', 'shoes'] category_plugin_str = \ {'eyebrows': '3_libraries_eyebrows', 'eyelashes': '3_libraries_eyelashes', 'hair': '3_libraries_polygon_hair_chooser', 'clothes': '3_libraries_clothes_chooser', 'shoes': '3_libraries_clothes_chooser'} category_paths = \ {'eyebrows': 'data/eyebrows/', 'eyelashes': 'data/eyelashes/', 'hair': 'data/hair/', 'clothes': 'data/clothes/', 'shoes': 'data/clothes/shoes/'} for category in categories_list: category_plugin = G.app.getPlugin(category_plugin_str[category]) category_path = category_paths[category] if category != 'shoes': if male_indicator: category_path = category_path + category + '_male/' else: category_path = category_path + category + '_female/' category_list = os.listdir(category_path) category_random = np.random.randint(0, len(category_list)) resulting_path = category_path+category_list[category_random]+'/' + category_list[category_random]+'.mhpxy' category_plugin.taskview.proxyFileSelected(resulting_path)
class appDummy: def __init__(self, human): self.selectedHuman = human self.splash = splashDummy() self.log_window = log_windowDummy() self.statusBar = None self.progress = None def addLogMessage(self, arg1, arg2): "Noop" buddy = human.Human( files3d.loadMesh(mh.getSysDataPath("3dobjs/base.obj"), maxFaces=5)) G.app = appDummy(buddy) base_skel = skeleton.load(mh.getSysDataPath('rigs/default.mhskel'), buddy.meshData) buddy.setBaseSkeleton(base_skel) import humanmodifier humanmodifier.loadModifiers("data/modifiers/modeling_modifiers.json", buddy) import proxy print os.getcwd() sys.stdout = stdout buddyProxy = proxy.loadProxy( buddy, os.path.join(os.getcwd(), 'data', 'eyes', 'low-poly', 'low-poly'), 'Eyes') print mesh, obj = buddyProxy.loadMeshAndObject(buddy) print
class appDummy: def __init__(self, human): self.selectedHuman = human self.splash = splashDummy() self.log_window = log_windowDummy() self.statusBar = None self.progress = None def addLogMessage(self, arg1, arg2): "Noop" buddy = human.Human(files3d.loadMesh(mh.getSysDataPath("3dobjs/base.obj"), maxFaces = 5)) G.app = appDummy(buddy) base_skel = skeleton.load(mh.getSysDataPath('rigs/default.mhskel'), buddy.meshData) buddy.setBaseSkeleton(base_skel) import humanmodifier humanmodifier.loadModifiers("data/modifiers/modeling_modifiers.json", buddy) import proxy print os.getcwd() sys.stdout = stdout buddyProxy = proxy.loadProxy(buddy, os.path.join(os.getcwd(), 'data', 'eyes', 'low-poly', 'low-poly'), 'Eyes') print mesh, obj = buddyProxy.loadMeshAndObject(buddy) print buddy.setEyesProxy(buddyProxy) mesh = obj.getSeedMesh()
def generateSpecificHuman(age, gender, race): """age is a string 'young', 'middleage', 'old' gender is a string 'male', 'female' race is a string 'caucasian', 'african', 'asian'""" import numpy as np import os G.app._resetHuman() import skeleton defaultSkeleton = skeleton.load("data/rigs/default.mhskel") rand_weight = np.random.uniform(0.0, 0.8) if gender == 'male': rand_gender = 0.9 + np.random.uniform(0.0, 0.1) elif gender == 'female': rand_gender = np.random.uniform(0.0, 0.1) male_indicator = rand_gender > 0.5 # True - male # age from 0.5 to 1.0 where 0.5 is 25y 1.0 is 90y if age == 'young': rand_age = np.random.uniform(0.5, 0.6) elif age == 'middleage': rand_age = np.random.uniform(0.7, 0.8) elif age == 'old': rand_age = np.random.uniform(0.9, 1.0) rand_muscle = np.random.uniform(0.2, 0.7) rand_height = 0.65 # np.random.uniform(0.3, 0.7) rand_body_proportions = np.random.uniform(0.2, 0.7) #african_incr = np.array([0.0, 0.9, 0.0]) #caucasian_incr = np.array([0.9, 0.0, 0.0]) #asian_incr = np.array([0.0, 0.0, 0.9]) #rand_race = np.random.uniform(0.01, 0.1, (3)) rand_race = np.random.uniform(0.8, 1.0) # if race == 'caucasian': # rand_race += caucasian_incr # elif race == 'african': # rand_race += african_incr # elif race == 'asian': # rand_race += asian_incr #race_indicator = np.argmax(rand_race) # 0 - white, 1 - black, 2 - asian human = G.app.selectedHuman human.setSkeleton(defaultSkeleton) human.setWeight(rand_weight) human.setGender(rand_gender) human.setAge(rand_age) human.setBodyProportions(rand_body_proportions) human.setHeight(rand_height) human.setMuscle(rand_muscle) if race == 'caucasian': human.setCaucasian(rand_race) elif race == 'african': human.setAfrican(rand_race) elif race == 'asian': human.setAsian(rand_race) RNG.randomize(human, 0.5, False, False, True, False, [0.2, 0.15, 0.2, 0.1, 0.05]) # randomize face age_str = None race_str = race gender_str = None if male_indicator: gender_str = 'male' else: gender_str = 'female' # if race_indicator == 0: # race_str = 'caucasian' # elif race_indicator == 1: # race_str = 'african' # else: # race_str = 'asian' if rand_age <= 0.6: age_str = 'young' elif rand_age <= 0.8: age_str = 'middleage' else: age_str = 'old' # assign material mat = material.fromFile('data/skins/' + age_str + '_' + race_str + '_' + gender_str + '/' + age_str + '_' + race_str + '_' + gender_str + '.mhmat') human.material = mat # set teeth teeth_plugin = G.app.getPlugin('3_libraries_teeth') teeth_plugin.taskview.proxyFileSelected( 'data/teeth/teeth_base/teeth_base.mhpxy') # set tongue tongue_plugin = G.app.getPlugin('3_libraries_tongue') tongue_plugin.taskview.proxyFileSelected( 'data/tongue/tongue01/tongue01.mhpxy') # set ['eyebrows', 'eyelashes', 'hair'] categories_list = ['eyebrows', 'eyelashes', 'hair'] #no clothes category_plugin_str = \ {'eyebrows': '3_libraries_eyebrows', 'eyelashes': '3_libraries_eyelashes', 'hair': '3_libraries_polygon_hair_chooser', 'clothes': '3_libraries_clothes_chooser'} for category in categories_list: category_plugin = G.app.getPlugin(category_plugin_str[category]) category_path = 'data/' + category + '/' if male_indicator: category_path = category_path + category + '_male/' else: category_path = category_path + category + '_female/' category_list = os.listdir(category_path) category_random = np.random.randint(0, len(category_list)) resulting_path = category_path + category_list[ category_random] + '/' + category_list[category_random] + '.mhpxy' category_plugin.taskview.proxyFileSelected(resulting_path)
def generateHuman(): import numpy as np import os G.app._resetHuman() import skeleton defaultSkeleton = skeleton.load("data/rigs/default.mhskel") rand_weight = np.random.uniform(0.0, 0.8) rand_gender = np.random.randint(0, 2) * 0.9 + np.random.uniform(0.1) male_indicator = rand_gender > 0.5 # True - male rand_age = np.random.uniform(0.5, 0.9) rand_muscle = np.random.uniform(0.3, 0.6) rand_height = 0.65 #np.random.uniform(0.3, 0.7) # TODO: it is a crutch to avoid camera adjusting rand_body_proportions = np.random.uniform(0.2, 0.7) rand_race = np.random.uniform(0.01, 1.0, (3)) race_indicator = np.argmax(rand_race) # 0 - white, 1 - black, 2 - asian human = G.app.selectedHuman human.setSkeleton(defaultSkeleton) human.setWeight(rand_weight) human.setGender(rand_gender) human.setAge(rand_age) human.setBodyProportions(rand_body_proportions) human.setHeight(rand_height) human.setMuscle(rand_muscle) human.setCaucasian(rand_race[0]) human.setAfrican(rand_race[1]) human.setAsian(rand_race[2]) RNG.randomize(human, 0.5, False, False, True, False, [0.2, 0.15, 0.2, 0.1, 0.05]) # randomize face age_str = None race_str = None gender_str = None if male_indicator: gender_str = 'male' else: gender_str = 'female' if race_indicator == 0: race_str = 'caucasian' elif race_indicator == 1: race_str = 'african' else: race_str = 'asian' if rand_age < 0.6: age_str = 'young' elif rand_age < 0.8: age_str = 'middleage' else: age_str = 'old' # assign material mat = material.fromFile('data/skins/' + age_str + '_' + race_str + '_' + gender_str + '/' + age_str + '_' + race_str + '_' + gender_str + '.mhmat') human.material = mat # set teeth teeth_plugin = G.app.getPlugin('3_libraries_teeth') teeth_plugin.taskview.proxyFileSelected( u'data\\teeth\\teeth_base\\teeth_base.mhpxy') # set tongue tongue_plugin = G.app.getPlugin('3_libraries_tongue') tongue_plugin.taskview.proxyFileSelected( u'data\\tongue\\tongue01\\tongue01.mhpxy') # set ['eyebrows', 'eyelashes', 'hair'] categories_list = ['eyebrows', 'eyelashes', 'hair'] #no clothes category_plugin_str = \ {'eyebrows': '3_libraries_eyebrows', 'eyelashes': '3_libraries_eyelashes', 'hair': '3_libraries_polygon_hair_chooser', 'clothes': '3_libraries_clothes_chooser'} #output_test = open(r'C:\Users\пк1\Desktop\test.txt'.decode('utf8'), 'w') for category in categories_list: category_plugin = G.app.getPlugin(category_plugin_str[category]) category_path = 'data/' + category + '/' if male_indicator: category_path = category_path + category + '_male/' else: category_path = category_path + category + '_female/' category_list = os.listdir(category_path) category_random = np.random.randint(0, len(category_list)) resulting_path = category_path + category_list[ category_random] + '/' + category_list[category_random] + '.mhpxy' category_plugin.taskview.proxyFileSelected(resulting_path)
def generateHuman(): import numpy as np import os G.app._resetHuman() import skeleton defaultSkeleton = skeleton.load("data/rigs/default.mhskel") rand_weight = np.random.uniform(0.0, 0.8) rand_gender = np.random.randint(0, 2)*0.9 + np.random.uniform(0.1) male_indicator = rand_gender > 0.5 # True - male rand_age = np.random.uniform(0.5, 0.9) rand_muscle = np.random.uniform(0.3, 0.6) rand_height = 0.65#np.random.uniform(0.3, 0.7) # TODO: it is a crutch to avoid camera adjusting rand_body_proportions = np.random.uniform(0.2, 0.7) rand_race = np.random.uniform(0.01, 1.0, (3)) race_indicator = np.argmax(rand_race) # 0 - white, 1 - black, 2 - asian human = G.app.selectedHuman human.setSkeleton(defaultSkeleton) human.setWeight(rand_weight) human.setGender(rand_gender) human.setAge(rand_age) human.setBodyProportions(rand_body_proportions) human.setHeight(rand_height) human.setMuscle(rand_muscle) human.setCaucasian(rand_race[0]) human.setAfrican(rand_race[1]) human.setAsian(rand_race[2]) RNG.randomize(human, 0.5, False, False, True, False, [0.2,0.15,0.2,0.1,0.05]) # randomize face age_str = None race_str = None gender_str = None if male_indicator: gender_str = 'male' else: gender_str = 'female' if race_indicator == 0: race_str = 'caucasian' elif race_indicator == 1: race_str = 'african' else: race_str = 'asian' if rand_age < 0.6: age_str = 'young' elif rand_age < 0.8: age_str = 'middleage' else: age_str = 'old' # assign material mat = material.fromFile('data/skins/'+age_str +'_'+race_str+'_'+gender_str+'/'+age_str+'_'+race_str+'_'+gender_str+'.mhmat') human.material = mat # set teeth teeth_plugin = G.app.getPlugin('3_libraries_teeth') teeth_plugin.taskview.proxyFileSelected(u'data\\teeth\\teeth_base\\teeth_base.mhpxy') # set tongue tongue_plugin = G.app.getPlugin('3_libraries_tongue') tongue_plugin.taskview.proxyFileSelected(u'data\\tongue\\tongue01\\tongue01.mhpxy') # set ['eyebrows', 'eyelashes', 'hair'] categories_list = ['eyebrows', 'eyelashes', 'hair'] #no clothes category_plugin_str = \ {'eyebrows': '3_libraries_eyebrows', 'eyelashes': '3_libraries_eyelashes', 'hair': '3_libraries_polygon_hair_chooser', 'clothes': '3_libraries_clothes_chooser'} #output_test = open(r'C:\Users\пк1\Desktop\test.txt'.decode('utf8'), 'w') for category in categories_list: category_plugin = G.app.getPlugin(category_plugin_str[category]) category_path = 'data/' + category + '/' if male_indicator: category_path = category_path + category + '_male/' else: category_path = category_path + category + '_female/' category_list = os.listdir(category_path) category_random = np.random.randint(0, len(category_list)) resulting_path = category_path+category_list[category_random]+'/' + category_list[category_random]+'.mhpxy' category_plugin.taskview.proxyFileSelected(resulting_path)