Notifications
Clear all

[Closed] UVWMap Modifier Gizmo

Does anyone know of a way to make the gizmo of the UVW Map Modifier inherit the same rotational angle as a set of selected faces? For example, I select the faces of one side of the roof of a building. The faces are all planar to themselves and slope down about 30 degrees. I want to create a script that automatically applies the uvw map modifier and then sizes and rotates the gizmo to match up with the selected faces.

I’ve got the size part done, but the only way I can think of to get the rotation part is to get the normal vector of one of the selected faces and then use that as the rotation value of the gizmo. The problem is that I don’t know how to convert the point3 vector value into a quat value for the gizmo. When I try using something like ‘faceNormal as quat’ I get an error message.

Anyone know how I can either use the normal vector or have a different idea of how to rotate the modifier gizmo to match the selected faces?

Thanks.

Edit: I just noticed there’s a “Normal Align” button in the UVW Map modifier. This is exactly what I want, but there doesn’t seem to be a way to access this functionality through MaxScript. Or is there?

10 Replies

I would suggest averaging the normals of all your selected faces (in case they’re not absolutely planar) and passing the resulting point3 to matrixFromNormal(). That should give you a transform matrix that you can simply assign to the .transform of the gizmo. Then all you have to worry about is the sizing, which you already have figured out:)

RH

I would suggest averaging the normals of all your selected faces (in case they’re not absolutely planar) and passing the resulting point3 to matrixFromNormal(). That should give you a transform matrix that you can simply assign to the .transform of the gizmo. Then all you have to worry about is the sizing, which you already have figured out:)

RH

Not sure how that posted twice:shrug:

Thanks LF! That’s sounds like what I’m after, but I don’t exactly understand the information I’m getting from it. Here’s an example from my scene:

faceNormal = [0,-1,0]
matrixFromNormal faceNormal
(matrix3 [0,0,-1] [1,0,0] [0,-1,0] [0,0,0])

I don’t see how I can apply the matrix3 values to the gizmo. Here are my options regarding the gizmo:

<Uvwmap.Gizmo>.position Point3 default: [0,0,0] – animatable

The position of the UVWmap gizmo.

<Uvwmap.Gizmo>.rotation Quat default: (quat 0 0 -1 0) – animatable

The rotation of the UVWmap gizmo.

<Uvwmap.Gizmo>.scale Point3 default: [1,1,1] – animatable

The scale of the UVWmap gizmo.

I read the reference notes regarding vectors, but it’s a bit over my head. I kind of understand what they are, but not completely how to use them, especially since the gizmo rotation is looking for a quat value.

Any insight would be greatly appreciated.

Once you’ve obtained a transform matrix (matrix3) from the normal, you just assign it to the .transform property of the gizmo. Following your example, it might look like this:

faceNormal = [0, -1, 0]
uvwmap.gizmo.transform = matrixFromNormal faceNormal

There you have it – a quat-free solution;)

RH

Ah, I see. Awesome! I didn’t even know that the gizmo had a .transform property.

Okay, that works. Now I’ve got a new problem (there always seems to be a new problem ). The planar mapping gizmo is sometimes sideways or upside down depending on which side of the building the faces are selected. I need for it to always point up, just like it does when you use the “Normal Align” button in the UVW Map modifier.

I’ve tried predicting which way it’s going to be oriented (along the vector’s Z axis) by tesing it on a lot of different faces and then using a bunch of ‘if…then’ statements to re-rotate the gizmo after it’s applied. It seems to work about 90% of the time, but is there a way to supply some kind of upnode for the vector matrix?

I found this option in the reference, but don’t really understand what kind of information it’s asking for as far as the ‘point3’ value:

arbAxis <point3>
Returns a Matrix3 value representing an arbitrary axis system using point3 as the “up” direction.

Is it something like [0,0,1]?

Originally posted by FatAssasin
[B]Ah, I see. Awesome! I didn’t even know that the gizmo had a .transform property.

Okay, that works. Now I’ve got a new problem (there always seems to be a new problem ). The planar mapping gizmo is sometimes sideways or upside down depending on which side of the building the faces are selected. I need for it to always point up, just like it does when you use the “Normal Align” button in the UVW Map modifier.

I’ve tried predicting which way it’s going to be oriented (along the vector’s Z axis) by tesing it on a lot of different faces and then using a bunch of ‘if…then’ statements to re-rotate the gizmo after it’s applied. It seems to work about 90% of the time, but is there a way to supply some kind of upnode for the vector matrix?

I found this option in the reference, but don’t really understand what kind of information it’s asking for as far as the ‘point3’ value:

Is it something like [0,0,1]? [/B]

I just posted a reply to the Discreet Support Forum, here is the code again:

faceArr = (getFaceSelection $) as array
faceNormal = in coordsys $ (getFaceNormal $ faceArr[1])

–This is the desired up vector in world space:
worldUpVector = [0,0,1]

–Now get the cross-product of the face normal and the up vector.
–This will give you a vector that is perpendicular to the plane defined
–by the normal and the up vector. Normalize it to get a normal vector
–pointing to the right
rightVector = normalize (cross worldUpVector faceNormal)

–Now using the face normal and the new right vector,
–get a vector that is perpendicular to the plane defined by the two.
–This is the “local up vector”, the vector that is the projection of
–the world up vector on the face you selected. This one is perpendicular
–to both the face normal and the right vector, and you have 3 normals now
–that define the X, Y and Z of your new orthogonal coordinate system
–for the UVW gizmo!
upVector = normalize ( cross rightVector faceNormal)

–Using the 3 vectors, define a matrix3 value which represents the
–coordinate system of the gizmo. The face normal is the Z axis,
–the right vector is the X axis, and the local up vector is the Y axis:
theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]

modPanel.addModToSelection (Uvwmap ()) ui:on
$.modifiers[#UVW_Mapping].gizmo.transform = theMatrix
$.modifiers[#UVW_Mapping].length = 400
$.modifiers[#UVW_Mapping].width = 400

hey guys,

I’m trying to do almost the exact same thing,

Bobo, when I run your code I get the following error at the following line

<quote>
faceNormal = in coordsys $ (getFaceNormal $ faceArr[1])
– Runtime error: Mesh operation on non-mesh: Editable Poly
</quote>

I won’t even pretend to understand the math underneath quats or point3’s or euler…

as good as the manual is, I don’t understand

isn’t there another way to get normals with rays or something? (no sure I want to open that can, but I just thought I’d mention it)

anyway, I’ll keep at this, and hopefully someone has experience with it that could help

This particular fix is an easy one. The code as written only works with Editable Mesh objects, not Editable Polys. Just convert the selected object to an EMesh first.

That’s what, “– Runtime error: Mesh operation on non-mesh: Editable Poly”, means.

Page 1 / 2