メッシュの変形

2010/8/12

Blender2.49

メッシュに頂点データの座標を変更することで行える。ただし、あくまで視覚的な変更だけで、物理エンジンに適応したり、センサーに反応させたりは出来ないご様子。

格子分割した平面メッシュを波(Sin波)の変形をさせるサンプル。頂点の取得についてはこちら。 objにはtimerプロパティ(obj["t"])が設定されている。

import math

cont = GameLogic.getCurrentController()
obj = cont.owner

t = obj["t"]

A = 0.5
T = 3.0
wLengh = 0.5

mesh = obj.meshes[0]
mat = mesh.materials[0]
matid = mat.getMaterialIndex()
lengh = mesh.getVertexArrayLength(matid)

for v_index in range(lengh):
    vex = mesh.getVertex(matid,v_index)
    d = math.hypot(vex.x,vex.y)
    vex.z = A*math.sin(2*math.pi*t/T - d/wLengh)

物理エンジンに適応したい場合にはプラグインなど使うとよいっぽい。
Blender game wave plug-in
http://www.ashsid.sk/wp/?p=105

Class KX_MeshProxy
http://www.blender.org/documentation/249PythonDoc/GE/GameTypes.KX_MeshProxy-class.html

Class KX_VertexProxy
http://www.blender.org/documentation/249PythonDoc/GE/GameTypes.KX_VertexProxy-class.html