Oxygen Basic

Programming => Problems & Solutions => Topic started by: Patrice Terrier on January 15, 2015, 05:37:10 AM

Title: Very impressed
Post by: Patrice Terrier on January 15, 2015, 05:37:10 AM
Charles--

I did check all your OpenGL demo, and i must say that i have been very impressed by the huge amount of work you have done with O2.

Congratulations!

...


Title: Re: Very impressed
Post by: Charles Pegge on January 15, 2015, 11:04:14 AM
Thank you, Patrice.

It certainly accumulates, and I am still intent upon producing a full OpenGL GUI :)
Title: Re: Very impressed
Post by: Patrice Terrier on January 16, 2015, 03:09:17 AM
Charles--

Speaking of full OpenGL GUI

Do you remember this The Panther GUI demo video (http://www.zapsolution.com/preview/PantherDemo.zip)

...

Title: Re: Very impressed
Post by: Patrice Terrier on January 16, 2015, 05:14:05 AM
Charles--

Here is a screen shot of a wavefront object, rendered with my own viewer, i would like to achieve something similar for strereolithography, because STL files are getting more popular now because of the new 3D printers

(http://www.zapsolution.com/pictures/chopper.png)

...
Title: Re: Very impressed
Post by: Charles Pegge on January 16, 2015, 02:04:13 PM
Yes Patrice, I remember the Panther Project - nice skins :)

STL:
Standard Tesselation Language
aka
Stereo Lithography

In STL There does not seem to be a fixed standard for defining colors, materials and other attributes, but it looks easily do-able in other respects.

http://en.wikipedia.org/wiki/STL_%28file_format%29
Title: Re: Very impressed
Post by: Charles Pegge on January 18, 2015, 12:33:23 PM
Patrice,

I have got STL working in the  o2 projectsA/OpenglCns framework.

Here is the rendering function in OxygenBasic, for both text and binary formats:

It won't need much work for a C++ interpretation :)

Code: OxygenBasic
  1.   string STLfilename ' loaded file
  2.  string status      ' info about file
  3.  float  smax        ' max scalar size
  4.  '
  5.  function ModelRender()
  6.   ======================
  7.   indexbase 1
  8.   string d  'STRING FOR STL FILE DATA
  9.  string er 'READING ERROR MESSAGE
  10.  sys    le 'LENGTH OF STRING
  11.  sys    n  'FACET COUNT
  12.  sys    tf 'TEXT FORMAT FLAG
  13.  '
  14.  getfile stlfilename,d
  15.  
  16.   if not d then
  17.     er="Problem: Please check Filename and location " stlfilename
  18.     goto done
  19.   end if
  20.  
  21.   le=len d
  22.  
  23.  
  24.   'TEXT FORMAT
  25.  ============
  26.  
  27.   /*
  28.   solid name
  29.   where name is an optional string (though if name is omitted there must still be a space after solid). The file continues with any number of triangles, each represented as follows:
  30.  
  31.   facet normal ni nj nk
  32.     outer loop
  33.         vertex v1x v1y v1z
  34.         vertex v2x v2y v2z
  35.         vertex v3x v3y v3z
  36.     endloop
  37.   endfacet
  38.   */
  39.  
  40.   string wr   'EXTRACTED WORDS
  41.  string name 'NAME OF SOLID
  42.  sys    i=1  'STRING INDEXER
  43.  string t    'TEMP HEADER STRING
  44.  
  45.   t=left d,80
  46.   i=instr t,"solid "
  47.   'if i<>1 then
  48.  if i=0 then
  49.     goto BinaryFormat
  50.   else
  51.     tf=1
  52.   end if
  53.  
  54.   StepWord d,i
  55.   name=GetWord d,i
  56.  
  57.   sys p=strptr(d) -1 'DATA STRING POINTER BASE
  58.  float  v[3]        'VERTEX OR NORMAL
  59.  '
  60.  macro ReadVector(v)
  61.   'READ NUMBERS DIRECTLY FROM STL STRING
  62.  StepWord d,i : v[1]=valat p+sttw
  63.   StepWord d,i : v[2]=valat p+sttw
  64.   StepWord d,i : v[3]=valat p+sttw
  65.   end macro
  66.   '
  67.  glBegin GL_TRIANGLES
  68.   smax=0
  69.   do
  70.     wr=GetWord d,i
  71.     if ascw=0 then exit do
  72.     if wr="normal" then
  73.       ReadVector v : glNormal3fv v
  74.       n++
  75.     elseif wr="vertex" then
  76.       ReadVector v : glVertex3fv v
  77.   if v[1]>smax then smax=v[1]
  78.   if v[2]>smax then smax=v[2]
  79.   if v[3]>smax then smax=v[3]
  80.     end if
  81.   end do
  82.   glEnd
  83.  
  84.   goto done
  85.  
  86.  
  87.   'BINARY FORMAT
  88.  ==============
  89.  
  90.   BinaryFormat:
  91.  
  92.   /*
  93.   UINT8[80] – Header
  94.   UINT32 – Number of triangles
  95.  
  96.   foreach triangle
  97.   REAL32[3] – Normal vector
  98.   REAL32[3] – Vertex 1
  99.   REAL32[3] – Vertex 2
  100.   REAL32[3] – Vertex 3
  101.   UINT16 – Attribute byte count
  102.   */
  103.  
  104.   type STLHeader
  105.   byte  hbytes[80]
  106.   dword count
  107.   end type
  108.  
  109.   packed
  110.   type SurfaceElement
  111.   float xn,yn,zn   'NORMAL
  112.  float x1,y1,z1   'VERTEX 1
  113.  float x2,y2,z2   'VERTEX 2
  114.  float x3,y3,z3   'VERTEX 3
  115.  word  AttribSize 'N BYTES DATA FOLLOWING
  116.  end type
  117.  
  118.   if len(d)<sizeof(STLHeader) then
  119.     er="binary file too small"
  120.     goto done
  121.   end if
  122.  
  123.  
  124.   p=strptr d
  125.   stlheader h at (p)
  126.   n=h.count
  127.   if n*sizeof(SufaceElement)+sizeof(STLHeader)>le then
  128.     er="corrupt element count " n
  129.     goto done
  130.   end if
  131.  
  132.   SurfaceElement s at (p+sizeof(STLHeader))
  133.  
  134.   'OPENGL READ IN TRIANGLES
  135.  
  136.   glBegin GL_TRIANGLES
  137.   smax=0
  138.   for i=1 to n
  139.     glNormal3fv s.xn
  140.     glVertex3fv s.x1
  141.     glVertex3fv s.x2
  142.     glVertex3fv s.x3
  143.     if s.x1>smax then smax=s.x1
  144.     if s.y1>smax then smax=s.y1
  145.     if s.z1>smax then smax=s.z1
  146.     if s.x2>smax then smax=s.x2
  147.     if s.y2>smax then smax=s.y2
  148.     if s.z2>smax then smax=s.z2
  149.     if s.x3>smax then smax=s.x3
  150.     if s.y3>smax then smax=s.y3
  151.     if s.z3>smax then smax=s.z3
  152.     @s+=sizeof(s) + s.AttribSize 'STEP
  153.  next
  154.   glEnd
  155.    
  156.   done:
  157.   if er then
  158.     status=er
  159.   else
  160.     if tf then status="Text File : " else status="Binary File : "
  161.     status+=str(n)+" Facets : " str(smax,2) " Max dimension"
  162.   end if
  163.   end function 'ModelRender
  164.  

Some sources for STL files:

http://cnc-step.de/en/service-support/downloads/free-stl-files-and-3d-cad-software.html
http://www.thingiverse.com/thing:558600/#files
http://3dprintingforbeginners.com/3d-model-repositories/



.
Title: Re: Very impressed
Post by: Patrice Terrier on January 21, 2015, 12:08:55 PM
Thank you Charles !

I am in the slow process of porting my wavefront obj reader to C++.
Once done i shall add the STL feature.

See the screen shot, this object is made of nearly 1 000 000 triangles, i have been able to reduce the time to load it from 72 secondes down to 7 secondes... (i am happy)

...


.
Title: Re: Very impressed
Post by: Charles Pegge on January 22, 2015, 03:45:09 AM
Are you tempted to get a 3D printer, Patrice?

I'm curious about this model:

Checking Out the Ultimaker 2 Series of 3D Printers
https://www.youtube.com/watch?v=Sz77Tq9xzpM
--
Ultimaker 2: 3D Printing a Dragon
https://www.youtube.com/watch?v=dKPxJW65IQg
--
Ultimaker 2 Making Of Pixar Lamp With LED And Switchbox
https://www.youtube.com/watch?v=qixurWTE_T4
--
(https://www.igo3d.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/u/l/ultimaker_2_3d_printer_front_2_igo3d_4.jpg)
Title: Advanced OpenGL programming
Post by: Patrice Terrier on January 22, 2015, 05:07:04 AM
I think it is a technlogy of the future.
I have seen that in China they are even starting to build simple houses using this process, taking just a fraction of time that would take to build it the usual way.

Here is the link to download the Hunter.obj file i have used to create the screen shot in my previous post.
http://www.zapsolution.com/preview/Hunter.zip (http://www.zapsolution.com/preview/Hunter.zip)
It takes 17 secondes to Blender to render it, and only 7 secondes into mine :)

If interrested i could send you the source code of my wavefront object viewer, definitly aimed to advanced OpenGL programmers like yourself. ;)

