示例#1
0
        public SWIGTYPE_p_Float CalcSurfaceDistancesFromPoint(PolygonObject pObject, int pindex, Neighbor pNeighbor, ref Fusee.Math.Core.double3 /* Vector*&_cstype */ pNormals)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BrushBase_CalcSurfaceDistancesFromPoint__SWIG_2(swigCPtr, PolygonObject.getCPtr(pObject), pindex, Neighbor.getCPtr(pNeighbor), ref pNormals /* Vector*&_csin */);
            SWIGTYPE_p_Float      ret  = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_Float(cPtr, false);

            return(ret);
        }
示例#2
0
        public static PolygonObject Alloc(int pcnt, int vcnt)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.PolygonObject_Alloc(pcnt, vcnt);
            PolygonObject         ret  = (cPtr == global::System.IntPtr.Zero) ? null : new PolygonObject(cPtr, false);

            return(ret);
        }
示例#3
0
        public PolygonObject Triangulate(double regular, BaseThread bt)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.LineObject_Triangulate(swigCPtr, regular, BaseThread.getCPtr(bt));
            PolygonObject         ret  = (cPtr == global::System.IntPtr.Zero) ? null : new PolygonObject(cPtr, false);

            return(ret);
        }
示例#4
0
        public SWIGTYPE_p_Float CalcSurfaceDistancesFromPoint(PolygonObject pObject, int pindex)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BrushBase_CalcSurfaceDistancesFromPoint__SWIG_4(swigCPtr, PolygonObject.getCPtr(pObject), pindex);
            SWIGTYPE_p_Float      ret  = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_Float(cPtr, false);

            return(ret);
        }
示例#5
0
        public DragablePointViewModel InsertPoint(Point insertMe, DragablePointViewModel insertBeforeMe)
        {
            DragablePoint          np       = new DragablePoint(1, insertMe.X - PosX, insertMe.Y - PosY);
            DragablePointViewModel newPoint = new DragablePointViewModel(MainVm, this, np);

            int index = 0;

            if (insertBeforeMe != null)
            {
                index = PointVms.IndexOf(insertBeforeMe);
            }

            if (index >= 0)
            {
                PointVms.Insert(index, newPoint);
            }

            if (insertBeforeMe != null)
            {
                PolygonObject.InsertPoint(newPoint.ModelObject, insertBeforeMe.ModelObject);
            }
            else
            {
                PolygonObject.InsertPoint(newPoint.ModelObject, null);
            }

            OnPropertyChanged("");
            Parent.OnPropertyChanged("");

            return(newPoint);
        }
示例#6
0
        public SWIGTYPE_p_Float CalcSurfaceDistances(PolygonObject pObject, BaseSelect selected, Neighbor pNeighbor, ref Fusee.Math.Core.double3 /* Vector*&_cstype */ pNormals, ref Fusee.Math.Core.double3 /* Vector*&_cstype */ pGlobalPoints)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BrushBase_CalcSurfaceDistances__SWIG_1(swigCPtr, PolygonObject.getCPtr(pObject), BaseSelect.getCPtr(selected), Neighbor.getCPtr(pNeighbor), ref pNormals /* Vector*&_csin */, ref pGlobalPoints /* Vector*&_csin */);
            SWIGTYPE_p_Float      ret  = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_Float(cPtr, false);

            return(ret);
        }
示例#7
0
        public SWIGTYPE_p_Float CalcSurfaceDistances(PolygonObject pObject, BaseSelect selected)
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.BrushBase_CalcSurfaceDistances__SWIG_4(swigCPtr, PolygonObject.getCPtr(pObject), BaseSelect.getCPtr(selected));
            SWIGTYPE_p_Float      ret  = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_Float(cPtr, false);

            return(ret);
        }
示例#8
0
    // Use this for initialization
    void Start()
    {
        _polygonCollider = this.GetComponent <PolygonCollider2D>();

        //this.ClearBodiesList();

        _polygonObject = new PolygonObject();
    }
