Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

15.) Cleanup sphere example #22

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions examples/sphere/main.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -106,4 +113,4 @@ def do_rotate(self, touch):


if __name__ == "__main__":
MainApp().run()
SphereExample().run()