Advertisement

NURBS

Started by March 13, 2005 07:44 PM
5 comments, last by Dani008 19 years, 8 months ago
Hi I have created a 3d Model with NURBS curve in Maya, I am trying to transfer the Model into Opengl, Does Open Gl support NURBS? I have the start point , the end point and all the knots the NURBS curve, anyone know how can I use these information and draw the curve in OPENGL? Thanks [Edited by - Celesa on March 13, 2005 8:25:10 PM]
Honestly, I don't know what a NURBS curve is, but I can tell you for sure that OpenGL can't draw curves.
You have to split it in segments.
If I knew something more about NURBS I would give you some other advices.
Advertisement
OpenGL does indeed support parametric curves, look here for a short introduction to OpenGL evaluators.
You can also evaluate curves manually, see GameDev article.

Nevertheless I'd suggest saving your model as a poly-mesh instead. Unless you want to implement dynamic LOD, offline pre-tesselation of the NURBS surface seems to be the least complex approach.

Good luck,
Pat.

NURBS means "Nobody understands rational B-splines" ;-)

OpenGL doesn't REALLY support NURBS, but GLU has a NURBS implementation that draws NURBS by splitting the surface up into triangles. But you still have to decide how fine the tesselation should be IIRC.

Here is a link to the GLU functions. Have a look at gluNurbsSurface to get a starting point.

Here is a good example for the usage. (Search for NURBS in this page).

HTH, Lutz
Hi

Thanks for replying, I need to transfer the model in NURBS because I am buidling an application which compares the Polygon model with the Nurbs model.

I will take a look at the pages.
Thanks
some maya exporters + loaders. The advanced one handles NURBS. If you use gluNurbs or evaluators to render the model, expect it to be EXTREMELY SLOW. You'll need to evaluate the surface yourself, and perform a LOT of caching to give you any decent performance. My code doesn't handle trims by the way (though i think it loads the data as i recall).
Advertisement
I worked a bit with NURBS when learning OpenGL with "Jetzt lerne ich OpenGL"(german book).

Here is a piece of code in PureBasic:
XIncludeFile "OpenGL.pb"#WindowWidth = 640#WindowHeight = 480#WindowFlags = #PB_Window_TitleBar | #PB_Window_MaximizeGadget | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCenteredVersion = 10Procedure MyWindowCallback(WindowID, Message, wParam, lParam)Result = #PB_ProcessPureBasicEventsIf Message = #WM_SIZEglViewport_(0, 0, WindowWidth(), WindowHeight())Result = 1EndIfProcedureReturn ResultEndProcedureIf OpenWindow(0, 0, 0, #WindowWidth, #WindowHeight, #WindowFlags, "PBGL - Tutorial "+Str(Version))SetWindowCallback(@MyWindowCallback())hWnd = WindowID(0)pfd.PIXELFORMATDESCRIPTORhDC = GetDC_(hWnd)pfd\nSize = SizeOf(PIXELFORMATDESCRIPTOR)pfd\nVersion = 1pfd\dwFlags = #PFD_SUPPORT_OPENGL | #PFD_DOUBLEBUFFER | #PFD_DRAW_TO_WINDOWpfd\iLayerType = #PFD_MAIN_PLANEpfd\iPixelType = #PFD_TYPE_RGBApfd\cColorBits = 24pfd\cDepthBits = 32pixformat = ChoosePixelFormat_(hDC, pfd)SetPixelFormat_(hDC, pixformat, pfd)hrc = wglCreateContext_(hDC)wglMakeCurrent_(hDC, hrc)SwapBuffers_(hDC);a few startsettingsglEnable_(#GL_FOG)glEnable_(#GL_DEPTH_TEST)glEnable_(#GL_AUTO_NORMAL)glEnable_(#GL_CULL_FACE);now we create a terrain object called NURBSNURBS = gluNewNurbsRenderer_();and then we must have the control over the NURBS terrain:Dim uknots.f(7);horizontal pointsDim vknots.f(7);vertical pointsDim ctrlP.f(3, 3, 2);heighcontroling;now we set the terrainpointsFor u=0 To 3uknots(u) = 0.0uknots(u+4) = 1.0For v=0 To 3If u = 0vknots(v) = 0.0vknots(v+4) = 1.0EndIfctrlP(u, v, 0) = 0.8*((u/7)-0.5)ctrlP(u, v, 2) = 0.8*((v/7)-0.5)If (u=1 Or u=2) And (v=2 Or v=1) ;Create hill in the middle of the terrainIf u=1ctrlP(u, v, 1) = 0.5 ;in the middle it should be heighElsectrlP(u, v, 1) = 0.0EndIfElsectrlP(u, v, 1) = 0.0EndIfNextNextRepeatglClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT) ;Clear viewglLoadIdentity_()glScalef_(2.5, 2.5, 2.5)glTranslatef_(0.25, -0.25, 0.0) ;normally it isn't in the right positionglRotatef_(350.0, 1.0, -1.0, 0.0)glColor3f_(0.25, 0.5, 0.0) ;color of terrain = greengluBeginSurface_(NURBS) ;start of surfacegluNurbsSurface_(NURBS,8,@uknots(),8,@vknots(),3*4,3,@ctrlP(),4,4,#GL_MAP2_VERTEX_3) ;draw surfacegluEndSurface_(NURBS) ;end of surfaceSwapBuffers_(hDC) ;show allEvent = WindowEvent()Delay(5)Until Event = #PB_Event_CloseWindowEndEndIf; ExecutableFormat=; CursorPosition=5; FirstLine=3; EOF
Thanks

This topic is closed to new replies.

Advertisement