Convert to a single surface

Blitz3D Forums/Blitz3D Programming/Convert to a single surface

FlagDKT(Posted 2009) [#1]
What's the best way to convert onthefly a b3dmodel(with his childs) to a single surface model?
I don't need to retain textures and uvs...I just need the model structure with 1 surface only.


Ross C(Posted 2009) [#2]
Addmesh will accomplish this :o) Just remember, it will create a new mesh. If you read the docs, you will see what i mean.


FlagDKT(Posted 2009) [#3]
Surface sets are *not* copied as well?


Ross C(Posted 2009) [#4]
It combines everything into the one surface. It just takes all the vertex locations and traingles that connect them and lumps it all into one mesh/surface.


FlagDKT(Posted 2009) [#5]
The problem is that I need to retain the model hierarchy too. There are several childs with a particular name that I use for doing stuff.


Ross C(Posted 2009) [#6]
You are at odds with what you said in your first post. You can't have a single surface model, yet retain the groups and their names. You could copy the mesh i suppose and combine the copy.

Can you further explain what this will be used for? Maybe there is another way around what you are trying to achieve.


FlagDKT(Posted 2009) [#7]
Ok I have to be more clear :)
From 3dsmax I export a b3dmodel containing several objects named "ground_collision", "wall_collision", "trigger_1" that I use to build the level structure.
I use getchild() to find "ground_collision" then pass it to PhysxBodyCreateMesh() function to create a static rigib body for the world collisions.
Unfortunately this function doesn't work well with multisurfaces objects (I know I could export it, disabling textures from b3d exporter).
The function is:

Function PhysxBodyCreateMesh(mesh%,mass=0)
	
	nsurf = CountSurfaces(mesh)
	nvert = 0
	nface=0
	For ns = 1 To nsurf
		Local surf = GetSurface(mesh,ns)
		nface = nface+CountTriangles(surf)
		nvert = nvert +CountVertices(surf)
	Next
	
	fbank = CreateBank(nface*4*3)	
	nf = 0
	vbank = CreateBank(nvert*4*3)	
	nv = 0
	For ns = 1 To nsurf
		surf = GetSurface(mesh,ns)
		
		nfv = CountTriangles(surf)
		For nfc = 0 To nfv -1
			PokeInt fbank,(nf*12)+0,TriangleVertex(surf,nfc,0)	
			PokeInt fbank,(nf*12)+4,TriangleVertex(surf,nfc,1)
			PokeInt fbank,(nf*12)+8,TriangleVertex(surf,nfc,2)
			nf=nf+1
		Next
		nvv = CountVertices(surf)
		For nvc = 0 To nvv - 1
			vx#=VertexX(surf,nvc)
			vy#=VertexY(surf,nvc)
			vz#=VertexZ(surf,nvc)
			TFormPoint vx#,vy#,vz#,mesh,0
			
			PokeFloat vbank,(nv*12)+0,TFormedX()
			PokeFloat vbank,(nv*12)+4,TFormedY()
			PokeFloat vbank,(nv*12)+8,TFormedZ()
			nv = nv+1

		Next
	Next
	

	bbb%=pxCreateTriMesh (vbank, fbank, nvert, nface, mass)
	FreeBank vbank
	FreeBank fbank
	Return bbb%
End Function

It is strange that it works only for a single surface object...with the two or more surfaces it creates random faces in the collisions.
What's wrong??


FlagDKT(Posted 2009) [#8]
Uhm... TriangleVertex returns an indexed vertex related to surface it is in. While the vertex loop uses a unique vertex index.
How to fix that?


FlagDKT(Posted 2009) [#9]
nevermind. fixed.


Ross C(Posted 2009) [#10]
So, do you still require help on this? :)


FlagDKT(Posted 2009) [#11]
No I found the solution!
thx anyway :)


Ross C(Posted 2009) [#12]
nps. glad your sorted.