コード例 #1
0
    void PaintRayAll(Vector3 pos, Vector3 dir)
    {
        // Paint all places where this ray hits paintable objects

        RaycastHit     hit;
        List <Vector3> hitList = new List <Vector3>();
        GameObject     gObject = null;

        // Forward pass: record hits (ray enters surface) and paint them
        while (Physics.Raycast(pos, dir, out hit, maxDist, layerMask))
        {
            GameObject g = hit.transform.gameObject;
            gObject = g;
            pt.PaintUV(g, hit.textureCoord);
            hitList.Add(hit.point);
            pos = hit.point + 0.001f * dir; // move slightly forward of latest hit
        }

        // Backward pass: Detect surface exits and paint them
        if (hitList.Count != 0)
        {
            Vector3 backHitStart = hitList[hitList.Count - 1] + (maxForward * dir);
            hitList.Add(backHitStart);
            hitList.Reverse();
            for (int i = 0; i < hitList.Count; i++)
            {
                if (Physics.Raycast(hitList[i], (-1 * dir), out hit, maxDist, layerMask))
                {
                    pt.PaintUV(gObject, hit.textureCoord);
                }
            }
        }
    }
コード例 #2
0
ファイル: StickBehavior.cs プロジェクト: knut0815/genusview
    void PaintFirstHit()
    {
        // Local "up"
        var        raydir = transform.TransformDirection(Vector3.up);
        RaycastHit hit;

        // Cast a ray in direction "up", deteremine what paintable is first hit.
        if (Physics.Raycast(transform.position, raydir, out hit, maxDist, layerMask))
        {
            GameObject g = hit.transform.gameObject;

            if (pt != null)
            {
                // Paint on the shared PaintableTexture at the (u,v) coordinates
                // of the point where the ray met the object.
                pt.PaintUV(g, hit.textureCoord);
            }
        }
    }