Change color material mesh

Hello,

I’m trying to change the color of a mesh via python with code found in this forum (several posts) but it does not work. I am using blender 2.69 and I’m running pdb.

When I create the mesh, I set the

This is what I get while debugging:

This is my mesh:
(Pdb) dir(self.bge_object.children[0].meshes[0])
[‘class’, ‘delattr’, ‘dir’, ‘doc’, ‘eq’, ‘format’, ‘ge’, ‘getattribute’, ‘gt’, ‘hash’, ‘init’, ‘le’, ‘lt’, ‘ne’, ‘new’, ‘reduce’, ‘reduce_ex’, ‘repr’, ‘setattr’, ‘sizeof’, ‘str’, ‘subclasshook’, ‘getMaterialName’, ‘getPolygon’, ‘getTextureName’, ‘getVertex’, ‘getVertexArrayLength’, ‘invalid’, ‘materials’, ‘name’, ‘numMaterials’, ‘numPolygons’, ‘transform’, ‘transformUV’]

And if I do this:
for i in range(0, self.bge_object.children[0].meshes[0].getVertexArrayLength(0)):
self.bge_object.children[0].meshes[0].getVertex(0,i).setRGBA([0.5,0.5,0.5,1])

The mesh does not change the color at all…

Any idea or hint to figure this out?
Thanks for the help.

So this is BGE / game-engine related?
setRGBA() exists, and if you don’t see any error then the access path should be okay. Maybe it’s not supported (anymore), or you’re looking at the wrong object?

Yes it is a GBE / game-engine related.

There is only one object in the scene and len(self.bge_object.children) outputs 1, therefore there is no other children. I believe that is the right object. Just in case, this is the output of dir(self.bge_object):

(Pdb) dir(self.bge_object)
[‘class’, ‘contains’, ‘delattr’, ‘delitem’, ‘dir’, ‘doc’, ‘eq’, ‘format’, ‘ge’, ‘getattribute’, ‘getitem’, ‘gt’, ‘hash’, ‘init’, ‘le’, ‘lt’, ‘ne’, ‘new’, ‘reduce’, ‘reduce_ex’, ‘repr’, ‘setattr’, ‘setitem’, ‘sizeof’, ‘str’, ‘subclasshook’, ‘actuators’, ‘alignAxisToVect’, ‘angularVelocity’, ‘applyForce’, ‘applyImpulse’, ‘applyMovement’, ‘applyRotation’, ‘applyTorque’, ‘attrDict’, ‘children’, ‘childrenRecursive’, ‘collisionCallbacks’, ‘color’, ‘controllers’, ‘disableRigidBody’, ‘enableRigidBody’, ‘endObject’, ‘get’, ‘getActionFrame’, ‘getAngularVelocity’, ‘getAxisVect’, ‘getDistanceTo’, ‘getLinearVelocity’, ‘getPhysicsId’, ‘getPropertyNames’, ‘getReactionForce’, ‘getVectTo’, ‘getVelocity’, ‘groupMembers’, ‘groupObject’, ‘invalid’, ‘isPlayingAction’, ‘life’, ‘linVelocityMax’, ‘linVelocityMin’, ‘linearVelocity’, ‘localAngularVelocity’, ‘localInertia’, ‘localLinearVelocity’, ‘localOrientation’, ‘localPosition’, ‘localScale’, ‘localTransform’, ‘mass’, ‘meshes’, ‘name’, ‘occlusion’, ‘orientation’, ‘parent’, ‘playAction’, ‘position’, ‘rayCast’, ‘rayCastTo’, ‘reinstancePhysicsMesh’, ‘removeParent’, ‘replaceMesh’, ‘restoreDynamics’, ‘scaling’, ‘scene’, ‘sendMessage’, ‘sensors’, ‘setActionFrame’, ‘setAngularVelocity’, ‘setCollisionMargin’, ‘setLinearVelocity’, ‘setOcclusion’, ‘setParent’, ‘setVisible’, ‘state’, ‘stopAction’, ‘suspendDynamics’, ‘timeOffset’, ‘visible’, ‘worldAngularVelocity’, ‘worldLinearVelocity’, ‘worldOrientation’, ‘worldPosition’, ‘worldScale’, ‘worldTransform’]
(Pdb) len(self.bge_object.meshes)

This is BGE / game-engine related…
This is the only object I have in my scenario. Just in case, this is the output from pdb:

