Example #1
0
        public byte[] Write()
        {
            MemoryStream       m  = new MemoryStream();
            EndianBinaryWriter er = new EndianBinaryWriter(m, Endianness.LittleEndian);

            Header.NrBlocks = 1;
            Header.Write(er);
            CGFXWriterContext c = new CGFXWriterContext();

            Data.Write(er, c);
            if (c.DoWriteIMAGBlock())
            {
                long curpos = er.BaseStream.Position;
                er.BaseStream.Position = 0x10;
                er.Write((uint)2);
                er.BaseStream.Position = curpos;
                c.WriteIMAGBlock(er);
            }
            long curpos2 = er.BaseStream.Position;

            er.BaseStream.Position = 0xC;
            er.Write((uint)(curpos2));
            er.BaseStream.Position = curpos2;

            byte[] result = m.ToArray();
            er.Close();
            return(result);
        }
Example #2
0
        public byte[] Write()
        {
            //MessageBox.Show("CGFX saving is experimental! A couple of sections (like animations) are lost while saving!");
            MemoryStream       m  = new MemoryStream();
            EndianBinaryWriter er = new EndianBinaryWriter(m, Endianness.LittleEndian);

            Header.NrBlocks = 1;
            Header.Write(er);
            CGFXWriterContext c = new CGFXWriterContext();

            Data.Write(er, c);
            if (c.DoWriteIMAGBlock())
            {
                long curpos = er.BaseStream.Position;
                er.BaseStream.Position = 0x10;
                er.Write((uint)2);
                er.BaseStream.Position = curpos;
                c.WriteIMAGBlock(er);
            }
            long curpos2 = er.BaseStream.Position;

            er.BaseStream.Position = 0xC;
            er.Write((uint)(curpos2));
            er.BaseStream.Position = curpos2;

            byte[] result = m.ToArray();
            er.Close();
            return(result);
        }
Example #3
0
 public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     base.Write(er, c);
     if (TextureImage != null) er.Write((uint)4);
     else er.Write((uint)0);
     if (TextureImage != null) TextureImage.Write(er, c);
 }
 public virtual void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     er.Write(Type);
     er.Write(Signature, Encoding.ASCII, false);
     er.Write(Revision);
     c.WriteStringReference(Name, er);
     er.Write(Unknown2);
     er.Write(Unknown3);
 }
 public void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     er.Write(Height);
     er.Write(Width);
     er.Write(DataSize);
     c.WriteDataReference(Data, er);
     er.Write(DynamicAllocator);
     er.Write(BitsPerPixel);
     er.Write(LocationAddress);
     er.Write(MemoryAddress);
 }
 public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     base.Write(er, c);
     er.Write(Height);
     er.Write(Width);
     er.Write(GLFormat);
     er.Write(GLType);
     er.Write(NrLevels);
     er.Write(TextureObject);
     er.Write(LocationFlag);
     er.Write((uint)HWFormat);
 }
 public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     base.Write(er, c);
     c.WriteStringReference(LinkedTextureName, er);
     if (LinkedTextureOffset == 0)
     {
         er.Write((uint)0);
     }
     else
     {
         er.Write((uint)0);             //TODO!
     }
 }
Example #8
0
 public void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     er.Write(RefBit);
     er.Write(LeftIndex);
     er.Write(RightIndex);
     if (Name != null)
     {
         c.WriteStringReference(Name, er);
     }
     else
     {
         er.Write((uint)0);
     }
     er.Write((uint)0);
 }
 public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     base.Write(er, c);
     if (TextureImage != null)
     {
         er.Write((uint)4);
     }
     else
     {
         er.Write((uint)0);
     }
     if (TextureImage != null)
     {
         TextureImage.Write(er, c);
     }
 }
Example #10
0
        public void Write(EndianBinaryWriter er, CGFXWriterContext c)
        {
            long basepos = er.BaseStream.Position;

            er.Write(Signature, Encoding.ASCII, false);
            er.Write((uint)0);
            er.Write((uint)Entries.Count);
            RootNode.Write(er, c);
            foreach (var v in Entries)
            {
                v.Write(er, c);
            }
            long curpos = er.BaseStream.Position;

            er.BaseStream.Position = basepos + 4;
            er.Write((uint)(curpos - basepos));
            er.BaseStream.Position = curpos;
        }
Example #11
0
 public void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     long basepos = er.BaseStream.Position;
     er.Write(Signature, Encoding.ASCII, false);
     er.Write((uint)0);
     er.Write((uint)Entries.Count);
     RootNode.Write(er, c);
     foreach (var v in Entries) v.Write(er, c);
     long curpos = er.BaseStream.Position;
     er.BaseStream.Position = basepos + 4;
     er.Write((uint)(curpos - basepos));
     er.BaseStream.Position = curpos;
 }
Example #12
0
 public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     base.Write(er, c);
     c.WriteStringReference(BoneName, er);
     er.Write(ObjectType);
 }
Example #13
0
 public virtual void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     er.Write((uint)Type);
     c.WriteStringReference(Path, er);
     er.Write(MemberOffset);
     er.Write(BlendOperationIndex);
     er.Write(ObjectType);
     er.Write(MemberType);
     er.Write(ResMaterialPtr);
 }
