Page 1 of 1

Include mesh with IncludeBinary

Posted: Tue Nov 04, 2025 7:58 pm
by minimy
I always felt like a CatchMesh was missing so I could include the mesh in the executable.
I have created version 1.01, it has a limit of 65536 faces and 65536 vertices.
Respect the vertices, the faces , the normal ones and apply BuildMeshTangents().

The object is included like any other binary.

Code: Select all

DataSection
  mesh1:
    IncludeBinary "mymesh"
  mesh1end:
EndDataSection
Use this to create and save the object.

Code: Select all

CreateCube(1,10)
Mesh2Disc("mymesh",1)
Comment the 2 lines and use this to catch the object.

Code: Select all

catchMesh(2,?mesh1,?mesh1end-?mesh1)
CreateEntity(#PB_Any,MeshID(2),#PB_Material_None,0,10,0)

Code: Select all

;App:       CatchMesh v1.01
;Author:    minimy
;Date:      04/11/2025 [dd/mm/yy]
Procedure   Mesh2Disc(file.s="mymesh",mesh=1)
  ;saveMesh
  Protected   mvc= MeshVertexCount(mesh), mfc= MeshIndexCount(mesh),p
  Protected   Dim v.MeshVertex(mvc), Dim f.MeshFace(mfc)
  Protected   memSize= 4 + ((mvc * 9) * 4) + (mfc * 2);just for information
  If CreateFile(0,file)
    WriteUnicodeCharacter(0,mvc): WriteUnicodeCharacter(0,mfc): GetMeshData(mesh,0,v(),#PB_Mesh_Vertex|#PB_Mesh_UVCoordinate|#PB_Mesh_Color|#PB_Mesh_Normal, 0,mvc-1): GetMeshData(mesh,0,f(),#PB_Mesh_Face, 0,mfc-1)
    For p= 0 To mvc-1: WriteFloat(0,v(p)\x):WriteFloat(0,v(p)\y):WriteFloat(0,v(p)\z): WriteFloat(0,v(p)\u):WriteFloat(0,v(p)\v):WriteFloat(0,v(p)\Color): WriteFloat(0,v(p)\NormalX):WriteFloat(0,v(p)\NormalY):WriteFloat(0,v(p)\Normalz): Next p
    For p= 0 To mfc-1: WriteUnicodeCharacter(0,f(p)\Index): Next p
    CloseFile(0)
    ProcedureReturn #True
  EndIf
  ProcedureReturn #False
EndProcedure
Procedure   catchMesh(mesh,*m,size)
  ;catch mesh
  Protected   mvc, mfc,p
  Protected   pun
  mvc= PeekU(*m+pun):pun+2
  mfc= PeekU(*m+pun):pun+2
  Protected   Dim v.MeshVertex(mvc-1)
  Protected   Dim f.MeshFace(mfc-1)
  For p= 0 To mvc-1
    v(p)\x= PeekF(*m+pun):pun+4: v(p)\y= PeekF(*m+pun):pun+4: v(p)\z= PeekF(*m+pun):pun+4
    v(p)\u= PeekF(*m+pun):pun+4: v(p)\v= PeekF(*m+pun):pun+4: v(p)\Color= PeekF(*m+pun):pun+4
    v(p)\NormalX= PeekF(*m+pun):pun+4: v(p)\NormalY= PeekF(*m+pun):pun+4: v(p)\NormalZ= PeekF(*m+pun):pun+4
  Next p
  For p= 0 To mfc-1: f(p)\Index= PeekU(*m+pun):pun+2: Next p
  If mesh= #PB_Any: CreateMesh(#PB_Any,#PB_Mesh_TriangleList): Else: CreateMesh(mesh,#PB_Mesh_TriangleList): EndIf
  For p= 0 To mvc-1: MeshVertexPosition(v(p)\x,v(p)\y,v(p)\z): MeshVertexTextureCoordinate(v(p)\u,v(p)\v): MeshVertexColor(v(p)\Color): MeshVertexNormal(v(p)\NormalX,v(p)\NormalY,v(p)\NormalZ): Next p
  For p= 0 To mfc-1 Step 3: MeshFace(f(p)\Index,f(p+1)\Index,f(p+2)\Index): Next p
  FinishMesh(#True): BuildMeshTangents(mesh): FreeArray(v()):FreeArray(f())
  If IsMesh(mesh): ProcedureReturn mesh: Else: ProcedureReturn -1: EndIf
EndProcedure

InitEngine3D(#PB_Engine3D_DebugLog):InitSprite():InitKeyboard():InitMouse()
sysWin=OpenWindow(#PB_Any,0,20,1280,720,"CatchMesh v1.01",#PB_Window_BorderLess): OpenWindowedScreen(WindowID(sysWin),0,0,1280,720, 0,0,0,#PB_Screen_SmartSynchronization)
CreateCamera(0, 0,0,100,100): MoveCamera(camara,29.32,33.27,54.61,#PB_Absolute): CameraLookAt(0, 0,0,0): CreateLight(0, $ffffff, 100,100,100, #PB_Light_Directional): LightDirection(0, 0.25,-0.75,-0.25)

;comment after create and save the mesh
; CreateCube(1,10)
; Mesh2Disc("mymesh",1)

;uncomment to catch mesh and create entity
catchMesh(2,?mesh1,?mesh1end-?mesh1)
CreateEntity(#PB_Any,MeshID(2),#PB_Material_None,0,10,0)

Repeat
  Repeat: ev= WindowEvent(): Until ev=0
  ExamineKeyboard():ExamineMouse(): RenderWorld()
  FlipBuffers(): Delay(1): If KeyboardPushed(#PB_Key_Escape):salApp=1:EndIf
Until salApp=1: End

DataSection
  mesh1:
    IncludeBinary "mymesh"
  mesh1end:
EndDataSection

Re: Include mesh with IncludeBinary

Posted: Tue Nov 04, 2025 8:16 pm
by miso
With respect to those who do not know what's this. It's a custom mesh format, not an ogre mesh.

Re: Include mesh with IncludeBinary

Posted: Tue Nov 04, 2025 9:07 pm
by minimy
miso wrote: Tue Nov 04, 2025 8:16 pm With respect to those who do not know what's this. It's a custom mesh format, not an ogre mesh.
I'm glad to hear from you. Yes miso, you´re right!. is custom format created with Mesh2Disc("mymesh",1) is simple and not compress.
I dont know other way to include direct a .mesh because is not a free format i cant found the information about the file.
But work :lol:
Your compress format is to much better to share code, this is a raw code of the mesh information captured with GetMeshData.

Re: Include mesh with IncludeBinary

Posted: Tue Nov 04, 2025 9:41 pm
by minimy
This is the link for Tiny Mesh file format by miso:
viewtopic.php?p=641001#p641001