# Blender/Python script for creating the default scene.
# Created by Olivier Saraja
# Initially published in French in Linux Magazine, Issue 73
# by Diamond Editions
# English translation by Ed Montgomery (Canada)

import Blender, math
from Blender import Camera, Object, Scene, Lamp, NMesh, Material

conv=2*math.pi/360

# A vertex or point in 3D space
# Definition of 3D coordinates of points
list_of_points=[
          [-1,-1,-1],	# point 0
          [-1,+1,-1],	# point 1
          [+1,+1,-1],	# point 2
          [+1,-1,-1],   # point 3
          [-1,-1,+1],	# point 4
          [-1,+1,+1],	# point 5
          [+1,+1,+1],	# point 6
          [+1,-1,+1]	# point 7
]

# A group of 4 points makes a plain or face of the cube
# Definition of faces
list_of_faces=[
          [0,1,2,3],	# face 0
          [4,5,6,7],	# face 1
          [0,4,7,3],	# face 2
          [1,2,6,5],	# face 3
          [0,1,5,4],	# face 4
          [3,7,6,2]		# face 5
]

# Definition of the cube
CubeMeshData=NMesh.GetRaw()

# Definition of the material for the cube
mat=Material.New('Material')
CubeMeshData.materials.append(mat)
print mat.rgbCol
mat.rgbCol=[0.756,0.756,0.756]
mat.setAlpha(1.0)
mat.setRef(0.8)
mat.setSpec(0.5)
mat.setHardness(50)

for composant in list_of_points:
	point=NMesh.Vert(composant[0],composant[1],composant[2])
	CubeMeshData.verts.append(point)
	
for current_face in list_of_faces:
	face=NMesh.Face()
	for number_of_vertex in current_face:
		face.append(CubeMeshData.verts[number_of_vertex])
	CubeMeshData.faces.append(face)

NMesh.PutRaw(CubeMeshData,'Cube',1)

# Definition of the camera
c=Camera.New('persp','Camera')
c.lens=35.0
cur=Scene.getCurrent()
ob=Object.New('Camera')
ob.link(c)
cur.link(ob)
cur.setCurrentCamera(ob)
ob.setEuler(52.928*conv,-1.239*conv,52.752*conv)
ob.setLocation(6.283,-5.000,5.867)

# Definition of the lamp
l=Lamp.New('Lamp','Lamp')
ob=Object.New('Lamp')
ob.link(l)
cur.link(ob)
ob.setLocation(0,-10,7)
ob.setEuler(47.534*conv,0,0)

Blender.Redraw()
