Home Technical Talk

Explode script needed(for baking purposes)

1
polycounter lvl 15
Offline / Send Message
CodeFather polycounter lvl 15
Basically what I need is script which groups lowpoly parts with their corresponding highpoly
parts and scatter all groups in the viewport for easy texture baking of normal and AO maps.
Right now I do that manually by linking lowpoly and highpoly pieces to different help objects and moving them around.

So if someone of you masterminds of game art can help here it will be awesome! :)

Here is a gif illustrating what I'm talking about:
ExpodeAnim.gif

Replies

  • BradMyers82
    Offline / Send Message
    BradMyers82 interpolator
    That's an interesting workflow you have there. Why not just organize the parts in layers, and hide / isolate what you want to bake individually?
    Anyways, did you try scriptspot?
    I found this one there, and it appears if you use only the 3rd dial it might give you what your after. http://scriptspot.com/3ds-max/the-bm-breaker
  • Mark Dygert
    Polyhurtz has a cool way of doing this, animate the pieces.
    Frame 0 = all parts together.
    Frame 1 = exploded.
  • Ben Apuna
    Yeah I don't know about that method... I'm all for the show and hide workflow. With the way you are doing it now how do you know if you've moved some part far enough away to not put any unwanted AO on any other part? I guess the advantage is that you can bake it all in one go, but what if there are problems? at least for me there usually are... then you need to rebake the whole thing all over again. Isn't there a way to accomplish the same goal with material IDs as well? Sorry I wish I had a script that makes the baking process more efficient but unfortunately I don't.
  • Lamont
    Offline / Send Message
    Lamont polycounter lvl 15
    How does the 3DS Max surface/normal/AO baker work? I have Mel that does this in Maya, but it goes by a naming convention. I'd be more than happy to guide you through what to look for to script this and how to structure it, but I don't have 3DS Max running on my comp.
  • CodeFather
    Offline / Send Message
    CodeFather polycounter lvl 15
    Vig wrote: »
    Polyhurtz has a cool way of doing this, animate the pieces.
    Frame 0 = all parts together.
    Frame 1 = exploded.

    Vig, I actually do it this way ,but when the pieces are too many it is annoying to group/link/move all pieces by hand(sometimes I forget to link some part to its corresponding group and I get even more pissed). What I was thinking of was to automate the process.

    My workflow right now goes like this: I create a helper object for each group(like the pants group, or shoulder piece group or whatever), then link the lowpoly and all corresponding highpoly objects to their helper; move all pieces away from each other far enough.Then I apply a projection modifier to each lowpoly object and render out normal and AO maps.I then combine all separate normal maps in one map into photoshop using a custom action,I do the same with the AO maps.
    So I was thinking of automating the first part, the "whole linking/moving pieces all around" stuff (and even setting projection settings,that will be even better).

    Lamont wrote: »
    How does the 3DS Max surface/normal/AO baker work? I have Mel that does this in Maya, but it goes by a naming convention. I'd be more than happy to guide you through what to look for to script this and how to structure it, but I don't have 3DS Max running on my comp.

    Yes, Lamont, I was thinking about naming conventions too but I have no experience in MaxScript. It will be really helpful if you provide some sort of algorithm, what are the general steps in your Mel script?
    That's an interesting workflow you have there. Why not just organize the parts in layers, and hide / isolate what you want to bake individually?
    Anyways, did you try scriptspot?
    I found this one there, and it appears if you use only the 3rd dial it might give you what your after. http://scriptspot.com/3ds-max/the-bm-breaker


    Brad, thanks, I'll give it a try :)
  • Lamont
    Offline / Send Message
    Lamont polycounter lvl 15
    This is how my script works:

    - Type in the name of the target mesh (or select).
    - Set your options (AO/Normal Map image size)
    - Hit the render button.

    Maya selects the correct mesh, and uses that as the source. I am not doing any kind of tricky math with this one, all I do is take the functions of Maya, wrap them in a UI with options and pass the data along. Streamline an otherwise PITA workflow for hundreds of meshes.

    If I know I will have AO maps a certain size, I will bind this to a key. So select the mesh, hit the key, and it kicks out the image.
  • Mark Dygert
    Maybe not explode the pieces but "isolate selection" then run a AO bake and exit isolation mode? Have it iterate over your selection or maybe objects in a specific selection set, layer or named group?
  • Lamont
    Offline / Send Message
    Lamont polycounter lvl 15
    That should work. You can even script temp locations. if Isolate still see's rays at render, then moving is the next option. Or set a flag (renderable) if 3DS Max has such a feature, then they can stay in place.
  • CodeFather
    Offline / Send Message
    CodeFather polycounter lvl 15
    Vig wrote: »
    Maybe not explode the pieces but "isolate selection" then run a AO bake and exit isolation mode? Have it iterate over your selection or maybe objects in a specific selection set, layer or named group?

    Isolation is a good idea! This way it will even cut down the render time of each map , because the groups(LPs + HPs) will be considered in the baking process one at a time, instead of loading all objects at once.
    So bassicaly the script should :

    1)group coresponding parts into different selection sets
    based on naming conventions, for instance:

    LP_ShoulderPart (the LowPoly object)
    HP_ShoulderPart (HighPoly object)
    ZB_ShoulderPart (HighPoly object imported from Zbrush)

    ...this should be grouped into one selection set called "ShoulderPart"

    2)iterate a render to texture for every selection set in isolation mode




    ...by the way, "the bm-breaker" doesn't work, it only detaches a selected object to its consisting sub-objects
  • Lamont
    Offline / Send Message
    Lamont polycounter lvl 15
    Are you trying to get the AO for all the parts on one texture?
  • CodeFather
    Offline / Send Message
    CodeFather polycounter lvl 15
    Lamont wrote: »
    Are you trying to get the AO for all the parts on one texture?

    Yes, in the end there should be one AO texture.Right now I use a custom photoshop action to combine the multiple AO parts in one final AO map
  • CodeFather
    Offline / Send Message
    CodeFather polycounter lvl 15
    This is what some good guy at cgTalk.com response to my request, but I haven't been able to execute it, maybe it is just a rough example. Anyway, it will be best to work with any names of objects, not just a predifined ones. I always have different parts named differently depending on the concept.

    (
    local parts = #("shoulder","elbow")
    local suffix = #("_L","_H","_Z")
    local thePart = undefined
    local theCenter = [0,0,0] -- this is the center of the character
    local proj = 20.0 -- the distance projected out
    
      for i = 1 to parts.count do
      (
       for n = 1 to suffix.count do
       (
       thePart = getNodeByName (parts[i] + suffix[n])
       
       if thePart != undefined do
       (
       thePart.pos = normalize (thePart.transform.pos - theCenter) * proj  + theCenter
       )
      )
     )
    )
    
  • CodeFather
    Offline / Send Message
    CodeFather polycounter lvl 15
    Hi, guys, I came up with a more detailed algorithm, It looks like this:


    The Explode baker:

    Step a) Link LPs to their corresponding HPs:
    - must provide flexible options such as smart sorting of names
    (even if some of the names are miswritten the script tries to find
    their best match).

    - linking by relative distance and positions.Even if there is no naming
    conventions and organization in the scene, the scripts pairs objects together
    by their relative pivot position( I saw smth like this at scriptspot.com, called
    "DistanceLinker" or smth similar.) It's not a perfect solution, can produce mistakes.

    - or the two methods could be combined together. First the script tries to
    group objects using naming convention and if miswritten object is present in
    the scene , groups it to the nearest object if there is any.

    - also option to link object by other criteries , like material IDs or
    smth is a plus.

    Step b) A projection modifier is applied to all LPs(with predefined settings),
    or it would be better if it preserves the settings avaible prior the linkage.
    Notice that a link hierarchy can't be created when a projection modifier is
    applied to some of the objects, so the modifier should be removed prior the
    linkage and applied back after.

    Step c) Exploded all linked groups using a unique vector so there are no
    overlapping groups of objects and there is enough space between them.

    Step d) Render all required maps on one pass using RTT.

    Step e) Revert the original position of the linked groups. That can be done by
    simple animation.At frame 0 all pieces are together, at frame 1 they are exploded.

    First of all sorry for my English, I hope you've understand the idea. Second, I'll be highly appreciative if someone in this community finds this script idea for interesting and wish to help. I think something like automated RTT will have a great value when it comes to cutting down production time. Tell me what you think, Cheers!
  • EarthQuake
    Rendering multiple maps and combining them is really a huge waste of time, i'm always surprised when i hear people suggest doing this. All you need to do is:

    Explode bake for your normals/high ao detail
    Simple AO bake from just the lowpoly mesh(projecting onto itself, no HP source)

    combine high + low ao!

    There you go, done! You have your highres ao detail, and the low freq. detail from various parts intersecting etc.

    In maya you can select multiple LP sources, which is very usefull. In max, i guess just combine your exploded objects before baking into one mesh, it really seems like you guys are trying to make this a lot more complicated than it is. =D
  • mLichy
    I just use the animation method. Works fine. Depending upon what I bake, I do multiple passes and combine them, but it's to save time. Otherwise trying to bake with floating stuff causes issues and wastes time.
  • CodeFather
    Offline / Send Message
    CodeFather polycounter lvl 15
    EarthQuake wrote: »
    Rendering multiple maps and combining them is really a huge waste of time, i'm always surprised when i hear people suggest doing this. All you need to do is:

    Explode bake for your normals/high ao detail
    Simple AO bake from just the lowpoly mesh(projecting onto itself, no HP source)

    combine high + low ao!

    There you go, done! You have your highres ao detail, and the low freq. detail from various parts intersecting etc.

    In maya you can select multiple LP sources, which is very usefull. In max, i guess just combine your exploded objects before baking into one mesh, it really seems like you guys are trying to make this a lot more complicated than it is. =D


    EarthQuake, my current workflow is exactly like you've discribed it ( + additional step : layering two more "fake AOs" generated in photoshop from the normal maps). Max is also capable of selecting multiple LP sources, that is what I always do, but the thing is that they render to separate maps, and should be combined in one map later in photoshop( I automated this with an action so it's not time consuming at all). If I want to bake all parts in one map in max, I should attach all LP objects together loosing their pivots,etc. And it's pain in the ass when it comes to fine tuning the projection cage or the parameters of only one part, if something goes wrong with that part, you'll waist time to render the whole thing again.
    What I want to do, is automate all the hand work . You click a button - your character or whatever , explodes to pieces. Click another button - all LP pieces are now with a projection modifier in their stack and with the correct parameters, click one more button - the RTT begins, etc. I'm not sure if this is posible but would be nice to have such tool, especialy when you're dealing with tons of objects to render out.
  • jerry
    I'm working on this. Posting here to let everyone know so there won't be three people doing the same thing. I got some detaching going on but nothing serious yet. When i have something concrete you can test I shall let you know. I think this script could prove to be a serious time saver :)
  • CodeFather
    Offline / Send Message
    CodeFather polycounter lvl 15
    jerry wrote: »
    I'm working on this. Posting here to let everyone know so there won't be three people doing the same thing. I got some detaching going on but nothing serious yet. When i have something concrete you can test I shall let you know. I think this script could prove to be a serious time saver :)

    Jerry, you're great man ! If you need some more information just ask, I'm glad someone took this siriously. I'm looking forward to it! :)
  • glib
    EarthQuake wrote: »
    Rendering multiple maps and combining them is really a huge waste of time, i'm always surprised when i hear people suggest doing this. All you need to do is:

    Explode bake for your normals/high ao detail
    Simple AO bake from just the lowpoly mesh(projecting onto itself, no HP source)

    combine high + low ao!

    There you go, done! You have your highres ao detail, and the low freq. detail from various parts intersecting etc.

    In maya you can select multiple LP sources, which is very usefull. In max, i guess just combine your exploded objects before baking into one mesh, it really seems like you guys are trying to make this a lot more complicated than it is. =D

    So when you talk about the explode bake, do you work with the keyframe method, or just save before, move everything, bake and then reload from your save file?
  • Xoliul
    Offline / Send Message
    Xoliul polycounter lvl 14
    Work faster Jerry, I need it now!
  • jerry
    Ok, it's not finished yet (at all) but i just want to show a sneak preview of what i've done :)

    The next part i'm gonna be working on is matching the high with the lowpoly. I would let you guys test the current version but it's way too buggy :poly127:

    68aa39.png

    Edit: I just browsed the plugins thread and see three people have actually written the detach by element part :poly124:. It didn't take me very long to write but it's pretty stupid three people wrote the same thing and then i write it the fourth time. Oh well. If anyone cares for just the detaching part (matID smthGrp) i can probably release it separately later, we'll see.
  • mLichy
    Nice man, keep it up!
  • EarthQuake
    glib wrote: »
    So when you talk about the explode bake, do you work with the keyframe method, or just save before, move everything, bake and then reload from your save file?

    Yeah the keyframe method is best. Anything that means you end up with multiple copies of the mesh is a bad idea, incase you need to go back and make changes.

    Also saving, moving etc assumes your bake is going to be perfect on the first try, which is pretty wishful thinking =). When you inevitably need to rebake, you'll be glad its set up as simple keyframes.
  • Jesse Moody
    Offline / Send Message
    Jesse Moody polycounter lvl 17
    yep the keyframe method rocks. Like EQ said. If you have to make changes then you have to remove everything over again. That is not fun by any means and in the end will waste a ton of time.
  • thatnumpty
    anyone use the multi-sub material and "Hit Only Matching Material ID" method? (using max, dunno about other apps)


    i was taught this recently, way easier than exploding imo.
  • Jesse Moody
    Offline / Send Message
    Jesse Moody polycounter lvl 17
    thatnumpty. I tried that on a few things and it was handy as well. I'm just used to my work flow of the exploding technique...But yeah that is another way for sure and it seems to work really well.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    I noticed this:
    http://www.scriptspot.com/forums/3ds-max/scripts-wanted/script-auto-baker-automated-rtt
    yesterday, and something else:

    another way to isolate, meshes before baking is to set parameter in th rendering command:
    render rendertype:#bakeSelected ...
    and use select #{baseObj, pairObj} before that
  • oXYnary
    Offline / Send Message
    oXYnary polycounter lvl 18
    Live and learn I guess. Kinda confused on the keyframe version. Your still moving those by hand? Or is there a script your running to explode? Maybe I'm reading too fast and missing the tool your using.

    Ive been putting a modifier on top of the stack of edit mesh that I can turn on/off. On = Height and NM. Off = AO. In high rez, just below mesh smooth.


    Why would you bake an AO of your low rez and do you multiply it on top of the high rez one?
  • whipSwitch
    Offline / Send Message
    whipSwitch polycounter lvl 8
    You bake a low res to capture AO that should be there, but is missed due to the parts being moved away from each other. Ex. Head geometry + big bulky collar, there would be AO between them, but you prolly wouldn't bake them together(as the collar would most like be part of the torso section or such). So you bake the low res to capture that missing shadow. Or, repeated overlapping armour plates that only need to be bakes once, but should have AO between them, stuff like that. Make sense?
  • oXYnary
    Offline / Send Message
    oXYnary polycounter lvl 18
    Kinda. But why not bake them from the high version and combine? Or because your dealing with such high pc counts you cant load both at once?

    I usually collapse my exploded high/low mesh for the AO.

    Is a limitation of max/maya? I know in xnormal you can choose a variety of high PC files to combine on final. Maybe thus far my polycounts just haven't been big enough to encounter what you mention?

    I guess Im asking. Is this just a workaround? Or part of the standard process to get AO to look correct?
  • mLichy
    What I do is select the LP piece I want to "explode" being a seperate object, apply a keyframe to it, then turn on auto key and move it to the side. Usually it's best to do this with both the LP and HP models that are overlapping already, and move both at the same time.
  • Electro
    Offline / Send Message
    Electro polycounter lvl 18
    Ok, so I've been selfish... but I've been meaning to release this as I've made it and been using it myself for quite some time. Sorry!

    I'll upload it later today when I get home and post the link (if I remember!)

    Here's some pics of how it works.

    http://bayimg.com/image/paelcaacc.jpg

    http://bayimg.com/image/paeldaacc.jpg


    It works with object names... LOW_objname and HIGH_objname are clearly buddies, and will stick together during explode/implode.

    For things you don't want to move, you don't give them the LOW_ prefix
    If you want only the low to move, give it the LOW_ prefix, but no matching HIGH_ buddy, and he will be a loner.
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    how about another script that adds the prefix to 2 selected objects based on which of of them has more polys . Or a script that processes everything or a whole selection and pairs up those 2 that are close to each other (you could do that with a distance sort table) and do it all automatically.
    Also less buttons is always a winner - so maybe you can combine some functionality into a few or just 1 button instead of several.
  • mLichy
    Awesome man, hope to test this soon :D
  • Electro
    Offline / Send Message
    Electro polycounter lvl 18
    renderhjs: sounds good :) I didn't really think about this much, just made it to help speed things up quicker for me, but definitely good ideas and worth doing. Rather than just comparing position, I'd probably also compare boundary box volumes to ensure the closest match is found. Love your textools btw ;)

    I'm all for UI ideas, like I said, really just hacked together. Even in its sloppy form right now I find it to be a big time saver. I have no patience for separating things manually for bakes. :P
  • oXYnary
    Offline / Send Message
    oXYnary polycounter lvl 18
    *waits with glee** :)
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    Yep, if you base it on bounding box matching and polygon count then it should be possible to do a fully automated script (and have it generate keyframes automatically), would be cool!
  • Electro
    Offline / Send Message
    Electro polycounter lvl 18
    MoP: why bother with keyframes? The script has full explode/implode functionality, doesn't need to stomp any kind of animation data that might be there ;)
  • MoP
    Offline / Send Message
    MoP polycounter lvl 18
    Oh right, I see - even cooler then :)

    Now I want to write one for Maya :(
  • renderhjs
    Offline / Send Message
    renderhjs sublime tool
    I would isolate the 2 objects that are needed for baking each time and loop through all pairs. Just like Electro I think it would only kill existing animations and make the whole script more of a risk of using - because one does not see instantly animation changes.

    I was thinking of something like this:
    bakeexplodescript.gif
    having 1 part of the GUI generating and controlling the pair list (using a multilist element). Double clicking on one would let you select that particular pair so you can check them out if the automatic pairings went ok.
    Finally a single render button that then in the end would loop through the pairs, isolate them - > bake them and store them to some specified folder.
  • CodeFather
    Offline / Send Message
    CodeFather polycounter lvl 15
    Electro wrote: »
    Ok, so I've been selfish... but I've been meaning to release this as I've made it and been using it myself for quite some time. Sorry!

    I'll upload it later today when I get home and post the link (if I remember!)

    Here's some pics of how it works.

    http://bayimg.com/image/paelcaacc.jpg

    http://bayimg.com/image/paeldaacc.jpg


    It works with object names... LOW_objname and HIGH_objname are clearly buddies, and will stick together during explode/implode.

    For things you don't want to move, you don't give them the LOW_ prefix
    If you want only the low to move, give it the LOW_ prefix, but no matching HIGH_ buddy, and he will be a loner.

    @Electro, we're waiting man, would you post it soon, I'm eager to try it out.

    @renderhjs , that is a nice mockup ! Maybe a drop down menu with render presets will be handy too.
  • sama.van
  • boyluya
    Offline / Send Message
    boyluya polycounter lvl 10
    Electro wrote: »
    Ok, so I've been selfish... but I've been meaning to release this as I've made it and been using it myself for quite some time. Sorry!

    I'll upload it later today when I get home and post the link (if I remember!)

    Here's some pics of how it works.

    http://bayimg.com/image/paelcaacc.jpg

    http://bayimg.com/image/paeldaacc.jpg


    It works with object names... LOW_objname and HIGH_objname are clearly buddies, and will stick together during explode/implode.

    For things you don't want to move, you don't give them the LOW_ prefix
    If you want only the low to move, give it the LOW_ prefix, but no matching HIGH_ buddy, and he will be a loner.


    Can't wait to try it out! Thanks man! :)
  • boyluya
    Offline / Send Message
    boyluya polycounter lvl 10
    Any development on this script?? It'll be a big help for sure. Thanks.
  • Xoliul
    Offline / Send Message
    Xoliul polycounter lvl 14
    thatnumpty wrote: »
    anyone use the multi-sub material and "Hit Only Matching Material ID" method? (using max, dunno about other apps)


    i was taught this recently, way easier than exploding imo.

    I gotsta try this! Does it mean you sort the pairs out by giving high and low (sub)objects matching material ID's ? So you can just keep everything clumped together, but correctly setting up ID's will leave you with no messy ray intersections?
  • Noren
    Offline / Send Message
    Noren polycounter lvl 19
    Yeah, but as as soon as you want to use Material IDs for anything else it gets in the way.
    You can set up subobjects in the projection modifier to only hit specified sourceobjects. Renders separate maps though.
    I do it like earthquake, just that I have set up animated dummies and link parts of the mesh and the corresponding sourceobjects via selection modifier and linked xform to them. Often you want to decide which parts of the mesh get separated and which stay together for baking. But an automated approach would come in handy, too, I'm sure.
  • Electro
    Offline / Send Message
    Electro polycounter lvl 18
    <<temporary link until my hosting is sorted, then it'll have a nice comfy home>>
    http://dl.dropbox.com/u/2298918/explosivo_02.mzp

    Here ye go everyone...

    Don't really expect much if you go looking in the maxscript "code". It's really messily slapped together and I didn't even go back and make things functions that should be... I really didn't care or expect to be releasing it when I made it... I just made it because of my bike model with 300+ pieces that I didn't want to keyframe by hand or whatever.

    Usage:
    Name your low poly objects with the prefix LOW_
    Name your high poly objects with the prefix HIGH_

    The rest of the name following the prefixes needs to be identical. Currently this script works off of names alone, I didn't get to making anything kind of automated like I would if I were to take the time when making it again. I may look at revising this if there's enough demand for it. In general however, I think using the naming convention kind of forces people into good habits in being able to manage their scenes better... not that I would be enforcing that onto anyone ;)

    Best of luck, and happy baking!
  • CodeFather
    Offline / Send Message
    CodeFather polycounter lvl 15
    Electro wrote: »
    Usage:
    Name your low poly objects with the prefix LOW_
    Name your high poly objects with the prefix HIGH_

    The rest of the name following the prefixes needs to be identical. Currently this script works off of names alone, I didn't get to making anything kind of automated like I would if I were to take the time when making it again. I may look at revising this if there's enough demand for it. In general however, I think using the naming convention kind of forces people into good habits in being able to manage their scenes better... not that I would be enforcing that onto anyone ;)

    Dude, this script is great, I've been waiting for someone to write this for long time! :)
    I've just tested it out and it works great! The only request I would have to make is to add an option to choose different naming conventions.I like to use
    LP_" instead of "LOW_" and "HP_" instead of "HIGH_",etc. It would be even better if its possible to define more than one prefix, for example, HP_ and ZB_(ZBrush imports) to be recognized both as HIGH_ objects.So some text fields in the interface where I can put my own conventions would be really nice !
    I would test it in production soon, thank you once again :)
  • Electro
    Offline / Send Message
    Electro polycounter lvl 18
    No problem, yeah that sounds like a good addition. I'm also going to add the ability to automatically detect high and low counterparts, in which case it won't bother using a naming convention. :)

    Glad you like it so far!
  • omid3098
    Offline / Send Message
    omid3098 polycounter lvl 13
    it's really handy!
    thank you VERY much!
1
Sign In or Register to comment.