PDA

View Full Version : HCE Using maxscript to weld mid-edge vertices to the nearest vertex of the same face?



sanni
September 21st, 2011, 01:59 PM
Hi,

If you have a look at image (1+2) you can see the problem.

http://img7.imagebanana.com/img/e9xvm691/thumb/Unbenannt.PNG (http://img7.imagebanana.com/img/e9xvm691/Unbenannt.PNG)

The vertex that connects the blue, black and green faces intersects the edge of the red face. Tool doesn't like that "special" kind of vertex. :ugh:

To fix that you can either weld the "special" vertex with another one like in image (3) or split the red face into 3 that that all share our special vertex. :woop:
But here comes the twist, what if you have hundreds of such "special" vertices? As an example if you import geometry from other games like Goldeneye 64 this happens alot.

Is there any automated variant to manually fixing all the vertices? Like a max script or so?

Here is another prime example of the problem:
2376

I have found this script that with a few alteration could work, problem is I don't understand maxscript good enough:

How do I remove mid-edge EPoly Vertices?



MAXScript Frequently Asked Questions (http://www.cgplusplus.com/online-reference/maxscript-reference/source/frequently_asked_questions.htm)





A user asked:



I want to filter the edge selection and create arrays containing connected edges, something like "edge selection elements". Edges from two arrays will never be connected, in other words will not share vertices.





Answer:



The following code implements a possible solution:







Script:








macroScript KillMidEdgeVerts category:"MXS Help"







(







--make sure a single EPoly object is selected







on isEnabled return selection.count == 1 and classof selection[1].baseobject == Editable_Poly







on execute do







(







thePoly = selection[1] --get the selected object







select thePoly --select it







max modify mode --switch to modify panel







--set the base object as current level:







modPanel.setCurrentObject selection[1].baseobject







subObjectLevel = 1 --set sub-*object level to vertex level







numVerts = (polyop.getNumVerts thePoly) --get the total vertex count







undo on "KillMidEdgeVerts" --enable undo context







(







--loop backwards from the last to the first vertex







for v = numVerts to 1 by -1 do







(







--get the edges using the vertex to check the count







nVerts = (polyop.getEdgesUsingVert thePoly v) as array







if nVerts.count == 2 do --if only two edges found, then







(







--get the verts of the first egde







edge1verts = (polyop.getVertsUsingEdge thePoly nVerts[1]) as array







--calculate the vector defined by the two vertices in the first edge







vector1 = (polyop.getVert thePoly edge1verts[1]) - (polyop.getVert thePoly edge1verts[2])







--get the verts of the second edge







edge2verts = (polyop.getVertsUsingEdge thePoly nVerts[2] as array)







--calculate the vector defined by the two vertices in the second edge







vector2 = (polyop.getVert thePoly edge2verts[1]) - (polyop.getVert thePoly edge2verts[2])







--calculate the angle between the two normalized vectors







angle = acos (dot (normalize vector1) (normalize vector2))







--if the angle is less than the threashold (change 0.01 to whatever threashold you want!)







if angle < 0.01 do







(







select thePoly.verts[v] --then select the current vertex







thePoly.EditablePoly.buttonOp #Remove --and hit the remove button







)







)--end if







)--end v loop







)--end undo







)--end on







)--end macro















Thank you very much :iamafag:

Siliconmaster
September 21st, 2011, 07:54 PM
Hmm, those errors do suck, but I don't know if anyone has ever found a way to fix them automatically. You might be stuck doing it by hand. Tedious, but worth it in the long run.

Donut
September 21st, 2011, 08:04 PM
i dont quite follow. is the situation that you have what LOOKS like 3 edges going to one vertex, but on the technical side its only actually connected to 2 of the 3 edges?

i guess you could try selecting all the vertices (im talking ctrl+a), using the weld tool, and setting the weld threshold really low. i dont know what the issue is, but if its what i think it is, this may help. keep track of the vertex count before and after the weld to see if anything changed.

Siliconmaster
September 21st, 2011, 08:11 PM
My understanding is that it was essentially a "T" intersection error, where there is one long edge (red in the picture), and two shorter edges (green and black) joining in the middle with a single vertex. It looks fine, but tool will bitch at you, and upon further notice you realize that the single long edge isn't connected at all to the middle vertex, resulting in an open edge error. As sanni tried to describe, the only solutions are to get rid of the vertex via welding or whatnot (as in figure 3), or to split the long edge (and as a result the face attached to it) so it has a corresponding vertex in the same place (seen in figure 4). That kind of fix can't be done automatically, since it requires so many manual steps, not just a weld. The very concept of a weld is actually useless due to the fact that the long edge has no vertex to weld to.

Amirite?

sanni
September 22nd, 2011, 08:10 AM
Yes exactly =)

