On Tue, Nov 18, 2008 at 3:55 PM, tiloprobst <[EMAIL PROTECTED]> wrote:

>
> If you could post or send your .obj loader I would be grateful.
> Will McGugan's .obj loader is on the APress source code page:
> http://apress.com/book/downloadfile/3765 To be honest I don't know
> what of his source code relies on Pygame, maybe a good proof of the
> "don't import * " rule ;) His book is more aimed at starters, so it
> fits my needs, but he relies a bit too much on 2D and Pygame. His game
> objects on his website: http://www.willmcgugan.com/game-objects/


Hopefully the attachment comes through fine, let me know if it doesn't. This
is a fairly naive .obj loader, and it produces basic triangles lists (not
indexed or optimised).

>
> The install of Pygame failed as I mentioned, but it's not just because
> of that I don't want install it. pyglet was recommended on
> idevgames.com as a superior alternative to Pygame.


>From a fair bit of pygame experience, I concur.

- Somebody knows of a de-installer for Python? I'd like to get rid of
> the 2.3 system-wide install.


Don't do that, you will most likely break your OS X install - just modify
your PATH environment variable to find the new python first.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

import pyglet
from pyglet.gl import *

class Model:
	def __init__(self, file):
		self.load(file)
	
	def load(self, fname):		
		f = open(fname,'rt')
		lines = f.readlines()
		f.close()
		
		words = []
		
		faces = 0
		start = 0
		
		buffers = []
		
		vertArray = []
		texArray = []
		normArray = []
		
		vertices = []
		texcoords = []
		normals = []

		for line in lines:
			words = line.split()
			
			if len(words) < 1:
				continue

			if words[0] == 'usemtl':
				if faces - start > 0:
					buffers.append({'start' : start*3, 'end' : faces*3})
					start = faces
			
			if words[0] == 'v':
				x = float(words[1])
				y = float(words[2])
				z = float(words[3])
				vertArray += [x,y,z]
			
			if words[0] == 'vt':
				u = float(words[1])
				v = float(words[2])
				texArray += [u,v]
			
			if words[0] == 'vn':
				x = float(words[1])
				y = float(words[2])
				z = float(words[3])
				normArray += [x,y,z]
							
			if words[0] == 'f':
				faces = faces + 1
				for w in words[1:]:
					ind = w.split('/')
					for n in range(3):
						vertices.append(vertArray[(int(ind[0])-1)*3 + n])
					for n in range(2):
						texcoords.append(texArray[(int(ind[1])-1)*2 + n])
					for n in range(3):
						normals.append(normArray[(int(ind[2])-1)*3 + n])
		
		if faces-start > 0:
			buffers.append({'start' : start*3, 'end' : faces*3})
				
		self.vbuffers = []
		for b in buffers:
			start = b['start']
			end = b['end']
			print start, end, len(vertices), len(texcoords), len(normals)
			buffer = pyglet.graphics.vertex_list( (end - start), ('v3f', vertices[start*3:end*3]), ('n3f', normals[start*3:end*3]), ('t2f', texcoords[start*2:end*2]) )
			self.vbuffers.append(buffer)
	
	def render(self):
		for b in self.vbuffers:
			b.draw(GL_TRIANGLES)

Reply via email to