(Pdb) dir(self.bge_object)
[‘class’, ‘contains’, ‘delattr’, ‘delitem’, ‘dir’, ‘doc’, ‘eq’, ‘format’, ‘ge’, ‘getattribute’, ‘getitem’, ‘gt’, ‘hash’, ‘init’, ‘le’, ‘lt’, ‘ne’, ‘new’, ‘reduce’, ‘reduce_ex’, ‘repr’, ‘setattr’, ‘setitem’, ‘sizeof’, ‘str’, ‘subclasshook’, ‘actuators’, ‘alignAxisToVect’, ‘angularVelocity’, ‘applyForce’, ‘applyImpulse’, ‘applyMovement’, ‘applyRotation’, ‘applyTorque’, ‘attrDict’, ‘children’, ‘childrenRecursive’, ‘collisionCallbacks’, ‘color’, ‘controllers’, ‘disableRigidBody’, ‘enableRigidBody’, ‘endObject’, ‘get’, ‘getActionFrame’, ‘getAngularVelocity’, ‘getAxisVect’, ‘getDistanceTo’, ‘getLinearVelocity’, ‘getPhysicsId’, ‘getPropertyNames’, ‘getReactionForce’, ‘getVectTo’, ‘getVelocity’, ‘groupMembers’, ‘groupObject’, ‘invalid’, ‘isPlayingAction’, ‘life’, ‘linVelocityMax’, ‘linVelocityMin’, ‘linearVelocity’, ‘localAngularVelocity’, ‘localInertia’, ‘localLinearVelocity’, ‘localOrientation’, ‘localPosition’, ‘localScale’, ‘localTransform’, ‘mass’, ‘meshes’, ‘name’, ‘occlusion’, ‘orientation’, ‘parent’, ‘playAction’, ‘position’, ‘rayCast’, ‘rayCastTo’, ‘reinstancePhysicsMesh’, ‘removeParent’, ‘replaceMesh’, ‘restoreDynamics’, ‘scaling’, ‘scene’, ‘sendMessage’, ‘sensors’, ‘setActionFrame’, ‘setAngularVelocity’, ‘setCollisionMargin’, ‘setLinearVelocity’, ‘setOcclusion’, ‘setParent’, ‘setVisible’, ‘state’, ‘stopAction’, ‘suspendDynamics’, ‘timeOffset’, ‘visible’, ‘worldAngularVelocity’, ‘worldLinearVelocity’, ‘worldOrientation’, ‘worldPosition’, ‘worldScale’, ‘worldTransform’]

(Pdb) len(self.bge_object.children)
1

(Pdb) dir(self.bge_object.children[0])
[‘class’, ‘contains’, ‘delattr’, ‘delitem’, ‘dir’, ‘doc’, ‘eq’, ‘format’, ‘ge’, ‘getattribute’, ‘getitem’, ‘gt’, ‘hash’, ‘init’, ‘le’, ‘lt’, ‘ne’, ‘new’, ‘reduce’, ‘reduce_ex’, ‘repr’, ‘setattr’, ‘setitem’, ‘sizeof’, ‘str’, ‘subclasshook’, ‘actuators’, ‘alignAxisToVect’, ‘angularVelocity’, ‘applyForce’, ‘applyImpulse’, ‘applyMovement’, ‘applyRotation’, ‘applyTorque’, ‘attrDict’, ‘children’, ‘childrenRecursive’, ‘collisionCallbacks’, ‘color’, ‘controllers’, ‘disableRigidBody’, ‘enableRigidBody’, ‘endObject’, ‘get’, ‘getActionFrame’, ‘getAngularVelocity’, ‘getAxisVect’, ‘getDistanceTo’, ‘getLinearVelocity’, ‘getPhysicsId’, ‘getPropertyNames’, ‘getReactionForce’, ‘getVectTo’, ‘getVelocity’, ‘groupMembers’, ‘groupObject’, ‘invalid’, ‘isPlayingAction’, ‘life’, ‘linVelocityMax’, ‘linVelocityMin’, ‘linearVelocity’, ‘localAngularVelocity’, ‘localInertia’, ‘localLinearVelocity’, ‘localOrientation’, ‘localPosition’, ‘localScale’, ‘localTransform’, ‘mass’, ‘meshes’, ‘name’, ‘occlusion’, ‘orientation’, ‘parent’, ‘playAction’, ‘position’, ‘rayCast’, ‘rayCastTo’, ‘reinstancePhysicsMesh’, ‘removeParent’, ‘replaceMesh’, ‘restoreDynamics’, ‘scaling’, ‘scene’, ‘sendMessage’, ‘sensors’, ‘setActionFrame’, ‘setAngularVelocity’, ‘setCollisionMargin’, ‘setLinearVelocity’, ‘setOcclusion’, ‘setParent’, ‘setVisible’, ‘state’, ‘stopAction’, ‘suspendDynamics’, ‘timeOffset’, ‘visible’, ‘worldAngularVelocity’, ‘worldLinearVelocity’, ‘worldOrientation’, ‘worldPosition’, ‘worldScale’, ‘worldTransform’]

I don’t know if that would help…

up up up up up