예제 #1
0
void Loader::LoadVertexList(Stream::IStream& stream)
{
   Stream::EndianAwareFilter filter(stream);

   WORD wNumVertices = filter.Read16LE();
   m_data.m_vecVertices.resize(wNumVertices);

   if (wNumVertices >= c_uiMaxVertices)
      throw Exception(_T("invalid number of vertices"), __FILE__, __LINE__);

   for (WORD w = 0; w<wNumVertices; w++)
   {
      Vertex& v = m_data.m_vecVertices[w];

      BYTE bFlags = stream.ReadByte();
      if ((bFlags & ~(flagSelected | flagSelected2 | flagHidden)) != 0)
          throw Exception(_T("invalid vertex flags"), __FILE__, __LINE__);

      float afVertex[3];
      afVertex[0] = ReadFloat(stream);
      afVertex[1] = ReadFloat(stream);
      afVertex[2] = ReadFloat(stream);

      char cBoneId = static_cast<char>(stream.ReadByte());
      /*BYTE bReferenceCount =*/ stream.ReadByte();

      v.m_vPos = Vector3d(afVertex[0], afVertex[1], afVertex[2]);
      v.m_iJointIndex = cBoneId;
   }
}
예제 #2
0
void Loader::LoadTriangleList(Stream::IStream& stream)
{
   Stream::EndianAwareFilter filter(stream);

   WORD wNumTriangles = filter.Read16LE();
   m_data.m_vecTriangles.resize(wNumTriangles);

   if (wNumTriangles >= c_uiMaxTriangles)
      throw Exception(_T("invalid number of triangles"), __FILE__, __LINE__);

   for (WORD w = 0; w<wNumTriangles; w++)
   {
      TriangleData t;

      t.wFlags = filter.Read16LE();
      if ((t.wFlags & ~(flagSelected | flagSelected2 | flagHidden)) != 0)
          throw Exception(_T("invalid triangle flags"), __FILE__, __LINE__);

      t.awVertexIndices[0] = filter.Read16LE();
      t.awVertexIndices[1] = filter.Read16LE();
      t.awVertexIndices[2] = filter.Read16LE();

      if (t.awVertexIndices[0] >= m_data.m_vecVertices.size() ||
          t.awVertexIndices[1] >= m_data.m_vecVertices.size() ||
          t.awVertexIndices[2] >= m_data.m_vecVertices.size())
         throw Exception(_T("invalid vertex index value"), __FILE__, __LINE__);

      for (int i=0; i<3; i++)
         for (int j=0; j<3; j++)
            t.afVertexNormals[i][j] = ReadFloat(stream);

      for (int i=0; i<3; i++)
         t.s[i] = ReadFloat(stream);
      for (int i=0; i<3; i++)
         t.t[i] = ReadFloat(stream);

      // check bSmoothingGroup
      t.bSmoothingGroup = stream.ReadByte(); /// 1-32
      if (t.bSmoothingGroup < 1 || t.bSmoothingGroup > 32)
          throw Exception(_T("invalid smooth group value"), __FILE__, __LINE__);

      t.bGroupIndex = stream.ReadByte();

      // copy over to Triangle
      MilkShape3D::Triangle& tri = m_data.m_vecTriangles[w];
      for (int i=0; i<3; i++)
      {
         tri.auiVertexIndices[i] = t.awVertexIndices[i];

         tri.aNormals[i] = Vector3d(
            t.afVertexNormals[i][0],
            t.afVertexNormals[i][1],
            t.afVertexNormals[i][2]);

         // reverse t; MilkShape3D stores them in reverse
         tri.aTex[i] = TexCoord2f(t.s[i], /*1.0f -*/ t.t[i]);
      }
   }
}
예제 #3
0
void Loader::LoadGroupList(Stream::IStream& stream)
{
   Stream::EndianAwareFilter filter(stream);

   WORD wNumGroups = filter.Read16LE();
   m_data.m_vecGroups.resize(wNumGroups);

   if (wNumGroups > c_uiMaxGroups)
      throw Exception(_T("invalid number of groups"), __FILE__, __LINE__);

   for (WORD w = 0; w<wNumGroups; w++)
   {
      GroupData g;

      g.bFlags = stream.ReadByte();
      if ((g.bFlags & ~(flagSelected | flagHidden)) != 0)
         throw Exception(_T("invalid group flags"), __FILE__, __LINE__);

      g.cszName = ReadString<32>(stream, _T("error reading group name"));

      WORD wNumTriangleIndices = filter.Read16LE();
      if (wNumTriangleIndices > 0)
      {
         m_data.m_vecGroups[w].m_vecTriangleIndices.resize(wNumTriangleIndices);

         for (WORD i=0; i<wNumTriangleIndices; i++)
         {
            WORD wIndex = filter.Read16LE();
            if (wIndex >= m_data.m_vecTriangles.size())
               throw Exception(_T("invalid triangle index value"), __FILE__, __LINE__);

            m_data.m_vecGroups[w].m_vecTriangleIndices[i] = wIndex;
         }
      }

      g.cMaterialIndex = static_cast<char>(stream.ReadByte());

      m_data.m_vecGroups[w].m_uiMaterialIndex = g.cMaterialIndex;
   }
}
예제 #4
0
void Loader::LoadMaterialsList(Stream::IStream& stream)
{
   Stream::EndianAwareFilter filter(stream);

   WORD wNumMaterials = filter.Read16LE();
   m_data.m_vecMaterials.resize(wNumMaterials);

   if (wNumMaterials > c_uiMaxMaterials)
      throw Exception(_T("invalid number of materials"), __FILE__, __LINE__);

   for (WORD w = 0; w<wNumMaterials; w++)
   {
      Material& m = m_data.m_vecMaterials[w];

      m.cszName = ReadString<32>(stream, _T("error reading material name"));

      for (unsigned int i=0; i<4; i++)
         m.afAmbient[i] = ReadFloat(stream);

      for (unsigned int i=0; i<4; i++)
         m.afDiffuse[i] = ReadFloat(stream);

      for (unsigned int i=0; i<4; i++)
         m.afSpecular[i] = ReadFloat(stream);

      for (unsigned int i=0; i<4; i++)
         m.afEmissive[i] = ReadFloat(stream);

      m.fShininess = ReadFloat(stream);
      m.fTransparency = ReadFloat(stream);

      m.bMode = stream.ReadByte();

      m.cszTexture = ReadString<128>(stream, _T("error reading material texture"));
      m.cszAlphaMap = ReadString<128>(stream, _T("error reading material alpha map"));
   }
}
void PcxImageReader::Load(Stream::IStream& stream)
{
   // read header
   PCXHeader header = {0};
   DWORD dwRead = 0;
   stream.Read(&header, sizeof(header), dwRead);

   // check header
   if (header.manufacturer != 0x0a)
      throw Exception(_T("wrong manufacturer number!"), __FILE__, __LINE__);

   // allocate pixels
   m_uiWidth = header.xmax - header.xmin + 1;
   m_uiHeight = header.ymax - header.ymin + 1;

   m_vecPixels.resize(m_uiWidth * m_uiHeight);

   // read in palette
   ULONGLONG ullPos = stream.Position();

   BYTE palette[256][3];
   stream.Seek(-768LL, Stream::IStream::seekEnd);
   stream.Read(&palette, sizeof(palette), dwRead);
   ATLASSERT(dwRead == sizeof(palette));

   stream.Seek(static_cast<LONGLONG>(ullPos), Stream::IStream::seekBegin);

   // read in image
   // \note only supports 8-bit at the moment
   unsigned int uiBitcount = header.bitsPerPixel * header.numColorPlanes;
   if (uiBitcount != 8)
      throw Exception(_T("wrong bit count!"), __FILE__, __LINE__);

   // read pixel data
   for (unsigned int y = 0; y < m_uiHeight; ++y)
   {
      Color* pColor = &m_vecPixels[y * m_uiWidth];
      unsigned int uiBytesLeft = header.bytesPerScanLine;

      // decode line
      unsigned int uiCount = 0;
      BYTE ubValue = 0;
      while (uiBytesLeft--)
      {
         if (uiCount == 0)
         {
            BYTE b = stream.ReadByte();
            if (b < 0xc0)
            {
               uiCount = 1;
               ubValue = b;
            }
            else
            {
               uiCount = b - 0xc0;
               ubValue = stream.ReadByte();
            }
         }

         uiCount--;

         *pColor = Color(
            palette[ubValue][0],
            palette[ubValue][1],
            palette[ubValue][2],
            255); // opaque
         pColor++;
      }
   }
}
예제 #6
0
void Loader::LoadJointList(Stream::IStream& stream)
{
   Stream::EndianAwareFilter filter(stream);

   WORD wNumJoints = filter.Read16LE();
   m_data.m_vecJoints.resize(wNumJoints);

   if (wNumJoints > c_uiMaxJoints)
      throw Exception(_T("invalid number of joints"), __FILE__, __LINE__);

   for (WORD wJoint = 0; wJoint<wNumJoints; wJoint++)
   {
      Joint& j = m_data.m_vecJoints[wJoint];

      j.bFlags = stream.ReadByte();
      if ((j.bFlags & ~(flagSelected | flagDirty | flagIsKey)) != 0)
         throw Exception(_T("invalid joint flags"), __FILE__, __LINE__);

      j.cszName = ReadString<32>(stream, _T("error reading joint name"));
      j.cszParentName = ReadString<32>(stream, _T("error reading joint parent name"));

      float x, y, z;
      x = ReadFloat(stream);
      y = ReadFloat(stream);
      z = ReadFloat(stream);
      j.rotation = RotAngle3d(x, y, z);

      x = ReadFloat(stream);
      y = ReadFloat(stream);
      z = ReadFloat(stream);
      j.vPosition = Vector3d(x, y, z);

      WORD wNumKeyFramesRot = filter.Read16LE();
      WORD wNumKeyFramesTrans = filter.Read16LE();

      j.RotationKeys().resize(wNumKeyFramesRot);
      for (WORD wKeyFramesRot=0; wKeyFramesRot<wNumKeyFramesRot; wKeyFramesRot++)
      {
         float fTime = ReadFloat(stream);
         fTime *= m_data.m_animationData.fAnimationFPS;

         x = ReadFloat(stream);
         y = ReadFloat(stream);
         z = ReadFloat(stream);

         j.RotationKeys()[wKeyFramesRot] = KeyframeRot(fTime, RotAngle3d(x, y, z));
      }

      j.PositionKeys().resize(wNumKeyFramesTrans);
      for (WORD wKeyFramesTrans=0; wKeyFramesTrans<wNumKeyFramesTrans; wKeyFramesTrans++)
      {
         float fTime = ReadFloat(stream);
         fTime *= m_data.m_animationData.fAnimationFPS;

         x = ReadFloat(stream);
         y = ReadFloat(stream);
         z = ReadFloat(stream);

         j.PositionKeys()[wKeyFramesTrans] = KeyframeTrans(fTime, Vector3d(x, y, z));
      }
   }
}