def execute(self, context): proContext.blenderContext = context bpy.ops.object.select_all(action="DESELECT") # remember the original object, it will be used for low poly model lowPolyObject = context.object lowPolyObject.select_set(True) bpy.ops.object.duplicate() highPolyObject = context.object # high poly model ruleFile = bpy.data.texts[context.scene.bcgaScript].filepath if ruleFile: highPolyParams = bpro.apply(ruleFile)[1] # convert highPolyParams to a dict paramName->instanceofParamClass highPolyParams = dict(highPolyParams) # low poly model context.view_layer.objects.active = lowPolyObject ruleFile = bpy.data.texts[context.scene.bakingBcgaScript].filepath if ruleFile: name = lowPolyObject.name module = bpro.getModule(ruleFile) lowPolyParams = bpro.getParams(module) # Apply highPolyParams to lowPolyParams # Normally lowPolyParams is a subset of highPolyParams for paramName, param in lowPolyParams: if paramName in highPolyParams: param.setValue(highPolyParams[paramName].getValue()) bpro.apply(module) # unwrap the low poly model bpy.ops.object.mode_set(mode="EDIT") bpy.ops.mesh.select_all(action="SELECT") bpy.ops.uv.smart_project() # prepare settings for baking bpy.ops.object.mode_set(mode="OBJECT") highPolyObject.select_set(True) bpy.context.scene.cycles.bake_type = "DIFFUSE" bpy.context.scene.cycles.use_bake_selected_to_active = True # create a new image with default settings for baking image = bpy.data.images.new(name=name, width=512, height=512) # finally perform baking bpy.ops.object.bake_image() # delete the high poly object and its mesh context.view_layer.objects.active = highPolyObject mesh = highPolyObject.data bpy.ops.object.delete() bpy.data.meshes.remove(mesh) context.view_layer.objects.active = lowPolyObject # assign the baked texture to the low poly object blenderTexture = bpy.data.textures.new(name, type="IMAGE") blenderTexture.image = image blenderTexture.use_alpha = True material = bpy.data.materials.new(name) # textureSlot = material.texture_slots.add() # textureSlot.texture = blenderTexture # textureSlot.texture_coords = "UV" # textureSlot.uv_layer = "bcga" lowPolyObject.data.materials.append(material) return {"FINISHED"}
def execute(self, context): proContext.blenderContext = context bpy.ops.object.select_all(action="DESELECT") # remember the original object, it will be used for low poly model lowPolyObject = context.object lowPolyObject.select_set(True) bpy.ops.object.duplicate() highPolyObject = context.object # high poly model ruleFile = bpy.data.texts[context.scene.bcgaScript].filepath if ruleFile: highPolyParams = bpro.apply(ruleFile)[1] # convert highPolyParams to a dict paramName->instanceofParamClass highPolyParams = dict(highPolyParams) # low poly model context.view_layer.objects.active = lowPolyObject ruleFile = bpy.data.texts[context.scene.bakingBcgaScript].filepath if ruleFile: name = lowPolyObject.name module = bpro.getModule(ruleFile) lowPolyParams = bpro.getParams(module) # Apply highPolyParams to lowPolyParams # Normally lowPolyParams is a subset of highPolyParams for paramName,param in lowPolyParams: if paramName in highPolyParams: param.setValue(highPolyParams[paramName].getValue()) bpro.apply(module) # unwrap the low poly model bpy.ops.object.mode_set(mode="EDIT") bpy.ops.mesh.select_all(action="SELECT") bpy.ops.uv.smart_project() # prepare settings for baking bpy.ops.object.mode_set(mode="OBJECT") highPolyObject.select_set(True) bpy.context.scene.cycles.bake_type = "DIFFUSE" bpy.context.scene.cycles.use_bake_selected_to_active = True # create a new image with default settings for baking image = bpy.data.images.new(name=name, width=512, height=512) # finally perform baking bpy.ops.object.bake_image() # delete the high poly object and its mesh context.view_layer.objects.active = highPolyObject mesh = highPolyObject.data bpy.ops.object.delete() bpy.data.meshes.remove(mesh) context.view_layer.objects.active = lowPolyObject # assign the baked texture to the low poly object blenderTexture = bpy.data.textures.new(name, type = "IMAGE") blenderTexture.image = image blenderTexture.use_alpha = True material = bpy.data.materials.new(name) # textureSlot = material.texture_slots.add() # textureSlot.texture = blenderTexture # textureSlot.texture_coords = "UV" # textureSlot.uv_layer = "bcga" lowPolyObject.data.materials.append(material) return {"FINISHED"}
def execute(self, context): proContext.blenderContext = context for param in self.params: param = param[1] param.setValue(getattr(param.collectionItem, "value")) bpro.apply(self.module) #align_view(context.object) return {"FINISHED"}
def invoke(self, context, event): proContext.blenderContext = context ruleFile = getRuleFile(context.scene.prokitekturaScript, self) if ruleFile: # append the directory of the ruleFile to sys.path ruleFileDirectory = os.path.dirname( os.path.realpath(os.path.expanduser(ruleFile))) if ruleFileDirectory not in sys.path: sys.path.append(ruleFileDirectory) module, params = bpro.apply(ruleFile) #align_view(context.object) self.module = module self.params = params # new params arrived, so clean all collections self.collectionFloat.clear() self.collectionColor.clear() paramCounter = 0 # for each entry in self.params create a new item in self.collection for param in self.params: param = param[1] if isinstance(param, ParamFloat): collectionItem = self.collectionFloat.add() elif isinstance(param, ParamColor): collectionItem = self.collectionColor.add() collectionItem.value = param.getValue() param.collectionItem = collectionItem paramCounter += 1 if paramCounter == 9: break return {"FINISHED"}
def invoke(self, context, event): self.initialize() proContext.blenderContext = context ruleFile = bpy.data.texts[context.scene.bcgaScript].filepath if ruleFile: # append the directory of the ruleFile to sys.path ruleFileDirectory = os.path.dirname(os.path.realpath(os.path.expanduser(ruleFile))) if ruleFileDirectory not in sys.path: sys.path.append(ruleFileDirectory) module,params = bpro.apply(ruleFile) #align_view(context.object) self.module = module self.params = params numFloats = 0 numColors = 0 # for each entry in self.params create a new item in self.collection for param in self.params: param = param[1] if isinstance(param, ParamFloat): collectionItem = self.collectionFloat[numFloats] numFloats += 1 elif isinstance(param, ParamColor): collectionItem = self.collectionColor[numColors] numColors += 1 collectionItem.value = param.getValue() param.collectionItem = collectionItem return {"FINISHED"}
def invoke(self, context, event): self.initialize() proContext.blenderContext = context ruleFile = getRuleFile(context.scene.bcgaScript, self) if ruleFile: # append the directory of the ruleFile to sys.path ruleFileDirectory = os.path.dirname(os.path.realpath(os.path.expanduser(ruleFile))) if ruleFileDirectory not in sys.path: sys.path.append(ruleFileDirectory) module,params = bpro.apply(ruleFile) #align_view(context.object) self.module = module self.params = params numFloats = 0 numColors = 0 # for each entry in self.params create a new item in self.collection for param in self.params: param = param[1] if isinstance(param, ParamFloat): collectionItem = self.collectionFloat[numFloats] numFloats += 1 elif isinstance(param, ParamColor): collectionItem = self.collectionColor[numColors] numColors += 1 collectionItem.value = param.getValue() param.collectionItem = collectionItem return {"FINISHED"}
def invoke(self, context, event): proContext.blenderContext = context ruleFile = getRuleFile(context.scene.prokitekturaScript, self) if ruleFile: # append the directory of the ruleFile to sys.path ruleFileDirectory = os.path.dirname(os.path.realpath(os.path.expanduser(ruleFile))) if ruleFileDirectory not in sys.path: sys.path.append(ruleFileDirectory) module,params = bpro.apply(ruleFile) #align_view(context.object) self.module = module self.params = params # new params arrived, so clean all collections self.collectionFloat.clear() self.collectionColor.clear() paramCounter = 0 # for each entry in self.params create a new item in self.collection for param in self.params: param = param[1] if isinstance(param, ParamFloat): collectionItem = self.collectionFloat.add() elif isinstance(param, ParamColor): collectionItem = self.collectionColor.add() collectionItem.value = param.getValue() param.collectionItem = collectionItem paramCounter += 1 if paramCounter==9:break return {"FINISHED"}