찾기
내용으로 건너뛰기
추적
문서의 이전 판을 선택했습니다!
저장하면 이 자료로 새 판을 만듭니다.
미디어 파일
======Example - Creating a Billboard Plane====== Unity comes with a Plane primitive object but a simpler plane may be useful in 2D games or GUI, and in any case makes a good starting example. A minimal plane will consist of four vertices to define the corners along with two triangles. The first thing is to set the vertices array. We'll assume that the plane lies in the X and Y axes and let its width and height be determined by parameter variables. We'll supply the vertices in the order bottom-left, bottom-right, top-left, top-right. {{:unity3d:MeshConstruction.png}} <file csharp>var vertices: Vector3[] = new Vector3[4]; vertices[0] = new Vector3(0, 0, 0); vertices[1] = new Vector3(width, 0, 0); vertices[2] = new Vector3(0, height, 0); vertices[3] = new Vector3(width, height, 0); mesh.vertices = vertices;</file> (Since the Mesh data properties execute code behind the scenes, it is much more efficient to set up the data in your own array and then assign this to a property rather than access the property array element by element.) Next come the triangles. Since we want two triangles, each defined by three integers, the triangles array will have six elements in total. Remembering the clockwise rule for ordering the corners, the lower left triangle will use 0, 2, 1 as its corner indices, while the upper right one will use 2, 3, 1. <file csharp>var tri: int[] = new int[6]; // Lower left triangle. tri[0] = 0; tri[1] = 2; tri[2] = 1; // Upper right triangle. tri[3] = 2; tri[4] = 3; tri[5] = 1; mesh.triangles = tri;</file> A mesh with just the vertices and triangles set up will be visible in the editor but will not look very convincing since it is not correctly shaded without the normals. The normals for the flat plane are very simple - they are all identical and point in the negative Z direction in the plane's local space. With the normals added, the plane will be correctly shaded but remember that you need a light in the scene to see the effect. <file csharp>var normals: Vector3[] = new Vector3[4]; normals[0] = -Vector3.forward; normals[1] = -Vector3.forward; normals[2] = -Vector3.forward; normals[3] = -Vector3.forward; mesh.normals = normals;</file> Finally, adding texture coordinates to the mesh will enable it to display a material correctly. Assuming we want to show the whole image across the plane, the UV values will all be 0 or 1, corresponding to the corners of the texture. <file csharp>var uv: Vector2[] = new Vector2[4]; uv[0] = new Vector2(0, 0); uv[1] = new Vector2(1, 0); uv[2] = new Vector2(0, 1); uv[3] = new Vector2(1, 1); mesh.uv = uv;</file> The complete script might look a bit like this:- <file csharp>var width: float; var height: float; function Start() { var mf: MeshFilter = GetComponent(MeshFilter); var mesh = new Mesh(); mf.mesh = mesh; var vertices: Vector3[] = new Vector3[4]; vertices[0] = new Vector3(0, 0, 0); vertices[1] = new Vector3(width, 0, 0); vertices[2] = new Vector3(0, height, 0); vertices[3] = new Vector3(width, height, 0); mesh.vertices = vertices; var tri: int[] = new int[6]; tri[0] = 0; tri[1] = 2; tri[2] = 1; tri[3] = 2; tri[4] = 3; tri[5] = 1; mesh.triangles = tri; var normals: Vector3[] = new Vector3[4]; normals[0] = -Vector3.forward; normals[1] = -Vector3.forward; normals[2] = -Vector3.forward; normals[3] = -Vector3.forward; mesh.normals = normals; var uv: Vector2[] = new Vector2[4]; uv[0] = new Vector2(0, 0); uv[1] = new Vector2(1, 0); uv[2] = new Vector2(0, 1); uv[3] = new Vector2(1, 1); mesh.uv = uv; }</file> Note that the if the code is executed once in the Start function then the mesh will stay the same throughout the game. However, you can just as easily put the code in the Update function to allow the mesh to be changed each frame (although this will increase the CPU overhead considerably). {{tag>유니티 unity}} * 출처: [[http://unitykoreawiki.com/index.php?n=KrMain.Example-CreatingaBillboardPlane|유니티코리아위키]] (CC BY-NC-SA 2.0)
2+1?
이 필드는 비어 있도록 유지하세요:
저장
미리 보기
취소
편집 요약
참고: 이 문서를 편집하면 내용은 다음 라이선스에 따라 배포하는 데 동의하는 것으로 간주합니다:
CC Attribution-Noncommercial-Share Alike 4.0 International
연결문서
절차에 맞게 메쉬 기하(Mesh Geometry) 생성하기
유니티3D ( Unity3D )
문서 도구
문서 보기
이전 판
연결문서
맨 위로
다크 모드로 보기
☀️
Toggle Menu
유니티3D ( Unity3D )
너두 고쳐두 됩니다.
사이트 도구
최근 바뀜
미디어 관리자
사이트맵
사용자 도구
등록
로긴
최근 수정된 문서
misuse_topical5
노박
unique_items
dinner_bell
deputy_beagle
ratslayer
one_for_my_baby
alerio
power_fist
제거됨
fixer
climb_ev_ry_mountain
companion
[장비 분실]
crashed_vertibird
brotherhood_t-51b_power_armor
marco
i_forgot_to_remember_to_forget
cateye