Esempio n. 1
0
        // http://tfc.duke.free.fr/old/models/md2.htm
        Assets::EntityModel* Md2Parser::doParseModel() {
            const char* cursor = m_begin;
            const int ident = readInt<int32_t>(cursor);
            const int version = readInt<int32_t>(cursor);
            
            if (ident != Md2Layout::Ident)
                throw AssetException() << "Unknown MD2 model ident: " << ident;
            if (version != Md2Layout::Version)
                throw AssetException() << "Unknown MD2 model version: " << version;
            
            /*const size_t skinWidth =*/ readSize<int32_t>(cursor);
            /*const size_t skinHeight =*/ readSize<int32_t>(cursor);
            /*const size_t frameSize =*/ readSize<int32_t>(cursor);
            
            const size_t skinCount = readSize<int32_t>(cursor);
            const size_t frameVertexCount = readSize<int32_t>(cursor);
            /* const size_t texCoordCount =*/ readSize<int32_t>(cursor);
            /* const size_t triangleCount =*/ readSize<int32_t>(cursor);
            const size_t commandCount = readSize<int32_t>(cursor);
            const size_t frameCount = readSize<int32_t>(cursor);
            
            const size_t skinOffset = readSize<int32_t>(cursor);
            /* const size_t texCoordOffset =*/ readSize<int32_t>(cursor);
            /* const size_t triangleOffset =*/ readSize<int32_t>(cursor);
            const size_t frameOffset = readSize<int32_t>(cursor);
            const size_t commandOffset = readSize<int32_t>(cursor);

            const Md2SkinList skins = parseSkins(m_begin + skinOffset, skinCount);
            const Md2FrameList frames = parseFrames(m_begin + frameOffset, frameCount, frameVertexCount);
            const Md2MeshList meshes = parseMeshes(m_begin + commandOffset, commandCount);
            
            return buildModel(skins, frames, meshes);
        }
Asset* AssetManager::LoadAsset(const std::string& fileName)
{
	IdIter iter = mAssetNameReferece.find(fileName);
	if (iter == mAssetNameReferece.end())
	{
		//load asset
		AvailableAsset* asset = AvailableAsset::GetAvailableAssetFromFileName(fileName, false);
		if (!asset)
		{
			//asset never exists
			MessageBox(0, std::wstring(fileName.begin(), fileName.end()).c_str(), L"Asset not found", MB_OK);
			throw AssetException(AssetException::ASSETFILENOTFOUND);
		}
		meta::metafunction_method* loader = AssetManager::getInstance()->getmeta().getfunctionbyname("Load" + asset->Type());
		if (!loader)
		{
			//loader doesn't exist
			throw AssetException(AssetException::ASSETFAILEDTOLOAD);
		}
		Asset* newAsset = loader->invoke(AssetManager::getInstance(), fileName).GetAs<Asset*>();
		if (newAsset == 0)
		{
			Log("Asset failed to load for unknown reason: " + fileName);
			return 0;
		}
    newAsset->SetName(fileName);
	newAsset->SetType(asset->Type());
		//add to the lists
		if (newAsset)
			InsertAssetInMap(newAsset);
		return newAsset;
	}
	//asset exists
	return mAssetContainer[iter->second];
}
Esempio n. 3
0
        const MipData Wad::mipData(const WadEntry& entry, const size_t mipLevel) const {
            assert(mipLevel < 4);
            
            if (entry.type() != WadEntryType::WEMip)
                throw AssetException(entry.name() + " is not a Mip entry");

            const char* cursor = m_file->begin() + entry.address() + WadLayout::TexWidthOffset;
            const size_t width = readSize<int32_t>(cursor);
            const size_t height = readSize<int32_t>(cursor);
            if (width == 0 || height == 0
//                || width > WadLayout::MaxTextureSize || height > WadLayout::MaxTextureSize
                )
                throw AssetException(entry.name() + " has invalid dimensions");

            advance<int32_t>(cursor, mipLevel);
            const size_t offset = readSize<int32_t>(cursor);
            const size_t divisor = 1 << mipLevel;
            const size_t size = width * height / (divisor * divisor);
            
            if (offset + size > entry.size())
                throw AssetException("Mip data of '" + entry.name() + "' is out of bounds");
            
            cursor = m_file->begin() + entry.address() + offset;
            return MipData(cursor, cursor + size);
        }
