|
|
Vertex Ordering in meshes
About Truespace Archives
These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.
They are retained here for archive purposes only.
Vertex Ordering in meshes // Archive: Tech Forum
Post by frootee // Aug 1, 2007, 6:12am
|
frootee
Total Posts: 2667
|
I have a question about determining the ordering of vertices in meshes such as planes, cubes, spheres, etc.
This may already be in the documentation, although I have not yet found it.
Take a quad divided plane, for example. Are the vertices row or column oriented?
The reason I am asking is because I am modifying Jack Edwards' morph script to generate a waving flag effect. This script is coupled with Dele's spring script. The spring script generates an output value, which is pumped (messaged) to the input of the modified morph script (aka flag). This value is used to translate an entire column of vertices.
Of course, additional scripting needs to be done but the foundation is accessing the correct subset of vertices.
Thanks!
Froo |
Post by Jack Edwards // Aug 1, 2007, 10:41am
|
Jack Edwards
Total Posts: 4062
|
Sounds cool Frootee. :)
If I remember right the data is in triangle strips with edge flags, so I'm not sure vertex order would be consistant...?
-Jack. |
Post by Emma // Aug 1, 2007, 10:54am
|
Emma
Total Posts: 344
|
Did you take a look at this tutorial, it may possibly help a little bit regarding the vertex question ?
http://forums1.caligari.com/truespace/showthread.php?t=1685 |
Post by frootee // Aug 1, 2007, 11:03am
|
frootee
Total Posts: 2667
|
Thank you Jack.
And Danke Shun (spelling? Schoen? ) Emma! (My wife speaks German fluently but I don't so well...) I forgot about your tutorial. I saw it before but then drifted away from scripting.
I will be reviewing that tutorial starting Right Now!
I took Jack's script and stripped out what I did not need. Now I need to be able to access only certain sets of triangles/vertices.
It looks like, then, the meshes are arranged by triangle strips. That makes sense. Sounds like OpenGL. Kind of like peeling an orange: the orange peel is made of adjoining triangles, hence a triangle strip. :)
Thanks again!
Froo |
Post by Jack Edwards // Aug 1, 2007, 11:42am
|
Jack Edwards
Total Posts: 4062
|
You can still work it on a vertex level. Take a look at the cone example. If you're storing the vertex positions in your object then you can just re-generate the mesh with each vert in the position you want corresponding to the current animation frame.
-Jack. |
Post by frootee // Aug 1, 2007, 2:52pm
|
frootee
Total Posts: 2667
|
Thanks Jack; this is true.
But what I need to understand first is, how are the vertices organized? I assume that there is some order to them; are they organized from left to right, then in the next row, right to left, etc. or are they organized from top to bottom, then bottom to top; OR, are they ordered according to their indices in the triangle strip? I think I can find the answer in Emma's tutorial; I am halfway through it now. But if you know already, I'm all ears! :)
Thanks,
Froo |
Post by Jack Edwards // Aug 1, 2007, 5:23pm
|
Jack Edwards
Total Posts: 4062
|
I think you can organize the verts any way you like in the vertex list. The triangle strip array just stores vertex indicies -- not the actual verts themselves. So I think the only thing you have to get right is the order of the verts for each triangle in the triangle array so that the normals point the right direction.
And if you are writing the vert array and the tri strips, it's up to you how you want to order them. ;)
Edit: so the simple solution is to just pick an order and if the normals are facing the wrong way, pick the other order, LOL :D
-Jack. |
Post by frootee // Aug 1, 2007, 5:50pm
|
frootee
Total Posts: 2667
|
Well you know, that would make sense too; order the vertices as you choose, provided you build it yourself. I was thinking originally about taking an object prebuilt by truespace and modifying it; that's why I was trying to figure out how the vertices were arranged. Cool!
Thanks,
Froo
BTW Emma I did read your tutorial. Thank You it was very helpful!
I think you can organize the verts any way you like in the vertex list. The triangle strip array just stores vertex indicies -- not the actual verts themselves. So I think the only thing you have to get right is the order of the verts for each triangle in the triangle array so that the normals point the right direction.
And if you are writing the vert array and the tri strips, it's up to you how you want to order them. ;)
Edit: so the simple solution is to just pick an order and if the normals are facing the wrong way, pick the other order, LOL :D
-Jack. |
Post by ProfessorKhaos // Aug 1, 2007, 8:17pm
|
ProfessorKhaos
Total Posts: 622
|
It's actually not too tough to read out the vertex order. The following script can serve as a mini-inspector for mesh vertices (very small models)
Jscript object - Vertex Lister
input type is a mesh
output type is a string
// OnComputeOutputs
// Called to compute values of all output connectors
function OnComputeOutputs(params)
{
var mesh_in = params.ConValue('mesh_in');
// TODO: put your computation here
NumVertices = mesh_in.GetNumVertices();
if (NumVertices == 0) {
params.ConValue('vertices_in_mesh_order') = "No Mesh Supplied";
return;
}
VertexList = mesh_in.GetVertices();
var vertices_in_mesh_order = "#\tx\ty\tz\n";
for (i=0; i < NumVertices; i++)
{
this_x = VertexList.x(i);
this_y = VertexList.y(i);
this_z = VertexList.z(i);
vertices_in_mesh_order = vertices_in_mesh_order + i + ":\t" + this_x + "\t" + this_y + "\t" + this_z + "\n"
}
params.ConValue('vertices_in_mesh_order') = vertices_in_mesh_order;
}
Hook the output of the mesh on the object to the input of this object.
Obviously you won't be able to see all of the vertices if there's a long list but for smaller objects it should give you a clue as to vertex order.
By the way, the Mesh Cube Example brick is under the Base Objects in the library (tS7.5+). It's a bit more detailed than the cone script when you want to deal with setting surface normals, UV coords, etc... Comments are very thorough. |
Post by frootee // Aug 2, 2007, 1:14am
|
frootee
Total Posts: 2667
|
Nice. Thanks PK!
I took my first shot at the scrip tlast night. Nothing happened. I'll take a look at it and will most likely post it here so others can take a look to see if there is anything that stands out as a problem.
Thanks again!
Froo |
Post by frootee // Aug 2, 2007, 2:11am
|
frootee
Total Posts: 2667
|
Problem solved!
The reason why nothing happened is because I did not EXPORT the output mesh attribute from the inner level of the object. Exporting the calculated output mesh made the mesh data 'public' to all objects in the scene, including the workspace realtime rendering engine.
Here's the scene if you want to take a look at the LE and associated script.
Currently the normals are inverted, as you can see the Inside of the cube, not the Outside. How'd that happen? I did not rearrange the vertex order; I just connected a cube mesh, translated all vertices (for now; shortly I will touch only the ones I want), then output the same mesh. Hm.
Thanks again for the script Jack. This looks like a good start for a troubleshooting app as well.
And thanks again Emma for the tutorial. That helped me visualize the organization of the vertices.
Froo
EDIT: Come to think of it now, this probably looks very near like Dele's original spring script. That would also be a good place to start (sometimes it takes awhile for things to dawn on me... ) |
Post by frootee // Aug 2, 2007, 2:17am
|
frootee
Total Posts: 2667
|
To get an idea of where I'm going with this, change this line in the script:
for (vert_index = 0; vert_index < BaseMeshNumVertices; vert_index++) {
to this: (just put the -4 after BaseMeshNumVertices).
for (vert_index = 0; vert_index < BaseMeshNumVertices-4; vert_index++) {
This affects only one set of vertices. If this were a subdivided cube we'd be getting closer to the flag wave effect I'm wanting to achieve for Weaveribm's flag and other apps.
Froo |
Post by ProfessorKhaos // Aug 2, 2007, 4:12am
|
ProfessorKhaos
Total Posts: 622
|
The normals aren't inverted... the vertices are inadvertently mirrored around the z-axis in your script. Hook a cone object up to your basemesh input and you'll see what I mean. Not as visible with a cube as input.
When you subtract z from nSpringVal1 then you're actually adding nSpringVal to a z-mirrored object.
I'd just add the numbers together instead of taking the difference. Difference calculation is involved in interpolation between 2 input meshes but not this case.
Maybe something like the following (simplified for the moment).
for (vert_index = 0; vert_index < BaseMeshNumVertices; vert_index++) {
// do x
x = BaseMeshVerts.x(vert_index);
new_x = x;
MeshVerts.x(vert_index) = new_x;
// do y
y = BaseMeshVerts.y(vert_index);
new_y = y;
MeshVerts.y(vert_index) = new_y;
// do z
z = BaseMeshVerts.z(vert_index);
new_z = nSpringVal1 + z;
MeshVerts.z(vert_index) = new_z;
}
X and Y axis are not actually modified so the above example just duplicates their old contents (though you may have plans for them later). |
Post by frootee // Aug 2, 2007, 4:26am
|
frootee
Total Posts: 2667
|
Thanks PK. That should do it! I don't have ts here at work so I'll take a look at it tonight. But I can see it in the math;
Even more directly,
// do x
MeshVerts.x(vert_index) = BaseMeshVerts.x(vert_index); // No Mods to x
// do y
MeshVerts.y(vert_index) = BaseMeshVerts.y(vert_index); // No Mods to y
Froo |
Post by frootee // Aug 3, 2007, 2:57am
|
frootee
Total Posts: 2667
|
Okay, I have another problem here.
I attached PK's Vertex Lister object and I can clearly see there are 26 unique vertices. But when I try to manipulate vertices beyond #7, nothing happens.
I started with a regular cube with 8 vertices, then quad divided it. I tried setting the output mesh to a non-registered mesh, and attached the Shape object to the output. Still nothing.
Also, if I try to create a copy of the Flag script, so I can attach it to a different object (another cube), the flag is created along with another cube. So, if I delete the flag copy, the cube copy that was created also gets deleted.
Here's the file, which includes PK's vertex counter.
Can you take a peek and see if you can find the problems?
Thanks,
Froo |
Post by ProfessorKhaos // Aug 3, 2007, 3:35am
|
ProfessorKhaos
Total Posts: 622
|
There was a slight connector problem in the top level encapsulation around your inner flag brick. You had two Mesh outputs which likely confused the system. You won't need the shape brick outside the top level encapsulation.
Here's a quick rework. Looks like your script is only set up to move vertex 9 at the moment. I was able to test it with all the vertices (changed it back to vertex 9 when I was done). Added another vertex lister to the output of the new flag mesh generator and you can clearly see vertex 9 getting modded.
Not quite sure on your 2nd question what you're trying to do? If you mean the output of the 2nd flag object shows a cube even with no incoming links, that's because the input connector is still storing information from the last mesh it dealt with in the original copy. You can right click on the mesh input and select reset if you like. That will clear it out until you're ready to link it to a new base mesh object.
P.K. |
Post by frootee // Aug 3, 2007, 4:17am
|
frootee
Total Posts: 2667
|
Thanks PK. I did not know it was possible to create two mesh outputs. I think I know how this happened. When I first started this I could not get the mesh to move so I exported the mesh output, but the connector did not turn into a blue/white half-circle which indicates an exported connector. At least that's what it looked like. I probably did not know what to look for. Thank You for investigating this and correcting the problem PK. I will review it tonight since I don't have truespace here at work (probably a good thing! :p )
Regarding the second question, I did not know you could right click and reset the input mesh connector. COOL! This is the process I would follow, and the result:
1. Disconnect all input links on the original script object
2. Ctrl-LMB drag on the flag script object to create a new one
3. add a cube object to the scene
4. convert new cube into a editable mesh
5. subdivide the cube created in step 4
6. attach the cube from step 5 as an input mesh to the flag object generated in step 2
7. Press Start on timer object to start spring object data generation
8. cube from step 5 does nothing
9. So this must be due to not resetting the input link on the 2nd flag script object.
Thanks again PK! I hope that continuing this discussion will allow others interested to learn from this.
Froo
There was a slight connector problem in the top level encapsulation around your inner flag brick. You had two Mesh outputs which likely confused the system. You won't need the shape brick outside the top level encapsulation.
Here's a quick rework. Looks like your script is only set up to move vertex 9 at the moment. I was able to test it with all the vertices (changed it back to vertex 9 when I was done). Added another vertex lister to the output of the new flag mesh generator and you can clearly see vertex 9 getting modded.
Not quite sure on your 2nd question what you're trying to do? If you mean the output of the 2nd flag object shows a cube even with no incoming links, that's because the input connector is still storing information from the last mesh it dealt with in the original copy. You can right click on the mesh input and select reset if you like. That will clear it out until you're ready to link it to a new base mesh object.
P.K. |
Post by frootee // Aug 4, 2007, 4:13am
|
frootee
Total Posts: 2667
|
OK, couple more questions:
Where is the Shape brick? Is it in the libraries? I cannot find it. I ended up Ctrl-click dragging a Shape brick from the cone object.
Trouble with this is, I cannot seem to Export the Output Mesh attribute. I try right clicking on the attribute and selecting Export but nothing happens.
Thanks!
Froo |
Post by frootee // Aug 4, 2007, 6:17am
|
frootee
Total Posts: 2667
|
Basically, in general, I cannot seem to Export the output mesh attribute at all on these Shape bricks.
Any tips would be most appreciated!
Froo |
Post by frootee // Aug 4, 2007, 7:41am
|
frootee
Total Posts: 2667
|
Basically, in general, I cannot seem to Export the output mesh attribute at all on these Shape bricks.
Any tips would be most appreciated!
Froo |
Post by ProfessorKhaos // Aug 4, 2007, 4:27pm
|
ProfessorKhaos
Total Posts: 622
|
Hmmm... maybe if there's some way of capturing it I could show a quick video of what I do. I'll see what I can put together. May end up just being a series of screenshots in a sort of tutorial style. Still need to find a good screen capturing program that shows mouse clicks and such. |
Post by frootee // Aug 4, 2007, 4:49pm
|
frootee
Total Posts: 2667
|
Well, I figured out how to be able to re-export the attribute -
Turns out that if I right click the mesh in a 3d view, the exported attribute from the shape brick gets disconnected. So if I try to reconnect, it is impossible, unless I start over, like this:
in the flag attributes, delete the output mesh
recreate the flag output mesh attribute
connect the flag output attribute to the input mesh attribute of the shape brick
export the mesh attribute of the shape brick
So I know how to redo it, but I still cannot find where the Shape brick is in the libraries. Maybe it's a moot point, but I just want to know where the heck to find it, as opposed to loading some pre-rolled object, and copying the shape brick from there in the LE.
thanks!@
Froo |
Post by stan // Aug 5, 2007, 7:14am
|
stan
Total Posts: 1240
|
to create a shape node from scratch run this line of code I usually do it from a jscript command ;)
Node.Create('Space 3D Package/Shape', '/Project/Space 3D') |
Post by frootee // Aug 5, 2007, 12:34pm
|
frootee
Total Posts: 2667
|
thanks Stan. I tried doing that but did not actually get one created. I will have to readup on script commands.
I got this sort of working; it's not perfect; basically I am using a sine wave to generate the wave flow. But, it still looks like right in the middle of the flag (plane), there is no movement. I am sure it is something simple; I want to be able to move the wave along the flag, rather than a simple oscillation.
Here's the file if you want to look at it, and if you can figure out how to make a better rolling effect please modify and repost!
Froo |
Post by stan // Aug 5, 2007, 4:52pm
|
stan
Total Posts: 1240
|
I posted an example of Node.Create() and hoe to use it in the scriptorium :) |
Post by frootee // Aug 5, 2007, 4:56pm
|
frootee
Total Posts: 2667
|
Groovy thanks Stan!
I am trying to learn scripting but also am strongly interested in character animation; hopefully I can meld the two sometime!
Froo |
Post by weaveribm // Aug 5, 2007, 11:26pm
|
weaveribm
Total Posts: 592
|
Very nice run cycle Frootee! :)
That was very speedily implemented and looks as if there's a cloth motion, water animation application?/plugin?/script? upcoming - must be a catchier name for scripts that do something wonderful rather than scripts. Not plugins because it's all there it just has to be dug out like Pharoah's tomb. This would make you Howard Carter :)
Is there a way to get your excellent sinewave animation into a Vray animation? I've rendered an RAF flag to your placeholder image Frootee and lit it and so on (to show to my friend who's directing our modest community movie) but the sinewaving-image animates on hitting the Timer Start button in the LE and I don't know how to get from the LE to keyframes. Sorry to add to your burden and thanks again for sharing this very interesting work!!
I'm not at all any use at maths Frootee but I do know that sinewaves are handled by that Fast Fourier Transform routine which allows composing a complex waveform from any number of pure sinewaves; and decomposing a complex signal (waveform) into the number of pure sinewaves that added together make the complex waveform. For future developments info I mean.
Very interesting watching the plane animating while having an eye on the LE and the script objects. You clever chaps are proving that Modelspace is the plugin not Workspace. It's an aagghh!-shock now switching to Modelspace - even if it's still very important for now for some things :)
Peter |
Post by frootee // Aug 6, 2007, 4:13am
|
frootee
Total Posts: 2667
|
No problem Peter. I ahve been wanting to get into scripting for awhile anyway. I was surprised at how much I had forgotten regarding geometry/trigonometry/Fourier signal stuff.
You're right about Fourier transforms. A sine wave is something like this (only from memory so don't laugh!) in the frequency domain:
[ e^(jw) + e^(-jw) ] / 2
e is the natural log, w (omega) is 2*PI*f (f = frequency), and j is the square root of -1.
Regarding animation, there is a keyframe attribute that can be added as an output from the script. I think that is how it could be done. I/We could ask the other scriptors this question.
I'm glad you also monitored the script output while the flag was oscillating. Being able to see the code in action from more than one point of view can get you to thinking about your creative animations from a technical perspective as well, which I feel is important and can be useful.
An interesting thought:
In production facilities, there are texture artists, lighters, modellers, environment modellers, animators, etc. Well, we have all that here! I think it would be really cool at some point if some folks could Organize and put an animation short together. But the trick is maintaining organization and following a plan from beginning to end.
Froo
Very nice run cycle Frootee! :)
That was very speedily implemented and looks as if there's a cloth motion, water animation application?/plugin?/script? upcoming - must be a catchier name for scripts that do something wonderful rather than scripts. Not plugins because it's all there it just has to be dug out like Pharoah's tomb. This would make you Howard Carter :)
Is there a way to get your excellent sinewave animation into a Vray animation? I've rendered an RAF flag to your placeholder image Frootee and lit it and so on (to show to my friend who's directing our modest community movie) but the sinewaving-image animates on hitting the Timer Start button in the LE and I don't know how to get from the LE to keyframes. Sorry to add to your burden and thanks again for sharing this very interesting work!!
I'm not at all any use at maths Frootee but I do know that sinewaves are handled by that Fast Fourier Transform routine which allows composing a complex waveform from any number of pure sinewaves; and decomposing a complex signal (waveform) into the number of pure sinewaves that added together make the complex waveform. For future developments info I mean.
Very interesting watching the plane animating while having an eye on the LE and the script objects. You clever chaps are proving that Modelspace is the plugin not Workspace. It's an aagghh!-shock now switching to Modelspace - even if it's still very important for now for some things :)
Peter |
Post by frootee // Aug 29, 2007, 4:23pm
|
frootee
Total Posts: 2667
|
Per Stan's suggestion I am attaching my transcript from the Aug. 28 2007 Scriptor meeting, explaining how I created this flag.
Froo
dadnabit... I forgot to email it to myself again... I'll do it tomorrow!
thanks Stan. I tried doing that but did not actually get one created. I will have to readup on script commands.
I got this sort of working; it's not perfect; basically I am using a sine wave to generate the wave flow. But, it still looks like right in the middle of the flag (plane), there is no movement. I am sure it is something simple; I want to be able to move the wave along the flag, rather than a simple oscillation.
Here's the file if you want to look at it, and if you can figure out how to make a better rolling effect please modify and repost!
Froo |
Post by weaveribm // Aug 30, 2007, 3:39am
|
weaveribm
Total Posts: 592
|
I am attaching my transcript
flab object
Hmmm :)
Excellent work Frootee and vertex team!!
Froo can you please tell us how to insert the flag-rippling scene into a Workspace scene and then run the flag animation while also running a camera flythrough of the main scene?
I'm not being lazy but on a really slow work 512MB computer...
The present flag scenes are scenes and I'm wondering if it's a matter of taking the script objects (FlagRippler and WindDance) and dropping them into the LE of the scene I'm working on, and then to attach the scripts somehow to Frootee's flag. I've found that I can change the flag texture and it still ripples :)
For more vertexes would it be reasonably easy to modify the basic flag script?
Nice work all, very much enjoying seeing the LE get one hell of a workout by youse guys :)
Peter |
|