Texturing complex levels in blender

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Texturing complex levels in blender

Post by roxaz »

I know that we can easyly texture small objects by UV unwrapping and paiting individual texture. i dont think that its a good idea to texture level by UV unwrapping. maybe anyone could direct me the right way? I could find only this tutorial but it seems tu be outdated, current blender does not have "From window" mentioned there so tutorial is useless...
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

You have to construct your level using seperate blender objects, then apply textures via face select mode and selecting the image in the uv window. I made a script that does tiled uv's in the same way quakeradiant and deled do it.

Code: Select all

#    _____            ______  ____        ____             ______  ____      
#   /\  __`\  /'\_/`\/\  _  \/\  _`\     /\  _`\   /'\_/`\/\  _  \/\  _`\    
#   \ \ \/\ \/\      \ \ \L\ \ \ \L\ \   \ \ \L\_\/\      \ \ \L\ \ \ \/\ \  
#    \ \ \ \ \ \ \__\ \ \  __ \ \ ,  /    \ \  _\L\ \ \__\ \ \  __ \ \ \ \ \ 
#     \ \ \_\ \ \ \_/\ \ \ \/\ \ \ \\ \    \ \ \L\ \ \ \_/\ \ \ \/\ \ \ \_\ \
#      \ \_____\ \_\\ \_\ \_\ \_\ \_\ \_\   \ \____/\ \_\\ \_\ \_\ \_\ \____/
#       \/_____/\/_/ \/_/\/_/\/_/\/_/\/ /    \/___/  \/_/ \/_/\/_/\/_/\/___/ 
#                                       PRESENTS
#                                      AUTOMAPUV
#a UV'er useful for map makers this automatically UV's boxes/brushes/planes/ in the same style as quark,deled,radiant
#I hope this will help game devlopers and mappers
#it should run out of the box but use the overrides for tweaking
#This script is works even if transforms are done in edit mode or object mode
#APPLY SCRIPT AFTER ALL THE MODELLING/COMPLEX UV`ING/SCALING IS DONE
#ALT-P to run
#please give critics as i hope to devlop this further


overrideX=1
overrideY=1
overrideZ=1

import Blender
import math
from Blender import NMesh, Material, Window

editmode = Window.EditMode()    # are we in edit mode?  If so ...
if editmode: Window.EditMode(0) # leave edit mode before getting the mesh

FactorX=1
FactorY=1

object = Blender.Object.GetSelected()[0]
me=object.getData()
for f in me.faces:               # loop the list of faces

#The uv calculation depends which way the face is facing so we have to use normals to find out
#we are only interested in the axsis so we do ^2 then sqrt so the normals is always postive	
  normalZ=math.sqrt(f.no[2]*f.no[2])
  normalY=math.sqrt(f.no[1]*f.no[1])
  normalX=math.sqrt(f.no[0]*f.no[0])

