本文整理汇总了C#中Poly2Tri.Triangulation.Delaunay.Sweep.DTSweepContext.PrepareTriangulation方法的典型用法代码示例。如果您正苦于以下问题:C# DTSweepContext.PrepareTriangulation方法的具体用法?C# DTSweepContext.PrepareTriangulation怎么用?C# DTSweepContext.PrepareTriangulation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poly2Tri.Triangulation.Delaunay.Sweep.DTSweepContext
的用法示例。
在下文中一共展示了DTSweepContext.PrepareTriangulation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Triangulate
public int[] Triangulate(UnityEngine.Vector2[] verts)
{
PolygonPoint[] points = new PolygonPoint[verts.Length];
for (int i = 0; i < verts.Length; i++)
points[i] = new PolygonPoint(verts[i].x, verts[i].y);
Polygon polygon = new Polygon(points);
DTSweepContext tcx = new DTSweepContext();
tcx.PrepareTriangulation(polygon);
DTSweep.Triangulate(tcx);
int[] resultPoints = new int[polygon.Triangles.Count * 3];
int idx = 0;
foreach (DelaunayTriangle triangle in polygon.Triangles) {
resultPoints[idx++] = FindIndex(points, triangle.Points._0);
resultPoints[idx++] = FindIndex(points, triangle.Points._1);
resultPoints[idx++] = FindIndex(points, triangle.Points._2);
}
return resultPoints;
}
示例2: ConvexPartition
public static List<Vertices> ConvexPartition(DetectedVertices vertices)
{
Polygon poly = new Polygon();
foreach (var vertex in vertices)
poly.Points.Add(new TriangulationPoint(vertex.X, vertex.Y));
if (vertices.Holes != null)
{
foreach (var holeVertices in vertices.Holes)
{
Polygon hole = new Polygon();
foreach (var vertex in holeVertices)
hole.Points.Add(new TriangulationPoint(vertex.X, vertex.Y));
poly.AddHole(hole);
}
}
DTSweepContext tcx = new DTSweepContext();
tcx.PrepareTriangulation(poly);
DTSweep.Triangulate(tcx);
List<Vertices> results = new List<Vertices>();
foreach (DelaunayTriangle triangle in poly.Triangles)
{
Vertices v = new Vertices();
foreach (TriangulationPoint p in triangle.Points)
{
v.Add(new FVector2((float)p.X, (float)p.Y));
}
results.Add(v);
}
return results;
}
示例3: CreateMesh
public void CreateMesh(Vector2[] vertsToCopy, Transform transform)
{
List<Vector3> resultsLocal = new List<Vector3>();
List<int> resultsTriIndexesLocal = new List<int>();
List<int> resultsTriIndexesReversedLocal = new List<int>();
List<Vector2> uvsLocal = new List<Vector2>();
List<Vector3> normalsLocal = new List<Vector3>();
Sprite spr = transform.GetComponent<SpriteRenderer>().sprite;
Rect rec = spr.rect;
Vector3 bound = transform.GetComponent<Renderer>().bounds.max- transform.GetComponent<Renderer>().bounds.min ;
TextureImporter textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(spr)) as TextureImporter;
int i = 0;
Polygon poly = new Polygon();
for (i=0; i <vertsToCopy.Length;i++)
{
poly.Points.Add(new TriangulationPoint(vertsToCopy[i].x, vertsToCopy[i].y));
}
DTSweepContext tcx = new DTSweepContext();
tcx.PrepareTriangulation(poly);
DTSweep.Triangulate(tcx);
int indexNumber = 0;
bool multiSprites = false;
foreach (DelaunayTriangle triangle in poly.Triangles)
{
Vector3 v = new Vector3();
foreach (TriangulationPoint p in triangle.Points)
{
v = new Vector3((float)p.X, (float)p.Y,0);
if(!resultsLocal.Contains(v))
{
resultsLocal.Add(v);
resultsTriIndexesLocal.Add(indexNumber);
Vector2 newUv = new Vector2((v.x /bound.x) + 0.5f, (v.y /bound.y) + 0.5f);
newUv.x *= rec.width/ spr.texture.width;
newUv.y *= rec.height/ spr.texture.height;
//Debug.Log(spr.textureRectOffset);
newUv.x += (rec.x)/ spr.texture.width;
newUv.y += (rec.y) / spr.texture.height;
//Debug.Log(Application.unityVersion);
SpriteMetaData[] smdArray = textureImporter.spritesheet;
Vector2 pivot = new Vector2(.0f,.0f);;
for (int j = 0; j < smdArray.Length; j++)
{
if (smdArray[j].name == spr.name)
{
switch(smdArray[j].alignment)
{
case(0):
smdArray[j].pivot = Vector2.zero;
break;
case(1):
smdArray[j].pivot = new Vector2(0f,1f) -new Vector2(.5f,.5f);
break;
case(2):
smdArray[j].pivot = new Vector2(0.5f,1f) -new Vector2(.5f,.5f);
break;
case(3):
smdArray[j].pivot = new Vector2(1f,1f) -new Vector2(.5f,.5f);
break;
case(4):
smdArray[j].pivot = new Vector2(0f,.5f) -new Vector2(.5f,.5f);
break;
case(5):
smdArray[j].pivot = new Vector2(1f,.5f) -new Vector2(.5f,.5f);
break;
case(6):
smdArray[j].pivot = new Vector2(0f,0f) -new Vector2(.5f,.5f);
break;
case(7):
smdArray[j].pivot = new Vector2(0.5f,0f) -new Vector2(.5f,.5f);
break;
case(8):
smdArray[j].pivot = new Vector2(1f,0f) -new Vector2(.5f,.5f);
break;
case(9):
smdArray[j].pivot -= new Vector2(.5f,.5f);
break;
}
pivot = smdArray[j].pivot ;
}
}
if(textureImporter.spriteImportMode == SpriteImportMode.Single)
pivot = textureImporter.spritePivot-new Vector2(.5f,.5f);
newUv.x += ((pivot.x)*rec.width)/ spr.texture.width;
newUv.y += ((pivot.y)*rec.height)/ spr.texture.height;
/*
if(Application.unityVersion != "4.3.0f4")
{
//.........这里部分代码省略.........
示例4: Run
//public bool ReverseNormals;
public GameObject Run(Transform transform,bool ReverseNormals )
{
PolygonCollider2D polygonCollider = transform.GetComponent<PolygonCollider2D>();
Sprite spr = transform.GetComponent<SpriteRenderer>().sprite;
Rect rec = spr.rect;
//for(int path =0;path<polygonCollider.pathCount;path++)
//{
int path =0;
bool overwrite = false;
MeshedSprite = new GameObject();
Undo.RegisterCreatedObjectUndo (MeshedSprite, "Created Mesh");
mf = MeshedSprite.AddComponent<MeshFilter>();
mr = MeshedSprite.AddComponent<MeshRenderer>();
mesh = new Mesh();
if(AssetDatabase.LoadAssetAtPath("Assets/Puppet2D/Models/"+transform.name+"_MESH.asset",typeof(Mesh)))
{
if(EditorUtility.DisplayDialog("Overwrite Asset?","Do you want to overwrite the current Mesh & Material?","Yes, Overwrite","No, Create New Mesh & Material"))
{
mesh = AssetDatabase.LoadAssetAtPath("Assets/Puppet2D/Models/"+transform.name+"_MESH.asset",typeof(Mesh))as Mesh;
overwrite = true;
}
else
{
string meshPath = AssetDatabase.GenerateUniqueAssetPath("Assets/Puppet2D/Models/"+transform.name+"_MESH.asset");
AssetDatabase.CreateAsset(mesh,meshPath);
}
}
else
{
string meshPath = AssetDatabase.GenerateUniqueAssetPath("Assets/Puppet2D/Models/"+transform.name+"_MESH.asset");
AssetDatabase.CreateAsset(mesh,meshPath);
}
Vector3 bound = transform.renderer.bounds.max- transform.renderer.bounds.min ;
List<Vector3> results = new List<Vector3>();
List<int> resultsTriIndexes = new List<int>();
List<int> resultsTriIndexesReversed = new List<int>();
List<Vector2> uvs = new List<Vector2>();
List<Vector3> normals = new List<Vector3>();
Vector2[] vertsToCopy = polygonCollider.GetPath(path);
int i = 0;
Polygon poly = new Polygon();
for (i=0; i <vertsToCopy.Length;i++)
{
poly.Points.Add(new TriangulationPoint(vertsToCopy[i].x, vertsToCopy[i].y));
}
DTSweepContext tcx = new DTSweepContext();
tcx.PrepareTriangulation(poly);
DTSweep.Triangulate(tcx);
int indexNumber = 0;
foreach (DelaunayTriangle triangle in poly.Triangles)
{
Vector3 v = new Vector3();
foreach (TriangulationPoint p in triangle.Points)
{
v = new Vector3((float)p.X, (float)p.Y,0);
if(!results.Contains(v))
{
results.Add(v);
resultsTriIndexes.Add(indexNumber);
Vector2 newUv = new Vector2((v.x /bound.x) + 0.5f, (v.y /bound.y) + 0.5f);
newUv.x *= rec.width/ spr.texture.width;
newUv.y *= rec.height/ spr.texture.height;
//Debug.Log(spr.textureRectOffset);
newUv.x += (rec.x)/ spr.texture.width;
newUv.y += (rec.y) / spr.texture.height;
uvs.Add(newUv);
normals.Add(new Vector3(0,0,-1));
indexNumber++;
}
else
{
resultsTriIndexes.Add(results.LastIndexOf(v));
}
}
}
for (int j = resultsTriIndexes.Count-1; j >=0; j--)
{
resultsTriIndexesReversed.Add(resultsTriIndexes[j]);
}
//.........这里部分代码省略.........