mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
Generate geometry for entities with brushes.
This commit is contained in:
parent
15a906aadb
commit
5d2b2639d0
2 changed files with 39 additions and 2 deletions
|
@ -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'}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue