Inheritance: UnityEngine.MonoBehaviour
Exemple #1
0
 public void EnforceStream()
 {
     if (_stream == null && renderer != null && meshFilter != null)
     {
         _stream = meshFilter.gameObject.AddComponent <VertexInstanceStream>();
     }
 }
        // copy a mesh, and bake it's vertex stream into the mesh data.
        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.Optimize();
             copy.RecalculateBounds();
             copy.UploadMeshData(false);

             return copy;
        }
Exemple #3
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();
 }
Exemple #4
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();
 }
Exemple #5
0
        // copy a mesh, and bake it's vertex stream into the mesh data.
        Mesh BakeDownMesh(Mesh mesh, VertexInstanceStream stream)
        {
            var copy = Instantiate(mesh);

            /*
             * foreach(var property in typeof(Mesh).GetProperties())
             * {
             * if(property.GetSetMethod() != null && property.GetGetMethod() != null)
             * {
             *    property.SetValue(copy, property.GetValue(mesh, null), null);
             * }
             * }
             * copy.hideFlags = 0;
             */

            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.Optimize();
            copy.RecalculateBounds();
            copy.UploadMeshData(false);

            return(copy);
        }
Exemple #6
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;
            }
        }
Exemple #7
0
        // copy a mesh, and bake it's vertex stream into the mesh data.
        public static Mesh BakeDownMesh(Mesh mesh, VertexInstanceStream stream)
        {
            var copy = GameObject.Instantiate(mesh);

            if (stream.colors != null && stream.colors.Length > 0)
            {
                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);
        }
        // copy a mesh, and bake it's vertex stream into the mesh data.
        Mesh BakeDownMesh(Mesh mesh, VertexInstanceStream stream)
        {
            var copy = new Mesh();
             foreach(var property in typeof(Mesh).GetProperties())
             {
            if(property.GetSetMethod() != null && property.GetGetMethod() != null)
            {
               property.SetValue(copy, property.GetValue(mesh, null), null);
            }
             }
             copy.hideFlags = 0;

             copy.colors = stream.colors;
             if (stream.uv0 != null) { copy.SetUVs(0, stream.uv0); }
             if (stream.uv1 != null) { copy.SetUVs(1, stream.uv1); }
             if (stream.uv2 != null) { copy.SetUVs(2, stream.uv2); }
             if (stream.uv3 != null) { 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.Optimize();
             copy.RecalculateBounds();
             copy.UploadMeshData(false);

             return copy;
        }
Exemple #9
0
 // draw any custom GUI we want for this brush in the editor
 public override void DrawGUI()
 {
     target        = (VertexInstanceStream)EditorGUILayout.ObjectField("Blend w/ Mesh", target, typeof(VertexInstanceStream), true);
     terrainTarget = (Terrain)EditorGUILayout.ObjectField("Blend w/ Terrain", terrainTarget, typeof(Terrain), true);
 }
        Setter GetSetter(VertexInstanceStream s)
        {
            if (tab == Tab.Flow)
             {
            switch (flowTarget)
            {
               case FlowTarget.ColorRG:
                  return delegate(int idx, ref object v)
                  {
                     Vector2 vv = (Vector2)v;
                     s.colors[idx].r = vv.x;
                     s.colors[idx].g = vv.y;
                  };
               case FlowTarget.ColorBA:
                  return delegate(int idx, ref object v)
                  {
                     Vector2 vv = (Vector2)v;
                     s.colors[idx].b = vv.x;
                     s.colors[idx].a = vv.y;
                  };
               case FlowTarget.UV0_XY:
                  return delegate(int idx, ref object v)
                  {
                     Vector4 vec = s.uv0[idx];
                     Vector2 iv = (Vector2)v;
                     vec.x = iv.x;
                     vec.y = iv.y;
                     s.uv0[idx] = vec;
                  };
               case FlowTarget.UV0_ZW:
                  return delegate(int idx, ref object v)
                  {
                     Vector4 vec = s.uv0[idx];
                     Vector2 iv = (Vector2)v;
                     vec.z = iv.x;
                     vec.w = iv.y;
                     s.uv0[idx] = vec;
                  };
               case FlowTarget.UV1_XY:
                  return delegate(int idx, ref object v)
                  {
                     Vector4 vec = s.uv1[idx];
                     Vector2 iv = (Vector2)v;
                     vec.x = iv.x;
                     vec.y = iv.y;
                     s.uv1[idx] = vec;
                  };
               case FlowTarget.UV1_ZW:
                  return delegate(int idx, ref object v)
                  {
                     Vector4 vec = s.uv1[idx];
                     Vector2 iv = (Vector2)v;
                     vec.z = iv.x;
                     vec.w = iv.y;
                     s.uv1[idx] = vec;
                  };
               case FlowTarget.UV2_XY:
                  return delegate(int idx, ref object v)
                  {
                     Vector4 vec = s.uv2[idx];
                     Vector2 iv = (Vector2)v;
                     vec.x = iv.x;
                     vec.y = iv.y;
                     s.uv2[idx] = vec;
                  };
               case FlowTarget.UV2_ZW:
                  return delegate(int idx, ref object v)
                  {
                     Vector4 vec = s.uv2[idx];
                     Vector2 iv = (Vector2)v;
                     vec.z = iv.x;
                     vec.w = iv.y;
                     s.uv2[idx] = vec;
                  };
               case FlowTarget.UV3_XY:
                  return delegate(int idx, ref object v)
                  {
                     Vector4 vec = s.uv3[idx];
                     Vector2 iv = (Vector2)v;
                     vec.x = iv.x;
                     vec.y = iv.y;
                     s.uv3[idx] = vec;
                  };
               case FlowTarget.UV3_ZW:
                  return delegate(int idx, ref object v)
                  {
                     Vector4 vec = s.uv3[idx];
                     Vector2 iv = (Vector2)v;
                     vec.z = iv.x;
                     vec.w = iv.y;
                     s.uv3[idx] = vec;
                  };
            }
            return null;
             }
             switch (brushMode)
             {
            case BrushTarget.Color:
               return delegate(int idx, ref object v)
               {
                  s.colors[idx] = (Color)v;
               };
            case BrushTarget.ValueR:
               return delegate(int idx, ref object v)
               {
                  s.colors[idx].r = (float)v;
               };
            case BrushTarget.ValueG:
               return delegate(int idx, ref object v)
               {
                  s.colors[idx].g = (float)v;
               };
            case BrushTarget.ValueB:
               return delegate(int idx, ref object v)
               {
                  s.colors[idx].b = (float)v;
               };
            case BrushTarget.ValueA:
               return delegate(int idx, ref object v)
               {
                  s.colors[idx].a = (float)v;
               };
            case BrushTarget.UV0_X:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv0[idx];
                  vec.x = (float)v;
                  s.uv0[idx] = vec;
               };
            case BrushTarget.UV0_Y:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv0[idx];
                  vec.y = (float)v;
                  s.uv0[idx] = vec;
               };
            case BrushTarget.UV0_Z:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv0[idx];
                  vec.z = (float)v;
                  s.uv0[idx] = vec;
               };
            case BrushTarget.UV0_W:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv0[idx];
                  vec.w = (float)v;
                  s.uv0[idx] = vec;
               };
            case BrushTarget.UV1_X:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv1[idx];
                  vec.x = (float)v;
                  s.uv1[idx] = vec;
               };
            case BrushTarget.UV1_Y:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv1[idx];
                  vec.y = (float)v;
                  s.uv1[idx] = vec;
               };
            case BrushTarget.UV1_Z:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv1[idx];
                  vec.z = (float)v;
                  s.uv1[idx] = vec;
               };
            case BrushTarget.UV1_W:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv1[idx];
                  vec.w = (float)v;
                  s.uv1[idx] = vec;
               };
            case BrushTarget.UV2_X:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv2[idx];
                  vec.x = (float)v;
                  s.uv2[idx] = vec;
               };
            case BrushTarget.UV2_Y:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv2[idx];
                  vec.y = (float)v;
                  s.uv2[idx] = vec;
               };
            case BrushTarget.UV2_Z:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv2[idx];
                  vec.z = (float)v;
                  s.uv2[idx] = vec;
               };
            case BrushTarget.UV2_W:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv2[idx];
                  vec.w = (float)v;
                  s.uv2[idx] = vec;
               };
            case BrushTarget.UV3_X:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv3[idx];
                  vec.x = (float)v;
                  s.uv3[idx] = vec;
               };
            case BrushTarget.UV3_Y:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv3[idx];
                  vec.y = (float)v;
                  s.uv3[idx] = vec;
               };
            case BrushTarget.UV3_Z:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv3[idx];
                  vec.z = (float)v;
                  s.uv3[idx] = vec;
               };
            case BrushTarget.UV3_W:
               return delegate(int idx, ref object v)
               {
                  Vector4 vec = s.uv3[idx];
                  vec.w = (float)v;
                  s.uv3[idx] = vec;
               };

             }
             return null;
        }
        Lerper GetLerper(VertexInstanceStream s)
        {
            if (tab == Tab.Flow)
             {
            switch (flowTarget)
            {
               case FlowTarget.ColorRG:
                  return delegate(int idx, ref object v, float r)
                  {
                     Vector2 vv = (Vector2)v;
                     Color c = s.colors[idx];
                     s.colors[idx].r = Mathf.Lerp(c.r, vv.x, r);
                     s.colors[idx].g = Mathf.Lerp(c.g, vv.y, r);
                  };
               case FlowTarget.ColorBA:
                  return delegate(int idx, ref object v, float r)
                  {
                     Vector2 vv = (Vector2)v;
                     Color c = s.colors[idx];
                     s.colors[idx].b = Mathf.Lerp(c.r, vv.x, r);
                     s.colors[idx].a = Mathf.Lerp(c.g, vv.y, r);
                  };
               case FlowTarget.UV0_XY:
                  return delegate(int idx, ref object v, float r)
                  {
                     Vector4 o = s.uv0[idx];
                     Vector2 t = (Vector2)v;
                     o.x = Mathf.Lerp(o.x, t.x, r);
                     o.y = Mathf.Lerp(o.y, t.y, r);
                     s.uv0[idx] = o;
                  };
               case FlowTarget.UV0_ZW:
                  return delegate(int idx, ref object v, float r)
                  {
                     Vector4 o = s.uv0[idx];
                     Vector2 t = (Vector2)v;
                     o.z = Mathf.Lerp(o.z, t.x, r);
                     o.w = Mathf.Lerp(o.w, t.y, r);
                     s.uv0[idx] = o;
                  };
               case FlowTarget.UV1_XY:
                  return delegate(int idx, ref object v, float r)
                  {
                     Vector4 o = s.uv1[idx];
                     Vector2 t = (Vector2)v;
                     o.x = Mathf.Lerp(o.x, t.x, r);
                     o.y = Mathf.Lerp(o.y, t.y, r);
                     s.uv1[idx] = o;
                  };
               case FlowTarget.UV1_ZW:
                  return delegate(int idx, ref object v, float r)
                  {
                     Vector4 o = s.uv1[idx];
                     Vector2 t = (Vector2)v;
                     o.z = Mathf.Lerp(o.z, t.x, r);
                     o.w = Mathf.Lerp(o.w, t.y, r);
                     s.uv1[idx] = o;
                  };
               case FlowTarget.UV2_XY:
                  return delegate(int idx, ref object v, float r)
                  {
                     Vector4 o = s.uv2[idx];
                     Vector2 t = (Vector2)v;
                     o.x = Mathf.Lerp(o.x, t.x, r);
                     o.y = Mathf.Lerp(o.y, t.y, r);
                     s.uv2[idx] = o;
                  };
               case FlowTarget.UV2_ZW:
                  return delegate(int idx, ref object v, float r)
                  {
                     Vector4 o = s.uv2[idx];
                     Vector2 t = (Vector2)v;
                     o.z = Mathf.Lerp(o.z, t.x, r);
                     o.w = Mathf.Lerp(o.w, t.y, r);
                     s.uv2[idx] = o;
                  };
               case FlowTarget.UV3_XY:
                  return delegate(int idx, ref object v, float r)
                  {
                     Vector4 o = s.uv3[idx];
                     Vector2 t = (Vector2)v;
                     o.x = Mathf.Lerp(o.x, t.x, r);
                     o.y = Mathf.Lerp(o.y, t.y, r);
                     s.uv3[idx] = o;
                  };
               case FlowTarget.UV3_ZW:
                  return delegate(int idx, ref object v, float r)
                  {
                     Vector4 o = s.uv3[idx];
                     Vector2 t = (Vector2)v;
                     o.z = Mathf.Lerp(o.z, t.x, r);
                     o.w = Mathf.Lerp(o.w, t.y, r);
                     s.uv3[idx] = o;
                  };
            }
            return null;
             }
             switch (brushMode)
             {
            case BrushTarget.Color:
               return delegate(int idx, ref object v, float r)
               {
                  s.colors[idx] = Color.Lerp(s.colors[idx], (Color)v, r);
               };
            case BrushTarget.ValueR:
               return delegate(int idx, ref object v, float r)
               {
                  s.colors[idx].r = Mathf.Lerp(s.colors[idx].r, (float)v, r);
               };
            case BrushTarget.ValueG:
               return delegate(int idx, ref object v, float r)
               {
                  s.colors[idx].g = Mathf.Lerp(s.colors[idx].g, (float)v, r);
               };
            case BrushTarget.ValueB:
               return delegate(int idx, ref object v, float r)
               {
                  s.colors[idx].b = Mathf.Lerp(s.colors[idx].b, (float)v, r);
               };
            case BrushTarget.ValueA:
               return delegate(int idx, ref object v, float r)
               {
                  s.colors[idx].a = Mathf.Lerp(s.colors[idx].a, (float)v, r);
               };
            case BrushTarget.UV0_X:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv0[idx];
                  vec.x = Mathf.Lerp(vec.x, (float)v, r);
                  s.uv0[idx] = vec;
               };
            case BrushTarget.UV0_Y:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv0[idx];
                  vec.y = Mathf.Lerp(vec.y, (float)v, r);
                  s.uv0[idx] = vec;
               };
            case BrushTarget.UV0_Z:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv0[idx];
                  vec.z = Mathf.Lerp(vec.z, (float)v, r);
                  s.uv0[idx] = vec;
               };
            case BrushTarget.UV0_W:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv0[idx];
                  vec.w = Mathf.Lerp(vec.w, (float)v, r);
                  s.uv0[idx] = vec;
               };
            case BrushTarget.UV1_X:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv1[idx];
                  vec.x = Mathf.Lerp(vec.x, (float)v, r);
                  s.uv1[idx] = vec;
               };
            case BrushTarget.UV1_Y:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv1[idx];
                  vec.y = Mathf.Lerp(vec.y, (float)v, r);
                  s.uv1[idx] = vec;
               };
            case BrushTarget.UV1_Z:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv1[idx];
                  vec.z = Mathf.Lerp(vec.z, (float)v, r);
                  s.uv1[idx] = vec;
               };
            case BrushTarget.UV1_W:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv1[idx];
                  vec.w = Mathf.Lerp(vec.w, (float)v, r);
                  s.uv1[idx] = vec;
               };
            case BrushTarget.UV2_X:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv2[idx];
                  vec.x = Mathf.Lerp(vec.x, (float)v, r);
                  s.uv2[idx] = vec;
               };
            case BrushTarget.UV2_Y:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv2[idx];
                  vec.y = Mathf.Lerp(vec.y, (float)v, r);
                  s.uv2[idx] = vec;
               };
            case BrushTarget.UV2_Z:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv2[idx];
                  vec.z = Mathf.Lerp(vec.z, (float)v, r);
                  s.uv2[idx] = vec;
               };
            case BrushTarget.UV2_W:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv2[idx];
                  vec.w = Mathf.Lerp(vec.w, (float)v, r);
                  s.uv2[idx] = vec;
               };
            case BrushTarget.UV3_X:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv3[idx];
                  vec.x = Mathf.Lerp(vec.x, (float)v, r);
                  s.uv3[idx] = vec;
               };
            case BrushTarget.UV3_Y:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv3[idx];
                  vec.y = Mathf.Lerp(vec.y, (float)v, r);
                  s.uv3[idx] = vec;
               };
            case BrushTarget.UV3_Z:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv3[idx];
                  vec.z = Mathf.Lerp(vec.z, (float)v, r);
                  s.uv3[idx] = vec;
               };
            case BrushTarget.UV3_W:
               return delegate(int idx, ref object v, float r)
               {
                  Vector4 vec = s.uv3[idx];
                  vec.w = Mathf.Lerp(vec.w, (float)v, r);
                  s.uv3[idx] = vec;
               };

             }
             return null;
        }
Exemple #12
0
 public void EnforceStream()
 {
     if (_stream == null && renderer != null && meshFilter != null)
      {
     _stream = meshFilter.gameObject.AddComponent<VertexInstanceStream>();
      }
 }