Questions in topic: "triangles"
http://answers.unity.com/questions/topics/single/1360.html
The latest questions for the topic "triangles"How to Detect All Mesh Triangles Within a Given Area
http://answers.unity.com/questions/1732228/how-to-detect-all-mesh-triangles-within-a-given-ar.html
Hello - I'm looking for a way to detect all mesh triangles of a single mesh within a given area.
I've actually gotten this working, but ever method I've used is simply not performant enough - it totally crushes my framerate.
My current method of detection is to iterate through all mesh vertices and check their proximity to a RaycastHit.point on the mesh's surface.
When the icospherical mesh is sparse, as you can see in IcoPerformance_1.JPG, performance is good.
However, when the icospherical mesh becomes more dense, as you can see in IcoPerformance_2.JPG and IcoPerformance_3.JPG, performance simply tanks (as there are many more mesh vertices to iterate through).
Some other methods I've tried:
* SphereCast and SphereCastAll only register the first impact with the mesh; not all impacted triangles.
* I have tried casting a "cone" of RayCasts out to the surface of the mesh from the camera. This sortof works, but because of the nature of casting hundreds of individual rays, sometimes triangles get missed, especially small ones.
* All of my triangles are linked to an abstract icospherical model in code. This model's triangular faces all have adjacency data; I have tried doing an adjacency search, and this works correctly, but unfortunately it also tanks performance.
There has got to be some method of simply detecting all mesh triangles within an area that I'm missing. Thank you in advance!
IcoPerformance 1:
![alt text][1]
IcoPerformance 2:
![alt text][2]
IcoPerformance 3:
[1]: /storage/temp/159850-icoperformance-1.jpg
[2]: /storage/temp/159851-icoperformance-2.jpgraycastcollidermeshmeshestrianglesMon, 18 May 2020 20:36:46 GMTKeeganTawaRealtime mesh triangles do not appear depending on camera angle
http://answers.unity.com/questions/1719462/realtime-mesh-triangles-do-not-appear-depending-on.html
I am creating a mesh that is a cube with two vertices of the same edge removed. This makes it a prism. The problem is that after clearing the mesh then setting the new vertices and triangles, only half of the triangles appear at the same time. The other half appear when changing the scene camera's angle. Here are some screenshots to show the problem :
![alt text][1]
![alt text][2]
As you can see the triangle to the right does not appear in the first screenshot but appears through a missing triangle in the second screenshot. Here is my code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class createPrism : MonoBehaviour {
public Mesh mesh;
void Start () {
mesh = GetComponent<MeshFilter>().mesh;
Vector3[] vertices = {
new Vector3(-0.5f,-0.5f,-0.5f),
new Vector3(0.5f,-0.5f,-0.5f),
new Vector3(-0.5f,0.5f,-0.5f),
new Vector3(0.5f,0.5f,-0.5f),
new Vector3(-0.5f,-0.5f,0.5f),
new Vector3(0.5f,-0.5f,0.5f)
};
int[] triangles = {
0,1,2,
1,2,3,
0,1,4,
1,4,5,
2,3,4,
3,4,5,
1,5,3,
0,2,4
};
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
}
}
This is probably an easy fix but I couldn't find anything like this online.
[1]: /storage/temp/156885-screenshot-2020-04-17-at-123432.png
[2]: /storage/temp/156886-screenshot-2020-04-17-at-123442.pngmeshrenderingverticestriangles3d modelFri, 17 Apr 2020 11:09:43 GMTRER1200How to calculate internal angles of a mesh triangle?
http://answers.unity.com/questions/1704153/how-to-calculate-internal-angles-of-a-mesh-triangl.html
Hi Guys!
I'm trying to find the internal angles a, b and c of the triangle in the picture below. The red points form a triangle of a mesh.
I know the Vector3 positions of the red points and the normal of the triangle, but I don't know how to work out the angles between these points. How do I do this?
My triangle is below:
![alt text][1]
[1]: /storage/temp/153497-vla396goa6k41.pngmeshanglestrianglesMon, 02 Mar 2020 02:57:26 GMTIrishSenthilCombining two objects in Probuilder that their meshes overlap. - New user question
http://answers.unity.com/questions/1673336/combining-two-objects-in-probuilder-that-their-mes.html
I am trying to create a concert hall. I try to built the bars using two cylinders that one passes trough the other as in the picture I am posting. You can see the merged object in the Game view while in the Scene view I have deleted some meshes so that you can understand how they fit together.
The questions is:
- Is it alright to leave it like this? Is this going to affect the performance or disturb the material textures? The material will be a metal painted white.
- This combination will appear around 50 times in the scene, should I prefer to have a little of unused surface (meshes that are not visible)? Should I break it in pieces (creating many more triangles?)
I am a new user, if this question has appeared before please redirect me.
Thank you in advance!
![alt text][1]
[1]: /storage/temp/147752-steely.jpgobjectsmeshestrianglesmergingMon, 21 Oct 2019 14:17:41 GMTChiefmastoras1Problem creating submeshes based on raycast.
http://answers.unity.com/questions/1664887/problem-creating-submeshes-based-on-raycast.html
Hi everybody. So I've been stuck on this problem for days now. So I have a mesh imported from Blender (picture down below) that will act as the game map. What I want to do at the moment is:
- Shoot a raycast into the scene and get the triangle index with hit.triangleIndex
- I then calculate the longest edge of this triangle to know which 2 vertices are next to the triangle that will form a square.
- Then I call another method that takes this two vertices and finds the indices of them in the vertices array.
- A call to another method that finds the index of the triangle next to the one shot with raycast.
- Call to a method passing the 2 indices in the triangle list forming a square. This method is called highlight square.
Now if I wanted to delete the square I selected, then there is no problem, but if I decide to modify the a bit to move the selected square to a different submesh I run into all kinds of weird problems. I have tested multiple solutions but it breaks everytime, you name it I've seen it (freezing, outOfMemory, failed setting triangles, out of bounds, it works for the first square but when I click on another one a random square gets selected etc.).
So please guys help me out in figuring this out, if it's too complicated can you guys show me how to do this with combine meshes instead (basically separate the square I select from the mesh and then combine it to a different submesh)?
Maybe it has to do with my code, maybe with the vertices array being messed up, I have no clue.
Here is the code, pardon the mess, I've changed it more than 20 times.
![using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class cutHole : MonoBehaviour {
private int[] triangles;
private Vector3[] vertices;
private int[] oldTriangles;
private int[] newTriangles;
private Mesh mesh;
public Material[] mats;
private Renderer rend;
private List<int> testL;
// Use this for initialization
void Start () {
mesh = transform.GetComponent<MeshFilter>().mesh;
triangles = mesh.triangles;
vertices = mesh.vertices;
oldTriangles = triangles;
rend = GetComponent<Renderer>();
testL = new List<int>();
}
void highlightSquare (int index1, int index2)
{
int i = 0;
int j = 0;
Debug.Log(index1);
Debug.Log(index2);
Debug.Log(oldTriangles.Length);
Debug.Log(vertices.Length);
newTriangles = new int[oldTriangles.Length - 6];
while (j < oldTriangles.Length)
{
if (j != index1 * 3 && j != index2 * 3)
{
newTriangles[i++] = oldTriangles[j++];
newTriangles[i++] = oldTriangles[j++];
newTriangles[i++] = oldTriangles[j++];
}
else
{
testL.Add(j++);
testL.Add(j++);
testL.Add(j++);
//j += 3;
}
}
mesh.subMeshCount = 2;
foreach (int h in testL)
{
Debug.Log(h);
}
Debug.Log(vertices.Length);
Debug.Log(vertices.Length);
mesh.SetTriangles(newTriangles, 1);
//mesh.SetTriangles(testL, 0);
oldTriangles = newTriangles;
triangles = oldTriangles;
rend.materials = mats;
Debug.Log(mesh.subMeshCount);
}
/*void deleteSquare(int index1, int index2)
{
//Destroy(this.gameObject.GetComponent<MeshCollider>());
//Mesh mesh = transform.GetComponent<MeshFilter>().mesh;
//int[] oldTriangles = triangles;
//int[] newTriangles = new int[triangles.Length-6];
int i = 0;
int j = 0;
while (j < triangles.Length)
{
if(j != index1*3 && j != index2*3)
{
newTriangles[i++] = oldTriangles[j++];
newTriangles[i++] = oldTriangles[j++];
newTriangles[i++] = oldTriangles[j++];
}
else
{
j += 3;
}
}
triangles = newTriangles;
oldTriangles = triangles;
transform.GetComponent<MeshFilter>().mesh.triangles = newTriangles;
this.gameObject.AddComponent<MeshCollider>();
}*/
int findVertex(Vector3 v)
{
for(int i = 0; i < vertices.Length; i++)
{
if(vertices[i] == v)
return i;
}
Debug.Log("Not found");
return -1;
}
int findTriangle(Vector3 v1, Vector3 v2, int notTriIndex)
{
int i = 0;
int j = 0;
int found = 0;
while (j < triangles.Length)
{
if(j/3 != notTriIndex)
{
if(vertices[triangles[j]] == v1 && (vertices[triangles[j+1]] == v2 || vertices[triangles[j+2]] == v2))
return j/3;
else if(vertices[triangles[j]] == v2 && (vertices[triangles[j+1]] == v1 || vertices[triangles[j+2]] == v1))
return j/3;
else if(vertices[triangles[j+1]] == v2 && (vertices[triangles[j]] == v1 || vertices[triangles[j+2]] == v1))
return j/3;
else if(vertices[triangles[j+1]] == v1 && (vertices[triangles[j]] == v2 || vertices[triangles[j+2]] == v2))
return j/3;
}
j+=3;
}
return -1;
}
// Update is called once per frame
void Update ()
{
//Debug.Log(mesh.subMeshCount);
if(Input.GetMouseButtonDown(0))
{
Debug.Log(vertices.Length);
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, 1000.0f))
{
int hitTri = hit.triangleIndex;
//get neighbour
Vector3 p0 = vertices[triangles[hitTri * 3 + 0]];
Vector3 p1 = vertices[triangles[hitTri * 3 + 1]];
Vector3 p2 = vertices[triangles[hitTri * 3 + 2]];
float edge1 = Vector3.Distance(p0,p1);
float edge2 = Vector3.Distance(p0,p2);
float edge3 = Vector3.Distance(p1,p2);
Vector3 shared1;
Vector3 shared2;
if (edge1 > edge2 && edge1 > edge3)
{
shared1 = p0;
shared2 = p1;
}
else if(edge2 > edge1 && edge2 > edge3)
{
shared1 = p0;
shared2 = p2;
}
else
{
shared1 = p1;
shared2 = p2;
}
int v1 = findVertex(shared1);
int v2 = findVertex(shared2);
//deleteSquare(hitTri,findTriangle(vertices[v1], vertices[v2], hitTri));
highlightSquare(hitTri, findTriangle(vertices[v1], vertices[v2], hitTri));}
}
}
}][1]
[1]: /storage/temp/146057-map-unity.pngc#scripting problemraycastingverticestrianglesThu, 12 Sep 2019 09:53:59 GMTslythethieveDeleting square in Mesh really slow. Need help optimizing code.
http://answers.unity.com/questions/1664186/deleting-square-in-mesh-really-slow-need-help-opti.html
Hi everybody,
After following the great tutorial of holistic3d on how to delete a square on a mesh at runtime, I decided to add this functionality to my mesh. At the moment I don't really need this, what I need is an highlight of the square, but whatever.
While her script works just fine on small meshes like planes or cubes, on mine it takes about 2 seconds to delete a square. I think it has to do either on number of vertices (around 700k) or on how the code was written with multiple array assignments and modifications.
This is the code, can anybody help me in coming up with a more optimized solution that will run faster? Maybe parallel for loops?
Also could you guys help me out in modifying this, so the square I hit instead of being deleted, I can put a texture on it.
Thank you.
public class cutHole : MonoBehaviour {
private int triangleStripDown;
private int triangleStripUp;
private int[] triangles;
private Vector3[] vertices;
private int[] oldTriangles;
private int[] newTriangles;
private Mesh mesh;
// Use this for initialization
void Start () {
mesh = transform.GetComponent<MeshFilter>().mesh;
triangles = transform.GetComponent<MeshFilter>().mesh.triangles;
vertices = transform.GetComponent<MeshFilter>().mesh.vertices;
oldTriangles = triangles;
newTriangles = new int[triangles.Length - 6];
}
void highlightSquare (int index1, int index2)
{
}
void deleteSquare(int index1, int index2)
{
Destroy(this.gameObject.GetComponent<MeshCollider>());
//Mesh mesh = transform.GetComponent<MeshFilter>().mesh;
//int[] oldTriangles = triangles;
//int[] newTriangles = new int[triangles.Length-6];
int i = 0;
int j = 0;
while (j < triangles.Length)
{
if(j != index1*3 && j != index2*3)
{
newTriangles[i++] = oldTriangles[j++];
newTriangles[i++] = oldTriangles[j++];
newTriangles[i++] = oldTriangles[j++];
}
else
{
j += 3;
}
}
triangles = newTriangles;
oldTriangles = triangles;
transform.GetComponent<MeshFilter>().mesh.triangles = newTriangles;
this.gameObject.AddComponent<MeshCollider>();
}
int findVertex(Vector3 v)
{
//vertices = transform.GetComponent<MeshFilter>().mesh.vertices;
for(int i = 0; i < vertices.Length; i++)
{
if(vertices[i] == v)
return i;
}
Debug.Log("Not found");
return -1;
}
int findTriangle(Vector3 v1, Vector3 v2, int notTriIndex)
{
//triangles = transform.GetComponent<MeshFilter>().mesh.triangles;
//vertices = transform.GetComponent<MeshFilter>().mesh.vertices;
int i = 0;
int j = 0;
int found = 0;
while (j < triangles.Length)
{
if(j/3 != notTriIndex)
{
if(vertices[triangles[j]] == v1 && (vertices[triangles[j+1]] == v2 || vertices[triangles[j+2]] == v2))
return j/3;
else if(vertices[triangles[j]] == v2 && (vertices[triangles[j+1]] == v1 || vertices[triangles[j+2]] == v1))
return j/3;
else if(vertices[triangles[j+1]] == v2 && (vertices[triangles[j]] == v1 || vertices[triangles[j+2]] == v1))
return j/3;
else if(vertices[triangles[j+1]] == v1 && (vertices[triangles[j]] == v2 || vertices[triangles[j+2]] == v2))
return j/3;
}
j+=3;
}
return -1;
}
void deleteTri(int index)
{
Destroy(this.gameObject.GetComponent<MeshCollider>());
Mesh mesh = transform.GetComponent<MeshFilter>().mesh;
int[] oldTriangles = triangles;
int[] newTriangles = new int[triangles.Length-3];
int i = 0;
int j = 0;
while (j < mesh.triangles.Length)
{
if(j != index*3)
{
newTriangles[i++] = oldTriangles[j++];
newTriangles[i++] = oldTriangles[j++];
newTriangles[i++] = oldTriangles[j++];
}
else
{
j += 3;
}
}
transform.GetComponent<MeshFilter>().mesh.triangles = newTriangles;
triangles = newTriangles;
this.gameObject.AddComponent<MeshCollider>();
}
// Update is called once per frame
void Update ()
{
if(Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, 1000.0f))
{
int hitTri = hit.triangleIndex;
//get neighbour
//triangles = transform.GetComponent<MeshFilter>().mesh.triangles;
//vertices = transform.GetComponent<MeshFilter>().mesh.vertices;
Vector3 p0 = vertices[triangles[hitTri * 3 + 0]];
Vector3 p1 = vertices[triangles[hitTri * 3 + 1]];
Vector3 p2 = vertices[triangles[hitTri * 3 + 2]];
float edge1 = Vector3.Distance(p0,p1);
float edge2 = Vector3.Distance(p0,p2);
float edge3 = Vector3.Distance(p1,p2);
Vector3 shared1;
Vector3 shared2;
if(edge1 > edge2 && edge1 > edge3)
{
shared1 = p0;
shared2 = p1;
}
else if(edge2 > edge1 && edge2 > edge3)
{
shared1 = p0;
shared2 = p2;
}
else
{
shared1 = p1;
shared2 = p2;
}
int v1 = findVertex(shared1);
int v2 = findVertex(shared2);
deleteSquare(hitTri,findTriangle(vertices[v1], vertices[v2], hitTri));
}
}
}
}
I modified it a bit because the original version was freezing Unity.
Edit:
I think I know what might be the problem, It could be reassigning the mesh collider that is causing the problem.scripting problemarrayoptimizationtrianglesvertice manipulationTue, 10 Sep 2019 21:13:59 GMTslythethieveGetting the index of a triangle in shader?
http://answers.unity.com/questions/1663070/getting-the-index-of-a-triangle-in-shader.html
Hello.
I'm kinda new to shader programming and I'm writing a shader where i would like to send custom data (1 byte) accompanying each triangle in the mesh.
Basically I want to have an array of data that is the same size as the number of triangles in the mesh, and then read that data in the shader based on which triangle is currently being drawn.
The problem here is that I need to know the index of a particular triangle in the shader, is that possible at all?
thxshadershader programmingtrianglesindexWed, 04 Sep 2019 21:05:39 GMTKatt1Triangles become black when flipping triangles
http://answers.unity.com/questions/1660630/triangles-become-black-when-flipping-triangles.html
I'm developing a procedural terrain generator using Marching cubes, and whenever I try to make my meshes double sided, I get tonnes of black triangles on the mesh.
*With double sided enabled:*
![With double sided enabled][1]
Without double sided enabled
![Without double sided enabled][2]
All I am doing in my script is adding the reversed triangles;
triangles.AddRange(meshDatas[m].triangles.AsEnumerable().Reverse());
or
//Get a copy of our triangles so we don't modify the original
int[] trisCopy = triangles.ToArray();
//Loop over each set of triangles
for (int t = 0; t < trisCopy.Length; t += 3)
{
//Swap them around
int temp = trisCopy[t + 0];
trisCopy[t + 0] = trisCopy[t + 1];
trisCopy[t + 1] = temp;
}
//Now add the swapped triangles
triangles.AddRange(trisCopy);
[1]: /storage/temp/145209-screenshot-253.jpg
[2]: /storage/temp/145210-screenshot-254.jpgmeshproceduraltrianglesMon, 26 Aug 2019 08:40:05 GMTEternalClickbaitWhy does the default Unity sphere have duplicate vertices?
http://answers.unity.com/questions/1655517/why-does-the-default-unity-sphere-have-duplicate-v.html
If I print the length of the default Unity sphere mesh, I get 515 vertices. If I run vertices.Distinct().ToArray(), I get 386 vertices.
<br>
<br>
From [Anatomy of a Mesh][1]:
> By calling Mesh.RecalculateNormals, you can get Unity to work out the normals’ directions for you by making some assumptions about the “meaning” of the mesh geometry; it assumes that vertices shared between triangles indicate a smooth surface while doubled-up vertices indicate a crisp edge.
<br>
So, if duplicate vertices indicate a crisp edge to the Unity renderer, and a sphere is supposed to be a perfectly smooth object, then why does the default Unity sphere mesh have any duplicate vertices at all? Wouldn't duplicate vertices only hurt the renderer's ability to draw a perfectly smooth sphere?
[1]: https://docs.unity3d.com/Manual/AnatomyofaMesh.htmlmeshrenderingverticesnormalstrianglesWed, 07 Aug 2019 23:40:11 GMTtuf91497Generate mesh.triangles Array Programmatically
http://answers.unity.com/questions/1651776/generate-meshtriangles-array-programmatically.html
I Have a mesh which I want to break it it smaller pieces.
I am doing that buy creating new submeshes which each contains X(random) triangles like this:
...
int loop_vertices = 3 + (X- 1);
int[] indices = M.GetTriangles(submesh);
for (int i = 0; i < indices.Length; i += loop_vertices)
{
Vector3[] newVerts = new Vector3[loop_vertices];
Vector3[] newNormals = new Vector3[loop_vertices];
Vector2[] newUvs = new Vector2[loop_vertices];
for (int n = 0; n < loop_vertices; n++)
{
int index = indices[i + n];
newVerts[n] = verts[index];
newUvs[n] = uvs[index];
newNormals[n] = normals[index];
}
mesh.triangles=????????
}
...
How can i create the mesh.triangles array programmatically?meshtrianglesmesh verticesThu, 25 Jul 2019 22:53:27 GMTelaligogGenerate mesh.triangles Array Programmatically
http://answers.unity.com/questions/1651691/generate-meshtriangles-array-programmaticallyunity.html
I Have a mesh which I want to break it it smaller pieces.
I am doing that buy creating new submeshes which each contains X(random) triangles like this:
...
int loop_vertices = 3 + (X- 1);
int[] indices = M.GetTriangles(submesh);
for (int i = 0; i < indices.Length; i += loop_vertices)
{
Vector3[] newVerts = new Vector3[loop_vertices];
Vector3[] newNormals = new Vector3[loop_vertices];
Vector2[] newUvs = new Vector2[loop_vertices];
for (int n = 0; n < loop_vertices; n++)
{
int index = indices[i + n];
newVerts[n] = verts[index];
newUvs[n] = uvs[index];
newNormals[n] = normals[index];
}
mesh.triangles=????????
}
...
How can i create the mesh.triangles array programmatically?meshtrianglesmesh verticesThu, 25 Jul 2019 21:55:25 GMTunity_ZMrMjhdfhYoPtQFinding the amount of polygons being displayed.
http://answers.unity.com/questions/1648912/finding-the-amount-of-polygons-being-displayed.html
Hello,
I am currently developing for Oculus quest and my experience is lagging. I would like to know when it starts to lag (at how many rendered polygons). I am wondering if someone knows away of showing the current count of rendered polygons in a GUI somewhere ( I know how to do GUIs, just not finding the poly count ). I sadly can't use the built in unity stats window as I need to build the project.apk to my Oculus to be able to play my experience.
Thanks you!vrtrianglescountTue, 16 Jul 2019 04:21:14 GMTRevisiaSharing vertex buffer between mesh objects
http://answers.unity.com/questions/1647616/sharing-vertex-buffer-between-mesh-objects.html
Is there possibility to share vertex buffers between Mesh Objects. I have baked some bezier patches to Mesh objects. I would like to create a LOD version of a bezier patch; can I re-use the vertices from one mesh and just use different triangles (index buffer) to reduce poly count.
This is trivial to do with pure graphics API but I have not found a way to do it with Unity meshes.meshoptimizationtriangleslodThu, 11 Jul 2019 09:36:44 GMTpmerilainenFor raycast hits, what is a "barycentric coordinate"?
http://answers.unity.com/questions/1645237/for-raycast-hits-what-is-a-barycentric-coordinate.html
I haven't seen a good explanation for this yet. It's defined elsewhere as the "center of mass" for a triangle, pyramid, or for any dimensional "simplex".
<br>
<br>
So in Unity, is it just the very center point of the raycast hit triangle?raycastraycastingraycasthittrianglestriangleTue, 02 Jul 2019 16:23:05 GMTtuf91497Hey everyone, can someone help me to get the vertices and triangles in my Curve meshes? Every time I try I get "isReadable = false"
http://answers.unity.com/questions/1642478/hey-everyone-can-someone-help-me-to-get-the-vertic.html
I was able to make all my graphics in ActionScript 3.0 to run in Flash.
Now that I'm using Unity I've had to think in 3D.vector3trianglesFri, 21 Jun 2019 07:05:15 GMTtechnofeeliakDoes mesh.triangles also return a copy of the triangle array?
http://answers.unity.com/questions/1642001/does-meshtriangles-also-return-a-copy-of-the-trian.html
So mesh.vertices returns a ***copy*** of the vertex array, so if you are accessing it more than a couple of times you should really store it in a local array to avoid excessive garbage being created. So if I have some code like this:
<br>
<br>
for(int i = 0; i < mesh.triangles.length; i+=3){
Vector3 v0Vec = mesh.vertices[mesh.triangles[i]];
Vector3 v1Vec = mesh.vertices[mesh.triangles[i + 1]];
Vector3 v2Vec = mesh.vertices[mesh.triangles[i + 2]];
...
}
<br>
Then I should really convert it to something like this:
<br>
<br>
Vector3[] verts = mesh.vertices;
for(int i = 0; i < mesh.triangles.length; i+=3){
Vector3 v0Vec = verts[mesh.triangles[i]];
Vector3 v1Vec = verts[mesh.triangles[i + 1]];
Vector3 v2Vec = verts[mesh.triangles[i + 2]];
...
}
<br>
But does mesh.triangles do the same thing? Should my code really be more like this?:
<br>
<br>
Vector3[] verts = mesh.vertices;
int[] tris = mesh.triangles;
for(int i = 0; i < tris.length; i+=3){
Vector3 v0Vec = verts[tris[i]];
Vector3 v1Vec = verts[tris[i + 1]];
Vector3 v2Vec = verts[tris[i + 2]];
...
}
Thanks for your help.scripting problemmeshverticestrianglesWed, 19 Jun 2019 19:27:50 GMTtuf91497Green Wireframe Length
http://answers.unity.com/questions/1638346/green-wireframe-length.html
Is there any way to get green wireframe lines length from mesh collider? I need to find the longest line.![alt text][1]
[1]: /storage/temp/139588-przechwytywanie.pngcollidermeshmeshcollidertriangleswireframeThu, 06 Jun 2019 11:17:25 GMTHylusHow to make sure two meshes have the same vertex count
http://answers.unity.com/questions/1617917/how-to-make-sure-two-meshes-have-the-same-vertex-c.html
I am creating meshes that have the same vertex counts in blender but once in unity the mesh I have altered further gains more vertices than the less altered mesh (think of a sphere and a spikey sphere where the spiky sphere gains vertices) I know that unity ads UV vertices and such (they have the same normal count) but is there a way to keep their vertex count the same?
Edit: for further clarity the two meshes have the same vertex count in blender but not in unitymeshverticesnormalstrianglesuvsMon, 01 Apr 2019 05:56:03 GMTDejojotheawsomeBest way to transition one mesh to another with the option to change the target mesh
http://answers.unity.com/questions/1617769/best-way-to-transition-one-mesh-to-another-with-th.html
I can't think of a better way to word it but I understand that the title may be confusing. What I am looking for is a program that will take the mesh of, for example, a cube and begin to transform it into the mesh of a sphere over a set period of time. I also want the ability to change the target mesh, so if halfway through the spherical transformation the user wished to turn the current mesh into a pyramid, the half sphere half cube would then start to transition into the pyramid. I had an idea of simply increasing and decreasing the number of triangles on the current shape and then moving the vertices of the shape toward the direction of the new vertices but I feel like that could result in issues, and I am fairly new to the mesh class. I really just want to make sure that my method is not going to be horribly slow or just plain wrong. I hope that I have provided enough information and thank you for you time. <3meshruntimedynamicverticestrianglesSun, 31 Mar 2019 16:12:01 GMTDejojotheawsomeHow to find connected mesh triangles?
http://answers.unity.com/questions/1615363/how-to-find-connecting-mesh-triangles.html
I have an object that I'm raycasting to, and when I hit a button I want to start a "signal" on the mesh surface, starting from the triangle that the raycast hit. The signal is just vertex coloring: I want the first triangle to turn yellow and then I want yellow to spread outwards from the triangle to other triangles that are touching it, and then to the triangles that are touching those, etc. [Like so](https://gfycat.com/unsungshockingibis.gif).
<br>
<br>
My problem is that the triangle array isn't really sorted like that. Triangles that share a face share two vertices. I printed out the triangle array of the default sphere mesh, and it seems like touching triangles are *near* each other in the triangle array, but not necessarily and not predictably near each other.
<br>
<br>
Is there a convenient way to do this, besides for parsing through the entire triangle array and looking for matches? I'd like to do this with a 14,000+ vertex geometry eventually, so if you can't rely on the touching triangles to be near each other in the array, that would be quite a performance cost to find the touching triangles.scripting problemraycastmeshverticestrianglesSat, 23 Mar 2019 19:54:30 GMTtuf91497Quick way to get touching triangles?
http://answers.unity.com/questions/1613424/quick-way-to-get-touching-triangles.html
I have a mesh with unsorted vertices/triangles. I would like to send a color animation through the object that looks like a color "spreads" through the object by a few triangles at a time. Is it feasible to sort the triangle array somehow, or make a data structure for each triangle that stores the other triangles that it shares at least one vertex with?scripting problemverticesmeshestrianglesSun, 17 Mar 2019 17:06:12 GMTtuf91497Issues with Low Poly Shader on Mesh
http://answers.unity.com/questions/1602040/issues-with-low-poly-shader-on-mesh.html
I am trying to make a randomly generated mesh with a low poly look to it, and have made a shader using this tutorial: https://www.youtube.com/watch?v=e3oYQL0oDEs. I also created a script to procedurally generate a mesh. Unfortunately, when I run it, this happens:
![alt text][1]
My issue is the random black triangles everywhere, and when I view the scene and pan around while its running, the triangles change in color. Ideally, I would want the mesh to have this same look, except for without the random black triangles.
The project uses a Lightweight Render Pipeline and uses the script pasted below. I made the script it's own object in the scene and set the xSize and zSize to 20. I also made a PBR Shader with this ShaderGraph: ![alt text][2]
Any help is appreciated. Here is the Mesh Generator Script:'
public int xSize = 10;
public int zSize = 10;
Mesh mesh;
Vector3[] vertices;
int[] triangles;
Color[] colors;
float minTerrainHeight;
float maxTerrainHeight;
void Start()
{
mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
CreateShape();
UpdateMesh();
}
void CreateShape()
{
vertices = new Vector3[(xSize + 1) * (zSize + 1)];
for (int i = 0, z = 0; z <= zSize; z++)
{
for (int x = 0; x <= xSize; x++)
{
float y = Mathf.PerlinNoise(x * .2f, z * .2f) * 3.5f;
vertices[i] = new Vector3(x, y, z);
if (y > maxTerrainHeight)
{
maxTerrainHeight = y;
}
if (y < minTerrainHeight)
{
minTerrainHeight = y;
}
i++;
}
}
triangles = new int[xSize * zSize * 6];
int vert = 0;
int tris = 0;
for (int z = 0; z < zSize; z++)
{
for (int x = 0; x < xSize; x++)
{
triangles[tris + 0] = vert + 0;
triangles[tris + 1] = vert + xSize + 1;
triangles[tris + 2] = vert + 1;
triangles[tris + 3] = vert + 1;
triangles[tris + 4] = vert + xSize + 1;
triangles[tris + 5] = vert + xSize + 2;
//yield return new WaitForSeconds(0.1f);
vert += 1;
tris += 6;
}
vert += 1;
}
Color currentColor = new Color();
colors = new Color[vertices.Length];
for (int i = 0, z = 0; z <= zSize; z++)
{
for (int x = 0; x <= xSize; x++)
{
if (i % 3 == 0)
{
float side = Random.Range(0f, 0.6f);
float opac = Random.Range(0.7f, 1f);
currentColor = new Color(side, opac, side, 1);
}
colors[i] = currentColor;
i++;
}
}
}
void UpdateMesh()
{
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
mesh.colors = colors;
mesh.RecalculateNormals();
}
'
[1]: /storage/temp/133165-screen-shot-2019-02-15-at-24914-am.png
[2]: /storage/temp/133167-screen-shot-2019-02-15-at-24835-am.pngmeshshaderstriangleslow polyFri, 15 Feb 2019 11:16:02 GMTDixitsHow can I calculate the angle between two adjacent triangles in 3D? (for detecting concave or convex triangles)
http://answers.unity.com/questions/1600038/how-can-i-calculate-the-angle-between-two-adjacent.html
Hi guys,
I am trying to calculate the angle between two triangles in 3D space.
Let's assume that triangle one consists of three points
`P1=(x1,y1,z1), P2=(x2,y2,z2), and **P3=(x3,y3,z3).**`
Triangle two consists also of three points
`P1=(x1,y1,z1), P2=(x2,y2,z2), and **P3=(x4,y4,z4).**`
Thank you in advance!!3danglestrianglestrigonometrySat, 09 Feb 2019 13:06:35 GMTkliment5Is there a premade triangle asset?
http://answers.unity.com/questions/1594750/is-there-a-premade-triangle-asset.html
Hi! I'm new to Unity and my project is to make a prefab out of primitives. So, I decided to try to make a house, I was able to do it mostly with cubes of varying sizes, but when it comes to the roof, if I want the triangular shaped kind I need a triangle for the front and back of the roof. I read that you need a modeling program to make it. I am not a fan of that situation since I have never used one, is there really no way to create a triangle in Unity without modeling software? It just seems so strange they give you Cubes and Spheres and even Capsules but NOT Triangles, doesn't? Even more strange is that the Asset Store seems to be devoid of anything triangles when I tried looking for one.triangles3d modelSat, 26 Jan 2019 22:00:21 GMTajrosenbachMesh adaption
http://answers.unity.com/questions/1592831/mesh-adaption.html
Hey guys, I'm currently working on a project where I import a mesh through code (C#) into my application. The triangles on the mesh are all in different sizes, meaning the edges and the area of the triangles are quite different. See the image below. Does anyone know a way to shape the triangles uniformly, while approximately keeping the shape of the whole mesh? Appreciate your answers!
![alt text][1]
[1]: /storage/temp/131679-mesh.jpgc#meshverticestrianglesTue, 22 Jan 2019 07:51:17 GMTShorayn_3d model with lower poly count than another model causing tons of lag
http://answers.unity.com/questions/1592674/3d-model-with-lower-poly-count-than-another-model.html
Hi, I have a 3d model of an infantryman that has about 45k triangles. When I spawn them, my fps drops a lot (if I spawn like 10, it drops from over 100 fps down to around 40 fps). But none of my other models cause this much lag. I have some tank models that have over 100k triangles, and they cause minimal drop in the fps. I checked the materials and bones on the infantryman, and came to a definite conclusion that it is the polycount, as when I lower its triangles to around 10k, I get minimal fps drop. So why would a model that has a lower triangles and vert count than a lot of my other models cause a worse drop in fps? When I spawn the infantry, my top CPU usage in the profiler is usually gfx.waitforpresent, which I read is the CPU waiting for the GPU. Any help would be much appreciated! Thanks! :)fpslagvertices3d modelstrianglesMon, 21 Jan 2019 19:41:18 GMTjobo22Want to create a new mesh (single triangle) "cloned" from an already existing triangle ....
http://answers.unity.com/questions/1592186/want-to-create-a-new-mesh-single-triangle-cloned-f.html
Hi,
I have a sort of a planet earth object, a mesh
when i click on a it, i register the triangle i clicked on (i got to get its triangle index)
from there i want to "create" a new mesh that is based on that very same triangle but would be like "hovering" over the original mesh (to achieve like a "floating" white clone of that triangle , this would show that the tile was selected, as it will turn into a white material)
(originally i planned to do it thru shader - but it's too hard for me now and i thought doing it with a mesh would make me learn about them - i thought about a Decal , but they are not in standard Unity yet, ....)
I have been struggling but i learned a lot about vertices and all, which is good, still i am at a stuck :
**the new object is created and all, but it is empty and at the center of the world instead of being hovering the original triangle**
![alt text][1]
**here is the code of the function that does it all :**
// WHEN WHE click on a triangle on the "Earth Mesh", a new one is created, like a clone of that triange, just a bit hovering it, and as a separate object
void SelectedTile(int triangleindex)
{
//check if a "Selected Tile" was already created (previous click) if yes, destroy it
GameObject[] olderTiles;
olderTiles = GameObject.FindGameObjectsWithTag("stile");
if (olderTiles.Length != 0)
{
Debug.Log("OLDER TILE FOUND, must destroy it0");
Destroy(olderTiles[0]);
}
Debug.Log("TILE SELECTED");
Debug.Log("Triangle id : " + triangleindex);
//get the whole mesh we clicked on, single out the vertices and the normals and the triangles
Mesh mesh = transform.GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;
Vector3[] normals = mesh.normals;
int[] triangles = mesh.triangles;
//Single out the 3 vertices from a specific triangle (the one that has the index passed as a parameter triangleindex in the method)
Vector3 p0 = vertices[triangles[triangleindex * 3 + 0]];
Vector3 p1 = vertices[triangles[triangleindex * 3 + 1]];
Vector3 p2 = vertices[triangles[triangleindex * 3 + 2]];
//
Transform hitTransform = transform;
p0 = hitTransform.TransformPoint(p0);
p1 = hitTransform.TransformPoint(p1);
p2 = hitTransform.TransformPoint(p2);
// Draw the triangle debug lines
Color color = new Color(1f, 0f, 0f);
Debug.DrawLine(p0, p1, color);
Debug.DrawLine(p1, p2, color);
Debug.DrawLine(p2, p0, color);
// CREATE a new MESH to create a flat triangle
// Set up game object with mesh;
GameObject Selectedtile = new GameObject("Selectedtile_"+triangleindex);
Selectedtile.tag = "stile";
// add the right needed components
Mesh newmesh = new Mesh();
Selectedtile.AddComponent<MeshFilter>();
Selectedtile.AddComponent<MeshRenderer>().material.color = Color.white;
Selectedtile.GetComponent<MeshFilter>().mesh = newmesh;
//create temp arrays for vertices and UVS and triangle
Vector3[] newVertices = new Vector3[3]; //just need 3 i guess....
Vector2[] newUV = new Vector2[3]; // same thing?
int[] newTriangles = new int[3]; //i guess one would even be enough... ??
//tell these vertices to be like the ones we got from the original target triangle but with little displacement so it "hovers" over it
for (int i = 0; i < 3; i++)
{
newVertices[i] += vertices[triangles[triangleindex * 3 + 0]] + new Vector3(0.5f,0.5f,0.5f); //not sure about that....
}
//same thing for UVs....not sure about what i am doing.....
for (int i = 0; i < 3; i++)
{
newUV[i] = new Vector2(vertices[i].x, vertices[i].z);
}
// assign the temp calculated arrays into the arrays of the new Mesh.
newmesh.vertices = newVertices;
newmesh.uv = newUV;
newmesh.triangles = newTriangles;
newmesh.RecalculateNormals();
newmesh.RecalculateBounds();
}
[1]: /storage/temp/131530-newtile.pngmeshverticestrianglesSun, 20 Jan 2019 17:04:33 GMTYa7yasugarihow to render 60k cubes as efficiently as possible?
http://answers.unity.com/questions/1591912/how-to-render-60k-cubes-as-efficiently-as-possible.html
Hello, i would like to render a large number of cubes efficiently. the user will also be interacting with the cubes on every frame, so i will be storing my cubes on a mesh and modifying the cube's alpha and color every frame.
i would like to minimize the number of vertices, but i see unity no longer supports triangle strips (8 vertices per cube) so i am limited to triangles (24 vertices per cube), which will presumably perform 3x worse.
does anyone know a fast way to render and interact with a large number of cubes (60k+)? also while i'm here doe anyone know why unity removed triangle strips?
thanks,meshfpscubetrianglesmeshfilterSat, 19 Jan 2019 16:48:02 GMTrustyruss1985Is it possible to group selected verticies(of a 3D model) into a single clickable/controllable object?
http://answers.unity.com/questions/1587316/is-it-possible-to-group-selected-verticiesof-a-3d.html
Taking this ball for example:
![alt text][1]
[1]: /storage/temp/130641-ball.jpg
The 3D model is a single object made of many verticies and triangles. Would it be possible to group them into the red, blue and green groups respectively? This way I would be able to code different functions according to which "group" collides with another object.
Pardon me if this was a silly question. I'm open to all suggestions and opinions.
Thank you Unity community :)shadergameobject3d modelstriangleshighlightSun, 06 Jan 2019 19:36:08 GMTAshleyWolfYapAdding texture to vertex ,I don't want to apply texture each vertex
http://answers.unity.com/questions/1577049/adding-texture-to-vertex-i-dont-want-to-apply-text.html
![alt text][1]
[1]: /storage/temp/128786-screen-shot-2018-12-02-at-55232-pm.png
I am using exactly the same code from this website https://catlikecoding.com/unity/tutorials/rounded-cube/ and I don't want to apply texture to EACH vertex I want to apply texture that covers the ENTRIE cube, not each vertex. Right now a grid image is applied to each vertex. I don't know how to fix the shader...
this is the code for shader
Shader "Custom/Rounded Cube Grid" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
[KeywordEnum(X, Y, Z)] _Faces ("Faces", Float) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
//#pragma shader_feature _FACES_X _FACES_Y _FACES_Z
#pragma surface surf Standard fullforwardshadows vertex:vert
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 cubeUV;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input, o);
o.cubeUV = v.color.xyz;
#if defined(_FACES_X)
o.cubeUV = v.color.yz * 255;
#elif defined(_FACES_Y)
o.cubeUV = v.color.xz * 255;
#elif defined(_FACES_Z)
o.cubeUV = v.color.xy * 255;
#endif
}
void surf (Input IN, inout SurfaceOutputStandard o) {
*fixed4 c = tex2D (_MainTex, IN.cubeUV) * _Color;
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}shadertexturecubeverticestrianglesSun, 02 Dec 2018 23:01:21 GMTheejoojin