...
Title: Re: Advanced OpenGL programming
Post by: Mike Lobanovsky on January 22, 2015, 05:37:04 AM
If interrested i could send you the source code of my wavefront object viewer, definitly aimed to advanced OpenGL programmers like yourself. ;)

If that "you" doesn't effectively stand for "you alone", than perhaps some other humble but rather advanced OpenGL programmers on this forum might enjoy getting access to the said source code as well? ;)
Title: About YOU
Post by: Patrice Terrier on January 22, 2015, 05:54:28 AM
YOU, was first intended to Charles, because he knows my coding style since the time of the BassBox project.

But it could be extended to more, familiar with the syntax used in my PowerBASIC GDImage projects.

I am working on the C++ version.

Note: It is intended to work on I7  8)

...
Title: Re: About YOU
Post by: Mike Lobanovsky on January 22, 2015, 09:00:40 AM
Actually, I read and write code in Intel and AT&T assembler, C and Delphi, C++ and Java, Python and Lua, and a multitude of BASIC dialects with almost equal proficiency, and I've been doing that for a living in recent 10 years or so. I can assure you reading PowerBASIC code wouldn't be too much of a problem for me either, whatever the actual coding style may be, SDK or DDT, whatever.

I used to create my own loaders for various open-spec 3D model formats as well, both static and animated, and OpenGL renderers to match. I used to take part in hacking proprietary 3D model formats of a few popular modern video games with a view to modding their visual content and game scenario. Snapshots taken in my own OpenGL rendering engine can be found on this forum too.

