Esempio n. 1
0
 WindowsMessage(const char *blobType,const void *mem,NxU32 len)
 {
   NxU32 slen = strlen(blobType)+1;
   mType = (char *)MEMALLOC_MALLOC(slen);
   memcpy(mType,blobType,slen);
   mLen = len;
   mMessage = (char *)MEMALLOC_MALLOC(mLen);
   memcpy(mMessage,mem,mLen);
 }
bool RadixSort::Resize(NxU32 nb)
{
	if(mDeleteRanks)
	{
		// Free previously used ram
		MEMALLOC_FREE(mRanks2);
		MEMALLOC_FREE(mRanks);

		// Get some fresh one
		mRanks	= (NxU32*)MEMALLOC_MALLOC(sizeof(NxU32)*nb);
		mRanks2	= (NxU32*)MEMALLOC_MALLOC(sizeof(NxU32)*nb);
	}

	return true;
}
Esempio n. 3
0
 MemoryBlock(size_t size)
 {
   mNextBlock = 0;
   mMemory    = (char *)MEMALLOC_MALLOC(size);
   mSize      = size;
   mLen       = 0;
 }
Esempio n. 4
0
 WindowsMessage(const char *message)
 {
   mType = 0;
   mLen  = strlen(message)+1;
   mMessage = (char *)MEMALLOC_MALLOC(mLen);
   memcpy(mMessage,message,mLen);
 }
Esempio n. 5
0
    void * getDataBlob(const char *key,const char *value,const void *mem,NxU32 len,NxU32 &olen)
    {
        NxU32 klen = strlen(key);
        NxU32 vlen = strlen(value);

        olen = klen+vlen+2+sizeof(NxU32)+len;

        char *blob = (char *)MEMALLOC_MALLOC(olen);

        char *dest = blob;
        memcpy(dest,key,klen+1);
        dest+=(klen+1);
        memcpy(dest,value,vlen+1);
        dest+=(vlen+1);
        NxU32 *destlen = (NxU32 *)dest;
        *destlen = len;
        dest+=sizeof(NxU32);
        memcpy(dest,mem,len);

        return blob;
    }
Esempio n. 6
0
  void * getMemBuffer(size_t &outputLength)
  {
    outputLength = mLoc;

    if ( mHeadBlock && mLoc > 0 )
    {
      assert(mData==0);
      mData = (char *)MEMALLOC_MALLOC(mLoc);
      char *dest = mData;
      MemoryBlock *mb = mHeadBlock;
      while ( mb )
      {
        dest = mb->getData(dest);
        MemoryBlock *next = mb->mNextBlock;
        delete mb;
        mb = next;
      }

      mHeadBlock = 0;
      mTailBlock = 0;
    }
    return mData;
  }
