3D Morph?

Blitz3D Forums/Blitz3D Programming/3D Morph?

The maths for doing a morph is really easy if you have the meshes to morph between. This is a function that I created some time ago to do some simple morphing for an idea i had. You simply call the function and send in the mesh to be morphed, the base mesh of the morph, the target mesh of the morph, and a stage between 0 and 1 that sets the bias of morph between base and target (0 = as base, 0.5 = even mix betwen base and target, 1 = as target).

Function DoMorph(morph,base,target,stage#)

	timeMorph = MilliSecs()

	allSurf = CountSurfaces(base)	
	
	For j = 1 To allSurf

		surfBase = GetSurface(base,j)
		surfTarget = GetSurface(target,j)
		surfMorph = GetSurface(morph ,j)
	
		allVerts = CountVertices(surfMorph)
	
		For i = 0 To allVerts-1
			VertexCoords surfMorph,i,VertexX(surfBase,i) + ((VertexX(surfTarget,i)-VertexX(surfBase,i))*stage),VertexY(surfBase,i) + ((VertexY(surfTarget,i)-VertexY(surfBase,i))*stage),VertexZ(surfBase,i) + ((VertexZ(surfTarget,i)-VertexZ(surfBase,i))*stage)
		Next
	
	Next
	
	Return  MilliSecs() - timeMorph
	
End Function


Oh! I just noticed there's a timer in there as well, which actually is the return value from the function. I guess I needed to time the time taken to do the morph. you can just remove it.

If you like I could send you the project where I do the morphing. It's actually really simple. I remember I just whipped it up in a few hours to test if you could do it

Hope this helps!

/PetBom