Home Coding, Scripting, Shaders

[Maxscript] random UV position of texture

polycounter lvl 11
Offline / Send Message
4KI75E4NN polycounter lvl 11
Hi,
I am new to Maxscript and dont know much about it, but to start, I would like to make a script that positions a texture randomly on a mesh.For example, I have 10 floor tiles and have one material. Every floor tile should have the same material but the UV position of the texture from the material should always be set random by the script with code like meditMaterials[1][#Maps][#color__Map__1____chesspattern].coords.U_distance = random <1> <10>
Is this possible ?

Replies

  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    So you want each element in the UV of a single mesh to be randomly positioned? For that you would need to collect the UV verts for each UV element, generate a random XY offset value for each element, and then apply that to said elements UV verts using the SetVertexPosition function (though I was never able to get that function to work with instanced UVW modifiers).
  • 4KI75E4NN
    Offline / Send Message
    4KI75E4NN polycounter lvl 11
    Yes, each floor tile should look different with only one material if possible, by setting the UV value different with the script for each mesh with the material applied to.

  • PolyHertz
    Offline / Send Message
    PolyHertz polycount lvl 666
    Well I already explained basically how you'd go about writing such a script.
    If you're hoping someone else will write the script though you'll need to post an example mesh and material you'd like said script to work on.
  • 4KI75E4NN
    Offline / Send Message
    4KI75E4NN polycounter lvl 11
    ok thanks, seems to be more complicated than I thought it might be.
  • Swordslayer
    Offline / Send Message
    Swordslayer interpolator
    Or alternatively use randomized UVWXform modifier on each mesh. If you hoped to do that material-side only, you'd have to use OSL instead (to have different coords as you mentioned in the first post, you'd have to also have a unique copy of the material to go with each one).
  • 4KI75E4NN
    Offline / Send Message
    4KI75E4NN polycounter lvl 11
    Would it be possible to do it with the Parameter-Editor and UVW-Xform too ? Because i dont know OSL or how to access it.
    I can connect the UV value to a custom parameter but how can I make it (the custom value) random ? And how to do it with only on material for all meshes, so that each mesh get different random UV coordinates ?

    UPDATE:
    I tried it with UVW Xform and a Maxscript with $.modifiers[#UVW_Xform].U_Offset = random 1.0 10
    And this works for a selected mesh. So I have to select every mesh successively and run the script for every mesh, which is a bit annoying. I get an error when none is selected or more than one is selectet. How can Imake the script to change all selected ?

    UPDATE 2:
    I get an error with this, but could something like this work:
    int i
    for(i=1; i<6; i++)
    {
    select $Quader(i+1)
    modPanel.setCurrentObject $.modifiers[#UVW_Xform]
    $.modifiers[#UVW_Xform].V_Offset = random 1.0 100
    }

  • Noors
    Offline / Send Message
    Noors greentooth
    That's not maxscript syntax. You should check some samples scripts .
    Should be :
    for i=1 to 6 do
    (
    )

    But instead of a fixed iterations number, you could parse your selected objects like so :

    --array of selected objects<br>sel = selection as array<br><br>--for each object in sel, with a check that the object is a geometry<br>for obj in sel where superclassof obj == geometryClass do<br>(<br>	--create a new modifier<br>	modUV = UVW_Xform ()<br>	modUV.U_Offset = random 0.0 1<br>	modUV.V_Offset = random 0.0 1<br>	--assign it<br>	addModifier obj modUV<br>	<br>	--uncomment next line if you want to collapse the stack<br>	--collapsestack obj<br>)



  • 4KI75E4NN
    Offline / Send Message
    4KI75E4NN polycounter lvl 11
    thanks :)
    but this script creates 5 Xform modifier to each of my 5 boxes, though and the values of the Xform UVs are random how it should be, but I have to delete 4 modifiers from each box


  • Noors
    Offline / Send Message
    Noors greentooth
    That's because your objects are instances. It's indeed as if you run the script 5 times on the same object. You might want to make copies instead because instances can't have different settings.

  • 4KI75E4NN
    Offline / Send Message
    4KI75E4NN polycounter lvl 11
    ok, now it works, great, thanks a lot :)
Sign In or Register to comment.