Unity mirroring a mesh but the colors are facing down - unity3d

I am trying to mirror a mesh to another mesh by using procedural mesh generation as seen below. The original mesh is at the positive z axis while the mirrored is at the negative z axis.
The vertices are all mirrored as I wanted but the color is facing down instead of up.
I tried to change the mesh uvs and normals but both did no affect on the mirrored mesh. I heard the triangles have to be reversed in their array or something that I do not understand. How do I make the mirrored mesh color face up?
The black plane is supposed to be half transparent blue water plane but it is not part of my question so I guess do not mind it.

Not 100% sure but I suspect it is the triangles as you say.
You would probably simply need to invert the triangles => simply invert the array e.g. using Array.Reverse like e.g.
var triangles = mirroredMesh.triangles;
Array.Reverse(triangles);
mirroredMesh.triangles = triangles;

Related

3d vectors from a Unity Plane to a flat 2D point as a pixel on a texture

If I had a sharp sword and I were to perfectly slice an object in half, I would like to sample the colours at various points along this flat, freshly cut face, and place these colours on a texture.
Imagine the face is a Unity Plane defined by its Vector3 normal that goes through a location Vector3 p.
Let the texture be a 100 x 100 sized image.
Lets say the samples I want to take are three 3D points all on this plane, and defined as Vector3 A, B and C.
How do I go about converting the 3D points (x,y,z) from the defined plane into a 2D pixel (x,y) of this texture?
I have read many similar questions but honestly could not understand the answers. I don't know in my scenario if I'm dealing with Orthographic vs Projection perspective, whether I need to create a "conversion matrix", whether I need be concerned about rotations, or if there is just a simpler solution.
I appreciate any tips or suggestions. Thanks

How to set direction of arrows in shadergraph

I'm pretty new to shader graph and shaders in general. I'm working on a 2D project and I'm trying to make a shader that rotates an arrow to make a flow-like material and use it on a sprite shape.
Basically what I want to do is make a proper version of this:
What I'm currently doing is multiplying the Y position of the position node by an exposed vector 1 and using it in Rotate node (which I know is pretty hacky and won't work if the shape is not an arc.)
Aligning UV with arbitrary mesh seems bit hard. Why not bend pre-made mesh instead? Graph below bends vertex positions around axis Z at given point and strength (0 makes mesh invisible tho), but, you can easily replace that Position node with UV and plug results into Sample Texture 2D. I just guess bending a mesh will give you better/easier results.
Create a subdivided and well UV-mapped rectangle plane
Bend that plane with a vertex shader (attached graph bends around Z axis)
graph is based on code from Blender source

Rotate vertices selected using weight map on UVs in Unity3D's Shader Graph around pivot point

TLDR: Can't figure out the correct Shader Graph setup for using UV and vertex displacement to cheaply animate a (unrigged) mesh.
I am trying to rotate a part of the mesh based on the UV coordinates, e.g: fromX 0 toX 0.4, fromY 0 toY 0.6. The mesh is created uv-mapped with this in mind.
I have no problem getting the affected vertices in this area. Problem is that I want to rotate these verts for customizable axis e.g. axis(X:1, Y:0, Z:1) using a weight so that the rotation takes place around a pivoted point. I want the bottom selection to stay connected to the rest of the mesh while the other affected vertices neatly rotate around this point.
The weight can be painted by using split UV channels as seen in the picture:
I multiply the weighted area with a rotation node to rotate it.
And I add that to the negative multiplied position (the rest of the verts, excluding the rotated area) to get the final output displacement.
But the rotated mesh is bent. I need it to be stiff as in the whole part rotated with weight=1 except for the very pivoting vertex.
I can get it as described using a weight=1 based rotation, but the pivot point becomes the center of the mesh, not the desired point.
How can I do this correctly?
Been at it for days, please help :')
I started using Unity about a month ago, and this is one of the first issues I faced.
The node you are using will always transform the vertices around the origin.
I think you have two options available:
Translate the vertices by the offset of where you want to rotate the wings. This would require storing the pivot point of the wings in the mesh somehow - This could done by utilizing a spare UV channel, or by using the vertex color channel.
Use bones and paint the weights in your chosen 3D package. This way, you can record the animation, and use Unity's skinned mesh shader to render it.
Hope that helps.
Try this:
I've used the UV ranges from your example applied to a sphere of unit size. The spheres original pivot is in the centre, and its adjusted pivot is shifted 0.5 on the Y axis.
The only variable the shader doesn't know, is the adjusted pivot position; so I pass this through the material.
I've not implemented your weight in the graph, as I just wanted to show you the process. You can easily plug that in.
The color output is just being used for debug purposes.
The first image is with the default object pivot.
The second image is with the adjusted pivot.
The final image is the graph. (Note the logic group is driving the vertex rotation based on the UV mask).

Changing the position of the vertices in a plane

Is it possible to change the positions of the corners of an SCNPlane? Or do I have to make a custom plane to change the positions of its vertices?
EDIT:
So i have a SCNPlane or a custom created plane, and i want to atleast print the coordinates of the vertices that the plane has.
For simple effects, you can effectively change the plane's corners by using the plane's transform matrix. You can do more complex effects with a shader modifier (see SCNShadable) or a morpher (see SCNMorpher). What effect are you trying to achieve?

reduce vertices and triangles for plane made with unity

I am creating a plane using unity. The thing is that this plane has 200 triangles and 100+ vertices. Because my plane is not altered( i only set a texture on it), i think that the plane should have 2 triangles and 4 vertices. Can this be done?
UPDATE:
i think i need to change the mesh filter for my plane. I've created one with only 4 vertices in blender, but after i delete the original plane mesh in unity and place the new 4-vertices mesh, i only get a color that can be found on my texture, but not the texture itself. Can i place a texture on a 4 vertices mesh? if so, what am i doing wrong?
Using a 4 vertices/2 triangles planes should work, and is also a good idea :-)
It's probably only showing part of the texture because it has some wrong UV coordinates.
Try using this plane:
https://dl.dropbox.com/u/4375689/Permanent/Plane.3DS
I'm not sure if the size is correct, but it should have the correct UV coordinates.
That is right, the default Unity plane has more than 2 tris and 4 vertices. To have such a mesh you need to either import it or create it in code.
I've built this script called ProceduralPlane that allows you to set the number of segments in the editor: https://github.com/doukasd/Unity-Components/tree/master/UnityPackages