######################################################
#ok here we see if the faces are mainly facing up/down 
  if normalZ>normalY and normalZ>normalX:
	print "cycle"
	
	#seems the vertex ordering depends on the normals so we have to add extra checks
	xdist1=0
	xdist2=0
	
	if(f.no[2]>0):
		#length of top edge
		xdist1=(f.v[0].co.x*object.SizeX*overrideX)-(f.v[1].co.x*object.SizeX*overrideX)
		xdist1=math.sqrt(xdist1*xdist1)
		#print xdist1
		#length of lower edge
		xdist2=(f.v[2].co.x*object.SizeX*overrideX)-(f.v[3].co.x*object.SizeX*overrideX)
		xdist2=math.sqrt(xdist2*xdist2)
		#print xdist2
		
	if(f.no[2]<0):
		#length of top edge
		xdist1=(f.v[0].co.x*object.SizeX*overrideX)-(f.v[2].co.x*object.SizeX*overrideX)
		xdist1=math.sqrt(xdist1*xdist1)
		#print xdist1
		#length of lower edge
		xdist2=(f.v[1].co.x*object.SizeX*overrideX)-(f.v[3].co.x*object.SizeX*overrideX)
		xdist2=math.sqrt(xdist2*xdist2)
		#print xdist2
	
	
	
	#seems the vertex ordering depends on the normals so we have to add extra checks
	ydist1=0
	ydist2=0
	
	if(f.no[2]>0):
		print "above"
		#length of top edge
		ydist1=(f.v[0].co.y*object.SizeY*overrideY)-(f.v[2].co.y*object.SizeY*overrideY)
		ydist1=math.sqrt(ydist1*ydist1)
		#print ydist1
		#length of lower edge
		ydist2=(f.v[1].co.y*object.SizeY*overrideY)-(f.v[3].co.y*object.SizeY*overrideY)
		ydist2=math.sqrt(ydist2*ydist2)
		#print ydist2
		
	if(f.no[2]<0):
		print "below"
		#length of top edge
		ydist1=(f.v[0].co.y*object.SizeY*overrideY)-(f.v[1].co.y*object.SizeY*overrideY)
		ydist1=math.sqrt(ydist1*ydist1)
		print ydist1
		#length of lower edge
		ydist2=(f.v[2].co.y*object.SizeY*overrideY)-(f.v[3].co.y*object.SizeY*overrideY)
		ydist2=math.sqrt(ydist2*ydist2)
		print ydist2
	

	
	if(f.no[2]<0):
		f.uv = [(f.uv[0][0]*xdist1,f.uv[0][1]*ydist1),(f.uv[1][0]*xdist1,f.uv[1][1]*ydist1),(f.uv[2][0]*xdist2,f.uv[2][1]*ydist2),(f.uv[3][0]*xdist2,f.uv[3][1]*ydist2)]	
	
	if(f.no[2]>0):
		f.uv = [(f.uv[0][0]*ydist2,f.uv[0][1]*xdist2),(f.uv[1][0]*ydist2,f.uv[1][1]*xdist2),(f.uv[2][0]*ydist1,f.uv[2][1]*xdist1),(f.uv[3][0]*ydist1,f.uv[3][1]*xdist1)]	
###############################################

######################################################
#ok here we see if the faces are mainly facing up*down 
  if normalY>normalZ and normalY>normalX:
	print "cycle"
	
	#seems the vertex ordering depends on the normals so we have to add extra checks
	xdist1=0
	xdist2=0
	
	if(f.no[1]>0):
		#length of top edge
		xdist1=(f.v[0].co.x*object.SizeX*overrideX)-(f.v[2].co.x*object.SizeX*overrideX)
		xdist1=math.sqrt(xdist1*xdist1)
		print xdist1
		#length of lower edge
		xdist2=(f.v[1].co.x*object.SizeX*overrideX)-(f.v[3].co.x*object.SizeX*overrideX)
		xdist2=math.sqrt(xdist2*xdist2)
		print xdist2
		
	if(f.no[1]<0):
		#length of top edge
		xdist1=(f.v[0].co.x*object.SizeX*overrideX)-(f.v[2].co.x*object.SizeX*overrideX)
		xdist1=math.sqrt(xdist1*xdist1)
		print xdist1
		#length of lower edge
		xdist2=(f.v[1].co.x*object.SizeX*overrideX)-(f.v[3].co.x*object.SizeX*overrideX)
		xdist2=math.sqrt(xdist2*xdist2)
		print xdist2
	
	
	
	#seems the vertex ordering depends on the normals so we have to add extra checks
	zdist1=0
	zdist2=0
	
	if(f.no[1]>0):
		print "above"
		#length of top edge
		zdist1=(f.v[0].co.z*object.SizeZ*overrideZ)-(f.v[2].co.z*object.SizeZ*overrideZ)
		zdist1=math.sqrt(zdist1*zdist1)
		print zdist1
		#length of lower edge
		zdist2=(f.v[1].co.z*object.SizeZ*overrideZ)-(f.v[3].co.z*object.SizeZ*overrideZ)
		zdist2=math.sqrt(zdist2*zdist2)
		print zdist2
		
	if(f.no[1]<0):
		print "below"
		#length of top edge
		zdist1=(f.v[0].co.z*object.SizeZ*overrideZ)-(f.v[1].co.z*object.SizeZ*overrideZ)
		zdist1=math.sqrt(zdist1*zdist1)
		print zdist1
		#length of lower edge
		zdist2=(f.v[2].co.z*object.SizeZ*overrideZ)-(f.v[3].co.z*object.SizeZ*overrideZ)
		zdist2=math.sqrt(zdist2*zdist2)
		print zdist2
	

	
	if(f.no[1]<0):
		f.uv = [(f.uv[0][0]*xdist1,f.uv[0][1]*zdist1),(f.uv[1][0]*xdist1,f.uv[1][1]*zdist1),(f.uv[2][0]*xdist2,f.uv[2][1]*zdist2),(f.uv[3][0]*xdist2,f.uv[3][1]*zdist2)]	
	
	if(f.no[1]>0):
		f.uv = [(f.uv[0][0]*xdist2,f.uv[0][1]*zdist2),(f.uv[1][0]*xdist2,f.uv[1][1]*zdist2),(f.uv[2][0]*xdist1,f.uv[2][1]*zdist1),(f.uv[3][0]*xdist1,f.uv[3][1]*zdist1)]

