vertices count in a mesh

Blitz3D Forums/Blitz3D Programming/vertices count in a mesh

orion one(Posted 2003) [#1]
hi, i'm new here and i am trying to get the coordinates of each and every vertex in imported .3ds or .x meshes, but i have no idea how i should be proceeding... my point is to interact with an imported mesh and deform it. thx in advance !


orion one(Posted 2003) [#2]
hi orion one, this is orion one ... what if those meshes have only one surface ? CountVertices can't work then, so ?

bye, orion one


semar(Posted 2003) [#3]
[EDITED]
surfaces = countsurfaces(mesh)
for S = 1 to surfaces
vertices = countvertices(surfaces)
for V = 0 to vertices - 1
print vertexX(S,V)
next
next


Hope this helps, orion one.
Sergio.


orion one(Posted 2003) [#4]
hi semar,

thx for your routine, i have tested it on the meshes from the built-in 3D tutorials. i get a number of surfaces from 1 to 5 i.e. but a systematic memory access violation when it comes to count the vertices... why o why ? thx to all of you


mesh=LoadMesh("C:\Program Files\Blitz3D\Samples\Blitz 3D Samples\mak\teapot\teapot.x")
surfaces=CountSurfaces(mesh)
For s=1 To surfaces
vertices=CountVertices(surfaces)
For v=0 To vertices
Print VertexX(s,v)
Next
Next

Acorn BBC model B 32k


semar(Posted 2003) [#5]
sorry.

Change
For v=0 To vertices
to
For v=0 To vertices -1

Since vertices counting in a surface go from 0 to num of vertices - 1.


orion one(Posted 2003) [#6]
ciao sergio,

now it's like that :

Graphics3D 640, 480
mesh=LoadMesh("C:\Program Files\Blitz3D\Samples\Blitz 3D Samples\mak\driver\car.x")
surfaces=CountSurfaces(mesh)
Print surfaces
For s=1 To surfaces
vertices=CountVertices(s)
For v=0 To vertices-1
Print VertexX(s,v)
Next
Next

i've changed vertices=countvertices(surfaces) to countvertices(s)

u've changed vertices to vertices-1

but still the same error... sorry to bother you with that

orion one


orion one(Posted 2003) [#7]
this works, Sergio !

Graphics3D 640, 480
mesh=LoadMesh("C:\Program Files\Blitz3D\Samples\Blitz 3D Samples\mak\driver\car.x")
surfaces=CountSurfaces(mesh)
For s=1 To surfaces
ss=GetSurface(mesh,s)
vertices=CountVertices(ss)
For v=0 To vertices-1
Print VertexX(ss,v)
Next
Next

the idea seems to use getsurface ... ti ringrazio molto, ciao


semar(Posted 2003) [#8]
Oh yes, getsurface was missing, hem... !!!

=)

You know, I have not blitz where I write from..!

(prego, non c'e' di che ! Ah ma sei italiano anche tu ?!?)

Bye,
Sergio.


orion one(Posted 2003) [#9]
50% italiano Sergio, forse ci conviene continuare via email/messenger senó incazziamo tutti hehe


orion one(Posted 2003) [#10]
now another question : how do you DELETE a vertex in a mesh, or a vertex just added via AddVertex ?

Orion One

P.S. Dai Sergio dammi 'cora 'na mano ti prego


semar(Posted 2003) [#11]
ClearSurface surface,[clear_verts][,clear_triangles]
Parameters:
surface - surface handle
clear_verts (optional) - true to remove all vertices from the specified surface, false not to. Defaults to true.
clear_triangles (optional) - true to remove all triangles from the specified surface, false not to. Defaults to true.
Description:
Removes all vertices and/or triangles from a surface.

This is useful for clearing sections of mesh. The results will be instantly visible.

After clearing a surface, you may wish to add vertices and triangles to it again but with a slightly different polygon count for dynamic level of detail (LOD).


orion one(Posted 2003) [#12]
thanks semar

but my point is to delete one or a few vertices from a surface, not all of them.

and by the way, how can i control the number of surfaces of a mesh created from scratch ? and in imported meshes (with 3D canvas per esempio)

thx a lot


semar(Posted 2003) [#13]
Hum, I don't know if you can just delete a vertex, since a surface is made up by triangles, and each triangle needs three vertices.

So if you (theoretically) delete only one vertex, how can the related triangle exist ?

I *think* that you should delete the triangle, so to delete the one vertex you need to be deleted, and then re-create the triangle with the remaining two vertices, plus one that should come from another adiacent triangle.

I'm just guessing...


orion one(Posted 2003) [#14]
good guesses :

i want to be able to delete vertices, and therefore the related triangles won't exist anymore (i want to create holes in meshes)

is there any mean to delete single triangles instead of vertices ?


DJWoodgate(Posted 2003) [#15]
Triangles can share vertices. So I guess what you could try is deleting all the triangles and then rebuild the surface without the triangle you want to remove. Rebuilding the triangle list should be faster than rebuilding the vert list because a triangle needs a lot less information. So you need to build a triangle list as shown below. This of course can be optimised, you do not really need to build a new trilist each time you do this. Of course you can get rid of the pesky verts you do not really need as well, but thats a bit more complicated.

Dim Trilist(3000,2)

Function removetri(surf,tri)
	numtris=CountTriangles(surf)
	For t=0 To numtris-1
		trilist(t,0)=TriangleVertex(surf,t,0)
		trilist(t,1)=TriangleVertex(surf,t,1)
		trilist(t,2)=TriangleVertex(surf,t,2)
	Next
	ClearSurface surf,False,True
	For t=0 To numtris-1
		If t<>tri Then 	AddTriangle(surf,trilist(t,0),trilist(t,1),trilist(t,2))
	Next
End Function	 


Graphics3D 640,480,0,2
sphere=CreateSphere(12)
EntityColor sphere,200,100,50
EntityPickMode sphere,2
EntityFX sphere,16

camera=CreateCamera()
PositionEntity camera,0,0,-3
light=CreateLight()
RotateEntity light,45,0,0


Repeat 

	mx=MouseX()
	my=MouseY()
	
	TurnEntity sphere,KeyDown(200)-KeyDown(208),KeyDown(205)-KeyDown(203),0
	
	If MouseDown(1) Then pick=CameraPick(camera,mx,my)
	
	If pick=sphere Then removetri(PickedSurface(),PickedTriangle())
	
	RenderWorld
	
	Text 0,0,TrisRendered()
	
	Flip
	
Until KeyDown(1)

End



orion one(Posted 2003) [#16]
thx for the code David.

i will post a new and better question a bit later when i come up with some fresh code and ideas.

thanks to all


Anthony Flack(Posted 2003) [#17]
By the way, I have no trouble clearing a surface and building up a whole new triangle + vertice list of about 3000 vertices and 1500 triangles within the space of 1 millisecond. My game does this every frame. So I think complete reconstruction could be an option.


orion one(Posted 2003) [#18]
thx Anthony, i have successfully solved my problem : i build a complex mesh with one triangle per surface, i can so delete a very small amount of the mesh at a time.

and with code optimization, this should do it

Orion One


Wayne(Posted 2003) [#19]
Hi Orion,
How large a mesh do you have planned ?


orion one(Posted 2003) [#20]
well, i plan to write a simulation of surgery, so i have several meshes representing each and every layer of human tissue, and moreover the deeper the structure the higher the number of meshes per tissue.

skin=at least 3 layers

let's say minimum 2000 triangles per layer, and that seems to me not to be enough