GetPosition() public method

public GetPosition ( int i ) : Vector3
i int
return UnityEngine.Vector3
コード例 #1
0
        void LerpFunc(PaintJob j, int idx, ref object val, float r)
        {
            if (didHit && j.stream.gameObject != target && target != null)
            {
                // convert from world space to local space
                Vector3 norm = j.stream.GetSafeNormal(idx);
                Vector4 tang = j.stream.GetSafeTangent(idx);

                var mtx = j.stream.transform.worldToLocalMatrix;
                var t   = tangent;
                t   = mtx.MultiplyVector(tangent);
                t.w = tangent.w;

                j.stream.normals[idx]  = Vector3.Lerp(norm, mtx.MultiplyVector(norm), r);
                j.stream.tangents[idx] = Vector4.Lerp(tang, t, r);
            }
            if (didHit && terrainTarget != null)
            {
                // retrieve our brush data and get the stream we're painting into

                Vector3 n = j.stream.normals[idx];
                Vector4 t = j.stream.tangents[idx];

                Vector3 pos = j.GetPosition(idx);

                Vector3 iNormal = terrainTarget.terrainData.GetInterpolatedNormal(pos.x, pos.z);
                iNormal = j.stream.transform.InverseTransformDirection(iNormal);

                j.stream.normals[idx] = Vector3.Lerp(n, iNormal, r);
                Vector3 tangentXYZ = Vector3.Cross(j.stream.normals[idx], new Vector3(0, 0, 1));
                Vector4 tangent    = new Vector4(tangentXYZ.x, tangentXYZ.y, tangentXYZ.z, -1);

                j.stream.tangents[idx] = Vector4.Lerp(t, tangent, r);
            }
        }
コード例 #2
0
        // this is the delegate we're going to return to apply a brush stamp. Your passed a paint job,
        // which contains important cached information to make painting fast, and hold the actual stream data.
        // the index is the index into the vertex array, the val is the brush data we supplied in GetBrushObject,
        // and r is a 0 to 1 with how far to tween the value towards the brush (brush pressure * deltatime)
        void LerpFunc(PaintJob j, int idx, ref object val, float r)
        {
            // retrieve our brush data and get the stream we're painting into
            BrushData bd = val as BrushData;
            var       s  = j.stream;
            // use our vertex position to generate noise. We use the get position function because it will
            // return a vert position from the original meshes cached verticies or modified verticies if
            // we've modified them. This makes it compatible with deformations, etc.
            Vector3 pos = j.GetPosition(idx);

            // convert into world space
            pos = j.renderer.localToWorldMatrix.MultiplyPoint(pos);
            // scale by frequency
            pos.x *= bd.frequency;
            pos.y *= bd.frequency;
            pos.z *= bd.frequency;
            float noise = 0.5f * (0.5f * JBooth.VertexPainterPro.SimplexNoise.Noise.Generate(pos.x, pos.y, pos.z) + 0.5f);

            noise += 0.25f * (0.5f * JBooth.VertexPainterPro.SimplexNoise.Noise.Generate(pos.y * 2.031f, pos.z * 2.031f, pos.x * 2.031f) + 0.5f);
            noise += 0.25f * (0.5f * JBooth.VertexPainterPro.SimplexNoise.Noise.Generate(pos.z * 4.01f, pos.x * 4.01f, pos.y * 4.01f) + 0.5f);
            noise *= bd.amplitude;
            // lerp the noise in
            Color c = s.colors[idx];

            c.r = Mathf.Lerp(c.r, noise, r);
            c.g = Mathf.Lerp(c.g, noise, r);
            c.b = Mathf.Lerp(c.b, noise, r);

            s.colors[idx] = c;
        }
コード例 #3
0
        // this is the delegate we're going to return to apply a brush stamp. Your passed a paint job,
        // which contains important cached information to make painting fast, and hold the actual stream data.
        // the index is the index into the vertex array, the val is the brush data we supplied in GetBrushObject,
        // and r is a 0 to 1 with how far to tween the value towards the brush (brush pressure * deltatime)
        void LerpFunc(PaintJob j, int idx, ref object val, float r)
        {
            // retrieve our brush data and get the stream we're painting into
             BrushData bd = val as BrushData;
             var s = j.stream;
             // use our vertex position to generate noise. We use the get position function because it will
             // return a vert position from the original meshes cached verticies or modified verticies if
             // we've modified them. This makes it compatible with deformations, etc.
             Vector3 pos = j.GetPosition(idx);
             // convert into world space
             pos = j.renderer.localToWorldMatrix.MultiplyPoint(pos);
             // scale by frequency
             pos.x *= bd.frequency;
             pos.y *= bd.frequency;
             pos.z *= bd.frequency;
             float noise = 0.5f * (0.5f * JBooth.VertexPainterPro.SimplexNoise.Noise.Generate(pos.x, pos.y, pos.z) + 0.5f);
             noise += 0.25f * (0.5f * JBooth.VertexPainterPro.SimplexNoise.Noise.Generate(pos.y * 2.031f, pos.z * 2.031f, pos.x * 2.031f) + 0.5f);
             noise += 0.25f * (0.5f * JBooth.VertexPainterPro.SimplexNoise.Noise.Generate(pos.z * 4.01f, pos.x * 4.01f, pos.y * 4.01f) + 0.5f);
             noise *= bd.amplitude;
             // lerp the noise in
             Color c = s.colors[idx];
             c.r = Mathf.Lerp(c.r, noise, r);
             c.g = Mathf.Lerp(c.g, noise, r);
             c.b = Mathf.Lerp(c.b, noise, r);

             s.colors[idx] = c;
        }