RaycastHit.textureCoord2 第二纹理坐标
var textureCoord2 : Vector2
Description描述
The secondary uv texture coordinate at the impact point.
碰撞点的第二个UV纹理坐标。
This can be used for 3D texture painting or drawing bullet marks. If the collider is not a mesh collider, Vector2.zero will be returned. If the mesh contains no secondary uv set, the uv of the primary uv set will be returned.
这个可用于3D纹理绘制或绘制弹痕。如果碰撞器时非网格碰撞器,将返回Vector2.zero。如果网格没有包含第二个uv集,主uv集将被返回。
// Attach this script to a camera and it will paint black pixels in 3D
// on whatever the user clicks. Make sure the mesh you want to paint
// on has a mesh collider attached.
//附加这个脚本到相机,当用户点击时
//它将在3D中绘制黑色的像素. 确保你想绘制的网格附加有一个网格碰撞器.
function Update () {
// Only when we press the mouse
//只有当按下鼠标
if (!Input.GetMouseButton (0))
return;
// 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. Also we should ignore primitive colliders.
//以防万一,还要确保碰撞器也有一个渲染器、材质和纹理.我们也应该忽略几何体碰撞器.
var renderer : Renderer = hit.collider.renderer;
var meshCollider = hit.collider as MeshCollider;
if (renderer == null || renderer.sharedMaterial == null ||
renderer.sharedMaterial.mainTexture == null || meshCollider == null)
return;
// Now draw a pixel where we hit the object
//在我们碰到的物体上,现在绘制一个像素
var tex : Texture2D = renderer.material.mainTexture;
var pixelUV = hit.textureCoord2;
pixelUV.x *= tex.width;
pixelUV.y *= tex.height;
tex.SetPixel(pixelUV.x, pixelUV.y, Color.black);
tex.Apply();
}
最后修改:2011年3月13日 Sunday 14:19