[Closed] UVWMap Modifier RealWorldMapsize
First of all, hello people and a short introduction:
Been working with Max for quite some while now (mainly contributing to game mods), but only recently started with Maxscript (since about a week) and while I managed to find lots and lots of resources to solve the things I needed, now I’m stuck on a relatively minor problem at first sight. However I seem to utterly fail to solve it.
I have a heightmap importing script for game maps that also is supposed to apply the correct textures as simple materials to it (it’s a simple diffuse texture, nothing special). Importing is no issue, assigning the texture is no issue. The original script was developed for Max 5-7 and I’m trying to port it to the “new era”. The one problem I’m facing is the new Max feature “RealWorldMapsize” (=RWMS). The terrain is made up of several “patches” ordered in a simple XY-grid and each has a very own texture sheet. The thing is, the individual size of the terrain and texture patches can be totally individual, one map can have 256×256 terrain and 1024×1024 texture and another can have it the other way around (alwys multiple of 2, of course). I need the texture to be simply fitted on top of the terrain as a simple plane (and a vflip) but that all works with the script. But this is where the RWMS mucks up. as it’s true by default, the tiling is completely off. If I manually specify a uvwmap.width and .length it works, but this setting varies from map to map, so no use setting a fixed value. I could work around it of course, but I’m sure there’s an easier solution.
On th right is what the script spits out, the left one shows what happens after I manually untick RWMS after the script is done. The left one is obviously what I want.
What I need: A way to disable RWMS in the UVWMap-Modifier via Script. And a possiblity to apply the “Fit”-Option afterwards, sizing the material perfectly to the terrain patch (this is done automatically when you untick the RWMS option in the UVWMap modifier).
In Max7 this works flawlessly, because RWMS doesn’t screw things up in the first place…
Code snippet:
terrainobject is the individual terrain patch.
uvw = Uvwmap()
addModifier terrainObject (uvw)
uvw.vflip = true
uvw.realWorldMapSize = false
-- uvw.length = 256.256
-- uvw.width = 256.256
-- collapseStack terrainObject (Disabled for debug purposes)
clearUndoBuffer()
if ( IdoTextures ) do
(
if (x > texOffsetX) and (y > texOffsetY) do
(
tmpFileName = (((getFilenamePath hmFileName) as string)+"Textures\\"+(parseTxName prefixTexN (abs(x-texOffsetX)) (abs(y-texOffsetY)) ".dds"))
if (thisfileDoesExist tmpFileName) do
(
tmpMaterial = standard name:("Mat_"+(parseTxName prefixTexN x y ""))
tmpMaterial.maps[2] = (Bitmaptexture fileName:tmpFileName)
showTextureMap tmpMaterial tmpMaterial.maps[2] true
terrainObject.material = tmpMaterial
)
)
)
As you can see I tried disabling the RWSM there, but it doesn’t do anything…and I have found absolutely no way to script the “Fit” function :curious: .
I’d be very grateful if you could help me with this.
I just turned on the macro recording function in maxscript listener,
then enabled\disabled the feature you wanted.
It uses On\Off instead of True \ False.
I guess this changed somewhere between the versions.
use:
turn on:
.realWorldMapSize = on
turn it off:
.realWorldMapSize = off
there is no difference between on/off and true/false, they are synonyms. It seems that changing the property just doesn’t update the modifier.
try this:
uvw = uvwMap realWorldMapSize:off vFlip:on
addModifier terrainObject uvw
about invoking ‘fit’, you can use uiaccessor to do that, but I remember there is a more elegant solution. maybe in the unwrapUVW interface.
It updates only if you reassign the following properties:
utile, vtile, wtile, length, width, height.
Because those properties change on the UI if you click the real-world map size checker.
You can see it with the macro recorder.
You could also try unchecking ‘Use Real-World Texture Coordinates’ on the general tab in Max’s preferences before you run the script. I don’t know whether it is accessible through maxscript.
As far as invoking ‘fit’ is concerned I thought that when you add a uvwmap modifier and don’t supply length, width or height then it is automatically set to the size of the underlying geometry.
Maybe its because you assign the UVWmap to a variable first before applying it.
Instead of:
uvw = Uvwmap()
addModifier terrainObject (uvw)
uvw.vflip = true
uvw.realWorldMapSize = false
-- uvw.length = 256.256
-- uvw.width = 256.256
try:
addModifier terrainObject (Uvwmap realWorldMapSize:false vflip:true)
Update: Sorry I should have checked before posting but setting realWorldMapSize to false when assigning directly to a node doesn’t work either. It looks like a bug as the help says it’s read/write.
I tried all suggestions, none worked .
I even have added a
uvw.utile 1.2
and a
uvw.vtile 1.3
for test reasons but…nothing. Oddly enough neither the RSWM = false or the utile=1.2 are executed, whereas the vflip still is applied. On the other hand it might be they are applied, but as RWMS is active and disables the uflip&vflip boxes in the UI they are not visually updated there. And once you untick RSWM, an automatic “Fit” is applied anyway, apparently.
uvw = Uvwmap()
addModifier terrainObject (uvw)
uvw.vflip = true
uvw.realWorldMapSize = false
-- uvw.length = 256.256
-- uvw.width = 256.256
uvw.utile = 1.2
uvw.realWorldMapSize = false
uvw.vtile = 1.2
The “fit” is not that bad, as already said it automatically fits once RWMS is unticked. But having to select every single terrain patch and unticking it is VERY annoying as there can be quite a bunch of patches (power of two, after all…).
I think the Macro recorder shows the utile etc. popping up simply because they are disabled/enabled with ticking/unticking RWMS.
You have to reassign all the properties I listed, not only a few.
uvw = Uvwmap()
addModifier terrainObject (uvw)
uvw.vflip = true
uvw.realWorldMapSize = false
uvw.length = 256.256
uvw.width = 256.256
uvw.height = 256.256
uvw.utile = 1.2
uvw.vtile = 1.2
uvw.wtile = 1.2
or instead just change the maptype for a second
local origMapType = uvw.mapType
uvw.mapType = if origMap == 0 then 1 else 0
uvw.mapType = origMapType
Well, reassigning all values is what I wanted to avoid as said before, as the length/width is variable for each map or even differ in a single map.
The maptype idea didn’t work, sadly.
And plastic, even your idea results in RSWM being ticked…the size is correct though, but merely because I “force it” so with the length/width values…I’m confused.
Alternatively I would ask for a pointer on how to read out the texture size for each terrain patch as a variable for the width/length so I could make your workaround work…
When you turn off real-world mapping on the UI, the modifier seems to fill in the new values based on the objects bounding box.
You can get the dimensions like this:
obj=$
bbox = nodeGetBoundingBox obj obj.transform
size=bbox[2]-bbox[1]
w=size[1]
l=size[2]
h=size[3]