当前位置: 首页>>代码示例>>C#>>正文


C# pb_Object.GetUVs方法代码示例

本文整理汇总了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;
	}
开发者ID:flickenmaste,项目名称:R6Demake,代码行数:30,代码来源:ExplodeFaces.cs

示例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]);

//.........这里部分代码省略.........
开发者ID:itubeasts,项目名称:I-eaT-U,代码行数:101,代码来源:pbSubdivideSplit.cs

示例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 };
//.........这里部分代码省略.........
开发者ID:itubeasts,项目名称:I-eaT-U,代码行数:101,代码来源:pbSubdivideSplit.cs

示例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;
			}
		}
	}
开发者ID:itubeasts,项目名称:I-eaT-U,代码行数:44,代码来源:pbUVOps.cs


注:本文中的pb_Object.GetUVs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。