Point Sprites with multi textures ??

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

Point Sprites with multi textures ??

Post by applePi »

i am preparing a very basic and short examples about how to plot 3d to publish it in this forum for the usage of new users and the users who have not yet tried to plot their 3d curves using purebasic. i reached the example to use point sprites, the point is i want to plot points as banana if y >= 0 and as flower if y < 0, i don't see how to do that, it is either a flower or banana. ie not like normal points in which we can plot red or blue etc as needed. the only way i see to do that is to create 2 overlapping entities which having different textures for point sprites

use the following transparent pictures (enlarge it before saving), the material file "PointSprites.material" , put all in the same folder with the code
Image
Image

PointSprites.material

Code: Select all

material PointsSprites
{
   technique
   {
      pass
      {
         cull_hardware none
         cull_software none
         scene_blend alpha_blend
         lighting on
         
         diffuse 1 1 1 1
         ambient 1 1 1 1
         specular 1 1 1 1
         emissive 1 1 1 1
         
         point_sprites on
         point_size 30
         //point_size_min 2.0
         //point_size_max 256.0
         
         depth_write off
         depth_check on
         
         depth_func less_equal
         
         //point_size_attenuation on 1.0 0.0 3.5
         
         texture_unit
         {
            filtering anisotropic
            max_anisotropy 16
            texture rose.png
         }
      }
   }
}

Code: Select all

Declare Plot3D()

Enumeration
  #mainwin
  #mesh
  #entity
  #tex
  #light
  #camera
EndEnumeration

InitEngine3D()
InitSprite()

