Dynamic Mesh : no UV and COLOR updates

Everything related to 3D programming
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Dynamic Mesh : no UV and COLOR updates

Post by eddy »

x64 win7

Code: Select all

InitEngine3D()
InitSprite()

AntialiasingMode(#PB_AntialiasingMode_None)

win=OpenWindow(#PB_Any, 0, 0, 800, 600, "Create QUAD mesh", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(win), 0, 0, WindowWidth(win), WindowHeight(win))

cam=CreateCamera(#PB_Any, 0, 0, 100, 100)
CameraProjectionMode(cam, #PB_Camera_Orthographic)
CameraRange(cam, 0.1, 1000)
CameraBackColor(cam, RGB(255, 55, 0))
RotateCamera(cam, 180, 0, 0)

hidden=CreateEntity(#PB_Any, MeshID(CreateCube(#PB_Any, 100)), #PB_Material_None, 0, 0, 500)
ScaleEntity(hidden, 100, 100, 0.01)
HideEntity(hidden, 1)
RenderWorld()
If MousePick(cam, 0, 0)
   zx.f=Abs(PickX()/(ScreenWidth()/2))
   zy.f=Abs(PickY()/(ScreenHeight()/2))
   FreeEntity(hidden)
EndIf


w=512
h=512

tex=CreateTexture(#PB_Any, w, h)
If StartDrawing(TextureOutput(tex))
   DrawingMode(#PB_2DDrawing_Gradient)
   BackColor(RGB(162, 75, 51))
   FrontColor(RGB(71, 162, 51))
   CircularGradient(w, h, w/2)
   Box(0, 0, w, h)
   DrawingMode(#PB_2DDrawing_Default)
   Plot(0, 1, 0)
   Plot(1, 0, 0)
   Plot(0, 3, 0)
   Plot(3, 0, 0)
   StopDrawing()
EndIf
mat=CreateMaterial(#PB_Any, TextureID(tex))
MaterialFilteringMode(mat, #PB_Material_None)
MaterialCullingMode(mat, #PB_Material_NoCulling)
DisableMaterialLighting(mat, #True)

m=CreateMesh(#PB_Any, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
MeshVertexPosition(0, 0, 0)
MeshVertexPosition(0, 0, 0)
MeshVertexPosition(0, 0, 0)
MeshFace(0, 1, 2)
FinishMesh(0)

UpdateMesh(m, 0)
MeshVertexPosition(0, 0, 0)
MeshVertexTextureCoordinate(0, 0)         ;<--- no effect ?
MeshVertexColor(RGBA(255, 255, 255, 255)) ;<--- no effect ?

MeshVertexPosition(w, 0, 0)
MeshVertexTextureCoordinate(1, 0)
MeshVertexColor(RGBA(255, 255, 255, 255))

MeshVertexPosition(w, h, 0)
MeshVertexTextureCoordinate(1, 1)
MeshVertexColor(RGBA(255, 255, 255, 255))

MeshVertexPosition(0, h, 0)
MeshVertexTextureCoordinate(0, 1)
MeshVertexColor(RGBA(255, 255, 255, 255))

MeshFace(0, 1, 2)
MeshFace(2, 3, 0)
FinishMesh(0)

e=CreateNode(#PB_Any, 0, 0, 500)
AttachNodeObject(e, MeshID(m))
SetMeshMaterial(m, MaterialID(mat))

posX.f=1.0
posY.f=1.0
MoveNode(e, (-ScreenWidth()/2.0+posX)*zx, (-ScreenHeight()/2.0+posY)*zy, 0)
ScaleNode(e, zx, zy, 1)

Repeat
   RenderWorld()
   FlipBuffers()
Until WaitWindowEvent(1)=#PB_Event_CloseWindow
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: PB5.2b9 - Dynamic Mesh : no UV and COLOR updates

Post by Comtois »

UpdateMesh() don't add uv and color. It should be done when you create for the first time your mesh.
the definition of the first vertex is used for all vertices, so you can create your mesh like this, and all vertices will have the UV and color available

Code: Select all

m=CreateMesh(#PB_Any, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
MeshVertexPosition(0, 0, 0)
MeshVertexTextureCoordinate(0, 0)         
MeshVertexColor(RGBA(0, 0, 0, 0))
MeshVertexPosition(0, 0, 0)
MeshVertexPosition(0, 0, 0)
MeshFace(0, 1, 2)
FinishMesh(0)
Please correct my english
http://purebasic.developpez.com/
Post Reply