mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-21 11:11:37 +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
|
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):
|
def import_map(operator, context, filepath):
|
||||||
bpy.context.user_preferences.edit.use_global_undo = False
|
bpy.context.user_preferences.edit.use_global_undo = False
|
||||||
|
|
||||||
|
@ -37,6 +66,7 @@ def import_map(operator, context, filepath):
|
||||||
raise
|
raise
|
||||||
operator.report({'ERROR'}, repr(err))
|
operator.report({'ERROR'}, repr(err))
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
if not entities:
|
for ent in entities:
|
||||||
return {'FINISHED'}
|
process_entity(ent)
|
||||||
|
bpy.context.user_preferences.edit.use_global_undo = True
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
|
@ -84,6 +84,11 @@ def clip_plane(plane, clip_planes):
|
||||||
poly = clip_poly(poly, p, True)
|
poly = clip_poly(poly, p, True)
|
||||||
return poly
|
return poly
|
||||||
|
|
||||||
|
EPSILON = 0.5**5 # 1/32 plenty for quake maps
|
||||||
|
|
||||||
|
def rnd(x):
|
||||||
|
return int(x / EPSILON) * EPSILON
|
||||||
|
|
||||||
def convert_planes(planes):
|
def convert_planes(planes):
|
||||||
verts = []
|
verts = []
|
||||||
faces = []
|
faces = []
|
||||||
|
@ -91,6 +96,7 @@ def convert_planes(planes):
|
||||||
poly = clip_plane(planes[i], planes[:i] + planes[i + 1:])
|
poly = clip_plane(planes[i], planes[:i] + planes[i + 1:])
|
||||||
face = []
|
face = []
|
||||||
for v in poly:
|
for v in poly:
|
||||||
|
v = Vector((rnd(v.x), rnd(v.y), rnd(v.z)))
|
||||||
ind = len(verts)
|
ind = len(verts)
|
||||||
for i in range(len(verts)):
|
for i in range(len(verts)):
|
||||||
d = verts[i] - v
|
d = verts[i] - v
|
||||||
|
@ -214,3 +220,4 @@ def parse_map(filename):
|
||||||
if not ent:
|
if not ent:
|
||||||
break
|
break
|
||||||
entities.append(ent)
|
entities.append(ent)
|
||||||
|
return entities
|
||||||
|
|
Loading…
Reference in a new issue