RaycastHit.triangleIndex 三角形索引
var triangleIndex : int
Description描述
The index of the triangle that was hit.
碰到的三角形的索引。
Triangle index is only valid if the collider that was hit is a MeshCollider.
如果被碰到的碰撞器是一个MeshCollider三角形索引才可用。
// Attach this script to a camera and it will
// draw a debug line triangle triangle
// at the triangle where you place the mouse.
//附加这个脚本到相机然后它将绘制一个调试直线三角形,在放置鼠标的三角形上
function Update () {
// Only if we hit something, do we continue
//如果碰到了什么东西,继续
var hit : RaycastHit;
if (!Physics.Raycast (camera.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 vertices = mesh.vertices;
var triangles = mesh.triangles;
// Extract local space vertices that were hit
//取回碰到的本地坐标点
var p0 = vertices[triangles[hit.triangleIndex * 3 + 0]];
var p1 = vertices[triangles[hit.triangleIndex * 3 + 1]];
var p2 = vertices[triangles[hit.triangleIndex * 3 + 2]];
// Transform local space vertices to world space
//变换本地空间点到世界空间
var hitTransform : Transform = hit.collider.transform;
p0 = hitTransform.TransformPoint(p0);
p1 = hitTransform.TransformPoint(p1);
p2 = hitTransform.TransformPoint(p2);
// Display with Debug.DrawLine
//显示调试线
Debug.DrawLine(p0, p1);
Debug.DrawLine(p1, p2);
Debug.DrawLine(p2, p0);
}
参见:Physics.Raycast, Physics.Linecast, Physics.RaycastAll.
最后修改:2011年5月16日 Monday 21:15