Obj Wavefront importer 2.0

Everything related to 3D programming
User avatar
minimy
Enthusiast
Enthusiast
Posts: 721
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Obj Wavefront importer 2.0

Post by minimy »

A while ago I published some code (pretty bad) for loading obj wavefront. Now I bring the definitive version, or almost... :P

OBJ Wavefront importer 2.0

Import external object from file in format .obj wavefront. I think this open a door to import a more friendly format.

✓ Import vertex
✓ Import faces
✓ Import uv
✓ Import normals
✓ Import tangents.

Finally i can say this work fine.

Is only one procedure called LoadOBJMesh(filename$, meshID)
Params:
filename$ local or absolute file
meshID mesh number.
Return:
True (1) if all is done.

I know that like me, many of you are interested in this code. I think it is a good contribution to PureBasic's 3D system.

I had not shared it because with some complex meshes sometimes the program failed and crashed or the ogre system returned errors. Now I have tried it with quite complicated meshes like the one in the image and it works perfectly in all the cases I have tried.

I have decided to provide the code by private message.
Why do I do this? Because a lot of people who don't share anything, just pick up.
I know many won't like it, but it is what it is.
If you are interested, contact me and I will send it to you.

The code is not here and now is under licensed, but you can read the license and if you agree can contact me.!
Why licensed? Because i invert hundred hours to make this tool. Now is part of a commercial project.

Code: Select all

  ;{   LICENCIA/LICENSE
  
  ; LICENCIA PERSONALIZADA DE USO LIBRE CON ATRIBUCIÓN Y PARTICIPACIÓN ECONÓMICA
  ; CUSTOM FREE USE LICENSE WITH ATTRIBUTION AND ECONOMIC PARTICIPATION
  
  ; [NOMBRE DEL AUTOR][AUTHOR NAME]:	Toni M. (aka minimy)
  ; [TÍTULO DE LA OBRA][WORK TITLE]:	LoadOBJMesh
  ; [FECHA-DD/MM/AA][DATE-DD/MM/YY]:	03/11/2025
  ; [TYPE:] LICENSED AND REGISTERED.
  
  ; -------------------------------------------------------------------------------------------------------------------------------
  ; LICENCIA PERSONALIZADA DE USO LIBRE CON ATRIBUCIÓN Y PARTICIPACIÓN ECONÓMICA
  
  ; DESCRIPCIÓN:
  ; Código informático. Procedure para PureBasic (www.purebasic.com) que convierte objetos 3D. '.obj Wavefront' en 'mesh' para el motor gráfico OGRE (www.ogre3d.org).
  
  ; El autor [NOMBRE DEL AUTOR], en calidad de titular de los derechos de la obra descrita, otorga al usuario una licencia no exclusiva, libre y revocable para utilizar, copiar, modificar y distribuir dicha obra, bajo las siguientes condiciones:
  
  ; 1. ATRIBUCIÓN
  ; El usuario se compromete a reconocer de forma clara y visible la autoría de la obra en cualquier reproducción, modificación o distribución, incluyendo el siguiente texto:
  ; "Basado en la obra de [NOMBRE DEL AUTOR], utilizada bajo licencia personalizada con participación económica."
  
  ; 2. PARTICIPACIÓN ECONÓMICA
  ; Antes de comenzar a usar esta obra con fines comerciales debe contactar con el autor usando los medios proporcionados en este documento.
  ; Si el uso de esta obra genera ingresos directos o indirectos, el usuario se compromete a compartir el 10% de los beneficios netos obtenidos con el autor, salvo acuerdo específico entre las partes que estipule condiciones distintas.  
  ; El usuario deberá informar al autor sobre el uso comercial y los ingresos generados, y realizar el pago por los medios acordados.
  
  ; 3. LIMITACIONES
  ; No se permite revender esta obra sin modificación como producto independiente.  
  ; El incumplimiento de estas condiciones podrá dar lugar a la revocación de la presente licencia, incluso acciones legales.
  
  ; 4. CONTACTO
  ; Para acuerdos específicos, reportes de uso o pagos, contactar al autor en: tvcry@hotmail.com / info@tvcry.net
  
  ; -------------------------------------------------------------------------------------------------------------------------------
  ; CUSTOM FREE USE LICENSE WITH ATTRIBUTION AND ECONOMIC PARTICIPATION
  
  ; DESCRIPTION:
  ; Computer code. Procedure for PureBasic (www.purebasic.com) that converts 3D objects. '.obj Wavefront' to 'mesh' for the OGRE graphics engine (www.ogre3d.org).
  
  ; The author [AUTHOR NAME], as the rights holder of the described work, grants the user a non-exclusive, free, and revocable license to use, copy, modify, and distribute said work under the following conditions:
  
  ; 1. ATTRIBUTION
  ; The user agrees to clearly and visibly credit the original author in any reproduction, modification, or distribution, including the following text:
  ; "Based on the work by [AUTHOR NAME], used under a custom license with economic participation."
  
  ; 2. ECONOMIC PARTICIPATION
  ; Before you begin using this work for commercial purposes you should contact the author using the means provided herein.
  ; If the use of this work generates direct or indirect income, the user agrees to share 10% of the net profits obtained with the author, unless a specific agreement between the parties stipulates otherwise.  
  ; The user must inform the author about commercial use and generated income, and make payment through the agreed means.
  
  ; 3. LIMITATIONS
  ; Reselling this work without modification as a standalone product is not permitted.  
  ; Failure to comply with these conditions may result in revocation of this license, including legal action.
  
  ; 4. CONTACT
  ; For specific agreements, usage reports, or payments, contact the author at: tvcry@hotmail.com / info@tvcry.net
  ;}


