Post by alphac on Jul 12, 2020 18:25:18 GMT
Script for adding textures to 3D models in Blender 2.79
Note to moderators: I'm not sure where to re-post this so move this thread as you please ;-)
------------------------
Here's a modified version of nobulle's script and it adds the alpha channel (transparency) to the textures
It works in Blender 2.79 - not in 2.80 which is a big Blender overhaul
Big thanks to nobulle for his/her work. I couldn't create my script without it
1) open Blender and import the .OBJ from ground_models
2) save the Blender file.
3) place the texture directory (called Textures) in the same place as the Blender file
4) open Python console in Blender
5) copy/paste this script and press Enter 2x (1x for entering the script, 1x running the script)
It works in Blender 2.79 - not in 2.80 which is a big Blender overhaul
Big thanks to nobulle for his/her work. I couldn't create my script without it

1) open Blender and import the .OBJ from ground_models
2) save the Blender file.
3) place the texture directory (called Textures) in the same place as the Blender file
4) open Python console in Blender
5) copy/paste this script and press Enter 2x (1x for entering the script, 1x running the script)
import math
import bpy
import mathutils
import re
for mat in list(bpy.data.materials):
newname = re.search('[0-9]+', mat.name)
if hasattr(newname, 'group'):
if newname.group(0)+".png" in bpy.data.images:
bpy.data.images[newname.group(0)+".png"].filepath = "//Textures/"+newname.group(0)+".png"
if newname.group(0)+".png" in bpy.data.images:
bpy.data.images[newname.group(0)+".png"].reload()
if newname.group(0)+".png.001" in bpy.data.images:
bpy.data.images[newname.group(0)+".png.001"].filepath = "//Textures/"+newname.group(0)+".png"
if newname.group(0)+".png.001" in bpy.data.images:
bpy.data.images[newname.group(0)+".png.001"].reload()
mat.specular_intensity = 0.0
mat.diffuse_intensity = 1.0
mat.use_transparency = True
if mat.texture_slots[0]:
mat.texture_slots[0].use_map_color_diffuse = True
mat.texture_slots[0].use_map_alpha = True
if mat.texture_slots[1]:
mat.texture_slots[1].use_map_color_diffuse = True
mat.texture_slots[1].use_map_alpha = True
6) in the 3D view find Shading in the right column (you can toggle the column with "n")
7) check "Textured solid" and you should see the textured model