Example #14
0
 public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     base.Write(er, c);
     c.WriteStringReference(MaterialName, er);
     er.Write(TextureMapperIndex);
 }
Example #15
0
 public void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     long offs = er.BaseStream.Position;
     er.Write((uint)0);
     er.Write((uint)0);
     er.Write((uint)0);
     er.Write((uint)0);
     er.Write((uint)0);
     er.Write((uint)0);
     if (ReflectanceRSampler != null)
     {
         long curpos = er.BaseStream.Position;
         er.BaseStream.Position = offs + 0;
         er.Write((uint)(curpos - (offs + 0)));
         er.BaseStream.Position = curpos;
         ReflectanceRSampler.Write(er, c);
     }
     if (ReflectanceGSampler != null)
     {
         long curpos = er.BaseStream.Position;
         er.BaseStream.Position = offs + 4;
         er.Write((uint)(curpos - (offs + 4)));
         er.BaseStream.Position = curpos;
         ReflectanceGSampler.Write(er, c);
     }
     if (ReflectanceBSampler != null)
     {
         long curpos = er.BaseStream.Position;
         er.BaseStream.Position = offs + 8;
         er.Write((uint)(curpos - (offs + 8)));
         er.BaseStream.Position = curpos;
         ReflectanceBSampler.Write(er, c);
     }
     if (Distribution0Sampler != null)
     {
         long curpos = er.BaseStream.Position;
         er.BaseStream.Position = offs + 12;
         er.Write((uint)(curpos - (offs + 12)));
         er.BaseStream.Position = curpos;
         Distribution0Sampler.Write(er, c);
     }
     if (Distribution1Sampler != null)
     {
         long curpos = er.BaseStream.Position;
         er.BaseStream.Position = offs + 16;
         er.Write((uint)(curpos - (offs + 16)));
         er.BaseStream.Position = curpos;
         Distribution1Sampler.Write(er, c);
     }
     if (FresnelSampler != null)
     {
         long curpos = er.BaseStream.Position;
         er.BaseStream.Position = offs + 20;
         er.Write((uint)(curpos - (offs + 20)));
         er.BaseStream.Position = curpos;
         FresnelSampler.Write(er, c);
     }
 }
Example #16
0
                public void Write(EndianBinaryWriter er, CGFXWriterContext c)
                {
                    long basepos = er.BaseStream.Position;
                    er.Write(Type);
                    er.Write(DynamicAllocator);
                    long offs = er.BaseStream.Position;
                    er.Write((uint)0);
                    er.Write((uint)0);
                    er.Write(Unknown4);
                    er.Write(Unknown5);
                    er.Write(Unknown6);
                    er.Write(Unknown7);
                    er.Write(Unknown8);
                    er.Write(Unknown9);
                    er.Write(Height);
                    er.Write(Width);
                    er.Write(Unknown12);
                    er.Write(Unknown13);
                    er.Write(Unknown14);
                    er.Write(Unknown15);
                    er.Write(Unknown16);
                    er.Write(Unknown17);
                    er.Write(Unknown18);
                    er.Write(Unknown19);
                    er.Write(Unknown20);
                    er.Write(CommandSizeToSend);

                    long curpos = er.BaseStream.Position;
                    er.BaseStream.Position = offs;
                    er.Write((uint)(curpos - offs));
                    er.BaseStream.Position = curpos;
                    TextureObject.Write(er, c);

                    curpos = er.BaseStream.Position;
                    er.BaseStream.Position = offs + 4;
                    er.Write((uint)(curpos - (offs + 4)));
                    er.BaseStream.Position = curpos;
                    Sampler.Write(er, basepos);
                }
