Esempio n. 1
0
 public void EnforceStream()
 {
     if (_stream == null && renderer != null && meshFilter != null)
     {
         _stream = meshFilter.gameObject.AddComponent <VertexInstanceStream>();
     }
 }
Esempio n. 2
0
 public PaintJob(MeshFilter mf, Renderer r)
 {
     meshFilter = mf;
     renderer   = r;
     _stream    = r.gameObject.GetComponent <VertexInstanceStream>();
     verts      = mf.sharedMesh.vertices;
     normals    = mf.sharedMesh.normals;
     tangents   = mf.sharedMesh.tangents;
     // optionally defer this unless the brush is set to position..
     InitMeshConnections();
 }
        public static Mesh BakeDownMesh(Mesh mesh, VertexInstanceStream stream)
        {
            var copy = GameObject.Instantiate(mesh);

            copy.colors = stream.colors;
            if (stream.uv0 != null && stream.uv0.Count > 0)
            {
                copy.SetUVs(0, stream.uv0);
            }

            if (stream.uv1 != null && stream.uv1.Count > 0)
            {
                copy.SetUVs(1, stream.uv1);
            }

            if (stream.uv2 != null && stream.uv2.Count > 0)
            {
                copy.SetUVs(2, stream.uv2);
            }

            if (stream.uv3 != null && stream.uv3.Count > 0)
            {
                copy.SetUVs(3, stream.uv3);
            }

            if (stream.positions != null && stream.positions.Length == copy.vertexCount)
            {
                copy.vertices = stream.positions;
            }
            if (stream.normals != null && stream.normals.Length == copy.vertexCount)
            {
                copy.normals = stream.normals;
            }
            if (stream.tangents != null && stream.tangents.Length == copy.vertexCount)
            {
                copy.tangents = stream.tangents;
            }
            copy.RecalculateBounds();
            copy.UploadMeshData(false);
            return(copy);
        }
Esempio n. 4
0
        public override void BeginApplyStroke(Ray ray)
        {
            Vector3 bary = Vector3.zero;
            VertexInstanceStream stream = null;

            didHit = false;
            Mesh  best     = null;
            int   triangle = 0;
            float distance = float.MaxValue;

            if (streams != null)
            {
                for (int i = 0; i < streams.Length; ++i)
                {
                    Matrix4x4 mtx = streams[i].transform.localToWorldMatrix;
                    Mesh      msh = streams[i].GetComponent <MeshFilter>().sharedMesh;

                    RaycastHit hit;
                    RXLookingGlass.IntersectRayMesh(ray, msh, mtx, out hit);
                    if (hit.distance < distance)
                    {
                        distance = hit.distance;
                        bary     = hit.barycentricCoordinate;
                        best     = msh;
                        triangle = hit.triangleIndex;
                        stream   = streams[i];
                        didHit   = true;
                    }
                }
            }
            if (didHit && best != null)
            {
                var triangles = best.triangles;
                int i0        = triangles[triangle];
                int i1        = triangles[triangle + 1];
                int i2        = triangles[triangle + 2];

                normal  = stream.GetSafeNormal(i0) * bary.x + stream.GetSafeNormal(i1) * bary.y + stream.GetSafeNormal(i2) * bary.z;
                tangent = stream.GetSafeTangent(i0) * bary.x + stream.GetSafeTangent(i1) * bary.y + stream.GetSafeTangent(i2) * bary.z;
            }
        }