Exemplo n.º 1
0
def create_plane(color=None):
    """Returns a glge.Object which is a two triangle plane"""
    plane = Object()
    plane.mesh = Mesh()
    plane.mesh.positions = [
        1.000,
        1.000,
        0.000,
        -1.000,
        1.000,
        0.000,
        -1.000,
        -1.000,
        0.000,
        1.000,
        1.000,
        0.000,
        -1.000,
        -1.000,
        0.000,
        1.000,
        -1.000,
        0.000,
    ]

    plane.mesh.normals = [
        -0.000,
        0.000,
        1.000,
        -0.000,
        0.000,
        1.000,
        -0.000,
        0.000,
        1.000,
        0.000,
        -0.000,
        1.000,
        0.000,
        -0.000,
        1.000,
        0.000,
        -0.000,
        1.000,
    ]

    plane.mesh.UV = [0.000, 0.000, 1.000, 0.000, 1.000, 1.000, 0.000, 0.000, 1.000, 1.000, 0.000, 1.000]

    plane.mesh.faces = [0, 1, 2, 3, 4, 5]
    plane.material = Material()
    plane.material.color = color or [1, 0.5, 0.5, 1]
    return plane
Exemplo n.º 2
0
	def genGeometry(self, name, face_start, face_end, materials):
		obj = Object()
		obj.mesh = Mesh()
		obj_mat = self.objMaterialForFace(face_start)
		if obj_mat and materials.has_key(obj_mat[0]):
			obj.material = materials[obj_mat[0]]
		else:
			obj.material = None
		for face in self.faces[face_start:face_end]:
			for point in face[0:3]: # TODO This is treating all faces like they are triangles, which is wrong
				vertex_offset = point[0] * 3
				obj.mesh.positions.extend([self.vertices[vertex_offset], self.vertices[vertex_offset + 1], self.vertices[vertex_offset + 2]])

				if point[1]:
					uv_offset = point[1] * 2
					obj.mesh.UV.extend([self.uvs[uv_offset], self.uvs[uv_offset + 1]])
					
				if point[2]:
					normal_offset = point[2] * 3
					obj.mesh.normals.extend([self.normals[normal_offset], self.normals[normal_offset + 1], self.normals[normal_offset + 2]])
		obj.mesh.faces = range(len(obj.mesh.positions) / 3)
		return obj
Exemplo n.º 3
0
def create_box(color=None):
    """Returns a glge.Object which is a cube"""
    box = Object()
    box.mesh = Mesh()
    box.mesh.positions = [
        1.0,
        -1.0,
        -1.0,
        1.0,
        -1.0,
        1.0,
        -1.0,
        -1.0,
        1.0,
        1.0,
        1.0,
        -1.0,
        -1.0,
        1.0,
        -1.0,
        -1.0,
        1.0,
        1.0,
        1.0,
        -1.0,
        -1.0,
        1.0,
        1.0,
        -1.0,
        0.99999899999999997,
        1.0,
        1.0000009999999999,
        1.0,
        -1.0,
        1.0,
        0.99999899999999997,
        1.0,
        1.0000009999999999,
        -1.0,
        1.0,
        1.0,
        -1.0,
        -1.0,
        1.0,
        -1.0,
        1.0,
        1.0,
        -1.0,
        1.0,
        -1.0,
        1.0,
        1.0,
        -1.0,
        1.0,
        -1.0,
        -1.0,
        -1.0,
        -1.0,
        -1.0,
    ]
    box.mesh.faces = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
    box.material = Material()
    box.material.color = color or [1, 0.5, 0.5, 1]
    return box
Exemplo n.º 4
0
	def toGeometry(self, json_string):
		json_data = simplejson.loads(json_string)
		root_group = Group()
		for obj_data in json_data['objects']:
			if obj_data['type'] != 'MESH': continue
			obj = Object()
			obj.name = obj_data['name']
			obj.set_loc(obj_data['location'])
			obj.set_scale(obj_data['scale'])
			obj.set_rot(obj_data['rotation'])
			obj.mesh = Mesh()
			obj.mesh.positions = obj_data['data']['vertices']
			obj.mesh.normals = obj_data['data']['normals']
			obj.mesh.faces = flatten_faces(obj_data['data']['faces'])
			if len(obj_data['data']['materials']) > 0:
				obj.material = self.toMaterial(obj_data['data']['materials'][0])
			else:
				obj.material = Material()
			root_group.children.append(obj)
		return root_group