Skip to content

Instantly share code, notes, and snippets.

@PierrickKoch
Last active December 15, 2015 06:59
Show Gist options
  • Select an option

  • Save PierrickKoch/5220663 to your computer and use it in GitHub Desktop.

Select an option

Save PierrickKoch/5220663 to your computer and use it in GitHub Desktop.
Blender 2.66 mesh bug
"""
Blender 2.66 mesh bug
EDIT: bug fixed on rev. r55483. by Dalai Felinto:
http://projects.blender.org/tracker/?func=detail&atid=306&aid=34550&group_id=9
This scipt gives:
mat 0 vert 9
in Blender versions <= 2.65a
while with Blender versions >= 2.66
mat 0 vert 16
"""
import bpy
script = """
from bge import logic
cont = logic.getCurrentController()
object = cont.owner
for mesh in object.meshes:
for m_index in range(len(mesh.materials)):
print("mat %i vert %i"%(m_index, mesh.getVertexArrayLength(m_index)))
for v_index in range(mesh.getVertexArrayLength(m_index)):
vertex = mesh.getVertex(m_index, v_index)
# Do something with vertex here...
# ... eg: color the vertex red.
vertex.color = [1.0, 0.1*v_index, 0.0, 1.0]
"""
# delete all objects
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
# Create new script
bpy.ops.text.new()
text = bpy.data.texts[-1]
text.name = "dbg.py"
text.write(script)
# Add a new Plane object in Edit mode
bpy.ops.mesh.primitive_plane_add(enter_editmode = True)
# Subdivide it
bpy.ops.mesh.subdivide()
# Add logic
bpy.ops.logic.sensor_add(type='ALWAYS')
sensor = bpy.context.object.game.sensors[-1]
bpy.ops.logic.controller_add(type='PYTHON')
controller = bpy.context.object.game.controllers[-1]
controller.text = text
controller.link(sensor = sensor)
# check poll() to avoid exception.
if bpy.ops.object.mode_set.poll():
# Exit Edit mode (Tab)
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
# Run the Game Engine
bpy.context.scene.game_settings.use_auto_start = True
# blender -P blend_mesh.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment