Material to UV texture ?

has any one ever made a texture to UV map script ? Would be good for quick tests of how something looks in the 3d view and game engines .

you mean a way to bake textures?

no

ok then , is it even possible with the API as it is ?

You can use Sticky option in edit window (f9)

That does nothing, I was wanting the crisp colorful UV texture look display. UV textures show up so nice and detailed, but Blenders textures sshow a very bad vertex color blow out in the 3d View.

you have also to use some simple subdiv…

Um I am just not seeing it. Oh I see you have to make the count to high. That just cansels the speed tests out.

You’r lucky, i made it few weeks ago. :smiley:
Here is it :


#!BPY 

""" 
Name: 'ph_UV_view_Update' 
Blender: 232 
Group: 'Misc' 
Tooltip: 'updating openGL view with first image of each faces material index.' 
""" 

################
#
# ph_UV_view_Update.py
#
# Cree le 21/04/2004
#
##########################

import Blender
from Blender import *
from Blender.Draw import *
from Blender.BGL import *
try:
	import meshtools
except:
	pass


EVENT_EXIT = 1
EVENT_GO = 2

###############
def info_Obj(Ob):
###############

  Obtype = 0
  mename = []
  me = []

  if (Ob.getType() == 'Mesh'):
      Obtype = 1
      calque = Ob.Layer                    # Le "layer" de l'object selectionne
      mename = Ob.getData().name
      me = Ob.getData()

  return Ob,Obtype,mename,me

###########
def main():
###########

	ObjS = Object.GetSelected()

	if ObjS:
		for o in ObjS:

			Obj,ObjType,meshname,mesh = info_Obj(o)

			print
			print "Objet:",Obj.name," Mesh:",meshname


			if ObjType:
				C = NMesh.FaceModes

				obFaces = mesh.faces  #### Liste des faces ####
				obVerts = mesh.verts  #### Liste des vertex ####
				obMats = mesh.materials  #### Liste des materiaux assignes a l'object ####

				if obMats:
					print obMats
					for f in obFaces:
						try:
							TextureOfFace = obMats[f.materialIndex].name

							##### ATTENTION : ci-dessous, .getTextures() est une fonction cache,
							##### on peut la trouve en haut de la doc du module Texture ###########

							f.image = Material.Get(TextureOfFace).getTextures()[0].tex.getImage()
							f.mode=C['TEX']
						except:
							pass

					NMesh.PutRaw(mesh,mesh.name)


		try:
			meshtools.print_boxed("Finished !")
		except:
			print "Finished !\a\r"

	return 0

##################
def draw():
##################
	global EVENT_EXIT, EVENT_GO

	glClearColor(0.265, 0.41, 0.4, 1)
	glClear(Blender.BGL.GL_COLOR_BUFFER_BIT)

	glColor3f(0.0,0.0,0.0)
	glRasterPos2d(31, 164)
	Text("ph_UV_view_Update.py.")
	glRasterPos2d(32, 163)
	Text("ph_UV_view_Update.py.")
	glColor3f(1,1,1)
	glRasterPos2d(30, 165)
	Text("ph_UV_view_Update.py.")


	glColor3f(1,1,1)
	glRasterPos2d(30, 140)
	Text("Met a jour la vue OpenGL")
	glRasterPos2d(30, 120)
	Text("pour que les faces de l'objet")

	glRasterPos2d(30, 100)
	Text("soient en rapport avec")
	glRasterPos2d(30, 80)
	Text("les images attribuees")

	glRasterPos2d(30, 60)
	Text("a ces differents materiaux.")

	Button("Update UV", EVENT_GO, 30, 20, 70, 20, "updating openGL view with first image of each faces material index.")
	Button("Exit", EVENT_EXIT, 165, 20, 35, 20, "Quit.")


######################
def event(evt, val): #
					 #
######################

	if ( evt == ESCKEY and not val):
		Exit()

	if (evt== QKEY and not val):
		Exit()

######################
######################
def bevent(evt):	 #
					 #
######################
	global EVENT_EXIT, EVENT_GO

	if evt == EVENT_EXIT:
		Exit()

	if evt == EVENT_GO:
		main()

	Blender.Window.Redraw()

######################
Register(draw, event, bevent)

++
Ph
http://hp.home.chez.tiscali.fr/re_illusion/index.htm

I just tried it. It was in french so i didn’t understand what the text in the UI said, but when i pressed the ‘update UV’ button, nothing happened, except my computer beeped, which was unusual.
<edit> ok I think I get it now,… :slight_smile:

In this script the texture image is linked to every faces of the mesh but no uvcoord is calculated. Do not forget that a texture is mapped with one of these types : flat, tube, cube or sphere…

:expressionless:
I just got to test it. Nothing happens, I get the GUI in french but nothing happens

i am going to try explain to you how to use the script :
First, your 3dview have to be in ‘textured mode’.
Select the object(s) you wanna update but note that these objects have to have a material with an image at least as texture (it is an compulsory need to see the script working).
Other compulsory need:

  • if these objects have not an ‘UVmap’, so, for all these objects, juste switch in ‘FaceMode’ once at least before return in ‘ObjectMode’ (push ‘F’ key twice).
    When all these conditions are combined, you can now push on ‘Update UV’ button in the script.
    I hope my explanations was clear enough. :wink:

++
Ph
http://hp.home.chez.tiscali.fr/re_illusion/index.htm

i am going to try explain to you how to use the script :
First, your 3dview have to be in ‘textured mode’.
Select the object(s) you wanna update but note that these objects have to have a material with an image at least as texture (it is an compulsory need to see the script working).
Other compulsory need:

  • if these objects have not an ‘UVmap’, so, for all these objects, juste switch in ‘FaceMode’ once at least before return in ‘ObjectMode’ (push ‘F’ key twice).
    When all these conditions are combined, you can now push on ‘Update UV’ button in the script.
    I hope my explanations was clear enough. :wink:

++
Ph
http://hp.home.chez.tiscali.fr/re_illusion/index.htm[/quote]

Ok maybe I am stupid or it just does not work for me. I followed this completely. But nothing happens, maybe I am just explaining it wrong, or thinking the wrong idea.

This:

Is a rendered icosphere lowpoly with a noise material. But showing it in the 3d view shows nothing at all, unless I make the mesh sub divide grossly unusable and sticky. But if it could be “baked” as a texture image I could view it and edit it’s look much faster in 3d view without haveing to do constant renders.

See what I am trying to get ? Maybe your script does it. Dont know I do get this in the console though
Objet: Sphere.004 Mesh: Sphere.004
[[Material “Material.016”]]
Finished !a

Ok maybe I am stupid or it just does not work for me. I followed this completely. But nothing happens, maybe I am just explaining it wrong, or thinking the wrong idea.

See what I am trying to get ?

OK!
May be i had to say “PICTURE” and not “IMAGE” in my precedent thread (sorry, but i’m ‘frenchy’).
In others words, my script only work if your objects have ‘Pictures’ as texture and only ‘Pictures’, so it don’t work with ‘Procedural textures’.
Sorry but i don’t see a way to do your request except as told above by the ‘Sticky methode’. :expressionless:

++
Ph
http://hp.home.chez.tiscali.fr/re_illusion/index.htm