} // Read PART private ZSCEffect ReadEffect() { uint transFlags = ZSC_TRANSITION_NONE; ZSCEffect effect = new ZSCEffect { EffectID = bh.ReadWord(), EffectType = bh.ReadWord() }; transFlags = ZSC_TRANSITION_NONE; while (true) { byte IDFlag = br.ReadByte(); if (IDFlag == 0) { break; } byte size = br.ReadByte(); switch (IDFlag) { case ZSC_EFFECT_POSITION: effect.Position = bh.ReadVector3f() * 0.01f; transFlags = transFlags | ZSC_TRANSITION_TRANSLATE; break; case ZSC_EFFECT_ROTATION: effect.Rotation = bh.ReadQuaternion(); transFlags = transFlags | ZSC_TRANSITION_ROTATE; break; case ZSC_EFFECT_SCALE: effect.Scale = bh.ReadVector3f(); transFlags = transFlags | ZSC_TRANSITION_SCALE; break; case ZSC_EFFECT_PARENT: effect.ParrentID = (int)bh.ReadWord(); break; default: br.ReadBytes(size); break; } // switch case } ; effect.TransformMatrix = Matrix4.IDENTITY; if ((transFlags & ZSC_TRANSITION_ROTATE) != 0) { effect.TransformMatrix = new Matrix4(effect.Rotation.ToRotationMatrix()); } if ((transFlags & ZSC_TRANSITION_SCALE) != 0) { effect.TransformMatrix.SetScale(effect.Scale); } if ((transFlags & ZSC_TRANSITION_TRANSLATE) != 0) { effect.TransformMatrix.SetTrans(effect.Position); } return(effect); } // Read Effect
public bool Load(string FileName) { try { FileStream fileStream = File.OpenRead(FileName); br = new BinaryReader(fileStream, koreanEncoding); bh = new BinaryHelper(br); try { MeshCount = bh.ReadWord(); for (int meshID = 0; meshID < MeshCount; meshID++) { MeshName.Add(bh.ReadZString()); } MaterialCount = bh.ReadWord(); for (int materialID = 0; materialID < MaterialCount; materialID++) { ZSCMaterial mat = new ZSCMaterial(); mat.Path = bh.ReadZString(); br.ReadBytes(2); // Skip 2 bytes! mat.UseAlpha = (bh.ReadWord() > 0); mat.DoubleSided = (bh.ReadWord() > 0); mat.AlphaTest = bh.ReadWord(); mat.AlphaRef = (bh.ReadWord() / 256.0f); mat.zTest = (bh.ReadWord() > 0); mat.zWrite = (bh.ReadWord() > 0); mat.BlendType = bh.ReadWord(); mat.Specular = bh.ReadWord(); mat.Alpha = br.ReadSingle(); mat.GlowType = bh.ReadWord(); mat.r = br.ReadSingle(); mat.g = br.ReadSingle(); mat.b = br.ReadSingle(); Material.Add(mat); } uint effectsNames_count = bh.ReadWord(); for (int effID = 0; effID < effectsNames_count; effID++) { EffectName.Add(bh.ReadZString()); } uint models_count = bh.ReadWord(); for (int modID = 0; modID < models_count; modID++) { ZSCModel model = new ZSCModel(); model.BBRadius = bh.ReadDWord(); model.BBX = bh.ReadDWord(); model.BBY = bh.ReadDWord(); uint parts_count = bh.ReadWord(); if (parts_count > 0) { // PARTS for (int jparts = 0; jparts < parts_count; jparts++) { ZSCPart part = ReadPart(); if (jparts == 0) { part.ParentID = -1; } model.Part.Add(part); } // parts // EFFECTS uint effects_count = bh.ReadWord(); for (int jeffects = 0; jeffects < effects_count; jeffects++) { ZSCEffect effect = ReadEffect(); model.Effect.Add(effect); } } // if > 0 else { Model.Add(model); continue; } model.BBoxMin = bh.ReadVector3f() * 0.01f; model.BBoxMax = bh.ReadVector3f() * 0.01f; Model.Add(model); } } finally { br.Close(); fileStream.Close(); } } catch (Exception) { return(false); } return(true); }