示例#9
0
        /// <summary>
        /// Creates a PolygonObject instance with specified name and parent.
        /// </summary>
        /// <param name="name">The name of the PolygonObject instance.</param>
        /// <param name="parent">The parent of the PolygonObject instance.</param>
        /// <returns>The PolygonObject instance.</returns>
        public static PolygonObject CreatePolygonObject(string name, Base parent)
        {
            PolygonObject polygon = new PolygonObject();

            polygon.Name   = name;
            polygon.Parent = parent;
            return(polygon);
        }
示例#10
0
 public void RemovePoint(DragablePointViewModel point)
 {
     PointVms.Remove(point);
     PolygonObject.RemovePoint(point.ModelObject);
     OnPropertyChanged("ClosedPointVms");
     OnPropertyChanged("Points");
     OnPropertyChanged("");
     Parent.OnPropertyChanged("");
 }
示例#11
0
        public bool GetNGons(PolygonObject op, SWIGTYPE_p_Int32 ngoncnt, SWIGTYPE_p_p_NgonNeighbor ngons)
        {
            bool ret = C4dApiPINVOKE.Neighbor_GetNGons(swigCPtr, PolygonObject.getCPtr(op), SWIGTYPE_p_Int32.getCPtr(ngoncnt), SWIGTYPE_p_p_NgonNeighbor.getCPtr(ngons));

            if (C4dApiPINVOKE.SWIGPendingException.Pending)
            {
                throw C4dApiPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#12
0
        private void AddPolygonObjectComponentsTo(GameObject gameObject, XElement goXml)
        {
            var xml = goXml.Element("PolygonObjectComponent");

            if (xml != null)
            {
                PolygonObject tmxPolygon = gameObject.AddComponent <Tiled2Unity.PolygonObject>();
                FillBaseTmxObjectProperties(tmxPolygon, xml);
            }
        }
        /// <summary>
        /// Creates a PolygonObject instance with specified name and parent.
        /// </summary>
        /// <param name="name">The name of the PolygonObject instance.</param>
        /// <param name="parent">The parent of the PolygonObject instance.</param>
        /// <returns>The PolygonObject instance.</returns>
        public static PolygonObject CreatePolygonObject(string name, Base parent)
        {
            PolygonObject polygon = new PolygonObject();

            polygon.Name = name;
            if ((parent as IParent).CanContain(polygon))
            {
                polygon.Parent = parent;
            }
            return(polygon);
        }
示例#14
0
        public void AddWeightData(SceneNodeContainer snc, PolygonObject polyOb, CAWeightTag weightTag, IEnumerable <int> range)
        {
            if (weightTag == null || polyOb == null)
            {
                return;
            }

            List <VertexWeightList> weightMap       = new List <VertexWeightList>();
            List <float4x4>         bindingMatrices = new List <float4x4>();

            foreach (int j in range)
            {
                using (CPolygon poly = polyOb.GetPolygonAt(j))
                {
                    foreach (int iVert in GetPolyPointIndices(poly, polyOb))
                    {
                        var vertexWeights = new List <VertexWeight>();

                        for (int iJoint = 0; iJoint < weightTag.GetJointCount(); iJoint++)
                        {
                            double weight = weightTag.GetWeight(iJoint, iVert);

                            // Leave out zero weights. This will save space for the sparse weight table.
                            if (Math.Abs(weight) > double.Epsilon)
                            {
                                vertexWeights.Add(new VertexWeight {
                                    JointIndex = iJoint, Weight = (float)weight
                                });
                            }
                        }

                        vertexWeights.Sort((vw1, vw2) => ((int)(vw1.Weight - vw2.Weight)));
                        weightMap.Add(new VertexWeightList {
                            VertexWeights = vertexWeights
                        });
                    }
                }
            }
            for (int iJoint = 0; iJoint < weightTag.GetJointCount(); iJoint++)
            {
                // Add Binding Matrix
                JointRestState jointRestState = weightTag.GetJointRestState(iJoint);
                float4x4       mat            = (float4x4)(jointRestState.m_oMi * weightTag.GetGeomMg());
                bindingMatrices.Add(mat);
            }

            _weightObjects.Add(new WeightObject()
            {
                SceneNodeContainer = snc,
                WeightTag          = weightTag,
                WeightMap          = weightMap,
                BindingMatrices    = bindingMatrices
            });
        }
示例#15
0
    public void SetPosition()
    {
        position = new Vector2(this.transform.position.x, this.transform.position.y);

        PolygonObject po   = GetComponent <PolygonObject>();
        int           xAux = (int)po.TmxPosition.x;
        int           yAux = (int)po.TmxPosition.y;

        positionAux = new Vector2(xAux, yAux);
        x           = positionAux.x;
        y           = positionAux.y;
    }
示例#16
0
        public DragablePointViewModel AddPoint(Point point)
        {
            DragablePoint          np       = new DragablePoint(1, point.X, point.Y);
            DragablePointViewModel newPoint = new DragablePointViewModel(MainVm, this, np);

            PointVms.Add(newPoint);
            PolygonObject.AddPoint(newPoint.ModelObject);

            OnPropertyChanged("");
            Parent.OnPropertyChanged("");

            return(newPoint);
        }
示例#17
0
        public static IEnumerable <int> GetPolyPointIndices(CPolygon polygon, PolygonObject polyOb)
        {
            yield return(polygon.a);

            yield return(polygon.b);

            yield return(polygon.c);

            if (!IsTri(polygon, polyOb))
            {
                yield return(polygon.d);
            }
        }
示例#18
0
    public void setPolygonOfIndex(int index)
    {
        _polygonObject = _totalPolygonsinFile[index];

        _polygonCollider.pathCount = _polygonObject.TotalPaths;

        for (int i = 0; i < _polygonCollider.pathCount; i++)
        {
            Vector2[] tempPoints = new Vector2[_polygonObject.paths[i].points.Length];
            for (int j = 0; j < _polygonObject.paths[i].points.Length; j++)
            {
                tempPoints[j] = (_polygonObject.paths[i].points[j]) / PixelsPerUnit;
            }

            _polygonCollider.SetPath(i, tempPoints);
        }
    }
示例#19
0
        private PolygonObject CreatePolygonObject(XmlNode node)
        {
            var polygonObject = new PolygonObject();

            string pointsData = node.GetNode("polygon").GetString("points");

            foreach (string p in pointsData.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
            {
                var pSplit = p.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                polygonObject.points.Add(new Vector2f(float.Parse(pSplit[0], CultureInfo.InvariantCulture), float.Parse(pSplit[1], CultureInfo.InvariantCulture)));
            }

            SetObjectProperties(polygonObject, node);

            return(polygonObject);
        }
示例#20
0
        private void ProcessPolygonObject(Quadtree <GameObject> hash, PolygonObject obj,
                                          Action <GameObject, BaseObject> func)
        {
            var entity   = new GameObject();
            var bounds   = new CCollisionBound(obj.Polygon.Select(point => new Vector2(point.X, point.Y)).ToList());
            var position = new CPosition(new Vector2(obj.X, obj.Y));

            entity.Components.Add(bounds);
            entity.Components.Add(position);

            func(entity, obj);

            hash.Add(entity, new RectangleF(
                         position.Position.X,
                         position.Position.Y,
                         bounds.Bounds.Width,
                         bounds.Bounds.Height
                         ));
        }
示例#21
0
 public static bool IsTri(CPolygon polygon, PolygonObject polyOb)
 {
     return(polyOb.GetPointAt(polygon.c) == polyOb.GetPointAt(polygon.d));
 }
示例#22
0
        /// <summary>

        /// This method tries to make the best out of C4Ds seldom relationship between objects with
        /// multiple materials which can or can not be restricted to polygon selections and one or more UV sets.
        /// But there are unhandled cases:
        /// Multple UV tags are not supported. Overlapping polygon selections are probably handled differently.
        /// The awkward side effects when changing the tags' order in C4D are not reproduced.
        /// </summary>
        /// <param name="ob"></param>
        /// <param name="snc"></param>


        private void VisitObject(BaseObject ob, SceneNodeContainer snc)
        {
            Collection <TextureTag>           textureTags   = new Collection <TextureTag>();
            Dictionary <string, SelectionTag> selectionTags = new Dictionary <string, SelectionTag>();
            UVWTag      uvwTag    = null;
            CAWeightTag weightTag = null;

            // SCRATCH
            // var targetComponent = new TargetComponent {ExtraInfo = aStr, Radius = anInt};
            // snc.AddComponent(targetComponent);

            // Iterate over the object's tags
            for (BaseTag tag = ob.GetFirstTag(); tag != null; tag = tag.GetNext())
            {
                // GeneralTag
                if (1036156 == tag.GetTypeC4D())
                {
                    var    di    = tag.GetDataInstance();
                    int    anInt = di.GetInt32(10000);
                    string aStr  = di.GetString(10001);
                    Logger.Debug("Found a GeneralTag with TheInt=" + anInt + " and TheString = \"" + aStr + "\"");
                    // var targetComponent = new TargetComponent {ExtraInfo = aStr, Radius = anInt};
                    // snc.AddComponent(targetComponent);
                }

                // CAWeightTag - Save data to create the weight list later
                CAWeightTag wTag = tag as CAWeightTag;
                if (wTag != null)
                {
                    weightTag = wTag;
                    continue;
                }

                // TextureTag (Material - there might be more than one)
                TextureTag tex = tag as TextureTag;
                if (tex != null)
                {
                    textureTags.Add(tex);
                    continue;
                }
                // UVWTag - the texutre coordinates. We handle only one
                UVWTag uvw = tag as UVWTag;
                if (uvw != null)
                {
                    if (uvwTag == null)
                    {
                        uvwTag = uvw;
                    }
                    else
                    {
                        Logger.Error("Object " + ob.GetName() + " contains more than one uv-coordinates-tag. Cannot handle this. Only the first texture tag will be recognized.");
                    }
                    continue;
                }
                // Selection tag. Only recognize the polygon selections as they might be referenced in a TextureTag
                SelectionTag selection  = tag as SelectionTag;
                string       selTagName = tag.GetName();
                if (selection != null && selection.GetTypeC4D() == C4dApi.Tpolygonselection && !string.IsNullOrEmpty(selTagName))    // One Type and three TypeIDs - You C4D programmer guys really suck
                {
                    selectionTags[selTagName] = selection;
                }
                // XPresso Tags - TBD
                XPressoTag xPresso = tag as XPressoTag;
                if (xPresso != null)
                {
                    // Handle XPresso tag
                    continue;
                }
            }

            TextureTag lastUnselectedTag = null;
            Collection <KeyValuePair <SelectionTag, TextureTag> > texSelList = new Collection <KeyValuePair <SelectionTag, TextureTag> >(); // Abused KeyValuePair. Should have been Pair...

            // Now iterate over the textureTags
            foreach (TextureTag texture in textureTags)
            {
                string selRef = "";
                using (BaseContainer texData = texture.GetData())
                {
                    selRef = texData.GetString(C4dApi.TEXTURETAG_RESTRICTION);
                }
                if (string.IsNullOrEmpty(selRef))
                {
                    // This material is not restricted to any polygon selection
                    lastUnselectedTag = texture;
                }
                else
                {
                    SelectionTag sel;
                    if (selectionTags.TryGetValue(selRef, out sel))
                    {
                        texSelList.Add(new KeyValuePair <SelectionTag, TextureTag>(sel, texture));
                    }
                }
            }

            // At this point we have the last texture tag not restricted to a seletion. This will become the Material of this FuseeObjectContainer
            // no matter if this object contains geometry or not
            if (lastUnselectedTag != null)
            {
                AddComponent(snc, GetMaterial(lastUnselectedTag));
            }

            // Further processing only needs to take place if the object contains any geometry at all.
            PolygonObject polyOb = ob as PolygonObject;

            // Check whether the object contains an unpolygonized mesh
            if (polyOb == null)
            {
                polyOb = ob.GetCache(null) as PolygonObject;
            }

            if (polyOb != null)
            {
                float3[] normalOb = polyOb.CreatePhongNormals();

                // Initialize the polygon index set
                int           nPolys   = polyOb.GetPolygonCount();
                HashSet <int> polyInxs = new HashSet <int>();
                for (int i = 0; i < nPolys; i++)
                {
                    polyInxs.Add(i);
                }

                foreach (KeyValuePair <SelectionTag, TextureTag> texSelItem in texSelList)
                {
                    HashSet <int> polyInxsSubset = new HashSet <int>();
                    BaseSelect    bs             = texSelItem.Key.GetBaseSelect();
                    int           nSegments      = bs.GetSegments();
                    for (int iSeg = 0; iSeg < nSegments; iSeg++)
                    {
                        int from = bs.GetRangeA(iSeg);
                        int to   = bs.GetRangeB(iSeg);
                        for (int iSel = from; iSel <= to; iSel++)
                        {
                            polyInxs.Remove(iSel);
                            polyInxsSubset.Add(iSel);
                        }
                    }

                    // Now generate Polygons for this subset
                    if (polyInxsSubset.Count > 0)
                    {
                        if (snc.Children == null)
                        {
                            snc.Children = new List <SceneNodeContainer>();
                        }

                        SceneNodeContainer subSnc = new SceneNodeContainer();

                        AddComponent(subSnc, new TransformComponent()
                        {
                            Translation = new float3(0, 0, 0),
                            Rotation    = new float3(0, 0, 0),
                            Scale       = new float3(1, 1, 1)
                        });

                        AddComponent(subSnc, GetMaterial(texSelItem.Value));
                        subSnc.Name = snc.Name + "_" + texSelItem.Key.GetName();
                        AddComponent(subSnc, GetMesh(polyOb, normalOb, uvwTag, polyInxsSubset));
                        _weightManager.AddWeightData(subSnc, polyOb, weightTag, polyInxsSubset);

                        snc.Children.Add(subSnc);
                    }
                }

                // The remaining polygons directly go into the original mesh

                AddComponent(snc, GetMesh(polyOb, normalOb, uvwTag, polyInxs));
                _weightManager.AddWeightData(snc, polyOb, weightTag, polyInxs);
            }
            else if (ob.GetTypeC4D() == C4dApi.Olight)
            {
                using (BaseContainer lightData = ob.GetData())
                    // Just for debugging purposes
                    for (int i = 0, id = 0; -1 != (id = lightData.GetIndexId(i)); i++)
                    {
                        if (lightData.GetTypeC4D(id) == C4dApi.DA_LONG)
                        {
                            int iii = lightData.GetInt32(id);
                        }
                        if (lightData.GetTypeC4D(id) == C4dApi.DA_REAL)
                        {
                            double d = lightData.GetFloat(id);
                        }
                        else if (lightData.GetTypeC4D(id) == C4dApi.DA_VECTOR)
                        {
                            double3 v = lightData.GetVector(id);
                        }
                    }
                ;
            }
        }
示例#23
0
        private static MeshComponent GetMesh(PolygonObject polyOb, float3[] normalsOb, UVWTag uvwTag, IEnumerable <int> range)
        {
            List <float3> normals = new List <float3>();

            ushort        nNewVerts = 0;
            VertexList    verts     = new VertexList();
            List <float2> uvs       = new List <float2>();
            List <ushort> tris      = new List <ushort>();

            foreach (int i in range)
            {
                int     iNorm = i * 4;
                double3 a, b, c, d;
                using (CPolygon poly = polyOb.GetPolygonAt(i))
                {
                    a = polyOb.GetPointAt(poly.a);
                    b = polyOb.GetPointAt(poly.b);
                    c = polyOb.GetPointAt(poly.c);
                    d = polyOb.GetPointAt(poly.d);
                }

                float2 uvA = new float2(0, 0);
                float2 uvB = new float2(0, 1);
                float2 uvC = new float2(1, 1);
                float2 uvD = new float2(1, 0);

                if (uvwTag != null)
                {
                    using (UVWStruct uvw = uvwTag.GetSlow(i))
                    {
                        uvA = new float2((float)uvw.a.x, 1.0f - (float)uvw.a.y);
                        uvB = new float2((float)uvw.b.x, 1.0f - (float)uvw.b.y);
                        uvC = new float2((float)uvw.c.x, 1.0f - (float)uvw.c.y);
                        uvD = new float2((float)uvw.d.x, 1.0f - (float)uvw.d.y);
                    }
                }

                verts.Add((float3)a);
                verts.Add((float3)b);
                verts.Add((float3)c);

                uvs.Add(uvA);
                uvs.Add(uvB);
                uvs.Add(uvC);

                float3 faceNormal = CalcFaceNormal((float3)a, (float3)b, (float3)c);
                float3 normalD;
                if (normalsOb != null)
                {
                    normals.Add(AdjustNormal(normalsOb[iNorm++], faceNormal));
                    normals.Add(AdjustNormal(normalsOb[iNorm++], faceNormal));
                    normals.Add(AdjustNormal(normalsOb[iNorm++], faceNormal));
                    normalD = AdjustNormal(normalsOb[iNorm++], faceNormal);
                }
                else
                {
                    normals.Add(faceNormal);
                    normals.Add(faceNormal);
                    normals.Add(faceNormal);
                    normalD = faceNormal;
                }

                tris.AddRange(new ushort[] { nNewVerts, (ushort)(nNewVerts + 2), (ushort)(nNewVerts + 1) });

                if (c != d)
                {
                    // The Polyogon is not a triangle, but a quad. Add the second triangle.
                    verts.Add((float3)d);
                    uvs.Add(uvD);
                    normals.Add(normalD);
                    tris.AddRange(new ushort[] { nNewVerts, (ushort)(nNewVerts + 3), (ushort)(nNewVerts + 2) });
                    nNewVerts += 1;
                }
                nNewVerts += 3;
            }
            Debug.WriteLine(verts.Count);
            return(new MeshComponent()
            {
                Normals = normals.ToArray(),
                Vertices = verts.ToArray(),
                Triangles = tris.ToArray(),
                UVs = uvs.ToArray(),
                BoundingBox = new AABBf(verts.Min, verts.Max)
            });
        }
示例#24
0
    public void ParsePolygonsFromFile()
    {
        this.ClearBodiesList();
        if (PlistPath == null)
        {
            return;
        }

        Hashtable plistData = new Hashtable();

        PListManager.ParsePListFile(PlistPath.text, ref plistData);

        Hashtable bodies = plistData["bodies"] as Hashtable;

        if (bodies == null)
        {
            Debug.Log("Bodies not found");
        }

        ArrayList keyNames = new ArrayList(bodies.Keys);

        _totalPolygonsinFile = new PolygonObject[keyNames.Count];


        if (keyNames != null)
        {
            for (int i = 0; i < keyNames.Count; i++)
            {
                _totalPolygonsinFile[i]          = new PolygonObject();
                _totalPolygonsinFile[i].bodyname = keyNames[i] as String;

                Hashtable bodyDic  = bodies[keyNames[i]] as Hashtable;
                ArrayList fixtures = bodyDic["fixtures"] as ArrayList;

                var totalPaths = new List <PolygonPath>();

                for (var f = 0; f < fixtures.Count; f++)
                {
                    var fixture = fixtures[f] as Hashtable;
                    if (fixture == null)
                    {
                        continue;
                    }

                    var polygonsArray = fixture["polygons"] as ArrayList;
                    if (polygonsArray == null)
                    {
                        continue;
                    }

                    for (int j = 0; j < polygonsArray.Count; j++)
                    {
                        ArrayList   pointArray   = polygonsArray[j] as ArrayList;
                        PolygonPath tempPath     = new PolygonPath();
                        Vector2[]   pointsVector = new Vector2[pointArray.Count];
                        for (int k = 0; k < pointsVector.Length; k++)
                        {
                            string pointInString = pointArray[k] as String;
                            pointsVector[k] = this.ConvertToVector2FromString(pointInString);
                        }

                        tempPath.points = pointsVector;

                        totalPaths.Add(tempPath);
                    }
                }

                _totalPolygonsinFile[i].paths = totalPaths.ToArray();
            }


            Array.Sort(_totalPolygonsinFile);
            this.setPolygonOfIndex(selectedIndex);
        }
        else
        {
            Debug.Log("Keys not found");
        }
    }
示例#25
0
        public static BaseObject ReadObject(this XmlReader reader)
        {
            if (!reader.IsStartElement("object"))
            {
                throw new XmlException(reader.Name);
            }

            var id = reader["id"].ParseInt32() ?? 0;

            var name = reader["name"];
            var type = reader["type"];

            var gid = reader["gid"].ParseInt32();

            var x = reader["x"].ParseInt32().Value;
            var y = reader["y"].ParseInt32().Value;
            var w = reader["width"].ParseInt32();
            var h = reader["height"].ParseInt32();

            BaseObject result     = null;
            var        properties = new Dictionary <string, string>();

            if (reader.IsEmptyElement)
            {
                reader.Skip();
            }
            else
            {
                reader.ReadStartElement("object");

                while (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                    case "properties":
                        reader.ReadProperties(properties);
                        break;

                    case "ellipse":
                        result = new EllipseObject(properties)
                        {
                            Id         = id,
                            X          = x,
                            Y          = y,
                            Width      = w.Value,
                            Height     = h.Value,
                            Name       = name,
                            IsEllipse  = true,
                            ObjectType = type
                        };
                        reader.Skip();
                        break;

                    case "polygon":
                        result = new PolygonObject(properties)
                        {
                            Id         = id,
                            X          = x,
                            Y          = y,
                            Name       = name,
                            Polygon    = reader.ReadPoints().ToArray(),
                            ObjectType = type
                        };
                        reader.Skip();
                        break;

                    case "polyline":
                        result = new PolyLineObject(properties)
                        {
                            Id         = id,
                            X          = x,
                            Y          = y,
                            Name       = name,
                            Polyline   = reader.ReadPoints().ToArray(),
                            ObjectType = type
                        };
                        reader.Skip();
                        break;

                    case "point":
                        result = new PointObject(properties)
                        {
                            Id         = id,
                            X          = x,
                            Y          = y,
                            Name       = name,
                            ObjectType = type
                        };
                        reader.Skip();
                        break;

                    default:
                        throw new XmlException(reader.Name);
                    }
                }

                if (reader.Name == "object")
                {
                    reader.ReadEndElement();
                }
                else
                {
                    throw new XmlException($"Expected </object>, found: {reader.Name}");
                }
            }

            if (gid.HasValue)
            {
                result = new TileObject(properties)
                {
                    Id         = id,
                    Gid        = gid.Value,
                    X          = x,
                    Y          = y,
                    Width      = w.Value,
                    Height     = h.Value,
                    Name       = name,
                    ObjectType = type
                }
            }
            ;

            return(result ?? new RectangleObject(properties)
            {
                Id = id,
                X = x,
                Y = y,
                Width = w.Value,
                Height = h.Value,
                Name = name,
                ObjectType = type
            });
        }
示例#26
0
    public void ParsePolygonsFromFile()
    {
        this.ClearBodiesList();
        if (PlistPath == null)
        {
            return;
        }

        Hashtable plistData = new Hashtable();

        PListManager.ParsePListFile(PlistPath.text, ref plistData);

        Hashtable bodies = plistData["bodies"] as Hashtable;

        if (bodies == null)
        {
            Debug.Log("Bodies not found");
        }

        ArrayList keyNames = new ArrayList(bodies.Keys);

        _totalPolygonsinFile = new PolygonObject[keyNames.Count];


        if (keyNames != null)
        {
            for (int i = 0; i < keyNames.Count; i++)
            {
                _totalPolygonsinFile[i]          = new PolygonObject();
                _totalPolygonsinFile[i].bodyname = keyNames[i] as String;

                Hashtable bodyDic = bodies[keyNames[i]] as Hashtable;
                /*Using single fixture because unity support single fixture*/
                ArrayList fixtures = bodyDic["fixtures"] as ArrayList;

                Hashtable fixture1 = fixtures[0] as Hashtable;

                ArrayList polygonsArray = fixture1["polygons"] as ArrayList;

                PolygonPath[] totalPaths = new PolygonPath[polygonsArray.Count];

                for (int j = 0; j < totalPaths.Length; j++)
                {
                    ArrayList   pointArray   = polygonsArray[j] as ArrayList;
                    PolygonPath tempPath     = new PolygonPath();
                    Vector2[]   pointsVector = new Vector2[pointArray.Count];
                    for (int k = 0; k < pointsVector.Length; k++)
                    {
                        string pointInString = pointArray[k] as String;
                        pointsVector[k] = this.ConvertToVector2FromString(pointInString);
                    }

                    tempPath.points = pointsVector;

                    totalPaths[j] = tempPath;
                }

                _totalPolygonsinFile[i].paths = totalPaths;
            }


            Array.Sort(_totalPolygonsinFile);
            this.setPolygonOfIndex(selectedIndex);
        }
        else
        {
            Debug.Log("Keys not found");
        }
    }
示例#27
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PolygonObject obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }