Extensions:2.4/Py/Scripts/Temp/UVtoTex

提供: wiki
< Extensions:2.4‎ | Py‎ | Scripts‎ | Temp
移動先: 案内検索

This script takes the current image and assigns it as a UV mapped texture to the first available texture channel on the current object's material. If the current object does not have a material, one will be created for it.

#!BPY

""" Registration info for Blender menus: <- these words are ignored
Name: 'Add UV Image as Material Texture'
Blender: 240
Group: 'UV'
Tooltip: 'Put Active Image as UV Mapped Texture on Active Object'
"""


__author__ = "Johnny Matthews"
__url__ = ("blender")
__version__ = "1.1 12/18/05"

__bpydoc__ = """\
This script takes the active image and sets it in the first texture channel of
the first material of the active object mapped to COL and UV. If no material
exists for the Object, one is created.
"""

# -------------------------------------------------------------------------- 
# Add UV as Material Texture
# -------------------------------------------------------------------------- 
# ***** BEGIN GPL LICENSE BLOCK ***** 
# 
# This program is free software; you can redistribute it and/or 
# modify it under the terms of the GNU General Public License 
# as published by the Free Software Foundation; either version 2 
# of the License, or (at your option) any later version. 
# 
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
# GNU General Public License for more details. 
# 
# You should have received a copy of the GNU General Public License 
# along with this program; if not, write to the Free Software Foundation, 
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
# 
# ***** END GPL LICENCE BLOCK ***** 
# -------------------------------------------------------------------------- 


import Blender
import bpy
from Blender import Material
from Blender import *

object = Blender.Object.GetSelected()[0]
mesh = object.getData()

mats = mesh.getMaterials()
material = 0

if len(mats) == 0:
	material = Material.New('newmat')
else:
	material = mats[0]

tex = Blender.Texture.New('UV')            
tex.setType('Image')                 
img = bpy.data.images.active            
tex.image = img                    

texs = material.getTextures()

i=0
for i in range (0,9):
	if texs[i] == None:
		break
	
material.setTexture(i, tex,Blender.Texture.TexCo.UV) 

if len(mats) == 0:
	mesh.materials.append(material)
	
mesh.update()

Window.RedrawAll()