示例#1
0
        public override Stream UnParse()
        {
            MemoryStream ms = new MemoryStream();
            BinaryWriter w  = new BinaryWriter(ms);

            w.Write(tag);
            w.Write(version);
            w.Write(materialNameHash);
            w.Write((uint)shader);
            long lenPos = ms.Position;

            w.Write((uint)0);//length
            long pos;

            if (version < 0x00000103)
            {
                pos = ms.Position;
                if (mtrl == null)
                {
                    mtrl = new MTRL(requestedApiVersion, OnRCOLChanged);
                }
                mtrl.UnParse(ms);
            }
            else
            {
                w.Write(isVideoSurface ? 1 : 0);
                w.Write(isPaintingSurface ? 1 : 0);
                pos = ms.Position;
                if (mtnf == null)
                {
                    mtnf = new MTNF(requestedApiVersion, OnRCOLChanged);
                }
                mtnf.UnParse(ms);
            }

            long endPos = ms.Position;

            ms.Position = lenPos;
            w.Write((uint)(endPos - pos));
            ms.Position = endPos;

            return(ms);
        }
示例#2
0
 public MATD(int APIversion, EventHandler handler,
             uint version, uint materialNameHash, ShaderType shader, bool isVideoSurface, bool isPaintingSurface, MTNF mtnf)
     : base(APIversion, handler, null)
 {
     this.version          = version;
     this.materialNameHash = materialNameHash;
     this.shader           = shader;
     if (checking)
     {
         if (version < 0x00000103)
         {
             throw new ArgumentException("version must be >= 0x0103 for MTNFs");
         }
     }
     this.isVideoSurface    = isVideoSurface;
     this.isPaintingSurface = isPaintingSurface;
     this.mtnf = mtnf != null
         ? new MTNF(requestedApiVersion, OnRCOLChanged, mtnf)
         : new MTNF(requestedApiVersion, OnRCOLChanged);
 }
示例#3
0
 public MATD(int APIversion, EventHandler handler, MATD basis)
     : base(APIversion, handler, null)
 {
     this.version          = basis.version;
     this.materialNameHash = basis.materialNameHash;
     this.shader           = basis.shader;
     if (version < 0x00000103)
     {
         this.mtrl = basis.mtrl != null
             ? new MTRL(requestedApiVersion, OnRCOLChanged, basis.mtrl)
             : new MTRL(requestedApiVersion, OnRCOLChanged);
     }
     else
     {
         this.isVideoSurface    = basis.isVideoSurface;
         this.isPaintingSurface = basis.isPaintingSurface;
         this.mtnf = basis.mtnf != null
             ? new MTNF(requestedApiVersion, OnRCOLChanged, basis.mtnf)
             : new MTNF(requestedApiVersion, OnRCOLChanged);
     }
 }
示例#4
0
        protected override void Parse(Stream s)
        {
            BinaryReader r = new BinaryReader(s);

            tag = r.ReadUInt32();
            if (checking)
            {
                if (tag != (uint)FOURCC("MATD"))
                {
                    throw new InvalidDataException(String.Format("Invalid Tag read: '{0}'; expected: 'MATD'; at 0x{1:X8}", FOURCC(tag), s.Position));
                }
            }
            version          = r.ReadUInt32();
            materialNameHash = r.ReadUInt32();
            shader           = (ShaderType)r.ReadUInt32();
            uint length = r.ReadUInt32();
            long start;

            if (version < 0x00000103)
            {
                start = s.Position;
                mtrl  = new MTRL(requestedApiVersion, OnRCOLChanged, s);
            }
            else
            {
                isVideoSurface    = r.ReadInt32() != 0;
                isPaintingSurface = r.ReadInt32() != 0;
                start             = s.Position;
                mtnf = new MTNF(requestedApiVersion, OnRCOLChanged, s);
            }

            if (checking)
            {
                if (start + length != s.Position)
                {
                    throw new InvalidDataException(string.Format("Invalid length 0x{0:X8} at 0x{1:X8}", length, s.Position));
                }
            }
        }