Anyone Have a B3d Loader?

Blitz3D Forums/Blitz3D Programming/Anyone Have a B3d Loader?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

If the quat stuff is freaking you out just use this. Create a quat, put data in from the file, convert to a rotation, and orient the mesh. No need to know how it works :D

http://www.dscho.co.uk/blitz/tutorials/quaternions.shtml
; Types
Type Rotation
	Field pitch#, yaw#, roll#
End Type

Type Quat
	Field w#, x#, y#, z#
End Type

; Change these constants if you notice slips in accuracy
Const QuatToEulerAccuracy# = 0.001

; convert a Quat to a Rotation
Function QuatToEuler(out.Rotation, src.Quat)
	Local sint#, cost#, sinv#, cosv#, sinf#, cosf#
	Local cost_temp#

	sint = (2 * src\w * src\y) - (2 * src\x * src\z)
	cost_temp = 1.0 - (sint * sint)

	If Abs(cost_temp) > QuatToEulerAccuracy
		cost = Sqr(cost_temp)
	Else
		cost = 0
	EndIf

	If Abs(cost) > QuatToEulerAccuracy
		sinv = ((2 * src\y * src\z) + (2 * src\w * src\x)) / cost
		cosv = (1 - (2 * src\x * src\x) - (2 * src\y * src\y)) / cost
		sinf = ((2 * src\x * src\y) + (2 * src\w * src\z)) / cost
		cosf = (1 - (2 * src\y * src\y) - (2 * src\z * src\z)) / cost
	Else
		sinv = (2 * src\w * src\x) - (2 * src\y * src\z)
		cosv = 1 - (2 * src\x * src\x) - (2 * src\z * src\z)
		sinf = 0
		cosf = 1
	EndIf

	; Generate the output rotation
	out\roll = -ATan2(sinv, cosv) ;  inverted due to change in handedness of coordinate system
	out\pitch = ATan2(sint, cost)
	out\yaw = ATan2(sinf, cosf)
End Function


Also, if you're still trying to write yours here's my crazy optimized way of identifying a ChunkID if your interested:

chunkID=PeekInt(bank,i)
Select chunkID
 Case 1398293844 ;TEXS
 Case 1398100546 ;BRUS
 Case 1162104654 ;NODE
 Case 1213416781 ;MESH
 Case 1398035030 ;VRTS
 Case 1397314132 ;TRIS
 Case 1296649793 ;ANIM
 Case 1162760002 ;BONE
 Case 1398359371 ;KEYS
End Select


And here's my read c string function:
Function ReadString$(Bank)
	Repeat
		ascii=PeekByte(Bank,i)
		If ascii=0 Then Exit Else out$=out$+Chr$(i)
		i=i+1
	Forever
	i=i+1
	Return out$
End Function
Assumes a global i which represents the position to be read (it also intcrements this up to the byte after the end of the string -ready for more reading.