CreateMesh, FinishMesh - Type, Mode?

Just starting out? Need help? Post your questions and find answers here.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

CreateMesh, FinishMesh - Type, Mode?

Post by STARGÅTE »

What is Type and Mode in CreateMesh and FinishMesh?
which constants can I use?
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: CreateMesh, FinishMesh - Type, Mode?

Post by Comtois »

Look at these examples, they show how To use CreateMesh() With the new constants :

- MeshManualFlag.pb
- MeshManualParametrics.pb
- MeshManual2.pb

Here is the List of new constants :

Code: Select all

;Text3DAlignment()
Debug #PB_Text3D_Left                 
Debug #PB_Text3D_HorizontallyCentered
Debug #PB_Text3D_Above               
Debug #PB_Text3D_Bottom               
Debug #PB_Text3D_VerticallyCentered 

;CreateMesh(), AddSubMesh()
Debug #PB_Mesh_PointList
Debug #PB_Mesh_LineList
Debug #PB_Mesh_LineStrip
Debug #PB_Mesh_TriangleList 
Debug #PB_Mesh_TriangleStrip
Debug #PB_Mesh_TriangleFan   

;Get/SetMaterialColor()
Debug #PB_Material_DiffuseColor
Debug #PB_Material_SpecularColor
Debug #PB_Material_AmbientColor
Debug #PB_Material_SelfIlluminationColor

;GetMaterialAttribute()
Debug #PB_Material_Shininess             
Debug #PB_Material_TextureRotate         
Debug #PB_Material_TextureUScale         
Debug #PB_Material_TextureVScale         
Debug #PB_Material_TextureUScroll       
Debug #PB_Material_TextureVScroll       
Debug #PB_Material_DepthWrite           
Debug #PB_Material_Lighting             
Debug #PB_Material_ShadingMode     

;MaterialCullingMode()
Debug #PB_Material_NoCulling
Debug #PB_Material_ClockWiseCull
Debug #PB_Material_AntiClockWiseCull 

And the List of new examples :

- MeshManualFlag.pb
- MeshManualParametrics.pb
- CameraTrack.pb (now use AttachEntityObject() without bone)
- CheckObjectVisibility.pb
- CheckObjectVisibility2.pb
- ConvertLocalToWorldPosition.pb
- ConvertWorldToLocalPosition.pb
- CopyAngle.pb
- EnableManualEntityBoneControl.pb
- FetchOrientation.pb
- MeshManual2.pb
- MouseRayCast.pb
- RayCast.pb
- SetOrientation.pb (For Next release)
Please correct my english
http://purebasic.developpez.com/
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: CreateMesh, FinishMesh - Type, Mode?

Post by Comtois »

