示例#1
0
文件: Visitor.cs 项目: shoff/FbxSharp
        protected void AcceptFbxObject(FbxObject obj, ISet <object> visitedObjects)
        {
            //AcceptEmitter(obj, visitedObjects);
            Visit(obj);

            //Accept(obj.GetDocument());
            //Accept(obj.GetRootDocument());
            Accept(obj.GetScene(), visitedObjects);

            int i;

            for (i = 0; i < obj.GetSrcObjectCount(); i++)
            {
                Accept(obj.GetSrcObject(i), visitedObjects);
            }
            for (i = 0; i < obj.GetDstObjectCount(); i++)
            {
                Accept(obj.GetDstObject(i), visitedObjects);
            }


            FbxProperty prop = obj.GetFirstProperty();

            while (prop != null && prop.IsValid())
            {
                for (i = 0; i < prop.GetSrcObjectCount(); i++)
                {
                    var srcObj = prop.GetSrcObject(i);
                    Accept(srcObj, visitedObjects);
                }
                for (i = 0; i < prop.GetDstObjectCount(); i++)
                {
                    var dstObj = prop.GetDstObject(i);
                    Accept(dstObj, visitedObjects);
                }

                // TODO: object references in properties
                // TODO: object references in src and dst properties

                prop = obj.GetNextProperty(prop);
            }

            prop = obj.RootProperty;
            for (i = 0; i < prop.GetSrcObjectCount(); i++)
            {
                var srcObj = prop.GetSrcObject(i);
                Accept(srcObj, visitedObjects);
            }
            for (i = 0; i < prop.GetDstObjectCount(); i++)
            {
                var dstObj = prop.GetDstObject(i);
                Accept(dstObj, visitedObjects);
            }
        }