Example #17
0
            public void Write(EndianBinaryWriter er, CGFXWriterContext c)
            {
                er.Write(Type);
                er.Write(Signature, Encoding.ASCII, false);
                er.Write(Revision);
                c.WriteStringReference(Name, er);
                er.Write(Unknown2);
                er.Write(Unknown3);
                er.Write((uint)Flags);
                er.Write(TexCoordConfig);
                er.Write(TranslucencyKind);
                MaterialColor.Write(er);
                Rasterization.Write(er);
                FragmentOperation.Write(er);
                er.Write(NrActiveTextureCoordiators);
                for (int i = 0; i < 3; i++)
                {
                    TextureCoordiators[i].Write(er);
                }
                long offs = er.BaseStream.Position;
                er.Write((uint)0);//tex0
                er.Write((uint)0);//tex1
                er.Write((uint)0);//tex2
                er.Write((uint)0);//proctex
                er.Write((uint)0);//shader
                er.Write((uint)0);//fragshader
                er.Write(ShaderProgramDescriptionIndex);
                er.Write(NrShaderParameters);
                er.Write((uint)0);//ShaderParametersOffsetArrayOffset
                er.Write(LightSetIndex);
                er.Write(FogIndex);
                er.Write(CGFXWriterContext.CalcHash(BitConverter.GetBytes((uint)((uint)Flags | 0x20))));//ShadingParameterHash
                byte[] result = new byte[NrShaderParameters * 4];
                //TODO: Read the shaderparameters, and put in array for hash
                er.Write(CGFXWriterContext.CalcHash(result));//ShaderParametersHash;

                List<byte> lresult;/* = new List<byte>();
                lresult.AddRange(BitConverter.GetBytes(TexCoordConfig));
                for (int i = 0; i < /*3/NrActiveTextureCoordiators; i++)
                {
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].SourceCoordinate));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].MappingMethod));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].ReferenceCamera));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].MatrixMode));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Scale.X));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Scale.Y));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Rotate));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Translate.X));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Translate.Y));
                    lresult.AddRange(BitConverter.GetBytes(false));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Matrix[0]));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Matrix[1]));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Matrix[2]));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Matrix[3]));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Matrix[4]));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Matrix[5]));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Matrix[6]));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Matrix[7]));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Matrix[8]));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Matrix[9]));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Matrix[10]));
                    lresult.AddRange(BitConverter.GetBytes(TextureCoordiators[i].Matrix[11]));
                    lresult.AddRange(BitConverter.GetBytes(TexCoordConfig));
                }*/
                er.Write((uint)0);//TextureCoordinatorsHash;

                lresult = new List<byte>();
                lresult.AddRange(BitConverter.GetBytes(TexCoordConfig));
                if (Tex0 != null && Tex0.Sampler is TexInfo.StandardTextureSamplerCtr)
                {
                    var v = Tex0.Sampler as TexInfo.StandardTextureSamplerCtr;
                    lresult.AddRange(BitConverter.GetBytes(v.BorderColor.X));
                    lresult.AddRange(BitConverter.GetBytes(v.BorderColor.Y));
                    lresult.AddRange(BitConverter.GetBytes(v.BorderColor.Z));
                    lresult.AddRange(BitConverter.GetBytes(v.BorderColor.W));
                    lresult.AddRange(BitConverter.GetBytes(WrapMapper[(Tex0.Unknown12 >> 12) & 0xF]));
                    lresult.AddRange(BitConverter.GetBytes(WrapMapper[(Tex0.Unknown12 >> 8) & 0xF]));
                    lresult.AddRange(BitConverter.GetBytes(0f));
                    lresult.AddRange(BitConverter.GetBytes(v.LodBias));
                    lresult.AddRange(BitConverter.GetBytes(v.MinFilter));
                    lresult.AddRange(BitConverter.GetBytes((uint)1));
                }
                if (Tex1 != null && Tex1.Sampler is TexInfo.StandardTextureSamplerCtr)
                {
                    var v = Tex1.Sampler as TexInfo.StandardTextureSamplerCtr;
                    lresult.AddRange(BitConverter.GetBytes(v.BorderColor.X));
                    lresult.AddRange(BitConverter.GetBytes(v.BorderColor.Y));
                    lresult.AddRange(BitConverter.GetBytes(v.BorderColor.Z));
                    lresult.AddRange(BitConverter.GetBytes(v.BorderColor.W));
                    lresult.AddRange(BitConverter.GetBytes(WrapMapper[(Tex1.Unknown12 >> 12) & 0xF]));
                    lresult.AddRange(BitConverter.GetBytes(WrapMapper[(Tex1.Unknown12 >> 8) & 0xF]));
                    lresult.AddRange(BitConverter.GetBytes(0f));
                    lresult.AddRange(BitConverter.GetBytes(v.LodBias));
                    lresult.AddRange(BitConverter.GetBytes(v.MinFilter));
                    lresult.AddRange(BitConverter.GetBytes((uint)1));
                }
                if (Tex2 != null && Tex2.Sampler is TexInfo.StandardTextureSamplerCtr)
                {
                    var v = Tex2.Sampler as TexInfo.StandardTextureSamplerCtr;
                    lresult.AddRange(BitConverter.GetBytes(v.BorderColor.X));
                    lresult.AddRange(BitConverter.GetBytes(v.BorderColor.Y));
                    lresult.AddRange(BitConverter.GetBytes(v.BorderColor.Z));
                    lresult.AddRange(BitConverter.GetBytes(v.BorderColor.W));
                    lresult.AddRange(BitConverter.GetBytes(WrapMapper[(Tex2.Unknown12 >> 12) & 0xF]));
                    lresult.AddRange(BitConverter.GetBytes(WrapMapper[(Tex2.Unknown12 >> 8) & 0xF]));
                    lresult.AddRange(BitConverter.GetBytes(0f));
                    lresult.AddRange(BitConverter.GetBytes(v.LodBias));
                    lresult.AddRange(BitConverter.GetBytes(v.MinFilter));
                    lresult.AddRange(BitConverter.GetBytes((uint)1));
                }
                er.Write(CGFXWriterContext.CalcHash(lresult.ToArray()));//TextureSamplersHash;
                er.Write((uint)0);
                er.Write(MaterialColor.GetHash());
                er.Write(Rasterization.GetHash());
                lresult = new List<byte>();
                lresult.AddRange(BitConverter.GetBytes((uint)FragShader.FragmentLighting.Flags));
                lresult.AddRange(BitConverter.GetBytes(FragShader.FragmentLighting.LayerConfig));
                lresult.AddRange(BitConverter.GetBytes(FragShader.FragmentLighting.FresnelConfig));
                lresult.AddRange(BitConverter.GetBytes(FragShader.FragmentLighting.BumpTextureIndex));
                lresult.AddRange(BitConverter.GetBytes(FragShader.FragmentLighting.BumpMode));
                lresult.AddRange(BitConverter.GetBytes(FragShader.FragmentLighting.IsBumpRenormalize));
                //lresult.AddRange(BitConverter.GetBytes((Flags & MaterialFlags.FragmentLightEnabled) != 0));
                er.Write(CGFXWriterContext.CalcHash(lresult.ToArray()));//FragmentLightingHash;
                er.Write((uint)0);
                er.Write(FragShader.FragmentLightingTable.GetHash());//FragmentLightingTableParametersHash;
                /*lresult = new List<byte>();
                lresult.AddRange(BitConverter.GetBytes(FragShader.BufferColor.X));
                lresult.AddRange(BitConverter.GetBytes(FragShader.BufferColor.Y));
                lresult.AddRange(BitConverter.GetBytes(FragShader.BufferColor.Z));
                lresult.AddRange(BitConverter.GetBytes(FragShader.BufferColor.W));
                for (int i = 0; i < 6; i++)
                {
                    lresult.AddRange(BitConverter.GetBytes(FragShader.TextureCombiners[i].Constant));
                    lresult.AddRange(BitConverter.GetBytes(TexCombSrcMapper[FragShader.TextureCombiners[i].ScaleRgb & 0xF]));
                    lresult.AddRange(BitConverter.GetBytes(TexCombSrcMapper[(FragShader.TextureCombiners[i].ScaleRgb >> 4) & 0xF]));
                    lresult.AddRange(BitConverter.GetBytes(TexCombSrcMapper[(FragShader.TextureCombiners[i].ScaleRgb >> 8) & 0xF]));
                }*/
                er.Write((uint)0);//TextureCombinersHash;
                er.Write(FragShader.AlphaTest.GetHash());//AlphaTestHash;
                er.Write(FragmentOperation.GetHash());//FragmentOperationHash;
                er.Write(MaterialId);
                if (Tex0 != null)
                {
                    long curpos = er.BaseStream.Position;
                    er.BaseStream.Position = offs + 0;
                    er.Write((uint)(curpos - (offs + 0)));
                    er.BaseStream.Position = curpos;
                    Tex0.Write(er, c);
                }
                if (Tex1 != null)
                {
                    long curpos = er.BaseStream.Position;
                    er.BaseStream.Position = offs + 4;
                    er.Write((uint)(curpos - (offs + 4)));
                    er.BaseStream.Position = curpos;
                    Tex1.Write(er, c);
                }
                if (Tex2 != null)
                {
                    long curpos = er.BaseStream.Position;
                    er.BaseStream.Position = offs + 8;
                    er.Write((uint)(curpos - (offs + 8)));
                    er.BaseStream.Position = curpos;
                    Tex2.Write(er, c);
                }
                if (ProcTex != null)
                {
                    long curpos = er.BaseStream.Position;
                    er.BaseStream.Position = offs + 12;
                    er.Write((uint)(curpos - (offs + 12)));
                    er.BaseStream.Position = curpos;
                    //currently unsupported!
                    //ProcTex.Write(er, c);
                }
                if (Shader != null)
                {
                    long curpos = er.BaseStream.Position;
                    er.BaseStream.Position = offs + 16;
                    er.Write((uint)(curpos - (offs + 16)));
                    er.BaseStream.Position = curpos;
                    Shader.Write(er, c);
                }
                if (FragShader != null)
                {
                    long curpos = er.BaseStream.Position;
                    er.BaseStream.Position = offs + 20;
                    er.Write((uint)(curpos - (offs + 20)));
                    er.BaseStream.Position = curpos;
                    FragShader.Write(er, c);
                }
            }
