realtime mesh warp

Hi,

Im trying to figure out how the mesh warp feature works so I can apply it in realtime to deform meshes. I think im part of the way there but im not too hot on my maths. If anyone can help that would be great. Ive asked similar stuff before but i think im clearer in my head what im after.

Here’s how the feature works as I understand it. Youre going to have to refer to my crappy diagram at: http://d.turboupload.com/d/525429/mesh_warp.jpg.html [sorry about the wait there, megaupload seems to be down]

Firstly, the warp only occurs on one plane so were dealing with 2 coordinates per point rather than 3 as we would 3d space.

X is the centre point or in Blender where the cursor lies[the red and white circle with a cross hair on it.]

v1 and v2 are two vertexs on a mesh were going to deform.

r1 and r2 are the radius’ of two imaginary circles drawn with X at their centre and v1 and v2 on their circumferance.

Now we have a number D which in Blender is the distance from the centre point to the mouse pointer. Lets say this number is +5.

To deform the mesh all that happens is the vertexs are moved around the imaginary circles circumferance- a distance of 5. Now this has to be a distance and not a degree in order for the vertexes furthest from X (in this case v2) to move less far.
[[ In actual fact both v1 and v2 are moving the same distance but the amount of degrees of their respective imaginary circles the inner vertex [v1] moves, is a larger amount than the vertex further away [v2].]]

From searching google ive found out the equation of a circle formula
( x – h)2 + (y – k)2 = r2
[ the 2’s in the formula are squared, cant figure superscript out]
Where h,k are the coords of the centre of the circle [X] and x,y are the coords of the point on the edge of the circle[our vertex].

What I cant figure out is how to get the coords of a point further along the circumferance.

If anyones got a maths brain on them or can point me in the direction of some equations that would be ace.

Thanks
Will

The only functions you can use in the game engine are the gamelogic functions.

Here’s a list of the object functions:
http://www.blender.org/modules/documentation/pydoc_gameengine/PyDoc-Gameengine-2.34/KX_GameObject.KX_GameObject-class.html

You’ll notice that there’s no mention of vertices any where in there. If you going to warp a mesh you’ll have to do it with an action, using bones.

Your only other alternative is to go into the source code and do it in c++.

I think the vertex wave demo you can download for 2.41 has something similar to this (You’ll need openGL 2.0). If you have OpenGL 2.0 you should see a mesh undulating up and down in a wavy fashion when you press P.

Hmm. Maybe you can do it with shader objects. I hadn’t looked at that.

hi Icoxco, ill check that outwhen im a bit more awake ut im trying to do this in blender alone, trying to learn pythons hard enough!!:slight_smile:

hi fireside, it is possible to get hold of individual vertices, after getting the object you get the mesh then you can get the vertex, then its possible to move them about


import GameLogic

cont = GameLogic.getCurrentController()
own = cont.getOwner()

scene = GameLogic.getCurrentScene()
grid = scene.getObjectList()["OBSphere"]
mesh = grid.getMesh(0)
for v_index in range(mesh.getVertexArrayLength(0)):
    vertex = mesh.getVertex(0, v_index)
    v_xyz = vertex.getXYZ()


but its a lot of hassle to move say the corner of a cube because 6(i think) vertices converge there, as there are the corners of 3 squares which each get broken into two triangles when entering the GE.

i wrote a script which makes it easier move “corners” of meshes by dumping all vertices that exist at the same coords into a list, its at
http://blenderartists.org/forum/showthread.php?t=54663

but im going off on one :slight_smile:

im slowly getting there with a test blend which is at:

http://d.turboupload.com/d/525699/meshdeform_test.blend.html

if you move the big cube away from the small one the radius of the circle increases and it goes round quicker. its just that the positioning of the centerpoint on the y axis isnt quite right, i guess its got something to do with sin and cos but like i say im no good at maths, got as far as i have thanks to pixelators post from a whiile back: http://blenderartists.org/forum/showthread.php?t=54636.

if you could take a look at the blend that would be great, thanks will

hi fireside, it is possible to get hold of individual vertices, after getting the object you get the mesh then you can get the vertex, then its possible to move them about

Hey!!! I missed that. Thanks. That could come in handy.
I wonder if it could be used for facial animation?
I bet it wouldn’t be hard to set up rvk in the game engine if they already have that.

hurray!!

so i found some maths on the net and its all working, but just with objects for the moment;

check it out at:

http://d.turboupload.com/d/525780/meshdeform_test.blend.html

up/down keys move the boxes

Just download the demo files just above the release logs on the 2.41 release page. It would be under graphics. It will be labled game engine demos.

Unfortunately I can’t help you farther then this cause I don’t understand the script it uses even though it’s available for anything you might need it for.

I’m afraid for most advanced effects like the new shaders you’ll need to learn python.

Hmm. Looks like you have some kind of planetary motion going on there. How is moving objects going to help moving vertices? I don’t quite get that, and what is it your trying to do, by the way?

im just trying to recreate the shift-w mesh warp tool and incorporate it into my vj app so meshes can be mangled in realtimeto a beat, hopefully it will really mess up the textures and look pretty interesting. Now all i have to do is replace the moving objects with groups of vertices on a mesh but i think ill wait till tomorrow for that:)

I haven’t downloaded yet, but I assume he’s moving all the verts, and not just the object.

No, it’s worse than that… you’ll have to learn how to write GLSL shaders in order to create a new shader and integrate it into Blender GE. :eek:

But if you can play your game on a system that supports them, GLSL shaders are definitely the way to go.

As far as moving vertices around realtime in the GE, Doc Holiday and JRT are probably the best folks to ask. Doc has a sample .blend on his site that uses Python to simulate a number of different wave patterns in a mesh. I’m sure you could learn what you need from his code to do what you want.

I started a thread on “realistic Ocean water” and the sample .exe I posted used GLSL vertex animation to move the surface around. I basically used the sample shader in the 2.41 sample graphics files (Rosesnail’s work, I beleive).

I’ve also experimented with bones to move vertices around, personally, I found it to be a pain.

Yup, sorry, no perfect solution, but some of these might get you started.

Which is why it would be atleast good to have a visual editor for the GLSL shaders, you could have a way of using Blender’s material editor for the shaders but for some like the texture blending you’ll need a different method. It would also greatly help if we could have an OpenGL 2.0 3D view and be able to see at least the shaders which this would go very nicely with the visual editor.

If Snailrose is reading this, he should try for this.

I might play around with it for a water effect. I think it would be a drag on the engine using a script to move that many vertices, though. Aside from being a good start for an rvk system, I don’t know what else it would be really good for. I wonder if it uses the same vertices as the modeling engine, or if they’re different?

Ok, sorry for going -way- off topic here: Yup, it would be great if Blender had this. Ogre has a plug-in for Max that does this. If you have Linux/OSX, you might want to check out my post in “Other Software” for “Equinox3D”. EQX3D (another free 3D model/animation app) not only has OpenGL 2.0 in a preview window, but also has a built-in CG/GLSL shader editor… too cool!

ok so heres a blend which warps a mesh around centre point- its really messy and not working quite right yet,ie its not actually moving around the centre point[ the small cube ]

http://d.turboupload.com/d/527142/meshwarp_alpha5.blend.html

it demonstrates that moving this small amount of vertices is no strain on the engine 300+ fps, but i guess opengl is the way forward from here