[Bf-python] Mesh custom layer api change
Campbell Barton
ideasman42 at gmail.com
Mon Mar 24 17:46:29 CET 2008
I dont see a problem, if this function existed it would just work like this
if (me.verts.getPropertyType('foo')==int): ....
Incase anyones interested I just used this (undocumented) api to store
colors in a vertex point cloud.
--------------------
from Blender import Scene, Mesh, Window, sys
import BPyMessages
import bpy
def col2int(r,g,b):
# Range check to be safe
if r < 0: r = 0
if g < 0: g = 0
if b < 0: b = 0
if r > 255: r = 255
if g > 255: g = 255
if b > 255: b = 255
return (r<<16) | (g<<8) | b
# Not used here
def int2col(rgb):
return (rgb>>16) & 255, (rgb>>8) & 255, rgb & 255
def main():
sce = bpy.data.scenes.active
file = '/test.ply'
vecs = []
cols = []
lines = open(file, 'rU')
for l in lines:
words = l.split()
if len(words)==6:
vecs.append( (float(words[0]), float(words[1]), float(words[2])) )
cols.append( col2int( int(words[3]), int(words[4]), int(words[5]) ) )
me = bpy.data.meshes.new('colmesh')
me.verts.extend( vecs )
me.verts.addPropertyLayer('vcol', Mesh.PropertyTypes.INT)
for i, v in enumerate(me.verts):
v.setProperty('vcol', cols[i])
if __name__ == '__main__':
main()
-------------
from Blender import Scene, Mesh, Window, sys
import BPyMessages
import bpy
def int2col(rgb):
return (rgb>>16) & 255, (rgb>>8) & 255, rgb & 255
# Read colors back
def my_mesh_util(me):
for i, v in enumerate(me.verts):
c=v.getProperty('vcol')
print int2col(c)
my_mesh_util()
------------------
More information about the Bf-python
mailing list