It is currently Mon Sep 23, 2019 9:32 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: OpenGL Gadget: Project points on to Mesh Model?
PostPosted: Fri Mar 29, 2019 1:30 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5833
Location: Wales, UK
Hi All

I am using applePi's sample Quads Mesh Model (my own imported meshes will use triangles as the are derived from STL files)
https://www.purebasic.fr/english/viewtopic.php?f=36&t=70312

... with the mouse pointer camera rotate/zoom and orthogonal view functionality of this module by StarBootics:
https://www.purebasic.fr/english/viewtopic.php?f=36&t=65829

So far, so good :)

Next step in the process is to place points on the mesh, as per my tiny video here:
https://www.professorcad.co.uk/PickPts.html

From ApplePi's other demo files, it looks as though OpenGL point objects are good for this purpose, i.e. User can see them.

What I need to know though is:

1) How to project or "ray" individual points onto the Mesh Model, position as defined by the User with the mouse cursor.
2) How to delete the points - they are a means to an end, three points to define a plane.

Image

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL Gadget: Project points on to Mesh Model?
PostPosted: Sat Jun 29, 2019 8:12 am 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5833
Location: Wales, UK
So, found the method which I had known of before but it slipped through all three brain cells:

http://antongerdelan.net/opengl/raycasting.html

This is described with User friendly drawings so that anyone can understand how to do it. Except me!

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL Gadget: Project points on to Mesh Model?
PostPosted: Thu Jul 04, 2019 9:26 am 
Offline
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1368
Hi IdeasVacuum
i think you refer to the subject "Quad Mesh, with Cartesian and parametric equations" in viewtopic.php?f=36&t=65748
since your above link refer to Ogre mesh made from points, and the points is big because we compile with opengl context and we choose glEnable_(#GL_POINT_SMOOTH) to let the points appears thick, the examples itself is for purebasic Ogre engine
regarding the STL models you wants to put a point over it, i don't see any way how to load it in the opengl and if we somehow loaded it how to paint a point over it. it is not a fault of purebasic which is very fine itself but the fault is from our ignorance of the deep things in opengl and how it works, only the young people below 37 years old who can know too much about the subject. i remember a nice example in ogre we can paint over it by the mouse but can't remember or find it at all .
regarding the opengl 4+ i estimate 1 per 5 millions who know about it, so there is only 8,000,000,000/5000,000 = 1600 persons who know about opengl 4+ well in all over the world and most people focus on old opengl v1.1. and they use usually 0.001 of its true capabilities this is why the graphics cards companies still support the v1.1 even in emulated mode because they will loose the market if otherwise. before 2 years i have tried to study from the link your refer to and finally i found it a complete waste of time.
in the next few weeks i will post how to fit graphics nicely to opengl gadget window, only simple short examples. my eyes status does not support complex things unfortunately.
regards


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL Gadget: Project points on to Mesh Model?
PostPosted: Sat Jul 06, 2019 12:13 am 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5833
Location: Wales, UK
Hi ApplePi

good to know your are still out there :)

I think it is relatively easy to load an STL into OpenGL, given that STL is built with planar triangle faces. I did write an STL importer for PB Ogre which worked well in an earlier PB release (does not work in PB5.7x). So loading STL data is not an issue, but picking STL faces is :)

PB Ogre has this function:
Code:
RayPick(x, y, z, DestinationX, DestinationY, DestinationZ [, PickMask])


