Пример #1
0
        private void CreateVerFrameDir(GrnNode mainNode)
        {
            GrnSectionNode verFrameDir = new GrnSectionNode(null, GrnNodeType.VersionFrameDirectory);

            verFrameDir.Offset             = 156;
            verFrameDir.NumTotalChildNodes = 6;
            mainNode.AppendChild(verFrameDir);

            GrnStringTableNode strNode = new GrnStringTableNode(verFrameDir);

            strNode.Offset = 88;
            strNode.Strings.Add(string.Empty);
            strNode.Strings.Add("RAD 3D Studio MAX 4.x");
            strNode.Strings.Add("1.2b");
            strNode.Strings.Add("10-4-2000");
            strNode.Strings.Add("win32");
            strNode.Strings.Add("(C) Copyright 1999-2000 RAD Game Tools, Inc.  All Rights Reserved.");
            verFrameDir.AppendChild(strNode);

            GrnNode verSect = new GrnNode(verFrameDir, GrnNodeType.VersionSection);

            verSect.Offset             = 208;
            verSect.NumTotalChildNodes = 3;
            verFrameDir.AppendChild(verSect);

            GrnNode expVer = new GrnNode(verSect, GrnNodeType.ExporterVersion);

            expVer.Offset             = 208;
            expVer.NumTotalChildNodes = 1;
            expVer.Data = new byte[] { 0x01, 0x00, 0x00, 0x00,
                                       0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00 };
            verSect.AppendChild(expVer);

            GrnNode maxSys = new GrnNode(expVer, GrnNodeType.ModelerAxisSystem);

            maxSys.Offset = 220;
            maxSys.Data   = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                         0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xBF,
                                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x00 };
            expVer.AppendChild(maxSys);

            GrnNode runVer = new GrnNode(verSect, GrnNodeType.RuntimeVersion);

            runVer.Offset = 268;
            runVer.Data   = new byte[] { 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
                                         0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00 };
            verSect.AppendChild(runVer);

            GrnNode nullTer = new GrnNode(verFrameDir, GrnNodeType.NullTerminator);

            nullTer.Offset = 284;
            verFrameDir.AppendChild(nullTer);
        }