I spend 3 hours yesterday just fixing those kind of errors. You can't weld them automaticly because the threshold required to do so would also weld a lot if not all of your more detailed geometry together.

I was thinking that 3ds Max could spot those erros by just counting how many lines/edges a vertex is connected to. If it is less than 4, then it is one of those "special" vertices. Then it could just weld it to the nearest neighbour that shares the same plane.


Example:

If you have a look at the 3 vertices in the first picture, the left one has six lines/edges connected to it. So it is a "good" vertex. The vertex on the far right also has 5 lines/edges connected so it's "good" too.

But the vertex in the middle has only two(which is less than 4) lines/edges connected to it since the horizontal line(which is red in picture 2) is actually not connected to it at all.
So now 3ds Max looks if any vertices in the neighbourhood share the same plane as the middle vertex. The middle vertex is connected to the black, blue and green plane. So now it compares all the vertices of the 3 planes with our middle vertex and sees that the vertex on the left is the closest so it welds the two vertices together.

Now the problem is how do I teach 3ds Max this?

neuro
September 23rd, 2011, 04:12 AM
simple fix.
move the middle vert up.

it's a stupid stupid thing to have several verts on the EXACT SAME AXIS, because ingame it'l triangulate everything.
if you have polygons like that, you need to cut your faces.

what tool is trying to do is cut a triangle between those 3 verts on the same edge, giving you a triangle with mathematical 0-surface area, which breaks the game.
that's all that error is.
it's got nothing to do with a very only having 2 edges (though that's usually a tell-tale sign of this type of error)

you dont need to teach max a damn thing, you need to teach yourself to cut your damn faces :P

neuro
September 23rd, 2011, 04:13 AM
i guess you could try selecting all the vertices (im talking ctrl+a), using the weld tool, and setting the weld threshold really low. i dont know what the issue is, but if its what i think it is, this may help. keep track of the vertex count before and after the weld to see if anything changed.

NO NO NO NO NEVER EVER EVER DONT NO FUCKING SHIT NO NOT DO THAT EVER FUCKING NO

sanni
September 23rd, 2011, 07:32 AM
you need to teach yourself to cut your damn faces :P

Nonono, not my faces. See:
http://img6.imagebanana.com/img/kkx7558r/dam.PNG
1) Goldeneye 64
2) Goldeneye Setup Editor
3) 3ds Max
4) Halo

You can blame Rare for being lazy when they created Goldeneye back then :P

If only Maxscript weren't so complicated.:raise:

neuro
September 23rd, 2011, 09:25 AM
it depsnt matter whose faces they are, you gotta cut them bitches

Donut
September 23rd, 2011, 05:27 PM
NO NO NO NO NEVER EVER EVER DONT NO FUCKING SHIT NO NOT DO THAT EVER FUCKING NO

well it worked for a .obj i imported once :v:

Siliconmaster
September 23rd, 2011, 05:37 PM
well it worked for a .obj i imported once :v:

Idk, if the shreshold is small enough it shouldn't fuck up the model.