void Settings::clearAllFields()
{
    // Fetch Dynamic-Field Dictionary.
    SimFieldDictionary* pFieldDictionary = getFieldDictionary();

    // Any Field Dictionary?
    if ( pFieldDictionary == NULL )
    {
        // No, so we're done.
        return;
    }

    // Iterate fields.
    for ( SimFieldDictionaryIterator itr(pFieldDictionary); *itr; ++itr )
    {
        // Fetch Field Entry.
        SimFieldDictionary::Entry* fieldEntry = *itr;

        // don't remove default field values
        if (dStrEndsWith(fieldEntry->slotName, "_default"))
           continue;

        // remove it.
        pFieldDictionary->setFieldValue( fieldEntry->slotName, "" );
    }
}
Beispiel #2
0
S32 TorqueMain( S32 argc, const char **argv )
{
   S32 failed = 0;

   // Initialize the subsystems.
   StandardMainLoop::init();
   Con::setVariable( "Con::Prompt", "" );
   WindowsConsole->enable( true );

   // install all drives for now until we have everything using the volume stuff
   Platform::FS::InstallFileSystems();
   Platform::FS::MountDefaults();

   bool compatMode = false;
   bool diffuseNames = false;
   bool verbose = false;
   bool saveDTS = true;
   bool saveDSQ = false;
   bool genMaterials = false;
   Torque::Path cfgPath, srcPath, destPath;

   // Parse arguments
   S32 i;
   for ( i = 1; i < argc-1; i++ )
   {
      if ( dStrEqual( argv[i], "--config" ) )
         cfgPath = makeFullPath( argv[++i] );
      else if ( dStrEqual( argv[i], "--output" ) )
         destPath = makeFullPath( argv[++i] );
      else if ( dStrEqual( argv[i], "--dsq" ) )
         saveDSQ = true;
      else if ( dStrEqual( argv[i], "--dsq-only" ) )
      {
         saveDTS = false;
         saveDSQ = true;
      }
      else if ( dStrEqual( argv[i], "--compat" ) )
         compatMode = true;
      else if ( dStrEqual( argv[i], "--diffuse" ) )
         diffuseNames = true;
      else if ( dStrEqual( argv[i], "--materials" ) )
         genMaterials = true;
      else if ( dStrEqual( argv[i], "--verbose" ) )
         verbose = true;
   }

   if ( ( i >= argc ) || ( !dStrEndsWith(argv[i], ".dae") && !dStrEndsWith(argv[i], ".kmz" ) ) )
   {
      Con::errorf( "Error: no DAE file specified.\n" );
      printUsage();
      return -1;
   }

   srcPath = makeFullPath( argv[i] );
   if ( destPath.isEmpty() )
   {
      destPath = srcPath;
      destPath.setExtension( "dts" );
   }

   if ( !cfgPath.isEmpty() )
      Con::printf( "Configuration files not yet supported.\n" );

   // Define script callbacks
   if ( verbose )
      Con::evaluate( "function UpdateTSShapeLoadProgress(%progress, %msg) { echo(%msg); }" );
   else
      Con::evaluate( "function UpdateTSShapeLoadProgress(%progress, %msg) { }" );

   if ( verbose )
      Con::printf( "Parsing configuration file...\n" );

   // Set import options
   ColladaUtils::getOptions().reset();
   ColladaUtils::getOptions().forceUpdateMaterials = genMaterials;
   ColladaUtils::getOptions().useDiffuseNames = diffuseNames;

   if ( verbose )
      Con::printf( "Reading dae file...\n" );

   // Attempt to load the DAE file
   Resource<TSShape> shape = ResourceManager::get().load( srcPath );
   if ( !shape )
   {
      Con::errorf( "Failed to convert DAE file: %s\n", srcPath.getFullPath() );
      failed = 1;
   }
   else
   {
      if ( compatMode && !shape->canWriteOldFormat() )
      {
         Con::errorf( "Warning: Attempting to save to DTS v24 but the shape "
                      "contains v26 features. Resulting DTS file may not be valid." );
      }

      FileStream outStream;

      if ( saveDSQ )
      {
         Torque::Path dsqPath( destPath );
         dsqPath.setExtension( "dsq" );

         for ( S32 i = 0; i < shape->sequences.size(); i++ )
         {
            const String& seqName = shape->getName( shape->sequences[i].nameIndex );
            if ( verbose )
               Con::printf( "Writing DSQ file for sequence '%s'...\n", seqName.c_str() );

            dsqPath.setFileName( destPath.getFileName() + "_" + seqName );

            if ( outStream.open( dsqPath, Torque::FS::File::Write ) )
            {
               shape->exportSequence( &outStream, shape->sequences[i], compatMode );
               outStream.close();
            }
            else
            {
               Con::errorf( "Failed to save sequence to %s\n", dsqPath.getFullPath().c_str() );
               failed = 1;
            }
         }
      }
      if ( saveDTS )
      {
         if ( verbose )
            Con::printf( "Writing DTS file...\n" );

         if ( outStream.open( destPath, Torque::FS::File::Write ) )
         {
            if ( saveDSQ )
               shape->sequences.setSize(0);

            shape->write( &outStream, compatMode );
            outStream.close();
         }
         else
         {
            Con::errorf( "Failed to save shape to %s\n", destPath.getFullPath().c_str() );
            failed = 1;
         }
      }
   }

   // Clean everything up.
   StandardMainLoop::shutdown();

   // Do we need to restart?
   if( StandardMainLoop::requiresRestart() )
      Platform::restartInstance();

   return failed;
}
// Recurse through the <visual_scene> adding nodes and geometry to the GuiTreeView control
static void processNode(GuiTreeViewCtrl* tree, domNode* node, S32 parentID, SceneStats& stats)
{
   stats.numNodes++;
   S32 nodeID = tree->insertItem(parentID, _GetNameOrId(node), "node", "", 0, 0);

   // Update mesh and poly counts
   for (int i = 0; i < node->getContents().getCount(); i++)
   {
      domGeometry* geom = 0;
      const char* elemName = "";

      daeElement* child = node->getContents()[i];
      switch (child->getElementType())
      {
         case COLLADA_TYPE::INSTANCE_GEOMETRY:
         {
            domInstance_geometry* instgeom = daeSafeCast<domInstance_geometry>(child);
            if (instgeom)
            {
               geom = daeSafeCast<domGeometry>(instgeom->getUrl().getElement());
               elemName = _GetNameOrId(geom);
            }
            break;
         }

         case COLLADA_TYPE::INSTANCE_CONTROLLER:
         {
            domInstance_controller* instctrl = daeSafeCast<domInstance_controller>(child);
            if (instctrl)
            {
               domController* ctrl = daeSafeCast<domController>(instctrl->getUrl().getElement());
               elemName = _GetNameOrId(ctrl);
               if (ctrl && ctrl->getSkin())
                  geom = daeSafeCast<domGeometry>(ctrl->getSkin()->getSource().getElement());
               else if (ctrl && ctrl->getMorph())
                  geom = daeSafeCast<domGeometry>(ctrl->getMorph()->getSource().getElement());
            }
            break;
         }

         case COLLADA_TYPE::INSTANCE_LIGHT:
            stats.numLights++;
            tree->insertItem(nodeID, _GetNameOrId(node), "light", "", 0, 0);
            break;
      }

      if (geom && geom->getMesh())
      {
         const char* name = _GetNameOrId(node);
         if ( dStrEqual( name, "null" ) || dStrEndsWith( name, "PIVOT" ) )
            name = _GetNameOrId( daeSafeCast<domNode>(node->getParent()) );

         stats.numMeshes++;
         tree->insertItem(nodeID, name, "mesh", "", 0, 0);

         for (S32 j = 0; j < geom->getMesh()->getTriangles_array().getCount(); j++)
            stats.numPolygons += geom->getMesh()->getTriangles_array()[j]->getCount();
         for (S32 j = 0; j < geom->getMesh()->getTristrips_array().getCount(); j++)
            stats.numPolygons += geom->getMesh()->getTristrips_array()[j]->getCount();
         for (S32 j = 0; j < geom->getMesh()->getTrifans_array().getCount(); j++)
            stats.numPolygons += geom->getMesh()->getTrifans_array()[j]->getCount();
         for (S32 j = 0; j < geom->getMesh()->getPolygons_array().getCount(); j++)
            stats.numPolygons += geom->getMesh()->getPolygons_array()[j]->getCount();
         for (S32 j = 0; j < geom->getMesh()->getPolylist_array().getCount(); j++)
            stats.numPolygons += geom->getMesh()->getPolylist_array()[j]->getCount();
      }
   }

   // Recurse into child nodes
   for (S32 i = 0; i < node->getNode_array().getCount(); i++)
      processNode(tree, node->getNode_array()[i], nodeID, stats);

   for (S32 i = 0; i < node->getInstance_node_array().getCount(); i++)
   {
      domInstance_node* instnode = node->getInstance_node_array()[i];
      domNode* node = daeSafeCast<domNode>(instnode->getUrl().getElement());
      if (node)
         processNode(tree, node, nodeID, stats);
   }
}