Example #18
0
                    public void Write(EndianBinaryWriter er, CGFXWriterContext c)
                    {
                        er.Write(NrIndexStreams);
                        if (NrIndexStreams != 0) er.Write((uint)0x14);
                        else er.Write((uint)0);
                        er.Write(NrBufferObjects);
                        if (NrIndexStreams != 0 && NrBufferObjects != 0) er.Write((uint)(12 + NrIndexStreams * 4));
                        else if (NrIndexStreams == 0 && NrBufferObjects != 0) er.Write((uint)12);
                        else er.Write((uint)0);
                        er.Write(Flags);
                        er.Write(CommandAllocator);

                        long idxstrmarray = er.BaseStream.Position;
                        er.Write(new uint[NrIndexStreams], 0, (int)NrIndexStreams);
                        er.Write(BufferObjects, 0, (int)NrBufferObjects);

                        for (int i = 0; i < NrIndexStreams; i++)
                        {
                            long curpos = er.BaseStream.Position;
                            er.BaseStream.Position = idxstrmarray + 4 * i;
                            er.Write((uint)(curpos - (idxstrmarray + 4 * i)));
                            er.BaseStream.Position = curpos;
                            IndexStreams[i].Write(er, c);
                        }
                    }
Example #19
0
                public void Write(EndianBinaryWriter er, CGFXWriterContext c)
                {
                    er.Write(NrRelatedBones);
                    if (NrRelatedBones != 0) er.Write((uint)0x10);
                    else er.Write((uint)0);
                    er.Write(SkinningMode);
                    er.Write(NrPrimitives);
                    if (NrRelatedBones != 0 && NrPrimitives != 0) er.Write((uint)(4 + NrRelatedBones * 4));
                    else if (NrRelatedBones == 0 && NrPrimitives != 0) er.Write((uint)4);
                    else er.Write((uint)0);

                    er.Write(RelatedBones, 0, (int)NrRelatedBones);
                    long primoffsarray = er.BaseStream.Position;
                    er.Write(new uint[NrPrimitives], 0, (int)NrPrimitives);

                    for (int i = 0; i < NrPrimitives; i++)
                    {
                        long curpos = er.BaseStream.Position;
                        er.BaseStream.Position = primoffsarray + 4 * i;
                        er.Write((uint)(curpos - (primoffsarray + 4 * i)));
                        er.BaseStream.Position = curpos;
                        Primitives[i].Write(er, c);
                    }
                }
