Esempio n. 1
0
        public static GrnNode ReadByNodeType(GrnBinaryReader reader, GrnNode parentNode, GrnNodeType nodeType)
        {
            GrnNode node;

            if (nodeType == GrnNodeType.FileDirectory)
            {
                node = new GrnMainNode();
            }
            else if (nodeType == GrnNodeType.VersionFrameDirectory ||
                     nodeType == GrnNodeType.StandardFrameDirectory ||
                     nodeType == GrnNodeType.NullFrameDirectory)
            {
                node = new GrnSectionNode(parentNode, nodeType);
            }
            else if (nodeType == GrnNodeType.StringTable)
            {
                node = new GrnStringTableNode(parentNode);
            }
            else if (parentNode.NodeType == GrnNodeType.MeshVertexSet)
            {
                if (nodeType == GrnNodeType.MeshVertices)
                {
                    node = new GrnMeshVerticesNode(parentNode);
                }
                else if (nodeType == GrnNodeType.MeshNormals)
                {
                    node = new GrnMeshNormalsNode(parentNode);
                }
                else
                {
                    node = new GrnNode(parentNode, nodeType);
                }
            }
            else if (nodeType == GrnNodeType.MeshField)
            {
                node = new GrnMeshFieldNode(parentNode);
            }
            else if (nodeType == GrnNodeType.MeshWeights)
            {
                node = new GrnMeshWeightsNode(parentNode);
            }
            else if (nodeType == GrnNodeType.MeshTriangles)
            {
                node = new GrnMeshTrianglesNode(parentNode);
            }
            else if (nodeType == GrnNodeType.DataExtensionProperty)
            {
                node = new GrnDataExtensionPropertyNode(parentNode);
            }
            else if (nodeType == GrnNodeType.DataExtensionPropertyValue)
            {
                node = new GrnDataExtensionPropertyValueNode(parentNode);
            }
            else if (nodeType == GrnNodeType.DataExtensionReference)
            {
                node = new GrnDataExtensionReferenceNode(parentNode);
            }
            else if (nodeType == GrnNodeType.Bone)
            {
                node = new GrnBoneNode(parentNode);
            }
            else if (nodeType == GrnNodeType.MaterialSimpleDiffuseTexture)
            {
                node = new GrnMaterialSimpleDiffuseTextureNode(parentNode);
            }
            else if (nodeType == GrnNodeType.FormBoneChannels)
            {
                node = new GrnFormBoneChannelsNode(parentNode);
            }
            else if (nodeType == GrnNodeType.FormMesh)
            {
                node = new GrnFormMeshNode(parentNode);
            }
            else if (nodeType == GrnNodeType.FormMeshBone)
            {
                node = new GrnFormMeshBoneNode(parentNode);
            }
            else if (nodeType == GrnNodeType.RenderPass)
            {
                node = new GrnRenderPassNode(parentNode);
            }
            else if (nodeType == GrnNodeType.RenderPassTriangles)
            {
                node = new GrnRenderPassTrianglesNode(parentNode);
            }
            else if (nodeType == GrnNodeType.AnimationTransformTrackKeys)
            {
                node = new GrnAnimationTransformTrackKeysNode(parentNode);
            }
            else if (nodeType == GrnNodeType.TextureMapImage)
            {
                node = new GrnTextureMapImageNode(parentNode);
            }
            else
            {
                node = new GrnNode(parentNode, nodeType);
            }

            node.Read(reader);
            return(node);
        }
Esempio n. 2
0
        public void WriteRenderPass(GrnNode rendPassSecNode, int meshIndex)
        {
            Dictionary<int, List<int>> matFaceMap = new Dictionary<int, List<int>>();
            for (int i = 0; i < this.Faces.Count; ++i)
            {
                if (!matFaceMap.ContainsKey(this.Faces[i].MaterialIndex))
                {
                    matFaceMap.Add(this.Faces[i].MaterialIndex, new List<int>());
                }
                matFaceMap[this.Faces[i].MaterialIndex].Add(i);
            }
            foreach (KeyValuePair<int, List<int>> matFace in matFaceMap)
            {
                GrnRenderPassNode rendPassNode = new GrnRenderPassNode(rendPassSecNode);
                rendPassNode.FormMeshIndex = meshIndex;
                rendPassNode.MaterialIndex = matFace.Key + 1;
                rendPassSecNode.AppendChild(rendPassNode);

                GrnNode rpFieldSecNode = new GrnNode(rendPassNode, GrnNodeType.RenderPassFieldSection);
                rendPassNode.AppendChild(rpFieldSecNode);
                GrnNode rpFieldConstNode = new GrnNode(rpFieldSecNode, GrnNodeType.RenderPassFieldConstant);
                rpFieldConstNode.Data = new byte[] { 0x00, 0x00, 0x80, 0x3F,
                    0x00, 0x00, 0x80, 0x3F,
                    0x00, 0x00, 0x80, 0x3F };
                rpFieldSecNode.AppendChild(rpFieldConstNode);
                GrnNode rpFieldAssNode = new GrnNode(rpFieldSecNode, GrnNodeType.RenderPassFieldAssignment);
                rpFieldAssNode.Data = new byte[] { 0x00, 0x00, 0x00, 0x00 };
                rpFieldSecNode.AppendChild(rpFieldAssNode);

                GrnRenderPassTrianglesNode rpTriNode = new GrnRenderPassTrianglesNode(rendPassNode);
                foreach (int faceIndex in matFace.Value)
                {
                    rpTriNode.TextureIndices.Add(faceIndex, this.Faces[faceIndex].TextureIndices);
                }
                rendPassNode.AppendChild(rpTriNode);
            }
        }