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.

Code Snippets / [DBP] Exploding sphere using vertexdata commands

Author
Message
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 19th Dec 2008 20:15
I tried out the vertexdata commands. I took advantage of the "make memblock from mesh" command, which converts from the format where polygons may share vertices with other polygons, as used by DB primitives, to one where there are 3 unique vertices per polygon.

Anyway, press space to explode the sphere.

I'd like to check the speed of this vs memblocks. Might do that next..



Quentin Collins
17
Years of Service
User Offline
Joined: 26th Apr 2007
Location:
Posted: 19th Dec 2008 20:23
Nice effect, and pretty smooth. Good work!

When this baby hits 88mph, you're gonna see some serious sh..!
Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 20th Dec 2008 03:01
Nice work, I like it.
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 20th Dec 2008 03:20
Thanks guys.

Have played with this some more since. You get a lot more speed using "texture object" instead of "color object".

Have made version where faces spin in motion. Works OK. Not much difference in speed. Will post soon.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Dec 2008 23:30
I'm looking forward to seeing your latest example.

BTW, there's no need to create a memblock to separate out the vertices. Simply converting the object to a mesh does that:


Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 21st Dec 2008 02:49 Edited at: 21st Dec 2008 03:37
I didn't know about the "change mesh" command. It doesn't seem to work for me. It seems to do the same as

delete object
make object (from mesh)

, which when i tried it, kept the "format" of the object intact- ie if it started with shared vertices it kept them. Perhaps this is a DBP version issue or i have misunderstood. If you could edit my code and make it work without recourse to memblocks, i'd be very happy to see it.

Anyway "change mesh" seems a very useful function - especially for changing limbs, so thanks for the info.

OK here's a new version. Press [space] to explode, [control] to reset.


I haven't changed the normals yet- they should be spinning too. However, there is a problem in that backfaces should have reversed normals - i probably need to double up my polygons.

This is going to be useful for me because i am using a debris generator in my spaceship game, where simple plain particles spew out from explosions etc. I tried objects, instanced objects and objects with many limbs, and all were hella slow when the number of particles is appreciable. The maths for moving them was fast, but it seems DB is quite slow when you move large numbers of objects or limbs at a time. This should make that stuff much faster hopefully, and i can have a lot more grit and junk flying around in my game!

I should do a comparison with using memblocks to change object vertices on the fly to see what the speed difference is if any, then implement in the game.

HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 21st Dec 2008 11:46
@Mr Tank,

That's one clever bit of coding , might have a go at fitting into IanM twisty blobbly thing, once I see how you've got it to work.

Dark Physics makes any hot drink go cold.
Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 21st Dec 2008 13:01
Wow, nice work, I loaded my own object and watched it disintegrate, it was awesome. Good job.
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 22nd Dec 2008 02:48
Quote: "That's one clever bit of coding , might have a go at fitting into IanM twisty blobbly thing, once I see how you've got it to work."

Cheers. I had a look at that and thought it was pretty sweet, but didn't feel like thinking too hard at the time. Will check it out properly in a mo.

Quote: "Wow, nice work, I loaded my own object and watched it disintegrate, it was awesome. Good job. "

Cheers. Good thinking.

I did a quick and fairly unscientific test of vertexdata vs meshes for resetting the object. It seems that if you reset all data (vert positions, normals, diffuse, uv), change mesh and vertexdata are comparable. Change mesh is actually slightly faster, which makes sense since presumably it's just copying a block of data.

However, if you just reset the vertices, or even the vertices plus the normals, vertexdata commands work out faster.

In the case of setting data you are calculating on the fly, i expect the slight speed benefit of change mesh when setting all data is nulled, since you'd have to write your new data into a memblock, then change mesh from memblock before you can change mesh.

To sum up, where you can use them, vertexdata commands are faster than memblocks.

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 23rd Dec 2008 04:49
Here's a kind of particle fountain i made using similar methods. I think by using diffuse, can get the particles to fade too. The DBP plain by default uses 6 vertices. I expect there is a way to make one with memblocks that has only 4 vertices, which might be a bit faster.



IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Dec 2008 14:57
Unfortunately not - memblocks always generate non-indexed meshes. To generate an indexed mesh, you'll need to take a look at my plug-ins - they're the only ones that I know of that can be used to generate them. http://www.matrix1.demon.co.uk/Matrix1Utils_Help/Matrix1Util_18/make_object_new.html

Jeff Miller
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 23rd Dec 2008 23:00
I've been using IanM's plugin to make 4-vertex planes and it is easy and efficient. I use them wherever I do not need the backface, or for a token object like the center of a skybox, or for a single pixel invisible sprite to use as a mouse-follower to get sprite collision using the system mouse.
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 24th Dec 2008 04:47 Edited at: 24th Dec 2008 04:49
Thanks.

