Exemplo n.º 1
0
/*
 * Load IQM model from disc and parse it.
 *
 * @param model_fname - file name of a supposed IQM data file
 * @return NULL if file does not exist, a valid pointer to a model otherwise
 *
 */
struct ov_model *
model_iqm_load_model(char *model_fname)
{
    struct ov_model *rc = NULL;
    struct _iqm_header *imodel = malloc(sizeof(struct _iqm_header));
    unsigned char *data;
  
    FILE *file;

    file = fopen (model_fname, "rb");
    if (!file) {
        fprintf (stderr, "cannot open model '%s'\n", model_fname);
        return rc;
    } 

    printf ("loading iqm model '%s'\n", model_fname);
    fread (imodel, 1, sizeof (struct _iqm_header), file);
    if (strcmp(imodel->magic, IQM_MAGIC) != 0) {
        fprintf (stderr, "not and IQM file '%s'\n", model_fname);
        fclose (file);
        return rc;
    }
    if (imodel->version != IQM_VERSION) {
        fprintf (stderr, "unknown IQM version '%s'\n", model_fname);
        fclose (file);
        return NULL;
    }

    data = malloc (imodel->filesize);
    fseek(file , 0, 0);
    fread (data, 1, imodel->filesize, file);
    fclose (file);
    rc = _load_model (data, imodel, model_fname);
    free (data);
    return rc;
}
Exemplo n.º 2
0
dmz::RenderPluginObjectOSG::DefStruct *
dmz::RenderPluginObjectOSG::_create_def_struct (const ObjectType &Type) {

   DefStruct *result = _defTable.lookup (Type.get_handle ());

   Config modelList;

   if (!result && Type.get_config ().lookup_all_config ("render.model", modelList)) {

      result = new DefStruct;

      if (_defTable.store (Type.get_handle (), result)) {

         _typeTable.store (Type.get_handle (), result);

         ConfigIterator it;
         Config model;

         unsigned int place (1);

         StateStruct *currentState (0);

         while (modelList.get_next_config (it, model)) {

            const String ResourceName (config_to_string ("resource", model));
            const Boolean NoModel (config_to_boolean ("none", model));
            Mask state;
            String stateName;
            const Boolean StateNameFound (model.lookup_attribute ("state", stateName));

            if (StateNameFound) { _defs.lookup_state (stateName, state); }

            if (!StateNameFound || state) {

               ModelStruct *ms = (NoModel ? &_noModel : _load_model (ResourceName));

               if (ms) {

                  unsigned int switchPlace (StateNameFound ? place : 0);
                  if (StateNameFound) { place++; }

                  if (((switchPlace + 1) > result->model->getNumChildren ()) ||
                        !result->model->getChild (switchPlace)) {

                     result->model->insertChild (switchPlace, ms->model.get ());

                     if (switchPlace) {

                        StateStruct *ss (new StateStruct (switchPlace, state));

                        if (currentState) {

                           currentState->next = ss;
                           currentState = ss;
                        }
                        else { result->stateMap = currentState = ss; }
                     }
                  }
               }
            }
         }
      }
      else { delete result; result = 0; }
   }

   return result;
}