コード例 #1
0
ファイル: Nb2dJson.cs プロジェクト: netonjm/RubeLoader
        public JObject B2n(b2World world)
        {
            JObject worldValue = new JObject();

            m_bodyToIndexMap.Clear();
            m_jointToIndexMap.Clear();

            VecToJson("gravity", world.Gravity, worldValue);
            worldValue["allowSleep"] = world.AllowSleep;

            //worldValue["autoClearForces"] = world.;
            worldValue["warmStarting"] = world.GetWarmStarting();
            //worldValue["continuousPhysics"] = world.isco;

            JArray customPropertyValue = WriteCustomPropertiesToJson(null);
            if (customPropertyValue.Count > 0)
                worldValue["customProperties"] = customPropertyValue;

            int i = 0;

            b2Body tmp = world.BodyList;
            while (tmp != null)
            {
                m_bodyToIndexMap.Add(tmp, i);
                worldValue.Add("body", B2n(tmp));
                tmp = tmp.Next;
                i++;
            }

            b2Joint tmpJoint = world.JointList;
            while (true)
            {
                if (tmpJoint.GetJointType() == b2JointType.e_gearJoint)
                    continue;
                m_jointToIndexMap.Add(tmpJoint, i);
                worldValue.Add("joint", B2n(world));
                i++;

                tmpJoint = tmpJoint.Next;
            }

            tmpJoint = world.JointList;

            while (true)
            {
                if (tmpJoint.GetJointType() == b2JointType.e_gearJoint)
                    continue;
                m_jointToIndexMap.Add(tmpJoint, i);
                worldValue.Add("joint", B2n(world));
                i++;

                tmpJoint = tmpJoint.Next;
            }

            // Currently the only efficient way to add images to a Jb2dJson
            // is by using the R.U.B.E editor. This code has not been tested,
            // but should work ok.
            i = 0;
            foreach (var image in m_imageToNameMap.Keys)
            {
                worldValue.Add("image", B2n(image));
            }

            m_bodyToIndexMap.Clear();
            m_jointToIndexMap.Clear();
            return worldValue;
        }