Esempio n. 7
0
  // warning, this code will not work on big endian processors.
  virtual bool             importMesh(const char *_meshName,const void *_data,NxU32 dlen,MeshImportInterface *callback,const char *options,MeshImportApplicationResource *appResource)
  {
	  bool ret = false;

	  const char *meshName = _meshName;
	  const char *slash = lastSlash(meshName);
	  if ( slash )
	  {
		  slash++;
		  meshName = slash;
	  }

	  char scratch[2048];
	  strncpy(scratch,_meshName,2048);
	  char *psk = stristr(scratch,".psk");
	  if ( psk )
	  {
		  *psk = 0;
		  strcat(scratch,".psa");
	  }

	  callback->importAssetName(meshName,0);
	  callback->importMesh(meshName,meshName);

      //  have to make a local copy of the data because we are going to modify some of it.
      // Primarily just truncating some whitespace from bone names.
      void *data = MEMALLOC_MALLOC(dlen);
      memcpy(data,_data,dlen);

      if ( appResource )
      {
        NxU32 len;
        void *mem = appResource->getApplicationResource(meshName,scratch,len);
        if ( mem )
        {

		   char *scan = ( char *)mem;
		   Header *baseHeader = ( Header *)scan;
		   scan+=sizeof(Header);

		   Header *bonesHeader = ( Header *)scan;
		   scan+=sizeof(Header);
		   Bone *bones = ( Bone *)scan;
		   assert(sizeof(Bone)==bonesHeader->mLen);
		   scan+=(bonesHeader->mLen*bonesHeader->mCount);

		   Header *animInfo = ( Header *)scan;
		   scan+=sizeof(Header);
		   assert( animInfo->mLen == sizeof(AnimInfo));
		   AnimInfo *ainfo = ( AnimInfo *)scan;
		   scan+=(animInfo->mLen*animInfo->mCount);

		   Header *animKeysHeader = ( Header *)scan;
		   scan+=sizeof(Header);
		   assert( animKeysHeader->mLen == sizeof(AnimKey) );
		   AnimKey *keys = ( AnimKey *)scan;
		   scan+=(animKeysHeader->mLen*animKeysHeader->mCount);

		   Header *scaleKeysHeader = ( Header *)scan;
		   scan+=sizeof(Header);

           MeshAnimation ma;
           ma.mName = ainfo->mName;
           ma.mTrackCount = ainfo->mTotalBones;
           ma.mFrameCount = ainfo->mNumRawFrames;
		   ma.mDtime = 1.0f / (NxF32)(ainfo->mAnimRate);
           ma.mDuration = ma.mDtime*ainfo->mNumRawFrames;
           ma.mTracks = (MeshAnimTrack **)MEMALLOC_MALLOC(sizeof(MeshAnimTrack *)*ma.mTrackCount);

           for (NxI32 i=0; i<ma.mTrackCount; i++)
           {
             Bone &b = bones[i];
             fixName(b.mName);
			 MeshAnimTrack *track = MEMALLOC_NEW(MeshAnimTrack);
             ma.mTracks[i] = track;
             track->mName      = b.mName;
             track->mFrameCount = ma.mFrameCount;
             track->mDuration   = ma.mDuration;
			 track->mDtime      = ma.mDtime;
             track->mPose       = MEMALLOC_NEW(MeshAnimPose)[track->mFrameCount];

             for (NxI32 j=0; j<ma.mFrameCount; j++)
             {

			   NxU32 index = (j*ma.mTrackCount)+i;

               AnimKey &key = keys[index];
               MeshAnimPose &p = track->mPose[j];

               p.mPos[0] = key.mPosition[0]*IMPORT_SCALE;
#if HACK_ANIMATION_POSITION
               p.mPos[1] = -key.mPosition[1]*IMPORT_SCALE;
#else
               p.mPos[1] = key.mPosition[1]*IMPORT_SCALE;
#endif
               p.mPos[2] = key.mPosition[2]*IMPORT_SCALE;

               p.mQuat[0] = key.mOrientation[0];
#if HACK_ANIMATION_ROTATION
               p.mQuat[1] = -key.mOrientation[1];
#else
               p.mQuat[1] = key.mOrientation[1];
#endif
               p.mQuat[2] = key.mOrientation[2];
               p.mQuat[3] = key.mOrientation[3];

#if HACK_ANIMATION_ROOT
			   if ( i == 0)
			   {
				   p.mQuat[3] = -p.mQuat[3];
			   }
#endif
               index++;
            }
          }

          callback->importAnimation(ma);

          for (NxI32 i=0; i<ma.mTrackCount; i++)
          {
            MeshAnimTrack *track = ma.mTracks[i];
            delete []track->mPose;
            delete track;
          }
          delete []ma.mTracks;
          appResource->releaseApplicationResource(mem);
        }
      }



       char *scan = ( char *)data;
       char *end  = scan+dlen;

	   Header *baseHeader = ( Header *)scan;

       scan+=sizeof(Header); // skip first dummy header

       Header *h = 0;

       Header *positionsHeader = h = (Header *)scan;
	   assert( positionsHeader->mLen == sizeof(Vector));
       scan+=sizeof(Header);
       Vector *positions = ( Vector *)scan;
       scan+=h->mLen*h->mCount;
#if HACK_MESH_POSITION
	   for (NxI32 i=0; i<positionsHeader->mCount; i++)
	   {
		   Vector &v = positions[i];
		   v.y*=-1; // flip the Y-coordinate
	   }
#endif
       Header *verticesHeader = h = ( Header *)scan;
	   assert( verticesHeader->mLen == sizeof(Vertex));
       scan+=sizeof(Header);
       Vertex *vertices = ( Vertex *)scan;
       scan+=h->mLen*h->mCount;

       Header *trianglesHeader = h = ( Header *)scan;
 	   assert( trianglesHeader->mLen == sizeof(Triangle));
       scan+=sizeof(Header);
       Triangle *triangles = ( Triangle *)scan;
       scan+=h->mLen*h->mCount;

       Header *materialsHeader = h = ( Header *)scan;
	   assert( materialsHeader->mLen == sizeof(Material));
       scan+=sizeof(Header);
       Material *materials= ( Material *)scan;
       scan+=h->mLen*h->mCount;

       Header *bonesHeader = h = ( Header *)scan;
	   assert( bonesHeader->mLen == sizeof(Bone));
       scan+=sizeof(Header);
       Bone *bones= ( Bone *)scan;
       scan+=h->mLen*h->mCount;

       Header *boneInfluencesHeader =  h = ( Header *)scan;
	   assert( boneInfluencesHeader->mLen == sizeof(BoneInfluence));
       scan+=sizeof(Header);
       BoneInfluence *boneInfluences = ( BoneInfluence *)scan;
       scan+=h->mLen*h->mCount;

      if ( bonesHeader->mCount > 0 )
      {
        MeshSkeleton *ms = MEMALLOC_NEW(MeshSkeleton);
        ms->mName = meshName;
        ms->mBoneCount = bonesHeader->mCount;
        ms->mBones = MEMALLOC_NEW(MeshBone)[ms->mBoneCount];
        for (NxI32 i=0; i<ms->mBoneCount; i++)
        {
            MeshBone &dest = ms->mBones[i];
            Bone &src = bones[i];
            fixName(src.mName);
            dest.mName = src.mName;
            dest.mParentIndex = (i==0) ? -1 : src.mParentIndex;

            dest.mPosition[0] = src.mPosition[0]*IMPORT_SCALE;
#if HACK_SKELETON_POSITION
            dest.mPosition[1] = -src.mPosition[1]*IMPORT_SCALE;
#else
            dest.mPosition[1] = src.mPosition[1]*IMPORT_SCALE;
#endif
            dest.mPosition[2] = src.mPosition[2]*IMPORT_SCALE;

            dest.mOrientation[0] = src.mOrientation[0];
#if HACK_SKELETON_ROTATION
            dest.mOrientation[1] = -src.mOrientation[1];
#else
            dest.mOrientation[1] = src.mOrientation[1];
#endif
            dest.mOrientation[2] = src.mOrientation[2];
            dest.mOrientation[3] = src.mOrientation[3];

#if HACK_SKELETON_ROOT
			if ( i == 0 )
			{
				dest.mOrientation[3]*=-1;
			}
#endif
            dest.mScale[0] = 1; //src.mXSize;
            dest.mScale[1] = 1; //src.mYSize;
            dest.mScale[2] = 1; //src.mZSize;

        }
        callback->importSkeleton(*ms);
        delete []ms->mBones;
        delete ms;
      }

      assert( scan == end );

      DeformVector *dvertices = MEMALLOC_NEW(DeformVector)[positionsHeader->mCount];

      for (NxI32 i=0; i<boneInfluencesHeader->mCount; i++)
      {
         BoneInfluence &b = boneInfluences[i];
        DeformVector &d = dvertices[b.mVertexIndex];
        if ( d.mCount < 4 )
        {
            d.mWeight[d.mCount] = b.mWeight;
            d.mBone[d.mCount] = (NxU16)b.mBoneIndex;
            d.mCount++;
        }
      }

      Vector *normals = (Vector *)MEMALLOC_MALLOC( sizeof(Vector)*positionsHeader->mCount);
      memset(normals,0,sizeof(Vector)*positionsHeader->mCount);
      for (NxI32 i=0; i<trianglesHeader->mCount; i++)
      {
         Triangle &t = triangles[i];
        MeshVertex mv1,mv2,mv3;

         Vertex &v1 = vertices[t.mWedgeIndex[0]];
         Vertex &v2 = vertices[t.mWedgeIndex[1]];
         Vertex &v3 = vertices[t.mWedgeIndex[2]];

         Vector &p1 = positions[v1.mIndex];
         Vector &p2 = positions[v2.mIndex];
         Vector &p3 = positions[v3.mIndex];

        Vector &n1 = normals[v1.mIndex];
        Vector &n2 = normals[v2.mIndex];
        Vector &n3 = normals[v3.mIndex];

        Vector normal;
        fm_computePlane( &p1.x, &p3.x, &p2.x, &normal.x );

        n1.x+=normal.x;
        n1.y+=normal.y;
        n1.z+=normal.z;

        n2.x+=normal.x;
        n2.y+=normal.y;
        n2.z+=normal.z;

        n3.x+=normal.x;
        n3.y+=normal.y;
        n3.z+=normal.z;
      }

      for (NxI32 i=0; i<positionsHeader->mCount; i++)
      {
        Vector &n = normals[i];
        fm_normalize(&n.x);
      }



      for (NxI32 i=0; i<trianglesHeader->mCount; i++)
      {
         Triangle &t = triangles[i];
        MeshVertex mv1,mv2,mv3;

         Vertex &v1 = vertices[t.mWedgeIndex[0]];
         Vertex &v2 = vertices[t.mWedgeIndex[1]];
         Vertex &v3 = vertices[t.mWedgeIndex[2]];

         Vector &p1 = positions[v1.mIndex];
         Vector &p2 = positions[v2.mIndex];
         Vector &p3 = positions[v3.mIndex];

         Vector &n1 = normals[v1.mIndex];
         Vector &n2 = normals[v2.mIndex];
         Vector &n3 = normals[v3.mIndex];


         DeformVector &dv1 = dvertices[v1.mIndex];
         DeformVector &dv2 = dvertices[v2.mIndex];
         DeformVector &dv3 = dvertices[v3.mIndex];

        getVertex(mv1,p1,v1,dv1,n1);
        getVertex(mv2,p2,v2,dv2,n2);
        getVertex(mv3,p3,v3,dv3,n3);

        const char *material = "default";
        if ( t.mMaterialIndex >= 0 && t.mMaterialIndex < materialsHeader->mCount )
        {
            material = materials[ t.mMaterialIndex ].mMaterialName;
        }
#if HACK_MESH_WINDING
        callback->importTriangle(meshName,material, MIVF_ALL, mv1, mv3, mv2 );
#else
		callback->importTriangle(meshName,material, MIVF_ALL, mv1, mv2, mv3 );
#endif

      }


      delete []dvertices;
      MEMALLOC_FREE(data);

	  return ret;
  }