- def create_texture(directory, texture_name):\r
- texture=bpy.data.textures.new(texture_name)\r
- texture.type='IMAGE'\r
- texture=texture.recast_type()\r
- #texturePath="%s/%s" % (directory, texture_name)\r
- texturePath=os.path.join(directory, texture_name)\r
- print('create_texture', texturePath)\r
- image=bpy.data.images.load(texturePath)\r
- texture.image=image\r
- texture.mipmap = True\r
- texture.interpolation = True\r
- texture.use_alpha = True\r
- return texture\r
-\r
- def create_materials(scene, mqo, directory):\r
- materials = []\r
- textureMap={}\r
- imageMap={}\r
- if len(mqo.materials)>0:\r
- for material_index, m in enumerate(mqo.materials):\r
- material = bpy.data.materials.new(m.getName())\r
- materials.append(material)\r
- # mqo material\r
- material.diffuse_color=[m.color.r, m.color.g, m.color.b]\r
- material.alpha=m.color.a\r
- material.diffuse_intensity=m.diffuse\r
- texture_name=m.getTexture()\r
- if texture_name!='':\r
- if texture_name in textureMap:\r
- texture=textureMap[texture_name]\r
- else:\r
- texture=create_texture(directory, texture_name)\r
- textureMap[texture_name]=texture\r
- imageMap[material_index]=texture.image\r
- #material.add_texture(texture, "UV", {"COLOR", "ALPHA"})\r
- material.add_texture(texture, "UV", "COLOR")\r
- # temporary\r
- material.emit=1.0\r
- else:\r
- material = bpy.data.materials.new('Default')\r
- materials.append(material)\r
- return materials, imageMap\r
-\r