Page 1 of 1

3D model inside windowed screen

Posted: Sun Dec 04, 2011 5:20 pm
by applePi
i begins to learn Ogre 3d using the book "PureBasic - A Beginners Guide" chapter 11 (3d graphics), example page 206, but modifying the example to work in a Windowed Screen, and using fish model with a texture to rotate, and a textured plane, also a shadow. also i have found the word "swim" inside fish.skeleton file using notepad so using AnimateEntity(#ENTITY_FISH, "swim") will animate the fish.
until now i can see 3 problems:
1- at the very beginning of the program the screen flicker for half a second then continue normaly.
2- the button (stop|rotate) does not appear at the same time as the window/ windowed screen.
is it possible that using "Event = WindowEvent()" cause the flicker at the beginning , but if we manage to not using it then the mouse cursor will be too busy as a hour glass, the WindowEvent() i think play as if it is a DoEvents, in the glorious old time.
3- if we look at the file fish.mesh using notepad we find this:
xxxx[MeshSerializer_v1.41]
xxxxxxxxExamples/Fish (the xxx are not Ascii letters)
so i guess it is trying to load something from Examples/Fish
and looking at the Ogre.txt which are produced in the program code folder we read ""Can't assign material Examples/Fish to SubEntity of E6 because this Material does not exist. Have you forgotten to define it in a .material script?""
even i have attached material to the fish. so are there some editor to get rid of this warning?


download the fish mesh + skeleton and textures from here:
http://www.mediafire.com/?rn4qquww12d8wj1
put the mesh and textures in the Data folder beside the below code.
regards
Image
Edited for 5.11 + 5.2 beta

Code: Select all

Enumeration
   #MESH
   #TEX
   #TEX_plane
   #MAT
   #MAT_plane
   #plane
   #ENTITY_FISH
   #LIGHT
   #CAMERA_ONE
   #BUTTON
   #mainwin
EndEnumeration
Global Quit.b = #False
Speed = 0.5
If OpenWindow(#mainwin, 0, 0, 500, 480, "press ESC to exit...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#BUTTON, 0, 405, 50, 30, "stop")  

;Initialize environment
InitEngine3D()
InitSprite()
InitKeyboard()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, 500, 400, 0, 0, 0)
;WorldShadows(#PB_Shadow_Additive)
WorldShadows(#PB_Shadow_Modulative, 100, RGB(100, 250, 100))
  
EnableWorldPhysics(#True)
EnableWorldCollisions(#True)
SetFrameRate(60)

Add3DArchive("Data\", #PB_3DArchive_FileSystem)

CreateMaterial(#MAT_plane, LoadTexture(#TEX_plane, "mosaic.png"))
CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))
  
LoadMesh(#MESH, "fish.mesh")
LoadTexture(#TEX, "steelhead.png")
CreateMaterial(#MAT, TextureID(#TEX))
CreateEntity(#ENTITY_FISH, MeshID(#MESH), MaterialID(#MAT))
ScaleEntity(#ENTITY_FISH,0.5,0.5,0.5)
EntityRenderMode(#ENTITY_FISH, #PB_Entity_CastShadow)

StartEntityAnimation(#ENTITY_FISH, "swim", #PB_EntityAnimation_Manual)
MoveEntity(#ENTITY_FISH,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)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)

RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf
rot.l=1
;Main loop
Repeat
  Event = WindowEvent()
  If Event = #PB_Event_Gadget
    Select EventGadget()
      Case #BUTTON
        If rot = 0
          rot = 1
          SetGadgetText(#BUTTON,"stop")
        Else
          rot = 0
          SetGadgetText(#BUTTON,"rotate")
        EndIf
    EndSelect
   EndIf 
  y.l + rot
  x.l + rot
  z.l + rot
  
  RotateEntity(#ENTITY_FISH, 0, y, 0)
  
  AddEntityAnimationTime(#ENTITY_FISH, "swim", TimeSinceLastFrame * Speed)
   
   TimeSinceLastFrame = RenderWorld()
   
  FlipBuffers()

   ExamineKeyboard()
   If KeyboardReleased(#PB_Key_Escape)
      Quit = #True
   EndIf

Until Quit = #True Or Event = #PB_Event_CloseWindow

   
    

Re: 3D model inside windowed screen

Posted: Sun Dec 04, 2011 5:39 pm
by PMV
applePi wrote:1- at the very beginning of the program the screen flicker for half a second then continue normaly.
2- the button (stop|rotate) does not appear at the same time as the window/ windowed screen.
is it possible that using "Event = WindowEvent()" cause the flicker at the beginning , but if we manage to not using it then the mouse cursor will be too busy as a hour glass, the WindowEvent() i think play as if it is a DoEvents, in the glorious old time.
One message is processed at one call of WindowEvent(). On a FPS
of 60, only 60 messages are handled per second ... so it needs a
few of them until the event-queue is empty. Write

Code: Select all

While WindowEvent() : Wend
before the main-loop and this 2 problems should be solved.
3- if we look at the file fish.mesh using notepad we find this:
xxxx[MeshSerializer_v1.41]
xxxxxxxxExamples/Fish (the xxx are not Ascii letters)
so i guess it is trying to load something from Examples/Fish
and looking at the Ogre.txt which are produced in the program code folder we read ""Can't assign material Examples/Fish to SubEntity of E6 because this Material does not exist. Have you forgotten to define it in a .material script?""
even i have attached material to the fish. so are there some editor to get rid of this warning?
The line you mentioned is the full name of the material name used
for the mesh. I don't know if it is enough, but you can try and delete
this name from the file ... till yet i have just renamed the material inside
of the mesh-file to a material that exists ... and it works well. :)

MFG PMV

Re: 3D model inside windowed screen

Posted: Sun Dec 04, 2011 7:37 pm
by Comtois
You can add these lines in the Examples.material file, or create a new file "fish.material" and copy these lines. (See your 3D\Data\Scripts folder)

Code: Select all

material Examples/Fish
{
	technique
	{
		pass
		{
			texture_unit
			{
				texture steelhead.png
			}
		}
	}
}
And add this in your code

Code: Select all

Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
As fish.mesh use a script material, you can write your entity like this :

Code: Select all

CreateEntity(#ENTITY_FISH, MeshID(#MESH), #PB_Material_None)