- Home /
Vertex Material add Burn Mark on Hit
Hi:
I am very new on the the UVs and meshes Vertices and colors topic. So I need to achieve the following. I have a scene with a Single Model. The model has a Vertex Colored Shader Material with a single texture over it. I have a code that allows you to place a flame sprite over the model where you actually place the flame. I have the code that allows the player to drag the flame over the model and adds burn physics to the flame and the model, I have also placed some nice burning sound. However, Im not sure about how to achieve the following: burn the material where the flame hit occurred, by changing the vertex colors of the mesh only on the spot where the flame was burning. I know that I have to change the color Array of the mesh, but I dont know how to get the specific "polygons" or "area" where the hit actually took place. Does anyone know a resource that I can refer to learn how to do this?
Thanks a lot.
Another important thing is that needs to be an "Area burn"... not just changing the color of specific pixel point. Thanks a lot again
If your model isn't a Skinned$$anonymous$$esh you can try to apply a decal. If you download the free asset Bootcamp from the store there is a simple decal system, that build a decal mesh on the fly based on the collision of the object hit and apply a decal texture. But if your model is a Skinned$$anonymous$$esh you can't do that as the decal would need to be rigged within the bone hierarchy of the mesh.
Alternatively to paint the vertcies you can do with a raycast, fire a a raycast toward the mesh from the flame, and from the raycast try to find the nearest vertices of the hit point, then build an array from what can be found and color them.
Check this for further info on this second method:
http://answers.unity3d.com/questions/43415/finding-the-polygonface-youre-currently-looking-at.html
You do a Physics.Raycast() or a Collider.Raycast() to the point of the flame. The RaycastHit structure returns a RaycastHit.triangleindex. This index allows you to find the three vertices of the triangle hit by the raycast. There are sample source on the reference page for finding vertices from the RaycastHit.triangleindex. Since there is a one-to-one correspondence between vertices and vertex colors, the same logic finds the the colors in the color array:
var c0 = colors[triangles[hit.triangleIndex * 3 + 0]];
var c1 = colors[triangles[hit.triangleIndex * 3 + 1]];
var c2 = colors[triangles[hit.triangleIndex * 3 + 2]];
This answer implies that the mesh are components of the same game object right?, thanks so much, but it is not the case.
I have been struggling with this solution, but heres some important factor: the mesh and the colliders are different game objects. I have a gameobject that has the whole mesh of the model, and different colliders for each limb of my model (since it is a ragdoll). I have tried the second method, but the burning is not precise.
Your answer
Follow this Question
Related Questions
How to get the colors of the vertices in a mesh? [or average color of a triangle] 1 Answer
Graphics.DrawMesh - cannot set mesh color 0 Answers
change color of the selected triangles inside human chest 1 Answer
Mesh.colors returns zero 1 Answer
How I can get InteractiveCloth vertices and apply to MeshFilter 0 Answers