Page 1 of 1

Ogre Mesh Viewer

Posted: Sun Sep 02, 2012 3:44 pm
by applePi
there are Ogre Meshy http://www.ogre3d.org/tikiwiki/Ogre+Meshy to view mesh files. and below another Ogre mesh viewer with several facilities
, the program can be used to view 3d mesh files the easy way.
look the keys you can use at the title bar
Image
download the program with the textures necessary to run the program and 7 mesh samples: arrow, chinese (3D chars), fish, helicopter, purebasic (3D chars), ring, teapot:
http://www.mediafire.com/?8rq1tt8loi1nf95
the purebasic (3D chars) made using purebasic MP3D library using this code:
mesh = MP_Create3DText ("Times", "PureBasic")
MP_ScaleMesh(mesh,1,1,3)
MP_SaveMesh("purebasic.x",mesh)

after that importing the file purebasic.x by milkshape and exporting it to Ogre mesh file, but the attached chinese chars i can't make it this way, but after installing chinese fonts , and using google sketchUp http://sketchup.google.com/download/ i succeed to make 3D chinese chars by using the menu Tools -> 3D Text (using google translator the ch3.mesh meaning is karate school)

more info for working with mesh files:
a program to export 3D files to *.mesh files is MilkShape , download a shareware from here http://chumbalum.swissquake.ch/ and after install. download the "Milkshape3D Exporter" from http://www.ogre3d.org/download/tools
now open any 3D file from milkshape and File->Export->Ogre Mesh/skeleton, it is near the bottom of the List, and don't forget to choose Export material.
now what if the 3D file can't be accepted by milkshape because it has too many vertices. then use the freeware utility MeshLab from http://meshlab.sourceforge.net/ go down the page to see different downloads:
Download V1.3.2
- Windows
- Windows (x64)
- Linux (src)
- MacOSX (intel only)

let us make a practical experiment with it, go to this site wich convert your 3D files to physical model using a 3D printer
http://www.shapeways.com/gallery?downloadable=1
download a 3d file i suggest
http://www.shapeways.com/model/52936/on ... -ball.html
it is *.stl file 7MB
use MeshLab to open the 3d file you want to reduce its polygons, if you tried to export this huge file to 3ds the program will issue an error "you can't save more than 65535 vertices for the 3DS format"
so reduce its Polygons like this
Filters > Remeshing, simplification and construction > Quadratic Edge Collapse Detection
Target Number of faces 10000 (just a suggestion)
after that i got a very small 3ds file just a 190KB, now you can use milkshape to import this 3ds file and Export to Mesh file easily.
the above MeshLab info from: http://www.shapeways.com/tutorials/poly ... th_meshlab

Code: Select all

Enumeration
   #MESH
   #TEX
   #TEX_plane
   #MAT
   #MAT_plane
   #plane
   #model
   #node
   #LIGHT
   #CAMERA_ONE
   #BUTTON
   #BUTTON_OPEN
   #mainwin
   #CheckBox
EndEnumeration
Global Quit.b = #False

