Giter VIP home page Giter VIP logo

kivy3dgui's Introduction

kivy3dgui

Kivy 3D. A pure Kivy library to display and interact with Kivy widgets in a 3D mesh.

If you want to help with the development you can mail me: [email protected]

It's easy to test, just download the code a run the examples. Enjoy it!!!

You can watch a video example here. Another video for Tour3D Example.

Work in progress

The 3D Editor is in the early stage. Baby steps, many issues :) anyway, you can test it at editor_3d branch.

How to use

Step 1

Start by importing the Layout3D. This layout manages 3D Nodes but behaves just like a normal Kivy FloatLayout.

#:kivy 1.0
#: import Layout3D kivy3dgui.layout3d

Step 2

Create a Layout3D, which you can also do from Python.

Layout3D:
    id: par #id for Layout3D, could be referenced just like any Kivy Widget
    size_hint: (1.0, 1.0)
    canvas_size: (1366, 768) # Canvas resolution
    post_processing: False # Post-processing effects (bloom, hdr,...)

You can change the position of the camera using the 'lookat' property, which sets the gluLookAt transformation. It defaults to (0, 0, 10, 0, 0, 0, 0, 1, 0).

Step 3

Create nodes and add them to the Layout3D. Nodes are used to apply 3D effects, transformations and display 3D meshes in Kivy layouts.

Nodes may be a set of 3D meshes (obj format is only supported at now). Be sure to set the UV mapping correctly. If you add a FloatLayout to the node it will be used as a texture for the meshes and you will be able to interact with the widgets that are seen on the surface of the meshes, no matter the shape: touch events are accurately translated to preserve behavior.

The possibilities are endless. Just use your imagination.

    Node:
        id: Node1
        name: 'Node 0'
        rotate: (90, 0.3, 1, 0)  # Angle and x, y, z axis of the rotation matrix
        scale: (0.4, 0.4, 0.4)  # x, y, z of scaling matrix
        translate: (20, -10.0, -110)  # x, y, z of translation matrix
        effect: True
        meshes: ("./data/obj/sphere.obj", ) #List of meshes (obj only)

For more detail on these parameters and matrices, please see the glRotate matrix, glScale matrix and glTranslate documentation.

Step 4

Create interaction widgets. The root widgets for Nodes must be a Layout3D. All its children will use this as the texture for the set of meshes. As mentioned, you will be able to interact with the widgets.

        FloatLayout:
            canvas:
                Color:
                    rgb: 1, 1, 1,0.1
                Rectangle:
                    size: self.size
                    pos: self.pos
                    source: "./data/imgs/background.jpg"
            size_hint: (1.0, 1.0)
            Button:
                pos_hint: {"x":0, "y":0 }
                size_hint: (None, None)
                text: "Hello"

Screenshot

kivy3dgui's People

Contributors

kpiorno avatar moonpyx avatar schoolsplay avatar zen-code avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kivy3dgui's Issues

init takes no parameters

Traceback (most recent call last):
File "C:\Users\Harry\Desktop\mykivy\kivy3dgui-master\example.py", line 197, in
ExampleApp().run()
File "C:\Users\Harry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\app.py", line 802, in run
root = self.build()
File "C:\Users\Harry\Desktop\mykivy\kivy3dgui-master\example.py", line 191, in build
''')
File "C:\Users\Harry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\lang\builder.py", line 381, in load_string
widget = Factory.get(parser.root.name)()
File "C:\Users\Harry\Desktop\mykivy\kivy3dgui-master\kivy3dgui\layout3d.py", line 159, in init
self.create_canvas()
File "C:\Users\Harry\Desktop\mykivy\kivy3dgui-master\kivy3dgui\layout3d.py", line 218, in create_canvas
canvas_size=self.canvas_size, id="CANVAS3D")
File "C:\Users\Harry\Desktop\mykivy\kivy3dgui-master\kivy3dgui\canvas3d.py", line 226, in init
super(Canvas3D, self).init(**kwargs)
File "C:\Users\Harry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\uix\floatlayout.py", line 65, in init
super(FloatLayout, self).init(**kwargs)
File "C:\Users\Harry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\uix\layout.py", line 76, in init
super(Layout, self).init(**kwargs)
File "C:\Users\Harry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\kivy\uix\widget.py", line 337, in init
super(Widget, self).init(**kwargs)
File "kivy_event.pyx", line 254, in kivy._event.EventDispatcher.init (kivy_event.c:5332)
TypeError: object.init() takes no parameters

Objects not showing correctly

Any idea why this happens for some objects?
Kivy vesion: 2.0.0rc4
Objects here

from kivy.app import App
from kivy.lang import Builder

class ExampleApp(App):

    def build(self):
        root = Builder.load_string('''

