Recent

Author Topic: A GLScene rotation mesh builder class.  (Read 5791 times)

dicepd

  • Full Member
  • ***
  • Posts: 163
A GLScene rotation mesh builder class.
« on: August 27, 2017, 12:50:34 pm »
Designed to be subclassed or used as a helper class for parametric mesh generation of rotated surfaces.

From the header (too lazy to type something like this again  :D)

Code: Pascal  [Select][+][-]
  1. unit GLRevolutionMeshObject;
  2. {
  3.    TGLRevolutionMeshObject
  4.  
  5.     A class used to build revolution onjects with features, such as shafts /
  6.     columms, or with some work freeform.
  7.  
  8.     Each section leaves an index value to the last ring of Vertices made.
  9.     Callable routines should have the option to use previous ring, mainly
  10.     for use with rounded features where the normals are the same for both
  11.     edges of the feature.
  12.  
  13.     If previous ring is not used at a given Z then dup points will be
  14.     generated, generally with a differing normal, which creates a hard edge.
  15.     Hopefully this will create a topologically correct mesh, with minimum
  16.     number of vertices.
  17.  
  18.     Setting  FaceGroups[0]).Mode to fgmmQuads will generate quad faces.
  19.     The default is triangular faces.
  20.  
  21.     Mesh density can be radially increased/decreased through
  22.     MakeTransitionFiner and MakeTransitionCoarser. This is a stateful change
  23.     which will keep the new density until another call is made.
  24.     NOTE: mesh density changing can only be used with triangular meshes.
  25.  
  26.     Revolutions should be built from the 'top' down. Top for solid rotations
  27.     means highest point that meets the Z axis. See Drilled hole example.
  28.     For shelled ojects such as a tube, top is the lowest Z point and the inside
  29.     of the shelled rotation is generated first.
  30.  
  31.     Edges are stored with an index to the first ring and the ring size.
  32.     This ring and the next ring should have congruent vertices. But this will
  33.     allow only one ring to be used if we need to collapse the edges for export,
  34.     reducing the risk of holes at the edge vertices. Plus we can dispay them
  35.     for debugging :) where we forget to set a UsePrevious to True.
  36.  
  37.     TODO
  38.       Add in Tex coords obviously only one is needed as the conic will
  39.       use either u or v for the wrap round, and the other specified in the call
  40.       to build the section? More thought required but basically not of interest
  41.       for my immediate needs.
  42.  
  43.  
  44.  
  45.     Optimisation Techniques Used.
  46.  
  47.     Sine and cosine calls removed from any inner loop by using predefined
  48.       x,y 2D unit vectors.
  49.  
  50.     Z components and normals are optimised by taking into account the fact that
  51.       any affine vector rotated around the Z axis will have the same z value.
  52.       So if we calculate that once in 2D space on a major axis, the x.z plane
  53.       for instance, the y component of the 2D unit vector becomes the z part
  54.       of the unit 3D vector and the x component becomes a scaling factor to
  55.       use with the predefined xy unit vector array.
  56.  
  57.     Added bonus to the above approach is we are calculating unit vector
  58.     normals. No need to call normalise on the Normals saving a sqrt call
  59.     per vertex.                                      

How it is used can be seen from the example code in the test form. Some comments on usage can be found in these code segement.

Enjoy

Peter

« Last Edit: August 27, 2017, 01:00:47 pm by dicepd »
Lazarus 1.8rc5 Win64 / Linux gtk2 64 / FreeBSD qt4

BeanzMaster

  • Sr. Member
  • ****
  • Posts: 268
Re: A GLScene rotation mesh builder class.
« Reply #1 on: August 27, 2017, 01:02:45 pm »
Nice job can I'll include your sample in GLScene for the next update ?

dicepd

  • Full Member
  • ***
  • Posts: 163
Re: A GLScene rotation mesh builder class.
« Reply #2 on: August 27, 2017, 01:14:44 pm »
Nice job can I'll include your sample in GLScene for the next update ?

Sure, no problem there.

Peter
Lazarus 1.8rc5 Win64 / Linux gtk2 64 / FreeBSD qt4

 

TinyPortal © 2005-2018