I was wondering how to set a normal array for faces instead for vertices with NormalPointer. I use DrawElements for drawing quads but edge vertices are always shared with multiple quads so the definition of normals per vertex is not helpful. When I duplicate vertices and use no ElementArrayBuffer I can solve this by using DrawArrays. However, the duplication of the vertices and using DrawArrays results in inaccaptable artefacts between the quads. Is there any possibility to use a list of face normals together with ElementArrayBuffer? Can this only be done with shaders?
Thanks in advance!
Related
Hello I am using DEVDEPT 3D engine FEM VERSION. I can read the Step File with ReadSTEP comand.
I would like to get the value of the Vertices, Edges and Faces.
I can read "design1.Entities[0].Vertices[0].X" from my c#code,
But I can not read "design1.Entities[0].Edges[0]" or "design1.Entities[0].Faces[0]".
There is no edges and faces properties on entities as I see.
how can i get faces and edges values?
Regards
Ahmet.
unfortunately I don’t know where is the problem?
I'm hoping to create a Voronoi landscape in Unity in C#. I looked at a number of Unity Project files, but they all implement Fortune's algorithm, which is completely over my head. Are there any other methods of generating Voronoi diagram (that is easier to understand)?
Slow performance is completely fine with me.
Much appreciated!
Sidenote: Since I'm working in Unity and need to generate 2D/3D mesh from Voronoi diagram, per-pixel distance check won't work :,(
On second thought, maybe I could use a 2D array of Vector2s instead of pixels, that are 1.0 unit spaced apart in x and z axis.
There is a very simple way to create an approximated Voronoi diagram VD. For every Site s that should define a cell in the VD (2D-plane) you center a cone at s with constant slope and a certain height. Then you look from above onto that landscape of cones (where all the spikes are visible). The boundary where the different cones meet (projected to the 2D-plane) is the (approximated) Voronoi diagram.
(Image Source)
As you requested in the comments, to get the actual edge data seems not so easy. But there could be some graphical routines to generate them by intersecting the cones.
An alternative is to compute a Delaunay triangulation of the given point set. There are some implementation referenced in this related post (also simple approximations are mentioned). Then you compute the dual graph of your triangulation and you have the Voronoi diagram. (Dual graph means that for every for every edge AB in the triangulation there exists an edge in the VD bisecting the space between the two vertices A and B, and for every triangle there exists a vertex in the VD where the dual edges meet.) Othwerwise there are also many C# Voronoi implementations around: Unity-delaunay, but as you mentioned using the Fortune approach.
If you want to code everything yourself you may compute a triangulation of the points with brute force for n points in O(n^2) time. Then apply in-circle tests and edge flips. That is, for every triangle t(abc) create a circle C defined by the three vertices of t. Then check if there lies another point d of your point set inside C. If so, then flip the edge that is in t as well as forms an edge in the triangle with d. This flipping is done until all triangles fulfil the empty circle property (Delaunay condition). Again with brute force will take O(n^2) time. Then you can compute the dual graph as mentioned above.
(Image Source)
"Easiest? That's the brute-force approach: For each pixel in your output, iterate through all points, compute distance, use the closest. Slow as can be, but very simple. If performance isn't important, it does the job."
[1] Easiest algorithm of Voronoi diagram to implement?
I'm looking forward to use A* pathfinding for a game I'm working on. (I'm actually making a game for myself to learn about this). I am wondering how the Unity NavMesh can be used with a custom A* algorithm, instead of using a NavMeshAgent.
No
Or at least, not easily (why would you want to?).
Unity's builtin NavMesh is intended to be used by Unity's builtin NavMeshAgent utilizing a builtin pathfinder. I don't know what algorithm it uses, but A* implementations typically operate on networks. That is, nodes connected by edges. It does not consider the interior volume (the mesh 'faces').
As Unity's builtins are intended to be used as such, it is very difficult to get access to any of the information directly for use with your own pathfinding algorithms.
If you want to write your own pathfinder, then I recommend writing your own mesh as well.
You can do the following:
var navMesh = NavMesh.CalculateTriangulation() // get baked Navigation Mesh Data;
Vector3[] vertices = navMesh.vertices;
int[] polygons = navMesh.indices;
vertices (obviously) are the vertices of your navigation mesh indicated by their position in unity space. The meshes are defined by polygons. The polygon array shows which vertice belongs to which polygon.
polygons:
0 0
1 0
2 1
3 1
4 0
5 1
This array would indicate that vertices with indices 0,1,4 belongs to polygon number 0 and vertices with indices 2,3,5 belongs to polygon number 1.
There you have your navmesh as polygons. You can define your search graph and run the search algorithm of your choice.
Wikipedia says that dodecahedron at the origin has vertices with this coordinates(x,y,z):
(±1, ±1, ±1)
(0, ±1/φ, ±φ)
(±1/φ, ±φ, 0)
(±φ, 0, ±1/φ)
where φ is golden ratio (φ = (1 + √5) / 2 ≈ 1.618 )
Let's say that I'll have this vertexes in vertexBuffer - which will be an array of Point3D.
I need prepare indexes of triangles for indexBuffer(which is an array of int). Dodecahedron has 12 faces, each face is pentagon and I will create each face from 3 triangles this way:
first triangle: a,e,b
second triangle: b,e,d
third triangle: d,c,b
For easier polyhedron I can draw it and then mark vertices and then easily get the indexes, but in this case it's not good way, cause after this Icosahedron, which has 20 faces, is waiting for me :/
So my question is: Is there any easier way how to get indexes for this vertices according requirements specified above?
Note:
I should also mentioned, that I couldn't use openGL or DirectX. We should practise 3D graphics without this libraries.
The first set of 8 vertices defines a cube.
The 3x4 remaining points come in 6 pairs that lie outside each of the 6 faces of the cube.
Each set of six points (four vertices of the cube face and the corresponding two points further away from the origin) form a pattern that repeats six times. You can get 6 triangles from each set.
An icosahedron is actually simpler: it has only 20 triangles instead of 36. It has a similar pattern, which you can see on its Wikipedia page.
I have a set of co-planar, connected triangles, i.e., a 2D mesh. Now I need to extrude it out a few units in the z-axis. The mesh is defined by a set of vertices which the renderer makes sense of by matching up against an array of triangles.
Example Mesh:
Vertices: (0,0,0), (10,0,0), (10,10,0), (0,10,0) <-- (x,y,z)
Triangles: (1, 2, 3) & (3, 4, 1) <-- numbers here reference the position of a vertex above.
So here we have a 2D square. Now I need to add more vertices and triangles to that list to make an extruded shape. Triangles must be in clockwise direction, otherwise they're backface-culled.
Is there a simple algorithm for this? Thank you.
Assuming you want to extrude by a distance z, you need to follow these steps:
0) let n be the original number of vertices (4 in your example)
1) For each vertex in your vertex array, add (0,0,z) to it, and add the result to your vertex array, for a total of 2*n vertices. So, for your example, you will add the vertices (0,0,z), (10,0,z), (10,10,z), (0,10,z) to your vertex array, for a total of 2*4=8 vertices.
2) Create a list of boundary (as opposed to internal) edges for your original mesh. To do this, create a list of all triangle edges (3 edges going in clockwise order for each triangle). Then remove pairs of equal but opposite edges (these are the internal edges). For your example, you will start with 6 edges, and end up with 4 edges after removing the edge pair (3,1) and (1,3).
3) for each triangle (a,b,c) in your triangle list, create a corresponding triangle (a+n,b+n,c+n). These will be the extruded faces
4) Finally, you want to create the sides of your extruded shape. For each edge (a,b) in the boundary edge list you created in step 2, add the triangles (a,b,b+n) and (b+n,a+n,a)
That's it. Assuming no typos on my part, and no typos on your part, you should now have your desired mesh.