a tour to stonehenge

Everything related to 3D programming
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

a tour to stonehenge

Post by applePi »

this is the model of the stonehenge: downloaded from here as skp
https://3dwarehouse.sketchup.com/model. ... c10dfa4b4d
using sketchUp to export it to *.3ds file then using the great OgreAssimpConverter http://www.purebasic.fr/english/viewtop ... 22#p401729 to convert it to Ogre *.mesh file
i have used the official purebasic example ThirdPerson.pb to replace the cubes with the stonehenge model. and a tiny other changes.
use the keys to move and rotate the robot , and the mouse to look up/down. press H to hide/unhide the Robot
the example ThirdPerson.pb can be used as a base for such tours with physics to virtual places such as museums, places etc.

how to run : download the code and the mesh with all textures from here:
http://www.2shared.com/file/icaehulb/stonehenge3.html

notes: the place to position the camera away or high from the robot is in line 173: \CameraNode = CreateNode(#PB_Any, -100, 100, 0)

Image
Image

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Third Person 
;
;    (c) 2011 - Fantaisie Software
;
; ------------------------------------------------------------
; 
; edited by applePi to add the stonehenge model to it
IncludeFile #PB_Compiler_Home + "Examples/3D/Screen3DRequester.pb"


#PlayerSpeed = 60
#CameraSpeed = 10
Global.f MouseY = 50

Structure Vector3
  x.f
  y.f
  z.f
EndStructure

Structure s_Key
  Up.i
  Down.i
  Left.i
  Right.i
  StrafeLeft.i
  StrafeRight.i
  Jump.i
EndStructure

Structure s_Entity
  Entity.i
  EntityBody.i
  BodyOffsetY.f 
  elapsedTime.f
  Key.s_Key
  MainNode.i  
  SightNode.i
  CameraNode.i  
  ForwardNode.i
  StrafeNode.i
EndStructure

Structure s_Camera
  Camera.i
  Tightness.f
  CameraNode.i 
  TargetNode.i
EndStructure    

Macro GetNodePosition(Position, Node)
  Position\x = NodeX(Node)  
  Position\y = NodeY(Node)  
  Position\z = NodeZ(Node)  
EndMacro

Macro SubVector3(V, V1, V2)
  V\x = V1\x - V2\x
  V\y = V1\y - V2\y
  V\z = V1\z - V2\z
EndMacro

;-Declare
Declare HandleEntity(*Entity.s_Entity)
Declare CameraTrack(*Camera.s_Camera, *Entity.s_Entity)
Declare OnGround(*Entity.s_Entity)

Define Robot.s_Entity
Define Camera.s_Camera
Define.f TimeSinceLastFrame = 0
If InitEngine3D()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
       
    ;Add3DArchive("../Data/Textures"        , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Models"          , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts"          , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/GUI"             , #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
    Add3DArchive("."        , #PB_3DArchive_FileSystem)
    Parse3DScripts()
    
    WorldShadows(#PB_Shadow_Modulative, 3000, RGB(150, 150, 150))
    ;WorldShadows(#PB_Shadow_Additive,3000, RGB(150, 150, 150))
    ;Texture
    CreateTexture(1, 256, 256)
    StartDrawing(TextureOutput(1))
    Box(0, 0, 256, 256, RGB(138, 115, 38))
    DrawingMode(#PB_2DDrawing_Outlined)
    Box(0, 0, 256, 256, RGB(255, 255, 0))
    Box(10, 10, 236, 236, RGB(255, 255, 50))
    StopDrawing()
    
    ;Material
    CreateMaterial(0, LoadTexture(0, "r2skin.jpg"))
    CreateMaterial(1, TextureID(1))
    MaterialFilteringMode(1, 2)
    
    CreateMaterial(2, LoadTexture(2, "Dirt.jpg"))
    CreateMaterial(3, LoadTexture(3, "Wood.jpg"))
    GetScriptMaterial(4, "Scene/GroundBlend")
    
    MaterialFilteringMode(1, #PB_Material_Anisotropic, 8) 
    
    ;Robot
    LoadMesh   (0, "robot.mesh")
    CreateEntity (0, MeshID(0), #PB_Material_None);
    StartEntityAnimation(0, "Walk")
    HideEntity(0, 1)        
    ;Robot Body
    CreateEntity(1, MeshID(0), #PB_Material_None, -100, 126, -500)
    RotateEntity(1, 0,-60,0)
    HideEntity(1, 1)
    
    ;Ground
    CreatePlane(2, 5000, 5000, 100, 100, 100, 100)
    CreateEntity(2, MeshID(2), MaterialID(1), 0, 0, 0)
       
    ;Body
    EntityPhysicBody(1, #PB_Entity_CapsuleBody, 1, 0, 0) 
    EntityPhysicBody(2, #PB_Entity_StaticBody)
    
    
    ;-Light
    ;CreateLight(0,RGB(255,255,155),700,500,0)
    ;AmbientColor(RGB(255,255,255))
    CreateLight(1,RGB(200,248,13),1000,700,1600, #PB_Light_Point       )
    AmbientColor(RGB(255,255,255))
    
    ;- Fog
    Fog(RGB(210, 210, 210), 1, 0, 10000)
    
    ; Skybox
    SkyBox("desert07.jpg")
    ; stonehenge
    LoadMesh(20, "stonehenge3_03ds.mesh")
    NormalizeMesh(20)
    BuildMeshShadowVolume(20)
    BuildMeshTangents(20)



    CreateEntity(20,MeshID(20), #PB_Material_None,1000,-70,1600)
    ScaleEntity(20,2000,2000,2000)
    EntityPhysicBody(20, #PB_Entity_StaticBody )
    EntityRenderMode(20, #PB_Entity_CastShadow )
;MoveEntity(1, 1000, 1000, 2000)
    ;
    With Robot
      \Entity = 0
      \EntityBody = 1
      \BodyOffsetY = 43 
      
      \Key\Down        = #PB_Key_Down
      \Key\Left        = #PB_Key_Left
      \Key\Right       = #PB_Key_Right
      \Key\Up          = #PB_Key_Up
      \Key\StrafeLeft  = #PB_Key_X
      \Key\StrafeRight = #PB_Key_C
      \Key\Jump        = #PB_Key_Space
     
      \MainNode    = CreateNode(#PB_Any) ; Entity position
      \SightNode   = CreateNode(#PB_Any,  120,  50,  0) ; For cameraLookAt 
      ;\CameraNode  = CreateNode(#PB_Any, -340, 100,  0) ; Camera position
      \CameraNode  = CreateNode(#PB_Any, -100, 100,  0) ; Camera position
      \ForwardNode = CreateNode(#PB_Any,    1,   0,  0) ; Direction normalized 
      \StrafeNode  = CreateNode(#PB_Any,    0,   0, -1) ; Direction normalized 
      
      AttachNodeObject(\MainNode, NodeID(\SightNode))
      AttachNodeObject(\MainNode, NodeID(\CameraNode))   
      AttachNodeObject(\MainNode, NodeID(\ForwardNode))     
      AttachNodeObject(\MainNode, NodeID(\StrafeNode))    
      AttachNodeObject(\MainNode, EntityID(\Entity))
    EndWith
    
    ;-Camera
    CreateCamera(0, 0, 0, 100, 100)
    With Camera  
      \Camera = 0
      \Tightness = 0.035
      ; Camera use 2 nodes
      \CameraNode = CreateNode(#PB_Any, -3000, 700, 0) ; Camera position
      \TargetNode = CreateNode(#PB_Any) ; For cameraLookAt 
      AttachNodeObject(\CameraNode, CameraID(\Camera))
    EndWith  
    
    ;-Main loop    
    ;
    Repeat
      Screen3DEvents()

      Robot\elapsedTime = TimeSinceLastFrame * 40
       
      HandleEntity(@Robot)
         
      CameraTrack(@Camera, @Robot)
      If KeyboardReleased(#PB_Key_H)
        HideEntity(0,hide)
        hide ! 1
      EndIf  
      
      TimeSinceLastFrame = RenderWorld(50) / 1000
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End

Procedure OnGround(*Entity.s_Entity)
  With *Entity
    ProcedureReturn RayCollide(NodeX(\MainNode),  NodeY(\MainNode)+3, NodeZ(\MainNode), NodeX(\MainNode), NodeY(\MainNode),  NodeZ(\MainNode)) 
  EndWith  
EndProcedure



Procedure HandleEntity(*Entity.s_Entity)
  Protected.Vector3 Forward, Strafe, PosMain, PosDir, PosStrafe
  Protected.f Speed, Speed2, x, y, MouseX
  Static Jump.f, MemJump.i, Rot.Vector3, Trans.Vector3, Clic, MouseY
  
  With *Entity
    GetNodePosition(PosMain, \MainNode)
    GetNodePosition(PosDir, \ForwardNode)
    GetNodePosition(PosStrafe, \StrafeNode)
    SubVector3(Forward, PosDir, PosMain)
    SubVector3(Strafe, PosStrafe, PosMain)
    
    Speed = #PlayerSpeed * \elapsedTime 
    Speed2 = Speed / 2
    
    
    If ExamineKeyboard()
      
      If KeyboardReleased(#PB_Key_F5)
        WorldDebug(#PB_World_DebugBody)
      ElseIf KeyboardReleased(#PB_Key_F6)
        WorldDebug(#PB_World_DebugEntity)
      ElseIf KeyboardReleased(#PB_Key_F7)
        WorldDebug(#PB_World_DebugNone)
      EndIf
           
      If KeyboardPushed(\Key\Jump) And OnGround(*Entity)>-1
        Jump = 4
        MemJump = 1
      EndIf  
      
      Rot\x * 0.30
      Rot\y * 0.30
      Rot\z * 0.30
      Trans\x * 0.20
      Trans\y = Jump
      Trans\z * 0.20
      
      If KeyboardPushed(\Key\Up)
        Trans\x + Forward\x * Speed 
        Trans\z + Forward\z * Speed
      ElseIf KeyboardPushed(\Key\Down)
        Trans\x + Forward\x * -Speed2
        Trans\z + Forward\z * -Speed2
      EndIf
      
      If KeyboardPushed(\Key\Left)
        Rot\y + 2 * \elapsedTime
      ElseIf KeyboardPushed(\Key\Right)
        Rot\y - 2 * \elapsedTime
      EndIf 
      
      If KeyboardPushed(\Key\StrafeLeft)
        Trans\x + Strafe\x * Speed2
        Trans\z + Strafe\z * Speed2
      ElseIf KeyboardPushed(\Key\StrafeRight)
        Trans\x + Strafe\x * -Speed2
        Trans\z + Strafe\z * -Speed2
      EndIf 
      
      If OnGround(*Entity) > -1 
        Jump = 0
      ElseIf MemJump  
        Jump + 20
        If Jump > 80 
          MemJump = 0
        EndIf  
      Else  
        Jump - 9 
      EndIf  
      
      
    EndIf
                
    MoveEntity  (\EntityBody, Trans\x, Trans\y, Trans\z)
    RotateEntity(\EntityBody, 0, Rot\y, 0, #PB_Relative)   
    
    MoveNode(\MainNode, EntityX(\EntityBody), EntityY(\EntityBody)-\BodyOffsetY, EntityZ(\EntityBody), #PB_Absolute) 
    RotateNode(\MainNode, 0, EntityYaw(\EntityBody), 0) 
  EndWith   
EndProcedure


Procedure CameraTrack(*Camera.s_Camera, *Entity.s_Entity)
   Protected.Vector3 CameraPosition, TargetPosition 
   Protected.f x, y, z

   GetNodePosition(CameraPosition, *Entity\CameraNode)
   GetNodePosition(TargetPosition, *Entity\SightNode)
   x = NodeX(*Camera\CameraNode)
   y = NodeY(*Camera\CameraNode)
   z = NodeZ(*Camera\CameraNode)
   x = (CameraPosition\x - x) *  *Camera\Tightness
   y = (CameraPosition\y - y) *  *Camera\Tightness
   z = (CameraPosition\z - z) *  *Camera\Tightness
   MoveNode(*Camera\CameraNode, x, y, z)

   x = NodeX(*Camera\TargetNode)
   y = NodeY(*Camera\TargetNode)
   z = NodeZ(*Camera\TargetNode)
   x = (TargetPosition\x - x) *  *Camera\Tightness
   y = (TargetPosition\y - y) *  *Camera\Tightness
   z = (TargetPosition\z - z) *  *Camera\Tightness
   
   MoveNode(*Camera\TargetNode, x, y, z)
   
   If ExamineMouse()
      MouseY = MouseY - MouseDeltaY() * 1
        
   EndIf
      
   CameraLookAt(*Camera\Camera, NodeX(*Camera\TargetNode)+ MouseX, NodeY(*Camera\TargetNode)+MouseY, NodeZ(*Camera\TargetNode))

EndProcedure

T4r4ntul4
Enthusiast
Enthusiast
Posts: 119
Joined: Tue Mar 04, 2014 4:15 pm
Location: Netherlands

Re: a tour to stonehenge

Post by T4r4ntul4 »

hi, thats nice!

did you know you can directly export your models from sketchup to *.mesh ?
see this link: http://www.cse.unr.edu/~lagoon/index.ph ... ls_to_OGRE

only steps 1 through 8 is needed from: Exporting SketchUp Models to OGRE


edit: some faces are not there maybe need to reverse them in sketchup?
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: a tour to stonehenge

Post by rsts »

Most impressive.

Thanks for sharing. :)
Thade
Enthusiast
Enthusiast
Posts: 266
Joined: Sun Aug 03, 2003 12:06 am
Location: Austria

Re: a tour to stonehenge

Post by Thade »

--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: a tour to stonehenge

Post by applePi »

thanks for the links. i have tried the sketchUp to mesh before but find this approach easier : 1-sketchUp to 3ds/obj 2- OgreAssimpConverter.exe test.obj. sometimes it needs to apply OgreMeshUpgrader.exe as reported here http://www.purebasic.fr/english/viewtop ... 49#p401285
for the edge list build.
and we can try export to 3ds or obj , what is worked better for OgreAssimpConverter we use it.
just i wish to light the model by different lights, but then naturally we will have a chaos of shadows, and i want only the unrealistic situation : one shadow from one light, ie different lights but one shadow !!!!.
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: a tour to stonehenge

Post by Bananenfreak »

Chaos of shadows... You could try to use Additive or TextureAdditive as shadowtype.
Image
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: a tour to stonehenge

Post by Samuel »

Nice example ApplePi.
applePi wrote: just i wish to light the model by different lights, but then naturally we will have a chaos of shadows, and i want only the unrealistic situation : one shadow from one light, ie different lights but one shadow !!!!.
You could try DisableLightShadows(#Light, #False). It disables a lights shadow casting.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: a tour to stonehenge

Post by applePi »

thanks Samuel, you are the Master. i spent all the day looking in the light help without noticing it, saying to myself how the team forget something like that. now i can enjoy bizarre and Unreal effects. :D
Artus
Enthusiast
Enthusiast
Posts: 104
Joined: Wed Feb 25, 2009 10:29 pm
Location: Germany
Contact:

Re: a tour to stonehenge

Post by Artus »

If you like Stonehenge, you must^^ look this:

http://www.youtube.com/watch?v=mbyzgeee2mg

Greetings Arthur
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: a tour to stonehenge

Post by Comtois »

Please correct my english
http://purebasic.developpez.com/
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: a tour to stonehenge

Post by applePi »

thats too much generous from Comtois to provide such a demo, thank you very much. i always finds that example impressive and now it is much more impressive with its PureBasic version since we can learn from it about materials and lights and more.
for those who hesitate to try it, this is a one capture:
Image
Last edited by applePi on Sun Mar 09, 2014 1:19 pm, edited 1 time in total.
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: a tour to stonehenge

Post by DK_PETER »

applePi wrote:thats too much generous from Comtois to provide such a demo, thank you very much. i always finds that example impressive and now it is much more impressive since we can learn from it about materials and lights and more.
for those who hesitate to try it, this is a one capture:
Image
Agree with ApplePi.

Excellent Comtois!
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: a tour to stonehenge

Post by davido »

@Comtois

Excellent! :D
DE AA EB
Post Reply