mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
Set the entity properties as parsed from the map.
This commit is contained in:
parent
825ce0dad6
commit
73cdd66c52
3 changed files with 60 additions and 15 deletions
|
@ -21,18 +21,32 @@
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from bpy.props import BoolProperty, FloatProperty, StringProperty, EnumProperty
|
from bpy.props import BoolProperty, FloatProperty, StringProperty, EnumProperty
|
||||||
from bpy.props import BoolVectorProperty, PointerProperty
|
from bpy.props import BoolVectorProperty, CollectionProperty, PointerProperty
|
||||||
|
from bpy.props import FloatVectorProperty, IntProperty
|
||||||
|
|
||||||
|
from .entityclass import EntityClass
|
||||||
|
|
||||||
def qfentity_items(self, context):
|
def qfentity_items(self, context):
|
||||||
qfmap = context.scene.qfmap
|
qfmap = context.scene.qfmap
|
||||||
entclasses = qfmap.entity_classes.entity_classes
|
entclasses = qfmap.entity_classes.entity_classes
|
||||||
eclist = list(entclasses.keys())
|
eclist = list(entclasses.keys())
|
||||||
eclist.sort()
|
eclist.sort()
|
||||||
return tuple(map(lambda ec: (ec, ec, entclasses[ec].comment), eclist))
|
enum = (('', '--', 'No class. Will be exported as part of the world entity.'),)
|
||||||
|
enum += tuple(map(lambda ec: (ec, ec, entclasses[ec].comment), eclist))
|
||||||
|
return enum
|
||||||
|
|
||||||
|
class QFEntityProp(bpy.types.PropertyGroup):
|
||||||
|
name = StringProperty()
|
||||||
|
float = FloatProperty()
|
||||||
|
vector = FloatVectorProperty()
|
||||||
|
string = StringProperty()
|
||||||
|
list_control = StringProperty(default="string", options={'HIDDEN'})
|
||||||
|
|
||||||
class QFEntity(bpy.types.PropertyGroup):
|
class QFEntity(bpy.types.PropertyGroup):
|
||||||
classname = EnumProperty(items = qfentity_items, name = "Entity Class")
|
classname = EnumProperty(items = qfentity_items, name = "Entity Class")
|
||||||
flags = BoolVectorProperty(size=12)
|
flags = BoolVectorProperty(size=12)
|
||||||
|
fields = CollectionProperty(type=QFEntityProp)
|
||||||
|
field_idx = IntProperty()
|
||||||
|
|
||||||
class EntityPanel(bpy.types.Panel):
|
class EntityPanel(bpy.types.Panel):
|
||||||
bl_space_type = 'PROPERTIES'
|
bl_space_type = 'PROPERTIES'
|
||||||
|
@ -48,7 +62,10 @@ class EntityPanel(bpy.types.Panel):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
obj = context.active_object
|
obj = context.active_object
|
||||||
qfmap = context.scene.qfmap
|
qfmap = context.scene.qfmap
|
||||||
|
if obj.qfentity.classname:
|
||||||
ec = qfmap.entity_classes.entity_classes[obj.qfentity.classname]
|
ec = qfmap.entity_classes.entity_classes[obj.qfentity.classname]
|
||||||
|
else:
|
||||||
|
ec = EntityClass.null()
|
||||||
flags = ec.flagnames + ("",) * (8 - len(ec.flagnames))
|
flags = ec.flagnames + ("",) * (8 - len(ec.flagnames))
|
||||||
flags += ("!easy", "!medium", "!hard", "!dm")
|
flags += ("!easy", "!medium", "!hard", "!dm")
|
||||||
layout.prop(obj.qfentity, "classname")
|
layout.prop(obj.qfentity, "classname")
|
||||||
|
@ -59,6 +76,8 @@ class EntityPanel(bpy.types.Panel):
|
||||||
for r in range(4):
|
for r in range(4):
|
||||||
idx = c * 4 + r
|
idx = c * 4 + r
|
||||||
sub.prop(obj.qfentity, "flags", text=flags[idx], index=idx)
|
sub.prop(obj.qfentity, "flags", text=flags[idx], index=idx)
|
||||||
|
layout.template_list(obj.qfentity, "fields", obj.qfentity, "field_idx",
|
||||||
|
prop_list="list_control")
|
||||||
|
|
||||||
def default_brush_entity(entityclass):
|
def default_brush_entity(entityclass):
|
||||||
name = entityclass.name
|
name = entityclass.name
|
||||||
|
@ -102,6 +121,21 @@ def entity_box(entityclass):
|
||||||
mesh.materials.append(mat)
|
mesh.materials.append(mat)
|
||||||
return mesh
|
return mesh
|
||||||
|
|
||||||
|
def set_entity_props(obj, ent):
|
||||||
|
qfe = obj.qfentity
|
||||||
|
if "classname" in ent.d:
|
||||||
|
qfe.classname = ent.d["classname"]
|
||||||
|
if "spawnflags" in ent.d:
|
||||||
|
flags = int(float(ent.d["spawnflags"]))
|
||||||
|
for i in range(12):
|
||||||
|
qfe.flags[i] = (flags & (1 << i)) and True or False
|
||||||
|
for key in ent.d.keys():
|
||||||
|
if key in {"classname", "spawnflags", "origin"}:
|
||||||
|
continue
|
||||||
|
item = qfe.fields.add()
|
||||||
|
item.name = key
|
||||||
|
item.string = ent.d[key]
|
||||||
|
|
||||||
def add_entity(self, context, entclass):
|
def add_entity(self, context, entclass):
|
||||||
entity_class = context.scene.qfmap.entity_classes.entity_classes[entclass]
|
entity_class = context.scene.qfmap.entity_classes.entity_classes[entclass]
|
||||||
context.user_preferences.edit.use_global_undo = False
|
context.user_preferences.edit.use_global_undo = False
|
||||||
|
|
|
@ -14,6 +14,9 @@ class EntityClass:
|
||||||
self.flagnames = flagnames
|
self.flagnames = flagnames
|
||||||
self.comment = comment
|
self.comment = comment
|
||||||
@classmethod
|
@classmethod
|
||||||
|
def null(cls):
|
||||||
|
return cls('', (1, 1, 1), None, (), "")
|
||||||
|
@classmethod
|
||||||
def from_quaked(cls, text, filename, line = 0):
|
def from_quaked(cls, text, filename, line = 0):
|
||||||
script = Script(filename, text)
|
script = Script(filename, text)
|
||||||
if line:
|
if line:
|
||||||
|
|
|
@ -24,11 +24,12 @@ import os
|
||||||
import bpy
|
import bpy
|
||||||
from bpy_extras.object_utils import object_data_add
|
from bpy_extras.object_utils import object_data_add
|
||||||
from mathutils import Vector,Matrix
|
from mathutils import Vector,Matrix
|
||||||
|
from math import pi
|
||||||
|
|
||||||
from .map import parse_map, MapError
|
from .map import parse_map, MapError
|
||||||
from .quakepal import palette
|
from .quakepal import palette
|
||||||
from .wad import WadFile
|
from .wad import WadFile
|
||||||
from .entity import entity_box
|
from .entity import entity_box, set_entity_props
|
||||||
|
|
||||||
def parse_vector(vstr):
|
def parse_vector(vstr):
|
||||||
v = vstr.split()
|
v = vstr.split()
|
||||||
|
@ -109,10 +110,6 @@ def process_entity(ent, wads):
|
||||||
light.distance = 300.0
|
light.distance = 300.0
|
||||||
light.falloff_type = 'CUSTOM_CURVE'
|
light.falloff_type = 'CUSTOM_CURVE'
|
||||||
obj = bpy.data.objects.new(name, light)
|
obj = bpy.data.objects.new(name, light)
|
||||||
obj.location = parse_vector (ent.d["origin"])
|
|
||||||
bpy.context.scene.objects.link(obj)
|
|
||||||
bpy.context.scene.objects.active=obj
|
|
||||||
obj.select = True
|
|
||||||
elif ent.b:
|
elif ent.b:
|
||||||
verts = []
|
verts = []
|
||||||
faces = []
|
faces = []
|
||||||
|
@ -156,9 +153,6 @@ def process_entity(ent, wads):
|
||||||
uvloop.data[k].uv = uv[j]
|
uvloop.data[k].uv = uv[j]
|
||||||
mesh.update()
|
mesh.update()
|
||||||
obj = bpy.data.objects.new(name, mesh)
|
obj = bpy.data.objects.new(name, mesh)
|
||||||
bpy.context.scene.objects.link(obj)
|
|
||||||
bpy.context.scene.objects.active=obj
|
|
||||||
obj.select = True
|
|
||||||
else:
|
else:
|
||||||
if entityclass.size:
|
if entityclass.size:
|
||||||
mesh = entity_box(entityclass)
|
mesh = entity_box(entityclass)
|
||||||
|
@ -168,10 +162,24 @@ def process_entity(ent, wads):
|
||||||
obj.empty_draw_type = 'CUBE'
|
obj.empty_draw_type = 'CUBE'
|
||||||
obj.empty_draw_size = 8
|
obj.empty_draw_size = 8
|
||||||
obj.show_name = True
|
obj.show_name = True
|
||||||
|
if "origin" in ent.d:
|
||||||
obj.location = parse_vector (ent.d["origin"])
|
obj.location = parse_vector (ent.d["origin"])
|
||||||
|
angles = Vector()
|
||||||
|
if not ent.b:
|
||||||
|
#brush entities doen't normally support rotation
|
||||||
|
if "angle" in ent.d:
|
||||||
|
angles = Vector((0, 0, float(ent.d["angle"])))
|
||||||
|
del ent.d["angle"]
|
||||||
|
elif "angles" in ent.d:
|
||||||
|
angles = parse_vector(ent.d["angles"])
|
||||||
|
angles = angles.xzy
|
||||||
|
del ent.d["angles"]
|
||||||
|
obj.rotation_mode = 'XZY'
|
||||||
|
obj.rotation_euler = angles * pi / 180
|
||||||
bpy.context.scene.objects.link(obj)
|
bpy.context.scene.objects.link(obj)
|
||||||
bpy.context.scene.objects.active=obj
|
bpy.context.scene.objects.active=obj
|
||||||
obj.select = True
|
obj.select = True
|
||||||
|
set_entity_props(obj, ent)
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue