How to Pick Arbitrary Faces in Viewport?

How to Pick Arbitrary Faces in Viewport?

lightcube
Advisor Advisor
379 Views
3 Replies
Message 1 of 4

How to Pick Arbitrary Faces in Viewport?

lightcube
Advisor
Advisor
I am building a utility to change material IDs on objects. Here is specifically what I am trying to accomplish:

A user chooses a material and starts picking faces... those faces automatically get that material. By picking faces... I mean any arbitrary face in the viewport on any arbitrary object.

Yes, you could always go to each object, go to face sub-object mode, select the face and then scroll down to the material IDs... but that's what I'm trying to skip! I want a simple utility that works easily for this one task.

So my dilemma is that I don't know how to 1) Initiate a listener for a picked face and 2) how I would use it.

I've been reviewing some of the docs on accessing active viewport info... but my brain isn't soaking it in. I also looked in the Scripted Mouse Tools and PolyOp sections... nothing jumps out at me.

One consideration is that the object type should be arbitrary as the objects could be Primitives, Editable Poly, Editable Mesh, etc.

What I want is a magical:

on face_selected face do (

--do whatever to face

)

Does it already exist? If so... please point me in the right direction. If not, why NOT!? (And in that case, any ideas... ?)


Shawn Olson

Developer of Wall Worm
3ds Max plugins and Scripts

3ds Max 4/Gmax - 3ds Max 2020
Mudbox 2009-2019

Windows 10 x64
i7 8700K
64GB RAM
Geforce 1080ti
0 Likes
380 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
here is a plan:
1. using mouseTrack or simply pickPoint get mouse on screen point
2. using mapScreenToWorldRay make the ray for intersectRayScene
3. get all intersected nodes, sort them by distance from ray to get the closest node
4. using RayMeshGridIntersect with the same ray get all hit points with the node
5. using the closest hit (getClosestHit) get the hit face (getHitFace)
6. the hit face is TriMesh face... so using face/vert/face conversion get current object face (mesh or poly)

here we go. i can post the code but i hope it will not be interesting for you 😉
0 Likes
Message 3 of 4

lightcube
Advisor
Advisor
Feel free to post the code. I will use it and give you credits in my tool ... since I'd rather not spend time reinventing something that seems to be figured out.


Shawn Olson

Developer of Wall Worm
3ds Max plugins and Scripts

3ds Max 4/Gmax - 3ds Max 2020
Mudbox 2009-2019

Windows 10 x64
i7 8700K
64GB RAM
Geforce 1080ti
0 Likes
Message 4 of 4

lightcube
Advisor
Advisor
Thanks for your help Denis. I've got the utility I was making (Worm Face). There are credits on that page as well as on the main credit section of the documents.

I have never run across some of those functions, and I can think of all kinds of things to do with them now that I've used them.

Too bad we can't download info straight into our brains... I fear that by the time I've learned it all I'll be picking out logs for my funeral pyre.


Shawn Olson

Developer of Wall Worm
3ds Max plugins and Scripts

3ds Max 4/Gmax - 3ds Max 2020
Mudbox 2009-2019

Windows 10 x64
i7 8700K
64GB RAM
Geforce 1080ti
0 Likes