Home Coding, Scripting, Shaders

[MAXScript] UVW Mapping Paste on Mesh Instances

interpolator
Offline / Send Message
Revel interpolator
Guys I've tried to copy paste a UV from one object to the other using maxscript, it worked but when it come to instanced object, it somewhat didn't paste it across all instance, but instead it paste it to only 1 specific instance mesh.

For example I have a mesh name Box_001, Box_002, Box_003, etc and all of them are instance to each other, then I have another same mesh BUT not instance to any of the rest name Box_CorrectUV, then I copy and paste the uv from Box_CorrectUV to the Box_001, and I get this:


I can drag and drop that modifier to below that thick line to apply to the rest of the instance and the maxscript listener give this this:
<div>addModifier $Box_002.baseObject (UVW_Mapping_Paste ())
deleteModifier $ 1</div>

Note that it add the modifier to the second instance mesh (Box_002) instead of itself (Box_001). But if I try to run this code myself, it doesn't work.
I kinda get that there is no UVW_Mapping_Paste modifier from the modifier list but even when I test it with this, the code still doesn't work:
addModifier $Box_002.baseObject ($.modifiers[1])

Anyone has idea of how to make this work? Or it's just one of the maxscript limitation that we can do nothing about.

Replies

  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
    after a quick read... i think you might be a bit stuffed.  There doesn't seem to be a non-pain in the arse solution 

    This will copy UVs from Box001 to anything you have selected so you can at least do it all in one hit but you'll always get the paste modifier at the top of the stack. 

    
    
    ChannelInfo.CopyChannel $Box001 3 1&nbsp;
    for o in $ do
        ChannelInfo.PasteChannel o 3 1&nbsp;
        ChannelInfo.update()<div><br></div>

    or.. 

    Alternatively - you can simply manually move the UVW Mapping Paste modifier down below the grey bar and it'll be applied to all instances

  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    Yeah I supposed I could iterate to all selection instead of one of every instance but that will break the instance if I ever collapse the stack. Even then I could re-instance them again and its still gonna be 2 step process.

    If it's only 1 or 2 type of instance that's easy, but if you have around 50+ mesh in the scene which each of them have their own instances that will take some time.
  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter


    Oh,  actually, this works


    
    
    
    
    <div>dest_obj = $Box002</div>
    <div>source_obj = $Box001</div>
    
    <div>addModifier dest_obj (Unwrap_UVW ())</div>
    <div>addModifierWithLocalData&nbsp; dest_obj dest_obj.modifiers[1] source_obj source_obj.modifiers[1]
    </div>
    <div>deleteModifier dest_obj 2<br></div>
    
    
    
    


    it'd be better not to reference the modifiers by index but that'll come out in the wash. 
    the behaviour is a bit odd - I'm not sure why it needs a uvw modifier to start with - but i can't be boetherd to look very deeply into it.
  • Eric Chadwick
    Options
    Offline / Send Message
    Why not approach it from a different angle... Change all the instances into an instance of the Box_CorrectUV?
  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
    That did occur to me as it's easy to do the instance swap using the instanceReplace command

     The benefit of doing the above is that it will work on anything that the manual UVW copy will work on.  Basically as long as the UV count matches up and the object class matches (i.e editable poly-editable poly,  box-box etc.) it should "work"


  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    @poopipe Hmm strange that it didn't work for me. I tried to change the source obj to become the Box_CorrectUV and destination to Box_001 still doesn't work. Though if I have manually add a Unwrap_UVW before running the addModifierWithLocalData script, looks like it works but if the Unwrap_UVW was added using the same script with the addModifierWithLocalData, it does not transfer well..Probably it's just my error cus I'm a bit tired right now brain doesn't function well lol, will look at it again tomorrow  :* 

    @Eric Chadwick I can't instance the mesh to the Box_CorrectUV because the mesh's smoothing group was messed up due to export-import process. I'm using this method to do packing in IPackThat without messed up my original mesh's SG and vertex normal.
  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
    The objects need to be the same type afaik.  So you can't mix Eg. editable poly and editable mesh. 
    If that's not the issue I don't know - the command is new to me. 
    You do need the unwrap uvw there first but I'm honestly stumped as to why. It was adding it fine in script here (on 2019)
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    The only time that it works on my end is that if I add the Unwrap modifier manually before run the script, to both the source and destination objects. If it's added using the maxscript itself, it either failed to run the script or didn't copy the info (I got both of this situation running different combination of steps, not sure which is which).

    Probably the problem is the Max version as I'm still using 2017. Too bad nothing we can do about it.
  • poopipe
    Options
    Offline / Send Message
    poopipe grand marshal polycounter
    I just checked this on 2012 and it doesn't work right .  I'll assume it's a version thing.
  • Revel
    Options
    Offline / Send Message
    Revel interpolator
    Thanks for checking and help man, appreciated it :smile:
  • monster
    Options
    Offline / Send Message
    monster polycounter
    Revel said:
    The only time that it works on my end is that if I add the Unwrap modifier manually before run the script, to both the source and destination objects. If it's added using the maxscript itself, it either failed to run the script or didn't copy the info (I got both of this situation running different combination of steps, not sure which is which).

    In general, with Unwrap UVW and with Skin mods it's better to use modpanel.addmodtoselection with ui set to true. Because unwrap/skin doesn't initialize with addModifier.
Sign In or Register to comment.