//---------------------------------------------------------------------
void OgreMeshDeserializer::readMesh()
{
    //First value is whether it's skeletally animated
    m_stream.seekg(sizeof(bool), std::ios_base::cur);

    // Find all substreams
    if (!m_stream.eof()) {

        unsigned short streamID = readChunk(m_stream);
        while (!m_stream.eof() &&
               (streamID == M_GEOMETRY ||
                streamID == M_SUBMESH ||
                streamID == M_MESH_SKELETON_LINK ||
                streamID == M_MESH_BONE_ASSIGNMENT ||
                streamID == M_MESH_LOD_LEVEL ||
                streamID == M_MESH_BOUNDS ||
                streamID == M_SUBMESH_NAME_TABLE ||
                streamID == M_EDGE_LISTS ||
                streamID == M_POSES ||
                streamID == M_ANIMATIONS ||
                streamID == M_TABLE_EXTREMES)) {
            switch (streamID) {
                case M_GEOMETRY:
                    readGeometry();
                    break;
                case M_SUBMESH:
                    readSubMesh();
                    break;
                case M_MESH_BOUNDS:
                    readBoundsInfo();
                    break;
                default:
                    skipChunk(m_stream);
            }

            if (!m_stream.eof()) {
                streamID = readChunk(m_stream);
            }

        }
        if (!m_stream.eof()) {
            // Backpedal back to start of m_stream
            backpedalChunkHeader(m_stream);
        }

    }

}
Beispiel #2
0
void ObjLoader::readMultiMeshFromFile(Model3D *pModel,const char *strFileName)
{

  ifstream in(strFileName);

  char strLine[256];
  string first;

  model_ = pModel;
  Mesh3D mesh;

  if(!in.is_open())
  {
    std::cerr<<"Unable to open file: "<<strFileName<<std::endl;
    exit(0);
  }

  //count the number of sub-meshes
  int subMeshes = 0;
  offset_ = 0;
  while(!in.eof())
  {
    in>>first;
    if(first == string("g"))
    {
      subMeshes++;
      in.getline(strLine,256);
    }
    else
      in.getline(strLine,256);
  }//end while

  in.clear();
  in.seekg(0,ios::beg);

  for(int i=0;i< subMeshes;i++)
  {
    Mesh3D mesh;
    readSubMesh(in,&mesh);
    pModel->meshes_.push_back(mesh);
    offset_+=mesh.getNumVerts();
  }

}//end ReadMultiMeshFromFile
void
OgreMeshReader::readMesh(void)
{
    OSG_OGRE_LOG(("OgreMeshReader::readMesh\n"));

    bool skelAnim = readBool(_is);
    bool stop     = false;

    Int16              boneIdxVE    = -1;
    Int16              boneWeightVE = -1;
    VertexElementStore sharedVertexElements;
    SubMeshStore       subMeshInfo;

    while(_is)
    {
        readChunkHeader(_is);

        switch(_header.chunkId)
        {
        case CHUNK_SUBMESH:
            readSubMesh(subMeshInfo, sharedVertexElements, skelAnim);
            break;

        case CHUNK_GEOMETRY:
            readGeometry(sharedVertexElements);
            break;

        case CHUNK_MESH_SKELETON_LINK:
            readMeshSkeletonLink(subMeshInfo);
            break;

        case CHUNK_MESH_BONE_ASSIGNMENT:
            readMeshBoneAssignment(sharedVertexElements, boneIdxVE, boneWeightVE);
            break;

        case CHUNK_MESH_LOD:
            readMeshLOD();
            break;

        case CHUNK_MESH_BOUNDS:
            readMeshBounds();
            break;

        case CHUNK_SUBMESH_NAME_TABLE:
            readSubMeshNameTable(subMeshInfo);
            break;

        case CHUNK_EDGE_LISTS:
            readEdgeLists();
            break;

        case CHUNK_POSES:
            readPoses();
            break;

        case CHUNK_ANIMATIONS:
            readAnimations();
            break;

        case CHUNK_TABLE_EXTREMES:
            readTableExtremes();
            break;

        default:
            OSG_OGRE_LOG(("OgreMeshReader::readMesh: Unknown chunkId '0x%x'\n",
                          _header.chunkId));
            stop = true;
            break;
        };

        if(stop == true)
        {
            skip(_is, -_chunkHeaderSize);
            break;
        }
    }

    if(boneIdxVE >= 0 || boneWeightVE >= 0)
    {
        verifyBoneAssignment(sharedVertexElements, boneIdxVE, boneWeightVE);
    }

    SubMeshStore::iterator smIt  = subMeshInfo.begin();
    SubMeshStore::iterator smEnd = subMeshInfo.end  ();

    for(; smIt != smEnd; ++smIt)
    {
        if((*smIt).sharedVertex == true)
        {
            constructSubMesh(*smIt, sharedVertexElements);
        }
        else
        {
            constructSubMesh(*smIt, (*smIt).vertexElements);
        }
    }
}
Beispiel #4
0
void readMesh(IOReadBase* pRead, iModelData* pModelData)
{
	bool skeletallyAnimated;
	pRead->Read(&skeletallyAnimated,sizeof(bool));
	// Find all substreams
	if (!pRead->IsEof())
	{
		CSubMesh sharedSubMesh;
		unsigned short streamID;
		unsigned int uLength;
		pRead->Read(&streamID,sizeof(unsigned short));
		pRead->Read(&uLength,sizeof(unsigned int));

		while(!pRead->IsEof() &&
			(streamID == M_GEOMETRY ||
			streamID == M_SUBMESH ||
			streamID == M_MESH_SKELETON_LINK ||
			streamID == M_MESH_BONE_ASSIGNMENT ||
			streamID == M_MESH_LOD ||
			streamID == M_MESH_BOUNDS ||
			streamID == M_SUBMESH_NAME_TABLE ||
			streamID == M_EDGE_LISTS ||
			streamID == M_POSES ||
			streamID == M_ANIMATIONS ||
			streamID == M_TABLE_EXTREMES))
		{
			switch(streamID)
			{
			case M_GEOMETRY:
				{
					//MessageBoxW(NULL, L"M_GEOMETRY",	L"readMesh",0);
					readGeometry(pRead, sharedSubMesh);
				}
				break;
			case M_SUBMESH:
				readSubMesh(pRead, pModelData, sharedSubMesh);
				break;
			case M_MESH_SKELETON_LINK:
				{
					std::string skelName = readString(pRead);

					// 				if(listener)
					// 					listener->processSkeletonName(pMesh, &skelName);
					// 
					// 				pMesh->setSkeletonName(skelName);
					//readSkeletonLink(stream, pMesh, listener);
				}
				break;
			case M_MESH_BONE_ASSIGNMENT:
				//readMeshBoneAssignment(stream, pMesh);
				{
					VertexBoneAssignment assign;

					// unsigned int vertexIndex;
					pRead->Read(&(assign.vertexIndex),sizeof(unsigned int));
					// unsigned short boneIndex;
					pRead->Read(&(assign.boneIndex),sizeof(unsigned short));
					// float weight;
					pRead->Read(&(assign.weight),sizeof(float));

					//sub->addBoneAssignment(assign);
				}
				break;
			case M_MESH_LOD:
				MessageBoxW(NULL,L"M_MESH_LOD",0,0);
				//readMeshLodInfo(stream, pMesh);
				break;
			case M_MESH_BOUNDS:
				//readBoundsInfo(stream, pMesh);
				{
					Vec3D min, max;
					// float minx, miny, minz
					pRead->Read(&min,sizeof(Vec3D));
					// float maxx, maxy, maxz
					pRead->Read(&max,sizeof(Vec3D));
					//AxisAlignedBox box(min, max);
					//pMesh->_setBounds(box, true);
					// float radius
					float radius;
					pRead->Read(&radius,sizeof(float));
					//pMesh->_setBoundingSphereRadius(radius);
				}
				break;
			case M_SUBMESH_NAME_TABLE:
				MessageBoxW(NULL,L"M_SUBMESH_NAME_TABLE",0,0);
				//readSubMeshNameTable(stream, pMesh);
				break;
			case M_EDGE_LISTS:
				MessageBoxW(NULL,L"M_EDGE_LISTS",0,0);
				//readEdgeList(stream, pMesh);
				break;
			case M_POSES:
				MessageBoxW(NULL,L"M_POSES",0,0);
				//readPoses(stream, pMesh);
				break;
			case M_ANIMATIONS:
				MessageBoxW(NULL,L"M_ANIMATIONS",0,0);
				//readAnimations(stream, pMesh);
				break;
			case M_TABLE_EXTREMES:
				MessageBoxW(NULL,L"M_TABLE_EXTREMES",0,0);
				//readExtremes(stream, pMesh);
				break;
			}

			if (!pRead->IsEof())
			{
				pRead->Read(&streamID,sizeof(unsigned short));
				pRead->Read(&uLength,sizeof(unsigned int));
			}
		}
		if (!pRead->IsEof())
		{
			// Backpedal back to start of non-submesh stream
			pRead->Move(-STREAM_OVERHEAD_SIZE);
		}
	}
}