void LodConfigSerializer::readLodLevels() { uint32 size = 0; readInts(mStream, &size, 1); mLodConfig->levels.clear(); while(size--){ LodLevel level; readFloats(mStream, &level.distance, 1); readInts(mStream, (Ogre::uint32*)&level.reductionMethod, 1); readFloats(mStream, &level.reductionValue, 1); level.manualMeshName = readString(mStream); mLodConfig->levels.push_back(level); } }
unsigned short Serializer::readChunk() { unsigned short id; readShorts(&id, 1); readInts(&mCurrentStreamLen, 1); return id; }
void OgreMeshDeserializer::readGeometry() { std::vector<char> vertexBuffer; std::vector<OgreMeshDeserializer::VertexElement> elements; unsigned int vertexCount = 0; readInts(m_stream, &vertexCount, 1); // Find optional geometry streams if (!m_stream.eof()) { unsigned short streamID = readChunk(m_stream); while (!m_stream.eof() && (streamID == M_GEOMETRY_VERTEX_DECLARATION || streamID == M_GEOMETRY_VERTEX_BUFFER)) { switch (streamID) { case M_GEOMETRY_VERTEX_DECLARATION: elements = readGeometryVertexDeclaration(); break; case M_GEOMETRY_VERTEX_BUFFER: vertexBuffer = readGeometryVertexBuffer(vertexCount); break; default: skipChunk(m_stream); } // Get next stream if (!m_stream.eof()) { streamID = readChunk(m_stream); } } if (!elements.empty()) { for (auto& element : elements) { if (element.vSemantic == VertexElementSemantic::VES_POSITION) { size_t vertexSize = vertexBuffer.size() / vertexCount; for (size_t i = 0; i < vertexCount; ++i) { char* vertexStart = vertexBuffer.data() + (i * vertexSize); char* positionStart = vertexStart + element.offset; if (element.vType == VertexElementType::VET_FLOAT3) { float* positions = reinterpret_cast<float*>(positionStart); m_vertices.push_back(*positions); positions++; m_vertices.push_back(*positions); positions++; m_vertices.push_back(*positions); } } } } } if (!m_stream.eof()) { // Backpedal back to start of non-submesh stream backpedalChunkHeader(m_stream); } } }
int main(void) { /* int a = 3, b = 5, c = 10; */ int a,b,c; char e; t_ordering mFunc; readInts(&a,&b,&c,&e ); /* printf("\nInitially: a = %d, b = %d, c = %d",a, b, c); ascending3( &a , &b, &c); printf("\nAfter running ascending: a = %d, b = %d, c = %d", a, b, c); descending3( &a, &b, &c); */ mFunc = order(e); mFunc(&a, &b, &c); printf("\nAfter running ascending3: a = %d, b = %d, c = %d\n", a, b, c); return 0; }
//--------------------------------------------------------------------- unsigned short Serializer::readChunk(DataStreamPtr& stream) { unsigned short id; readShorts(stream, &id, 1); readInts(stream, &mCurrentstreamLen, 1); return id; }
//--------------------------------------------------------------------- unsigned short OgreMeshDeserializer::readChunk(std::istream& stream) { unsigned short id; readShorts(stream, &id, 1); readInts(stream, &mCurrentstreamLen, 1); return id; }
int main(){ int A[64]; int N; int capacity = 64; N = readInts(A, capacity); sortInts(A, N); printf("\n"); printInts(A, N); return 0; }
void LodConfigSerializer::readLodProfile() { uint32 size = 0; readInts(mStream, &size, 1); mLodConfig->advanced.profile.clear(); while(size--){ ProfiledEdge pv; readObject(mStream, pv.src); readObject(mStream, pv.dst); readFloats(mStream, &pv.cost, 1); mLodConfig->advanced.profile.push_back(pv); } }
void TriMeshLoader::processFace(char *tok,TriMesh *pmesh){ //cout << "PROCESSING FACE" << endl; int ids[256]; int cnt=readInts(tok,ids,256); if(cnt>=3){ int tri[3]={ids[0]-1,ids[1]-1,ids[2]-1}; pmesh->addFace(tri); for(int i=3;i<cnt;i++){ tri[1]=tri[2]; tri[2]=ids[i]-1; pmesh->addFace(tri); } } }
//--------------------------------------------------------------------- unsigned short Serializer::readChunk(DataStreamPtr& stream) { #if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE size_t pos = stream->tell(); #endif unsigned short id; readShorts(stream, &id, 1); readInts(stream, &mCurrentstreamLen, 1); #if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE if (!mChunkSizeStack.empty() && !stream->eof()){ if (pos != static_cast<size_t>(mChunkSizeStack.back()) && mReportChunkErrors){ LogManager::getSingleton().logMessage("Corrupted chunk detected! Stream name: '" + stream->getName() + "' Chunk id: " + StringConverter::toString(id)); } mChunkSizeStack.back() = pos + mCurrentstreamLen; } #endif return id; }
//--------------------------------------------------------------------- void OgreMeshDeserializer::readSubMesh() { unsigned short streamID; std::string materialName = readString(m_stream); bool useSharedVertices; readBools(m_stream, &useSharedVertices, 1); size_t offset = 0; if (!useSharedVertices) { offset = m_vertices.size() / 3; } unsigned int indexCount = 0; readInts(m_stream, &indexCount, 1); bool idx32bit; readBools(m_stream, &idx32bit, 1); if (indexCount > 0) { if (idx32bit) { std::vector<std::uint32_t> indices; indices.resize(indexCount); readInts(m_stream, indices.data(), indexCount); for (auto& index : indices) { m_indices.emplace_back(index + offset); } } else // 16-bit { std::vector<std::uint16_t> indices; indices.resize(indexCount); readShorts(m_stream, indices.data(), indexCount); for (auto& index : indices) { m_indices.emplace_back(index + offset); } } } { // M_GEOMETRY m_stream (Optional: present only if useSharedVertices = false) if (!useSharedVertices) { streamID = readChunk(m_stream); if (streamID != M_GEOMETRY) { std::runtime_error("Missing geometry data in mesh file"); } readGeometry(); } // Find all bone assignments, submesh operation, and texture aliases (if present) if (!m_stream.eof()) { streamID = readChunk(m_stream); while (!m_stream.eof() && (streamID == M_SUBMESH_BONE_ASSIGNMENT || streamID == M_SUBMESH_OPERATION || streamID == M_SUBMESH_TEXTURE_ALIAS)) { 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); } } } }
//--------------------------------------------------------------------- String Reader::readString(void) { uint32 numChars; readInts(&numChars); return readString(numChars); }