Hi,
I've tried your code with Maya 2017. It looks working fine when I changed the unpack from big-endian to little-endian(<f). I guess it is still working just not recommended.
import struct
import maya.OpenMaya as om
import maya.OpenMayaUI as omUI
def readDepthMap(x, y):
view = omUI.M3dView.active3dView()
width = view.portWidth()
height = view.portHeight()
width = 1
height = 1
numPixels = width*height*4
depth = [0.0]*numPixels
util = om.MScriptUtil()
util.createFromList(depth, numPixels)
utilPtr = util.asUcharPtr()
view.readDepthMap(x, y, width, height, utilPtr, omUI.M3dView.kDepth_Float)
b1 = om.MScriptUtil.getUcharArrayItem(utilPtr, 0)
b2 = om.MScriptUtil.getUcharArrayItem(utilPtr, 1)
b3 = om.MScriptUtil.getUcharArrayItem(utilPtr, 2)
b4 = om.MScriptUtil.getUcharArrayItem(utilPtr, 3)
data = [b1,b2,b3,b4]
print data # always 0's....
b = struct.pack('4B', *data)
return struct.unpack('<f', b)
print readDepthMap(1,1)
[0, 255, 127, 59]
(0.0039061903953552246,)
About MImage:readDepthMap, I think it should only work with .iff file type.
Yours,
Li