Jorge, I didn’t think it would take just 2 lines of code Thank you soo much!
Jorge, I have just found a limitation for our script. I wanted to have the possibility to exclude faces with certain Ids from applying UV. In my case now I have pF array where pF[1] is with clusters and pF[2] with ID for every cluster.
the next code is deleting those clusters from pF[2] which have ID 6:
excludeID = 6
if (polyOp.getFaceMatID node iFace) == excludeID then
(
while ((local index = findItem pF[2] excludeID) > 0 ) do
(
deleteItem pF[1] index
deleteItem pF[2] index
)
)
ApplyPlanarMapping node pF[1]
Here is what I get when the face with ID 6 is excluded from pF[1], however before applying the function, the texture on it was not distorted. It’s happening only when it’s applying UV to adjacent faces:
Mike, do you have an .OBJ of that model so I can try it out?
No need for textures or materials, just the same model as .OBJ if possible.
Thank you.
Jorge, here is it!
Try to exclude the same face from elements array no matter how. Thank you, Jorge for your efforts. I really need it.
convert this model to editable poly and apply the same function with just these changes:
fn ApplyPlanarMapping node elements channel:1 flipU:false flipV:false =
(
elements[3]-=#{4}
elements[4]-=#{5}
polyop.setmapsupport node channel true
.....
I am not sure to be understanding the idea.
What you want is to apply a planar map to “some” of the faces of a given element?
What should happened to the remaining faces in that element, do they already have a mapping and you need to keep it?
Yea Jorge. You got the point. They have a mapping and we need to keep it.
OK, I believe this should work.
The function now expects an array or arbitraries bitarrays of faces, similar to the previous one.
Each array does not need to contain the whole element faces but just the ones you need to map.
So if you have an element with faces #{1..32} with faces #{1..10} using ID1, #{11..20} ID2 and #{21..32} ID3, and you want to apply the mapping just to the ID2, you only need to pass the #{11..20} array in the elements parameter.
For example, for the .OBJ you uploaded the following applies a planar mapping to faces 4 and 5 only:
ApplyPlanarMapping $ #(#{4..5})
On the other hand the following code will apply two planar mapping, one to face 4 and one to face 5:
ApplyPlanarMapping $ #(#{4}, #{5})
You could easily modify the function to have another parameter "excludeMatID", pass the whole elements faces and do the MatID sorting inside the function or you can leave it as it is and split the faces bitarrays before. I didn't implement the MatID sorting inside so it could be used in general situations.
Please let me know if this works, as I have barely tested it just with the model you provided.
(
/*
This function applies a normalized planar mapping to a given
set of faces passed as array of bitarrays. Works for Editable Poly
but can easily be modified to work with meshes.
node : The object
elements: #( #{faces}, #{faces} )
flipU : Flip the mapping in U direction
flipV : Flip the mapping in V direction
*/
fn ApplyPlanarMapping node elements channel:1 flipU:false flipV:false =
(
lastvert = node.mesh.numfaces*3
polyop.setmapsupport node channel true
polyop.setnummapverts node channel (lastvert*2) keep:true
for cluster in elements do
(
clusterNormal = [0,0,0]
for f in cluster do clusterNormal += polyop.getfacenormal node f
clusterNormal = normalize clusterNormal
clusterverts = (polyop.getvertsusingface node cluster) as array
mt = matrixfromnormal clusterNormal
if flipU do mt.row1 *= -1
if flipV do mt.row2 *= -1
in coordsys mt
(
minx = 1E10
maxx = -1E10
miny = 1E10
maxY = -1E10
mapverts = for v in clusterverts collect
(
vpos = polyop.getvert node v
if vpos.x < minx do minx = vpos.x
if vpos.x > maxx do maxx = vpos.x
if vpos.y < miny do miny = vpos.y
if vpos.y > maxy do maxy = vpos.y
vpos
)
maxside = amax #(maxx-minx, maxy-miny)
cmin = [minx, miny, 0]
c = lastvert
for v in mapverts do
(
vpos = (v-cmin)/maxside
polyop.setmapvert node channel (c+=1) vpos
)
for f in cluster do
(
faceverts = polyop.getfaceverts node f
verts = for v in faceverts collect
(
found = finditem clusterverts v
found += lastvert
)
polyop.setmapface node channel f verts
)
)
lastvert += clusterverts.count
)
node.deleteisomapverts()
completeredraw()
)
)
This approach is much better but still not finished:
Try to apply this to the same model:
ApplyPlanarMapping $ #(#{1…2},#{3},#{5},#{6…7},#{8},#{9},#{10},#{11…12})
that means we apply UV to all faces except the face 4. In my case after this, the face 4 gets distorted.
If I apply ApplyPlanarMapping $ #(#{4…5}) then faces 4 and 5 become mapped well, but faces 1 and 2 become distorted.
and then try ApplyPlanarMapping $ #(#{4})
Please try at you – do you get the same? Try these 3 lines to see the difference!
Trust me, I did test the function before posting and it was working well. However I didn’t try to run it twice on the same model with different faces. Now I see there is a bug there and it seems to be related to the isolated map vertices not being removed.
Besides that, what is this line doing in the function?
polyop.deleteisoverts node
Awful mistake I made and it survived several posts!
It does nothing and has nothing to do with the mapping. Used to work with meshes, I just mislead it.
I have updated the function. Please try it and let me know if it is working now.
[font=Wingdings][/font]
Are you receiveing email notifications? Because I am not since yesterday.