ExamineDesktops()
OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "How to Plot3D .... press space to toggle rotation ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
InitKeyboard()
InitMouse()
SetFrameRate(60)

Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
;Add3DArchive("Data/", #PB_3DArchive_FileSystem)
Parse3DScripts()

CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 2, 14 )
CameraLookAt(#camera, 0, 0, 0)

CreateLight(#light,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(255,255,255))

GetScriptMaterial(#tex, "PointsSprites")
SetMeshMaterial(#tex, MaterialID(#tex))
;MaterialCullingMode(#tex, #PB_Material_NoCulling)
;DisableMaterialLighting(#tex, #True)

CreateMesh(#mesh, #PB_Mesh_PointList, #PB_Mesh_Static)
SetMeshMaterial(#mesh, MaterialID(#tex))


Plot3D() ;calling the drawing routine

temp = 1
Repeat
  Event = WindowEvent()
  ExamineKeyboard()
      
  If KeyboardReleased(#PB_Key_Space)  
    temp ! 1
    
  EndIf
  
  roty - temp  ;roty-temp: roty-temp
  
  RotateEntity(#entity, 0, roty, 0,#PB_Absolute)
   
   RenderWorld()
   FlipBuffers()  

Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow

;main drawing routine
Procedure Plot3D()
  
  incr.f = 1
  Zmin.f = -5: Zmax.f = 5: Xmin = -5: Xmax = 5
  z.f = Zmin: x.f = Xmin
  While z <= Zmax - 1
    
    While x <= Xmax - 1
      
        y.f = ATan ((z*z*z)/4 - (x*x))
         
        MeshVertexPosition(x, y, z)
         
        x + incr        
        Wend
       
    x = Xmin
    
    z + incr
  Wend
        NormalizeMesh(#mesh)
        FinishMesh(#True)
        CreateEntity(#entity, MeshID(#mesh), MaterialID(#tex))
        ;ScaleEntity(#entity,1/2,1/2,1/2) ; decrease the curve size
  
EndProcedure
if you want to try the code which uses 2 entities, use the following points.material in addition to the above one

Code: Select all

material PointsSprites_banana
{
   technique
   {
      pass
      {
         cull_hardware none
         cull_software none
         scene_blend alpha_blend
         lighting on
         
         diffuse 1 1 1 1
         ambient 1 1 1 1
         specular 1 1 1 1
         emissive 1 1 1 1
         
         point_sprites on
         point_size 30
         //point_size_min 2.0
         //point_size_max 256.0
         
         depth_write off
         depth_check on
         
         depth_func less_equal
         
         //point_size_attenuation on 1.0 0.0 3.5
         
         texture_unit
         {
            filtering anisotropic
            max_anisotropy 16
            texture banana.png
         }
      }
   }
}
the code

Code: Select all

Declare Plot3D()
Declare Plot3D_2()

Enumeration
  #mainwin
  #mesh
  #mesh2
  #entity
  #entity2
  #tex
  #tex2
  #light
  #camera
EndEnumeration

;Initialize environment
InitEngine3D()
InitSprite()

ExamineDesktops()
OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "How to Plot3D ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
InitKeyboard()
InitMouse()
SetFrameRate(60)

Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
;Add3DArchive("Data/", #PB_3DArchive_FileSystem)
Parse3DScripts()

CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 2, 14 )
CameraLookAt(#camera, 0, 0, 0)

CreateLight(#light,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(255,255,255))

GetScriptMaterial(#tex, "PointsSprites")
SetMeshMaterial(#tex, MaterialID(#tex))
GetScriptMaterial(#tex2, "PointsSprites_banana")
SetMeshMaterial(#tex2, MaterialID(#tex2))

;CreateMesh(#mesh, #PB_Mesh_PointList, #PB_Mesh_Dynamic)
CreateMesh(#mesh, #PB_Mesh_PointList, #PB_Mesh_Static)
SetMeshMaterial(#mesh, MaterialID(#tex))

Plot3D() ;calling the drawing routine
CreateMesh(#mesh2, #PB_Mesh_PointList, #PB_Mesh_Static)
SetMeshMaterial(#mesh2, MaterialID(#tex2))
Plot3D_2()

temp = 1
Repeat
  Event = WindowEvent()
  ExamineKeyboard()
      
  If KeyboardReleased(#PB_Key_Space)  
    temp ! 1
    
  EndIf
  
  roty - temp : ;roty-temp: roty-temp
  
  RotateEntity(#entity, 0, roty, 0,#PB_Absolute)
  RotateEntity(#entity2, 0, roty, 0,#PB_Absolute)
   
   RenderWorld()
   FlipBuffers()  

Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow

;main drawing routine
Procedure Plot3D()
  incr.f = 1
  Zmin.f = -5: Zmax.f = 5: Xmin = -5: Xmax = 5
  z.f = Zmin: x.f = Xmin
  While z <= Zmax - 1
    
    While x <= Xmax - 1
      
      y.f = ATan ((z*z*z)/4 - (x*x))
      
      If y <= 0
         
        MeshVertexPosition(x, y, z)
       
       EndIf   
        x + incr        
        Wend
       
    x = Xmin
    z + incr
  Wend
        NormalizeMesh(#mesh)
        FinishMesh(#True)
        CreateEntity(#entity, MeshID(#mesh), MaterialID(#tex))
        ;ScaleEntity(#entity,1/2,1/2,1/2) ; decrease the curve size
  
      EndProcedure
      
  Procedure Plot3D_2()
  
  incr.f = 1
  Zmin.f = -5: Zmax.f = 5: Xmin = -5: Xmax = 5
  z.f = Zmin: x.f = Xmin
  While z <= Zmax - 1
    
    While x <= Xmax - 1
      
      y.f = ATan ((z*z*z)/4 - (x*x))
      
      If y > 0
         
        MeshVertexPosition(x, y, z)
        
       EndIf   
          
        x + incr        
        Wend
       
    x = Xmin
    z + incr
  Wend
        NormalizeMesh(#mesh2)
        FinishMesh(#True)
        CreateEntity(#entity2, MeshID(#mesh2), MaterialID(#tex2))
        ;ScaleEntity(#entity,1/2,1/2,1/2) ; decrease the curve size
  
EndProcedure

User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Point Sprites with multi textures ??

Post by Samuel »

I don't know if it's possible to set multiple textures directly to a point sprite mesh.
What you can do is create sub meshes and add the textures to them. So, you would still have the ease of one entity with just a couple extra sub meshes.
Here's a little example I put together using your code and materials.

First the new script. It contains both of the required material scripts.

Code: Select all

material PointsSprites
{
   technique
   {
      pass
      {
         cull_hardware none
         cull_software none
         scene_blend alpha_blend
         lighting on
         
         diffuse 1 1 1 1
         ambient 1 1 1 1
         specular 1 1 1 1
         emissive 1 1 1 1
         
         point_sprites on
         point_size 30
         //point_size_min 2.0
         //point_size_max 256.0
         
         depth_write off
         depth_check on
         
         depth_func less_equal
         
         //point_size_attenuation on 1.0 0.0 3.5
         
         texture_unit
         {
            filtering anisotropic
            max_anisotropy 16
            texture rose.png
         }
      }
   }
}

material PointsSprites2
{
   technique
   {
      pass
      {
         cull_hardware none
         cull_software none
         scene_blend alpha_blend
         lighting on
         
         diffuse 1 1 1 1
         ambient 1 1 1 1
         specular 1 1 1 1
         emissive 1 1 1 1
         
         point_sprites on
         point_size 30
         //point_size_min 2.0
         //point_size_max 256.0
         
         depth_write off
         depth_check on
         
         depth_func less_equal
         
         //point_size_attenuation on 1.0 0.0 3.5
         
         texture_unit
         {
            filtering anisotropic
            max_anisotropy 16
            texture banana.png
         }
      }
   }
}
Now the new code to run the scripts.

Code: Select all

Declare Plot3D()

Enumeration
  #mainwin
  #mesh
  #entity
  #tex
  #subtex
  #light
  #camera
EndEnumeration

InitEngine3D()
InitSprite()

ExamineDesktops()
OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "How to Plot3D .... press space to toggle rotation ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
InitKeyboard()
InitMouse()
SetFrameRate(60)

Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
;Add3DArchive("Data/", #PB_3DArchive_FileSystem)
Parse3DScripts()

CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 2, 14 )
CameraLookAt(#camera, 0, 0, 0)

CreateLight(#light,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(255,255,255))

GetScriptMaterial(#tex, "PointsSprites")

;#### Load The Material Script For The Banana ####
GetScriptMaterial(#subtex, "PointsSprites2")


CreateMesh(#mesh, #PB_Mesh_PointList, #PB_Mesh_Static)
SetMeshMaterial(#mesh, MaterialID(#tex))


Plot3D() ;calling the drawing routine


;#### Set SubMesh Material To The Banana ####
SetEntityMaterial(#entity,MaterialID(#subtex),1)

temp = 1
Repeat
  Event = WindowEvent()
  ExamineKeyboard()
     
  If KeyboardReleased(#PB_Key_Space) 
    temp ! 1
   
  EndIf
 
  roty - temp  ;roty-temp: roty-temp
 
  RotateEntity(#entity, 0, roty, 0,#PB_Absolute)
   
   RenderWorld()
   FlipBuffers() 

Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow

;main drawing routine
Procedure Plot3D()
 
  incr.f = 1
  Zmin.f = -5: Zmax.f = 5: Xmin = -5: Xmax = 5
  z.f = Zmin: x.f = Xmin
  While z <= Zmax - 1
   
    While x <= Xmax - 1
     
        y.f = ATan ((z*z*z)/4 - (x*x))
         
        MeshVertexPosition(x, y, z)
         
        x + incr       
        Wend
       
    x = Xmin
   
    z + incr
  Wend
  ;#### Add Submesh For The Banana Material ####
  AddSubMesh(#PB_Mesh_PointList)
  MeshVertexPosition(5, 2, 6)
  MeshVertexPosition(-5, 2, 6)
  MeshVertexPosition(1, 0, 0)
  MeshVertexPosition(-1, 0, 0)
  
        NormalizeMesh(#mesh)
        FinishMesh(#True)
        
        CreateEntity(#entity, MeshID(#mesh), MaterialID(#tex))
        ;ScaleEntity(#entity,1/2,1/2,1/2) ; decrease the curve size
 
EndProcedure
This is the only way I can think of to add multiple textures to point sprites.
Maybe someone else knows of a more efficient way of doing this.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Point Sprites with multi textures ??

Post by applePi »

thank you Samuel very much, yes your suggestion solves the problem. i have replaced your points with the points under condition y >= 0 to plot banana. so we have two loops one for the flowers and one for the banana. it seems to me that we can't use (for the point sprites) one loop which have something like

Code: Select all

y.f = ATan ((z*z*z)/4 - (x*x))
      If y < 0  ; plot flowers
         MeshVertexPosition(x, y, z)
       Else  ; plot banana
        ; some function to reset the pointer to the submesh
        MeshVertexPosition(x, y, z)
      EndIf 

Code: Select all

Declare Plot3D()

Enumeration
  #mainwin
  #mesh
  #entity
  #tex
  #subtex
  #light
  #camera
EndEnumeration

InitEngine3D()
InitSprite()

ExamineDesktops()
OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "How to Plot3D .... press space to toggle rotation ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
InitKeyboard()
InitMouse()
SetFrameRate(60)

Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
;Add3DArchive("Data/", #PB_3DArchive_FileSystem)
Parse3DScripts()

CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 2, 14 )
CameraLookAt(#camera, 0, 0, 0)

CreateLight(#light,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(255,255,255))

GetScriptMaterial(#tex, "PointsSprites")

;#### Load The Material Script For The Banana ####
GetScriptMaterial(#subtex, "PointsSprites2")


CreateMesh(#mesh, #PB_Mesh_PointList, #PB_Mesh_Static)
;SetMeshMaterial(#mesh, MaterialID(#tex))


Plot3D() ;calling the drawing routine


;#### Set SubMesh Material To The Banana ####
SetEntityMaterial(#entity,MaterialID(#subtex),1)

temp = 1
Repeat
  Event = WindowEvent()
  ExamineKeyboard()
     
  If KeyboardReleased(#PB_Key_Space) 
    temp ! 1
   
  EndIf
 
  roty - temp 
 
  RotateEntity(#entity, 0, roty, 0,#PB_Absolute)
   
   RenderWorld()
   FlipBuffers() 

Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow

;main drawing routine
Procedure Plot3D()
 
  incr.f = 1
  Zmin.f = -5: Zmax.f = 5: Xmin = -5: Xmax = 5
  z.f = Zmin: x.f = Xmin
  While z <= Zmax - 1
    While x <= Xmax - 1
      y.f = ATan ((z*z*z)/4 - (x*x))
      If y < 0
        MeshVertexPosition(x, y, z)
      EndIf 
        x + incr       
        Wend
    x = Xmin
    z + incr
  Wend
  
  ;#### Add Submesh For The Banana Material ####
  AddSubMesh(#PB_Mesh_PointList)
  
  z.f = Zmin: x.f = Xmin
  While z <= Zmax - 1
    While x <= Xmax - 1
      y.f = ATan ((z*z*z)/4 - (x*x))
      If y >= 0
        MeshVertexPosition(x, y, z)
      EndIf 
        x + incr       
        Wend
    x = Xmin
    z + incr
  Wend
  
        NormalizeMesh(#mesh)
        FinishMesh(#True)
        
        CreateEntity(#entity, MeshID(#mesh), MaterialID(#tex))
        ;ScaleEntity(#entity,1/2,1/2,1/2) ; decrease the curve size
 
EndProcedure
regards
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Point Sprites with multi textures ??

Post by applePi »

i got this beautiful l animation for the flowers and bananas curve, just using the same animation equation used here http://www.purebasic.fr/english/viewtop ... shMaterial
the animation have done twice one for the main mesh and the other for the submesh number 1.
Image

copy the 2 pictures above of the rose and the banana (after enlarging it) with the material file below and the code to the same folder
here is again the material file ( thanks for Samuel )
pointSprites.material

Code: Select all

material PointsSprites
{
   technique
   {
      pass
      {
         cull_hardware none
         cull_software none
         scene_blend alpha_blend
         lighting on
         
         diffuse 1 1 1 1
         ambient 1 1 1 1
         specular 1 1 1 1
         emissive 1 1 1 1
         
         point_sprites on
         point_size 30
         //point_size_min 2.0
         //point_size_max 256.0
         
         depth_write off
         depth_check on
         
         depth_func less_equal
         
         //point_size_attenuation on 1.0 0.0 3.5
         
         texture_unit
         {
            filtering anisotropic
            max_anisotropy 16
            texture rose.png
         }
      }
   }
}

material PointsSprites2
{
   technique
   {
      pass
      {
         cull_hardware none
         cull_software none
         scene_blend alpha_blend
         lighting on
         
         diffuse 1 1 1 1
         ambient 1 1 1 1
         specular 1 1 1 1
         emissive 1 1 1 1
         
         point_sprites on
         point_size 30
         //point_size_min 2.0
         //point_size_max 256.0
         
         depth_write off
         depth_check on
         
         depth_func less_equal
         
         //point_size_attenuation on 1.0 0.0 3.5
         
         texture_unit
         {
            filtering anisotropic
            max_anisotropy 16
            texture banana.png
         }
      }
   }
}
code

Code: Select all

Declare Plot3D()
Declare UpdateMatrix()
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)

Enumeration
  #mainwin
  #mesh
  #entity
  #tex
  #subtex
  #light
  #camera
EndEnumeration

InitEngine3D()
InitSprite()

ExamineDesktops()
OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "point sprites.. press space to toggle rotation, ....Up key to toggle animation ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
InitKeyboard()
InitMouse()
SetFrameRate(60)

Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
;Add3DArchive("Data/", #PB_3DArchive_FileSystem)
Parse3DScripts()

CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 2, 14 )
CameraLookAt(#camera, 0, 0, 0)

CreateLight(#light,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(255,255,255))

GetScriptMaterial(#tex, "PointsSprites")

;#### Load The Material Script For The Banana ####
GetScriptMaterial(#subtex, "PointsSprites2")


CreateMesh(#mesh, #PB_Mesh_PointList, #PB_Mesh_Dynamic)
;SetMeshMaterial(#mesh, MaterialID(#tex))


Plot3D() ;calling the drawing routine


;#### Set SubMesh Material To The Banana ####
SetEntityMaterial(#entity,MaterialID(#subtex),1)

temp = 1
Repeat
  Event = WindowEvent()
  ExamineKeyboard()
  
  If KeyboardPushed(#PB_Key_Right)
          x + 0.4 :UpdateMatrix()
        ElseIf KeyboardPushed(#PB_Key_Left) 
          x - 0.4 :UpdateMatrix()
  EndIf
  
  If KeyboardReleased(#PB_Key_Z) 
    ;GetMeshData(#mesh, 0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#mesh,0)-1)
    ;MeshData(6)\y= -3 : MeshData(8)\y= 3
    ;SetMeshData(#mesh,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#mesh,0)-1)
    y.f=Sin(Radian((AngleVague+a*WavePeriodX+b*WavePeriodZ)))*WaveAmplitude 
    GetMeshData(#mesh, 1, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#mesh,1)-1)
    MeshData(10)\y= 3 : MeshData(12)\y= 4
    SetMeshData(#mesh,1, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#mesh,1)-1)
    
  EndIf
  
  
  If KeyboardReleased(#PB_Key_Up) 
    animate ! 1
  EndIf  
  
  If animate = 0
      UpdateMatrix() ; to animate the curve
  EndIf
  
  ;UpdateMatrix() ; to animate the curve
  
  If KeyboardReleased(#PB_Key_Space) 
    temp ! 1
  EndIf
  roty - temp 
  RotateEntity(#entity, 0, roty/2, 0,#PB_Absolute)
     
   RenderWorld()
   FlipBuffers() 

Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow

;main drawing routine
Procedure Plot3D()
 
  incr.f = 0.5 ; change this to decrease or increase the vertices
  Zmin.f = -5: Zmax.f = 5: Xmin = -5: Xmax = 5
  z.f = Zmin: x.f = Xmin
  While z <= Zmax - 1
    While x <= Xmax - 1
      y.f = ATan ((z*z*z)/4 - (x*x))
      If y < 0
        MeshVertexPosition(x, y, z)
        
      EndIf 
      x + incr       
    Wend
    x = Xmin
    z + incr
  Wend
  
  ;#### Add Submesh For The Banana Material ####
  AddSubMesh(#PB_Mesh_PointList) ; its number will be (1)
  
  z.f = Zmin: x.f = Xmin
  While z <= Zmax - 1
    While x <= Xmax - 1
      y.f = ATan ((z*z*z)/4 - (x*x))
      If y >= 0
        MeshVertexPosition(x, y, z)
        
      EndIf 
        x + incr       
    Wend
    x = Xmin
    z + incr
  Wend
  
NormalizeMesh(#mesh)
FinishMesh(#True)
        
CreateEntity(#entity, MeshID(#mesh), MaterialID(#tex))
   
  EndProcedure
  
  Procedure UpdateMatrix() ; for animation of the vertices
     
    GetMeshData(#mesh, 0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#mesh,0)-1)
    ArrSize = ArraySize(MeshData())
    dtime.f=ElapsedMilliseconds()/600 ; reduce 600 to get speedier animation
    
    For a=0 To ArrSize
      xa.f=MeshData(c)\x
      zb.f=MeshData(c)\z
      
      MeshData(c)\y=Cos(dtime + (Sqr(Pow(0.5*xa,2)+Pow(0.5*zb,2))))*2
      c + 1 ; vertex number
      
    Next a
   
  SetMeshData(#mesh,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#mesh,0)-1)
  
  
  ;animation of the submesh; note the submesh number (1)
  c=0  
    GetMeshData(#mesh, 1, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#mesh,1)-1)
    ArrSize = ArraySize(MeshData())
    dtime.f=ElapsedMilliseconds()/600 ; reduce 600 to get speedier animation
    
    For a=0 To ArrSize
      xa.f=MeshData(c)\x
      zb.f=MeshData(c)\z
      
      MeshData(c)\y=Cos(dtime + (Sqr(Pow(0.5*xa,2)+Pow(0.5*zb,2))))*2
      c + 1 ; vertex number
      
    Next a
   
  SetMeshData(#mesh,1, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#mesh,1)-1)
  
  EndProcedure
  
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Point Sprites with multi textures ??

Post by Samuel »

Good job applePi. It's a very nice looking example.
Post Reply