Example #20
0
 public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     base.Write(er, c);
     er.Write(BufferObject);
     er.Write(LocationFlag);
     er.Write(VertexStreamLength);
     //Not supported yet
     //if (BufferDataLength != 0) c.WriteDataReference(VertexStream, er);
     /*else*/
     er.Write((uint)0);
     er.Write(LocationAddress);
     er.Write(MemoryArea);
     er.Write((uint)FormatType);
     er.Write(NrComponents);
     er.Write(Scale);
     er.Write(Offset);
 }
Example #21
0
                public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
                {
                    base.Write(er, c);
                    er.Write(BufferObject);
                    er.Write(LocationFlag);
                    er.Write(VertexStreamLength);
                    c.WriteDataReference(VertexStream, er);
                    er.Write(LocationAddress);
                    er.Write(MemoryArea);
                    er.Write(VertexDataEntrySize);
                    er.Write(NrVertexStreams);
                    if (NrVertexStreams != 0) er.Write((uint)4);
                    else er.Write((uint)0);

                    long vtxstrmarray = er.BaseStream.Position;
                    er.Write(new uint[NrVertexStreams], 0, (int)NrVertexStreams);

                    for (int i = 0; i < NrVertexStreams; i++)
                    {
                        long curpos = er.BaseStream.Position;
                        er.BaseStream.Position = vtxstrmarray + 4 * i;
                        er.Write((uint)(curpos - (vtxstrmarray + 4 * i)));
                        er.BaseStream.Position = curpos;
                        VertexStreams[i].Write(er, c);
                    }
                }
Example #22
0
            public void Write(EndianBinaryWriter er, CGFXWriterContext c)
            {
                er.Write(Type);
                er.Write(Signature, Encoding.ASCII, false);
                er.Write(Revision);
                c.WriteStringReference(Name, er);
                er.Write(Unknown2);
                er.Write(Unknown3);
                er.Write((uint)Flags);
                long bboffs = er.BaseStream.Position;
                er.Write((uint)0);
                er.WriteVector3(PositionOffset);
                er.Write(NrPrimitiveSets);
                long primsetoffsarrayoffs = er.BaseStream.Position;
                er.Write((uint)0);
                er.Write(BaseAddress);
                er.Write(NrVertexAttributes);
                long vtxattroffsarrayoffs = er.BaseStream.Position;
                er.Write((uint)0);
                long blendshapeoffs = er.BaseStream.Position;
                er.Write((uint)0);

                long primsetoffsarray = er.BaseStream.Position;
                er.BaseStream.Position = primsetoffsarrayoffs;
                er.Write((uint)(primsetoffsarray - primsetoffsarrayoffs));
                er.BaseStream.Position = primsetoffsarray;
                er.Write(new uint[NrPrimitiveSets], 0, (int)NrPrimitiveSets);

                long vtxattroffsarray = er.BaseStream.Position;
                er.BaseStream.Position = vtxattroffsarrayoffs;
                er.Write((uint)(vtxattroffsarray - vtxattroffsarrayoffs));
                er.BaseStream.Position = vtxattroffsarray;
                er.Write(new uint[NrVertexAttributes], 0, (int)NrVertexAttributes);

                long curpos = er.BaseStream.Position;
                er.BaseStream.Position = bboffs;
                er.Write((uint)(curpos - bboffs));
                er.BaseStream.Position = curpos;
                BoundingBox.Write(er);

                for (int i = 0; i < NrPrimitiveSets; i++)
                {
                    curpos = er.BaseStream.Position;
                    er.BaseStream.Position = primsetoffsarray + 4 * i;
                    er.Write((uint)(curpos - (primsetoffsarray + 4 * i)));
                    er.BaseStream.Position = curpos;
                    PrimitiveSets[i].Write(er, c);
                }

                for (int i = 0; i < NrVertexAttributes; i++)
                {
                    curpos = er.BaseStream.Position;
                    er.BaseStream.Position = vtxattroffsarray + 4 * i;
                    er.Write((uint)(curpos - (vtxattroffsarray + 4 * i)));
                    er.BaseStream.Position = curpos;
                    VertexAttributes[i].Write(er, c);
                }

                if (BlendShape != null)
                {
                    curpos = er.BaseStream.Position;
                    er.BaseStream.Position = blendshapeoffs;
                    er.Write((uint)(curpos - blendshapeoffs));
                    er.BaseStream.Position = curpos;
                    BlendShape.Write(er);
                }
            }
