コード例 #1
0
        public Vector3 CalcBarycentricCoords(Vector3 point)
        {
            Vector3 result;

            Triangle3.CalcBarycentricCoords(ref point, ref this.V0, ref this.V1, ref this.V2, out result);
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Sampples an array of random points on the surface. Users can provide additional parameters for sampling.
        /// Sample map controls the chance of sampling (texture is read from r channel), where white gives maximum chance
        /// and black gives no chance. To read the texture an array of uv coordinates is used. It's also possible to
        /// explicitly set additional range of chances (so that if sample map has gradient from 0 to 1, then adding
        /// min to 0.5 will result in no samples generated in areas with color &lt;= 0.5). Notice that in this function
        /// count is upper bound of samples to generate, resulting array may have less samples due to some samples
        /// being rejected according to sample map.
        /// </summary>
        public Vector3[] SampleArray(int count, Vector2[] uvs, Texture2D sampleMap, float min = 0f, float max = 1f)
        {
            Vector3[] temp = new Vector3[count];
            int       c    = 0;

            for (int i = 0; i < count; ++i)
            {
                int     index = SampleIndex() * 3;
                int     i0    = _indices[index];
                int     i1    = _indices[index + 1];
                int     i2    = _indices[index + 2];
                Vector3 v0    = _vertices[i0];
                Vector3 v1    = _vertices[i1];
                Vector3 v2    = _vertices[i2];
                Vector3 vec   = _rand.InTriangle(ref v0, ref v1, ref v2);
                Vector3 bary;
                Triangle3.CalcBarycentricCoords(ref vec, ref v0, ref v1, ref v2, out bary);
                Vector2 uv     = uvs[i0] * bary.x + uvs[i1] * bary.y + uvs[i2] * bary.z;
                float   factor = sampleMap.GetPixelBilinear(uv.x, uv.y).r;
                if (min <= factor && factor <= max && _rand.NextFloat() < factor)
                {
                    temp[c] = vec;
                    ++c;
                }
            }
            Vector3[] result = new Vector3[temp.Length];
            System.Array.Copy(temp, result, temp.Length);
            return(result);
        }
コード例 #3
0
 public static Vector3 CalcAnglesRad(Vector3 v0, Vector3 v1, Vector3 v2)
 {
     return(Triangle3.CalcAnglesRad(ref v0, ref v1, ref v2));
 }