Links und Funktionen
Sprachumschaltung

Navigationspfad
Sie sind hier: Startseite / Probestudium / 2015 / WS I: 3D-Programmierung / Skripte / auto-mit-bedienfenster.py


Inhaltsbereich

auto-mit-bedienfenster.py

Python Source icon auto-mit-bedienfenster.py — Python Source, 7 KB (7720 bytes)

Dateiinhalt

# 3D-Objektklasse "convex"
# einfaches Auto
# mit "Schalttafel" zur Manipulation


from visual import *
from visual.controls import *


anzeige = display(x=0, y=0, width=400, height=400)

# ----------------- aus einfachen Objekten entsteht ein Auto -------------------------------------

radLV = ring(pos=(1,0,2), radius=0.4, thickness=0.25, color=color.gray(0.3), axis=(0,0,1))
radkap = pyramid(pos=(1,0,2.1),size=(0.2,0.5,0.5), color=color.gray(0.2), axis=(0,0,0.2))
radLH = ring(pos=(4,0,2), radius=0.4, thickness=0.25, color=color.gray(0.3), axis=(0,0,1))
radkap = pyramid(pos=(4,0,2.1),size=(0.2,0.5,0.5), color=color.gray(0.2), axis=(0,0,0.1))
radRV = ring(pos=(1,0,0), radius=0.4, thickness=0.25, color=color.gray(0.3), axis=(0,0,1))
radkap = pyramid(pos=(1,0,-0.1),size=(0.2,0.5,0.5), color=color.gray(0.2), axis=(0,0,-0.1))
radRH = ring(pos=(4,0,0), radius=0.4, thickness=0.25, color=color.gray(0.3), axis=(0,0,1))
radkap = pyramid(pos=(4,0,-0.1),size=(0.2,0.5,0.5), color=color.gray(0.2), axis=(0,0,-0.2))

fLichtR= sphere(pos=(0.1,0.5,0.3), radius=0.2, color=(0.9,0.9,0.6), material=materials.emissive)
fLichtL= sphere(pos=(0.1,0.5,1.7), radius=0.2, color=(0.9,0.9,0.6), material=materials.emissive)

rLichtL= ellipsoid(pos=(4.9,0.5,1.7), size=(0.1,0.1,0.2), color=color.red, material=materials.emissive)
rLichtR= ellipsoid(pos=(4.9,0.5,0.3), size=(0.1,0.1,0.2), color=color.red, material=materials.emissive)

rBlinkerL= ellipsoid(pos=(4.9,0.6,1.7), size=(0.1,0.1,0.2), color=color.orange, material=materials.emissive)
rBlinkerR= ellipsoid(pos=(4.9,0.6,0.3), size=(0.1,0.1,0.2), color=color.orange, material=materials.emissive)

dach = box(pos=(2.95,2,1), size=(1.9,0.05,1.7), color=color.magenta, material=materials.plastic, teil=1)
asaeuleR = box(pos=(1.7,1.5,0.15), height=0.05, width=0.05, axis=(0.70,1.0,0.1), color=color.magenta, material=materials.plastic, teil=1)
asaeulel = box(pos=(1.7,1.5,1.85), height=0.05, width=0.05, axis=(0.70,1.0,-0.1), color=color.magenta, material=materials.plastic, teil=1)
bSaeuleR = box(pos=(3,1.5,0.15), height=0.05, width=0.05, axis=(0.1,1,0.1), color=color.magenta, material=materials.plastic, teil=1)
bSaeuleL = box(pos=(3,1.5,1.85), height=0.05, width=0.05, axis=(0.1,1.0,-0.1), color=color.magenta, material=materials.plastic, teil=1)
cSaeuleR = box(pos=(4.2,1.5,0.15), height=0.1, width=0.05, axis=(0.70,-1.0,-0.1), color=color.magenta, material=materials.plastic, teil=1)
cSaeuleL = box(pos=(4.2,1.5,1.85), height=0.1, width=0.05, axis=(0.70,-1.0,0.1), color=color.magenta, material=materials.plastic, teil=1)
gestell = convex(pos=[(0.25,0,0),(0.25,0,2),(0,1,0),(0,1,2),(4.8,1,0),(4.8,1,2),(5,0,0),(5,0,2)], \
          color=color.magenta, material=materials.plastic, teil=1)

wScheibe = box(pos=(1.7,1.5,1), height=1.2, width=1.7, axis = (0.05,-0.035,0), color=color.white, opacity=0.2, material=materials.plastic) 
hScheibe = box(pos=(4.2,1.5,1), height=1.2, width=1.7, axis = (0.05,0.035,0), color=color.white, opacity=0.2, material=materials.plastic) 

vStoss = curve(pos=[(0.2,0.1,-0.1),(0.1,0.1,0),(0.1,0.1,2),(0.2,0.1,2.1)], radius=0.05, color=color.gray(0.7), material=materials.plastic)
hStoss = curve(pos=[(5.0,0.1,-0.1),(5.1,0.1,0),(5.1,0.1,2),(5.0,0.1,2.1)], radius=0.05, color=color.gray(0.7), material=materials.plastic)