Example #23
0
 public void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     er.Write(RefBit);
     er.Write(LeftIndex);
     er.Write(RightIndex);
     if (Name != null) c.WriteStringReference(Name, er);
     else er.Write((uint)0);
     er.Write((uint)0);
 }
Example #24
0
 public void Write(EndianBinaryWriter er, CGFXWriterContext c, long OwnerOffset)
 {
     er.Write(Type);
     er.Write(Signature, Encoding.ASCII, false);
     er.Write(Revision);
     c.WriteStringReference(Name, er);
     er.Write(Unknown2);
     er.Write(Unknown3);
     er.Write(ShapeIndex);
     er.Write(MaterialIndex);
     er.Write((int)(OwnerOffset - er.BaseStream.Position));
     er.Write((byte)(IsVisible ? 1 : 0));
     er.Write(RenderPriority);
     er.Write(MeshNodeVisibilityIndex);
     er.Write(Unknown8);
     er.Write(Unknown9);
     er.Write(Unknown10);
     er.Write(Unknown11);
     er.Write(Unknown12);
     er.Write(Unknown13);
     er.Write(Unknown14);
     er.Write(Unknown15);
     er.Write(Unknown16);
     er.Write(Unknown17);
     er.Write(Unknown18);
     er.Write(Unknown19);
     er.Write(Unknown20);
     er.Write(Unknown21);
     er.Write(Unknown22);
     er.Write(Unknown23);
     er.Write(Unknown24);
     er.Write(Unknown25);
     if (MeshNodeName != null) c.WriteStringReference(MeshNodeName, er);
     else er.Write((uint)0);
     er.Write(Unknown27);
     er.Write(Unknown28);
     er.Write(Unknown29);
     er.Write(Unknown30);
 }
Example #25
0
 public void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     er.Write(InputCommand);
     er.Write(ScaleCommand);
     er.Write((uint)4);
     Sampler.Write(er, c);
 }
Example #26
0
 public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     base.Write(er, c);
     er.Write(Height);
     er.Write(Width);
     er.Write(GLFormat);
     er.Write(Type);
     er.Write(NrLevels);
     er.Write(TextureObject);
     er.Write(LocationFlag);
     er.Write((uint)HWFormat);
 }
Example #27
0
 public void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     er.Write(Type);
     c.WriteStringReference(BinaryPath, er);
     c.WriteStringReference(TableName, er);
     er.Write((uint)0);//TargetLUTOffset
 }
Example #28
0
 public virtual void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     er.Write(Type);
     er.Write(Signature, Encoding.ASCII, false);
     er.Write(Revision);
     c.WriteStringReference(Name, er);
     er.Write(Unknown2);
     er.Write(Unknown3);
 }
Example #29
0
 public void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     c.WriteStringReference(Name, er);
     er.Write((uint)(Visible ? 1 : 0));
 }
Example #30
0
 public void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     er.Write(FormatType);
     er.Write(PrimitiveMode);
     er.Write((byte)(IsVisible ? 1 : 0));
     er.Write((ushort)0);//padding
     er.Write(FaceDataLength);
     c.WriteDataReference(FaceData, er);
     er.Write(BufferObject);
     er.Write(LocationFlag);
     er.Write(CommandCache);
     er.Write(CommandCacheSize);
     er.Write(LocationAddress);
     er.Write(MemoryArea);
     if (BoundingBox != null)
     {
         er.Write((uint)4);
         BoundingBox.Write(er);
     }
     else er.Write((uint)0);
 }
Example #31
0
 public void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     er.WriteVector4(BufferColor);
     FragmentLighting.Write(er);
     long tableoff = er.BaseStream.Position;
     er.Write((uint)0);
     for (int i = 0; i < 6; i++) TextureCombiners[i].Write(er);
     AlphaTest.Write(er);
     er.Write(BufferCommand1);
     er.Write(BufferCommand2);
     er.Write(BufferCommand3);
     er.Write(BufferCommand4);
     er.Write(BufferCommand5);
     er.Write(BufferCommand6);
     if (FragmentLightingTable != null)
     {
         long curpos = er.BaseStream.Position;
         er.BaseStream.Position = tableoff;
         er.Write((uint)(curpos - tableoff));
         er.BaseStream.Position = curpos;
         FragmentLightingTable.Write(er, c);
     }
 }
Example #32
0
 public void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     er.Write(Height);
     er.Write(Width);
     er.Write(DataSize);
     c.WriteDataReference(Data, er);
     er.Write(DynamicAllocator);
     er.Write(BitsPerPixel);
     er.Write(LocationAddress);
     er.Write(MemoryAddress);
 }
Example #33
0
 public virtual void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     er.Write(Type);
     er.Write((uint)Usage);
     er.Write((uint)Flags);
 }
Example #34
0
 public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     base.Write(er, c);
     c.WriteStringReference(LinkedTextureName, er);
     if (LinkedTextureOffset == 0) er.Write((uint)0);
     else er.Write((uint)0);//TODO!
 }