...which is essentially what I would like to do in OpenGL. The reason I'd like to use the OpenGL gadget instead of a Windowed Screen is the fret-free mouse pointer between Window gadgets and model space. Also the mouse pointer camera rotate/zoom and orthogonal view functionality by StarBootics is excellent for my project.

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL Gadget: Project points on to Mesh Model?
PostPosted: Wed Jul 24, 2019 5:43 pm 
Offline
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1368
you are right IdeasVacuum the STL models files is simple in its structure, just vertex positions and normals. i have tried the following loader to openglGadget using
glOrtho_(-50,50,-50,50,-50,50)
glDrawArrays_(#GL_TRIANGLES, 0, ArraySize(vertex()))

i first loaded the mesh positions and normals to vertex() array, it will load only the stl if it is ascii and not binary, there are sites in the web which converts binaries to ascii
glOrtho is very nice and will project the 3D scene to the openglgadget sizes, it is making things easy and straightforward. some people may say it is deprecated. whats the point, we are using our DNA code from millions of years ago and it is not deprecated yet
glDrawArrays is also very nice and it is the easiest to graph scenes whether 2d or 3d

the regular expression to parse the 3 floating numbers i have copied from the web , it does not work with scientific notation numbers some times we find it like:
-4.62238e-05 this number is almost equal zero -0.000046223799
this site https://www.meshconvert.com/ add these notations sometimes . another converter here https://github.com/cmpolis/convertSTL haven't tried it yet
attached 3 specimens of STL meshes as text, line 17 choose owl.stl or spider.stl or purebasic.stl. to see the spider.stl better use glOrtho_(-10,10,-10,10,-10,10) since glOrtho_(-50,50,-50,50,-50,50) is for big models sizes
http://s000.tinyupload.com/index.php?fi ... 1296197433
Code:
Declare findNumbers(s.s)
Global t

Structure vert
 x.f
 y.f
 z.f
 nx.f ;for normals
 ny.f
 nz.f
EndStructure

 
stlMesh.s = "owl.stl"
;stlMesh.s = "spider.stl"
;stlMesh.s = "purebasic.stl"

If ReadFile(0, stlMesh)   ; if the file could be read, we continue...
  While Eof(0) = 0                   ; loop as long the 'end of file' isn't reached
    s$ = ReadString(0)
    If FindString(s$, "vertex")
      lines+1
    EndIf
  Wend
EndIf

CloseFile(0)
;Debug lines

Global.f Dim vertex.vert(lines)
Global.f Dim tmp(2)
Global rot.f = 1
Global t, n
ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "STL reader")
SetWindowColor(0, RGB(200,220,200))
OpenGLGadget(0, 10, 10, WindowWidth(0) , WindowHeight(0) , #PB_OpenGL_Keyboard)
SetWindowTitle(0, "STL reader    "+Str(lines)+" vertices")


If ReadFile(0, stlMesh)   ; if the file could be read, we continue...
  While Eof(0) = 0                   ; loop as long the 'end of file' isn't reached
    s$ = ReadString(0)
    If FindString(s$, "vertex")
      findNumbers(s$)
      vertex(t)\x = tmp(0)
      vertex(t)\y = tmp(1)
      vertex(t)\z = tmp(2)
      t+1
    EndIf
       
   If FindString(s$, "normal")
      findNumbers(s$)
      vertex(n)\nx = tmp(0)
      vertex(n)\ny = tmp(1)
      vertex(n)\nz = tmp(2)
      n+1     
  EndIf
   
  Wend 
  ;Debug t
  CloseFile(0)
   
  Else
    MessageRequester("Information","Couldn't open the file!")
  EndIf

 
glLoadIdentity_()
glOrtho_(-50,50,-50,50,-50,50)
;glOrtho_(-10,10,-10,10,-10,10)
glMatrixMode_(#GL_PROJECTION); 

glEnable_(#GL_DEPTH_TEST)
glPolygonMode_(#GL_FRONT_AND_BACK, #GL_LINE )

glShadeModel_(#GL_SMOOTH)
glEnable_(#GL_DEPTH_TEST)
glEnable_(#GL_LIGHT_MODEL_AMBIENT)

glClearColor_ (1.0, 0.6, 0.4, 0.0);

glEnable_(#GL_LIGHTING) ;Enable Lighting
glEnable_(#GL_LIGHT0)

glEnable_(#GL_NORMALIZE)

gluLookAt_( 0, 0.5, 1, ; the camera looking from position 0,0.5,1  to 0,0,0 from above
            0,  0, 0,
            0,  1,  0 )

;glRotatef_(-90, 0, 1, 0)

Repeat
 
  event = WindowEvent()
 
  glClearColor_(0.9, 0.9, 0.9, 1)
  glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
  glRotatef_(rot, 0, 1, 0)
 
      glEnableClientState_(#GL_VERTEX_ARRAY)
      glEnableClientState_(#GL_NORMAL_ARRAY)
     
      glVertexPointer_(3, #GL_FLOAT, SizeOf(vert), @vertex(0)\x)
      glNormalPointer_(#GL_FLOAT, SizeOf(vert), @vertex(0)\nx)
           
      ;glDrawArrays_(#GL_POINTS, 0, ArraySize(vertex()))
      glDrawArrays_(#GL_TRIANGLES, 0, ArraySize(vertex()))
     
      glDisableClientState_(#GL_NORMAL_ARRAY)
      glDisableClientState_(#GL_VERTEX_ARRAY);
     
  SetGadgetAttribute(0, #PB_OpenGL_FlipBuffers, #True)
Until Event = #PB_Event_CloseWindow Or quit = 1
  Procedure findNumbers(s.s)
    ;Debug t
    If CreateRegularExpression(0, "[+-]?([0-9]*[.])?[0-9]+")
    If ExamineRegularExpression(0, s)   
        For i=0 To 2
         If NextRegularExpressionMatch(0)
          tmp(c) = ValF(RegularExpressionMatchString(0))
          c+1
         EndIf
        Next
      c=0
    EndIf
   
  Else
    Debug RegularExpressionError()
  EndIf
 
EndProcedure


 


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGL Gadget: Project points on to Mesh Model?
PostPosted: Sun Aug 04, 2019 4:21 pm 
Offline
Always Here
Always Here

Joined: Fri Oct 23, 2009 2:33 am
Posts: 5833
Location: Wales, UK
Nice work ApplePi :)

Actually, the binary STL files are extremely simple and so easy to read too. I have just got back to this project so your example is very very useful thank you.

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye