Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Work in Progress / Real-time Mesh Deformation Functions

Author
Message
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th Apr 2007 13:48 Edited at: 13th Apr 2007 11:43
Here are some functions which will deform a mesh in real-time. You can use them to blow stuff up, and simulate car crashes, etc.

Unfortunately, it does not yet support limbs, due to the missing command: Make mesh from limb

Also, it requires the matrix_utils plugin, or you have to write your own find free mesh() function

edit:
DEMO PROGRAM! (includes 1 extra function)


Here are the current functions:

ID as dword = SetupDeformableObject(ObjNum as dword, MemNum as dword)

ObjNum as dword = RemoveDeformableObject(ID as dword)

ApplySphereStickyDeformation(ID as dword, X as float, Y as float, Z as float, Xmo as float, Ymo as float, Zmo as float, Radius as float)

ApplySpherePushDeformation(ID as dword, X as float, Y as float, Z as float, Radius as float)

PositionVertexA(ID as dword, X as float, Y as float, Z as float, Xpos as float, Ypos as float, Zpos as float, Near as float)

PositionVertexB(ID as dword, Vertex as dword, Xpos as float, Ypos as float, Zpos as float)

OffsetVertexB(ID as dword, Vertex as dword, Xmo as float, Ymo as float, Zmo as float)

Number as dword = GetObjectNumber(ID as dword)

Number as dword = GetObjectMemblock(ID as dword)

FindObjectLocalCoords(ID as dword, X as float, Y as float, Z as float)

Result as float = GetObjectLocalCoordX(ID as dword)
Result as float = GetObjectLocalCoordY(ID as dword)
Result as float = GetObjectLocalCoordZ(ID as dword)

Here is a definition of each parameter:
ID as dword : Unique ID of deformable object, must be stored in a dword variable.
ObjNum as dword : Object Number.
MemNum as dword : Memblock Number to store mesh data.
X,Y,Z as float : Position where deforming happens.
Xmo/Ymo/Zmo as float : Direction of deformation.
Radius : Radius of deformation sphere.

Here is a definition of each function:
SetupDeformableObject : Must be called on an object prior to first deformation. Returns the ID needed to reference the object.
RemoveDeformableObject : Frees all memory created with SetupDeformableObject
ApplySphereStickyDeformation : Pushes all vertices within sphere in the direction of deformation
ApplySpherePushDeformation : Pushes all vertices out of the sphere in their current angle from the center of the sphere.
PositionVertexA : Positions all vertices within a sphere at a point
PositionVertexB : Positions a single verticex at a point
OffsetVertexB : Offsets a single verticex
GetObjectNumber : Gets object number from ID
GetObjectMemblock : Gets memblock number from ID
FindObjectLocalCoords : Transforms world coords into local coords (requires ezrotate)
GetObjectLocalCoordX : Retrieves X value from FindObjectLocalCoords (requires ezrotate)
GetObjectLocalCoordY : Retrieves Y value from FindObjectLocalCoords (requires ezrotate)
GetObjectLocalCoordZ : Retrieves Z value from FindObjectLocalCoords (requires ezrotate)

Functions working on:
ApplySimplePlaneDeformation : Push all vertices in front of a plane.
ApplyComplexPlaneDeformation : Push all vertices in a custom direction if a plane goes through them.
ApplySimpleCircleDeformation : Push all vertices in front of a circle.
ApplyComplexCircleDeformation : Push all vertices in a custom direction if a circle goes through them.

For me to complete those four functions, I need someone to answer my question in THIS thread.

And finally, here is the code: UPDATED WITH NINE NEW FUNCTIONS!


If you use these, or like them, then please post here! It will be much appreciated

Enjoy!

Vampiric
18
Years of Service
User Offline
Joined: 30th Oct 2006
Location:
Posted: 11th Apr 2007 14:21
Woah, how the hell?

Computer says n00bed
Bizar Guy
19
Years of Service
User Offline
Joined: 20th Apr 2005
Location: Bostonland
Posted: 11th Apr 2007 14:28
Nice, This could save me tons of time. Thanks!

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th Apr 2007 15:10
Quote: "Woah, how the hell?"

I'll take that as a compliment

Quote: "Nice, This could save me tons of time. Thanks!"

No problem

Tom J
19
Years of Service
User Offline
Joined: 4th Aug 2005
Location: Essex, England
Posted: 11th Apr 2007 15:50
Sounds cool, especially helpful for driving games

For that limbs problem, see if you can ask wolf about puting in the missing command into his dll that he is making. http://forum.thegamecreators.com/?m=forum_view&t=100167&b=8

Visit GamingColosseum Web - http://www.gamingc.co.nr/
Math89
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 11th Apr 2007 15:59
You should use vertexdata commands (it's what I usually do and it's really fast), it lets you specify the limb number you want to change and it's easier.
Vampiric
18
Years of Service
User Offline
Joined: 30th Oct 2006
Location:
Posted: 11th Apr 2007 16:18 Edited at: 11th Apr 2007 16:18
yeah that was a compliment, you've done some great coding there, looks like deformable terrain got a hell easier.

Computer says n00bed
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th Apr 2007 16:35
@Math89
I think it would be slower, because I would have to lock and unlock the vertexdata every time there was a deformation. At the moment, the memblocks are only created when the object is setup. Also, they may already be using the vertexdata for something

@Vampiric
Thanks again

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th Apr 2007 17:11 Edited at: 13th Apr 2007 11:43
OK, I have added three new functions, two are for modifying individual vertices, and one is for positioning all vertices inside a sphere at a specified point. The plane function only have a few bugs left to fix, and I am adding some functions for turning world coordinates into object coordinates (They will require EZrotate)

Here are the three new functions (UNTESTED)


Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 11th Apr 2007 18:34
Quote: "I think it would be slower, because I would have to lock and unlock the vertexdata every time there was a deformation."

Actually, using change mesh from memblock is very slow in realtime compared to using the vertex commands. At least, only when you want to edit a certain number of vertices. If all the vertices are being edited in one time it might be just as fast using memblocks however.

Tempest (DBP/DBCe)
Multisync V1 (DBP/DBCe)
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th Apr 2007 18:58
Here are 6 new functions to add


Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 12th Apr 2007 13:56
Here is an example of two of the mesh deformation functions

It lets you blow up a sphere in slow motion, and you can see the mesh deforming



You will see that there is a new function, called SphereDestroyFaces()
Any face which has a vertex inside the specified sphere, will have all of its vertices positioned at a point. (Effectively hiding the face)

If you use any of these, please post here

Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 13th Apr 2007 11:14
This is cool, keep up the good work.

Cheers,

-db


Albert Einstein believed that imagination is more important than knowledge.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 14th Apr 2007 00:07
Airslide
20
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 14th Apr 2007 00:13
This could be really useful! Thanks

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 16th Apr 2007 13:36
Glad you liked it

Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 17th Apr 2007 02:33 Edited at: 17th Apr 2007 02:35
Wow somebody made a really cool program!

(I like your avatar, it's always right and it catches me off guard so I can't outsmart it -_- Grr....)

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 17th Apr 2007 12:18

Login to post a reply

Server time is: 2024-11-23 23:39:46
Your offset time is: 2024-11-23 23:39:46