Example #35
0
 public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     base.Write(er, c);
     er.Write((uint)FormatType);
     er.Write(NrComponents);
     er.Write(Scale);
     er.Write(NrAttributes);
     if (NrAttributes != 0) er.Write((uint)4);
     else er.Write((uint)0);
     er.Write(Attributes, 0, (int)NrAttributes);
 }
Example #36
0
        public void Write(EndianBinaryWriter er, CGFXWriterContext c)
        {
            long basepos = er.BaseStream.Position;
            er.Write(Type);
            er.Write(Signature, Encoding.ASCII, false);
            er.Write(Revision);
            c.WriteStringReference(Name, er);
            er.Write(Unknown2);
            er.Write(Unknown3);
            er.Write(Flags);
            er.Write((uint)(IsBranchVisible ? 1 : 0));
            er.Write(NrChildren);
            er.Write(Unknown7);
            er.Write(NrAnimationGroupDescriptions);
            long anmgrpdescdictoffs = er.BaseStream.Position;
            er.Write((uint)0);
            er.WriteVector3(Scale);
            er.WriteVector3(Rotation);
            er.WriteVector3(Translation);
            er.Write(LocalMatrix, 0, 4 * 3);
            er.Write(WorldMatrix, 0, 4 * 3);

            er.Write(NrMeshes);
            long mshoffsoffs = er.BaseStream.Position;
            er.Write((uint)0);

            er.Write(NrMaterials);
            long matdictoffs = er.BaseStream.Position;
            er.Write((uint)0);

            er.Write(NrShapes);
            long shpoffsoffs = er.BaseStream.Position;
            er.Write((uint)0);

            er.Write(NrMeshNodes);
            long mshnodedictoffs = er.BaseStream.Position;
            er.Write((uint)0);

            er.Write(Unknown23);
            er.Write(Unknown24);
            er.Write(Unknown25);

            long skeletonoffs = er.BaseStream.Position;
            if (Skeleton != null) er.Write((uint)0);

            //seems to be padded to 8 bytes
            while ((er.BaseStream.Position % 8) != 0) er.Write((byte)0);

            long meshoffs = er.BaseStream.Position;
            er.BaseStream.Position = mshoffsoffs;
            er.Write((uint)(meshoffs - mshoffsoffs));
            er.BaseStream.Position = meshoffs;
            er.Write(new uint[NrMeshes], 0, (int)NrMeshes);

            long shpoffs = er.BaseStream.Position;
            er.BaseStream.Position = shpoffsoffs;
            er.Write((uint)(shpoffs - shpoffsoffs));
            er.BaseStream.Position = shpoffs;
            er.Write(new uint[NrShapes], 0, (int)NrShapes);

            long anmgrpdict = er.BaseStream.Position;
            if (NrAnimationGroupDescriptions != 0 && AnimationInfoDict != null)
            {
                er.BaseStream.Position = anmgrpdescdictoffs;
                er.Write((uint)(anmgrpdict - anmgrpdescdictoffs));
                er.BaseStream.Position = anmgrpdict;
                AnimationInfoDict.Write(er, c);
            }

            long matdict = er.BaseStream.Position;
            if (NrMaterials != 0 && MaterialsDict != null)
            {
                er.BaseStream.Position = matdictoffs;
                er.Write((uint)(matdict - matdictoffs));
                er.BaseStream.Position = matdict;
                MaterialsDict.Write(er, c);
            }

            long mshnoddict = er.BaseStream.Position;
            if (NrMeshNodes != 0 && MeshNodeVisibilitiesDict != null)
            {
                er.BaseStream.Position = mshnodedictoffs;
                er.Write((uint)(mshnoddict - mshnodedictoffs));
                er.BaseStream.Position = mshnoddict;
                MeshNodeVisibilitiesDict.Write(er, c);
            }

            for (int i = 0; i < NrAnimationGroupDescriptions; i++)
            {
                long curpos = er.BaseStream.Position;
                long bpos = er.BaseStream.Position = anmgrpdict + 0x1C + i * 0x10 + 0xC;
                er.Write((uint)(curpos - bpos));
                er.BaseStream.Position = curpos;
                AnimationGroupDescriptions[i].Write(er, c);
            }

            for (int i = 0; i < NrMeshes; i++)
            {
                while ((er.BaseStream.Position % 8) != 0) er.Write((byte)0);
                long curpos = er.BaseStream.Position;
                long bpos = er.BaseStream.Position = meshoffs + i * 4;
                er.Write((uint)(curpos - bpos));
                er.BaseStream.Position = curpos;
                Meshes[i].Write(er, c, basepos);
            }

            for (int i = 0; i < NrMaterials; i++)
            {
                long curpos = er.BaseStream.Position;
                long bpos = er.BaseStream.Position = matdict + 0x1C + i * 0x10 + 0xC;
                er.Write((uint)(curpos - bpos));
                er.BaseStream.Position = curpos;
                Materials[i].Write(er, c);
            }

            for (int i = 0; i < NrShapes; i++)
            {
                long curpos = er.BaseStream.Position;
                long bpos = er.BaseStream.Position = shpoffs + i * 4;
                er.Write((uint)(curpos - bpos));
                er.BaseStream.Position = curpos;
                Shapes[i].Write(er, c);
            }

            for (int i = 0; i < NrMeshNodes; i++)
            {
                long curpos = er.BaseStream.Position;
                long bpos = er.BaseStream.Position = mshnoddict + 0x1C + i * 0x10 + 0xC;
                er.Write((uint)(curpos - bpos));
                er.BaseStream.Position = curpos;
                MeshNodeVisibilities[i].Write(er, c);
            }

            if (Skeleton != null)
            {
                throw new NotImplementedException();
                long curpos = er.BaseStream.Position;
                er.BaseStream.Position = skeletonoffs;
                er.Write((uint)(curpos - skeletonoffs));
                er.BaseStream.Position = curpos;
                //Skeleton.Write(er, c);
            }

            //Mesh
            //Shape
            //animgroupdesc dict
            //materials dict
            //MeshNodeVisibilities Dict

            //animgroupdesc dict entries
            //mesh entries
            //material dict entries
            //shape entries
            //MeshNodeVisibilities Dict entries

            //skeleton
        }