innenraum = box(pos=(3,1,1), size=(3,0.1,1.8), color=color.black)
lenkrad = ring(pos=(1.8,1,1.5), radius=0.2, axis=(1,0.3,0), thickness=0.02, color=color.orange, material=materials.wood)
lehneL = cylinder(pos=(2.5,1,1.5), radius=0.3, axis=(0.15,-0.05,0), thickness=0.2, color=(0.8,0.6,0.1), material=materials.rough)
lehneR = cylinder(pos=(2.5,1,0.5), radius=0.3, axis=(0.15,-0.05,0), thickness=0.2, color=(0.8,0.6,0.1), material=materials.rough)
rueckbankR = cylinder(pos=(3.8,1,0.5), radius=0.3, axis=(0.15,-0.05,0), thickness=0.2, color=(0.8,0.6,0.1), material=materials.rough)
rueckbankM = cylinder(pos=(3.8,1,1.0), radius=0.3, axis=(0.15,-0.05,0), thickness=0.2, color=(0.8,0.6,0.1), material=materials.rough)
rueckbankL = cylinder(pos=(3.8,1,1.5), radius=0.3, axis=(0.15,-0.05,0), thickness=0.2, color=(0.8,0.6,0.1), material=materials.rough)


# -------Kontrollfenster--------------------------------

def setBackground():
    if anzeige.background==(0,0,0):
        anzeige.background=(1,1,1)
    else:
        anzeige.background=(0,0,0)

def setRender():
    if anzeige.show_rendertime:
        anzeige.show_rendertime=False
    else:
        anzeige.show_rendertime=True

def setStereo(modus):
    anzeige.stereo=modus

def setRange(obj):
    anzeige.range=obj.value

def setLicht():
    if len(anzeige.lights)==1:
        anzeige.lights = [distant_light(direction=(0.22, 0.44, 0.88), color=color.gray(0.8)),\
                          distant_light(direction=(-0.88, -0.22, -0.44), color=color.gray(0.3))]
    else:
        anzeige.lights = [distant_light(direction=(-0.88, -0.22, -0.44), color=color.gray(0.3))]
        
        
def setUserzoom():
    if anzeige.userzoom:
        anzeige.userzoom = False
    else:
        anzeige.userzoom = True

def setMaterial():
    for obj in anzeige.objects:
        try:
            if obj.teil:
                if obj.material == materials.plastic:
                    obj.material = materials.marble
                else:
                    obj.material = materials.plastic
        except:
            pass
        
def setUserspin():
    if anzeige.userspin:
        anzeige.userspin = False
    else:
        anzeige.userspin = True

def setCenter(obj):
    orientierung = {'rechts vorn':(0,1,0), 'links vorn':(0,1,2), 'links hinten':(5,1,2), 'rechts hinten':(5,1,0), 'mittig':(2.5,1,1)}
    anzeige.center=orientierung[obj]

def setColor(ra):
    for obj in anzeige.objects:
        try :
            if obj.teil:
                obj.color = color.hsv_to_rgb((ra.value,1,1))
        except:
            pass

# Kontrollfenster mit Steuerelementen: Schalter, Schieberegler, Menu-Button
cwindow = controls(title='Schalttafel 3D-Attribute', x=400, y=0, width=400, height=400, range=200)

ms = menu(pos=(-60,150), height=30, width=100, text='  Stereomodus  ')
ms.items.append(('--kein--', lambda: setStereo("nostereo")))
ms.items.append(('rot-cyan', lambda: setStereo("redcyan")))
ms.items.append(('gelb-blau', lambda: setStereo("yellowblue")))
ms.items.append(('ueber Kreuz', lambda: setStereo("crosseyed")))
ms.items.append(('Polarisation', lambda: setStereo("passive")))
ms.items.append(('Shutter-Brille', lambda: setStereo("active")))

ra = slider(pos=( -100,-50), width=10, length=200, axis=(1,0), min=0, max=1, action=lambda: setColor(ra))
bg = toggle(pos=(-100,10), width=30, height=30, text0='schwarz', text1='weiss', action=lambda: setBackground())
sr = toggle(pos=(0,10), width=30, height=30, text0='ohne rTime', text1='mit rTime', action=lambda: setRender())
au = toggle(pos=(-100,100), width=30, height=30, text0='Licht an', text1='Licht aus', action=lambda: setLicht())
zo = toggle(pos=(   0,100), width=30, height=30, text0='zoom +', text1='zoom -', action=lambda: setUserzoom())
uz = toggle(pos=( 100,100), width=30, height=30, text0='spin +', text1='spin -', action=lambda: setUserspin())
cv = toggle(pos=( 100, 10), width=30, height=30, text0='Glanz', text1='Marmor', action=lambda: setMaterial())


ce = menu(pos=(60,150), height=30, width=100, text='Kamerafokus')
ce.items.append(('vRechts', lambda: setCenter("rechts vorn")))
ce.items.append(('vLinks', lambda: setCenter("links vorn")))
ce.items.append(('hLinks', lambda: setCenter("links hinten")))
ce.items.append(('hRechts', lambda: setCenter("rechts hinten")))
ce.items.append(('mittig', lambda: setCenter("mittig")))

anzeige.center=(2.5,1,1)


while True:
    rate(50)
    cwindow.interact()

Funktionsleiste