Home Technical Talk

How do you combine UVW Coordinates with Texture Coordinates?

polycounter lvl 13
Offline / Send Message
shawnolson polycounter lvl 13
I am trying to wrap up the loose ends in various tools in Wall Worm. Almost all of these functions that are left to finish involve UVW... and are stalled due to my own poor math skills.

One dilemma is that I do not know how to create UVW coordinates that correctly account for a texture's individual coordinates (BItmapTexture.coords.W_Angle, BItmapTexture.coords.U_Offset, etc). The values that a freind and I have come up with are "close" but not 100%.

Here is a script to demonstrate the data I can get for an object's UVW and the Bitmap... I'm just not certain of the proper way to combine the data. I'm guessing some matrix function... but that is the bottom of my Max skillset. The methods I'm employing in Wall Worm work for the geometry that needs this unless you add any texture coord rotation... then the offset it wrong. Oh how I despise linear algebra! :poly118:
clearListener()
/* Create a simple plane and convert it to an Editable Poly */
MyObj = Plane name:"MyPlaneTest" width:256 length:256 lengtsegs:1 widthsegs:1
convertToPoly MyObj
/* Apply a Planar UVW Map so we can animate UVW Data to more easily demonstrate the  values */
PlanarMod = Uvwmap name:"Planar UVW" length:256 width:256 utile:1 vtile:1 wtile:1
addmodifier MyObj PlanarMod
/* Make a texture and material to use for demonstration */
myTex = Checker name:"MyTexWithCoords"
myMat = StandardMaterial name:"MyMaterialWithBitmap" diffuseMap:myTex
/* Show the tex in the viewport... if you hit play you should see the tex move. */
showTextureMap myMat myTex on
/* Assign the material to the Object */
MyObj.mat = myMat

 
with animate on (
 
 /* Animate the U offset of the tex (myTex) coordinates */
 at time 0 myTex.Coordinates.U_Offset = 0
 at time 10 myTex.Coordinates.U_Offset = 0
 at time 100 myTex.Coordinates.U_Offset = 50
 
 /* Animate the W_Angle of the tex (myTex) coordinates */
 at time 0 myTex.Coordinates.W_Angle = 0
 at time 10 myTex.Coordinates.W_Angle = 0
 at time 100 myTex.Coordinates.W_Angle = 180
   
 /* Animate the rotation of the UVW Gizmo */
 at time 0 PlanarMod.Gizmo.rotation = (quat 0 0 -1 0)
 at time 100 PlanarMod.Gizmo.rotation = (quat 0 0 0 1)
  
)
 
 
function printMyUVWData obj mapChannel:1 faceIndex:1 frame:1= (
 
 sliderTime = frame
 
 format "\n#################\nUVW Data for Channel % on Face % at Frame %\n" mapChannel faceIndex frame
 
 at time frame (
 
  format "The Texture Coords\n\n"
  format "UV Transform: %\n\n" obj.mat.diffuseMap.coords.UVTransform
  
  format "U Offset: %\n\n" obj.mat.diffuseMap.coords.U_Offset
  format "W_Angle: %\n\n" obj.mat.diffuseMap.coords.W_Angle
  
  
  
  tvertFace = polyop.getMapFace obj mapChannel faceIndex
 
  format "Texture Vertex Info:\n"
  
  vi =1
  for i in tvertFace do (
   theMapVert =  (polyop.getMapVert obj mapChannel i)
   format "% - TV% :\t%\n" vi i theMapVert
   vi+=1
  )
 
  
 )
 
 
 
)

for f=0 to 100 do (
 printMyUVWData MyObj frame:f
)

Any help would be appreciated. I have a couple other UVW problems I'll post soon.

Replies

  • Angry Beaver
    Options
    Offline / Send Message
    Angry Beaver polycounter lvl 7
    I'm confused, you're trying to go from Max's UVW to source's texture projection system (this)

    And your trying to do this by only reading u/v co-ordinates?

    Your setting yourself up for the impossible if that's the case as the math to transfer between the two would be WAY out of the leauge of most anyone who'd do it for free.

    Your best option is to force people to use the 'planar u/v projections' and seeing if you can read that modifier off the stack as that most closely approximates how Source handles it.

    I wrote that article back in the day and I've come a long way as programmer since then so I understand the u/v axis lines of code way better than I did back then. That explanation talks about the effects rather than the functionality, but with the info you pull from a planar projection modifier I think you stand a stronger chance of getting u/v-ing exporting 100%

    [edit]
    the more I think about it your chances probably aren't as hopeless as I thought because your going on an n-gon by n-gon basis. give me a few moments while I make notes on a potential approach.

    [edit2]
    So if you wan't to jsut read UVs your bets bet unless I'm corrected would be something like this:

    Go face by face (tri, n-gon, quad, whatever) and generate an averaged 'normal' for the face by going clockwise round each vert.

    Then using the same order of verts do the same for the uv.

    Then through comparisons of these normals you can get the projection orientation to fill in the [] sections.

    Scale/rotation might be a little trickier. I'd imagine you would probably have to see if there's an roll to the projection normals for rotation and scale could be handled through the comparative normals if you we're to establish a vertex as your 'up'

    This is pretty theoretical though as I'm at work and so totally do not have the spare time to do this outside of work. Being able to assume these faces are planar is a huge component of my simplified methodology.
  • shawnolson
    Options
    Offline / Send Message
    shawnolson polycounter lvl 13
    This is for Brush faces in Source... which must always be Planar UVW.

    For the most part the code I've got does a good job by trying to "add up" the values: Taking the Planar UVW coords on a Polygon and then adding the texture scaling/offsets, etc. This works but when rotating the uaxis and vaxis with the texture coordinate's angles, the translation gets knocked out of whack.
Sign In or Register to comment.