Пример #2
0
        public void Write(Stream stream)
        {
            using (GrnBinaryWriter writer = new GrnBinaryWriter(stream))
            {
                this.WriteHeader(writer);

                GrnMainNode mainNode = new GrnMainNode();
                mainNode.NumTotalChildNodes = 3;
                this.CreateVerFrameDir(mainNode);

                GrnSectionNode staFrameDir = new GrnSectionNode(mainNode, GrnNodeType.StandardFrameDirectory);
                staFrameDir.Offset = 440;
                mainNode.AppendChild(staFrameDir);

                // 0StringTable
                OrderedDictionary  stringMap    = this.CreateStringMap();
                GrnStringTableNode strTableNode = new GrnStringTableNode(staFrameDir);
                strTableNode.Strings = stringMap.Keys.Cast <string>().ToList();
                staFrameDir.AppendChild(strTableNode);

                // 1DataExtension
                GrnNode dataExtSecNode = new GrnNode(staFrameDir, GrnNodeType.DataExtensionSection);
                staFrameDir.AppendChild(dataExtSecNode);
                this.WriteDataExtensions(dataExtSecNode, stringMap);

                // 2VectorChannel
                GrnNode vecChanSecNode = new GrnNode(staFrameDir, GrnNodeType.VectorChannelSection);
                staFrameDir.AppendChild(vecChanSecNode);

                // 3TransformChannel
                GrnNode traChanSecNode = new GrnNode(staFrameDir, GrnNodeType.TransformChannelSection);
                staFrameDir.AppendChild(traChanSecNode);
                foreach (GrnBone bone in this.Bones)
                {
                    GrnNode traChanNode = new GrnNode(traChanSecNode, GrnNodeType.TransformChannel);
                    traChanSecNode.AppendChild(traChanNode);

                    GrnDataExtensionReferenceNode refNode = new GrnDataExtensionReferenceNode(traChanNode);
                    refNode.DataExtensionIndex = bone.DataExtensionIndex + 1;
                    traChanNode.AppendChild(refNode);
                }

                // 4Mesh
                GrnNode meshSecNode = new GrnNode(staFrameDir, GrnNodeType.MeshSection);
                staFrameDir.AppendChild(meshSecNode);
                foreach (GrnMesh mesh in this.Meshes)
                {
                    mesh.Write(meshSecNode);
                }

                // 5Skeleton
                GrnNode skelSecNode = new GrnNode(staFrameDir, GrnNodeType.SkeletonSection);
                staFrameDir.AppendChild(skelSecNode);
                GrnNode skelNode = new GrnNode(skelSecNode, GrnNodeType.Skeleton);
                skelSecNode.AppendChild(skelNode);
                GrnNode boneSecNode = new GrnNode(skelNode, GrnNodeType.BoneSection);
                skelNode.AppendChild(boneSecNode);
                foreach (GrnBone bone in this.Bones)
                {
                    bone.Write(boneSecNode);
                }

                // 6Texture
                GrnNode texSecNode = new GrnNode(staFrameDir, GrnNodeType.TextureSection);
                staFrameDir.AppendChild(texSecNode);
                foreach (GrnTexture tex in this.Textures)
                {
                    tex.Write(texSecNode);
                }

                // 7Material
                GrnNode matSecNode = new GrnNode(staFrameDir, GrnNodeType.MaterialSection);
                staFrameDir.AppendChild(matSecNode);
                foreach (GrnMaterial mat in this.Materials)
                {
                    mat.Write(matSecNode);
                }

                // 8Form
                GrnNode formSecNode = new GrnNode(staFrameDir, GrnNodeType.FormSection);
                staFrameDir.AppendChild(formSecNode);
                this.WriteForm(formSecNode);

                // 9Model
                GrnNode modelSecNode = new GrnNode(staFrameDir, GrnNodeType.ModelSection);
                staFrameDir.AppendChild(modelSecNode);
                GrnNode modelNode = new GrnNode(modelSecNode, GrnNodeType.Model);
                modelNode.Data = new byte[] { 0x01, 0x00, 0x00, 0x00 };
                modelSecNode.AppendChild(modelNode);
                GrnNode rendPassSecNode = new GrnNode(modelNode, GrnNodeType.RenderPassSection);
                modelNode.AppendChild(rendPassSecNode);
                for (int i = 0; i < this.Meshes.Count; ++i)
                {
                    this.Meshes[i].WriteRenderPass(rendPassSecNode, i);
                }

                // 10Animation
                GrnNode animSecNode = new GrnNode(staFrameDir, GrnNodeType.AnimationSection);
                staFrameDir.AppendChild(animSecNode);
                GrnNode animNode = new GrnNode(animSecNode, GrnNodeType.Animation);
                animSecNode.AppendChild(animNode);
                GrnNode animVecTraSecNode = new GrnNode(animNode, GrnNodeType.AnimationVectorTrackSection);
                animNode.AppendChild(animVecTraSecNode);
                GrnNode animTraTraSecNode = new GrnNode(animNode, GrnNodeType.AnimationTransformTrackSection);
                animNode.AppendChild(animTraTraSecNode);
                for (int i = 0; i < this.Animation.BoneTracks.Count; ++i)
                {
                    this.Animation.BoneTracks[i].Write(animTraTraSecNode, i);
                }

                // 11NullTerminator
                GrnNode nullTermNode = new GrnNode(staFrameDir, GrnNodeType.NullTerminator);
                staFrameDir.AppendChild(nullTermNode);

                GrnSectionNode nullFrameDir = new GrnSectionNode(mainNode, GrnNodeType.NullFrameDirectory);
                mainNode.AppendChild(nullFrameDir);
                nullTermNode = new GrnNode(nullFrameDir, GrnNodeType.NullTerminator);
                nullFrameDir.AppendChild(nullTermNode);

                mainNode.Write(writer);
            }
        }