Esempio n. 4
0
 void Wad::loadEntries() {
     if (WadLayout::NumEntriesAddress + sizeof(int32_t) >= m_file->size() ||
         WadLayout::DirOffsetAddress + sizeof(int32_t) >= m_file->size())
         throw AssetException("Invalid wad layout");
     
     const char* cursor = m_file->begin() + WadLayout::NumEntriesAddress;
     const size_t entryCount = readSize<int32_t>(cursor);
     cursor = m_file->begin() + WadLayout::DirOffsetAddress;
     const size_t directoryAddr = readSize<int32_t>(cursor);
     
     if (directoryAddr  >= m_file->size())
         throw AssetException("Wad directory beyond end of file");
     
     char entryType;
     char entryName[WadLayout::DirEntryNameSize];
     
     cursor = m_file->begin() + directoryAddr;
     
     for (size_t i = 0; i < entryCount; i++) {
         size_t entryAddress = readSize<int32_t>(cursor);
         size_t entrySize = readSize<int32_t>(cursor);
         
         if (entryAddress + entrySize > m_file->size())
             throw AssetException("Wad entry beyond end of file");
         
         cursor += WadLayout::DirEntryTypeOffset;
         readBytes(cursor, &entryType, 1);
         cursor += WadLayout::DirEntryNameOffset;
         readBytes(cursor, entryName, WadLayout::DirEntryNameSize);
         
         // might leak if there are duplicate entries
         m_entries.push_back(WadEntry(entryName, entryType, entryAddress, entrySize));
     }
 }
Esempio n. 5
0
 const MipSize Wad::mipSize(const WadEntry& entry) const {
     if (entry.type() != WadEntryType::WEMip)
         throw AssetException(entry.name() + " is not a Mip entry");
     
     const char* cursor = m_file->begin() + entry.address() + WadLayout::TexWidthOffset;
     const size_t width = readSize<int32_t>(cursor);
     const size_t height = readSize<int32_t>(cursor);
     if (width == 0 || height == 0)
         throw AssetException(entry.name() + " has invalid dimensions");
     
     return MipSize(width, height);
 }
AssetHandle AssetManager::GetAsset( unsigned assetId )
{
	AssetIter iter = mAssetContainer.find(assetId);
	if (iter == mAssetContainer.end())
		throw AssetException(AssetException::ASSETNOTFOUND);
	return AssetHandle(iter->second);
}
std::string AssetManager::GetAbsolutePathOfFile(const std::string& filename, bool createIfNotFound)
{
	AvailableAsset* aa = AvailableAsset::GetAvailableAssetFromFileName(filename, createIfNotFound);
	if (!aa)
		throw AssetException(AssetException::ASSETINVALID);
	return aa->FileID().Filename();
}
Sound* AssetManager::LoadMusics( const std::string& musicName )
{
  std::string fullPath = GetAbsolutePathOfFile(musicName);
  Sound* pSound = nullptr; // AudioManager::getInstance()->GetAudio(fullPath);
  //pSound->SetName(musicName);
  throw AssetException(AssetException::ASSETINVALID);

  return pSound;
}
Esempio n. 9
0
//------------------------------------------------------------------------------
void BodyFixedPoint::UpdateBodyFixedLocation()
{
   if (stateType == "Cartesian")
   {
      bfLocation[0] = location[0];
      bfLocation[1] = location[1];
      bfLocation[2] = location[2];
   }
   // Otherwise, convert from input type to Cartesian
   else if (stateType == "Spherical")
   {
      Rvector3 spherical(location[0], location[1], location[2]);
      Rvector3 cart;
      if (horizon == "Sphere")
      {
         cart = BodyFixedStateConverterUtil::SphericalToCartesian(spherical,
                flattening, meanEquatorialRadius);
         bfLocation[0] = cart[0];
         bfLocation[1] = cart[1];
         bfLocation[2] = cart[2];
      }
      else if (horizon == "Ellipsoid")
      {
         cart = BodyFixedStateConverterUtil::SphericalEllipsoidToCartesian(spherical,
                flattening, meanEquatorialRadius);
         bfLocation[0] = cart[0];
         bfLocation[1] = cart[1];
         bfLocation[2] = cart[2];
      }
      else
         throw AssetException("Unable to set body fixed location for BodyFixedPoint \"" +
               instanceName + "\"; horizon reference is not a recognized type (known "
                     "types are either \"Sphere\" or \"Ellipsoid\")");
   }
   else
   {
      throw AssetException("Unable to set body fixed location for BodyFixedPoint \"" +
            instanceName + "\"; state type is not a recognized type (known "
                  "types are either \"Cartesian\" or \"Spherical\")");
   }

}
AssetHandle AssetManager::GetAsset(std::string assetId)
{
	int id = GetIdFromName(assetId);
	if (id == -1)
	{
		Asset* a = LoadAsset(assetId);
		if (!a)
			throw AssetException(AssetException::ASSETFAILEDTOLOAD);
		return a;
	}
	return GetAsset((unsigned)id);
}
Esempio n. 11
0
//------------------------------------------------------------------------------
Real GroundStation::SetRealParameter(const Integer id,
                                      const Real value)
{
   if (id == MINIMUM_ELEVATION_ANGLE)
   {
	  if (( value < -90.0)||( value > 90.0))
         throw AssetException("Minimum elevation angle set to " + GetName() + " is not in range [-90.0, 90.0]\n");
	  minElevationAngle = value;
	  return minElevationAngle;
   }
   
   return GroundstationInterface::SetRealParameter(id, value);
}
Esempio n. 12
0
 Wad::Wad(const Path& path) :
 m_file(Disk::openFile(path)) {
     if (m_file == NULL)
         throw AssetException("Cannot open wad file " + path.asString());
     loadEntries();
 }
