Point Sprites with multi textures ??
Posted: Thu Nov 21, 2013 8:21 pm
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


PointSprites.material
if you want to try the code which uses 2 entities, use the following points.material in addition to the above one
the code
use the following transparent pictures (enlarge it before saving), the material file "PointSprites.material" , put all in the same folder with the code


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
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
}
}
}
}
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