I'm trying to make it so that when the user clicks while the game is playing, it converts the quads of the "Gem" object into tris.
I have the camera with a sensor for the Left Mouse Button connected to a python controller.
The python script is as follows:
import bge,bpy
cont = bge.logic.getCurrentController()
lclick = cont.sensors["lclick"]
if lclick.positive:
print(len(bpy.data.objects["Gem"].data.vertices))
cam = cont.owner
origMode = bpy.context.object.mode
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_all(action="DESELECT")
bpy.data.objects["Gem"].select = True
bpy.ops.object.mode_set(mode = 'EDIT')
bpy.ops.mesh.quads_convert_to_tris()
bpy.ops.object.mode_set(mode = origMode)
print(len(bpy.data.objects["Gem"].data.polygons))
This seems to fail sometimes depending on what was selected before starting. When it doesn't work, it gives me the following error:
TypeError: Converting py args to operator properties: enum "EDIT" not found in ('OBJECT')
Furthermore, when I exit the game engine, it does indeed show that "Object mode" is the only available mode for the selection, despite the fact that it shows the "Gem" object as the only thing selected (though, it is outlined in a darker orange than usual).
Can this not be done this way in the game engine? Is there a better way to do it?