Save UV Face Layout gaps


(Bobson) #1

When I export my UV layout to an image file, using the UV_export.py(“Save UV Face Layout”) script.

It exports fine, but there are all these 1 pixel gaps in the lines all of the place.

Here’s a simple plane that has been exported to .jpg file(I’ve marked the gaps)…

http://img.photobucket.com/albums/v107/bobson-uk-/Plane.jpg

Please could someone tell me how to edit the uv_export.py script to remove all these gaps.

Thanks… :smiley:


(macouno) #2

yeah I’ve noticed this as well… is it always in the middle of the line? With non horizontal/vertical lines as well?

You’d think perhaps it’s just a > where it should be a >= or something.

It’s hard to tell since the script isn’t commented at all.

Maybe you should bug theeth about it, he wrote it after all, and his mail’s in the script as well. :wink:


(theeth) #3

This script is long due for a rewrite. Hopefully, I’ll get some time for that soonish.

Martin


(tedi) #4

why not make it a native ‘export’ option, from UV-vindow?


(JA-forreal) #5

I was wondering if any “updates” to this script could possibly include using the mesh that is associated to an assigned selected material. Then the exported uv map could have the same name as the selected material… Just thinking out loud…


(theeth) #6

I’m sorry, I didn’t quite get that… :-?

Martin


(z3r0 d) #7

it looks like a rounding error

… I can’t quite understand your approach though, so I wouldn’t know where to point out the error


(macouno) #8

I think he means he’d rather have the image name contain the current object’s material’s name than the object name.

I had another look as well, and it seems to happen at all sorts of different points along the edge. But only once per edge.

To me it looks like there might be an issue somewhere in this bit of the code:

			step = int(size*sqrt((co1[0]-co2[0])**2+(co1[1]-co2[1])**2))
			if step:
				for t in range(step + 1):
					x = int((co1[0] + t*(co2[0]-co1[0])/step) * size)
					y = int((co1[1] + t*(co2[1]-co1[1])/step) * size)

					if bWrap.val:
						x = x % wrapSize
						y = y % wrapSize
					else:
						x = int ((x - minx) * scale)
						y = int ((y - miny) * scale)
						
					co = x * 3 + y * 3 * size

Perhaps in either:

step = int(size*sqrt((co1[0]-co2[0])**2+(co1[1]-co2[1])**2))
x = int((co1[0] + t*(co2[0]-co1[0])/step) * size)

I forgot but perhaps rounding the values up or down before making them an int would help?

I think this script also makes a good case to perhaps make commenting your code a requirement before inclusion in blender releases?


(Bobson) #9

I did this…

step = round(size*sqrt((co1[0]-co2[0])**2+(co1[1]-co2[1])**2))

I get this warning message, but it still creates my image file with no gaps.

C:\Program Files\Blender Foundation\Blender\blender.exe:243: DeprecationWarning: integer argument expected, got float

(macouno) #10

yah it needs an int… a float is basicly a different type of variable than an int… say a float is 1.6 and you do a round, the result is a float of 2.0

So you’d need

step = int(round(size*sqrt((co1[0]-co2[0])**2+(co1[1]-co2[1])**2)))

But since an int is a rounded nr… the result of this is pretty much the same as without the round function. I’m afraid it’s not that simple :wink:


(Bobson) #11
step = int(round(size*sqrt((co1[0]-co2[0])**2+(co1[1]-co2[1])**2)))

Works great, no gaps, no errors and all the lines are 1 pixel wide.

Thanks macouno :smiley:

…now just to work out how to change it so all the lines are black instead of red.


(macouno) #12

Well that’s just the rgb color.

try replacing this bit:

					img[co] = 0
					img[co+1] = 0
					img[co+2] = 255
					if wsize > 1:
						for x in range(-1*wsize + 1,wsize):
							for y in range(-1*wsize,wsize):
								img[co + 3 * x + y * 3 * size] = 0
								img[co + 3 * x + y * 3 * size +1] = 0
								img[co + 3 * x + y * 3 * size +2] = 255

with this bit:

					img[co] = 0
					img[co+1] = 0
					img[co+2] = 0
					if wsize > 1:
						for x in range(-1*wsize + 1,wsize):
							for y in range(-1*wsize,wsize):
								img[co + 3 * x + y * 3 * size] = 0
								img[co + 3 * x + y * 3 * size +1] = 0
								img[co + 3 * x + y * 3 * size +2] = 0

haven’t tested it… all I did was change the 3rd img[] color (red) from 255 to 0


(macouno) #13

Did a test and the color thing works fine… it didn’t solve the gaps completely though.

Here’s a new bit of the script to try:


			step = int(ceil(size*sqrt((co1[0]-co2[0])**2+(co1[1]-co2[1])**2)))
			if step:
				for t in range(step):
					x = int(floor((co1[0] + t*(co2[0]-co1[0])/step) * size))
					y = int(floor((co1[1] + t*(co2[1]-co1[1])/step) * size))

					if bWrap.val:
						x = x % wrapSize
						y = y % wrapSize
					else:
						x = int ((x - minx) * scale)
						y = int ((y - miny) * scale)
						
					co = x * 3 + y * 3 * size;
					
					img[co] = 0
					img[co+1] = 0
					img[co+2] = 0
					if wsize > 1:
						for x in range(-1*wsize + 1,wsize):
							for y in range(-1*wsize,wsize):
								img[co + 3 * x + y * 3 * size] = 0
								img[co + 3 * x + y * 3 * size +1] = 0
								img[co + 3 * x + y * 3 * size +2] = 0
	
		for v in f:
			x = int(v[0] * size)
			y = int(v[1] * size)

			if bWrap.val:
				x = x % wrapSize
				y = y % wrapSize
			else:
				x = int ((x - minx) * scale)
				y = int ((y - miny) * scale)

			co = x * 3 + y * 3 * size
			img[co] = 0
			img[co+1] = 0
			img[co+2] = 255


Ok I updated this post a few times now.

Just a round didn’t fix it… you had to either round up or down. Rounding up worked fine but didn’t line up with the “verts”.

We had to round down and not the step value but the x and y coords.

Also in this version the lines are black and the vert points red.

My result is quite perfect now, even with complex meshes, uv layouts.


(JA-forreal) #14

I was talking about extracting the uv face output data from the mesh based on it’s assigned material name. For any mesh or group of meshes that are assigned a material this uv face script would use this material assignment as a basis for output. Maybe this can’t be done.

It would be so much easier for objects with multiple materials and uv maps. It would be even cooler if we could select an object, call up the uv face script and select a material from a drop down tab. It would be “sick” if we could dump the complete list of uv maps from all of the materials out to a file.

I was even hoping one day to see this script output a gimp or photoshop image file ready for layering.


(macouno) #15

all of that is very possible, but I doubt its of as much use to everybody as it may be to you.

Since it’s not too complicated you may consider coding it yourself.


(Bobson) #16

Great work macouno, just added your bit of the script to the uv_export.py and it makes a great looking uvmap image file.

No gaps or errors, I’ve edited it a small bit so all the lines are black, I just like my uvmaps like that.

Thanks so much for everyones help with this.

:smiley:


(JA-forreal) #17

Yeah, I’m working with c++ basics now getting my skills on for renderman shader coding and what not. I’ve been delaying the coding but I will try to to stick with it.