######################################################
#ok here we see if the faces are mainly facing up*down 
  if normalX>normalZ and normalX>normalY:
	print "cycle"
	
	#seems the vertex ordering depends on the normals so we have to add extra checks
	ydist1=0
	ydist2=0
	
	if(f.no[0]>0):
		#length of top edge
		ydist1=(f.v[0].co.y*object.SizeY*overrideY)-(f.v[2].co.y*object.SizeY*overrideY)
		ydist1=math.sqrt(ydist1*ydist1)
		print ydist1
		#length of lower edge
		ydist2=(f.v[1].co.y*object.SizeY*overrideY)-(f.v[3].co.y*object.SizeY*overrideY)
		ydist2=math.sqrt(ydist2*ydist2)
		print ydist2
		
	if(f.no[0]<0):
		#length of top edge
		ydist1=(f.v[0].co.y*object.SizeY*overrideY)-(f.v[2].co.y*object.SizeY*overrideY)
		ydist1=math.sqrt(ydist1*ydist1)
		print ydist1
		#length of lower edge
		ydist2=(f.v[1].co.y*object.SizeY*overrideY)-(f.v[3].co.y*object.SizeY*overrideY)
		ydist2=math.sqrt(ydist2*ydist2)
		print ydist2
	
	
	
	#seems the vertex ordering depends on the normals so we have to add extra checks
	zdist1=0
	zdist2=0
	
	if(f.no[0]>0):
		print "above"
		#length of top edge
		zdist1=(f.v[0].co.z*object.SizeZ*overrideZ)-(f.v[2].co.z*object.SizeZ*overrideZ)
		zdist1=math.sqrt(zdist1*zdist1)
		print zdist1
		#length of lower edge
		zdist2=(f.v[1].co.z*object.SizeZ*overrideZ)-(f.v[3].co.z*object.SizeZ*overrideZ)
		zdist2=math.sqrt(zdist2*zdist2)
		print zdist2
		
	if(f.no[0]<0):
		print "below"
		#length of top edge
		zdist1=(f.v[0].co.z*object.SizeZ*overrideZ)-(f.v[1].co.z*object.SizeZ*overrideZ)
		zdist1=math.sqrt(zdist1*zdist1)
		print zdist1
		#length of lower edge
		zdist2=(f.v[2].co.z*object.SizeZ*overrideZ)-(f.v[3].co.z*object.SizeZ*overrideZ)
		zdist2=math.sqrt(zdist2*zdist2)
		print zdist2
	

	
	if(f.no[1]<0):
		f.uv = [(f.uv[0][0]*ydist1,f.uv[0][1]*zdist1),(f.uv[1][0]*ydist1,f.uv[1][1]*zdist1),(f.uv[2][0]*ydist2,f.uv[2][1]*zdist2),(f.uv[3][0]*ydist2,f.uv[3][1]*zdist2)]	
	
	if(f.no[1]>0):
		f.uv = [(f.uv[0][0]*ydist2,f.uv[0][1]*zdist2),(f.uv[1][0]*ydist2,f.uv[1][1]*zdist2),(f.uv[2][0]*ydist1,f.uv[2][1]*zdist1),(f.uv[3][0]*ydist1,f.uv[3][1]*zdist1)]
