How can I change the [mesh] vertices data ...

Everything related to 3D programming
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

How can I change the [mesh] vertices data ...

Post by marc_256 »

Hi,

I just restarted my delta robot animation program,

To create my vacuum rubber mouth animation,
I can't use scale, as scale will scale all the parts of the mesh.
Same for the springs in the same project. (see image below)

So, I'm writing an animation algorithm ...

But I'm stuck ...

Where am I till now:

- created [texture]
- created [material]
- created [vertices] position list (x,y,z)
- created [vertices] number list
- created [edge] list (vertex1#, vertex2#)
- created [face] list (vertex1#, vertex2#, vertex3#)
- created [mesh]

- position [mesh]
- rotate [mesh]
- scale [mesh]

- created [camera]
- created [light]

- RenderWorld ()
- FlipBuffer ()

Till here all works very well ...


But:

For my mesh animation:
- the [vertices] quantity is the same
- the [edges] quantity is the same
- the [faces] quantity is the same

only the [vertices] positions are changing to animate.

example:
I have 1000 vertices and want to animate 500 of them.

- I updated the [vertices] position list (x,y,z) with new calculated data.
- my [vertices] number list is the same
- my [edge] list (vertex1#, vertex2#) is the same
- my [face] list (vertex1#, vertex2#, vertex3#) is the same

How can I change the [mesh] data to create a new animated mesh ?
Do I need to create new meshes [mesh1]...[mesh25] ?

thanks,
marc



Image
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
miso
Enthusiast
Enthusiast
Posts: 406
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: How can I change the [mesh] vertices data ...

Post by miso »

I'm not sure, how would I do this. If I understand well, you want to animate the springs. With UpdateMesh(), you can move the vertices to a new position.
(that will update all entities using that mesh.) If different moving parts are made as different submeshes, you can update those parts even individually, repositioning only their vertices.

Another method would be using bones, painting the vertices to them, and updating those.

I cant thin'k of another method, but might exist... (vertex shaders for example, but I'm not really good in that)
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How can I change the [mesh] vertices data ...

Post by Caronte3D »

Bones aren't a good choice for animating springs, as the spring wire itself would also stretch.
I think it's better to animate springs with "shape keys" in a 3D editor (like Blender) and then use this animation in PB as needed.
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: How can I change the [mesh] vertices data ...

Post by marc_256 »

Hi miso and Caronte3D,

what I can't use, tested till now:
- Scale = scaling the whole mesh, even the wire thickness.
- Bones = are deforming the mesh, it can also deform the wire.

The goal is to have the same wire diameter on all sides.
That is the reason i builded my own animation algorithm.
and it works very well, in separated meshes.

But my question was, how to change the vertices positions, and recreate the same mesh.

@miso

I think you are good,
I only need to create my mesh with #PB_Mesh_Dynamic flag.
Change the vertices position values, and use UpdateMesh().

I will test this.

thanks,
marc
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
SMaag
Enthusiast
Enthusiast
Posts: 299
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: How can I change the [mesh] vertices data ...

Post by SMaag »

maybe CreateDataMesh() will be faster than dynamic mesh and modifing vertice positions.
But you have to try.

CreateDataMesh() ; create the first view of the Spring
FreeMesh ; destroy the Mesh
CreateDataMesh() ; create the second view of the Spring

the reason why this might be faster is:
CreateDataMesh() copies all the Meshdata from your private Array in CPU RAM to the Video RAM.
So one solid block will be cpied to the GPU Video RAM using DMA commands, what's really fast.

Updating each vertice position in GPU RAM needs at least 1 procedure call per vertice which copy the
new positions for only one vertice. And this needs dynamic mesh what is slower in rendering..
marc_256
Addict
Addict
Posts: 835
Joined: Thu May 06, 2010 10:16 am
Location: Belgium
Contact:

Re: How can I change the [mesh] vertices data ...

Post by marc_256 »

Hello SMaag,

thanks for the tip,
I see under the documentation of [CreateDataMesh()]

Remarks
If the #Mesh was already created, then it is freed and replaced by a new one.

So, I don't need to free the mesh myself.

Marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...
miso
Enthusiast
Enthusiast
Posts: 406
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: How can I change the [mesh] vertices data ...

Post by miso »

But I'm not sure, that the new meshid will correspond to existing entitites. Positioning 1000 individual vertices should be fast even with every loop. (If thats the main feature you will show on screen)
Post Reply