Announcement

Collapse
No announcement yet.

Maxscript: Flip Normals

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

  • Maxscript: Flip Normals

    Hey guys,
    I have quite a simple problem here: We often get lots of CAD data. On some parts, the normals are flipped, so far so good.

    Because the normal-modifier does not work on imported Nurbs data (breaks normals), I have to use the following workaround:

    Select the part you want to flip -> right click -> convert to editable poly -> go to polygon sub-object-mode -> select all polygons -> use "flip" in the edit polygons section of the editable poly.

    This way, all the normals are preserved and correctly flipped. However, this becomes a tedious process, because there is lots of clicking involved. I tried to put this into a small script with a little help from the macro recorder, but somehow it gets stuck when selecting all polygons, because polycount on every part varies. Is there somebody out there who could give some help?
    Last edited by kosso_olli; 17-01-2020, 03:22 AM.
    https://www.behance.net/Oliver_Kossatz

  • #2
    What is the difference between converting the part you need to an editable poly, and just sticking an editpoly modifier on it?
    Doesnt that both break the normals?

    (Are we talking Catia Body objects here?)
    Kind Regards,
    Morne

    Comment


    • #3
      I dont have a body object handy to test this on, but try this.
      Stick this into the Maxscript editor, then drag it to a toolbar to create a button

      Code:
      /* Use at own Risk!!! */
      
      (
          myObjects = for o in selection where superClassOf o == geometryClass collect o
      
          for i = 1 to myObjects.count do
          (
              select myObjects[i]
              macros.run "Modifier Stack" "Convert_to_Poly"
              subobjectLevel = 4
              max select all
              $.EditablePoly.flipNormals 1
              subobjectLevel = 0
          )
      )
      It will check if you have any objects selected. If you do, it will convert all selected geometry objects to poly (even if they are already poly)
      Then it will one by one go and flip all the normals of each of those objects.

      Code may need slight modification for body objects. If you can get me a single simple body object to test this one if it doesnt work I'll see what I can do to get it to work.

      Otherwise just modify the code you already have. While you are in poly mode, "max select all" will select all polygons for you
      Kind Regards,
      Morne

      Comment


      • #4
        Hey, nice to see you putting code out there Morne!

        Comment


        • #5
          Originally posted by Morne View Post
          I dont have a body object handy to test this on, but try this.
          Stick this into the Maxscript editor, then drag it to a toolbar to create a button

          Code:
          /* Use at own Risk!!! */
          
          (
          myObjects = for o in selection where superClassOf o == geometryClass collect o
          
          for i = 1 to myObjects.count do
          (
          select myObjects[i]
          macros.run "Modifier Stack" "Convert_to_Poly"
          subobjectLevel = 4
          max select all
          $.EditablePoly.flipNormals 1
          subobjectLevel = 0
          )
          )
          It will check if you have any objects selected. If you do, it will convert all selected geometry objects to poly (even if they are already poly)
          Then it will one by one go and flip all the normals of each of those objects.

          Code may need slight modification for body objects. If you can get me a single simple body object to test this one if it doesnt work I'll see what I can do to get it to work.

          Otherwise just modify the code you already have. While you are in poly mode, "max select all" will select all polygons for you
          Thank you very much, this works like a charm!
          We have the parts in Max as geometry. Importing them as body objects from Catia is not a good idea, considering the number of parts.
          Regarding the edit poly versus convert to poly: No, it is not the same. Edit poly modifier on top of imported Edit mesh breaks normals, convert to poly preserves them. Take a look at the images:

          Convert to Editable Poly:

          Click image for larger version

Name:	convert_poly.PNG
Views:	2187
Size:	48.9 KB
ID:	1058637

          Edit Poly modifier on top of Edit Mesh:

          Click image for larger version

Name:	edit_poly.PNG
Views:	2146
Size:	95.7 KB
ID:	1058638
          https://www.behance.net/Oliver_Kossatz

          Comment


          • #6
            Just curious. I thought the problems was that some parts needed flipping. Doesn't the script flip all surfaces, equal to adding a Normal-modifier and check "flip normals"? If i understood it correct, that it is indeed for only some parts - how does the script know what parts (I am assuming you are talking about sub-objects).
            Kindly,
            Haider

            Comment


            • #7
              Originally posted by Haider_of_Sweden View Post
              If i understood it correct, that it is indeed for only some parts - how does the script know what parts (I am assuming you are talking about sub-objects).
              No. This script is working on the whole objects, not just individual polygons. And no, it is not the same as adding a normal modifier. As shown in the screenshot, adding a normal modifier in CAD-data originating from Nurbs will break normals. The script does not, and that is the whole point.
              https://www.behance.net/Oliver_Kossatz

              Comment


              • #8
                Originally posted by kosso_olli View Post

                No. This script is working on the whole objects, not just individual polygons. And no, it is not the same as adding a normal modifier. As shown in the screenshot, adding a normal modifier in CAD-data originating from Nurbs will break normals. The script does not, and that is the whole point.
                If I may ask, could you please provide a sample DWG that has those problems and which the script solves? I still don't get it.
                Kindly,
                Haider

                Comment


                • #9
                  We do not get the data as DWG.
                  Our data comes from Catpart, Iges or Step.
                  Last edited by kosso_olli; 15-06-2020, 01:43 AM.
                  https://www.behance.net/Oliver_Kossatz

                  Comment


                  • #10
                    Okay! Do you have any sample files you could provide, because I would like to try this solution.
                    the file doesn't need to be any fancy useful model or so, for me it's more important to see the problem and its solution.
                    Kindly,
                    Haider

                    Comment


                    • #11
                      No. You can easily try it yourself with any Nurbs data coming from Catpart/Iges/Step. Sites like GrabCad have loads of free models.
                      Put an Edit Normal Modifier onto the geometry and watch closely.
                      https://www.behance.net/Oliver_Kossatz

                      Comment

                      Working...
                      X