CreateMesh(0, #PB_Mesh_TriangleList, #True)
Mode = #True . Mesh can be update

FinishMesh(#False) : #False if you need to update a mesh or attach a mesh to a node or a bone (you cant use it to create an entity).
FinishMesh(#True) : If you need to instantiate your mesh (using with CreateEntity())
Please correct my english
http://purebasic.developpez.com/
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: CreateMesh, FinishMesh - Type, Mode?

Post by Comtois »

I have modified MeshManual2.pb to show how to use MeshIndex()

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - MeshManual 
;
;    (c) 2012 - Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 1
#scale = 3

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/fonts", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    ;- Material
    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
    
    ;- Mesh Plane
    CreateMesh(0, #PB_Mesh_LineStrip, #False)
    MeshVertexPosition(-10, 0, -10) 
    MeshVertexColor(RGB(255,0,0))
    MeshVertexPosition(-10, 0,  10) 
    MeshVertexColor(RGB(255,255,0)) 
    MeshVertexPosition( 10, 0,  10) 
    MeshVertexColor(RGB(255,0,255))
    MeshVertexPosition( 10, 0, -10)
    MeshVertexColor(RGB(0,255,0))
    MeshVertexPosition(-10, 0, -10)
    MeshVertexColor(RGB(255,0,0))
    FinishMesh(#False)
    
    SetMeshMaterial(0, MaterialID(0))
    Plane = CreateNode(#PB_Any, -40, 0, 0)
    AttachNodeObject(Plane, MeshID(0))
    
    ;- Mesh Stars
    CreateMesh(1, #PB_Mesh_PointList, #False)
    For i = 0 To 10000
      MeshVertexPosition(Random(200)-100, Random(200)-100, Random(200)-100)
      MeshVertexColor(RGB(255,255,0))
    Next i 
    FinishMesh(#False)
    
    SetMeshMaterial(1, MaterialID(0))
    
    Stars = CreateNode(#PB_Any)
    AttachNodeObject(Stars, MeshID(1))
    
    ;- Mesh Box
    CreateMesh(2, #PB_Mesh_LineStrip, #False)
    MeshVertexPosition(-10, -10, -10) 
    MeshVertexPosition(-10, -10,  10) 
    MeshVertexPosition( 10, -10,  10) 
    MeshVertexPosition( 10, -10, -10)
    MeshVertexPosition(-10, -10, -10)
    AddSubMesh(#PB_Mesh_LineStrip)
    MeshVertexPosition(-10,  10, -10) 
    MeshVertexPosition(-10,  10,  10) 
    MeshVertexPosition( 10,  10,  10) 
    MeshVertexPosition( 10,  10, -10)
    MeshVertexPosition(-10,  10, -10)
    AddSubMesh(#PB_Mesh_LineList)
    MeshVertexPosition(-10, -10, -10) 
    MeshVertexPosition(-10,  10, -10) 
    MeshVertexPosition(-10, -10,  10) 
    MeshVertexPosition(-10,  10,  10) 
    MeshVertexPosition( 10, -10,  10) 
    MeshVertexPosition( 10,  10,  10) 
    MeshVertexPosition( 10, -10, -10) 
    MeshVertexPosition( 10,  10, -10) 
    FinishMesh(#False)
    
    SetMeshMaterial(2, MaterialID(0))
    Box = CreateNode(#PB_Any, 40, 0, 0)
    AttachNodeObject(Box, MeshID(2))
    
    ;- Mesh Grid
    CreateMesh(3, #PB_Mesh_LineList, #False)
    For i=0 To 20
      MeshVertexPosition(-20, 0, (i-10)*-2) 
      MeshVertexColor(RGB(55,155,255))
      MeshVertexPosition(20, 0, (i-10)*-2) 
      MeshVertexColor(RGB(55,155,255))
    Next
    For i=0 To 20
      MeshVertexPosition((i-10)*-2, 0, -20) 
      MeshVertexColor(RGB(255,155,55))
      MeshVertexPosition((i-10)*-2, 0,  20) 
      MeshVertexColor(RGB(255,155,55))
    Next     
    FinishMesh(#False)
    
    SetMeshMaterial(3, MaterialID(0))
    Grid = CreateNode(#PB_Any, 0, 0, 0)
    AttachNodeObject(Grid, MeshID(3))
    
    
    ;- Mesh Plane (using MeshIndex)
    CreateMesh(4, #PB_Mesh_LineStrip, #False)
    
    ; Define vertex position of index 0..3
    MeshVertexPosition(-10, 0, -10) 
    MeshVertexPosition(-10, 0,  10) 
    MeshVertexPosition( 10, 0,  10) 
    MeshVertexPosition( 10, 0, -10)
    
    ; Define usage of vertices by refering To the indexes
    MeshIndex(0)
    MeshIndex(1)
    MeshIndex(2)
    MeshIndex(3)
    MeshIndex(0)
    FinishMesh(#False)
    
    SetMeshMaterial(4, MaterialID(0))
    Plane2 = CreateNode(#PB_Any, 0, 30, 0)
    AttachNodeObject(Plane2, MeshID(4))
    
    ;- Mesh Box (using MeshIndex) 
    CreateMesh(5, #PB_Mesh_LineList, #False)
    
    ; Define vertex position of index 0..7
    MeshVertexPosition(-10, -10, -10) 
    MeshVertexPosition(-10, -10,  10) 
    MeshVertexPosition( 10, -10,  10) 
    MeshVertexPosition( 10, -10, -10)
    MeshVertexPosition(-10,  10, -10) 
    MeshVertexPosition(-10,  10,  10) 
    MeshVertexPosition( 10,  10,  10) 
    MeshVertexPosition( 10,  10, -10)
    
    ; Define usage of vertices by refering To the indexes
    MeshIndex(0)
    MeshIndex(1)
    MeshIndex(1)
    MeshIndex(2)
    MeshIndex(2)
    MeshIndex(3)
    MeshIndex(0)
    MeshIndex(3)
    
    MeshIndex(4)
    MeshIndex(5)
    MeshIndex(5)
    MeshIndex(6)
    MeshIndex(6)
    MeshIndex(7)
    MeshIndex(4)
    MeshIndex(7)
    
    MeshIndex(0)
    MeshIndex(4)
    MeshIndex(1)
    MeshIndex(5)
    MeshIndex(2)
    MeshIndex(6)
    MeshIndex(3)
    MeshIndex(7)
    
    FinishMesh(#False)
    
    SetMeshMaterial(5, MaterialID(0))
    Box2 = CreateNode(#PB_Any, 0, -30, 0)
    AttachNodeObject(Box2, MeshID(5))
    
    ;-Camera
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 40, 150, #PB_Absolute)
    CameraFOV(0, 40)
    CameraLookAt(0, NodeX(Grid),  NodeY(Grid),  NodeZ(Grid))
    CameraBackColor(0, RGB(0, 0, 40))
    
    ;-Light
    CreateLight(0, RGB(255,255,255), -10, 60, 10)
    AmbientColor(RGB(90, 90, 90))
    
    Repeat
      Screen3DEvents()
      
      ExamineKeyboard()
      
      RotateNode(Plane, 0.3, -0.3, -0.3, #PB_Relative)
      RotateNode(Stars, 0.1, 0.1, 0.1, #PB_Relative)
      RotateNode(Box, 0.3, 0.3, 0.3, #PB_Relative)
      RotateNode(Grid, 0.3, 0.3, 0.3, #PB_Relative) 
      RotateNode(Plane2, 0.3, -0.3, -0.3, #PB_Relative) 
      RotateNode(Box2, 0.3, 0.3, 0.3, #PB_Relative)
      RenderWorld()
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

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

Re: CreateMesh, FinishMesh - Type, Mode?

Post by applePi »

i haven't seen the meshmanual2.pb before, i admit it is fantastic, a surreal astro effect, and a subject for the study. thanks
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: CreateMesh, FinishMesh - Type, Mode?

Post by STARGÅTE »

thx for examples
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Post Reply