<p dir="auto">I have an indexed BufferGeometry and indexed set of uvs. I have been unsuccessfully trying to pass uv coordinates per face per vertex to the vertex shader as it seems that BufferGeometry expects exactly one uv vertex per geometry vertex.</p>
<p dir="auto">I resorted to using Geometry.fromBufferGeometry and then populating the faceVertexUvs array but there's a lot of overhead involved.</p>
<p dir="auto">Judging by <a href="http://stackoverflow.com/questions/25874926/buffergeometry-always-creates-flatshading-normals-i-need-smoothshading" rel="nofollow">http://stackoverflow.com/questions/25874926/buffergeometry-always-creates-flatshading-normals-i-need-smoothshading</a>, it seems this is not supported yet, is that right?</p>
<p dir="auto">A vertex is basically just a set of attributes, so it doesn't seem that easy to implement (you probably need to duplicate vertices where necessary), do you have ideas in this direction?</p>
<p dir="auto">Hi guys,</p>
<p dir="auto">I wanted to try and contribute to Three.js and this thread is for discussing about the stuff i wrote.</p>
<p dir="auto">The questions that are open:</p>
<ol dir="auto">
<li>Do you want to use this functionality or do you think three.js needs it?</li>
<li>What do you think of my algorithm. I was hoping for some guys to check the functions and maybe try to optimize the functionalty in case question 1) is "yes" ;)</li>
</ol>
<hr>
<p dir="auto">What i caught missing in THree.js is the functionality to smooth dynamically generated geometries based on an angle. (like in 3dsMax for example)<br>
If the angle between two face normals is smaller than 'angle' the faces get smothed and the vertex normal accounts for that smoothing.</p>
<p dir="auto">I forked the three.js repository and created a new branch.</p>
<p dir="auto">I provide an example in my github fork:<br>
<a href="https://github.com/GuyGood/three.js/blob/AngleBasedSmoothing/examples/webgl_geometry_smoothing.html">https://github.com/GuyGood/three.js/blob/AngleBasedSmoothing/examples/webgl_geometry_smoothing.html</a></p>
<p dir="auto">The example compares an extruded geometry with bevel applied.<br>
left: unsmoothed as is, middle: my angle based smoothing, 25°, right: computeVertexNormals(true)<br>
<a href="http://img109.imageshack.us/img109/3081/v0jc.png" rel="nofollow">http://img109.imageshack.us/img109/3081/v0jc.png</a></p>
<p dir="auto">As I put all my code into Three.GeometryUtils without rebuilding, my example directly uses GeometryUtils.js script.</p>
<h2 dir="auto">New stuff to GeometryUtils briefly explained:</h2>
<p dir="auto">So, i added the function "calculateVertexNormals"  (should then be renamed to sth else).<br>
It firsts creates new vector3 objects for every vertexNormal for every face of the mesh. (just for having everything at zero).</p>
<p dir="auto">It then fills an array 'adjacentNormals' with objects so that it contains a face and the vertexNormal, and an empty array for the smoothingGroup stuffs for later on.</p>
<p dir="auto">then there is the helper method _sortAdjacentFaces. This is because what i am going to do is iterate over all vertices and check all faces connected to one vertex , so to say in a circular manner. And if i don't sort the array beforehand, i would compare faces, connected to the vertex that do NOT share one edge, which would be no good. As a side note, the last iteration compares the last and first face of the vertex in question.</p>
<p dir="auto">After sorting,  the algorithm gets  the angle between the faces and checks if it is &lt;= the user defined angle. if it is, it will generate 'smoothing groups' . These groups are local to each vertex and do not work like in 3dsMax for example. They are just for knowing which facenormal from which face to take into account for the vertex normal calculation.</p>
<p dir="auto">After having calculated the groups and based on them, the vertexNormal is calculated using the helper function: '_calculateVectorSumsForSmoothingGroups'</p>
<p dir="auto">This function is much like the "computeVertexNormal" from geometries but is always area weighted, so normals are accumulated but not normalized within there.</p>
<p dir="auto">Finally, normalize the vertex normals and we are done.</p>
<hr>
<p dir="auto">I hope i could explain some of the stuff and maybe you like the general idea. I am just proposing some code for review because although it works, there are for sure 2-3 small issues and maybe it can be greatly optimized.<br>
p.s. i know the code is for sure not nice to read but i hope you like the feature anyway and want to have a discussion about it.</p>
<p dir="auto">Thanks in Advance</p>