Code archives/Miscellaneous/MediaView Enhanced

This code has been declared by its author to be Public Domain code.

Download source code

MediaView Enhanced by superqix2002
Attached is a new version of the MediaView that I enhanced with B3D support, spot and ambient light control, zoom in and out, Mesh Width, Height, and Depth data and some Windows XP fixes for Drag and Drop. Plus this version doesn't scale the model, so what you see (size wise) is what you get.
;Blitz media viewer.
;
;Create executable in 'bin'

AppTitle CommandLine$()
fil$=Trim$(Replace(Lower$( CommandLine$()),Chr$(34),Chr$(32)))


index=Instr( fil$,"." )
If index>0 ext$=Mid$( fil$,index+1 )

Select ext$
Case "x","3ds","b3d"
	ShowModel( fil$,False )
Case "md2"
	ShowModel( fil$,True )
Case "bmp","jpg","png","pcx","tga","iff"
	ShowImage( fil$ )
Case "wav"
	ShowSound( fil$ )
Case "mp3","mid","mod","x3m","xm","it"
	ShowMusic( fil$ )
Default
	RuntimeError "Unknown File Extension ("+ext$+")" 
End Select

End

Function ShowModel( fil$,md2 )
	If Windowed3D()
		Graphics3D 512,384,0,2
	Else
		Graphics3D 640,480,0,1
	EndIf
	If md2
		model=LoadMD2( fil$ )
;		If model ScaleEntity model,.025,.025,.025
	Else
		model=LoadMesh( fil$ )
;		If model FitMesh model,-1,-1,-1,2,2,2,True
	EndIf
	If model=0 RuntimeError "Unable to load 3D mesh:"+fil$
	sc=CountSurfaces(model)
	For k=1 To sc
		vc=vc+CountVertices( GetSurface( model,k ) )
		tc=tc+CountTriangles( GetSurface( model,k ) )
	Next
	camera=CreateCamera()
	CameraClsColor camera,0,0,64
	CameraRange camera,.01,10
	xr#=0:yr#=0:z#=2.1
	light=CreateLight()
	TurnEntity light,45,45,0
	bright = 255
	abright = 128
	Repeat
		RotateEntity model,xr,yr,0
		PositionEntity model,0,0,z
		If bright > 255 Then bright = 255
		If bright < -255 Then bright = -255
		LightColor light,bright,bright,bright 
		If abright > 255 Then abright = 255
		If abright < 0 Then abright = 0
		AmbientLight abright,abright,abright 
		UpdateWorld
		RenderWorld
    	Text 10,10,"Triangles: "+tc+" Vertices: "+vc+" Surfaces: "+sc
	  Text 10,22,"Point Light (-/+): "+bright
	  Text 10,34,"Ambient Light ([/]): "+abright
		Text 10,46,"Mesh Width: "+MeshWidth(model)
		Text 10,58,"Mesh Height: "+MeshHeight(model)
		Text 10,70,"Mesh Depth: "+MeshDepth(model)
		Text 10,82,"Zoom (a/z): "+z
		Flip
		key=False
		Repeat
			If KeyHit(1) End
			If KeyDown(200) xr=xr-3:key=True
			If KeyDown(208) xr=xr+3:key=True
			If KeyDown(203) yr=yr+3:key=True
			If KeyDown(205) yr=yr-3:key=True
			If KeyDown( 30) z=z-.1:key=True
			If KeyDown( 44) z=z+.1:key=True
			If KeyDown( 12) bright=bright-1:key=True
			If KeyDown( 13) bright=bright+1:key=True			
			If KeyDown( 26) abright=abright-1:key=True
			If KeyDown( 27) abright=abright+1:key=True	
			If Not key WaitKey
		Until key
	Forever
End Function

Function ShowImage( fil$ )
	Graphics 400,300,0,2
	SetBuffer BackBuffer()
	image=LoadImage( fil$ )
	If image=0 RuntimeError "Unable to load image:"+fil$
	MidHandle image
	x=200:y=150:t=4
	Repeat
		Cls
		DrawImage image,x,y
		Flip
		key=False
		Repeat
			If KeyHit(1) End
			If KeyDown(200) y=y-t:key=True
			If KeyDown(208) y=y+t:key=True
			If KeyDown(203) x=x-t:key=True
			If KeyDown(205) x=x+t:key=True
			If Not key WaitKey
		Until key
	Forever
End Function

Function ShowSound( fil$ )
	sound=LoadSound( fil$ )
	If sound=0 RuntimeError "Unable to load sound:"+fil$
	Repeat
		PlaySound sound
		WaitKey
		If KeyHit(1) End
	Forever
End Function

Function ShowMusic( fil$ )
	music=PlayMusic( fil$ )
	If music=0 RuntimeError "Unable to play music: "+fil$
	WaitKey
End Function

Comments

None.

Code Archives Forum