December 13, 2019, 05:06:14 PM

Author Topic: [bb] AddSurfaceToOtherSurface(Surface,Mesh,OSurface,OMesh) by RemiD [ 8 months ago ]  (Read 520 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : AddSurfaceToOtherSurface(Surface,Mesh,OSurface,OMesh)
Author : RemiD
Posted : 8 months ago

Description : merges a surface with another surface (alternative to addmesh)

Code :
Code: BlitzBasic
  1. ;AddSurfaceToOtherSurface(Surface,Mesh,OSurface,OMesh)
  2. ;merges a surface with another surface (alternative to addmesh)
  3. ;
  4. Graphics3D(1000,625,32,2)
  5.  
  6. SeedRnd(MilliSecs())
  7.  
  8. ;Input
  9. Global MX%
  10. Global MY%
  11. Global MXDiff%
  12. Global MYDiff%
  13.  
  14. Global Camera = CreateCamera()
  15. CameraViewport(Camera,0,0,GraphicsWidth(),GraphicsHeight())
  16. CameraRange(Camera,0.1,100)
  17. CameraClsColor(Camera,000,000,000)
  18.  
  19. Origine = CreateCube()
  20. ScaleMesh(Origine,0.01,0.01,0.01)
  21. EntityColor(Origine,255,000,255)
  22. EntityFX(Origine,1)
  23.  
  24. ;DLight
  25. Global DLight = CreateLight(1)
  26. LightColor(DLight,192,192,192)
  27. PositionEntity(DLight,0,1000,-1000,True)
  28. RotateEntity(DLight,45,0,0,True)
  29.  
  30. AmbientLight(019*2,019*2,019*2)
  31.  
  32. ;InteractionMode
  33. Global InteractionMode%
  34. Const C2D% = 1
  35. Const C3D% = 2
  36. InitializeInteractionMode()
  37.  
  38. ;Ghost
  39. Global GhostRoot
  40. Global GhostRootYaw#
  41. Global GhostEyes
  42. Global GhostEyesPitch#
  43. BuildGhost()
  44. InitializeGhost()
  45.  
  46. ;XCube = LoadMesh("cube 201610011115.b3d")
  47. ;ScaleMesh(XCube,0.01,0.01,0.01)
  48. XCube = CreateCube()
  49. ScaleMesh(XCube,1.0/2,1.0/2,1.0/2)
  50. HideEntity(XCube)
  51. DebugLog("Cube has "+CountVertices(GetSurface(XCube,1))+"vertices and "+CountTriangles(GetSurface(XCube,1))+"triangles")
  52.  
  53. ;XCylinder = LoadMesh("cylinder16 201610011126.b3d")
  54. ;ScaleMesh(XCylinder,0.01,0.01,0.01)
  55. XCylinder = CreateCylinder(16)
  56. ScaleMesh(XCylinder,1.0/2,1.0/2,1.0/2)
  57. HideEntity(XCylinder)
  58. DebugLog("Cylinder has "+CountVertices(GetSurface(XCylinder,1))+"vertices and "+CountTriangles(GetSurface(XCylinder,1))+"triangles")
  59.  
  60. ;XSphere = LoadMesh("sphere16 201610011129.b3d")
  61. ;ScaleMesh(XSphere,0.01,0.01,0.01)
  62. XSphere = CreateSphere(8)
  63. ScaleMesh(XSphere,1.0/2,1.0/2,1.0/2)
  64. HideEntity(XSphere)
  65. DebugLog("Sphere has "+CountVertices(GetSurface(XSphere,1))+"vertices and "+CountTriangles(GetSurface(XSphere,1))+"triangles")
  66.  
  67. Global FinalShape = CreateMesh()
  68. CreateSurface(FinalShape)
  69. ;add a cube to the finalshape
  70. TPart = CopyMesh(XCube)
  71. PositionMesh(TPart,0,0.5,0)
  72. AddSurfaceToOtherSurface(GetSurface(TPart,1),TPart,GetSurface(FinalShape,1),FinalShape)
  73. FreeEntity(TPart)
  74. ;add a cylinder to the finalshape
  75. TPart = CopyMesh(XCylinder)
  76. PositionMesh(TPart,0,1.0+0.5,0)
  77. AddSurfaceToOtherSurface(GetSurface(TPart,1),TPart,GetSurface(FinalShape,1),FinalShape)
  78. FreeEntity(TPart)
  79. ;add a sphere to the finalshape
  80. TPart = CopyMesh(XSphere)
  81. PositionMesh(TPart,0,1.0+1.0+0.5,0)
  82. AddSurfaceToOtherSurface(GetSurface(TPart,1),TPart,GetSurface(FinalShape,1),FinalShape)
  83. FreeEntity(TPart)
  84. DebugLog("FinalShape has "+CountVertices(GetSurface(FinalShape,1))+"vertices and "+CountTriangles(GetSurface(FinalShape,1))+"triangles")
  85.  
  86. ;ColorSurfaceWithBrush(GetSurface(FinalShape,1),Rand(025,255),Rand(025,255),Rand(025,255),1.0)
  87. EntityColor(FinalShape,Rand(025,255),Rand(025,255),Rand(025,255))
  88. EntityAlpha(FinalShape,1.0)
  89. EntityFX(FinalShape,0)
  90. EntityBlend(FinalShape,1)
  91.  
  92. PositionEntity(GhostRoot,0,1.65,-5,True)
  93.  
  94. Global MainLoopTimer = CreateTimer(30)
  95.  
  96. Main()
  97.  
  98. End()
  99.  
  100. Function Main()
  101.  
  102.  Repeat
  103.  
  104.   MainLoopMsStart% = MilliSecs()
  105.  
  106.   GetInput()
  107.  
  108.   UpdateInteractionMode()
  109.   If( InteractionMode = C2D )
  110.    ;
  111.   Else If( InteractionMode = C3D )
  112.    UpdateGhost()          
  113.   EndIf
  114.  
  115.   TurnEntity(FinalShape,0,1.0,0)
  116.  
  117.   PositionRotateEntityLikeOtherEntity(Camera,GhostEyes)
  118.  
  119.   WireFrame(False)
  120.   If( KeyDown(2)=1 )
  121.    WireFrame(True)
  122.   EndIf
  123.  
  124.   SetBuffer(BackBuffer())
  125.   Render3dMsStart% = MilliSecs()
  126.   RenderWorld()
  127.   Render3dMsTime% = MilliSecs()- Render3dMsStart
  128.  
  129.   Color(255,255,255)
  130.   CText("FPS = "+FPS,0,0)
  131.   CText("Render3dMsTime = "+Render3dMsTime,0,15)
  132.   CText("Tris = "+TrisRendered(),0,30)
  133.  
  134.   ;Flip(1)
  135.   WaitTimer(MainLoopTimer)
  136.   VWait():Flip(False)
  137.  
  138.   MainLoopMsTime = MilliSecs() - MainLoopMsStart
  139.   If( MainLoopMsTime <= 1 )
  140.    MainLoopMsTime = 1
  141.   EndIf
  142.  
  143.   FPS% = 1000.0/MainLoopMsTime
  144.  
  145.  Until( KeyDown(1)=1 )
  146.  
  147. End Function
  148.  
  149. Function CText(TextStr$,PX%,PY%)
  150.  Text(PX,PY,TextStr,False,False)
  151. End Function
  152.  
  153. Function PositionEntityLikeOtherEntity(Entity,OEntity)
  154.  PositionEntity(Entity,EntityX(OEntity,True),EntityY(OEntity,True),EntityZ(OEntity,True),True)
  155. End Function
  156.  
  157. Function RotateEntityLikeOtherEntity(Entity,OEntity)
  158.  RotateEntity(Entity,EntityPitch(OEntity,True),EntityYaw(OEntity,True),EntityRoll(OEntity,True),True)
  159. End Function
  160.  
  161. Function PositionRotateEntityLikeOtherEntity(Entity,OEntity)
  162.  PositionEntity(Entity,EntityX(OEntity,True),EntityY(OEntity,True),EntityZ(OEntity,True),True)
  163.  RotateEntity(Entity,EntityPitch(OEntity,True),EntityYaw(OEntity,True),EntityRoll(OEntity,True),True)
  164. End Function
  165.  
  166. Function InitializeInteractionMode()
  167.  InteractionMode = C3D
  168.  HidePointer()
  169. End Function
  170.  
  171. Function UpdateInteractionMode()
  172.  
  173.  If( KeyHit(15)=1 )
  174.   If( InteractionMode = C2D )
  175.    InteractionMode = C3D
  176.    HidePointer()
  177.   Else If( InteractionMode = C3D )
  178.    InteractionMode = C2D
  179.    ShowPointer()
  180.   EndIf
  181.  EndIf
  182.  
  183. End Function
  184.  
  185. Function BuildGhost()
  186.  
  187.  GhostRoot = CreatePivot()
  188.  
  189.  GhostEyes = CreatePivot()
  190.  PositionRotateEntityLikeOtherEntity(GhostEyes,GhostRoot)
  191.  EntityParent(GhostEyes,GhostRoot,True)
  192.  
  193. End Function
  194.  
  195. Function InitializeGhost()
  196.  PositionEntity(GhostRoot,0,0,-3,True)
  197. End Function
  198.  
  199. Function UpdateGhost()
  200.  
  201.  MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
  202.  GhostRootYaw = GhostRootYaw - Float(MXDiff)/10
  203.  RotateEntity(GhostRoot,0,GhostRootYaw,0,False)
  204.  GhostEyesPitch = GhostEyesPitch + Float(MYDiff)/10
  205.  If( GhostEyesPitch < -89 )
  206.   GhostEyesPitch = -89
  207.  Else If( GhostEyesPitch > 89 )
  208.   GhostEyesPitch = 89
  209.  EndIf
  210.  RotateEntity(GhostEyes,GhostEyesPitch,0,0,False)
  211.  
  212.  If( KeyDown(42) = 0 And KeyDown(29) = 0 )
  213.   Speed# = 0.1
  214.  Else If( KeyDown(42) = 1 And KeyDown(29) = 0 )
  215.   Speed# = 1
  216.  Else If( KeyDown(42) = 0 And KeyDown(29) = 1 )
  217.   Speed# = 0.01
  218.  EndIf
  219.  
  220.  If( KeyDown(17)=1 Or MouseDown(1)=1 )
  221.   MoveEntity(GhostRoot,0,0,Speed)
  222.  Else If( KeyDown(31)=1 Or MouseDown(2)=1 )
  223.   MoveEntity(GhostRoot,0,0,-Speed)
  224.  EndIf
  225.  If( KeyDown(30)=1 )
  226.   MoveEntity(GhostRoot,-Speed,0,0)
  227.  Else If( KeyDown(32)=1 )
  228.   MoveEntity(GhostRoot,Speed,0,0)
  229.  EndIf
  230.  If( KeyDown(16)=1 )
  231.   MoveEntity(GhostRoot,0,-Speed,0)
  232.  Else If( KeyDown(18)=1 )
  233.   MoveEntity(GhostRoot,0,Speed,0)
  234.  EndIf
  235.  
  236. End Function
  237.  
  238. Function GetInput()
  239.  
  240.  MX = MouseX()
  241.  MY = MouseY()
  242.  
  243.  MXDiff = MouseXSpeed()
  244.  MYDiff = MouseYSpeed()
  245.  
  246. End Function
  247.  
  248. ;vertices+triangles (with normals, with colors, with alphas, with uvs)
  249. Function AddSurfaceToOtherSurface(Surface,Mesh,OSurface,OMesh)
  250.  SurfaceVerticesCount% = CountVertices(Surface)
  251.  ;DebugLog("SurfaceVerticesCount = "+SurfaceVerticesCount)
  252.  OSurfaceVerticesCount% = CountVertices(OSurface)
  253.  ;DebugLog("OSurfaceVerticesCount = "+OSurfaceVerticesCount)
  254.  For VI% = 0 To CountVertices(Surface)-1 Step 1
  255.   ;DebugLog("VI = "+VI)
  256.   VLX# = VertexX(Surface,VI)
  257.   VLY# = VertexY(Surface,VI)
  258.   VLZ# = VertexZ(Surface,VI)
  259.   TFormPoint(VLX,VLY,VLZ,Mesh,0)
  260.   VGX# = TFormedX()
  261.   VGY# = TFormedY()
  262.   VGZ# = TFormedZ()
  263.   VNX# = VertexNX(Surface,VI)
  264.   VNY# = VertexNY(Surface,VI)
  265.   VNZ# = VertexNZ(Surface,VI)
  266.   VR% = VertexRed(Surface,VI)
  267.   VG% = VertexGreen(Surface,VI)
  268.   VB% = VertexBlue(Surface,VI)
  269.   VA# = VertexAlpha(Surface,VI)
  270.   VU# = VertexU(Surface,VI,0)
  271.   VV# = VertexV(Surface,VI,0)
  272.   If( OSurfaceVerticesCount = 0 )
  273.    NVI = VI
  274.   Else If( OSurfaceVerticesCount > 0 )
  275.    NVI% = OSurfaceVerticesCount+VI
  276.   EndIf
  277.   ;DebugLog("NVI = "+NVI)
  278.   AddVertex(OSurface,VGX,VGY,VGZ)
  279.   VertexNormal(OSurface,NVI,VNX,VNY,VNZ)
  280.   VertexColor(OSurface,NVI,VR,VG,VB,VA)
  281.   VertexTexCoords(OSurface,NVI,VU,VB)
  282.   ;WaitKey()
  283.  Next
  284.  SurfaceTrianglesCount% = CountTriangles(Surface)
  285.  ;DebugLog("SurfaceTrianglesCount = "+SurfaceTrianglesCount)
  286.  OSurfaceTrianglesCount% = CountTriangles(OSurface)
  287.  ;DebugLog("OSurfaceTrianglesCount = "+OSurfaceTrianglesCount)
  288.  For TI% = 0 To CountTriangles(Surface)-1 Step 1
  289.   V0I% = TriangleVertex(Surface,TI,0) ;vertex0
  290.   V1I% = TriangleVertex(Surface,TI,1) ;vertex1
  291.   V2I% = TriangleVertex(Surface,TI,2) ;vertex2
  292.   ;DebugLog("oldtriangle"+TI+" "+V0I+","+V1I+","+V2I)
  293.   If( OSurfaceVerticesCount = 0 )
  294.    NV0I% = V0I
  295.    NV1I% = V1I
  296.    NV2I% = V2I
  297.   Else If( OSurfaceVerticesCount > 0 )
  298.    NV0I% = OSurfaceVerticesCount+V0I
  299.    NV1I% = OSurfaceVerticesCount+V1I
  300.    NV2I% = OSurfaceVerticesCount+V2I
  301.   EndIf
  302.   ;DebugLog("newtriangle"+TI+" "+NV0I+","+NV1I+","+NV2I)
  303.   AddTriangle(OSurface,NV0I,NV1I,NV2I)
  304.  Next
  305.  ;WaitKey()
  306. End Function
  307.  
  308. Function ColorSurfaceWithBrush(Surface,R%,G%,B%,A#=1.0,Fx%=0,BlendMode%=1)
  309.  Brush = CreateBrush()
  310.  BrushColor(Brush,R,G,B)
  311.  BrushAlpha(Brush,A)
  312.  BrushFX(Brush,Fx)
  313.  BrushBlend(Brush,BlendMode)
  314.  PaintSurface(Surface,Brush)
  315.  FreeBrush(Brush)
  316. End Function


Comments :


RemiD(Posted 8 months ago)

 i suggest to not use Blitz3d primitives because you don't know exactly how they are made/structured.So use your own clean shapes. (i suggest to export with Fragmotion, the export has always been correct for all my shapes so far...)


Offline RemiD

  • Hero Member
  • *****
  • Posts: 1027
there was an error in the code posted previously and only the UVs on coordset 0 were copied (the UVs on coordset 1 were not)

this code fixes the error / missing UVs (coordset1) :
Code: [Select]
;AddSurfaceToOtherSurface(Surface,Mesh,OSurface,OMesh) 20191009
;merges a surface with another surface (alternative to addmesh)
;vertices+triangles (with normals, with colors, with alphas, with uvs coordset0 and uvs coordset1 )
Graphics3D(1000,625,32,2)
 
SeedRnd(MilliSecs())
 
;Input
Global MX%
Global MY%
Global MXDiff%
Global MYDiff%
 
Global Camera = CreateCamera()
CameraViewport(Camera,0,0,GraphicsWidth(),GraphicsHeight())
CameraRange(Camera,0.1,100)
CameraClsColor(Camera,000,000,000)
 
Origine = CreateCube()
ScaleMesh(Origine,0.01,0.01,0.01)
EntityColor(Origine,255,000,255)
EntityFX(Origine,1)

Global InteractionMode%
Const C2D% = 1
Const C3D% = 2
InteractionMode = C2D
HidePointer()
 
;Ghost
Global GhostRoot
Global GhostRootYaw#
Global GhostEyes
Global GhostEyesPitch#
BuildGhost()
 
;XCube = LoadMesh("cube 201610011115.b3d")
;ScaleMesh(XCube,0.01,0.01,0.01)
XCube = CreateCube()
ScaleMesh(XCube,1.0/2,1.0/2,1.0/2)
HideEntity(XCube)
DebugLog("Cube has "+CountVertices(GetSurface(XCube,1))+"vertices and "+CountTriangles(GetSurface(XCube,1))+"triangles")
 
;XCylinder = LoadMesh("cylinder16 201610011126.b3d")
;ScaleMesh(XCylinder,0.01,0.01,0.01)
XCylinder = CreateCylinder(16)
ScaleMesh(XCylinder,1.0/2,1.0/2,1.0/2)
HideEntity(XCylinder)
DebugLog("Cylinder has "+CountVertices(GetSurface(XCylinder,1))+"vertices and "+CountTriangles(GetSurface(XCylinder,1))+"triangles")
 
;XSphere = LoadMesh("sphere16 201610011129.b3d")
;ScaleMesh(XSphere,0.01,0.01,0.01)
XSphere = CreateSphere(8)
ScaleMesh(XSphere,1.0/2,1.0/2,1.0/2)
HideEntity(XSphere)
DebugLog("Sphere has "+CountVertices(GetSurface(XSphere,1))+"vertices and "+CountTriangles(GetSurface(XSphere,1))+"triangles")
 
Global NMesh = CreateMesh()
CreateSurface(NMesh)
;add a cube to the new mesh
TPart = CopyMesh(XCube)
PositionMesh(TPart,0,0.5,0)
AddSurfaceToOtherSurface(GetSurface(TPart,1),TPart,GetSurface(NMesh,1),NMesh)
FreeEntity(TPart)
;add a cylinder to the new mesh
TPart = CopyMesh(XCylinder)
PositionMesh(TPart,0,1.0+0.5,0)
AddSurfaceToOtherSurface(GetSurface(TPart,1),TPart,GetSurface(NMesh,1),NMesh)
FreeEntity(TPart)
;add a sphere to the new mesh
TPart = CopyMesh(XSphere)
PositionMesh(TPart,0,1.0+1.0+0.5,0)
AddSurfaceToOtherSurface(GetSurface(TPart,1),TPart,GetSurface(NMesh,1),NMesh)
FreeEntity(TPart)
DebugLog("NMesh has "+CountVertices(GetSurface(NMesh,1))+"vertices and "+CountTriangles(GetSurface(NMesh,1))+"triangles")
 
EntityColor(NMesh,Rand(025,255),Rand(025,255),Rand(025,255))
EntityAlpha(NMesh,1.0)
EntityFX(NMesh,0)
EntityBlend(NMesh,1)
 
;DLight
Global DLight = CreateLight(1)
LightColor(DLight,192,192,192)
PositionEntity(DLight,0,1000,-1000,True)
RotateEntity(DLight,45,0,0,True)
 
AmbientLight(019*2,019*2,019*2)

PositionEntity(GhostRoot,0,1.65,-5,True)
 
Main()
 
End()
 
Function Main()
 
 Repeat
 
  GetInput()

  UpdateInteractionMode()
  If( InteractionMode = C2D )
   ;
  Else If( InteractionMode = C3D )
   UpdateGhost()         
  EndIf         
 
  TurnEntity(NMesh,0,1.0,0)
 
  PositionRotateEntityLikeOtherEntity(Camera,GhostEyes)
 
  WireFrame(False)
  If( KeyDown(2)=1 )
   WireFrame(True)
  EndIf
 
  SetBuffer(BackBuffer())
  RenderWorld()
 
  Color(255,255,255)
  CText("Tris = "+TrisRendered(),0,0)
 
  Flip(1)
 
 Until( KeyDown(1)=1 )
 
End Function
 
Function CText(TextStr$,PX%,PY%)
 Text(PX,PY,TextStr,False,False)
End Function
 
Function PositionEntityLikeOtherEntity(Entity,OEntity)
 PositionEntity(Entity,EntityX(OEntity,True),EntityY(OEntity,True),EntityZ(OEntity,True),True)
End Function
 
Function RotateEntityLikeOtherEntity(Entity,OEntity)
 RotateEntity(Entity,EntityPitch(OEntity,True),EntityYaw(OEntity,True),EntityRoll(OEntity,True),True)
End Function
 
Function PositionRotateEntityLikeOtherEntity(Entity,OEntity)
 PositionEntity(Entity,EntityX(OEntity,True),EntityY(OEntity,True),EntityZ(OEntity,True),True)
 RotateEntity(Entity,EntityPitch(OEntity,True),EntityYaw(OEntity,True),EntityRoll(OEntity,True),True)
End Function

Function UpdateInteractionMode()
 
 If( KeyHit(15)=1 )
  If( InteractionMode = C2D )
   InteractionMode = C3D
   HidePointer()
  Else If( InteractionMode = C3D )
   InteractionMode = C2D
   ShowPointer()
  EndIf
 EndIf
 
End Function
 
Function BuildGhost()
 
 GhostRoot = CreatePivot()
 
 GhostEyes = CreatePivot()
 PositionRotateEntityLikeOtherEntity(GhostEyes,GhostRoot)
 EntityParent(GhostEyes,GhostRoot,True)
 
End Function

Function UpdateGhost()
 
 MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
 GhostRootYaw = GhostRootYaw - Float(MXDiff)/10
 RotateEntity(GhostRoot,0,GhostRootYaw,0,False)
 GhostEyesPitch = GhostEyesPitch + Float(MYDiff)/10
 If( GhostEyesPitch < -89 )
  GhostEyesPitch = -89
 Else If( GhostEyesPitch > 89 )
  GhostEyesPitch = 89
 EndIf
 RotateEntity(GhostEyes,GhostEyesPitch,0,0,False)
 
 If( KeyDown(42) = 0 And KeyDown(29) = 0 )
  Speed# = 0.1
 Else If( KeyDown(42) = 1 And KeyDown(29) = 0 )
  Speed# = 1
 Else If( KeyDown(42) = 0 And KeyDown(29) = 1 )
  Speed# = 0.01
 EndIf
 
 If( KeyDown(17)=1 Or MouseDown(1)=1 )
  MoveEntity(GhostRoot,0,0,Speed)
 Else If( KeyDown(31)=1 Or MouseDown(2)=1 )
  MoveEntity(GhostRoot,0,0,-Speed)
 EndIf
 If( KeyDown(30)=1 )
  MoveEntity(GhostRoot,-Speed,0,0)
 Else If( KeyDown(32)=1 )
  MoveEntity(GhostRoot,Speed,0,0)
 EndIf
 If( KeyDown(16)=1 )
  MoveEntity(GhostRoot,0,-Speed,0)
 Else If( KeyDown(18)=1 )
  MoveEntity(GhostRoot,0,Speed,0)
 EndIf
 
End Function
 
Function GetInput()
 
 MX = MouseX()
 MY = MouseY()
 
 MXDiff = MouseXSpeed()
 MYDiff = MouseYSpeed()
 
End Function
 
;vertices+triangles (with normals, with colors, with alphas, with uvs coordset0 and uvs coordset1 )
Function AddSurfaceToOtherSurface(Surface,Mesh,OSurface,OMesh)

 SurfaceVerticesCount% = CountVertices(Surface)
 ;DebugLog("SurfaceVerticesCount = "+SurfaceVerticesCount)
 OSurfaceVerticesCount% = CountVertices(OSurface)
 ;DebugLog("OSurfaceVerticesCount = "+OSurfaceVerticesCount)
 For VI% = 0 To CountVertices(Surface)-1 Step 1
  ;DebugLog("VI = "+VI)
  TFormPoint(VertexX(Surface,VI),VertexY(Surface,VI),VertexZ(Surface,VI),Mesh,0)
  VGX# = TFormedX() : VGY# = TFormedY() : VGZ# = TFormedZ()
  TFormVector(VertexNX(Surface,VI),VertexNY(Surface,VI),VertexNZ(Surface,VI),Mesh,0)
  VGNX# = TFormedX() : VGNY# = TFormedY() : VGNZ# = TFormedZ()
  VR% = VertexRed(Surface,VI) : VG% = VertexGreen(Surface,VI) : VB% = VertexBlue(Surface,VI)
  VA# = VertexAlpha(Surface,VI)
  VU0# = VertexU(Surface,VI,0) : VV0# = VertexV(Surface,VI,0)
  VU1# = VertexU(Surface,VI,1) : VV1# = VertexV(Surface,VI,1)
  If( OSurfaceVerticesCount = 0 )
   NVI = VI
  Else If( OSurfaceVerticesCount > 0 )
   NVI% = OSurfaceVerticesCount+VI
  EndIf
  ;DebugLog("NVI = "+NVI)
  AddVertex(OSurface,VGX,VGY,VGZ)
  VertexNormal(OSurface,NVI,VGNX,VGNY,VGNZ)
  VertexColor(OSurface,NVI,VR,VG,VB,VA)
  VertexTexCoords(OSurface,NVI,VU0,VV0,0,0)
  VertexTexCoords(OSurface,NVI,VU1,VV1,0,1)
  ;WaitKey()
 Next
 SurfaceTrianglesCount% = CountTriangles(Surface)
 ;DebugLog("SurfaceTrianglesCount = "+SurfaceTrianglesCount)
 OSurfaceTrianglesCount% = CountTriangles(OSurface)
 ;DebugLog("OSurfaceTrianglesCount = "+OSurfaceTrianglesCount)
 For TI% = 0 To CountTriangles(Surface)-1 Step 1
  V0I% = TriangleVertex(Surface,TI,0) ;vertex0
  V1I% = TriangleVertex(Surface,TI,1) ;vertex1
  V2I% = TriangleVertex(Surface,TI,2) ;vertex2
  ;DebugLog("oldtriangle"+TI+" "+V0I+","+V1I+","+V2I)
  If( OSurfaceVerticesCount = 0 )
   NV0I% = V0I
   NV1I% = V1I
   NV2I% = V2I
  Else If( OSurfaceVerticesCount > 0 )
   NV0I% = OSurfaceVerticesCount+V0I
   NV1I% = OSurfaceVerticesCount+V1I
   NV2I% = OSurfaceVerticesCount+V2I
  EndIf
  ;DebugLog("newtriangle"+TI+" "+NV0I+","+NV1I+","+NV2I)
  AddTriangle(OSurface,NV0I,NV1I,NV2I)
 Next
 ;WaitKey()

End Function

DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0