################################################	
  #f.uv = [(f.uv[0][0]*object.SizeY*overrideY*Factory,f.uv[0][1]*object.SizeZ*overrideZ*FactorY),(f.uv[1][0]*object.SizeY*overrideY*Factory,f.uv[1][1]*object.SizeZ*overrideZ*FactorY),(f.uv[2][0]*object.SizeY*overrideY*Factory,f.uv[2][1]*object.SizeZ*overrideZ*FactorY),(f.uv[3][0]*object.SizeY*overrideY*Factory,f.uv[3][1]*object.SizeZ*overrideZ*FactorY)]
  
me.update()                      # update the real mesh in Blender

if editmode: Window.EditMode(1)  # optional, just being nice
use alt p to runthe script
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

hehehehe, the perfect situation to display your script Omar! ;)
Is this an updated version? Anything new compared to the one posted before?

regards,
Alvaro
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Hehe, sorry about how it broke the formatting, my host has been down so you cant get the script from the old thread.

No its just the same :cry: .

Btw this tool is only useful if you want tiled textures, since most of blender's uv tools keep the uv coords normalised.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

it works a bit... :) when i mapped my texture it was like this:
Image
bricks were shown not propertly so i turned everything in uv editor. it worked but texture was streched. so far so good, time to use script. after i execured script i saw this:
ImageImage
what i am doing wrong?
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

If the script errored mid execution it might do that.
Check your console in blender for errors, python is very strict when it comes to indents so maybe copyingand pasting ruined some of the formatting.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

output:
cycle
above
cycle
0.140519857407
0.298681020737
below
0.0381548404694
0.0381548404694
cycle
0.298681020737
0.140519857407
above
0.444022417068
0.520332574844
cycle
below
0.100205183029
0.100205183029
no syntax errors...
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

UV wrapping is always the way to go that's what everyone does no matter how complex a level is. That's why people say it isn't a cake walk making 3D games. To make something as beatiful as Halo 3 you have to UV wrap it. You are going to need time, frustration, sweat, and hard work, but if you do it right the payoffs will be amazing.
TheQuestion = 2B || !2B
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

not necessarily, i can map textures to faces while not unwrapping all faces to one big texture. thats the easy way :)
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

something bad is happening! When i load my scene with irrlicht i see this:
Image
but it looks normal in blender and mviewer:
ImageImage
First i thought that it was scaling problem but model do not react to scaling. Im using this x exporter. Anyone? Suggestions? :)
Halifax
Posts: 1424
Joined: Sun Apr 29, 2007 10:40 pm
Location: $9D95

Post by Halifax »

I didn't say unwrap it all with just one huge texture. I am saying cut it into small pieces and texture those as if they were there own object in there own scene but they are all coming back to one theme or whatever. This is how I usually do my levels.
TheQuestion = 2B || !2B
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

sorry, i misunderstood you :)
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

Is that something going to become some kind of "dungeon only" game? I'd try to split the map into "tiles" then. So you'll end up getting tiles with an size of 1x1x2 containing either floor only, or floor and wall on one side, floor and wall on two sides, etc.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Post by roxaz »

it is not going to be a game :lol: im just learning ;)

EDIT:
someone, check this out. mwiever says that it is ok but irrlicht shows complete mess. normals inverted, scene flipped, exporter dont react to scaling... and i managed to get map in one peace just when i joined all objects in blender. separate objects can not be exported to x i gues...
Post Reply