#: import Layout3D kivy3dgui.layout3d
Layout3D:
    id: par
    size_hint: (1.0, 1.0)
    Node:
        id: Node1
        name: 'Node 0'
        rotate: (270, 90, 0, 0)
        # scale: (0.2, 0.2, 0.2)
        translate: (0, -10, -50)
        meshes: ("./untitled.obj", )
        FloatLayout:
            canvas:
                Color:
                    rgb: 1, 1, 1, 1
                Rectangle:
                    size: self.size
                    pos: self.pos
        ''')
        self.root = root
        return root


if __name__ == '__main__':
    ExampleApp().run()

Untitled

Suggestion: default mesh for a Node

In order to work 'out of the box', would it not be best to have a default mesh that displays as close to standard FloatLayout as much as possible.

The aim to to have it just work, with as few 'surprises' as possible e.g. having to create a mesh. Many users will now know what a mesh is, so a default, simple mesh makes sense?

editor3d does not statt

Note: all other demos run properly

[INFO ] [CutBuffer ] cut buffer support enabled
Traceback (most recent call last):
File "editor3d.py", line 445, in
Minimal3dApp().run()
File "/usr/lib/python2.7/dist-packages/kivy/app.py", line 829, in run
root = self.build()
File "editor3d.py", line 238, in build
self.space_editor = SpaceEditor(layout3d, self, self.editor_manager)
File "/tmp/kivy3dgui/editor/space_editor.py", line 37, in init
node = Builder.load_string(dedent(axis.format(e, colors[i])))
File "/usr/lib/python2.7/dist-packages/kivy/lang/builder.py", line 405, in load_string
rule_children=rule_children)
File "/usr/lib/python2.7/dist-packages/kivy/lang/builder.py", line 707, in _apply_rule
e), cause=tb)
kivy.lang.builder.BuilderException: Parser: File "", line 9:
...
7: always_on_top: True
8: receive_shadows: False

9: meshes: ("./editor/meshes/x-rot-axis.obj",)
10: Button:
11: id: c_button
...
AttributeError: 'NoneType' object has no attribute 'add_node'
File "/usr/lib/python2.7/dist-packages/kivy/lang/builder.py", line 700, in _apply_rule
setattr(widget_set, key, value)
File "kivy/weakproxy.pyx", line 35, in kivy.weakproxy.WeakProxy.setattr
File "kivy/properties.pyx", line 497, in kivy.properties.Property.set
File "kivy/properties.pyx", line 839, in kivy.properties.ListProperty.set
File "kivy/properties.pyx", line 544, in kivy.properties.Property.set
File "kivy/properties.pyx", line 599, in kivy.properties.Property.dispatch
File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
File "kivy/_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
File "/tmp/kivy3dgui/kivy3dgui/node.py", line 303, in on_meshes
self.parent.add_node(self)

Positioning and sizing nodes in 3d canvas

Hi dear sir,
I would like to know how to set a node parameters to adapt position and size. For example, I would like a node to be a button which can rotate on pressed. Imagine in your checker example. You have two buttons in the left top corner. I would like these buttons were two nodes and they stayed in that position as window resizes and changed size accordingly.

Best regards

Issues on loading large obj files

engine.zip

I get the following error when loading large obj files. I have attached the concerned obj file and the code file as well.
3d_render.zip

kivy.graphics.vertex_instructions._ensure_ushort_view OverflowError: value too large to convert to unsigned short

checkers.py crashes on a touchscreen with kivy 2.1

On a desktop with a mouse everything works ok.
But on a touchscreen, HP All-in-One system the checkers.py crashed. I suspect the problem lies in the fact that on a touchscreen a "touch_move" event is generated iso a "touch_up/down".
Both systems are Ubuntu 22.04 with a python v3.8 virtual environment with kivy 2.1 installed and the kivy3dgui placed inside the tree.

To reproduce, start checkers.py and touch any stone.

This is the complete traceback:

[.[1;32mINFO.[0m   ] [Logger      ] Record log in /home/user/.kivy/logs/kivy_22-09-22_5.txt
[.[1;32mINFO.[0m   ] [Kivy        ] v2.1.0
[.[1;32mINFO.[0m   ] [Kivy        ] Installed at "/opt/App/.venv3.8/lib/python3.8/site-packages/kivy/__init__.py"
[.[1;32mINFO.[0m   ] [Python      ] v3.8.13 (default, Apr 19 2022, 02:32:06)
[GCC 11.2.0]
[.[1;32mINFO.[0m   ] [Python      ] Interpreter at "/opt/App/.venv3.8/bin/python3"
[.[1;32mINFO.[0m   ] [Logger      ] Purge log fired. Processing...
[.[1;32mINFO.[0m   ] [Logger      ] Purge finished!
[.[1;32mINFO.[0m   ] [Factory     ] 189 symbols loaded
[.[1;32mINFO.[0m   ] [ImageLoaderFFPy] Using ffpyplayer 4.3.1
[.[1;32mINFO.[0m   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_ffpyplayer
[.[1;32mINFO.[0m   ] [Text        ] Provider: sdl2
[.[1;32mINFO.[0m   ] [Window      ] Provider: sdl2
[.[1;32mINFO.[0m   ] [GL          ] Using the "OpenGL" graphics system
[.[1;32mINFO.[0m   ] [GL          ] Backend used <sdl2>
[.[1;32mINFO.[0m   ] [GL          ] OpenGL version <b'4.6 (Compatibility Profile) Mesa 22.0.1'>
[.[1;32mINFO.[0m   ] [GL          ] OpenGL vendor <b'Intel'>
[.[1;32mINFO.[0m   ] [GL          ] OpenGL renderer <b'Mesa Intel(R) UHD Graphics 610 (CFL GT1)'>
[.[1;32mINFO.[0m   ] [GL          ] OpenGL parsed version: 4, 6
[.[1;32mINFO.[0m   ] [GL          ] Shading version <b'4.60'>
[.[1;32mINFO.[0m   ] [GL          ] Texture max size <16384>
[.[1;32mINFO.[0m   ] [GL          ] Texture max units <32>
[.[1;32mINFO.[0m   ] [Window      ] auto add sdl2 input provider
[.[1;32mINFO.[0m   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[.[1;32mINFO.[0m   ] [GL          ] NPOT texture support is available
[.[1;32mINFO.[0m   ] [Shader      ] Read </opt/App/BtpKivy_Xf_16.6/kivy3dgui/gles2.0/toonshader/toon_shadows.glsl>
[.[1;32mINFO.[0m   ] [Shader      ] Read </opt/App/BtpKivy_Xf_16.6/kivy3dgui/gles2.0/shaders/shadowpass.glsl>
[.[1;32mINFO.[0m   ] [Shader      ] Read </opt/App/BtpKivy_Xf_16.6/kivy3dgui/gles2.0/shaders/selection.glsl>
[.[1;32mINFO.[0m   ] [Shader      ] Read </opt/App/BtpKivy_Xf_16.6/kivy3dgui/gles2.0/shaders/dop.glsl>
[.[1;32mINFO.[0m   ] [ProbeSysfs  ] device match: /dev/input/event8
[.[1;32mINFO.[0m   ] [MTD         ] Read event from </dev/input/event8>
[.[1;32mINFO.[0m   ] [Base        ] Start application main loop
[.[1;32mINFO.[0m   ] [MTD         ] </dev/input/event8> range position X is 0 - 4095
[.[1;32mINFO.[0m   ] [MTD         ] </dev/input/event8> range position Y is 0 - 4095
[.[1;32mINFO.[0m   ] [MTD         ] </dev/input/event8> range touch major is 0 - 0
[.[1;32mINFO.[0m   ] [MTD         ] </dev/input/event8> range touch minor is 0 - 0
[.[1;32mINFO.[0m   ] [MTD         ] </dev/input/event8> range pressure is 0 - 255
[.[1;32mINFO.[0m   ] [MTD         ] </dev/input/event8> axes invertion: X is 0, Y is 0
[.[1;32mINFO.[0m   ] [MTD         ] </dev/input/event8> rotation set to 0
[.[1;32mINFO.[0m   ] [Base        ] Leaving application in progress...
 Traceback (most recent call last):
   File "checker.py", line 136, in <module>
     CheckerApp().run()
   File "/opt/App/.venv3.8/lib/python3.8/site-packages/kivy/app.py", line 955, in run
     runTouchApp()
   File "/opt/App/.venv3.8/lib/python3.8/site-packages/kivy/base.py", line 574, in runTouchApp
     EventLoop.mainloop()
   File "/opt/App/.venv3.8/lib/python3.8/site-packages/kivy/base.py", line 339, in mainloop
     self.idle()
   File "/opt/App/.venv3.8/lib/python3.8/site-packages/kivy/base.py", line 383, in idle
     self.dispatch_input()
   File "/opt/App/.venv3.8/lib/python3.8/site-packages/kivy/base.py", line 334, in dispatch_input
     post_dispatch_input(*pop(0))
   File "/opt/App/.venv3.8/lib/python3.8/site-packages/kivy/base.py", line 263, in post_dispatch_input
     listener.dispatch('on_motion', etype, me)
   File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
   File "/opt/App/.venv3.8/lib/python3.8/site-packages/kivy/core/window/__init__.py", line 1662, in on_motion
     self.dispatch('on_touch_move', me)
   File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
   File "/opt/App/.venv3.8/lib/python3.8/site-packages/kivy/core/window/__init__.py", line 1689, in on_touch_move
     if w.dispatch('on_touch_move', touch):
   File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
   File "/opt/App/.venv3.8/lib/python3.8/site-packages/kivy/uix/widget.py", line 600, in on_touch_move
     if child.dispatch('on_touch_move', touch):
   File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
   File "/opt/App/BtpKivy_Xf_16.6/kivy3dgui/canvas3d.py", line 770, in on_touch_move
     if 'right' in t_touch.button:
 TypeError: argument of type 'NoneType' is not iterable

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.