3D Lines

115 views
Skip to first unread message

Johanna Latt

unread,
May 25, 2018, 11:48:32 AM5/25/18
to Kivy users support
Hi everyone,

I am trying to use kivy to draw 3D lines and 3D spheres with openGL but I just can't find the right approach to get it to work. I want to draw multiple lines and spheres with different coordinates on every frame.

I got it to work in PyQt simply by using GL_LINES and glVertex3d as well as using the glutSolidSphere from OpenGL.GLUT, but I have no idea how to get that incorporated into kivy. I have looked at the few openGL/3D examples that Google gave me but they didn't really seem to be what I was looking for.

Can anyone point me into the right direction on how to achieve this?

Thanks a lot!

Pieter van der Meer

unread,
May 25, 2018, 12:15:28 PM5/25/18
to kivy-...@googlegroups.com
Have you looked at the "3DRendering" example? Probably you'll have to rebuild the Mesh() every frame if you want new coordinates every frame. But Mesh() just takes a nice (numpy) array of coordinates to display primitives in various modes. You can use PushMatrix() PopMatrix() and other GL like commands to set up the 3D world. 

Also see https://kivy.org/docs/examples/gen__canvas__mesh__py.html for more info on how using a mesh works in various modes.

Cheers!

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Pieter van der Meer
System engineer / Owner
Tasty Chips Electronics
www.tastychips.nl

Johanna Latt

unread,
May 25, 2018, 1:09:00 PM5/25/18
to Kivy users support
Hi Pieter,

thanks for the quick reply!

However, the Mesh-component is also just in 2D, isn't it? I am looking for something that takes z-coordinates as well. 
It is important for me that the lines overlap correctly according to their z-coordinate and that the viewer gets a sense of the placement of the lines in the 3D space. I also need the lines to be thicker than what you see in the example you posted - using the approach in PyQt that I mentioned I could simply set glLineWidth() but I don't see an option to adjust the line-width in the kivy-example.

Is there no way I can work with GL_LINES and glVertex3d in kivy? 



Am Freitag, 25. Mai 2018 12:15:28 UTC-4 schrieb Pieter van der Meer:
Have you looked at the "3DRendering" example? Probably you'll have to rebuild the Mesh() every frame if you want new coordinates every frame. But Mesh() just takes a nice (numpy) array of coordinates to display primitives in various modes. You can use PushMatrix() PopMatrix() and other GL like commands to set up the 3D world. 

Also see https://kivy.org/docs/examples/gen__canvas__mesh__py.html for more info on how using a mesh works in various modes.

Cheers!
On Fri, May 25, 2018 at 5:48 PM, Johanna Latt <johanna...@gmail.com> wrote:
Hi everyone,

I am trying to use kivy to draw 3D lines and 3D spheres with openGL but I just can't find the right approach to get it to work. I want to draw multiple lines and spheres with different coordinates on every frame.

I got it to work in PyQt simply by using GL_LINES and glVertex3d as well as using the glutSolidSphere from OpenGL.GLUT, but I have no idea how to get that incorporated into kivy. I have looked at the few openGL/3D examples that Google gave me but they didn't really seem to be what I was looking for.

Can anyone point me into the right direction on how to achieve this?

Thanks a lot!

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Pieter van der Meer

unread,
May 25, 2018, 1:32:12 PM5/25/18
to kivy-...@googlegroups.com
thick lines are best done with polygons (cylinders probably in your case).. native GL thick lines will look different on different machines. (Although you could be on a single platform, i don't know?) using Kivy's 3D commands you can transform 3D space coordinates to 2D and use that for your mesh.. 

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

ZenCODE

unread,
May 25, 2018, 2:18:06 PM5/25/18
to Kivy users support

Johanna Latt

unread,
May 25, 2018, 2:46:12 PM5/25/18
to Kivy users support
Thanks for your thoughts!

Both options don't really seem feasible for me though since they are way more complex than what I need - I don't want to have to calculate all the vertices of a 3D mesh first to then convert it back to 2D. I simply want a line between two 3D points. 

For now I just went with normal kivy Lines() and made the draw order depend on the z-coordinates of the end-points of each line to get them to overlap correctly. Not ideal, since I still don't get the 3D look in terms of the thickness of the lines changing depending on the depth, but at least it isn't nearly as complex as having to dynamically calculate vertex-coordinates for the whole mesh on each frame.

(I am on a single platform by the way so I don't really have to bother with different machines' behaviors)

Am Freitag, 25. Mai 2018 14:18:06 UTC-4 schrieb ZenCODE:
 
Reply all
Reply to author
Forward
0 new messages