//--------------------------------------------------------------------- void Reader::readObject(Ogre::Quaternion& q) { readFloats(&q.x); readFloats(&q.y); readFloats(&q.z); readFloats(&q.w); }
void LodConfigSerializer::readLodAdvancedInfo() { readBools(mStream, &mLodConfig->advanced.useCompression, 1); readBools(mStream, &mLodConfig->advanced.useVertexNormals, 1); readBools(mStream, &mLodConfig->advanced.useBackgroundQueue, 1); readFloats(mStream, &mLodConfig->advanced.outsideWeight, 1); readFloats(mStream, &mLodConfig->advanced.outsideWalkAngle, 1); }
//--------------------------------------------------------------------- void SkeletonSerializer::readAnimation(DataStreamPtr& stream, Skeleton* pSkel) { // char* name : Name of the animation String name; name = readString(stream); // float length : Length of the animation in seconds float len; readFloats(stream, &len, 1); Animation *pAnim = pSkel->createAnimation(name, len); // Read all tracks if (!stream->eof()) { unsigned short streamID = readChunk(stream); // Optional base info is possible if (streamID == SKELETON_ANIMATION_BASEINFO) { // char baseAnimationName String baseAnimName = readString(stream); // float baseKeyFrameTime float baseKeyTime; readFloats(stream, &baseKeyTime, 1); pAnim->setUseBaseKeyFrame(true, baseKeyTime, baseAnimName); if (!stream->eof()) { // Get next stream streamID = readChunk(stream); } } while(streamID == SKELETON_ANIMATION_TRACK && !stream->eof()) { readAnimationTrack(stream, pAnim, pSkel); if (!stream->eof()) { // Get next stream streamID = readChunk(stream); } } if (!stream->eof()) { // Backpedal back to start of this stream if we've found a non-track stream->skip(-SSTREAM_OVERHEAD_SIZE); } } }
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); } }
//--------------------------------------------------------------------- void SkeletonSerializer::readKeyFrame(DataStreamPtr& stream, NodeAnimationTrack* track, Skeleton* pSkel) { // float time : The time position (seconds) float time; readFloats(stream, &time, 1); TransformKeyFrame *kf = track->createNodeKeyFrame(time); // Quaternion rotate : Rotation to apply at this keyframe Quaternion rot; readObject(stream, rot); kf->setRotation(rot); // Vector3 translate : Translation to apply at this keyframe Vector3 trans; readObject(stream, trans); kf->setTranslate(trans); // Do we have scale? if (mCurrentstreamLen > calcKeyFrameSizeWithoutScale(pSkel, kf)) { Vector3 scale; readObject(stream, scale); kf->setScale(scale); } }
void SkeletonSerializerEx::readAnimation(Ogre::DataStreamPtr& stream, Ogre::Skeleton* pSkel) { // char* name : Name of the animation Ogre::String name; name = readString(stream); // float length : Length of the animation in seconds float len; readFloats(stream, &len, 1); Ogre::Animation *pAnim = pSkel->createAnimation(name, len); // Read all tracks if (!stream->eof()) { unsigned short streamID = readChunk(stream); while(streamID == Ogre::SKELETON_ANIMATION_TRACK && !stream->eof()) { readAnimationTrack(stream, pAnim, pSkel); if (!stream->eof()) { // Get next stream streamID = readChunk(stream); } } if (!stream->eof()) { // Backpedal back to start of this stream if we've found a non-track stream->skip(-STREAM_OVERHEAD_SIZE); } } }
bool B3DMeshLoader::readChunkANIM() { #ifdef _B3D_READER_DEBUG core::stringc logStr; for ( u32 i=1; i < B3dStack.size(); ++i ) logStr += "-"; logStr += "read ChunkANIM"; os::Printer::log(logStr.c_str()); #endif s32 animFlags; //not stored\used s32 animFrames;//not stored\used f32 animFPS; //not stored\used B3DFile->read(&animFlags, sizeof(s32)); B3DFile->read(&animFrames, sizeof(s32)); readFloats(&animFPS, 1); if (animFPS>0.f) AnimatedMesh->setAnimationSpeed(animFPS); os::Printer::log("FPS", io::path((double)animFPS), ELL_DEBUG); #ifdef __BIG_ENDIAN__ animFlags = os::Byteswap::byteswap(animFlags); animFrames = os::Byteswap::byteswap(animFrames); #endif B3dStack.erase(B3dStack.size()-1); return true; }
void Serializer::readObject(Vector3& pDest) { float tmp[3]; readFloats(tmp, 3); pDest.x = tmp[0]; pDest.y = tmp[1]; pDest.z = tmp[2]; }
//--------------------------------------------------------------------- void Serializer::readObject(DataStreamPtr& stream, Quaternion& pDest) { float tmp[4]; readFloats(stream, tmp, 4); pDest.x = tmp[0]; pDest.y = tmp[1]; pDest.z = tmp[2]; pDest.w = tmp[3]; }
void Serializer::readObject(Quaternion& pDest) { float tmp[4]; readFloats(tmp, 4); pDest.x = tmp[0]; pDest.y = tmp[1]; pDest.z = tmp[2]; pDest.w = tmp[3]; }
bool B3DMeshLoader::readChunkTEXS() { #ifdef _B3D_READER_DEBUG core::stringc logStr; for ( u32 i=1; i < B3dStack.size(); ++i ) logStr += "-"; logStr += "read ChunkTEXS"; os::Printer::log(logStr.c_str()); #endif while((B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) //this chunk repeats { Textures.push_back(SB3dTexture()); SB3dTexture& B3dTexture = Textures.getLast(); readString(B3dTexture.TextureName); B3dTexture.TextureName.replace('\\','/'); #ifdef _B3D_READER_DEBUG os::Printer::log("read Texture", B3dTexture.TextureName.c_str()); #endif B3DFile->read(&B3dTexture.Flags, sizeof(s32)); B3DFile->read(&B3dTexture.Blend, sizeof(s32)); #ifdef __BIG_ENDIAN__ B3dTexture.Flags = os::Byteswap::byteswap(B3dTexture.Flags); B3dTexture.Blend = os::Byteswap::byteswap(B3dTexture.Blend); #endif #ifdef _B3D_READER_DEBUG os::Printer::log("Flags", core::stringc(B3dTexture.Flags).c_str()); os::Printer::log("Blend", core::stringc(B3dTexture.Blend).c_str()); #endif readFloats(&B3dTexture.Xpos, 1); readFloats(&B3dTexture.Ypos, 1); readFloats(&B3dTexture.Xscale, 1); readFloats(&B3dTexture.Yscale, 1); readFloats(&B3dTexture.Angle, 1); } B3dStack.erase(B3dStack.size()-1); return true; }
//--------------------------------------------------------------------- void SkeletonSerializer::readSkeletonAnimationLink(DataStreamPtr& stream, Skeleton* pSkel) { // char* skeletonName String skelName = readString(stream); // float scale float scale; readFloats(stream, &scale, 1); pSkel->addLinkedSkeletonAnimationSource(skelName, scale); }
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 OgreMeshDeserializer::readBoundsInfo() { WFMath::Point<3> min, max; readFloats(m_stream, &min.x(), 1); readFloats(m_stream, &min.y(), 1); readFloats(m_stream, &min.z(), 1); readFloats(m_stream, &max.x(), 1); readFloats(m_stream, &max.y(), 1); readFloats(m_stream, &max.z(), 1); min.setValid(true); max.setValid(true); m_bounds = WFMath::AxisBox<3>(min, max); readFloats(m_stream, &m_radius, 1); }
static void readVertices(spSkeletonBinary *self, spVertexAttachment *attachment, int vertexCount) { if (!readBoolean(self)) { attachment->vertices = readFloats(self, self->scale, vertexCount << 1); attachment->verticesCount = vertexCount << 1; attachment->bones = NULL; attachment->bonesCount = 0; } else { float *weights; int *bones; int weightCount = 0, boneCount = 0; int position = self->data->position; for (int i = 0; i < vertexCount; i++) { int nn = readVarint(self, true); boneCount++; for (int ii = 0; ii < nn; ii++) { readVarint(self, true); self->data->position += sizeof(float) * 3; weightCount += 3; boneCount++; } } self->data->position = position; attachment->bones = MALLOC(int, boneCount); attachment->bonesCount = boneCount; attachment->vertices = MALLOC(float, weightCount); attachment->verticesCount = weightCount; weights = attachment->vertices; bones = attachment->bones; for (int i = 0; i < vertexCount; i++) { int nn = readVarint(self, true); *bones++ = nn; for (int ii = 0; ii < nn; ii++) { *bones++ = readVarint(self, true); *weights++ = readFloat(self) * self->scale; *weights++ = readFloat(self) * self->scale; *weights++ = readFloat(self); } } } }
//--------------------------------------------------------------------- void Reader::readObject(Ogre::Vector3& v) { readFloats(&v.x); readFloats(&v.y); readFloats(&v.z); }
bool B3DMeshLoader::readChunkKEYS(scene::CSkinnedMesh::SJoint *inJoint) { #ifdef _B3D_READER_DEBUG // Only print first, that's just too much output otherwise if ( !inJoint || (inJoint->PositionKeys.empty() && inJoint->ScaleKeys.empty() && inJoint->RotationKeys.empty()) ) { core::stringc logStr; for ( u32 i=1; i < B3dStack.size(); ++i ) logStr += "-"; logStr += "read ChunkKEYS"; os::Printer::log(logStr.c_str()); } #endif s32 flags; B3DFile->read(&flags, sizeof(flags)); #ifdef __BIG_ENDIAN__ flags = os::Byteswap::byteswap(flags); #endif scene::CSkinnedMesh::SPositionKey *oldPosKey=0; core::vector3df oldPos[2]; scene::CSkinnedMesh::SScaleKey *oldScaleKey=0; core::vector3df oldScale[2]; scene::CSkinnedMesh::SRotationKey *oldRotKey=0; core::quaternion oldRot[2]; bool isFirst[3]={true,true,true}; while((B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) //this chunk repeats { s32 frame; B3DFile->read(&frame, sizeof(frame)); #ifdef __BIG_ENDIAN__ frame = os::Byteswap::byteswap(frame); #endif // Add key frames, frames in Irrlicht are zero-based f32 data[4]; if (flags & 1) { readFloats(data, 3); if ((oldPosKey!=0) && (oldPos[0]==oldPos[1])) { const core::vector3df pos(data[0], data[1], data[2]); if (oldPos[1]==pos) oldPosKey->frame = (f32)frame-1; else { oldPos[0]=oldPos[1]; oldPosKey=AnimatedMesh->addPositionKey(inJoint); oldPosKey->frame = (f32)frame-1; oldPos[1].set(oldPosKey->position.set(pos)); } } else if (oldPosKey==0 && isFirst[0]) { oldPosKey=AnimatedMesh->addPositionKey(inJoint); oldPosKey->frame = (f32)frame-1; oldPos[0].set(oldPosKey->position.set(data[0], data[1], data[2])); oldPosKey=0; isFirst[0]=false; } else { if (oldPosKey!=0) oldPos[0]=oldPos[1]; oldPosKey=AnimatedMesh->addPositionKey(inJoint); oldPosKey->frame = (f32)frame-1; oldPos[1].set(oldPosKey->position.set(data[0], data[1], data[2])); } } if (flags & 2) { readFloats(data, 3); if ((oldScaleKey!=0) && (oldScale[0]==oldScale[1])) { const core::vector3df scale(data[0], data[1], data[2]); if (oldScale[1]==scale) oldScaleKey->frame = (f32)frame-1; else { oldScale[0]=oldScale[1]; oldScaleKey=AnimatedMesh->addScaleKey(inJoint); oldScaleKey->frame = (f32)frame-1; oldScale[1].set(oldScaleKey->scale.set(scale)); } } else if (oldScaleKey==0 && isFirst[1]) { oldScaleKey=AnimatedMesh->addScaleKey(inJoint); oldScaleKey->frame = (f32)frame-1; oldScale[0].set(oldScaleKey->scale.set(data[0], data[1], data[2])); oldScaleKey=0; isFirst[1]=false; } else { if (oldScaleKey!=0) oldScale[0]=oldScale[1]; oldScaleKey=AnimatedMesh->addScaleKey(inJoint); oldScaleKey->frame = (f32)frame-1; oldScale[1].set(oldScaleKey->scale.set(data[0], data[1], data[2])); } } if (flags & 4) { readFloats(data, 4); if ((oldRotKey!=0) && (oldRot[0]==oldRot[1])) { // meant to be in this order since b3d stores W first const core::quaternion rot(data[1], data[2], data[3], data[0]); if (oldRot[1]==rot) oldRotKey->frame = (f32)frame-1; else { oldRot[0]=oldRot[1]; oldRotKey=AnimatedMesh->addRotationKey(inJoint); oldRotKey->frame = (f32)frame-1; oldRot[1].set(oldRotKey->rotation.set(data[1], data[2], data[3], data[0])); } } else if (oldRotKey==0 && isFirst[2]) { oldRotKey=AnimatedMesh->addRotationKey(inJoint); oldRotKey->frame = (f32)frame-1; // meant to be in this order since b3d stores W first oldRot[0].set(oldRotKey->rotation.set(data[1], data[2], data[3], data[0])); oldRotKey=0; isFirst[2]=false; } else { if (oldRotKey!=0) oldRot[0]=oldRot[1]; oldRotKey=AnimatedMesh->addRotationKey(inJoint); oldRotKey->frame = (f32)frame-1; // meant to be in this order since b3d stores W first oldRot[1].set(oldRotKey->rotation.set(data[1], data[2], data[3], data[0])); } } } B3dStack.erase(B3dStack.size()-1); return true; }
/* VRTS: int flags ;1=normal values present, 2=rgba values present int tex_coord_sets ;texture coords per vertex (eg: 1 for simple U/V) max=8 but we only support 3 int tex_coord_set_size ;components per set (eg: 2 for simple U/V) max=4 { float x,y,z ;always present float nx,ny,nz ;vertex normal: present if (flags&1) float red,green,blue,alpha ;vertex color: present if (flags&2) float tex_coords[tex_coord_sets][tex_coord_set_size] ;tex coords } */ bool B3DMeshLoader::readChunkVRTS(scene::CSkinnedMesh::SJoint *inJoint) { #ifdef _B3D_READER_DEBUG core::stringc logStr; for ( u32 i=1; i < B3dStack.size(); ++i ) logStr += "-"; logStr += "ChunkVRTS"; os::Printer::log(logStr.c_str()); #endif const s32 max_tex_coords = 3; s32 flags, tex_coord_sets, tex_coord_set_size; B3DFile->read(&flags, sizeof(flags)); B3DFile->read(&tex_coord_sets, sizeof(tex_coord_sets)); B3DFile->read(&tex_coord_set_size, sizeof(tex_coord_set_size)); #ifdef __BIG_ENDIAN__ flags = os::Byteswap::byteswap(flags); tex_coord_sets = os::Byteswap::byteswap(tex_coord_sets); tex_coord_set_size = os::Byteswap::byteswap(tex_coord_set_size); #endif if (tex_coord_sets >= max_tex_coords || tex_coord_set_size >= 4) // Something is wrong { os::Printer::log("tex_coord_sets or tex_coord_set_size too big", B3DFile->getFileName(), ELL_ERROR); return false; } //------ Allocate Memory, for speed -----------// s32 numberOfReads = 3; if (flags & 1) { NormalsInFile = true; numberOfReads += 3; } if (flags & 2) { numberOfReads += 4; HasVertexColors=true; } numberOfReads += tex_coord_sets*tex_coord_set_size; const s32 memoryNeeded = (B3dStack.getLast().length / sizeof(f32)) / numberOfReads; BaseVertices.reallocate(memoryNeeded + BaseVertices.size() + 1); AnimatedVertices_VertexID.reallocate(memoryNeeded + AnimatedVertices_VertexID.size() + 1); //--------------------------------------------// while( (B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) // this chunk repeats { f32 position[3]; f32 normal[3]={0.f, 0.f, 0.f}; f32 color[4]={1.0f, 1.0f, 1.0f, 1.0f}; f32 tex_coords[max_tex_coords][4]; readFloats(position, 3); if (flags & 1) readFloats(normal, 3); if (flags & 2) readFloats(color, 4); for (s32 i=0; i<tex_coord_sets; ++i) readFloats(tex_coords[i], tex_coord_set_size); f32 tu=0.0f, tv=0.0f; if (tex_coord_sets >= 1 && tex_coord_set_size >= 2) { tu=tex_coords[0][0]; tv=tex_coords[0][1]; } f32 tu2=0.0f, tv2=0.0f; if (tex_coord_sets>1 && tex_coord_set_size>1) { tu2=tex_coords[1][0]; tv2=tex_coords[1][1]; } // Create Vertex... video::S3DVertex2TCoords Vertex(position[0], position[1], position[2], normal[0], normal[1], normal[2], video::SColorf(color[0], color[1], color[2], color[3]).toSColor(), tu, tv, tu2, tv2); // Transform the Vertex position by nested node... inJoint->GlobalMatrix.transformVect(Vertex.Pos); inJoint->GlobalMatrix.rotateVect(Vertex.Normal); //Add it... BaseVertices.push_back(Vertex); AnimatedVertices_VertexID.push_back(-1); AnimatedVertices_BufferID.push_back(-1); } B3dStack.erase(B3dStack.size()-1); return true; }
bool B3DMeshLoader::readChunkNODE(scene::CSkinnedMesh::SJoint *inJoint) { scene::CSkinnedMesh::SJoint *joint = AnimatedMesh->addJoint(inJoint); readString(joint->Name); #ifdef _B3D_READER_DEBUG core::stringc logStr; for ( u32 i=1; i < B3dStack.size(); ++i ) logStr += "-"; logStr += "read ChunkNODE"; os::Printer::log(logStr.c_str(), joint->Name.c_str()); #endif f32 position[3], scale[3], rotation[4]; readFloats(position, 3); readFloats(scale, 3); readFloats(rotation, 4); joint->Animatedposition = core::vector3df(position[0],position[1],position[2]) ; joint->Animatedscale = core::vector3df(scale[0],scale[1],scale[2]); joint->Animatedrotation = core::quaternion(rotation[1], rotation[2], rotation[3], rotation[0]); //Build LocalMatrix: core::matrix4 positionMatrix; positionMatrix.setTranslation( joint->Animatedposition ); core::matrix4 scaleMatrix; scaleMatrix.setScale( joint->Animatedscale ); core::matrix4 rotationMatrix; joint->Animatedrotation.getMatrix_transposed(rotationMatrix); joint->LocalMatrix = positionMatrix * rotationMatrix * scaleMatrix; if (inJoint) joint->GlobalMatrix = inJoint->GlobalMatrix * joint->LocalMatrix; else joint->GlobalMatrix = joint->LocalMatrix; while(B3dStack.getLast().startposition + B3dStack.getLast().length > B3DFile->getPos()) // this chunk repeats { SB3dChunkHeader header; B3DFile->read(&header, sizeof(header)); #ifdef __BIG_ENDIAN__ header.size = os::Byteswap::byteswap(header.size); #endif B3dStack.push_back(SB3dChunk(header, B3DFile->getPos()-8)); if ( strncmp( B3dStack.getLast().name, "NODE", 4 ) == 0 ) { if (!readChunkNODE(joint)) return false; } else if ( strncmp( B3dStack.getLast().name, "MESH", 4 ) == 0 ) { VerticesStart=BaseVertices.size(); if (!readChunkMESH(joint)) return false; } else if ( strncmp( B3dStack.getLast().name, "BONE", 4 ) == 0 ) { if (!readChunkBONE(joint)) return false; } else if ( strncmp( B3dStack.getLast().name, "KEYS", 4 ) == 0 ) { if(!readChunkKEYS(joint)) return false; } else if ( strncmp( B3dStack.getLast().name, "ANIM", 4 ) == 0 ) { if (!readChunkANIM()) return false; } else { os::Printer::log("Unknown chunk found in node chunk - skipping"); B3DFile->seek(B3dStack.getLast().startposition + B3dStack.getLast().length); B3dStack.erase(B3dStack.size()-1); } } B3dStack.erase(B3dStack.size()-1); return true; }
bool B3DMeshLoader::readChunkBRUS() { #ifdef _B3D_READER_DEBUG core::stringc logStr; for ( u32 i=1; i < B3dStack.size(); ++i ) logStr += "-"; logStr += "read ChunkBRUS"; os::Printer::log(logStr.c_str()); #endif u32 n_texs; B3DFile->read(&n_texs, sizeof(u32)); #ifdef __BIG_ENDIAN__ n_texs = os::Byteswap::byteswap(n_texs); #endif // number of texture ids read for Irrlicht const u32 num_textures = core::min_(n_texs, video::MATERIAL_MAX_TEXTURES); // number of bytes to skip (for ignored texture ids) const u32 n_texs_offset = (num_textures<n_texs)?(n_texs-num_textures):0; while((B3dStack.getLast().startposition + B3dStack.getLast().length) > B3DFile->getPos()) //this chunk repeats { // This is what blitz basic calls a brush, like a Irrlicht Material core::stringc name; readString(name); #ifdef _B3D_READER_DEBUG os::Printer::log("read Material", name); #endif Materials.push_back(SB3dMaterial()); SB3dMaterial& B3dMaterial=Materials.getLast(); readFloats(&B3dMaterial.red, 1); readFloats(&B3dMaterial.green, 1); readFloats(&B3dMaterial.blue, 1); readFloats(&B3dMaterial.alpha, 1); readFloats(&B3dMaterial.shininess, 1); B3DFile->read(&B3dMaterial.blend, sizeof(B3dMaterial.blend)); B3DFile->read(&B3dMaterial.fx, sizeof(B3dMaterial.fx)); #ifdef __BIG_ENDIAN__ B3dMaterial.blend = os::Byteswap::byteswap(B3dMaterial.blend); B3dMaterial.fx = os::Byteswap::byteswap(B3dMaterial.fx); #endif #ifdef _B3D_READER_DEBUG os::Printer::log("Blend", core::stringc(B3dMaterial.blend).c_str()); os::Printer::log("FX", core::stringc(B3dMaterial.fx).c_str()); #endif u32 i; for (i=0; i<num_textures; ++i) { s32 texture_id=-1; B3DFile->read(&texture_id, sizeof(s32)); #ifdef __BIG_ENDIAN__ texture_id = os::Byteswap::byteswap(texture_id); #endif //--- Get pointers to the texture, based on the IDs --- if ((u32)texture_id < Textures.size()) { B3dMaterial.Textures[i]=&Textures[texture_id]; #ifdef _B3D_READER_DEBUG os::Printer::log("Layer", core::stringc(i).c_str()); os::Printer::log("using texture", Textures[texture_id].TextureName.c_str()); #endif } else B3dMaterial.Textures[i]=0; } // skip other texture ids for (i=0; i<n_texs_offset; ++i) { s32 texture_id=-1; B3DFile->read(&texture_id, sizeof(s32)); #ifdef __BIG_ENDIAN__ texture_id = os::Byteswap::byteswap(texture_id); #endif if (ShowWarning && (texture_id != -1) && (n_texs>video::MATERIAL_MAX_TEXTURES)) { os::Printer::log("Too many textures used in one material", B3DFile->getFileName(), ELL_WARNING); ShowWarning = false; } } //Fixes problems when the lightmap is on the first texture: if (B3dMaterial.Textures[0] != 0) { if (B3dMaterial.Textures[0]->Flags & 65536) // 65536 = secondary UV { SB3dTexture *TmpTexture; TmpTexture = B3dMaterial.Textures[1]; B3dMaterial.Textures[1] = B3dMaterial.Textures[0]; B3dMaterial.Textures[0] = TmpTexture; } } //If a preceeding texture slot is empty move the others down: for (i=num_textures; i>0; --i) { for (u32 j=i-1; j<num_textures-1; ++j) { if (B3dMaterial.Textures[j+1] != 0 && B3dMaterial.Textures[j] == 0) { B3dMaterial.Textures[j] = B3dMaterial.Textures[j+1]; B3dMaterial.Textures[j+1] = 0; } } } //------ Convert blitz flags/blend to irrlicht ------- //Two textures: if (B3dMaterial.Textures[1]) { if (B3dMaterial.alpha==1.f) { if (B3dMaterial.Textures[1]->Blend == 5) //(Multiply 2) B3dMaterial.Material.MaterialType = video::EMT_LIGHTMAP_M2; else B3dMaterial.Material.MaterialType = video::EMT_LIGHTMAP; B3dMaterial.Material.Lighting = false; } else { B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; B3dMaterial.Material.ZWriteEnable = false; } } else if (B3dMaterial.Textures[0]) //One texture: { // Flags & 0x1 is usual SOLID, 0x8 is mipmap (handled before) if (B3dMaterial.Textures[0]->Flags & 0x2) //(Alpha mapped) { B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; B3dMaterial.Material.ZWriteEnable = false; } else if (B3dMaterial.Textures[0]->Flags & 0x4) //(Masked) B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF; // TODO: create color key texture else if (B3dMaterial.Textures[0]->Flags & 0x40) B3dMaterial.Material.MaterialType = video::EMT_SPHERE_MAP; else if (B3dMaterial.Textures[0]->Flags & 0x80) B3dMaterial.Material.MaterialType = video::EMT_SPHERE_MAP; // TODO: Should be cube map else if (B3dMaterial.alpha == 1.f) B3dMaterial.Material.MaterialType = video::EMT_SOLID; else { B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; B3dMaterial.Material.ZWriteEnable = false; } } else //No texture: { if (B3dMaterial.alpha == 1.f) B3dMaterial.Material.MaterialType = video::EMT_SOLID; else { B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; B3dMaterial.Material.ZWriteEnable = false; } } B3dMaterial.Material.DiffuseColor = video::SColorf(B3dMaterial.red, B3dMaterial.green, B3dMaterial.blue, B3dMaterial.alpha).toSColor(); B3dMaterial.Material.ColorMaterial=video::ECM_NONE; //------ Material fx ------ if (B3dMaterial.fx & 1) //full-bright { B3dMaterial.Material.AmbientColor = video::SColor(255, 255, 255, 255); B3dMaterial.Material.Lighting = false; } else B3dMaterial.Material.AmbientColor = B3dMaterial.Material.DiffuseColor; if (B3dMaterial.fx & 2) //use vertex colors instead of brush color B3dMaterial.Material.ColorMaterial=video::ECM_DIFFUSE_AND_AMBIENT; if (B3dMaterial.fx & 4) //flatshaded B3dMaterial.Material.GouraudShading = false; if (B3dMaterial.fx & 16) //disable backface culling B3dMaterial.Material.BackfaceCulling = false; if (B3dMaterial.fx & 32) //force vertex alpha-blending { B3dMaterial.Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA; B3dMaterial.Material.ZWriteEnable = false; } B3dMaterial.Material.Shininess = B3dMaterial.shininess; } B3dStack.erase(B3dStack.size()-1); return true; }
//--------------------------------------------------------------------- void Serializer::readObject(DataStreamPtr& stream, Vector3& pDest) { readFloats(stream, pDest.ptr(), 3); }
void TriMeshLoader::processVertex(char* tok,TriMesh *pmesh){ //cout << "PROCESSING VERTEX" << endl; float values[3]; int cnt=readFloats(tok,values,3); if(cnt>=3) pmesh->addVertex(values); }
void SkeletonSerializerEx::readAnimationTrack( Ogre::DataStreamPtr& stream, Ogre::Animation* anim, Ogre::Skeleton* pSkel) { // unsigned short boneIndex : Index of bone to apply to unsigned short boneHandle; readShorts(stream, &boneHandle, 1); // Find bone Ogre::Bone *targetBone = pSkel->getBone(boneHandle); // Create track Ogre::NodeAnimationTrack* pTrack = anim->createNodeTrack(boneHandle, targetBone); // Keep looking for nested keyframes if (!stream->eof()) { unsigned short streamID = readChunk(stream); while((streamID == Ogre::SKELETON_ANIMATION_TRACK_KEYFRAME || streamID == 0x4120 ) && !stream->eof()) { if (streamID == 0x4120) { unsigned short len; unsigned short flags; readShorts(stream, &len, 1); readShorts(stream, &flags, 1); float time; for (int i = 0; i < len; i += 1) { readFloats(stream, &time, 1); Ogre::TransformKeyFrame *kf = pTrack->createNodeKeyFrame(time); Ogre::Quaternion rot = Ogre::Quaternion::IDENTITY; if (flags & 1) { readObject(stream, rot); } kf->setRotation(rot); Ogre::Vector3 trans = Ogre::Vector3::ZERO; if (flags & 2) { readObject(stream, trans); } kf->setTranslate(trans); // 为正确解析天龙八部模型的骨骼动画 Ogre::Vector3 scale = Ogre::Vector3::UNIT_SCALE; if (flags & 4) { readObject(stream, scale); } kf->setScale(scale); } } else readKeyFrame(stream, pTrack, pSkel); if (!stream->eof()) { // Get next stream streamID = readChunk(stream); } } if (!stream->eof()) { // Backpedal back to start of this stream if we've found a non-keyframe stream->skip(-STREAM_OVERHEAD_SIZE); } } }
static spAttachment *readAttachment(spSkeletonBinary *self, spSkin *skin, int slotIndex, const char *attachmentName) { spAttachment *attachment = NULL; float scale = self->scale; char *name = readString(self); if (name == NULL) name = (char *)attachmentName; switch ((spAttachmentType)readByte(self)) { case SP_ATTACHMENT_REGION: { spRegionAttachment *region; char *path = readString(self); if (path == NULL) path = name; attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_REGION, name, path); region = SUB_CAST(spRegionAttachment, attachment); if (path) { region->path = copyString(path); } region->rotation = readFloat(self); region->x = readFloat(self) * scale; region->y = readFloat(self) * scale; region->scaleX = readFloat(self); region->scaleY = readFloat(self); region->width = readFloat(self) * scale; region->height = readFloat(self) * scale; readColor(self, ®ion->r, ®ion->g, ®ion->b, ®ion->a); spRegionAttachment_updateOffset(region); spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); break; } case SP_ATTACHMENT_BOUNDING_BOX: { spBoundingBoxAttachment *boundingBox; int vertexCount = readVarint(self, true); attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_BOUNDING_BOX, name, name); boundingBox = SUB_CAST(spBoundingBoxAttachment, attachment); readVertices(self, SUPER(boundingBox), vertexCount); SUPER(boundingBox)->worldVerticesLength = vertexCount << 1; spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); break; } case SP_ATTACHMENT_MESH: { spMeshAttachment *mesh; int vertexCount; char *path = readString(self); if (path == NULL) path = name; attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_MESH, name, path); mesh = SUB_CAST(spMeshAttachment, attachment); if (path) { mesh->path = copyString(path); } readColor(self, &mesh->r, &mesh->g, &mesh->b, &mesh->a); vertexCount = readVarint(self, true); mesh->regionUVs = readFloats(self, 1, vertexCount << 1); mesh->trianglesCount = readVarint(self, true); mesh->triangles = readShorts(self, mesh->trianglesCount); readVertices(self, SUPER(mesh), vertexCount); SUPER(mesh)->worldVerticesLength = vertexCount << 1; mesh->hullLength = readVarint(self, true) << 1; spMeshAttachment_updateUVs(mesh); spAttachmentLoader_configureAttachment(self->attachmentLoader, attachment); break; } case SP_ATTACHMENT_LINKED_MESH: { spMeshAttachment *mesh; char *parent; char *skinName; char *path = readString(self); if (path == NULL) path = name; attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_LINKED_MESH, name, path); mesh = SUB_CAST(spMeshAttachment, attachment); if (path) { mesh->path = copyString(path); } readColor(self, &mesh->r, &mesh->g, &mesh->b, &mesh->a); skinName = readString(self); parent = readString(self); mesh->inheritDeform = readBoolean(self); addLinkedMesh(self, mesh, skinName, slotIndex, parent); break; } case SP_ATTACHMENT_PATH: { spPathAttachment *path; int vertexCount; attachment = spAttachmentLoader_createAttachment(self->attachmentLoader, skin, SP_ATTACHMENT_PATH, name, NULL); path = SUB_CAST(spPathAttachment, attachment); path->closed = readBoolean(self); path->constantSpeed = readBoolean(self); vertexCount = readVarint(self, true); readVertices(self, SUPER(path), vertexCount); SUPER(path)->worldVerticesLength = vertexCount << 1; path->lengthsLength = vertexCount / 3; path->lengths = MALLOC(float, path->lengthsLength); for (int i = 0; i < path->lengthsLength; i++) { path->lengths[i] = readFloat(self) * self->scale; } break; } } return attachment; }