Skip to content

Commit

Permalink
[fix] Blender: Type selector field gets type of the object.
Browse files Browse the repository at this point in the history
  • Loading branch information
hhirsch committed Oct 18, 2014
1 parent bc7b96a commit 475def6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 28 deletions.
11 changes: 5 additions & 6 deletions tools/blender/blenderToXmlExport/glportalobjectpanel.py
Expand Up @@ -29,13 +29,12 @@ def draw(self, context):
layout = self.layout
row = layout.row()
row.label(text="Type:")
layout.prop_menu_enum(object, "types")

if "glpType" in object:
layout.prop_menu_enum(object, "types", text=object["glpType"])
else:
layout.prop_menu_enum(object, "types")
split = layout.split()
col = split.column(align=True)

col.operator("wm.clear_selection", text="Clear Type", icon='MESH_CUBE')
col.operator("wm.selection_to_win", text="Set Win Area", icon='MESH_CUBE')
col.operator("wm.selection_to_death", text="Set Death Area", icon='MESH_CUBE')
col.operator("wm.selection_to_radiation", text="Set Radiation Area", icon='MESH_CUBE')
col.operator("wm.selection_to_door", text="Set Door", icon='MESH_CUBE')
col.operator("wm.selection_to_portable", text="Set Wall Portable", icon='MESH_CUBE')
3 changes: 2 additions & 1 deletion tools/blender/blenderToXmlExport/glportalpanel.py
Expand Up @@ -12,4 +12,5 @@ def draw(self, context):
split = layout.split()
col = split.column(align=True)
col.operator("wm.add_door", text="Add Door", icon='MESH_CUBE')
col.operator("wm.add_portable", text="Add Portable Wall", icon='MESH_CUBE')
col.operator("wm.add_portable", text="Add Portable Wall", icon='MESH_PLANE')
col.operator("wm.add_wall", text="Add Wall", icon='MESH_PLANE')
62 changes: 41 additions & 21 deletions tools/blender/blenderToXmlExport/operators.py
Expand Up @@ -64,32 +64,51 @@ def execute(self, context):
object["glpType"] = "door"
return {'FINISHED'}

def getMaterial(texturePath):
realpath = os.path.expanduser(texturePath)
try:
portableWallImage = bpy.data.images.load(realpath)
except:
raise NameError("Cannot load image %s" % realpath)

portableWallTexture = bpy.data.textures.new('ColorTex', type = 'IMAGE')
portableWallTexture.image = portableWallImage

mat = bpy.data.materials.new('TexMat')

# Add texture slot for color texture
mtex = mat.texture_slots.add()
mtex.texture = portableWallTexture
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = True
mtex.use_map_color_emission = True
mtex.emission_color_factor = 0.5
mtex.use_map_density = True
mtex.mapping = 'FLAT'
return mat

class addPortable(bpy.types.Operator):
bl_idname = "wm.add_portable"
bl_label = "Mark the selection as portable."

def execute(self, context):
realpath = os.path.expanduser('~/.glportal/data/textures/wall.png')
try:
portableWallImage = bpy.data.images.load(realpath)
except:
raise NameError("Cannot load image %s" % realpath)
mat = getMaterial('~/.glportal/data/textures/wall.png')
bpy.types.Object.glpType = bpy.props.StringProperty()
object = bpy.context.active_object
clearGlpProperties()
if object:
object["glpType"] = "portable"
me = object.data
me.materials.append(mat)
return {'FINISHED'}

portableWallTexture = bpy.data.textures.new('ColorTex', type = 'IMAGE')
portableWallTexture.image = portableWallImage

mat = bpy.data.materials.new('TexMat')

# Add texture slot for color texture
mtex = mat.texture_slots.add()
mtex.texture = portableWallTexture
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = True
mtex.use_map_color_emission = True
mtex.emission_color_factor = 0.5
mtex.use_map_density = True
mtex.mapping = 'FLAT'


class addWall(bpy.types.Operator):
bl_idname = "wm.add_wall"
bl_label = "Mark the selection as portable."

def execute(self, context):
mat = getMaterial('~/.glportal/data/textures/tiles.png')
bpy.types.Object.glpType = bpy.props.StringProperty()
object = bpy.context.active_object
clearGlpProperties()
Expand All @@ -98,3 +117,4 @@ def execute(self, context):
me = object.data
me.materials.append(mat)
return {'FINISHED'}

0 comments on commit 475def6

Please sign in to comment.