Example #37
0
            public void Write(EndianBinaryWriter er, CGFXWriterContext c)
            {
                er.Write(Type);
                er.Write((uint)Flags);
                c.WriteStringReference(Name, er);
                er.Write((uint)MemberType);

                er.Write(NrMembers);
                long mbrinfdictoffs = er.BaseStream.Position;
                er.Write((uint)0);

                er.Write(NrBlendOperations);
                long blndopoffs = er.BaseStream.Position;
                er.Write((uint)0);

                er.Write((uint)EvaluationTiming);

                long curpos = er.BaseStream.Position;
                er.BaseStream.Position = blndopoffs;
                er.Write((uint)(curpos - blndopoffs));
                er.BaseStream.Position = curpos;
                er.Write(BlendOperations, 0, BlendOperations.Length);

                long mbrinfodict = curpos = er.BaseStream.Position;
                er.BaseStream.Position = mbrinfdictoffs;
                er.Write((uint)(curpos - mbrinfdictoffs));
                er.BaseStream.Position = curpos;
                MemberInfoDICT.Write(er, c);

                for (int i = 0; i < AnimationGroupMembers.Length; i++)
                {
                    curpos = er.BaseStream.Position;
                    long bpos = er.BaseStream.Position = mbrinfodict + 0x1C + i * 0x10 + 0xC;
                    er.Write((uint)(curpos - bpos));
                    er.BaseStream.Position = curpos;
                    AnimationGroupMembers[i].Write(er, c);
                }
            }
Example #38
0
            public void Write(EndianBinaryWriter er, CGFXWriterContext c)
            {
                long basepos = er.BaseStream.Position;

                er.Write(Signature, Encoding.ASCII, false);
                er.Write((uint)0);
                for (int i = 0; i < 16; i++)
                {
                    if (Dictionaries[i] != null)
                    {
                        if (i != 0 && i != 1)
                        {
                            throw new NotImplementedException();
                        }
                        er.Write((uint)Dictionaries[i].Count);
                        er.Write((uint)0);                        //dictoffset
                    }
                    else
                    {
                        er.Write((uint)0);
                        er.Write((uint)0);
                    }
                }
                long[] dictoffsets = new long[16];
                for (int i = 0; i < 16; i++)
                {
                    if (Dictionaries[i] != null)
                    {
                        dictoffsets[i]         = er.BaseStream.Position;
                        er.BaseStream.Position = basepos + 8 + i * 8 + 4;
                        er.Write((uint)(dictoffsets[i] - (basepos + 8 + i * 8 + 4)));
                        er.BaseStream.Position = dictoffsets[i];
                        Dictionaries[i].Write(er, c);
                    }
                }
                if (Dictionaries[0] != null)
                {
                    for (int i = 0; i < Dictionaries[0].Count; i++)
                    {
                        long curpos = er.BaseStream.Position;
                        long bpos   = er.BaseStream.Position = dictoffsets[0] + 0x1C + i * 0x10 + 0xC;
                        er.Write((uint)(curpos - bpos));
                        er.BaseStream.Position = curpos;
                        Models[i].Write(er, c);
                    }
                }
                if (Dictionaries[1] != null)
                {
                    for (int i = 0; i < Dictionaries[1].Count; i++)
                    {
                        long curpos = er.BaseStream.Position;
                        long bpos   = er.BaseStream.Position = dictoffsets[1] + 0x1C + i * 0x10 + 0xC;
                        er.Write((uint)(curpos - bpos));
                        er.BaseStream.Position = curpos;
                        Textures[i].Write(er, c);
                    }
                }
                c.WriteStringTable(er);
                if (c.DoWriteIMAGBlock())
                {
                    int length = c.GetIMAGBlockSize();
                    while (((er.BaseStream.Position + length) % 64) != 0)
                    {
                        er.Write((byte)0);
                    }
                }
                long curpos2 = er.BaseStream.Position;

                er.BaseStream.Position = basepos + 4;
                er.Write((uint)(curpos2 - basepos));
                er.BaseStream.Position = curpos2;
            }
Example #39
0
 public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
 {
     base.Write(er, c);
     er.Write(ObjectType);
 }