Page 1 of 1

Accessing UV Islands

Posted: 14 Oct 2017, 16:32
by homam
Hi,

Is there someway to get a list of UV islands through any scripting/complied language in XSI?

We can select islands easily from the UV editor UI but I don't know why this feature is not exposed to the SDK :-\

Thanks!

Re: Accessing UV Islands

Posted: 14 Oct 2017, 16:49
by rray
Hi Homam,

I think the texture editor might just be looking for polygons that are connected by their uv's each time. It should be a quick lookup, maybe it's using a UV->polygon lookup table, then it's even faster.

I've got this compound which initializes an attribute per node that you can read to get a polygon island id. (Set the checkmark to use its 'uv' mode)

Re: Accessing UV Islands

Posted: 16 Oct 2017, 00:28
by homam
Thanks rray! your ICE compound does the trick.

Re: Accessing UV Islands

Posted: 16 Oct 2017, 19:36
by rray
Good to hear it works with that :-!

Re: Accessing UV Islands

Posted: 19 Oct 2017, 11:39
by myara
Sorry, how do I use this compound ?

Re: Accessing UV Islands

Posted: 19 Oct 2017, 23:50
by rray
It sets an Attribute NodeIslandID,
you can use it to detect the island of a sample/node like this

Code: Select all

var selected_samples = Selection(0);
var selected_samples_coll = selected_samples.SubComponent.ComponentCollection;
var selected_obj = selected_samples.SubComponent.Parent3DObject;
var ICEAttr = selected_obj.ActivePrimitive.Geometry.GetICEAttributeFromName("NodeIslandID");
var ICEAttr_array = new VBArray( ICEAttr.DataArray ).toArray();

var oldAlwaysEvaluated = ICEAttr.AlwaysEvaluated;
ICEAttr.AlwaysEvaluated = true;  // forces evaluation of attribute

for(i=0; i<selected_samples_coll.Count; i++)
	logmessage("Selected Sample "+selected_samples_coll(i).Index+" is on island "+  ICEAttr_array[selected_samples_coll(i).Index]);
	
ICEAttr.AlwaysEvaluated = oldAlwaysEvaluated;

Re: Accessing UV Islands

Posted: 23 Oct 2017, 12:23
by myara
Thanks for the code !

I've found my problem.
The XSI Man I was using as a test has it's Texture Projection named 'UV' so the compound was red and didn't give me the results I expected.

I was using a recursive function to get islands, but it was pretty slow. Your ICE solution seems to be the solution. With this I may be able to reproduce a tool I wrote in Maya to check the distance between islands to avoid bleeding when using mipmapping. I wish I was more "fluent" in ICE...

Thanks again

Re: Accessing UV Islands

Posted: 23 Oct 2017, 14:53
by rray
You're welcome! Yes would've been useful to have a "get main UV" node in ICE for the main UV instead of having to select a specific one by name.

If it's applied in scripting there's at least a chance to set it inside the compound.

Re: Accessing UV Islands

Posted: 26 Oct 2017, 16:54
by myara
I'm using your compound and it works perfect ! Can i use it in my plugin (mTextureEditor) ?

I wanted to use it for UV borders too, but it doesn't work well for that when the UV island are overlapped and folded in the middle like a XSI man head, sadly.
I guess I'll have to script something because I have no idea how to do it in ICE :D

Re: Accessing UV Islands

Posted: 26 Oct 2017, 17:36
by rray
Great! Feel free to use it!

About uv mode, the compound would have to check each edge if its neighbor uv polygons are on the same side of the edge.
It's tricky however finding the exact meaning of "same side" (considering weird formed polygons) :)
Do you think checking the uv polygon centers is enough?

Re: Accessing UV Islands

Posted: 27 Oct 2017, 05:37
by myara
I wouldn't mind if it doesn't support bad geometry or broken UVs. I was thinking in taking just one point of the neighbour polygon uv coordinates and triangulate with the edge, but centers would probably be better.

Re: Accessing UV Islands

Posted: 27 Oct 2017, 17:05
by rray
Center turned out to be not so great because the polygon center can easily move on the other side of the edge if it's a 4+ sided polygon. I think testing 2 points very close to the edge and check if they're inside the 2 uv polygons is better

I'll try to put together a new compound tonight.

Image
(The house shaped part in the bottom right became it's own island because the center of the polyon above it is below the roof...)

Re: Accessing UV Islands

Posted: 27 Oct 2017, 22:05
by rray
Image

There's a new tolerance settings that can deal with little errors in the uvs:
Image

Re: Accessing UV Islands

Posted: 28 Oct 2017, 05:25
by myara
awesome I’ll try it as soon as I can ! thanks !