Circular plane , Mobius Strip, from CreatePlane

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

Circular plane , Mobius Strip, from CreatePlane

Post by applePi »

Image
Circular plane from CreatePlane with a hole in the middle
a strip of paper (or plane) bend it in a circular way:

Code: Select all

Enumeration
  #Window
  #Camera
  #sphere
  #plane
  #cyl
        
EndEnumeration

Global Dim MeshData.PB_MeshVertex(0)

#CameraSpeed = 1

Global TileCountX = 5, TileCountZ = 30

Declare plane()

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
  
  ;Add3DArchive(".", #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)
    
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
ExamineDesktops()
DesktopW = DesktopWidth(0)
DesktopH = DesktopHeight(0)

If OpenWindow(#Window, 0, 0, DesktopW, DesktopH, "W wire/solid Frame ....Z/X :Push the sphere.....mouse+arrow keys for the camera ")
  If OpenWindowedScreen(WindowID(#Window), 0, 0, DesktopW, DesktopH, 0, 0, 0)
    
    CreateCamera(#Camera, 0, 0, 100, 100)
    MoveCamera(#Camera, 0, 70, 240, #PB_Absolute)
    CameraLookAt(#Camera,0,-5,0)
    CameraBackColor(#Camera, RGB(254,236,186)) ;RGB(200,155,40)
    
    CreateMaterial(1, LoadTexture(1, "Geebee2.bmp"))
    MaterialCullingMode(1, #PB_Material_NoCulling)
    
    CreateMaterial(2, LoadTexture(2, "RustySteel.jpg"))
    MaterialCullingMode(2, #PB_Material_NoCulling)
       
    CreateMaterial(0, LoadTexture(0, "MRAMOR6X6.jpg"))
    MaterialCullingMode(0, #PB_Material_NoCulling)
    
    CreateLight(0, RGB(255, 255, 255), 0, 100, 50)
    AmbientColor(RGB(255, 255, 255))
  
  EndIf
EndIf


;CreatePlane(#Mesh, TileSizeX, TileSizeZ, TileCountX, TileCountZ, TextureRepeatCountX, TextureRepeatCountZ)
CreatePlane(#plane,50, 300, TileCountX, TileCountZ, 10,10)
CreateEntity(#plane,MeshID(#plane),MaterialID(0), 0, 0, 0)
;MaterialShadingMode(0, #PB_Material_Wireframe)
wireFrame = 1

plane() ; create the circular plane mesh
ScaleEntity(#plane, 20,1,20)

CreateSphere(#sphere, 6)
CreateEntity(#sphere, MeshID(#sphere),  MaterialID(1) ,90,20,0)
EntityPhysicBody(#plane, #PB_Entity_StaticBody)
EntityPhysicBody(#sphere, #PB_Entity_SphereBody, 1, 2, 2 )
;EntityPhysicBody(#sphere, #PB_Entity_ConvexHullBody , 1.0, 0.02, 1.0)

WorldGravity(-30)
CreateCylinder(#cyl, 30, 14 , 8, 0, 0)
CreateEntity(#cyl, MeshID(#cyl),  MaterialID(2) ,0,-100,0)
EntityPhysicBody(#cyl, #PB_Entity_StaticBody)

Repeat
  
  Event = WindowEvent()
        
      If ExamineMouse()
        MouseX = -MouseDeltaX()/20 
        MouseY = -MouseDeltaY()/20
      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
        
                
        If KeyboardPushed(#PB_Key_Z)
          ApplyEntityImpulse(#sphere, -1,0,0)
        ElseIf KeyboardPushed(#PB_Key_X)
          ApplyEntityImpulse(#sphere, 1,0,0)
        EndIf 
        
        
        If KeyboardReleased(#PB_Key_W)
          If wireFrame
            MaterialShadingMode(0, #PB_Material_Wireframe)
          wireFrame ! 1
        Else 
            MaterialShadingMode(0, #PB_Material_Solid)
          wireFrame ! 1
        EndIf
        EndIf
            
      EndIf
              
      RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(#Camera, KeyX, 0, KeyY)
            
      RenderWorld()
           
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End

  
  Procedure plane()
    
 t.f=0
 GetMeshData(#plane,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate , 0, MeshVertexCount(#plane)-1)
   
  c=0 : dist.f : u.f: v.f
  For i=0 To TileCountZ
    dist = 0.4 ; determine the size of the hole, try dist = 0
    t.f+ #PI*2/TileCountZ
    u.f = 0 
    For k=0 To TileCountX
       ;parametric equations for the circle     
       MeshData(c)\x =  Cos(t) * dist 
       MeshData(c)\z =  Sin(t) * dist 
       MeshData(c)\u =  u
       MeshData(c)\v =  v
       dist + 1 ; determin the displacement of the points
       c + 1
       u + 1/(TileCountX/1)
     Next
     v + 1/(TileCountZ/5) ; change 5 to 1 to texture the whole plane with one picture
  Next
  
   SetMeshData(#plane,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(#plane)-1)     
   NormalizeMesh(#plane)
   UpdateMeshBoundingBox(#plane)
  

  EndProcedure
  
 
 
notes:
1-to get a hexagonal plane : TileCountZ = 6 in line 14
1-to get a triangular plane : TileCountZ = 3 in line 14 and so on
2- to increase / decrease the hole size change line 151 dist = 0.4 to other value ( zero will close the hole)
3- to increase / decrease the whole size of the Disk change line 160 dist + 1 to other value
4- change number of the tiles from line 14 TileCountX = 5, TileCountZ = 40
Last edited by applePi on Thu Aug 13, 2015 5:00 am, edited 3 times in total.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 635
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: Circular plane from CreatePlane, with a hole in the Midd

Post by falsam »

I really like. Thank you for sharing applePi.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Circular plane from CreatePlane, with a hole in the Midd

Post by IdeasVacuum »

Very neat applePi. Perhaps you should put all your 3D work together to make a Book or eBook about 3D Programming using PB.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Circular plane from CreatePlane, with a hole in the Midd

Post by davido »

@applePi,

Another really nice example. Thank you very much for sharing. :D

After moving the sphere to the centre it dropped, presumably by gravity, into the cup below. Excellent.
After a lot of mouse movements I managed to get the thing upside down but the ball didn't fall back again. :)
DE AA EB
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Circular plane from CreatePlane, with a hole in the Midd

Post by applePi »

Thank you falsam,IdeasVacuum and Davido , about ebook i am thinking of the github site since several users here have pages on that site, like Joakim pages https://github.com/JoakimCh/JLCs_PB_stuff

my favourite is the Mobius strip, It is formed by joining the ends of a rectangle with one twist of 180 degrees. its parametric equations here: http://mathworld.wolfram.com/MoebiusStrip.html
the mobius strip surface here are overlapping with normals which seems mostly correctly aligned to the surface. . note how the engine put the normals on this strange and confusing strip which you can't tell where is the up or down.

notes and experiments:
1- comment line 91 MoveEntity(spike, 0,0,-0.051, #PB_Local ) to position the cylinders which represent normals over the strip from its centers.

2- to make the strip thinner or wider change line 173 r.f=5 to something else :10 is thinner
3- line 6 TileCountX = 6 is the number of divisions across the strip, try = 2
4- line 6 TileCountZ = 100 change it to TileCountZ = 10 and you get a cartoon like mobius strip
5- uncomment line 60 SaveMesh(#plane, "mobius.mesh") to save the mobius strip. i have opened it in deepMesh (after editing http://purebasic.fr/english/viewtopic.p ... 45#p466340
. the meshes saved by current purebasic have this info at the files start: [MeshSerializer_v1.8] and we need to change it to [MeshSerializer_v1.40] (note v1.40 not v1.4) i have used now notepad++ for this kind of editing ( https://notepad-plus-plus.org/ )
then exporting the *.mesh files to *.x and *.3ds , download it from here:
http://wikisend.com/download/443254/mobius.rar. you may can print the mobius models in 3D printer, or use the models with other programs.
Image

Code: Select all

#CameraSpeed = 0.1

Global Dim MeshData.PB_MeshVertex(0)

Global ArrSize
Global TileCountX = 6, TileCountZ = 100 ; number of squares on the plain on x and z
Global TileX = TileCountX/2 ; the plot will go from -TileX to  +TileX

Declare plane()

Define.f KeyX, KeyY, MouseX, MouseY

Enumeration
  #plane
  #Camera
  
EndEnumeration

If InitEngine3D()
  
  Add3DArchive(".", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
      
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
ExamineDesktops()
DesktopW = DesktopWidth(0)
DesktopH = DesktopHeight(0)

If OpenWindow(0, 0, 0, DesktopW, DesktopH, "Mobius Strip,....W toggle wire/solid Frame ... arrow keys/ mouse to move/ rotate Camera")
  If OpenWindowedScreen(WindowID(0), 0, 0, DesktopW, DesktopH, 0, 0, 0)
    
    Global monitor=CreateSprite(#PB_Any,120,40)
    
    CreateCamera(#Camera, 0, 0, 100, 100)
    MoveCamera(#Camera, 0, 2, 3, #PB_Absolute)
    CameraLookAt(#Camera,0,-0.1,0)
    CameraBackColor(#Camera, RGB(250,250,250))


    CreateLight(0, RGB(0, 0, 0), -20, 40, 20)
    SetLightColor(0, #PB_Light_DiffuseColor, RGB(255,255,255))
        
    AmbientColor(RGB(255, 255, 255))
    
    CreateMaterial(5, LoadTexture(5, "Wood.jpg"))
    MaterialCullingMode(5, #PB_Material_NoCulling)
    CreateMaterial(6, LoadTexture(6, "Geebee2.bmp"))
     
    CreatePlane(#plane,6, 60, TileCountX, TileCountZ, 1,1); only TileCountX, TileCountZ are important here

wireFrame = 0

plane() ;call the mobius strip constrution
;SaveMesh(#plane, "mobius.mesh")
   CreateEntity(#plane,MeshID(#plane), MaterialID(5),0,0,0 )
            
    GetMeshData(#plane,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_Tangent , 0, MeshVertexCount(#plane)-1)
    ArrSize = ArraySize(MeshData())
    ;Debug ArrSize
        
    ;find Normals lines end points
      
    For c=0 To ArrSize
      
      ;the vertex on the object surface 
      x.f = MeshData(c)\x 
      y.f = MeshData(c)\y
      z.f = MeshData(c)\z
        
      nx.f = MeshData(c)\NormalX
      ny.f = MeshData(c)\NormalY
      nz.f = MeshData(c)\NormalZ
                       
      ;for normals; find the next vertex to draw line along the normal vector begins from the vertex on the object surface
      x2.f = x+nx*7 : y2.f = y+ny*7: z2.f = z+nz*7   
                             
      spike = c + 10 ; begins numbering spikes from number 10 and up
      ;CreateCube(spike, 1)
      CreateCylinder(spike, 1, 1)
      TransformMesh(spike, 0,0,0, 0.01,0.1,0.01, 90,0,0)
      UpdateMeshBoundingBox(spike)
      CreateEntity(spike , MeshID(spike), MaterialID(6), x,y,z)
      EntityFixedYawAxis(spike , #True)
      EntityLookAt(spike , x2,y2,z2)
      MoveEntity(spike, 0,0,-0.051, #PB_Local )
      AttachEntityObject(#plane,"",EntityID(spike ))
      
    Next c
       
    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
    
  EndIf
EndIf
;HideEntity(#plane,#True)

RotateEntity(#plane, 0,20,0)
wireFrame = 1
triangles = MeshIndexCount(#plane)/3

    Repeat
      
      If ExamineMouse()
        MouseX = -MouseDeltaX()/20 
        MouseY = -MouseDeltaY()/20
      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
        
        If KeyboardReleased(#PB_Key_W)
          If wireFrame
          MaterialShadingMode(5, #PB_Material_Wireframe)
          wireFrame ! 1
        Else 
          MaterialShadingMode(5, #PB_Material_Solid)
          wireFrame ! 1
        EndIf
        EndIf
            
      EndIf
  
      RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(#Camera, KeyX, 0, KeyY)
      
      RotateEntity(#plane, 0.0,0.1,0.0,#PB_Relative)
      
      RenderWorld()
      
      StartDrawing(SpriteOutput(monitor))
      DrawText(5,5,"FPS : "+Str(Engine3DStatus(#PB_Engine3D_CurrentFPS )))
      DrawText(5,20,"Triangles=" +Str(triangles))
      
      StopDrawing()
      DisplaySprite(monitor,0,0)
  
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End


  Procedure plane()
    
 t.f=0
 GetMeshData(#plane,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate , 0, MeshVertexCount(#plane)-1)
 
  c=0 : u.f: v.f: r.f=5
  For i=0 To TileCountZ
    t.f+ #PI*2/TileCountZ
    u.f = 0 
    For k=-TileX To TileX
       ;parametric equations of mobius strip  
       MeshData(c)\x =  Cos(t) * ( 1 + (k/r * Cos(t/2)) )*1
       MeshData(c)\z =  Sin(t) * ( 1 + (k/r * Cos(t/2)) )*1
       MeshData(c)\y =  k/r * Sin(t/2)*1
    
       MeshData(c)\u =  u ; for texturing the shape
       MeshData(c)\v =  v ; //
   
       c + 1
       u + 1/TileCountX
     Next
     v + 1/TileCountZ
  Next
  
  SetMeshData(#plane,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(#plane)-1)     
  NormalizeMesh(#plane)
  BuildMeshTangents(#plane)
  UpdateMeshBoundingBox(#plane)
  

  EndProcedure
  
 
 
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Circular plane , Mobius Strip, from CreatePlane

Post by applePi »

just another deformation of the plane made month ago, something like a channel with sine shape and a ball rolling in it

Code: Select all

Enumeration
  #Window
  #Camera
  #sphere
  #plane
  #RedMaterial
      
EndEnumeration

Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)


#CameraSpeed = 0.2

Global TileCountX = 5, TileCountZ = 200

Declare plane()

Define.f KeyX, KeyY, MouseX, MouseY


If InitEngine3D()
  
  ;Add3DArchive(".", #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)
    
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
ExamineDesktops()
DesktopW = DesktopWidth(0)
DesktopH = DesktopHeight(0)

If OpenWindow(#Window, 0, 0, DesktopW, DesktopH, "W toggle wire/solid Frame ....mouse+arrow keys to move/ rotate the camera ")
  If OpenWindowedScreen(WindowID(#Window), 0, 0, DesktopW, DesktopH, 0, 0, 0)
    
    CreateCamera(#Camera, 0, 0, 100, 100)
    MoveCamera(#Camera, 10, 15, 30, #PB_Absolute)
    CameraLookAt(#Camera,14,0,0)
    CameraBackColor(#Camera, RGB(254,236,186)) ;RGB(200,155,40)
        
    CreateMaterial(2, LoadTexture(2, "ground_diffuse.png"))
    MaterialCullingMode(2, #PB_Material_NoCulling)
    DisableMaterialLighting(2, #True)
    ScrollMaterial(2, 0, 0, #PB_Material_Animated) 
    SetMaterialColor(2, #PB_Material_AmbientColor, RGB(250, 255, 0))
    SetMaterialColor(2, #PB_Material_SpecularColor, RGB(255, 255, 0))
    
    ;CreateMaterial(0, LoadTexture(0, "ground_diffuse.png"))
    CreateMaterial(0, LoadTexture(0, "MRAMOR6X6.jpg"))
    MaterialCullingMode(0, #PB_Material_NoCulling)
    DisableMaterialLighting(0, #True)
    
    GetScriptMaterial(#RedMaterial, "Color/Red")
    
    CreateLight(0, RGB(255, 255, 255), 500, 100, 500)
    AmbientColor(RGB(255, 255, 255))
  
  EndIf
EndIf

CreateMaterial(1, LoadTexture(1, "Geebee2.bmp"))
MaterialCullingMode(1, #PB_Material_NoCulling)

CreatePlane(#plane,50, 300, TileCountX, TileCountZ, 10,10)
CreateEntity(#plane,MeshID(#plane),MaterialID(0), 0, 0, 0)

MaterialShadingMode(0, #PB_Material_Wireframe)
wireFrame = 0

plane()
RotateEntity(#plane, 0,0, -5)
EntityPhysicBody(#plane, #PB_Entity_StaticBody)

CreateSphere(#sphere, 0.5)
CreateEntity(#sphere, MeshID(#sphere),  MaterialID(1) ,1,4,2.5)
EntityPhysicBody(#sphere, #PB_Entity_SphereBody, 1,1,1)

GetMeshData(#plane,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate , 0, MeshVertexCount(#plane)-1)
Repeat
  
  Event = WindowEvent()
        
      If ExamineMouse()
        MouseX = -MouseDeltaX()/20 
        MouseY = -MouseDeltaY()/20
      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
        
        If KeyboardPushed(#PB_Key_E)
          x.f+0.001
          ScrollMaterial(2, x, 0, #PB_Material_Fixed  , 1)    
         EndIf 
        
        If KeyboardReleased(#PB_Key_W)
          If wireFrame
            MaterialShadingMode(0, #PB_Material_Wireframe)
          wireFrame ! 1
        Else 
            MaterialShadingMode(0, #PB_Material_Solid)
          wireFrame ! 1
        EndIf
        EndIf
            
      EndIf
      
      RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(#Camera, KeyX, 0, KeyY)
       
      
      
      RenderWorld()
            
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End

  
  Procedure plane()
    
 t.f=0
 GetMeshData(#plane,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate , 0, MeshVertexCount(#plane)-1)
  ;GetMeshData(#TempSphere,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(#TempSphere, 0)-1)
 
  c=0 : dist.f : u.f: v.f
  For i=0 To TileCountZ
    dist  = 0 ; try dist = 0
    t.f+ #PI*4/30
    u.f = 0 
    For k=0 To TileCountX
                 
       MeshData(c)\x =  t
       MeshData(c)\z =  Sin(t) + dist
       If k=0 Or k=TileCountX: MeshData(c)\y + 1:EndIf
           
       MeshData(c)\u =  u
       MeshData(c)\v =  v
       dist + 0.4
       c + 1
       u + 1/TileCountX
     Next
     v + 1/TileCountZ
  Next
  
  SetMeshData(#plane,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(#plane)-1)     
  
   NormalizeMesh(#plane)
   BuildMeshTangents(#plane)
   UpdateMeshBoundingBox(#plane)
  

  EndProcedure
  
 
 
the second demo is a staircase, it needs models of man, woman, cat. attached all the package here:
http://wikisend.com/download/618390/staircase.rar
more links later
it depicts a crowd of people waiting in the desert in a long queue and then they climbed a very big staircase
all the models are free from here: http://tf3dm.com/3d-models/

the code alone (you need the models)

Code: Select all

Enumeration
  #Window
  #Camera
  #sphere
  #plane
  #plane2
  #win20
  #winDVD
  #man
  #girl
  #cat
  #ground
  
      
EndEnumeration

Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000)
  ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure

Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)


#CameraSpeed = 1

Global TileCountX = 5, TileCountZ = 400

Declare plane()

Define.f KeyX, KeyY, MouseX, MouseY


LoadFont(0, "Arial", 24, #PB_Font_Bold)
If InitEngine3D()
  
  Add3DArchive(".", #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)
    
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
ExamineDesktops()
DesktopW = DesktopWidth(0)
DesktopH = DesktopHeight(0)

If OpenWindow(#Window, 0, 0, DesktopW, DesktopH, "W toggle wire/solid Frame ..,Space: move the sphere to next vertex...mouse+arrow keys to move/ rotate the camera ")
  If OpenWindowedScreen(WindowID(#Window), 0, 0, DesktopW, DesktopH, 0, 0, 0)
    
    CreateCamera(#Camera, 0, 0, 100, 100)
    MoveCamera(#Camera, 0, 5, 30, #PB_Absolute)
    
    CameraLookAt(#Camera,0,0,0)
    CameraBackColor(#Camera, RGB(254,236,186)) ;RGB(200,155,40)
        
    CreateMaterial(2, LoadTexture(2, "house.jpg")) ;ground_diffuse.png
    MaterialCullingMode(2, #PB_Material_NoCulling)
    CreateMaterial(3, LoadTexture(3, "Wood.jpg"))
    MaterialCullingMode(3, #PB_Material_NoCulling)
    CreateMaterial(4, LoadTexture(4, "Geebee2.bmp"))
    
    CreateMaterial(0, LoadTexture(0, "gridMetal1.jpg"))
    MaterialCullingMode(0, #PB_Material_NoCulling)
    
    CreateLight(0, RGB(255, 255, 255), 100, 100, 0)
    CreateLight(1, RGB(255, 255, 255), 100, -100, 100)
    AmbientColor(RGB(255, 255, 255))
  
  EndIf
EndIf
notImportant=1
CreateMaterial(1, LoadTexture(1, "White.jpg"))
MaterialCullingMode(1, #PB_Material_NoCulling)

;CreatePlane(#Mesh, TileSizeX, TileSizeZ, TileCountX, TileCountZ, TextureRepeatCountX, TextureRepeatCountZ)
CreatePlane(#plane,notImportant, notImportant, TileCountX, TileCountZ, 1,1); only TileCountX, TileCountZ are important here
CreateEntity(#plane,MeshID(#plane),MaterialID(2), -15, 0, 0)
CreatePlane(#ground,1000, 1000, 100, 100, 1,1); only TileCountX, TileCountZ are important here
CreateEntity(#ground,MeshID(#ground),MaterialID(3), 500, -262, 0)
EntityPhysicBody(#ground, #PB_Entity_StaticBody)

wireFrame = 0

plane()

TransformMesh(#plane,0,0,0,1,1,1,0,0,15)
UpdateMeshBoundingBox(#plane)
GetMeshData(#plane,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate , 0, MeshVertexCount(#plane)-1)
;RotateEntity(#plane, 0,0, -15)
EntityPhysicBody(#plane, #PB_Entity_StaticBody)

CopyEntity(#plane, #plane2)
MoveEntity(#plane2, EntityX(#plane),EntityY(#plane), EntityZ(#plane), #PB_Absolute)
RotateEntity(#plane2, 0,0, -0.01)
SetEntityMaterial(#plane2, MaterialID(0))

CreateSphere(#sphere, 1)
CreateEntity(#sphere, MeshID(#sphere),  MaterialID(4) ,-13,4,2.0)
EntityPhysicBody(#sphere, #PB_Entity_SphereBody, 1,1,1)


LoadMesh(#man, "oldman_obj.mesh")
LoadMesh(#girl, "Girl_3ds.mesh")
TransformMesh(#man,0,0,0,0.2,0.2,0.2,0,0,0)
TransformMesh(#girl,0,0.3,-2,25,25,25,0,0,0)
UpdateMeshBoundingBox(#girl)
CreateEntity(#man, MeshID(#man), #PB_Material_None, 4,-14,8 )
CreateEntity(#girl, MeshID(#girl), #PB_Material_None, -10,-1,5 )

LoadMesh(#cat, "cat_obj.mesh")
TransformMesh(#cat,0,0,0,1.5,1.5,1.5,0,0,0)
CreateEntity(#cat, MeshID(#cat), #PB_Material_None, -12,-0.8,8 )
RotateEntity(#cat, 0,90,0)

RotateEntity(#man, 0,-90,0)
RotateEntity(#girl, 0,90,0)
meshcnt = MeshVertexCount(#plane) + 1

 ent = 800: entCat=2000
 For i=49 To meshcnt Step 60
  ent+1
  CopyEntity(Random(#girl,#man), ent)
  MoveEntity(ent, MeshData(i)\x, MeshData(i)\y-13, MeshData(i)\z+Randf(4,7), #PB_Absolute)
  RotateEntity(ent, 0,-90,0, #PB_Absolute)
  If EntityY(ent) < -262: MoveEntity(ent,0,EntityY(#ground)-EntityY(ent)-0.1, 0, #PB_Relative): EndIf
Next

xspace.f = -150
For i=1 To 2000 Step 60
  ent+1
  xspace.f+10
  CopyEntity(Random(#girl,#man), ent)
  MoveEntity(ent, EntityX(#ground)+xspace, EntityY(#ground)-EntityY(ent)-0.1, EntityZ(#ground)+Randf(4,7), #PB_Absolute)
  
  RotateEntity(ent, 0,-90,0, #PB_Absolute)
  If EntityY(ent) < -262: MoveEntity(ent,0,EntityY(#ground)-EntityY(ent)-0.1, 0, #PB_Relative): EndIf
 Next

 wireFrame = 1
    
 CreateTexture(90, 256, 256)
    StartDrawing(TextureOutput(90))
      Box(0, 0, 256, 256, RGB(218, 131, 14))
      Box(6, 6, 244, 244, RGB(190, 190, 190))
      DrawingMode(#PB_2DDrawing_Transparent)
      DrawingFont(FontID(0))
      DrawText(10, 10, "   Windows 20 ", RGB(149, 43, 255))
      DrawText(10, 60, "   Free License ", RGB(149, 43, 255))
      DrawText(10, 90, "   Welcome    ", RGB(168, 31, 220))
    StopDrawing()
    
    CreateMaterial(90, TextureID(90))
    MaterialCullingMode(90, #PB_Material_NoCulling)
    DisableMaterialLighting(90, #True)
    CreateCube(#win20,50)
    CreateEntity(#win20,MeshID(#win20),MaterialID(90), -15,4,2.5)
    ScaleEntity(#win20, 0.01,1,1.5)
    CreateEntity(#winDVD,MeshID(#win20),MaterialID(90), -11,0,1.5)
    ScaleEntity(#winDVD, 0.04,0.04,0.04)
    
    
Repeat
  
  Event = WindowEvent()
        
      If ExamineMouse()
        MouseX = -MouseDeltaX()/20 
        MouseY = -MouseDeltaY()/20
      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
        
        If KeyboardPushed(#PB_Key_E)
          x.f+0.001
          ScrollMaterial(2, x, 0, #PB_Material_Fixed  , 1)    
         EndIf 
        
        If KeyboardReleased(#PB_Key_W)
          If wireFrame
            MaterialShadingMode(2, #PB_Material_Wireframe)
            MaterialShadingMode(0, #PB_Material_Wireframe)
          wireFrame ! 1
        Else 
          MaterialShadingMode(2, #PB_Material_Solid)
          MaterialShadingMode(0, #PB_Material_Solid)
          wireFrame ! 1
        EndIf
        EndIf
            
      EndIf
      
      If KeyboardReleased(#PB_Key_Space)
        
             
        MoveEntity(#sphere, MeshData(num)\x,MeshData(num)\y,MeshData(num)\z, #PB_Absolute)
        num + 1
      EndIf
      
            
      If KeyboardReleased(#PB_Key_Z)
        Debug CameraX(#Camera): Debug CameraY(#Camera):Debug CameraZ(#Camera)
        Debug CameraYaw(#Camera):Debug CameraPitch(#Camera):Debug CameraRoll(#Camera):
      EndIf
      
    
  
      RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(#Camera, KeyX, 0, KeyY)
               
      
      RenderWorld()
            
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End

  
  Procedure plane()
    
 t.f=0
 GetMeshData(#plane,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate , 0, MeshVertexCount(#plane)-1)
   
  c=0 : dist.f : u.f: v.f
  For i=0 To TileCountZ
    dist  = 0 ; try dist = 0
              ;t.f+ #PI*2/30
    t.f+ #PI*10/30
    u.f = 0 
             
    For k=0 To TileCountX
                 
       MeshData(c)\x =  t
       MeshData(c)\z =  dist
       
       r.f=MeshData(c)\y
       If r<>rr.f
         ee=2
       Else
         ee=1
       EndIf
       
       MeshData(c)\y    - (Round(down.f, #PB_Round_Down )) * ee
       
       rr.f=MeshData(c)\y
       
       MeshData(c)\u =  u
       MeshData(c)\v =  v
       
       dist + 2
       c + 1
       u + 1/TileCountX
     Next
     down.f + 0.2: ;Debug down
     v + 1/(TileCountZ/100)
      
   Next
   
  SetMeshData(#plane,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(#plane)-1)     
  
   NormalizeMesh(#plane)
   BuildMeshTangents(#plane)
   UpdateMeshBoundingBox(#plane)
  

  EndProcedure
  
 
 
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Circular plane , Mobius Strip, from CreatePlane

Post by Keya »

applePi it seems like you're having a lot of fun with that Bullet physics engine heehee :) :) :)
I hadnt even heard of a Mobius strip until a couple months ago when i watched this cool little 9 minute TEDx talk, "The surprising beauty of mathematics" :)
https://youtu.be/SEiSloE1r-A?t=113
I set the URL to start at the Mobius strip part, about 2 mins in. Interesting for all ages! :)
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Circular plane , Mobius Strip, from CreatePlane

Post by applePi »

thank you Keya for the links, the first time i cut Mobius strip in half up the middle many years ago i have surprised too much that the result is one big loop, and cutting this bigger loop results in two interlinked loops
there is a device resembles mobius strip called MAMIKON SPINNER it is a strip twisted twice (instead of once like mobius). they said it is very sensible to wind blow, so can be used instead of usual blades in wind turbines to produce electricity.
http://www.mamikon.com/Spinner/Spinner.html
but there is not enough docs about that
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Circular plane , Mobius Strip, from CreatePlane

Post by Keya »

Its patented!! :( ... take a piece of paper, twist it twice and patent it!? he's lucky trees weren't patented...
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Circular plane , Mobius Strip, from CreatePlane

Post by davido »

When I first downloaded applePi's code it ran perfectly on both Mac & PC when compiled with PB5.2LTS and PB5.31.

I recently tried it again but compiled with PB5.40 Beta2, Beta4 and Beta6. Same result on both PB & Mac.
It flags an error as it does not recognise EntityPhysicalBody() as a function, array etc.

Can anyone confirm this or am I doing something wrong here?
DE AA EB
box_80
Enthusiast
Enthusiast
Posts: 117
Joined: Mon Sep 03, 2012 8:52 pm

Re: Circular plane , Mobius Strip, from CreatePlane

Post by box_80 »

davido wrote:When I first downloaded applePi's code it ran perfectly on both Mac & PC when compiled with PB5.2LTS and PB5.31.

I recently tried it again but compiled with PB5.40 Beta2, Beta4 and Beta6. Same result on both PB & Mac.
It flags an error as it does not recognise EntityPhysicalBody() as a function, array etc.

Can anyone confirm this or am I doing something wrong here?
EntityPhysicalBody was renamed to CreateEntityBody in PB5.40, along with TerrainPhysicBody to CreateTerrainBody.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Circular plane , Mobius Strip, from CreatePlane

Post by davido »

@box_80,
Thank you very much.
I really should read all the announcement thread. :oops:
DE AA EB
Post Reply