Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //so for example, the texture sampler is this
- public static Color SampleTextureColour(RaycastHit hit) // Creates a material instance wtf?
- {
- Renderer rend = hit.transform.GetComponent<Renderer>();
- MeshCollider meshCollider = hit.collider as MeshCollider;
- Color colour = Color.white;
- if (rend == null || rend.sharedMaterial == null || meshCollider == null)
- return colour;
- if (rend.material.HasProperty("_ColourTint"))
- colour = rend.material.GetColor("_ColourTint");
- return colour;
- }
- //and the vertex colour sampler is this
- public static Color SampleVertexColour(RaycastHit hit) //creates a mesh instance wtf??
- {
- Transform objectHit = hit.transform;
- MeshCollider hitCollider = objectHit.GetComponent<MeshCollider>();
- if (hitCollider == null)
- return Color.grey;
- MeshFilter meshFilter = objectHit.GetComponent<MeshFilter>();
- if (meshFilter == null)
- return Color.grey;
- Mesh _mesh = meshFilter.mesh;
- if (_mesh == null)
- return Color.grey;
- Renderer _renderer = objectHit.GetComponent<Renderer>();
- if (!_renderer.isPartOfStaticBatch)
- {
- int[] triangles = _mesh.triangles;
- Color[] hitColors = _mesh.colors;
- if (hitColors.Length != 0)
- {
- //Vertex indices
- int t1 = triangles[(hit.triangleIndex * 3) + 0];
- int t2 = triangles[(hit.triangleIndex * 3) + 1];
- int t3 = triangles[(hit.triangleIndex * 3) + 2];
- //Colors
- Color c1 = hitColors[t1];
- Color c2 = hitColors[t2];
- Color c3 = hitColors[t3];
- Vector3 b = hit.barycentricCoordinate;
- var sampleColor = c1 * b.x + c2 * b.y + c3 * b.z;
- return sampleColor;
- }
- }
- return Color.grey;
- }
Advertisement
Add Comment
Please, Sign In to add comment