/* =================== idRestoreGame::WriteTraceModel =================== */ void idSaveGame::WriteTraceModel( const idTraceModel &trace ) { int j, k; WriteInt( (int&)trace.type ); WriteInt( trace.numVerts ); for ( j = 0; j < MAX_TRACEMODEL_VERTS; j++ ) { WriteVec3( trace.verts[j] ); } WriteInt( trace.numEdges ); for ( j = 0; j < (MAX_TRACEMODEL_EDGES+1); j++ ) { WriteInt( trace.edges[j].v[0] ); WriteInt( trace.edges[j].v[1] ); WriteVec3( trace.edges[j].normal ); } WriteInt( trace.numPolys ); for ( j = 0; j < MAX_TRACEMODEL_POLYS; j++ ) { WriteVec3( trace.polys[j].normal ); WriteFloat( trace.polys[j].dist ); WriteBounds( trace.polys[j].bounds ); WriteInt( trace.polys[j].numEdges ); for ( k = 0; k < MAX_TRACEMODEL_POLYEDGES; k++ ) { WriteInt( trace.polys[j].edges[k] ); } } WriteVec3( trace.offset ); WriteBounds( trace.bounds ); WriteBool( trace.isConvex ); // padding win32 native structs char tmp[3]; memset( tmp, 0, sizeof( tmp ) ); file->Write( tmp, 3 ); }
/* =================== idSaveGame::WriteContactInfo =================== */ void idSaveGame::WriteContactInfo( const contactInfo_t &contactInfo ) { WriteInt( (int)contactInfo.type ); WriteVec3( contactInfo.point ); WriteVec3( contactInfo.normal ); WriteFloat( contactInfo.dist ); WriteInt( contactInfo.contents ); WriteMaterial( contactInfo.material ); WriteInt( contactInfo.modelFeature ); WriteInt( contactInfo.trmFeature ); WriteInt( contactInfo.entityNum ); WriteInt( contactInfo.id ); }
/* ================ idSaveGame::WriteRenderLight ================ */ void idSaveGame::WriteRenderLight( const renderLight_t &renderLight ) { int i; WriteMat3( renderLight.axis ); WriteVec3( renderLight.origin ); WriteInt( renderLight.suppressLightInViewID ); WriteInt( renderLight.allowLightInViewID ); WriteBool( renderLight.noShadows ); WriteBool( renderLight.noSpecular ); WriteBool( renderLight.pointLight ); WriteBool( renderLight.parallel ); WriteVec3( renderLight.lightRadius ); WriteVec3( renderLight.lightCenter ); WriteVec3( renderLight.target ); WriteVec3( renderLight.right ); WriteVec3( renderLight.up ); WriteVec3( renderLight.start ); WriteVec3( renderLight.end ); // only idLight has a prelightModel and it's always based on the entityname, so we'll restore it there // WriteModel( renderLight.prelightModel ); WriteInt( renderLight.lightId ); WriteMaterial( renderLight.shader ); for( i = 0; i < MAX_ENTITY_SHADER_PARMS; i++ ) { WriteFloat( renderLight.shaderParms[ i ] ); } if( renderLight.referenceSound != NULL ) { WriteInt( renderLight.referenceSound->Index() ); } else { WriteInt( 0 ); } }
/* =================== idSaveGame::WriteTrace =================== */ void idSaveGame::WriteTrace( const trace_t& trace ) { WriteFloat( trace.fraction ); WriteVec3( trace.endpos ); WriteMat3( trace.endAxis ); WriteContactInfo( trace.c ); }
/* ================ idSaveGame::WriteRenderEntity ================ */ void idSaveGame::WriteRenderEntity( const renderEntity_t &renderEntity ) { int i; WriteModel( renderEntity.hModel ); WriteInt( renderEntity.entityNum ); WriteInt( renderEntity.bodyId ); WriteBounds( renderEntity.bounds ); // callback is set by class's Restore function WriteInt( renderEntity.suppressSurfaceInViewID ); WriteInt( renderEntity.suppressShadowInViewID ); WriteInt( renderEntity.suppressShadowInLightID ); WriteInt( renderEntity.allowSurfaceInViewID ); WriteVec3( renderEntity.origin ); WriteMat3( renderEntity.axis ); WriteMaterial( renderEntity.customShader ); WriteMaterial( renderEntity.referenceShader ); WriteSkin( renderEntity.customSkin ); if( renderEntity.referenceSound != NULL ) { WriteInt( renderEntity.referenceSound->Index() ); } else { WriteInt( 0 ); } for( i = 0; i < MAX_ENTITY_SHADER_PARMS; i++ ) { WriteFloat( renderEntity.shaderParms[ i ] ); } for( i = 0; i < MAX_RENDERENTITY_GUI; i++ ) { WriteUserInterface( renderEntity.gui[ i ], renderEntity.gui[ i ] ? renderEntity.gui[ i ]->IsUniqued() : false ); } WriteFloat( renderEntity.modelDepthHack ); WriteBool( renderEntity.noSelfShadow ); WriteBool( renderEntity.noShadow ); WriteBool( renderEntity.noDynamicInteractions ); WriteBool( renderEntity.weaponDepthHack ); WriteInt( renderEntity.forceUpdate ); }
/* ================ idSaveGame::WriteRenderView ================ */ void idSaveGame::WriteRenderView( const renderView_t &view ) { int i; WriteInt( view.viewID ); WriteInt( view.x ); WriteInt( view.y ); WriteInt( view.width ); WriteInt( view.height ); WriteFloat( view.fov_x ); WriteFloat( view.fov_y ); WriteVec3( view.vieworg ); WriteMat3( view.viewaxis ); WriteBool( view.cramZNear ); WriteInt( view.time ); for( i = 0; i < MAX_GLOBAL_SHADER_PARMS; i++ ) { WriteFloat( view.shaderParms[ i ] ); } }
/* ================ idSaveGame::WriteRefSound ================ */ void idSaveGame::WriteRefSound( const refSound_t &refSound ) { if( refSound.referenceSound ) { WriteInt( refSound.referenceSound->Index() ); } else { WriteInt( 0 ); } WriteVec3( refSound.origin ); WriteInt( refSound.listenerId ); WriteSoundShader( refSound.shader ); WriteFloat( refSound.diversity ); WriteBool( refSound.waitfortrigger ); WriteFloat( refSound.parms.minDistance ); WriteFloat( refSound.parms.maxDistance ); WriteFloat( refSound.parms.volume ); WriteFloat( refSound.parms.shakes ); WriteInt( refSound.parms.soundShaderFlags ); WriteInt( refSound.parms.soundClass ); }
void ezJSONWriter::AddVariableVec3(const char* szName, const ezVec3& value) { BeginVariable(szName); WriteVec3(value); EndVariable(); }
void ezJSONWriter::WriteVariant(const ezVariant& value) { switch (value.GetType()) { case ezVariant::Type::Invalid: //EZ_REPORT_FAILURE("Variant of Type 'Invalid' cannot be written as JSON."); WriteNULL(); return; case ezVariant::Type::Bool: WriteBool(value.Get<bool>()); return; case ezVariant::Type::Int8: WriteInt32(value.Get<ezInt8>()); return; case ezVariant::Type::UInt8: WriteUInt32(value.Get<ezUInt8>()); return; case ezVariant::Type::Int16: WriteInt32(value.Get<ezInt16>()); return; case ezVariant::Type::UInt16: WriteUInt32(value.Get<ezUInt16>()); return; case ezVariant::Type::Int32: WriteInt32(value.Get<ezInt32>()); return; case ezVariant::Type::UInt32: WriteUInt32(value.Get<ezUInt32>()); return; case ezVariant::Type::Int64: WriteInt64(value.Get<ezInt64>()); return; case ezVariant::Type::UInt64: WriteUInt64(value.Get<ezUInt64>()); return; case ezVariant::Type::Float: WriteFloat(value.Get<float>()); return; case ezVariant::Type::Double: WriteDouble(value.Get<double>()); return; case ezVariant::Type::Color: WriteColor(value.Get<ezColor>()); return; case ezVariant::Type::Vector2: WriteVec2(value.Get<ezVec2>()); return; case ezVariant::Type::Vector3: WriteVec3(value.Get<ezVec3>()); return; case ezVariant::Type::Vector4: WriteVec4(value.Get<ezVec4>()); return; case ezVariant::Type::Quaternion: WriteQuat(value.Get<ezQuat>()); return; case ezVariant::Type::Matrix3: WriteMat3(value.Get<ezMat3>()); return; case ezVariant::Type::Matrix4: WriteMat4(value.Get<ezMat4>()); return; case ezVariant::Type::String: WriteString(value.Get<ezString>().GetData()); return; case ezVariant::Type::Time: WriteTime(value.Get<ezTime>()); return; case ezVariant::Type::Uuid: WriteUuid(value.Get<ezUuid>()); return; default: break; } EZ_REPORT_FAILURE("The Variant Type %i is not supported by ezJSONWriter::WriteVariant.", value.GetType()); }
void ObjectWriter::Write(std::string file_name) { out.open((model_output_path + file_name).c_str(), std::ios::binary); // Write Object Name WriteUInt(object_name.size()); WriteString(object_name); // Write Basic Transformation std::vector<EG::Game::ObjectAttribute *> *transformation_attributes = object->GetAttributesByType(EG::Game::ObjectAttribute::OBJECT_ATTRIBUTE_BASIC_TRANSFORMATION); EG::Game::ObjectAttributeBasicTransformation *transformation_attribute = static_cast<EG::Game::ObjectAttributeBasicTransformation *>(transformation_attributes->at(0)); WriteMat4(transformation_attribute->GetTransformation()); // Mesh/Material Attributes std::vector<EG::Game::ObjectAttribute *> *mesh_attributes = object->GetAttributesByType(EG::Game::ObjectAttribute::OBJECT_ATTRIBUTE_RENDERING_MESH); std::vector<EG::Game::ObjectAttribute *>::iterator mesh_attribute_iterator = mesh_attributes->begin(); WriteUInt(mesh_attributes->size()); while (mesh_attribute_iterator != mesh_attributes->end()){ EG::Game::ObjectAttributeRenderingMesh *mesh_attribute = static_cast<EG::Game::ObjectAttributeRenderingMesh *>(*mesh_attribute_iterator); EG::Graphics::RenderingMaterial *material = mesh_attribute->GetMaterial(); EG::Graphics::Mesh *mesh = scene->GetMeshManager()->Get(mesh_attribute->GetMeshId()); // Material if (material->HasTexture(EG::Graphics::RenderingMaterial::RENDERING_MATERIAL_TEXTURE_DECAL)) { EG::Graphics::Texture *texture = scene->GetTextureManager()->GetTexture(material->GetTexture(EG::Graphics::RenderingMaterial::RENDERING_MATERIAL_TEXTURE_DECAL)); std::string image_out_path = (images_output_path + EG::Utility::StringMethods::GetFilenameFromPath(texture->GetFilePath())); CopyFile(texture->GetFilePath(), image_out_path.c_str()); WriteBool(true); WriteUInt(image_out_path.size()); WriteString(image_out_path); }else{ WriteBool(false); } if (material->HasTexture(EG::Graphics::RenderingMaterial::RENDERING_MATERIAL_TEXTURE_NORMAL)){ EG::Graphics::Texture *texture = scene->GetTextureManager()->GetTexture(material->GetTexture(EG::Graphics::RenderingMaterial::RENDERING_MATERIAL_TEXTURE_NORMAL)); std::string image_out_path = (images_output_path + EG::Utility::StringMethods::GetFilenameFromPath(texture->GetFilePath())); CopyFile(texture->GetFilePath(), image_out_path.c_str()); WriteBool(true); WriteUInt(image_out_path.size()); WriteString(image_out_path); }else{ WriteBool(false); } if (material->HasTexture(EG::Graphics::RenderingMaterial::RENDERING_MATERIAL_TEXTURE_HEIGHT)){ EG::Graphics::Texture *texture = scene->GetTextureManager()->GetTexture(material->GetTexture(EG::Graphics::RenderingMaterial::RENDERING_MATERIAL_TEXTURE_HEIGHT)); std::string image_out_path = (images_output_path + EG::Utility::StringMethods::GetFilenameFromPath(texture->GetFilePath())); CopyFile(texture->GetFilePath(), image_out_path.c_str()); WriteBool(true); WriteUInt(image_out_path.size()); WriteString(image_out_path); }else{ WriteBool(false); } if (material->HasTexture(EG::Graphics::RenderingMaterial::RENDERING_MATERIAL_TEXTURE_SPECULAR)){ EG::Graphics::Texture *texture = scene->GetTextureManager()->GetTexture(material->GetTexture(EG::Graphics::RenderingMaterial::RENDERING_MATERIAL_TEXTURE_SPECULAR)); std::string image_out_path = (images_output_path + EG::Utility::StringMethods::GetFilenameFromPath(texture->GetFilePath())); CopyFile(texture->GetFilePath(), image_out_path.c_str()); WriteBool(true); WriteUInt(image_out_path.size()); WriteString(image_out_path); }else{ WriteBool(false); } if (material->GetLit()){ WriteBool(true); }else{ WriteBool(false); } if (material->GetCastsShadows()){ WriteBool(true); }else{ WriteBool(false); } if (material->GetTranslucent()){ WriteBool(true); }else{ WriteBool(false); } WriteFloat(material->GetAmbient()); WriteFloat(material->GetDiffuse()); WriteFloat(material->GetSpecular()); WriteFloat(material->GetSpecularExponent()); WriteVec4(material->GetColor()); // Mesh WriteUInt(mesh_attribute->GetMeshId().size()); WriteString(mesh_attribute->GetMeshId()); WriteUInt(mesh->GetVertexCount()); WriteUInt(mesh->GetStride()); if (mesh->HasVertices()){ WriteBool(true); float *d = mesh->GetVertices(); WriteFloatV(d, mesh->GetVertexCount() * 4); } else { WriteBool(false); } if (mesh->HasNormals()){ WriteBool(true); float *d = mesh->GetNormals(); WriteFloatV(d, mesh->GetVertexCount() * 4); } else { WriteBool(false); } if (mesh->HasTexCoords()){ WriteBool(true); float *d = mesh->GetTexCoords(); WriteFloatV(d, mesh->GetVertexCount() * 4); } else { WriteBool(false); } if (mesh->HasBinormals()){ WriteBool(true); float *d = mesh->GetBinormals(); WriteFloatV(d, mesh->GetVertexCount() * 4); } else { WriteBool(false); } if (mesh->HasBitangents()){ WriteBool(true); float *d = mesh->GetBitangents(); WriteFloatV(d, mesh->GetVertexCount() * 4); } else { WriteBool(false); } if (mesh->HasSkeleton()) { WriteBool(true); float *d = mesh->GetWeights(); WriteFloatV(d, mesh->GetVertexCount() * 4); float *di = mesh->GetWeightVertexIndices(); WriteFloatV(di, mesh->GetVertexCount() * 4); } else { WriteBool(false); } // Animations if (object->HasAttributesOfType(EG::Game::ObjectAttribute::OBJECT_ATTRIBUTE_CONTROL_ANIMATION)) { WriteBool(true); // Has Animations EG::Game::ObjectAttributeControlAnimationState *animation_attribute = static_cast<EG::Game::ObjectAttributeControlAnimationState *>(object->GetAttributesByType(EG::Game::ObjectAttribute::OBJECT_ATTRIBUTE_CONTROL_ANIMATION)->at(0)); EG::Dynamics::AnimationState *animation_state = animation_attribute->GetAnimationState(); EG::Dynamics::Animations *animations = animation_state->GetAnimations(); // Bind Pose Skeleton EG::Dynamics::Skeleton *bind_pose = animations->GetBindPose(); std::map<unsigned int, EG::Dynamics::Bone *> *bones = bind_pose->GetBoneMap(); unsigned int bone_count = bind_pose->GetBones()->size(); WriteUInt(bone_count); for (unsigned int i = 0; i < bone_count; i++) { EG::Dynamics::Bone *bone = (*bones)[i]; WriteUInt(i); // Bone ID if (bone->GetParent() != NULL) { WriteUInt(bone->GetParent()->GetId()); } else { WriteUInt(99999); } WriteMat4(bone->GetOffset()); } // Animations std::vector<std::string> animation_names = animations->GetAnimationNames(); WriteUInt(animation_names.size()); std::vector<std::string>::iterator aiter = animation_names.begin(); while (aiter != animation_names.end()) { // Animation std::string animation_name = (*aiter); EG::Dynamics::Animation *animation = animations->Get(animation_name); // Animation Name WriteUInt(animation_name.size()); WriteString(animation_name); WriteFloat(animation->GetDuration()); WriteUInt(animation->GetBoneCount()); std::map<unsigned int, std::vector<std::pair<float, glm::vec3> > > *positions = animation->GetPositions(); std::map<unsigned int, std::vector<std::pair<float, glm::vec3> > > *scalings = animation->GetScalings(); std::map<unsigned int, std::vector<std::pair<float, glm::quat> > > *rotations = animation->GetRotations(); for (unsigned int i = 0; i < animation->GetBoneCount(); i++) { WriteUInt(i); // Bone ID std::vector<std::pair<float, glm::vec3> > p = (*positions)[i]; std::vector<std::pair<float, glm::vec3> > s = (*scalings)[i]; std::vector<std::pair<float, glm::quat> > r = (*rotations)[i]; // Write Positions WriteUInt(p.size()); for (unsigned int j = 0; j < p.size(); j++) { WriteFloat(p[j].first); WriteVec3(p[j].second); } // Write Scalings WriteUInt(s.size()); for (unsigned int j = 0; j < s.size(); j++) { WriteFloat(s[j].first); WriteVec3(s[j].second); } // Write Rotations WriteUInt(r.size()); for (unsigned int j = 0; j < r.size(); j++) { WriteFloat(r[j].first); WriteQuat(r[j].second); } } ++aiter; } } else { WriteBool(false); } // Lights // Particle Systems? ++mesh_attribute_iterator; } out.close(); }
void idSaveGame::WriteBox( const idBox &box ) { WriteVec3( box.GetCenter() ); WriteVec3( box.GetExtents() ); WriteMat3( box.GetAxis() ); }
void idSaveGame::WriteBounds( const idBounds &bounds ) { WriteVec3( bounds[0] ); WriteVec3( bounds[1] ); }
// ----------------------------------------------------------------------------------- // Write a binary model dump void WriteBinaryDump(const aiScene* scene, FILE* out, const char* src, const char* cmd, bool shortened, bool compressed, ImportData& imp) { time_t tt = ::time(NULL); tm* p = ::gmtime(&tt); // header ::fprintf(out,"ASSIMP.binary-dump.%s.",::asctime(p)); // == 45 bytes WriteInteger(aiGetVersionMajor(),out); WriteInteger(aiGetVersionMinor(),out); WriteInteger(aiGetVersionRevision(),out); WriteInteger(aiGetCompileFlags(),out); WriteShort(shortened,out); WriteShort(compressed,out); // == 20 bytes char buff[256]; ::strncpy(buff,src,256); ::fwrite(buff,256,1,out); ::strncpy(buff,cmd,128); ::fwrite(buff,128,1,out); // leave 41 bytes free for future extensions ::memset(buff,0xcd,41); ::fwrite(buff,32,1,out); // == 435 bytes // ==== total header size: 500 bytes // Up to here the data is uncompressed. For compressed files, the rest // is compressed using standard DEFLATE from zlib. // basic scene information WriteInteger(scene->mFlags,out); WriteInteger(scene->mNumAnimations,out); WriteInteger(scene->mNumTextures,out); WriteInteger(scene->mNumMaterials,out); WriteInteger(scene->mNumCameras,out); WriteInteger(scene->mNumLights,out); WriteInteger(scene->mNumMeshes,out); // write node graph WriteBinaryNode(scene->mRootNode,out); // write materials for (unsigned int i = 0; i< scene->mNumMaterials; ++i) { const aiMaterial* mat = scene->mMaterials[i]; WriteMagic("#MA",out); WriteInteger(mat->mNumProperties,out); for (unsigned int a = 0; a < mat->mNumProperties;++a) { const aiMaterialProperty* prop = mat->mProperties[a]; WriteMagic("#MP",out); WriteAiString(prop->mKey,out); WriteInteger(prop->mSemantic,out); WriteInteger(prop->mIndex,out); WriteInteger(prop->mDataLength,out); ::fwrite(prop->mData,prop->mDataLength,1,out); } } // write cameras for (unsigned int i = 0; i < scene->mNumCameras;++i) { const aiCamera* cam = scene->mCameras[i]; WriteMagic("#CA",out); WriteAiString(cam->mName,out); WriteVec3(cam->mPosition,out); WriteVec3(cam->mLookAt,out); WriteVec3(cam->mUp,out); WriteFloat(cam->mClipPlaneNear,out); WriteFloat(cam->mClipPlaneFar,out); WriteFloat(cam->mHorizontalFOV,out); WriteFloat(cam->mAspect,out); } // write lights for (unsigned int i = 0; i < scene->mNumLights;++i) { const aiLight* l = scene->mLights[i]; WriteMagic("#LI",out); WriteAiString(l->mName,out); WriteInteger(l->mType,out); WriteVec3((const aiVector3D&)l->mColorDiffuse,out); WriteVec3((const aiVector3D&)l->mColorSpecular,out); WriteVec3((const aiVector3D&)l->mColorAmbient,out); if (l->mType != aiLightSource_DIRECTIONAL) { WriteVec3(l->mPosition,out); WriteFloat(l->mAttenuationLinear,out); WriteFloat(l->mAttenuationConstant,out); WriteFloat(l->mAttenuationQuadratic,out); } if (l->mType != aiLightSource_POINT) { WriteVec3(l->mDirection,out); } if (l->mType == aiLightSource_SPOT) { WriteFloat(l->mAttenuationConstant,out); WriteFloat(l->mAttenuationQuadratic,out); } } // write all animations for (unsigned int i = 0; i < scene->mNumAnimations;++i) { const aiAnimation* anim = scene->mAnimations[i]; WriteMagic("#AN",out); WriteAiString (anim->mName,out); WriteDouble (anim->mTicksPerSecond,out); WriteDouble (anim->mDuration,out); WriteInteger(anim->mNumChannels,out); for (unsigned int a = 0; a < anim->mNumChannels;++a) { const aiNodeAnim* nd = anim->mChannels[a]; WriteMagic("#NA",out); WriteAiString(nd->mNodeName,out); WriteInteger(nd->mPreState,out); WriteInteger(nd->mPostState,out); WriteInteger(nd->mNumPositionKeys,out); WriteInteger(nd->mNumRotationKeys,out); WriteInteger(nd->mNumScalingKeys,out); if (nd->mPositionKeys) { if (shortened) { WriteBounds(nd->mPositionKeys,nd->mNumPositionKeys,out); } // else write as usual else ::fwrite(nd->mPositionKeys,sizeof(aiVectorKey),nd->mNumPositionKeys,out); } if (nd->mRotationKeys) { if (shortened) { WriteBounds(nd->mRotationKeys,nd->mNumRotationKeys,out); } // else write as usual else ::fwrite(nd->mRotationKeys,sizeof(aiQuatKey),nd->mNumRotationKeys,out); } if (nd->mScalingKeys) { if (shortened) { WriteBounds(nd->mScalingKeys,nd->mNumScalingKeys,out); } // else write as usual else ::fwrite(nd->mScalingKeys,sizeof(aiVectorKey),nd->mNumScalingKeys,out); } } } // write all meshes for (unsigned int i = 0; i < scene->mNumMeshes;++i) { const aiMesh* mesh = scene->mMeshes[i]; WriteMagic("#ME",out); WriteInteger(mesh->mPrimitiveTypes,out); WriteInteger(mesh->mNumBones,out); WriteInteger(mesh->mNumFaces,out); WriteInteger(mesh->mNumVertices,out); // write bones if (mesh->mNumBones) { for (unsigned int a = 0; a < mesh->mNumBones;++a) { const aiBone* b = mesh->mBones[a]; WriteMagic("#BN",out); WriteAiString(b->mName,out); WriteMat4x4(b->mOffsetMatrix,out); WriteInteger(b->mNumWeights,out); // for the moment we write dumb min/max values for the bones, too. // maybe I'll add a better, hash-like solution later if (shortened) { WriteBounds(b->mWeights,b->mNumWeights,out); } // else write as usual else ::fwrite(b->mWeights,sizeof(aiVertexWeight),b->mNumWeights,out); } } // write faces. There are no floating-point calculations involved // in these, so we can write a simple hash over the face data // to the dump file. We generate a single 32 Bit hash for 512 faces // using Assimp's standard hashing function. if (shortened) { unsigned int processed = 0; for (unsigned int job;job = std::min(mesh->mNumFaces-processed,512u);processed += job) { unsigned int hash = 0; for (unsigned int a = 0; a < job;++a) { const aiFace& f = mesh->mFaces[processed+a]; hash = SuperFastHash((const char*)&f.mNumIndices,sizeof(unsigned int),hash); hash = SuperFastHash((const char*) f.mIndices,f.mNumIndices*sizeof(unsigned int),hash); } WriteInteger(hash,out); } } else // else write as usual { for (unsigned int i = 0; i < mesh->mNumFaces;++i) { const aiFace& f = mesh->mFaces[i]; WriteInteger(f.mNumIndices,out); for (unsigned int a = 0; a < f.mNumIndices;++a) WriteInteger(f.mIndices[a],out); } } // first of all, write bits for all existent vertex components unsigned int c = 0; if (mesh->mVertices) c |= 1; if (mesh->mNormals) c |= 2; if (mesh->mTangents && mesh->mBitangents) c |= 4; for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_TEXTURECOORDS;++n) { if (!mesh->mTextureCoords[n])break; c |= (8 << n); } for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_COLOR_SETS;++n) { if (!mesh->mColors[n])break; c |= (16 << n); } WriteInteger(c,out); aiVector3D minVec, maxVec; if (mesh->mVertices) { if (shortened) { WriteBounds(mesh->mVertices,mesh->mNumVertices,out); } // else write as usual else ::fwrite(mesh->mVertices,12*mesh->mNumVertices,1,out); } if (mesh->mNormals) { if (shortened) { WriteBounds(mesh->mNormals,mesh->mNumVertices,out); } // else write as usual else ::fwrite(mesh->mNormals,12*mesh->mNumVertices,1,out); } if (mesh->mTangents && mesh->mBitangents) { if (shortened) { WriteBounds(mesh->mTangents,mesh->mNumVertices,out); WriteBounds(mesh->mBitangents,mesh->mNumVertices,out); } // else write as usual else { ::fwrite(mesh->mTangents,12*mesh->mNumVertices,1,out); ::fwrite(mesh->mBitangents,12*mesh->mNumVertices,1,out); } } for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_TEXTURECOORDS;++n) { if (!mesh->mTextureCoords[n])break; // write number of UV components WriteInteger(mesh->mNumUVComponents[n],out); if (shortened) { WriteBounds(mesh->mTextureCoords[n],mesh->mNumVertices,out); } // else write as usual else ::fwrite(mesh->mTextureCoords[n],12*mesh->mNumVertices,1,out); } for (unsigned int n = 0; n < AI_MAX_NUMBER_OF_COLOR_SETS;++n) { if (!mesh->mColors[n]) break; if (shortened) { WriteBounds(mesh->mColors[n],mesh->mNumVertices,out); } // else write as usual else ::fwrite(mesh->mColors[n],16*mesh->mNumVertices,1,out); } } }