UV image
MikeD
Posts: 299
Hi all.
I am trying to get an image or pixmap of the current UV set for a selected material, throught a script. Any ideas?
Mike
Comments
You mean a template?
Yes, like making a template!
I think you can get the UVs from DzShape - unfortunately the docs for that are not currently available, so you may have to do a bit of guessing using discovery and the DS 3 scripting docs (and bear in mind that the change log has shown various changes). However, I'm not sure how easy it would be to then build the map.
i can retrieve all properties, methods and signals from the DzShape (and the parent Objects) from here....
Ok, I took them.... Let me see if I can get something usefull in here....
Thanks a lot for the response Richard... I' ll post the resaults....
No luck with DzShape....
I can take the UVsets from DzMaterial getActiveUVSet but it is just the vertex map containing the data for a UV set. The problem is to turn this UVSet into an image....
It should be a list of UV values, which are coordinates in ( [0,1] , [0,1] ). You'd have to figure out how to extract those, which in turn would probably require getting the list of vertices making up each polygon, and as I said i don't know how you'd then turn a list of lines into a map (if it's even possible). Assuming it actually possible to do the first part (get a list of edge coordinates in 2D-space) I wonder if it would be possible to generate a simple vector image format, which you could then open in a drawing app to get your template.
I managed to take the values of the map, but the image is not quite right. The image is made in DAZ with setPixel method. The image was initially inverted in Y axis ...
I will try to take the UVs from every vertice using facets, and make a connection between them.
The above code gave me the result in the attachment... (a test at one of my columns)!
Ok! The above code is a first approach but not the idial.
The correct approach is:
- Take the edges --> take the vertices (A and B) indexes and the facets (A and B) indexes of each edge
- Take the facets (A and B) by their indexes
- Find the Vertices (A and B) of the Facets (A and B) that belong to the specific edge
- Check their UV indexes
- If the UVs of the A vertex or the B vertex are not the same between the Facets than we have a discontinue, otherwise they are normal
- Collect the normal and discontinue vetrexes' UVs indexes in arrays
- Take the UVSet, as I did in the above code
-Make lines, using setPixel() method to an Image object and a lot of maths.
- Show the image
The result is awesome (attachment):
Now I have to figure out a way to see if a point of the image is in or out the UV islands...
Thanks for the code. You may also want to check mcasual's scripts:
https://www.daz3d.com/forums/discussion/13672/mcjtemplate-comes-to-daz-studio-4-5-updated-april-2017
https://sites.google.com/site/mcasualsdazscripts2/mcjtemplate
Nice work!
@MikeD:
I think I got it fairy good after some tweaking and finding a brilliant line drawing routine that I ported to DS, here.
Pretty nice Totte....
Guess I'm late to the party, but I thought you might want to consider what I did a while back. I started with mcjtemplate, but rather than outputting an image, I output SVG. When you open an SVG in Photoshop (or Gimp), it asks what you'd like the resolution to be. You do have to draw a bounding box around the image to make it play nice, but otherwise you get resolution independant UVs with no maths necessary for the drawing.
The Zip contains only the source SVG file.
Nice idea!