Generate geometry for entities with brushes.

This commit is contained in:
Bill Currie 2012-08-30 14:50:19 +09:00
parent 15a906aadb
commit 5d2b2639d0
2 changed files with 39 additions and 2 deletions

View file

@ -25,6 +25,35 @@ from mathutils import Vector,Matrix
from .map import parse_map, MapError
def process_entity(ent):
if "classname" in ent.d and ent.d["classname"][:5] == "light":
pass
elif ent.b:
name = "brush"
verts = []
faces = []
for bverts, bfaces in ent.b:
base = len(verts)
verts.extend(bverts)
for f in bfaces:
for i in range(len(f)):
f[i] += base
f.reverse()
if not f[-1]:
t = f[0]
del f[0]
f.append(t)
faces.extend(bfaces)
mesh = bpy.data.meshes.new(name)
mesh.from_pydata(verts, [], faces)
mesh.update()
obj = bpy.data.objects.new(name, mesh)
bpy.context.scene.objects.link(obj)
bpy.context.scene.objects.active=obj
obj.select = True
else:
pass
def import_map(operator, context, filepath):
bpy.context.user_preferences.edit.use_global_undo = False
@ -37,6 +66,7 @@ def import_map(operator, context, filepath):
raise
operator.report({'ERROR'}, repr(err))
return {'CANCELLED'}
if not entities:
return {'FINISHED'}
for ent in entities:
process_entity(ent)
bpy.context.user_preferences.edit.use_global_undo = True
return {'FINISHED'}

View file

@ -84,6 +84,11 @@ def clip_plane(plane, clip_planes):
poly = clip_poly(poly, p, True)
return poly
EPSILON = 0.5**5 # 1/32 plenty for quake maps
def rnd(x):
return int(x / EPSILON) * EPSILON
def convert_planes(planes):
verts = []
faces = []
@ -91,6 +96,7 @@ def convert_planes(planes):
poly = clip_plane(planes[i], planes[:i] + planes[i + 1:])
face = []
for v in poly:
v = Vector((rnd(v.x), rnd(v.y), rnd(v.z)))
ind = len(verts)
for i in range(len(verts)):
d = verts[i] - v
@ -214,3 +220,4 @@ def parse_map(filename):
if not ent:
break
entities.append(ent)
return entities