Esempio n. 13
0
//------------------------------------------------------------------------------
bool BodyFixedPoint::SetStringParameter(const Integer id,
                                       const std::string &value)
{
   if (IsParameterReadOnly(id))
       return false;

   static bool firstTimeWarning = true;
   bool        retval           = false;
   std::string stateTypeList    = "Cartesian, Spherical";
   std::string horizonList      = "Sphere, Ellipsoid";
   std::string currentStateType = stateType;
   std::string currentHorizon   = horizon;

   if (id == CENTRAL_BODY)
   {
      if (value != SolarSystem::EARTH_NAME)
      {
         std::string errmsg =
            "The value of \"" + value + "\" for field \"CentralBody\""
            " on object \"" + instanceName + "\" is not an allowed value.\n"
            "The allowed values are: [ " + SolarSystem::EARTH_NAME + " ]. ";
         throw AssetException(errmsg);
      }
      if (theBody)
         theBody = NULL;
      cBodyName = value;
      retval = true;
   }
   else if (id == STATE_TYPE)
   {
      std::string v = value;
      if (v == "Geographical") // deprecated value
      {
        v = "Spherical";
        // write one warning per GMAT session
        if (firstTimeWarning)
        {
           std::string msg =
              "The value of \"" + value + "\" for field \"StateType\""
              " on object \"" + instanceName + "\" is not an allowed value.\n"
              "The allowed values are: [ " + stateTypeList + " ]. ";
           MessageInterface::ShowMessage("*** WARNING *** " + msg + "\n");
           firstTimeWarning = false;
        }
      }

      if ((v == "Cartesian") || (v == "Spherical"))
      {
         stateType = v;
         if (v == "Cartesian")
         {
            locationLabels[0] = "X";
            locationLabels[1] = "Y";
            locationLabels[2] = "Z";
            locationUnits[0] = "km";
            locationUnits[1] = "km";
            locationUnits[2] = "km";
         }
         else
         {
            locationLabels[0] = "Latitude";
            locationLabels[1] = "Longitude";
            locationLabels[2] = "Altitude";
            locationUnits[0] = "deg";
            locationUnits[1] = "deg";
            locationUnits[2] = "km";
         }
         if (currentStateType != stateType)
         {
            Rvector3 locIn(location[0], location[1], location[2]);
            Rvector3 locOut = BodyFixedStateConverterUtil::Convert(locIn, currentStateType, horizon, stateType, horizon,
                                                           flattening, meanEquatorialRadius);
            location[0] = locOut[0];
            location[1] = locOut[1];
            location[2] = locOut[2];
         }
         retval = true;
      }
      else
      {
         std::string errmsg =
            "The value of \"" + value + "\" for field \"StateType\""
            " on object \"" + instanceName + "\" is not an allowed value.\n"
            "The allowed values are: [ " + stateTypeList + " ]. ";
         throw AssetException(errmsg);
      }
   }
   else if (id == HORIZON_REFERENCE)
   {
      if ((value == "Sphere") || (value == "Ellipsoid"))
      {
         horizon = value;
         if (currentHorizon != horizon)
         {
            Rvector3 locIn(location[0], location[1], location[2]);
            Rvector3 locOut = BodyFixedStateConverterUtil::Convert(locIn, stateType, currentHorizon, stateType, horizon,
                                                       flattening, meanEquatorialRadius);
            location[0] = locOut[0];
            location[1] = locOut[1];
            location[2] = locOut[2];
         }
         retval = true;
      }
      else
      {
         std::string errmsg =
            "The value of \"" + value + "\" for field \"HorizonReference\""
            " on object \"" + instanceName + "\" is not an allowed value.\n"
            "The allowed values are: [ " + horizonList + " ]. ";
         throw AssetException(errmsg);
      }
   }
   else
      retval = SpacePoint::SetStringParameter(id, value);

   return retval;
}
Esempio n. 14
0
//---------------------------------------------------------------------------
bool BodyFixedPoint::Initialize()
{
   // Initialize the body data
   if (!theBody)
   {
      if (!solarSystem)
         throw AssetException("Unable to initialize ground station " +
               instanceName + "; its solar system is not set\n");
      theBody = solarSystem->GetBody(cBodyName);
      if (!theBody)
      {
         throw AssetException("Unable to initialize ground station " +
               instanceName + "; its origin is not set\n");
      }
   }

   // Get required data from the body
   flattening            = theBody->GetRealParameter("Flattening");
   meanEquatorialRadius  = theBody->GetRealParameter("EquatorialRadius");

   // @todo: This should work, but doesn't.  It needs to be figured out
   //        eventually, I think.
   //
   //        One clue: When walking through this code in nemiver (Linux
   //        debugger), I saw a covariance matrix destructor being called,
   //        and did not expect that.  Maybe there is something around that
   //        piece...
   
   // set up local coordinate systems - delete the old ones if they have already been created
   //if (mj2kcs)   delete mj2kcs;
   //if (bfcs)     delete bfcs;
   if (!mj2kcs)
      mj2kcs  = CoordinateSystem::CreateLocalCoordinateSystem("mj2kcs", "MJ2000Eq", theBody,
                                                           NULL, NULL, theBody->GetJ2000Body(), solarSystem);
   if (!bfcs)
      bfcs    = CoordinateSystem::CreateLocalCoordinateSystem("bfcs", "BodyFixed", theBody,
                                                           NULL, NULL, theBody->GetJ2000Body(), solarSystem);

   // Calculate the body-fixed Cartesian position
   // If it was input in Cartesian, we're done
   UpdateBodyFixedLocation();

   #ifdef DEBUG_INIT
      MessageInterface::ShowMessage("...BodyFixedPoint %s Initialized!\n", instanceName.c_str());
   #endif

   #ifdef TEST_BODYFIXED_POINT
      MessageInterface::ShowMessage("For %s, %s %s location [%lf "
            "%lf %lf] --> XYZ [%lf %lf %lf]\n", instanceName.c_str(),
            stateType.c_str(), horizon.c_str(), location[0], location[1],
            location[2], bfLocation[0], bfLocation[1], bfLocation[2]);
      // Check the MJ2000 methods
      if (theBody == NULL)
      {
         MessageInterface::ShowMessage(
               "Error initializing ground station %s: theBody is not set\n",
               instanceName.c_str());
         return false;
      }
      if (bfcs == NULL)
      {
         MessageInterface::ShowMessage(
               "Error initializing ground station %s: bfcs is not set\n",
               instanceName.c_str());
         return false;
      }
      if (mj2kcs == NULL)
      {
         MessageInterface::ShowMessage(
               "Error initializing ground station %s: mj2kcs is not set\n",
               instanceName.c_str());
         return false;
      }

      Rvector6 j2kState = GetMJ2000State(GmatTimeConstants::MJD_OF_J2000);
      MessageInterface::ShowMessage("The resulting MJ2000 Cartesian state is "
            "\n   [%s]\n", j2kState.ToString(16).c_str());
   #endif
   return true;
}