生活随笔
收集整理的這篇文章主要介紹了
【原】Unity3D 窗口裁剪
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
實(shí)現(xiàn)效果 拖動(dòng)readplane 當(dāng)包圍盒最小點(diǎn)超出bluePlane的最小點(diǎn)時(shí)(僅做了左邊裁剪),對(duì)超出部分裁剪,當(dāng)全部超出隱藏readPlane 當(dāng)readPlane包圍盒的最大坐標(biāo)點(diǎn)大于bluePlane的最小點(diǎn)時(shí),顯示readPlane;
閱讀此文時(shí),讀者最好具備世界坐標(biāo) 本地坐標(biāo) bounds 等之類的知識(shí)!
collider.bounds、render.bounds的min max是世界坐標(biāo),size是大小? mesh.bounds是本地坐標(biāo)。mesh.vertices對(duì)線框頂點(diǎn)坐標(biāo)更改。
???
public Transform readPlane;public Transform bluePlane;Bounds readBoundPlane;Bounds blueBoundPlane;Vector3 blueBoundMin;Vector3 blueBoundMax;Mesh mesh;void Start(){mesh=readPlane.GetComponent<MeshFilter>
().mesh;Vector3[] ve=
mesh.vertices;print(ve[1]+
"\\"+ve[
3]);
//readPlane最左邊兩個(gè)點(diǎn)blueBoundPlane=
bluePlane.gameObject.collider.bounds;blueBoundMin=
blueBoundPlane.min;blueBoundMax=
blueBoundPlane.max;print(blueBoundMin+
"||||"+blueBoundMax+
"|||"+blueBoundPlane.size+
"|||||"+
blueBoundPlane.center);}void Update(){if(Input.GetMouseButton(
0)){readBoundPlane=readPlane.GetComponent<BoxCollider>
().bounds;if(readBoundPlane.min.x<blueBoundMin.x)
//包圍盒最小坐標(biāo)x超出blue的最小坐標(biāo)開(kāi)始裁剪
{Vector3[] vec3=
mesh.vertices;Vector3 vec3local=(readPlane.worldToLocalMatrix*
new Vector3(readBoundPlane.min.x-blueBoundMin.x,
0,
0));
//因?yàn)閏ollider.bounds.min是世界坐標(biāo),mesh.vertices是本地坐標(biāo)所以需要世界到本地的轉(zhuǎn)化vec3[
1]=
new Vector3(mesh.bounds.min.x-vec3local.x,vec3[
1].y,vec3[
1].z);vec3[3]=
new Vector3(mesh.bounds.min.x-vec3local.x,vec3[
3].y,vec3[
3].z);Vector2[] uvs=
new Vector2[vec3.Length];for(
int i=
0;i<vec3.Length;i++
){if(i%
2!=
0){uvs[i]=
new Vector2(((readBoundPlane.min.x-blueBoundMin.x)+readBoundPlane.size.x)/readBoundPlane.size.x,mesh.uv[i].y);
//更新UV
}else{uvs[i]=
new Vector2(mesh.uv[i].x,mesh.uv[i].y);}}mesh.uv=
uvs;mesh.vertices=
vec3;}if(readBoundPlane.max.x<=
blueBoundMin.x){readPlane.GetComponent<MeshRenderer>().enabled=
false;}if(readBoundPlane.max.x>
blueBoundMin.x){readPlane.GetComponent<MeshRenderer>().enabled=
true;}float x=Input.GetAxis(
"Mouse X");float y=Input.GetAxis(
"Mouse Y");readPlane.position+=
new Vector3(x,y,
0);}} ?
???最終效果圖:
?
轉(zhuǎn)載于:https://www.cnblogs.com/U-tansuo/archive/2012/07/11/2587151.html
總結(jié)
以上是生活随笔為你收集整理的【原】Unity3D 窗口裁剪的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。