Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
RaycastHit.barycentricCoordinate 重心坐标
# [RaycastHit](RaycastHit.html).barycentricCoordinate 重心坐标 var *barycentricCoordinate* : [Vector3](../Vector3/Vector3.html) *Description* 描述 The barycentric coordinate of the triangle we hit. 所碰到的三角形的重心坐标。 This lets you interpolate any of the vertex data along the 3 axes. 这允许你沿着 3 个轴插值任何顶点数据。 ``` // Attach this script to a camera and it will // draw a debug line pointing outward from the normal //附加这个脚本到相机,它将绘制一条从法线指出的调试直线 function Update () { // Only if we hit something, do we continue //只有当碰到了什么东西,继续 var hit : RaycastHit; if (!Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), hit)) return; // Just in case, also make sure the collider also has a renderer // material and texture //以防万一,确保碰撞器也有一个渲染器、材质和纹理 var meshCollider = hit.collider as MeshCollider; if (meshCollider == null || meshCollider.sharedMesh == null) return; var mesh : Mesh = meshCollider.sharedMesh; var normals = mesh.normals; var triangles = mesh.triangles; // Extract local space normals of the triangle we hit //取得所碰到三角形的本地法线 var n0 = normals[triangles[hit.triangleIndex * 3 + 0]]; var n1 = normals[triangles[hit.triangleIndex * 3 + 1]]; var n2 = normals[triangles[hit.triangleIndex * 3 + 2]]; // interpolate using the barycentric coordinate of the hitpoint //使用碰撞点的重心坐标来插值 var baryCenter = hit.barycentricCoordinate; // Use barycentric coordinate to interpolate normal //使用重心坐标插值法线 var interpolatedNormal = n0 * baryCenter.x + n1 * baryCenter.y + n2 * baryCenter.z; // normalize the interpolated normal //规范化插值法线 interpolatedNormal = interpolatedNormal.normalized; // Transform local space normals to world space //变换本地法线到世界空间 var hitTransform : Transform = hit.collider.transform; interpolatedNormal = hitTransform.TransformDirection(interpolatedNormal); // Display with Debug.DrawLine //显示调试线 Debug.DrawRay(hit.point, interpolatedNormal); } ```
da
2022年5月23日 14:26
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码