Never mind my inquiry though. I already regret having meddled with the topic so please do me a favor and dismiss it altogether as irrelevant. :)
Title: Re: Very impressed
Post by: JRS on January 22, 2015, 09:12:46 AM
I got an idea. Why don't you and Patrice agree to leave your egos at the door and accept the fact you both are VERY talented programmers that would be more productive working together than apart.

Title: Re: Very impressed
Post by: Frankolinox on January 22, 2015, 09:23:23 AM
question general: is there any chance or realistic way to load a lightwave *.obj file (or converted *.MTL file) to oxygenbasic (openGL) ? may be it's possible to load other objects / models (cars, houses etcpp) into oxygen, but how?

thanks, regards, frank
Title: Re: Very impressed
Post by: Patrice Terrier on January 22, 2015, 09:50:40 AM
Mike--

My purpose was not to offend you or anybody else.
It is just because i don't know who are the peoples from this forum, and their OpenGL leverage.

I shall post a link to the PowerBASIC/GDImage project, altogether with the wavefront object source code, and a couple of my best .OBJ files.

It is targeted to work on I7 and with nVidia graphic cards, thus i don't know if it would work on I5 and Intel graphic's.

...

Title: Re: Very impressed
Post by: Charles Pegge on January 22, 2015, 12:21:23 PM
Yes, many thanks, Patrice. :)

Your source code would be very helpful. I see that obj files are substantially more complex than STL files. An STL text file of your model above would be about 150 meg, since the vertices of each triangle have to be listed, regardless of common points.

I also heard about the 3d house printing:

http://www.theguardian.com/technology/video/2014/apr/29/3d-printer-builds-houses-china-video

http://3dprint.com/12933/3d-printed-castle-complete/

 
Title: Re: Very impressed
Post by: Patrice Terrier on January 23, 2015, 12:05:49 AM
Quote
I see that obj files are substantially more complex than STL files.

Yes, have a look at the mobj_dll.bas source code, that was a huge piece of work that kept me busy for while. And i had a hard time to figure how to write the cache iterator in PB (there is still room there to speed up the code).

...

Title: Re: Very impressed
Post by: Mike Lobanovsky on January 23, 2015, 09:27:43 PM
Hi Patrice and John,

My purpose was not to offend you or anybody else.
Why don't you ... leave your egos at the door

I wasn't feeling offended in the least. In fact, I realized that Patrice was new here and my post was just an attempt at self-presentation, nothing more, nothing less. I can only regret if my wording didn't really produce the intended impression, and especially on you, John.

Quote from: Patrice Terrier
... thus i don't know if it would work on I5 and Intel graphic's.

While my motherboard does have an on-board integrated Intel graphics chip that drives my left-side monitor that I'm usually using to host my text-mostly windows with reference data, tables, manuals and GDI(+) graphics, the MB is a special make that is compatible with, and certified for, nVidia's SLI Technology (http://www.nvidia.co.uk/object/sli_technology_overview_uk.html). The two GeForces that are mentioned in my forum signature are identical premium makes of nVidia 8600 graphics cards with 1GB on-board video memory each, bridged on this MB in the aforesaid SLI configuration. While the cards aren't top-notch by modern standards any more (it's been 5 years since I had them installed first on my previous, older Core2 Duo MB), they are compatible up to DX10 and they still outperform in this configuration many of nVidia's more modern video cards hosted apiece in the motherboards that don't support SLI.

What concerns i7 vs. i5, I don't think the difference will be so very noticeable, especially if i5's clock frequency happens to be higher than that of i7.

Quote from: Patrice Terrier
I shall post a link to ... the wavefront object source code ...

Thank you very much. I'm looking forward to that chance to get acquainted with yet more of your superior talents. :)