示例#1
0
            public static IEnumerable <IPXVertex> SelectorList(XmlNodeList list, IPXPmx pmx)
            {
                HashSet <IPXVertex> vertices = new HashSet <IPXVertex>();

                foreach (XmlElement selector in list.OfType <XmlElement>())
                {
                    switch (selector.Name.ToLowerInvariant())
                    {
                    case "material":
                    case "object":
                        switch (selector.GetAttribute("method").ToLowerInvariant())
                        {
                        case "index":
                            if (int.TryParse(selector.InnerText, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out int index))
                            {
                                vertices.UnionWith(Vertex.FromMaterial(Material.ByIndex(index, pmx)));
                            }
                            break;

                        case "note":
                            vertices.UnionWith(Vertex.ByMaterialNote(selector.InnerText, pmx));
                            break;

                        default:
                            vertices.UnionWith(Vertex.ByMaterialName(selector.InnerText, pmx));
                            break;
                        }
                        break;

                    case "bone":
                    case "weight":
                        switch (selector.GetAttribute("method").ToLowerInvariant())
                        {
                        case "index":
                            if (int.TryParse(selector.InnerText, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out int index))
                            {
                                vertices.UnionWith(Vertex.FromBoneWeight(Bone.ByIndex(index, pmx), pmx));
                            }
                            break;

                        default:
                            vertices.UnionWith(Vertex.FromBoneWeight(Bone.ByName(selector.InnerText, pmx).FirstOrDefault(), pmx));
                            break;
                        }
                        break;

                    default:
                        break;
                    }
                }
                return(vertices);
            }
示例#2
0
            public static IEnumerable <IPXVertex> SelectorNode(XmlElement selectorNode, IPXPmx pmx)
            {
                HashSet <IPXVertex> vertices = new HashSet <IPXVertex>();

                // <select type="material" method="name">MatName</select>
                foreach (XmlElement selector in selectorNode.ChildNodes.OfType <XmlElement>())
                {
                    string type    = selector.GetAttributeCI("type").ToLowerInvariant();
                    string method  = selector.GetAttributeCI("method").ToLowerInvariant();
                    string combine = selector.GetAttributeCI("combine").ToLowerInvariant();

                    switch (type)
                    {
                    // Find by material properties
                    case "material":
                    case "object":
                        switch (method)
                        {
                        case "note":
                            //vertices.UnionWith(Vertex.ByMaterialNote(selector.InnerText, pmx));
                            Combine(vertices, Vertex.ByMaterialNote(selector.InnerText, pmx), combine);
                            break;

                        case "index":
                            if (int.TryParse(selector.InnerText, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out int index))
                            {
                                Combine(vertices, Vertex.FromMaterial(Material.ByIndex(index, pmx)), combine);
                            }
                            break;

                        default:
                            Combine(vertices, Vertex.ByMaterialName(selector.InnerText, pmx), combine);
                            break;
                        }
                        break;

                    // Find by bone weights
                    case "bone":
                    case "weight":
                        switch (method)
                        {
                        case "index":
                            if (int.TryParse(selector.InnerText, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out int index))
                            {
                                Combine(vertices, Vertex.FromBoneWeight(Bone.ByIndex(index, pmx), pmx), combine);
                            }
                            break;

                        default:
                            Combine(vertices, Vertex.FromBoneWeight(Bone.ByName(selector.InnerText, pmx).FirstOrDefault(), pmx), combine);
                            break;
                        }
                        break;

                    // Find by position inside box
                    case "box":
                        switch (method)
                        {
                        // Box is defined by a center position, and a size vector.
                        case "center":
                            XmlElement centerElement = selector.GetChildElementCI("center");
                            XmlElement sizeElement   = selector.GetChildElementCI("size");
                            if (centerElement != null && sizeElement != null)
                            {
                                V3 center = centerElement.GetV3();
                                V3 size   = sizeElement.GetV3();

                                V3 a = new V3(center.X - size.X / 2, center.Y - size.Y / 2, center.Z - size.Z / 2);
                                V3 b = new V3(center.X + size.X / 2, center.Y + size.Y / 2, center.Z + size.Z / 2);
                                Combine(vertices, Vertex.InsideCube(a, b, pmx), combine);
                            }
                            break;

                        // Box is defined by its two opposite corners.
                        default:
                            Combine(vertices, Vertex.InsideCube(selector.GetChildElementCI("a").GetV3(), selector.GetChildElementCI("b").GetV3(), pmx), combine);
                            break;
                        }
                        break;

                    // Find by position inside sphere
                    case "sphere":
                        break;

                    // Find by position inside cylinder
                    case "cylinder":
                        break;

                    default:
                        break;
                    }
                }
                return(vertices);
            }