Sort of works, trying to figure out the gl matrix is making my head hurt so…
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2006 Mariano Hidalgo
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------
bl_info = {
"name": "Lamp Widgets",
"author": "Mariano Hidalgo a.k.a. uselessdreamer",
"version": (1, 1, 0),
"blender": (2, 6, 2),
"location": "View3D",
"description": "Displays extra info on each lamp on scene",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "3D View"
}
import bpy
import bgl as gl
class VIEW3D_MT_Lamp_Widgets(bpy.types.Operator):
"""Displays extra information for lamps in the 3d View.
Dot Color is Lamp color.
Dot Size is Lamp energy.
Square Size on floor is Lamp distance (scale 10:1).
Black triangle on top if Cast Shadows is enabled.
"""
bl_idname = "view3d.lamp_widgets"
bl_label = "Lamp Widgets"
def modal(self, context, event):
context.area.tag_redraw()
if event.type in ('RIGHTMOUSE', 'ESC'):
context.region.callback_remove(self._handle)
return {'CANCELLED'}
return {'RUNNING_MODAL'}
def invoke(self, context, event):
if context.area.type != 'VIEW_3D':
self.report({'WARNING'}, "View3D not found, cannot run operator")
return {'CANCELLED'}
context.window_manager.modal_handler_add(self)
self._handle = context.region.callback_add(self.draw_lamp_widgets,
(context,),
'POST_PIXEL')
return {'RUNNING_MODAL'}
def draw_lamp_widgets(self, context):
# Get the Window matrix and create a gl Buffer with its data.
viewMatrix = context.space_data.region_3d.perspective_matrix
viewBuff = [viewMatrix[j][i] for i in range(4) for j in range(4)]
viewBuff = gl.Buffer(gl.GL_FLOAT, 16, viewBuff)
# Load the Window matrix for gl Drawing.
gl.glLoadIdentity()
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glPushMatrix()
gl.glLoadMatrixf(viewBuff)
# Enable Point antializing to get round points.
gl.glEnable(gl.GL_POINT_SMOOTH);
# Enable glBlend for alpha blending.
gl.glEnable(gl.GL_BLEND);
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA);
lamps = [obj for obj in context.visible_objects if obj.type == 'LAMP']
for lamp in lamps:
gl.glColor4f(0.0, 0.0, 0.0, 1.0)
gl.glPointSize(8)
gl.glBegin(gl.GL_POINTS)
gl.glVertex3f(lamp.location[0],
lamp.location[1],
lamp.location[2])
gl.glEnd()
# Set size and color.
gl.glColor4f(lamp.data.color[0],
lamp.data.color[1],
lamp.data.color[2],
1.0)
gl.glPointSize(int(lamp.data.energy * 10))
# Lamp colored dot.
gl.glBegin(gl.GL_POINTS)
gl.glVertex3f(lamp.location[0],
lamp.location[1],
lamp.location[2])
gl.glEnd()
# Lamp distance square
offset = lamp.data.distance * 0.1
z = 0.0
gl.glColor4f(1.0, 1.0, 1.0, 0.3)
#gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE);
gl.glBegin(gl.GL_LINE_LOOP)
gl.glVertex3f(lamp.location[0] - offset,
lamp.location[1] - offset,
z)
gl.glVertex3f(lamp.location[0] - offset,
lamp.location[1] + offset,
z)
gl.glVertex3f(lamp.location[0] + offset,
lamp.location[1] + offset,
z)
gl.glVertex3f(lamp.location[0] + offset,
lamp.location[1] - offset,
z)
gl.glEnd()
# Lamp shadow triangle
if lamp.data.shadow_method != 'NOSHADOW':
gl.glColor4f(0.0, 0.0, 0.0, 0.8)
#gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
gl.glBegin(gl.GL_POLYGON)
gl.glVertex3f(lamp.location[0],
lamp.location[1],
lamp.location[2] + 1)
gl.glVertex3f(lamp.location[0] - 0.25,
lamp.location[1],
lamp.location[2] + 0.6)
gl.glVertex3f(lamp.location[0] + 0.25,
lamp.location[1],
lamp.location[2] + 0.6)
gl.glEnd()
# Disable alpha blending and point smoothing.
gl.glDisable(gl.GL_BLEND)
gl.glDisable(gl.GL_POINT_SMOOTH)
def register():
bpy.utils.register_class(VIEW3D_MT_Lamp_Widgets)
def unregister():
bpy.utils.unregister_class(VIEW3D_MT_Lamp_Widgets)
if __name__ == "__main__":
register()
–edit–
Now that I think about it they changed the may matricies are stored to be column (or row) major now so that’s probably the problem.
–edit 2–
Yep, that was it so it’s fixed now with this edit.