日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【原】Unity3D 窗口裁剪

發布時間:2025/3/13 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【原】Unity3D 窗口裁剪 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

實現效果 拖動readplane 當包圍盒最小點超出bluePlane的最小點時(僅做了左邊裁剪),對超出部分裁剪,當全部超出隱藏readPlane 當readPlane包圍盒的最大坐標點大于bluePlane的最小點時,顯示readPlane;

閱讀此文時,讀者最好具備世界坐標 本地坐標 bounds 等之類的知識!
collider.bounds、render.bounds的min max是世界坐標,size是大小? mesh.bounds是本地坐標。mesh.vertices對線框頂點坐標更改。
???

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最左邊兩個點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)//包圍盒最小坐標x超出blue的最小坐標開始裁剪 {Vector3[] vec3=mesh.vertices;Vector3 vec3local=(readPlane.worldToLocalMatrix*new Vector3(readBoundPlane.min.x-blueBoundMin.x,0,0));//因為collider.bounds.min是世界坐標,mesh.vertices是本地坐標所以需要世界到本地的轉化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);}}

?

???最終效果圖:

?

轉載于:https://www.cnblogs.com/U-tansuo/archive/2012/07/11/2587151.html

總結

以上是生活随笔為你收集整理的【原】Unity3D 窗口裁剪的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。