本文整理汇总了C#中pb_Object.GetUVs方法的典型用法代码示例。如果您正苦于以下问题:C# pb_Object.GetUVs方法的具体用法?C# pb_Object.GetUVs怎么用?C# pb_Object.GetUVs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pb_Object
的用法示例。
在下文中一共展示了pb_Object.GetUVs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExplodeObject
// breaks a pb_object into a zillion* faces
public static GameObject[] ExplodeObject(pb_Object pb)
{
// disable 'ze donor
pb.gameObject.SetActive(false);
GameObject[] pieces = new GameObject[pb.faces.Length];
// extract mesh and material information for every face, and assign it to a gameobject
for(int i = 0; i < pieces.Length; i++)
{
Mesh m = new Mesh();
m.vertices = pb.GetVertices(pb.faces[i]);
m.triangles = new int[6] {0,1,2, 1,3,2};
m.normals = pb.GetNormals(pb.faces[i]);
m.uv = pb.GetUVs(pb.faces[i]);
m.RecalculateBounds();
GameObject go = new GameObject();
go.transform.position = pb.transform.position + pb_Math.PlaneNormal(m.vertices).normalized * .3f;
go.transform.localRotation = pb.transform.localRotation;
go.AddComponent<MeshFilter>().sharedMesh = m;
go.AddComponent<MeshRenderer>().sharedMaterial = pb.GetMaterial(pb.faces[i]);
pieces[i] = go;
}
return pieces;
}
示例2: SubdivideFace_Internal
/**
* Inserts a vertex at the center of each edge, then connects the new vertices to another new
* vertex placed at the center of the face.
*/
private static bool SubdivideFace_Internal(pb_Object pb, pb_EdgeConnection pb_edgeConnection,
out DanglingVertex?[] appendedVertices,
out pb_Face[] splitFaces,
out Vector3[][] splitVertices,
out Color[][] splitColors,
out Vector2[][] splitUVs,
out int[][] splitSharedIndices)
{
splitFaces = null;
splitVertices = null;
splitColors = null;
splitUVs = null;
splitSharedIndices = null;
appendedVertices = new DanglingVertex?[pb_edgeConnection.edges.Count];
// cache all the things
pb_Face face = pb_edgeConnection.face;
Dictionary<int, int> sharedIndices = pb.sharedIndices.ToDictionary();
Vector3[] vertices = pb.vertices;
Vector2[] uvs = pb.uv;
List<Vector2> edgeCentersUV = new List<Vector2>();
List<Vector3> edgeCenters3d = new List<Vector3>();
List<Color> edgeCentersCol = new List<Color>();
// filter duplicate edges
int u = 0;
List<int> usedEdgeIndices = new List<int>();
foreach(pb_Edge edge in pb_edgeConnection.edges)
{
int ind = face.edges.IndexOf(edge, sharedIndices);
if(!usedEdgeIndices.Contains(ind))
{
Vector3 cen = (vertices[edge.x] + vertices[edge.y]) / 2f;
appendedVertices[u] = new DanglingVertex(cen, (pb.colors[edge.x] + pb.colors[edge.y]) / 2f);
edgeCenters3d.Add(cen);
edgeCentersUV.Add( (uvs[edge.x] + uvs[edge.y])/2f );
edgeCentersCol.Add( (pb.colors[edge.x] + pb.colors[edge.y])/2f );
usedEdgeIndices.Add(ind);
}
else
{
appendedVertices[u] = null;
}
u++;
}
// now we have all the vertices of the old face, plus the new edge center vertices
Vector3 nrm = pb_Math.Normal(pb.GetVertices(face.indices));
Vector3[] verts3d = pb.GetVertices(face.distinctIndices);
Vector2[] faceUVs = pb.GetUVs(face.distinctIndices);
Color[] colors = pbUtil.ValuesWithIndices(pb.colors, face.distinctIndices);
Vector2[] verts2d = pb_Math.PlanarProject(verts3d, nrm);
Vector2[] edgeCenters2d = pb_Math.PlanarProject(edgeCenters3d.ToArray(), nrm);
Vector3 cen3d = pb_Math.Average(verts3d);
Vector2 cenUV = pb_Bounds2D.Center(faceUVs);
Vector2 cen2d = pb_Math.PlanarProject( new Vector3[1] { cen3d }, nrm)[0];
// Get the directions from which to segment this face
Vector2[] dividers = new Vector2[edgeCenters2d.Length];
for(int i = 0; i < edgeCenters2d.Length; i++)
dividers[i] = (edgeCenters2d[i] - cen2d).normalized;
List<Vector2>[] quadrants2d = new List<Vector2>[edgeCenters2d.Length];
List<Vector3>[] quadrants3d = new List<Vector3>[edgeCenters2d.Length];
List<Vector2>[] quadrantsUV = new List<Vector2>[edgeCenters2d.Length];
List<Color>[] quadrantsCol = new List<Color>[edgeCenters2d.Length];
List<int>[] sharedIndex = new List<int>[edgeCenters2d.Length];
for(int i = 0; i < quadrants2d.Length; i++)
{
quadrants2d[i] = new List<Vector2>(1) { cen2d };
quadrants3d[i] = new List<Vector3>(1) { cen3d };
quadrantsUV[i] = new List<Vector2>(1) { cenUV };
quadrantsCol[i] = new List<Color>(1) { pb_Math.Average(pbUtil.ValuesWithIndices(pb.colors, face.distinctIndices)) };
sharedIndex[i] = new List<int>(1) { -2 }; // any negative value less than -1 will be treated as a new group
}
// add the divisors
for(int i = 0; i < edgeCenters2d.Length; i++)
{
quadrants2d[i].Add(edgeCenters2d[i]);
quadrants3d[i].Add(edgeCenters3d[i]);
quadrantsUV[i].Add(edgeCentersUV[i]);
quadrantsCol[i].Add(edgeCentersCol[i]);
//.........这里部分代码省略.........
示例3: PokeFace_Internal
/**
* Inserts a split from each selected vertex to the center of the face
*/
private static bool PokeFace_Internal(pb_Object pb, pb_Face face, int[] indices_nonFaceSpecific,
out Vector3 pokedVertex,
out pb_Face[] splitFaces,
out Vector3[][] splitVertices,
out Color[][] splitColors,
out Vector2[][] splitUVs,
out int[][] splitSharedIndices)
{
pokedVertex = Vector3.zero;
splitFaces = null;
splitVertices = null;
splitColors = null;
splitUVs = null;
splitSharedIndices = null;
pb_IntArray[] sharedIndices = pb.sharedIndices;
///** Sort index array such that it only uses indices local to the passed face
int[] dist_indices = new int[indices_nonFaceSpecific.Length];
int[] dist_ind_si = new int[face.distinctIndices.Length];
// figure out sharedIndices index of distinct Indices
for(int i = 0; i < face.distinctIndices.Length; i++)
dist_ind_si[i] = sharedIndices.IndexOf(face.distinctIndices[i]);
// now do the same for non-face specific indices, assigning matching groups
///** Sort index array such that it only uses indices local to the passed face
for(int i = 0; i < dist_indices.Length; i++)
{
int ind = System.Array.IndexOf(dist_ind_si, sharedIndices.IndexOf(indices_nonFaceSpecific[i]));
if(ind < 0) return false;
dist_indices[i] = face.distinctIndices[ind];
}
int[] indices = dist_indices.Distinct().ToArray();
// throw out splits with less than 2 vertices, or splits composed
// of a single edge
switch(indices.Length)
{
case 0:
case 1:
return false;
case 2:
if( System.Array.IndexOf(face.edges, new pb_Edge(indices[0], indices[1]) ) > -1)
return false;
break;
default:
break;
}
// end triangle sorting
/**
* The general idea here is to project the face into 2d space,
* split the 2d points into groups based on the intersecting lines,
* then triangulate those groups. once the groups have been
* triangulated, rebuild the 3d vertices using the new groups
* (building new verts for seams).
*
* Think like you're cutting a pie... but first the pie is a basketball,
* then a pie, then a basketball again. I'm on a horse.
*/
Vector3[] verts = pb.GetVertices(face.distinctIndices);
Vector2[] uvs = pb.GetUVs(face.distinctIndices);
Color[] colors = pbUtil.ValuesWithIndices(pb.colors, face.distinctIndices);
Vector2 cenUV = pb_Bounds2D.Center(uvs);
Vector3 cen3d = pb_Math.Average(verts);
pokedVertex = cen3d;
Vector3 nrm = pb_Math.Normal(pb.GetVertices(face.indices));
Color cenColor = pb_Math.Average(colors);
// this should be cleaned up
Vector2[] plane = pb_Math.PlanarProject(verts, nrm);
Vector2[] indPlane = pb_Math.PlanarProject(pb.GetVertices(indices), nrm);
Vector2 cen2d = pb_Math.PlanarProject( new Vector3[1] { cen3d }, nrm)[0];
// Get the directions from which to segment this face
Vector2[] dividers = new Vector2[indices.Length];
for(int i = 0; i < indices.Length; i++)
dividers[i] = (indPlane[i] - cen2d).normalized;
List<Vector2>[] quadrants2d = new List<Vector2>[indices.Length];
List<Vector3>[] quadrants3d = new List<Vector3>[indices.Length];
List<Vector2>[] quadrantsUV_2d = new List<Vector2>[indices.Length];
List<Color>[] quadrantsCol = new List<Color>[indices.Length];
List<int>[] sharedIndex = new List<int>[indices.Length];
for(int i = 0; i < quadrants2d.Length; i++)
{
quadrants2d[i] = new List<Vector2>(1) { cen2d };
//.........这里部分代码省略.........
示例4: SetAutoUV
/**
* Sets the passed faces to use Auto or Manual UVs, and (if previously manual) splits any vertex connections.
*/
public static void SetAutoUV(pb_Object pb, pb_Face[] faces, bool auto)
{
if(auto)
{
faces = System.Array.FindAll(faces, x => x.manualUV).ToArray(); // only operate on faces that were previously manual
pb.SplitUVs( pb_Face.AllTriangles(faces) );
Vector2[][] uv_origins = new Vector2[faces.Length][];
for(int i = 0; i < faces.Length; i++)
uv_origins[i] = pb.GetUVs(faces[i].distinctIndices);
for(int f = 0; f < faces.Length; f++)
{
faces[f].uv.Reset();
faces[f].manualUV = !auto;
faces[f].elementGroup = -1;
}
pb.RefreshUV(faces);
for(int i = 0; i < faces.Length; i++)
{
pb_Transform2D transform = MatchCoordinates(pb.GetUVs(faces[i].distinctIndices), uv_origins[i]);
faces[i].uv.offset = -transform.position;
faces[i].uv.rotation = transform.rotation;
if( Mathf.Abs(transform.scale.sqrMagnitude - 2f) > .1f )
faces[i].uv.scale = transform.scale;
}
}
else
{
foreach(pb_Face f in faces)
{
f.textureGroup = -1;
f.manualUV = !auto;
}
}
}