示例#1
0
        /// <summary>
        /// Loads a custom material.  That is, loads a material with a custom effect.
        /// </summary>
        /// <returns>The custom material</returns>
        private MaterialContent ImportCustomMaterial()
        {
            EffectMaterialContent content = new EffectMaterialContent();

            tokens.SkipName();
            string effectName = GetAbsolutePath(tokens.NextString());

            content.Effect = new ExternalReference <EffectContent>(effectName);

            // Find value initializers for the effect parameters and set the values
            // as indicated
            for (string token = tokens.NextToken(); token != "}"; token = tokens.NextToken())
            {
                if (token == "EffectParamFloats")
                {
                    tokens.SkipName();
                    string  floatsParamName = tokens.NextString();
                    int     numFloats       = tokens.NextInt();
                    float[] floats          = new float[numFloats];
                    for (int i = 0; i < numFloats; i++)
                    {
                        floats[i] = tokens.NextFloat();
                    }
                    tokens.SkipToken();
                    content.OpaqueData.Add(floatsParamName, floats);
                }
                else if (token == "EffectParamDWord")
                {
                    tokens.SkipName();
                    string dwordParamName = tokens.NextString();
                    float  dword          = tokens.NextFloat();
                    tokens.SkipToken();
                    content.OpaqueData.Add(dwordParamName, dword);
                }
                else if (token == "EffectParamString")
                {
                    tokens.SkipName();
                    string stringParamName = tokens.NextString();
                    string paramValue      = tokens.NextString();
                    tokens.SkipToken();
                    content.OpaqueData.Add(stringParamName, paramValue);
                }
                if (token == "{")
                {
                    tokens.SkipNode();
                }
            }
            return(content);
        }
示例#2
0
            // template Mesh
            // {
            //      DWORD nVertices;
            //      array Vector vertices[nVertices];
            //      DWORD nFaces;
            //      array MeshFace faces[nFaces];
            //      [...]
            // }
            /// <summary>
            /// Imports a mesh.
            /// </summary>
            /// <returns>The imported mesh</returns>
            public NodeContent ImportMesh()
            {
                // Initialize mesh
                mesh      = new MeshContent();
                mesh.Name = tokens.ReadName();
                if (mesh.Name == null)
                {
                    mesh.Name = "Mesh" + meshID.ToString();
                    meshID++;
                }
                // Read in vertex positions and vertex indices
                InitializeMesh();

                // Fill in the geometry channels and materials for this mesh
                for (string next = tokens.NextToken(); next != "}"; next = tokens.NextToken())
                {
                    if (next == "MeshNormals")
                    {
                        ImportNormals();
                    }
                    else if (next == "MeshTextureCoords")
                    {
                        ImportTextureCoords();
                    }
                    else if (next == "SkinWeights")
                    {
                        ImportSkinWeights();
                    }
                    else if (next == "MeshMaterialList")
                    {
                        ImportMaterialList();
                    }
                    else if (next == "Frame")
                    {
                        mesh.Children.Add(model.ImportNode());
                    }
                    else if (next == "{")
                    {
                        tokens.SkipNode();
                    }
                    else if (next == "}")
                    {
                        break;
                    }
                }
                return(mesh);
            }