def createMakeSkinMaterial(name, materialSettingsHash, obj, ifExists="CREATENEW", importBlendMat=False, onlyBlendMat=False): # TODO: Support overwriting existing material # TODO: This will cause problem with blendMat attachments in second import mat = bpy.data.materials.get(name) if not mat is None and ifExists == "REUSE": print("Resuing existing material " + name) return mat from makeskin import MHMat, blendMatLoad mhmat = MHMat(fileName=materialSettingsHash["materialFile"]) mat = None if importBlendMat and "blendMaterial" in mhmat.settings and mhmat.settings[ "blendMaterial"]: if not onlyBlendMat: mat = mhmat.assignAsNodesMaterialForObj(obj) mat.name = name path = mhmat.settings["blendMaterial"] if not mat: mat = blendMatLoad(path, obj) mat.name = name else: mat2 = blendMatLoad(path, obj) mat2.name = name + ".blendMat" else: mat = mhmat.assignAsNodesMaterialForObj(obj) mat.name = name return mat
def make(self): self.bodyPart = self.clothesObj.MhOffsetScale # get the scalings if len(self.bodyPart) == 0: return (False, "No scaling defined") (self.baseMeshType, self.meshConfig) = _loadMeshJson( self.humanObj) # load parameters for scales according to mesh if len(self.meshConfig) == 0: return (False, "Cannot open configuration file for " + self.baseMeshType) if self.bodyPart not in self.meshConfig[ "dimensions"]: # check if we have the scalings return (False, "Cannot evaluate offsets for " + self.bodyPart) # also the groups have been tested we should avoid going on with an unknown group # (b, text) = self.findClosestVertices() if b is False: return (False, text) self.findBestFaces() self.findWeightsAndDistances() self.evaluateDeleteVertices() self.dirName = None self.cleanedName = None self.setupTargetDirectory() # # get dimensions of the selected BodyPart (values from json are blender values) # dims = self.meshConfig["dimensions"][self.bodyPart] self.minmax = { 'xmin': dims['xmin'], 'xmax': dims['xmax'], 'ymin': dims['ymin'], 'ymax': dims['ymax'], 'zmin': dims['zmin'], 'zmax': dims['zmax'] } self.scales[0] = self.humanmesh.getScale(dims['xmin'], dims['xmax'], 0) self.scales[2] = self.humanmesh.getScale(dims['ymin'], dims['ymax'], 1) # scales-index self.scales[1] = self.humanmesh.getScale(dims['zmin'], dims['zmax'], 2) # y and z are changed # # write the output files and check for errors # (b, hint) = self.writeMhClo() if b is False: return (False, hint) (b, hint) = self.writeObj() if b is False: return (False, hint) if self.useMakeSkin: print("Using makeskin to write material") from makeskin import MHMat as MakeSkinMat mat = MakeSkinMat(self.clothesObj) outputFile = os.path.join(self.dirName, self.cleanedName + ".mhmat") handling = "NORMALIZE" if self.clothesObj.MhMsTextures: handling = self.clothesObj.MhMsTextures if handling == "NORMALIZE": mat.copyTextures(outputFile) if handling == "COPY": mat.copyTextures(outputFile, normalize=False) if mat.settings["normalmapTexture"]: mat.shaderConfig["normal"] = True if mat.settings["bumpmapTexture"]: mat.shaderConfig["bump"] = True if self.clothesObj.MhMsUseLit and self.clothesObj.MhMsLitsphere: mat.litSphere = self.clothesObj.MhMsLitsphere if mat.settings["displacementmapTexture"]: mat.shaderConfig["displacement"] = True with open(outputFile, 'w') as f: f.write(str(mat)) else: print("Using limited MakeClothes material model, ie not MakeSkin") (b, hint) = self.writeMhMat() if b is False: return (False, hint) if True: self.writeDebug() self.selectHumanVertices() return (True, "")
def load(self, context, props): realpath = os.path.realpath(os.path.expanduser(props.filepath)) folder = os.path.dirname(realpath) try: fp = open(props.filepath, "r") except: return None vn = 0 status = "" mhmat = None for line in fp: words = line.split() l = len(words) if l == 0: status = "" continue # at least grab what you get from the comment # if words[0] == '#': if l > 2: key = words[1].lower() if "author" in key: self.author = words[2] elif "license" in key: if "by" in line.lower(): self.license = "CC-BY" elif "apgl" in line.lower(): self.license = "AGPL" elif "description" in key: self.description = " ".join(words[2:]) continue if words[0] == "material": mhmat = os.path.join(folder, words[1]) # read vertices lines # if status == 'v': if words[0].isnumeric() is False: status = "" continue if l == 1: v = int(words[0]) self.verts[vn] = { 'verts': (v, v, v), 'weights': (1, 0, 0), 'offsets': Vector((0, 0, 0)) } else: v0 = int(words[0]) v1 = int(words[1]) v2 = int(words[2]) w0 = float(words[3]) w1 = float(words[4]) w2 = float(words[5]) d0 = float(words[6]) d1 = float(words[7]) d2 = float(words[8]) self.verts[vn] = { 'verts': (v0, v1, v2), 'weights': (w0, w1, w2), 'offsets': Vector((d0, -d2, d1)) } vn += 1 continue elif status == 'd': if words[0].isnumeric() is False: status = "" continue sequence = False for v in words: if v == "-": sequence = True else: v1 = int(v) if sequence: for vn in range(v0, v1 + 1): self.delverts.append(vn) sequence = False else: self.delverts.append(v1) v0 = v1 continue key = words[0] status = "" if key == 'obj_file': self.obj_file = os.path.join(folder, words[1]) print("Loading: " + self.obj_file + "\n") elif key == 'verts': if len(words) > 1: self.first = int( words[1] ) # this value will be ignored, we always start from zero status = "v" elif key == 'x_scale': self.xs = (int(words[1]), int(words[2]), float(words[3])) elif key == 'y_scale': self.ys = (int(words[1]), int(words[2]), float(words[3])) elif key == 'z_scale': self.zs = (int(words[1]), int(words[2]), float(words[3])) elif key == 'name': self.name = words[1] elif key == 'z_depth': self.zdepth = int(words[1]) elif key == 'tag': if self.tags != "": self.tags += "," self.tags += words[1].lower() elif key == 'delete_verts': self.delete = True status = 'd' fp.close obj = None if self.obj_file != "": obj = loadObjFile(context, self.obj_file) if obj is not None: self.clothes = obj context.active_object.MhObjectType = "Clothes" context.active_object.MhClothesName = self.name context.active_object.MhClothesTags = self.tags context.active_object.MhClothesDesc = self.description context.active_object.MhZDepth = self.zdepth context.scene.MhClothesAuthor = self.author context.scene.MhClothesLicense = self.license if self.delete is True: self.delete_group = "Delete_" + self.name context.active_object.MhDeleteGroup = self.delete_group if mhmat and obj and self.checkMakeSkinAvailable(): print("Makeskin is available. Using it to import MHMAT file too.") from makeskin import MHMat, blendMatLoad while len(obj.data.materials) > 0: obj.data.materials.pop(index=0) makeskinMaterial = MHMat(fileName=mhmat) makeskinMaterial.assignAsNodesMaterialForObj(obj) return
def make(self): self.bodyPart = self.clothesObj.MhOffsetScale # get the scalings if len(self.bodyPart) == 0: return (False, "No scaling defined") (self.baseMeshType, self.meshConfig) = _loadMeshJson( self.humanObj) # load parameters for scales according to mesh if len(self.meshConfig) == 0: return (False, "Cannot open configuration file for " + self.baseMeshType) if self.bodyPart not in self.meshConfig[ "dimensions"]: # check if we have the scalings return (False, "Cannot evaluate offsets for " + self.bodyPart) # also the groups have been tested we should avoid going on with an unknown group # (b, text) = self.findClosestVertices() if b is False: return (False, text) self.findBestFaces() self.findWeightsAndDistances() self.evaluateDeleteVertices() self.dirName = None self.cleanedName = None self.setupTargetDirectory() # # get dimensions of the selected BodyPart (values from json are blender values) # dims = self.meshConfig["dimensions"][self.bodyPart] self.minmax = { 'xmin': dims['xmin'], 'xmax': dims['xmax'], 'ymin': dims['ymin'], 'ymax': dims['ymax'], 'zmin': dims['zmin'], 'zmax': dims['zmax'] } self.scales[0] = self.humanmesh.getScale(dims['xmin'], dims['xmax'], 0) self.scales[2] = self.humanmesh.getScale(dims['ymin'], dims['ymax'], 1) # scales-index self.scales[1] = self.humanmesh.getScale(dims['zmin'], dims['zmax'], 2) # y and z are changed # # write the output files and check for errors # (b, hint) = self.writeMhClo() if b is False: return (False, hint) (b, hint) = self.writeObj() if b is False: return (False, hint) if self.useMakeSkin: print("Using makeskin to write material") from makeskin import MHMat as MakeSkinMat mat = MakeSkinMat(self.clothesObj) outputFile = os.path.join(self.dirName, self.cleanedName + ".mhmat") checkImg = mat.checkAllTexturesAreSaved() if checkImg: return (False, checkImg) errtext = mat.writeMHmat(self.clothesObj, outputFile) if errtext: return (False, errtext) else: print("Using limited MakeClothes material model, ie not MakeSkin") (b, hint) = self.writeMhMat() if b is False: return (False, hint) if True: self.writeDebug() self.selectHumanVertices() return (True, "")