Exemplo n.º 1
0
        private void GatherObjects(IEnumerable<MDagPath> inObjects, out LinkedList<MayaObject> ObjList, out HashSet<MayaObjPropId> Found)
        {
            ObjList = new LinkedList<MayaObject>();
            Found = new HashSet<MayaObjPropId>();

            foreach (var Obj in inObjects)
            {
                var mo = new MayaObject();

                // Init the object
                mo.type = Obj.node.apiTypeStr;
                mo.name = Obj.partialPathName;
                mo.properties = new Dictionary<string, MayaObjPropVal>();

                // The two first properties
                var mopi = new MayaObjPropId("ObjName", null);
                Found.Add(mopi);
                var mopv = new MayaObjPropVal(null, Obj.partialPathName);
                mo.properties.Add("ObjName", mopv);

                mopi = new MayaObjPropId("ObjType", null);
                Found.Add(mopi);
                mopv = new MayaObjPropVal(null, Obj.node.apiTypeStr);
                mo.properties.Add("ObjType", mopv);

                // The rest of the properties
                Object mobj = SpecializeObject(Obj);

                if (mobj != null)
                {
                    var nodeProp = mobj.GetType()
                                        .GetProperties()
                                        .Where(pi => (pi.GetGetMethod() != null) && (pi.PropertyType == typeof(string) || pi.PropertyType == typeof(int) || pi.PropertyType == typeof(double) || pi.PropertyType == typeof(bool) || pi.PropertyType == typeof(float)))
                                        .Select(pi => new
                                        {
                                            Name = pi.Name,
                                            Value = pi.GetGetMethod().Invoke(mobj, null),
                                            Type = pi.PropertyType
                                        });

                    foreach (var pair in nodeProp)
                    {
                        // Add the property to the global prop set found
                        mopi = new MayaObjPropId(pair.Name, pair.Type);
                        Found.Add(mopi);

                        // Add the property value to the specific object
                        mopv = new MayaObjPropVal(pair.Type, pair.Value.ToString());
                        mo.properties.Add(pair.Name, mopv);
                    }
                }

                var typeProp = Obj.GetType()
                                    .GetProperties()
                                    .Where(pi => (pi.GetGetMethod() != null) && (pi.PropertyType == typeof(string) || pi.PropertyType == typeof(int) || pi.PropertyType == typeof(double) || pi.PropertyType == typeof(bool) || pi.PropertyType == typeof(float)))
                                    .Select(pi => new
                                    {
                                        Name = pi.Name,
                                        Value = pi.GetGetMethod().Invoke(Obj, null),
                                        Type = pi.PropertyType
                                    });

                foreach (var pair in typeProp)
                {
                    // Add the property to the global prop set found
                    mopi = new MayaObjPropId(pair.Name, pair.Type);
                    Found.Add(mopi);

                    // Add the property value to the specific object
                    mopv = new MayaObjPropVal(pair.Type, pair.Value.ToString());

                    // Add only if the property hasn't been seen already
                    if (!mo.properties.ContainsKey(pair.Name))
                        mo.properties.Add(pair.Name, mopv);
                }

                ObjList.AddLast(mo);
            }
        }
Exemplo n.º 2
0
        private void GatherObjects(IEnumerable <MDagPath> inObjects, out LinkedList <MayaObject> ObjList, out HashSet <MayaObjPropId> Found)
        {
            ObjList = new LinkedList <MayaObject>();
            Found   = new HashSet <MayaObjPropId>();

            foreach (var Obj in inObjects)
            {
                var mo = new MayaObject();

                // Init the object
                mo.type       = Obj.node.apiTypeStr;
                mo.name       = Obj.partialPathName;
                mo.properties = new Dictionary <string, MayaObjPropVal>();

                // The two first properties
                var mopi = new MayaObjPropId("ObjName", null);
                Found.Add(mopi);
                var mopv = new MayaObjPropVal(null, Obj.partialPathName);
                mo.properties.Add("ObjName", mopv);

                mopi = new MayaObjPropId("ObjType", null);
                Found.Add(mopi);
                mopv = new MayaObjPropVal(null, Obj.node.apiTypeStr);
                mo.properties.Add("ObjType", mopv);

                // The rest of the properties
                Object mobj = SpecializeObject(Obj);

                if (mobj != null)
                {
                    var nodeProp = mobj.GetType()
                                   .GetProperties()
                                   .Where(pi => (pi.GetGetMethod() != null) && (pi.PropertyType == typeof(string) || pi.PropertyType == typeof(int) || pi.PropertyType == typeof(double) || pi.PropertyType == typeof(bool) || pi.PropertyType == typeof(float)))
                                   .Select(pi => new
                    {
                        Name  = pi.Name,
                        Value = pi.GetGetMethod().Invoke(mobj, null),
                        Type  = pi.PropertyType
                    });

                    foreach (var pair in nodeProp)
                    {
                        // Add the property to the global prop set found
                        mopi = new MayaObjPropId(pair.Name, pair.Type);
                        Found.Add(mopi);

                        // Add the property value to the specific object
                        mopv = new MayaObjPropVal(pair.Type, pair.Value.ToString());
                        mo.properties.Add(pair.Name, mopv);
                    }
                }


                var typeProp = Obj.GetType()
                               .GetProperties()
                               .Where(pi => (pi.GetGetMethod() != null) && (pi.PropertyType == typeof(string) || pi.PropertyType == typeof(int) || pi.PropertyType == typeof(double) || pi.PropertyType == typeof(bool) || pi.PropertyType == typeof(float)))
                               .Select(pi => new
                {
                    Name  = pi.Name,
                    Value = pi.GetGetMethod().Invoke(Obj, null),
                    Type  = pi.PropertyType
                });

                foreach (var pair in typeProp)
                {
                    // Add the property to the global prop set found
                    mopi = new MayaObjPropId(pair.Name, pair.Type);
                    Found.Add(mopi);

                    // Add the property value to the specific object
                    mopv = new MayaObjPropVal(pair.Type, pair.Value.ToString());

                    // Add only if the property hasn't been seen already
                    if (!mo.properties.ContainsKey(pair.Name))
                    {
                        mo.properties.Add(pair.Name, mopv);
                    }
                }

                ObjList.AddLast(mo);
            }
        }