Embedded Python

K3Studio has embedded Python. Started from a shell user gets a standard command line with Python prompt.
The embedding consists of C wrappers created from headers (.i files resp.) with SWIG which also generates appropriate .py script files. The main application has interface described in k3studio.py but every plugin can have its own Python interface. The .py files are located in KDEPREFIX/apps/k3studio/python/.
Use dir() to see what's available.

Example 1

Here we create point, paint it, change its coordinates and paint it again.

r=net().root() 		// get the root of network 
p1=K3Point(r) 		// create the point p1, child of root 
paint()			// change are reflected on area(s)
p1.setXyz(10,10,10) 	// set new p1 coordinates
paint()			// again changes are reflected

Example 2

This example demonstrates how to play with camera. We rotate the scene (camera) around vector (0,0,1) in 5 degrees steps - K3Studio uses quaternions for rotations. Note the peq() function.

c=area().camera()	// get the camera node
for i in range(0,359,5): 	
	c.rotate(5,0,0,1)
	paint()
	peq()		// you can play with the scene while this loop is running

Example 3

This example demonstrates how to play with lights. We create one sphere and two points - which are set to be lights. Then the lights rotate around the sphere. Note that only the first light is on (OpenGL default). You can turn on the second light in e.g. Configure/Lighting/Source, also try to change the diffuse and other light properties. The shapes plugin has to be in.

from math import *
r=area().root()
N=K3NSphere(r,"Sphere")
n.setScaleXyz(4,4,4)
p=K3Point(r,"Light")
p1=K3Point(r,"Light")
p.setXyz(5,5,5)
area().lighting().setOn(1)
area().lighting().light(0).setNode(p)
area().lighting().light(1).setNode(p1)
paint()

while 1:
    for i in range(0,360):
        x=5*cos(2*pi*i/360)
        y=5*sin(2*pi*i/360)
        p.setX(x)
        p.setZ(y)
        p.lookAt(0,0,0)
        x=5*cos(2*pi*(i+180)/360)
        y=5*sin(2*pi*(i+180)/360)
        p1.setX(x)
        p1.setZ(y)
        p1.lookAt(0,0,0)
        paint()
        peq()

Misc functions