示例#2
0
        public void PrintProperty(FbxProperty prop, TextWriter writer, bool indent = false)
        {
            string prefix = indent ? "            " : "        ";

            writer.WriteLine("{0}Name = {1}", prefix, prop.GetName());
            var type = prop.GetPropertyDataType();

            writer.WriteLine("{0}Type = {1}", prefix, type.GetName());
//            writer.WriteLine("{0}HierName = {1}", prefix, prop.GetHierarchicalName());
//            writer.WriteLine("{0}Label = {1}", prefix, prop.GetLabel());

//            char n[1024];
            int i;
//            for (i = 0; i < 1024; i++)
//            {
//                n[i] = 0;
//            }
            sbyte      ch;
            byte       uch;
            uint       ui;
            short      sh;
            ushort     ush;
            long       ll;
            ulong      ull;
            bool       b;
            float      f;
            double     d;
            string     fstr;
            FbxVector2 v2;
            FbxVector3 v3;
            FbxVector4 v4;
            string     s;
            FbxTime    t;
            var        sb = new StringBuilder();

            bool printValue = true;

//            switch (type.GetType())
//            {
//            case eFbxUndefined:
//                printValue = false;
//                break;
//            case eFbxChar:
            if (type == typeof(sbyte))
            {
                ch = prop.Get <sbyte>();
                sb.AppendFormat("%i ('%c')", (int)ch, ch);
            }
//                break;
//            case eFbxUChar:
            if (type == typeof(byte))
            {
                uch = prop.Get <byte>();
                sb.AppendFormat("%i ('%c')", (uint)uch, uch);
            }
//                break;
//            case eFbxShort:
            if (type == typeof(short))
            {
                sh = prop.Get <short>();
                sb.AppendFormat("%i", (int)sh);
            }
//                break;
//            case eFbxUShort:
            if (type == typeof(ushort))
            {
                ush = prop.Get <ushort>();
                sb.AppendFormat("%ui", (uint)ush);
            }
//                break;
//            case eFbxUInt:
            if (type == typeof(uint))
            {
                ui = prop.Get <uint>();
                sb.AppendFormat("%ui", ui);
            }
//                break;
//            case eFbxLongLong:
            if (type == typeof(long))
            {
                ll = prop.Get <long>();
                sb.AppendFormat("%lli", ll);
            }
//                break;
//            case eFbxULongLong:
            if (type == typeof(ulong))
            {
                ull = prop.Get <ulong>();
                sb.AppendFormat("%llu", ull);
            }
//                break;
//            case eFbxHalfFloat:
//                printValue = false;
//                break;
//            case eFbxBool:
            if (type == typeof(bool))
            {
                b = prop.Get <bool>();
                if (b)
                {
                    sb.AppendFormat("true");
                }
                else
                {
                    sb.AppendFormat("false");
                }
            }
//                break;
//            case eFbxInt:
            if (type == typeof(int))
            {
                i = prop.Get <int>();
                sb.AppendFormat("%i", i);
            }
//                break;
//            case eFbxFloat:
            if (type == typeof(float))
            {
                f = prop.Get <float>();
                sb.AppendFormat("%f", f);
            }
//                break;
//            case eFbxDouble:
            if (type == typeof(double))
            {
                d = prop.Get <double>();
                sb.AppendFormat("{0}", d);
            }
//                break;
//            case eFbxDouble2:
            if (type == typeof(FbxVector2))
            {
                v2 = prop.Get <FbxVector2>();
                sb.AppendFormat("{0}, {1}", v2.X, v2.Y);
            }
//                break;
//            case eFbxDouble3:
            if (type == typeof(sbyte))
            {
                v3 = prop.Get <FbxVector3>();
                sb.AppendFormat("{0}, {1}, {2}", v3.X, v3.Y, v3.Z);
            }
//                break;
//            case eFbxDouble4:
            if (type == typeof(sbyte))
            {
                v4 = prop.Get <FbxVector4>();
                sb.AppendFormat("{0}, {1}, {2}, {3}", v4.X, v4.Y, v4.Z, v4.W);
            }
//                break;
//            case eFbxDouble4x4:
//            case eFbxEnum:
//                printValue = false;
//                break;
//            case eFbxString:
            if (type == typeof(sbyte))
            {
                fstr = prop.Get <string>();
                sb.Append(quote(fstr));
            }
//                break;
//            case eFbxTime:
            if (type == typeof(sbyte))
            {
                t = prop.Get <FbxTime>();
                sb.AppendFormat("{0}", t);
            }
//                break;
//            case eFbxReference:
            //            FbxObject* obj;
            //            obj = prop.Get<FbxObject*>();
            //            cout << prefix << ".Value = " << obj.GetRuntimeClassId().GetName() << ", uid=" << obj.GetUniqueID() << endl;
            //            break;
//            case eFbxBlob:
//            case eFbxDistance:
//            case eFbxDateTime:
//            case eFbxTypeCount:
//                printValue = false;
//                break;

            if (printValue)
            {
                writer.WriteLine("{0}Value = {1}", prefix, sb.ToString());
            }


            writer.WriteLine("{0}{1}{2}", prefix, "SrcObjectCount = ", prop.GetSrcObjectCount());
            for (i = 0; i < prop.GetSrcObjectCount(); i++)
            {
                FbxObject srcObj = prop.GetSrcObject(i);
                writer.Write("{0}{1}{2}", prefix, "    #", i, " ");
                PrintObjectID(srcObj);
                writer.WriteLine();
            }
            writer.WriteLine("{0}{1}{2}", prefix, "DstObjectCount = ", prop.GetDstObjectCount());
            for (i = 0; i < prop.GetDstObjectCount(); i++)
            {
                FbxObject dstObj = prop.GetDstObject(i);
                writer.Write("{0}{1}{2}", prefix, "    #", i, " ");
                PrintObjectID(dstObj);
                writer.WriteLine();
            }
//            writer.WriteLine("{0}{1}{2}", prefix , "SrcPropertyCount = " , prop.GetSrcPropertyCount() );
//            for (i = 0; i < prop.GetSrcPropertyCount(); i++)
//            {
//                Property prop2 = prop.GetSrcProperty(i);
//                writer.Write("{0}{1}{2}", prefix , "    #" , i , " ");
//                PrintPropertyID(prop2);
//                writer.WriteLine();
//            }
//            writer.WriteLine("{0}{1}{2}", prefix , "DstPropertyCount = " , prop.GetDstPropertyCount() );
//            for (i = 0; i < prop.GetDstPropertyCount(); i++)
//            {
//                Property prop2 = prop.GetDstProperty(i);
//                writer.Write("{0}{1}{2}", prefix , "    #" , i , " ");
//                PrintPropertyID(prop2);
//                writer.WriteLine();
//            }
        }