Announcement

Collapse
No announcement yet.

Script question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script question

    I thought I'd be so cheeky as to post this question here due to the fact that I prefer this forum to any others.

    I'm trying to automate some things I seem to need to do very often when opening .skp files in 3dsmax design 2010. Quite a lot of objects in the file seem to be ok, but are not when you try to edit them. It boils down to this:
    • Convert them to poly
    • Add edit normals modifier
    • Select all normals
    • Hit reset in the normals modifier
    • Reset xform
    • Collapse to mesh for optimizing file size

    What I can't seem to get to work, and can't find any good info in the help file or on the web, is how to select all the normals in the edit normals modifier, and then reset them?
    So far this is what the maxscript listener returns when resetting:
    Code:
    $.modifiers[#Edit_Normals].EditNormalsMod.Reset ()
    I seem to need to be able to store the normals I think, and this is what I have so far:
    Code:
    Normalselection = #{}
    addmodifier $ (Edit_Normals())
    $.modifiers[#Edit_Normals].EditNormalsMod.Select #all
    $.modifiers[#Edit_Normals].EditNormalsMod.Reset ()
    ResetXForm $
    maxOps.CollapseNode $ off
    ConvertToMesh $
    Obviously the "#all" is not valid. I have tried to get it to read the array called "Normalselection", but this doesn't work. Are the normals even stored in the variable?
    So what is the command for selecting every normal in the edit normals modifier?
    Can anyone help me with this?
    Last edited by trixian; 07-01-2010, 08:03 AM.
    Signing out,
    Christian

  • #2
    Yeah #all doesnt seem to work here, you can try to replace it using the GetNumNormals() method:
    Code:
    $.modifiers[#Edit_Normals].EditNormalsMod.Select #{1..($.modifiers[#Edit_Normals].EditNormalsMod.GetNumNormals())}

    Comment


    • #3
      Also, for modifying all the selected objects, you could do something like this:

      Code:
      for o in selection do (
          addmodifier o (Edit_Normals())
          en_mod = o.modifiers[#Edit_Normals].EditNormalsMod
          en_mod.Select #{1..(en_mod.GetNumNormals())}
          en_mod.Reset ()
          ResetXForm o
          maxOps.CollapseNode o true
          ConvertToMesh o
      )
      Hope it helps

      Comment


      • #4
        Hmm, well taking your first example and adding some stuff from the original, executes fine with no errors, but the object I tried it on still has the mesh issue, leading me to believe that the script only appears to do what it is supposed to.

        Same happens with your for-loop example.

        To explain, the faces of the objects from sketchup can't be flipped sometimes. You hit the flip button and they change to a darker shade, but don't actually flip (I always work with backfaces culled).
        Only after manually selecting the normals and hitting the reset button does this work.

        The attached file should illustrate the problem.
        Attached Files
        Signing out,
        Christian

        Comment


        • #5
          Looking at your sample I don't really see whats the problem, if I run the script on it all the normals become dark blue (Unespecified), the same as if I select them all manually and reset.

          Are you sure the problem is not due the smoothing groups? I found that many imported objects mess with that. I usually solve it welding all the coincident vertices and applying a smooth modifier with Auto Smooth enabled and a generic value of 30 in threshold, or some lower value like 1.0 if you don't mind having some faceting in curved objects.

          I don't have experience working with SU, so I can't be o much help ...

          Comment


          • #6
            Hey. First off, I'd like to thank you for looking into this
            The smoothing is a different problem, but gets solved when fixing the normals (naturally).
            Did you try to flip a face on the object i attached? Here in Max Design 2010 (64bit) the face doesn't flip, it just changes its shade to a darker version. After doing the manual normal reset, it flips like it should (visible with backface culling on). Welding the vertices actually doesn't solve this issue, but I usually weld them and autosmooth the object after all the other steps. I really hope this isn't one of those issues where I'm the only one experiencing the problem, while it works fine for everyone else
            Signing out,
            Christian

            Comment


            • #7
              You are welcome trixian

              now I realize there is something strange when you flip the faces, the mesh normal information seems to be messed when imported. Can you try to use this script?

              Code:
              for o in selection do (
                  sm_mod = Smooth()
                  addmodifier o sm_mod
                  sm_mod.autosmooth = true
                  sm_mod.threshold = 1.0
                  ResetXForm o
                  maxOps.CollapseNode o true
                  ConvertToMesh o
              )
              Instead of editing the normals I apply a smooth modifier to try to reset the normal information and it seems to solve it on my end.

              Comment


              • #8
                Nice. It works on nearly all objects, though the worse the models look initially (from architects) the less success the script has. On some objects, I had to flip a face 3 times before it flipped properly....like it went through some sort of stage for every click, shading slightly differently each time. For the more straight forward objects, I works perfectly. I added a "ConvertToPoly" up front and a "Vertex_Weld" to it for general mesh hygiene concerns, and now it seems to do the trick 90% of the time. Thanks.

                It worries me though that Autodesk included this feature in the Connectivity Pack without properly testing if it actually works right.
                Then again, these models I often get from Architects "doodling" in sketchup are nearly always really strange and badly modelled.
                (No offense to any Architects out there who actually know how to model)
                Last edited by trixian; 12-01-2010, 02:29 AM.
                Signing out,
                Christian

                Comment

                Working...
                X