diff --git a/examples/sphere/main.py b/examples/sphere/main.py index 8c88ccf..ebdb750 100644 --- a/examples/sphere/main.py +++ b/examples/sphere/main.py @@ -1,28 +1,32 @@ -import os -import math from kivy.app import App -from kivy.clock import Clock - -from kivy3 import Scene, Renderer, PerspectiveCamera, Material, Mesh -from kivy3.extras.geometries import GridGeometry, SphereGeometry from kivy.uix.floatlayout import FloatLayout +from kivy3 import Material +from kivy3 import Mesh +from kivy3 import PerspectiveCamera +from kivy3 import Renderer +from kivy3 import Scene +from kivy3.extras.geometries import GridGeometry +from kivy3.extras.geometries import SphereGeometry from kivy3.objects.lines import Lines +import math +import os # Resource paths _this_path = os.path.dirname(os.path.realpath(__file__)) shader_file = os.path.join(_this_path, "./blinnphong.glsl") -class MainApp(App): +class SphereExample(App): + """This is a basic example showcasing the Sphere Geometry. + """ + def build(self): - self.renderer = Renderer(shader_file=shader_file) - scene = Scene() + renderer = self.renderer = Renderer(shader_file=shader_file) + renderer.set_clear_color((0.2, 0.2, 0.2, 1.0)) + camera = PerspectiveCamera(45, 1, 0.1, 2500) - self.renderer.set_clear_color((0.2, 0.2, 0.2, 1.0)) - self.camera = camera - self.renderer.main_light.intensity = 5000 - root = ObjectTrackball(camera, 10) + renderer.main_light.intensity = 5000 geometry = SphereGeometry(radius=1) material = Material( @@ -33,7 +37,6 @@ def build(self): transparency=0.8, ) obj = Mesh(geometry, material) - scene.add(obj) # create a grid on the xz plane geometry = GridGeometry(size=(30, 30), spacing=1) @@ -45,13 +48,17 @@ def build(self): ) lines = Lines(geometry, material) lines.rotation.x = 90 + + scene = Scene() + scene.add(obj) scene.add(lines) - self.renderer.render(scene, camera) - self.renderer.main_light.intensity = 500 + renderer.render(scene, camera) + renderer.main_light.intensity = 500 + renderer.bind(size=self._adjust_aspect) - root.add_widget(self.renderer) - self.renderer.bind(size=self._adjust_aspect) + root = ObjectTrackball(camera, 10) + root.add_widget(renderer) return root def _adjust_aspect(self, inst, val): @@ -106,4 +113,4 @@ def do_rotate(self, touch): if __name__ == "__main__": - MainApp().run() + SphereExample().run()