Procedure textured()
CreateEntity(#model, MeshID(#MESH), MaterialID(#MAT))
meshsize.f = MeshRadius(#MESH)
ScaleEntity(#model,3/meshsize,3/meshsize,3/meshsize)
AttachNodeObject(#node,EntityID(#model),#PB_Node_Entity)
NodeLocate(#node,0,1.5,3)
EndProcedure

Procedure textured_no()
      FreeEntity(#model)
      CreateEntity(#model, MeshID(#MESH), #PB_Material_None )
      AttachNodeObject(#node,EntityID(#model),#PB_Node_Entity)
      NodeLocate(#node,0,1.5,3)
      meshsize.f = MeshRadius(#MESH)
      ScaleEntity(#model,3/meshsize,3/meshsize,3/meshsize) 
EndProcedure
ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "PgUp PgD scale model..Arrows for rotation, space: stop/rotate,  QA Up/Down, WS far/near", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(#BUTTON, 0, 420, 50, 30, "stop") 
  ButtonGadget(#BUTTON_OPEN, 70, 420, 50, 30, "Open File") 
CheckBoxGadget(#CheckBox, 200,  420, 250, 20, "Default Texture") :SetGadgetState(#CheckBox, #PB_Checkbox_Checked)

;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-70, 0, 0, 0)
WorldShadows(#PB_Shadow_Additive)

InitKeyboard()
SetFrameRate(60)

Add3DArchive("Data/", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Textures\", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()

LoadTexture(#TEX, "steelhead.png")
CreateMaterial(#MAT, TextureID(#TEX))

CreateMaterial(#MAT_plane, LoadTexture(#TEX_plane, "mosaic.png"))
;CreatePlane(#Mesh, TileSizeX, TileSizeZ, TileCountX, TileCountZ, TextureRepeatCountX, TextureRepeatCountZ)
CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))

LoadMesh(#MESH, "helicopter.mesh")
meshsize.f = MeshRadius(#MESH)
CreateNode(#node)
CreateEntity(#model, MeshID(#MESH), MaterialID(#MAT))
ScaleEntity(#model,3/meshsize,3/meshsize,3/meshsize)
AttachNodeObject(#node,EntityID(#model),#PB_Node_Entity)
NodeLocate(#node,0,1.5,3)
CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(#CAMERA_ONE, 0, 0, 400, 400)
CameraLocate(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)

RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf
rot.l=1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
rotx.f:roty.f=1:rotz.f :rotx0.f: roty0.f: rotz0.f
up.f = 1.5: depth.f=3
SetActiveGadget(#BUTTON)
SkyDome("clouds.jpg", 100) ;for blue color background

;Main loop
Repeat
  Event = WindowEvent()
  If Event = #PB_Event_Gadget
    Select EventGadget()
      Case #BUTTON
        If rot = 0
          rot = 1
          rotx= rotx0:roty=roty0:rotz=rotz0 ; restore rotation status
          SetGadgetText(#BUTTON,"stop")
        Else
          rot = 0
          rotx0= rotx:roty0=roty:rotz0=rotz ;back up rotation status
          rotx=0:roty=0:rotz=0
          SetGadgetText(#BUTTON,"rotate")
        EndIf
      Case #BUTTON_OPEN
        File$ = OpenFileRequester("choose *.mesh file", "", "Mesh files|*.mesh|All Files|*.*", 0)
        File$ = GetFilePart(File$)
        If File$="":End:EndIf
        SetActiveGadget(#BUTTON)
        FreeEntity(#model)
        FreeMesh(#MESH)
        LoadMesh(#MESH, File$)
        meshsize.f = MeshRadius(#MESH)
        CreateEntity(#model, MeshID(#MESH), MaterialID(#MAT))
        ScaleEntity(#model,3/meshsize,3/meshsize,3/meshsize)
        ;AnimateEntity(#model, "swim") ; if using the animated fish only, , removed and replaced in pb5 by other plan
        AttachNodeObject(#node,EntityID(#model),#PB_Node_Entity)
        NodeLocate(#node,0,1.5,3)
      Case #CheckBox
        If GetGadgetState(#CheckBox) = 0
           SetActiveGadget(#BUTTON)
           textured_no()
           NodeLocate(#node,0,up,depth)
          Else
            SetActiveGadget(#BUTTON)
            FreeEntity(#model)
            textured()
            NodeLocate(#node,0,up,depth)
            
       EndIf  
        
    EndSelect
  EndIf 
  
  x + rotx
  y + roty
  z + rotz
   RotateEntity(#model, x, y, z)
   
   RenderWorld()
   FlipBuffers()

  ExamineKeyboard()
  If KeyboardReleased(#PB_Key_Up)  ; rotate left
    rotx=1:roty=0:rotz=0
    rotx0 = rotx: roty0 = roty :rotz0 = rotz
    SetGadgetText(#BUTTON,"stop") : rot = 1
  ElseIf KeyboardReleased(#PB_Key_Down) ; rotate right
    rotx=-1:roty=0:rotz=0
    rotx0 = rotx: roty0 = roty :rotz0 = rotz
    SetGadgetText(#BUTTON,"stop") : rot = 1
  ElseIf KeyboardReleased(#PB_Key_Right)   ; rotate up
    rotx=0:roty=1:rotz=0
    rotx0 = rotx: roty0 = roty :rotz0 = rotz
    SetGadgetText(#BUTTON,"stop") : rot = 1
  ElseIf KeyboardReleased(#PB_Key_Left) ; rotate down
    rotx=0:roty=-1:rotz=0 
    rotx0 = rotx: roty0 = roty :rotz0 = rotz
    SetGadgetText(#BUTTON,"stop") : rot = 1
  EndIf 
  
  If KeyboardPushed(#PB_Key_PageUp) ; scale up model
    xs.f = 1.1:ys.f = 1.1:zs.f = 1.1
    ScaleEntity(#model,xs,ys,zs)
    
  ElseIf KeyboardPushed(#PB_Key_PageDown) ; scale down model
    xs = 0.9:ys = 0.9:zs= 0.9
    ScaleEntity(#model,xs,ys,zs)
    
  EndIf
  If KeyboardPushed(#PB_Key_Q) ; up move
    up + 0.1
    NodeLocate(#node,0,up,depth)
   ElseIf KeyboardPushed(#PB_Key_A) ; down move
    up - 0.1
    NodeLocate(#node,0,up,depth)
    ElseIf KeyboardPushed(#PB_Key_W) ; forward move
    depth - 0.1
    NodeLocate(#node,0,up,depth)
    ElseIf KeyboardPushed(#PB_Key_S) ; inward move
    depth + 0.1
    NodeLocate(#node,0,up,depth)

  EndIf
   If KeyboardPushed(#PB_Key_Escape)
      Quit = #True
    EndIf
    
    
Until Quit = #True Or Event = #PB_Event_CloseWindow

   
    

Re: Ogre Mesh Viewer

Posted: Fri Jan 25, 2013 4:59 pm
by djes
Here's one done fastly. Save the file in your 3d examples folder.

Pick the wanted resolution,
Pick the places where are the textures/scripts and so on,
Pick the mesh to view.

Code: Select all

; ------------------------------------------------------------
;
; Fast PureBasic/ogre mesh viewer
; (c) djes 2013
; PB 5.1b4
;
; ------------------------------------------------------------

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

#CameraSpeed  = 1
#Object        = 0

If InitEngine3D(#PB_Engine3D_DebugLog)
	
	InitSprite()
	InitKeyboard()
	InitMouse()
	
	If Screen3DRequester()
		
		InitialPath$ = GetHomeDirectory()   ; set initial path to display (could also be blank)
		Path$ = PathRequester("Please choose a path", InitialPath$)
		If Path$ = ""
			MessageRequester("Information", "The requester was canceled.", 0) 
			End  
		EndIf
		
		Add3DArchive(Path$, #PB_3DArchive_FileSystem)
		Parse3DScripts()
		
		Pattern$ = "Meshes (*.mesh)|*.mesh|All files (*.*)|*.*"
		Pattern = 0    ; use the first of the three possible patterns as standard
		File$ = OpenFileRequester("Please choose file to load", Path$, Pattern$, Pattern)
		If File$ = ""
			MessageRequester("Information", "The requester was canceled.", 0) 
			End  
		EndIf
		
		LoadMesh(#Object, File$)
		CreateEntity(#Object, MeshID(#Object), #PB_Material_None)
		
		CreateLight(0, RGB(0,0,255), 100.0, 0, 0)
		SetLightColor(0, #PB_Light_SpecularColor, RGB(255, 0, 0))
		
		CreateCamera(0, 0, 0, 100, 100)
		MoveCamera(0, 0, 40, 150)
		CameraBackColor(0, RGB(0, 0, 128))
		
		Repeat
			Screen3DEvents()
			
			If ExamineMouse()
				MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
				MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
			EndIf
			
			If ExamineKeyboard()
				
				If KeyboardPushed(#PB_Key_Left)
					KeyX = -#CameraSpeed
				ElseIf KeyboardPushed(#PB_Key_Right)
					KeyX = #CameraSpeed
				Else
					KeyX = 0
				EndIf
				
				If KeyboardPushed(#PB_Key_Up)
					KeyY = -#CameraSpeed
				ElseIf KeyboardPushed(#PB_Key_Down)
					KeyY = #CameraSpeed
				Else
					KeyY = 0
				EndIf
				
			EndIf
			
			RotateEntity(#Object, 0, 1, 0, #PB_Relative)
			
			RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
			MoveCamera  (0, KeyX, 0, KeyY)
			
			RenderWorld()
			Screen3DStats()
			FlipBuffers()
		Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
	EndIf
	
Else
	MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

Re: Ogre Mesh Viewer

Posted: Fri Jan 25, 2013 7:33 pm
by applePi
thank you djes for the 5.10b4 version. last week i have changed my first example to work with PB 5.10b4+ for windows, to view the models made by the Sculptris (after converting it to *.mesh with OgreAssimpConverter, i am still experimenting and reading its user guide)
my new model viewer can load all mesh examples in the 3D\data\models except the facial.mesh with the error:
http://s13.postimage.org/6qtztdf4n/error.png
the official release FacialAnimation.pb runs without problems.
the control keys are listed in the Title bar
save in Example\3D folder.

Code: Select all

Enumeration
   #MESH
   #TEX_plane
   #MAT
   #MAT_plane
   #plane
   #model
   #node
   #LIGHT
   #CAMERA_ONE
   #BUTTON
   #BUTTON_OPEN
   #mainwin
 EndEnumeration
Global Quit.b = #False
rot.l=1 :stopFlag = 1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
rotx.f:roty.f=1:rotz.f :rotx0.f: roty0.f: rotz0.f
up.f = 2.2: depth.f=0

ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "PgUp PgD scale model..Arrows for rotation, space: stop/rotate,  QA Up/Down, WS far/near", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(#BUTTON, 0, DesktopHeight(0)-60, 60, 30, "rotate/stop") 
  ButtonGadget(#BUTTON_OPEN, 70, DesktopHeight(0)-60, 50, 30, "Open File") 

;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-70, 0, 0, 0)
WorldShadows(#PB_Shadow_Additive)

InitKeyboard()
SetFrameRate(60)

Add3DArchive("Data/", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Textures\", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()

CreateMaterial(#MAT_plane, LoadTexture(#TEX_plane, "snow_1024.jpg"))
CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))

LoadMesh(#MESH, "tudorhouse.mesh")
meshsize.f = MeshRadius(#MESH)
CreateNode(#node)
CreateEntity(#model, MeshID(#MESH), #PB_Material_None)
ScaleEntity(#model,3/meshsize,3/meshsize,3/meshsize)
AttachNodeObject(#node,EntityID(#model))
CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(#CAMERA_ONE, 0, 0, 400, 400)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)

RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf

MoveNode(#node,0,up,depth,#PB_Absolute)
SetActiveGadget(#BUTTON)
SkyDome("clouds.jpg", 100) ;for blue color background

;Main loop
Repeat
  Event = WindowEvent()
  If Event = #PB_Event_Gadget
    Select EventGadget()
      Case #BUTTON
        If rot = 0
          rot = 1
          rotx= rotx0:roty=roty0:rotz=rotz0 ; restore rotation status
          stopFlag = 1
          ;SetGadgetText(#BUTTON,"stop")
        Else
          rot = 0
          rotx0= rotx:roty0=roty:rotz0=rotz ;back up rotation status
          rotx=0:roty=0:rotz=0
          stopFlag = 0
          ;SetGadgetText(#BUTTON,"rotate")
        EndIf
      Case #BUTTON_OPEN
        File$ = OpenFileRequester("choose *.mesh file", "", "Mesh files|*.mesh|All Files|*.*", 0)
        File$ = GetFilePart(File$)
        If File$="":End:EndIf
        SetActiveGadget(#BUTTON)
        FreeEntity(#model)
        FreeMesh(#MESH)
        LoadMesh(#MESH, File$)
        meshsize.f = MeshRadius(#MESH)
        CreateEntity(#model, MeshID(#MESH), #PB_Material_None)
        ScaleEntity(#model,3/meshsize,3/meshsize,3/meshsize)
        ;AnimateEntity(#model, "swim") ; if using the animated fish only
        AttachNodeObject(#node,EntityID(#model))
        MoveNode(#node,0,1.5,3,#PB_Absolute)
              
    EndSelect
  EndIf 
  If stopFlag=1
    x + rotx
    y + roty
    z + rotz
  EndIf

   RotateEntity(#model, x, y, z)
   
   RenderWorld()
   FlipBuffers()

  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Up)  ; rotate left
    rotx=1:roty=0:rotz=0
    rotx0 = rotx: roty0 = roty :rotz0 = rotz
    x + rotx
    y + roty
    z + rotz
    stopFlag=0
    rot = 0
  ElseIf KeyboardPushed(#PB_Key_Down) ; rotate right
    rotx=-1:roty=0:rotz=0
    rotx0 = rotx: roty0 = roty :rotz0 = rotz
    x + rotx
    y + roty
    z + rotz
    stopFlag=0
    rot = 0
  ElseIf KeyboardPushed(#PB_Key_Right)   ; rotate up
    rotx=0:roty=1:rotz=0
    rotx0 = rotx: roty0 = roty :rotz0 = rotz
    x + rotx
    y + roty
    z + rotz
    stopFlag=0
    rot = 0
  ElseIf KeyboardPushed(#PB_Key_Left) ; rotate down
    rotx=0:roty=-1:rotz=0 
    rotx0 = rotx: roty0 = roty :rotz0 = rotz
    x + rotx
    y + roty
    z + rotz
    stopFlag=0
    rot = 0
  EndIf 
  
  If KeyboardPushed(#PB_Key_PageUp) ; scale up model
    xs.f = 1.1:ys.f = 1.1:zs.f = 1.1
    ScaleEntity(#model,xs,ys,zs)
    
  ElseIf KeyboardPushed(#PB_Key_PageDown) ; scale down model
    xs = 0.9:ys = 0.9:zs= 0.9
    ScaleEntity(#model,xs,ys,zs)
    
  EndIf
  If KeyboardPushed(#PB_Key_Q) ; up move
    up + 0.1
    MoveNode(#node,0,up,depth,#PB_Absolute)
   ElseIf KeyboardPushed(#PB_Key_A) ; down move
    up - 0.1
    MoveNode(#node,0,up,depth,#PB_Absolute)
    ElseIf KeyboardPushed(#PB_Key_W) ; forward move
    depth - 0.1
    MoveNode(#node,0,up,depth,#PB_Absolute)
    ElseIf KeyboardPushed(#PB_Key_S) ; inward move
    depth + 0.1
    MoveNode(#node,0,up,depth,#PB_Absolute)

  EndIf
   If KeyboardPushed(#PB_Key_Escape)
      Quit = #True
    EndIf
    
    
Until Quit = #True Or Event = #PB_Event_CloseWindow