コード例 #1
0
    private void convexDecomp()
    {
        Mesh       col        = null;
        MeshFilter meshFilter = GetComponent <MeshFilter>();

        if (meshFilter != null)
        {
            col = meshFilter.mesh;
        }
        if (col == null)
        {
            Debug.LogError("There is no 'Mesh' attached");
            convexPolys = new List <Vector2[]>(1);
            return;
        }

        List <Vector2> worldColPoints = new List <Vector2>(col.vertices.Length);
        Transform      thisTransform  = transform;

        foreach (Vector2 point in col.vertices)
        {
            Vector2 currentWorldPoint = thisTransform.TransformPoint(point);
            worldColPoints.Add(currentWorldPoint);
        }

        convexPolys = BayazitPolygonDecomposer.ConvexPartition(worldColPoints);
    }
コード例 #2
0
    private static void setupPolyshapes(GameObject go)
    {
        // take the mesh vertices
        Vector3[] meshVertices = getMeshVertices(go);
        // split in several convex polygons
        List <Vector2[]> convexVects2 = BayazitPolygonDecomposer.ConvexPartition(meshVertices);

        // add a new ChipmunkPolyShape for every convex polygon
        for (int i = 0, c = convexVects2.Count; i < c; ++i)
        {
            Vector2[] vec2arr = convexVects2[i];
            // for every poly shape component set its vertex[] attribute as the convex vertex[]
            ChipmunkPolyShape polyShape = go.AddComponent <ChipmunkPolyShape>();
            polyShape.verts = vec2arr;
        }
    }