Ian
I keep meaning to use your plugins, because i keep hearing really good stuff about them. I will try to do so soon. I don't really understand the whole plugin thing yet. Should really dip my toes in soon.

Jeff
Not sure what you mean about not needing backfaces. I guess for token objects, you mean using single, or no vertex objects with no faces or something? That would be cool. I guess i'll find all this stuff out when i play with the plugin.


For my current purpose, i could just export a plain from milkshape. Should work well enough.


I will certainly check out Ian's thing at some point soon though! Sounds like a very powerful tool. For large smooth meshes, having a sixth the number of vertices will be very useful, particularly when manipulating in realtime!

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Dec 2008 17:54
Very nice effect.

Definitely one to include in a game - when I eventually get around to it.
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 26th Dec 2008 23:00
Thanks Gandalf. I look forward to seeing what you make from it.

Here's a confetti sprinkling demo thing. It uses a 4 vertex plain .x object that i will attatch to this post. Uses vertex diffuse for colours instead of texture. I was inspired by IanM's blobby thing. You can also use vertex diffuse with rgba and alpha mapping to fade vertices individually. This isn't in the code here, but you can try uncommenting some things....

Note that this code uses 64 objects instead of one. For speed it is better to use one. It's only 64 because this is approaching the code i will be using on my game, and i am using multiple objects for other reasons.



Attachments

Login to view attachments
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 28th Dec 2008 04:00 Edited at: 28th Dec 2008 05:26
I managed to add this into my game now. Works OK.

Vertexdata is awesome. You can change uv coordinates individually for different texture layers. This means you can get around the blend mapping bug/problem where you can't scale (or scroll i think) the object's textures separately! Many more possibilities!



Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 9th Jan 2009 14:35
Outstanding work! Kudos (and a Kiwi)
Dragon Knight
17
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 4th Mar 2009 04:09
Mr Tank, this is absolutely what i've been looking for! I'm going to implement it as a function to create a partial explosion / desintigrate an object in-game, if the object doesn't already exist.

This leads to so many possibilities, for me now ^-^, just wanted to say thanks

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 27th Mar 2009 22:37
Thanks guys. I'm really glad someone is finding a use for this.

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 9th Apr 2009 03:03
That's great! Very usable. One thing - I noticed that whenever I loaded an outside object, there was always one triangle that stayed floating in the air where the object was. It did this with several models I've tried from the TGC store.



Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 9th Apr 2009 18:41 Edited at: 9th Apr 2009 18:42
Thanks dude. I suspect i am one out in a loop. I probably put

1 to nfm1

where it should actually be

0 to nfm1

somewhere. Which version are you using? The one from the first post, or the next version? If you can't fix it i'll see if i can.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 10th Apr 2009 02:03
Indeed, I changed the statement on line 273 to for f=0 to... and it worked fine! Thanks! (it's the second version)



Juso
22
Years of Service
User Offline
Joined: 23rd Sep 2002
Location: Finland
Posted: 9th May 2009 15:12 Edited at: 9th May 2009 15:15
Excellent fun!

With minor changes (in the beginning of the Do loop) you can suspend and continue the explosion with Space key and move camera with arrowkeys. Also in windowed mode.

Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 28th May 2009 16:54
I stored a copy of this code when I saw it, thinking it would be useful sometime =)

Now that Ive started my game, I was right, this, with a bit of tinkering plus a new texture, looks like it could be the explosion I'm looking for.

Cheers for the hard work, Dr Tank (You changed name right...)

Hope you keep coming up with cool stuff =)

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 28th May 2009 17:37
Quote: "You changed name right..."

Yes, he did, I didn't even notice that

Wait, but then who is this Dr Tank 4 posts up from this post?

Anyway, I'm nearly done converting this into a set of functions that should enable you to explode an indefinite number of objects at once or at different times...I just need to get rang# converted to a memblock...



Diggsey: I have a spine and memory, but one memorable guy says he hates me. What am I?
Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 31st May 2009 16:09
Quote: "Wait, but then who is this Dr Tank 4 posts up from this post? "


Ones guessing he graduated.....

That function sounds very useful for many different things... I wouldnt mind seeing that once youve done it..

Dr Tank
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 31st May 2009 18:27
Thanks guys. Good to know this is useful.

The name change was forced - some knobhead put a misleading link in a thread here and logged me out, and i no longer have the email address i signed up with.

However, i have graduated. I've had a PhD in physics for a couple of years now. Still haven't got a proper job yet, because i'm lazy and i suck. Working on it.

Login to post a reply

Server time is: 2024-11-24 22:20:21
Your offset time is: 2024-11-24 22:20:21