scene analyzer

Let us know if you have a nice R.U.B.E script to share!
Post Reply
tescott
Posts: 68
Joined: Wed Feb 06, 2013 6:32 pm

scene analyzer

Post by tescott » Mon Mar 18, 2013 9:47 pm

This script looks through the scene for fixtures that are overlapping duplicates. This will help address problems if you do a "Shift+D, ESC" on a fixture... thinking you canceled the duplicate operation when in fact you have just now dropped a fixture on top of another one. I've been guilty of that. Oops.

If I run into other gotchas, I'll add them to the script.

Code: Select all

// Scene analysis checker

//
// This function iterates through all the fixtures in the scene and compares their
// vertices.  If the world coordinates are identical between two or more fixtures, the 
// fixture is exactly overlapping which may not be desired (copy and paste issue?)
//
// A text line is emitted and the fixtures are selected.
// 
void checkForIdenticalFixtures()
{
   fixture [] fixtures = af();
   
   print("\nIdentical fixture test...");

   // iterate through all fixtures in the scene...
   for (uint i = 0; i < fixtures.length; i++)
   {
      fixture baseFix = fixtures[i];
      for (uint j = i + 1; j < fixtures.length; j++)
      {
         fixture testFix = fixtures[j];
         if (baseFix.getNumVertices() == testFix.getNumVertices())
         {
            uint vertexCount = baseFix.getNumVertices();
            bool identical = true; // assume identical vertices
            for (uint k = 0; k < vertexCount; k++)
            {
               if ((baseFix.getVertex(k).wx != testFix.getVertex(k).wx) || 
                     (baseFix.getVertex(k).wy != testFix.getVertex(k).wy))
               {
                  identical = false;
                  break; // out of vertice check loop
               }
            }

            if (identical)
            {
               baseFix.select();
               testFix.select();
               print("Identical fixture vertices found.  BodyA/Fix: "
                     + baseFix.getBody().getName() + "/"
                     + baseFix.getName() + " BodyB/Fix: "
                     + testFix.getBody().getName() + "/"
                     + testFix.getName());
            }
         }
      }
   }
}

void main()
{
   checkForIdenticalFixtures();
   print("Check done.");
}

Post Reply