Image

This organic model is much more complicated but the importer converts it exactly like the original.
Image


I apologize if something is confusing or the code seems written by a five-year-old. :mrgreen:

I'm fighting now with the .mesh format to be able to preview the mesh in canvas or image, without loading it in ogre, but the 'chunks' are worse than the cyberpunk 'chun' :lol:


I hope you enjoy using this in your projects.
Last edited by minimy on Fri Nov 21, 2025 2:42 pm, edited 4 times in total.
If translation=Error: reply="Sorry, Im Spanish": Endif
threedslider
Enthusiast
Enthusiast
Posts: 452
Joined: Sat Feb 12, 2022 7:15 pm

Re: Obj Wavefront importer 2.0

Post by threedslider »

Work here ! :D

But watch out from size and rotation for model :wink:
User avatar
minimy
Enthusiast
Enthusiast
Posts: 721
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: Obj Wavefront importer 2.0

Post by minimy »

Yee, youre right threeslider. Take care with the object size. I said here:
In case the object is not visible, check the scale of the object and use W and S to move the camera.
Be careful that the mouse moves the orientation of the camera. :mrgreen:
I hope you found any use for this. Thanks for comment!
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
skinkairewalker
Addict
Addict
Posts: 806
Joined: Fri Dec 04, 2015 9:26 pm

Re: Obj Wavefront importer 2.0

Post by skinkairewalker »

awesome, thanks :D
User avatar
minimy
Enthusiast
Enthusiast
Posts: 721
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: Obj Wavefront importer 2.0

Post by minimy »

Thanks skinkairewalker!
If any of you find a bug tell me please!
I won't solve the problem, but I'll be entertained. :lol:
Nahh is joke. I will try.
If translation=Error: reply="Sorry, Im Spanish": Endif
threedslider
Enthusiast
Enthusiast
Posts: 452
Joined: Sat Feb 12, 2022 7:15 pm

Re: Obj Wavefront importer 2.0

Post by threedslider »

minimy wrote: Tue Nov 18, 2025 1:58 pm I hope you found any use for this. Thanks for comment!
Yes it is useful and you are welcome :mrgreen:
User avatar
minimy
Enthusiast
Enthusiast
Posts: 721
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: Obj Wavefront importer 2.0

Post by minimy »

I've been seeing a lot of posts for years from people trying to convert obj to mesh.
Yee very useful.. Especially for grateful people. :P
He he, next time i will think if share or not... :mrgreen:

Now i have Mesh2objExport(), LoadSTL(), Mesh2stlExport(), MeshApplyUV() can change UV on the fly for any projjection, cubic, sphere, cylinder, planar, and others. Load3DS() and now im working in LoadGLTF() to load all in one. And binary mesh get data without ogre engine. Soon more... or not... :mrgreen:
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
skinkairewalker
Addict
Addict
Posts: 806
Joined: Fri Dec 04, 2015 9:26 pm

Re: Obj Wavefront importer 2.0

Post by skinkairewalker »

minimy wrote: Fri Nov 21, 2025 2:08 pm Yee very useful.. Especially for grateful people. :P
He he, next time i will think if share or not... :mrgreen:
Unfortunately, this is a minority, don't be upset if you don't receive the number of thanks you deserve...
Focus on the people who are truly grateful, they deserve recognition and our work!!
Post Reply