Page 2 of 2

Re: experiment with water

Posted: Thu Jun 05, 2014 9:40 pm
by applePi
thats certainly big contribution, thanks, we can make niagara water falls simulation .
i'm trying to go around the waterfall, but still can't go around it exactly, the waterfall follow the camera, i will flatten the code to be compatible with my Flat one track only brain :) but not now.
use the mouse and keys to try going around, or to have a bath under the waterfall. until it is corrected.

Code: Select all

;First simple try to mimic splashing water....

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

UsePNGImageDecoder()

Add3DArchive("textures",#PB_3DArchive_FileSystem)
Add3DArchive("scripts", #PB_3DArchive_FileSystem)


DeclareModule WaterWorld
    
  Declare.i SetResolution(Width.i, Height.i, FullScreen.i = #False)
  Declare.i RunWaterWorld()
  
EndDeclareModule

Module WaterWorld
  ;IncludeFile #PB_Compiler_Home + "Examples/3D/Screen3DRequester.pb"
  
  Structure mainVars
    Win.i
    Scr.i
    FS.i
    Cam.i
    Quit.i
    lgt.i
    lgt2.i
  EndStructure
  
  Structure EntityVars
    id.i
    mes.i
    mat.i
    tex.i
  EndStructure
  
  Global va.mainVars
  
  Declare.i MakePart()
  Declare.i MakePlasticWater()
  
  Global foam1.EntityVars
  Global foam2.EntityVars
  Global foam3.EntityVars
  Global wat.EntityVars
  
  Procedure.i MakePart()
    foam1\id = GetScriptParticleEmitter(#PB_Any, "waterfosset")
    foam2\id = GetScriptParticleEmitter(#PB_Any, "Watercircles")
    foam3\id = GetScriptParticleEmitter(#PB_Any, "waterbounce")
  EndProcedure
  
  Procedure.i MakePlasticWater() 
    Protected extratex.i
    extratex = LoadTexture(#PB_Any, "water1.png")
    wat\mes = CreatePlane(#PB_Any, 1024, 1024, 10, 10, 1, 1)
    wat\tex = LoadTexture(#PB_Any, "bwater.png")
    wat\mat = CreateMaterial(#PB_Any, TextureID(wat\tex))
    MaterialBlendingMode(wat\mat, #PB_Material_AlphaBlend)
    AddMaterialLayer(wat\mat, TextureID(extratex), #PB_Material_Color)
    RotateMaterial(wat\mat, -0.01,#PB_Material_Animated,0)
    ScrollMaterial(wat\mat, 0.01, -0.01, #PB_Material_Animated, 1)
    wat\id = CreateEntity(#PB_Any, MeshID(wat\mes), MaterialID(wat\mat), 0, -30, 0)
    ProcedureReturn 0
  EndProcedure
  
  Procedure.i SetResolution(Width.i, Height.i, FullScreen.i = #False)
    va\FS = FullScreen
    Select FullScreen
      Case #False ;Windowed
        va\Win = OpenWindow(#PB_Any, 0, 0, Width, Height, "WaterWorld", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
        va\Scr = OpenWindowedScreen(WindowID(va\Win), 0, 0, Width, Height, #False, 0, 0, #PB_Screen_SmartSynchronization)
      Default
        va\Scr = OpenScreen(Width, Height, 32, "Waterworld", #PB_Screen_SmartSynchronization, 60)
    EndSelect
    va\Cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
    MoveCamera(va\Cam, 0, 55, 150)

    va\lgt = CreateLight(#PB_Any, $EEEEEE, 0, 1000, -3000, #PB_Light_Directional)
    LightDirection(va\lgt, 1, -1, 0)
  EndProcedure
  
  
  Procedure.i RunWaterWorld()
    Protected Quit.i = 0
    Protected CameraSpeed = 3
    Protected KeyX.f, KeyY.f, MouseX.f, MouseY.f
    Parse3DScripts()
    ret = MakePart()
    ret = MakePlasticWater()
    
    
    Repeat
      ;Screen3DEvents()  
      If ExamineMouse()
          MouseX.f = -MouseDeltaX() * CameraSpeed * 0.05
          MouseY.f = -MouseDeltaY() * CameraSpeed * 0.05
        EndIf
        
        ExamineKeyboard()
        If KeyboardPushed(#PB_Key_Left)
            KeyX.f = -CameraSpeed
          ElseIf KeyboardPushed(#PB_Key_Right)
            KeyX.f = CameraSpeed
          Else
            KeyX.f = 0
          EndIf
          
        If KeyboardPushed(#PB_Key_Up)
            KeyY = -CameraSpeed
          ElseIf KeyboardPushed(#PB_Key_Down)
            KeyY = CameraSpeed
          Else
            KeyY = 0
          EndIf  
        
      If va\FS = #False
        Repeat
          ev = WindowEvent()
          If ev = #PB_Event_CloseWindow
            Quit = 1
          EndIf
        Until ev = 0
      EndIf
      
      
      RotateCamera(va\Cam, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (va\Cam, KeyX, 0, KeyY)
      
      RenderWorld()
      
      FlipBuffers()

    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
  EndProcedure
  
  
EndModule



WaterWorld::SetResolution(800, 600, #False)
WaterWorld::RunWaterWorld()



Re: experiment with water

Posted: Fri Jun 06, 2014 3:26 pm
by DK_PETER
EDIT: 18:08.

@ApplePi and Bananenfreak

Glad you both liked it. Since the emitter uses billboard, it will always face the camera, hence giving a weird camera/particle movement illusion..
In my next attempt I'm gonna try a different method... (I'm in the process of using planes together with particles).
I hope the AttachEntityObject() will be fixed soon.

Anyway...Here's the link to my third attempt.

Project removed..

Re: experiment with water

Posted: Fri Jun 06, 2014 7:50 pm
by Samuel
Nice example, DK_PETER.

You could also give the waterfall a deflector plane for a sort of splash effect.


waterfosset.particle

Code: Select all


particle_system waterfosset
{
	quota	10000
	material	PE/lensflare2
	particle_width	5
	particle_height	9
	cull_each	False
	renderer	billboard
	billboard_type	oriented_common

	emitter Point
	{
		angle	60
		colour	0 0 1 1
		colour_range_start 0 0 0.02 1
		colour_range_end   0 0 1    1
		direction -1 1 0
		emission_rate 2000
		position -340 376 -450
		velocity 8
		velocity_min 8
		velocity_max 18
		time_to_live 3.5
		time_to_live_min 3.5
		time_to_live_max 3.6
		duration 0
		duration_min 0
		duration_max 0
		repeat_delay 0
		repeat_delay_min 0
		repeat_delay_max 0
	}

	affector LinearForce
	{
		force_vector 0 -200 0
		force_application add
	}

	affector DeflectorPlane
	{
		plane_point	0 -30 0
		plane_normal	0 1 0
		bounce	0.15
	}
	affector DirectionRandomiser
	{
		randomness	90
	}
}

Re: experiment with water

Posted: Fri Jun 06, 2014 8:46 pm
by applePi
thanks DK_PETER for the interesting scenes and codes and ideas, regarding your first example "water_test_1" in the previous page, i want to say it is resembling a real waterFall too much and can be used for some sorts of scenes, also as a comet in the sky, but i have noticed this phenomena :it is by loading a robot mesh then attach the particleEmitter to it then rotate the robot so the water flow will rotate around it falling to the sea in a helical shape, the values of force, directions, positions in the waterfosset.particle are suitable with the robot rotation and position so they generate a helical water fall
i have noticed that we can't use mesh without a bone, this why i have used the robot from example AttachEntityObject2.pb in 3D examples. ie i can't use a sphere. so is this a bug ?.
to see the helical water fall shape press the Left key continuously, of course save the code to the folder of the code posted by DK_PETER in the previous page "water_test_1".
i forgot to say that while testing the first example i have Flattened it by one level, i need more time before be comfortable with Module .

Image

press Left key to generate the helical water fall:

Code: Select all

;First simple try to mimic splashing water....
#CameraSpeed = 1

Define.f KeyX, KeyY, MouseX, MouseY, Speed = 1.0
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

UsePNGImageDecoder()

Add3DArchive("textures",#PB_3DArchive_FileSystem)
Add3DArchive("scripts", #PB_3DArchive_FileSystem)
Add3DArchive("\", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Models", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
    
    
 Declare.i SetResolution(Width.i, Height.i, FullScreen.i = #False)
 Declare.i RunWaterWorld()

  ;IncludeFile #PB_Compiler_Home + "Examples/3D/Screen3DRequester.pb"
  
  Structure mainVars
    Win.i
    Scr.i
    FS.i
    Cam.i
    Quit.i
    lgt.i
    lgt2.i
  EndStructure
  
  Structure EntityVars
    id.i
    mes.i
    mat.i
    tex.i
  EndStructure
  
  Global va.mainVars
  
  Declare.i MakePart()
  Declare.i MakePlasticWater()
  
  Global foam1.EntityVars
  Global foam2.EntityVars
  Global foam3.EntityVars
  Global wat.EntityVars
    
  Procedure.i MakePart()
    foam1\id = GetScriptParticleEmitter(#PB_Any, "waterfosset")
    foam2\id = GetScriptParticleEmitter(#PB_Any, "Watercircles")
    foam3\id = GetScriptParticleEmitter(#PB_Any, "waterbounce")
  EndProcedure
  
  Procedure.i MakePlasticWater() 
    Protected extratex.i
    extratex = LoadTexture(#PB_Any, "water1.png")
    wat\mes = CreatePlane(#PB_Any, 800, 800, 10, 10, 1, 1)
    wat\tex = LoadTexture(#PB_Any, "bwater.png")
    wat\mat = CreateMaterial(#PB_Any, TextureID(wat\tex))
    MaterialBlendingMode(wat\mat, #PB_Material_AlphaBlend)
    AddMaterialLayer(wat\mat, TextureID(extratex), #PB_Material_Color)
    RotateMaterial(wat\mat, -0.01,#PB_Material_Animated,0)
    ScrollMaterial(wat\mat, 0.01, -0.01, #PB_Material_Animated, 1)
    wat\id = CreateEntity(#PB_Any, MeshID(wat\mes), MaterialID(wat\mat), 0, -30, 0)
    
    ProcedureReturn 0
  EndProcedure
  
  Procedure.i SetResolution(Width.i, Height.i, FullScreen.i = #False)
    va\FS = FullScreen
    Select FullScreen
      Case #False ;Windowed
        va\Win = OpenWindow(#PB_Any, 0, 0, Width, Height, "WaterWorld", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
        va\Scr = OpenWindowedScreen(WindowID(va\Win), 0, 0, Width, Height, #False, 0, 0, #PB_Screen_SmartSynchronization)
      Default
        va\Scr = OpenScreen(Width, Height, 32, "Waterworld", #PB_Screen_SmartSynchronization, 60)
    EndSelect
    va\Cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
    MoveCamera(va\Cam, -30, 100, 100)
    CameraLookAt(va\Cam, -35, 50,20)

    va\lgt = CreateLight(#PB_Any, $EEEEEE, 0, 1000, -3000, #PB_Light_Directional)
    LightDirection(va\lgt, 1, -1, 0)
    
  EndProcedure
  
  
  Procedure.i RunWaterWorld()
    Protected Quit.i = 0
    Parse3DScripts()
    ret = MakePart()
    ret = MakePlasticWater()
    ;CreateSphere(12,1)
    LoadMesh(12, "robot.mesh")
    CreateEntity(12, MeshID(12), #PB_Material_None, -32, 50, 20)
    ScaleEntity(12, 0.1,0.1,0.1)
    AttachEntityObject(12, "Joint18", ParticleEmitterID(foam1\id), 0, 10, 20, 0, 0, 0) 
    
    Repeat
      ;Screen3DEvents()  
      If ExamineMouse()
          MouseX.f = -MouseDeltaX() * #CameraSpeed * 0.05
          MouseY.f = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
        
        
        ExamineKeyboard()
        If KeyboardPushed(#PB_Key_Left)
          
          RotateEntity(12, 0, 10, 0, #PB_Relative)
          
          ;KeyX = -#CameraSpeed 
        ;ElseIf KeyboardPushed(#PB_Key_Right)
          ;KeyX = #CameraSpeed 
        ;Else
          ;KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf
        
      If va\FS = #False
        Repeat
          ev = WindowEvent()
          If ev = #PB_Event_CloseWindow
            Quit = 1
          EndIf
        Until ev = 0
      EndIf
      
      
      RotateCamera(va\Cam, MouseY, MouseX, 0, #PB_Relative)
      
      MoveCamera  (va\Cam, KeyX, 0, KeyY)
      
      RenderWorld()
      
      FlipBuffers()

    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
  EndProcedure


  SetResolution(800, 600, #False)
  
RunWaterWorld()

Re: experiment with water

Posted: Fri Jun 06, 2014 9:35 pm
by DK_PETER
@Samuel
Thanks..It actually looks better. Good idea. ;-)

ApplePi. You just do what you're most comfortable with. You just flatten away :-)

The AttachEntityObject() has a bug, when dealing with particles. It has been reported twice
and I'm pretty sure, that they are at it again to fix the problem.

I'll continue to 'fiddle' with particles and planes.

Here's a small gift for all of you, if you're interested:
It's some of my creations I use for testing.

https://www.dropbox.com/s/kgx028lpbzchq ... MODELS.rar

If you find some use for them ---- then that's good.
Content:
uboat.mesh
BorgSphere.mesh
BorgCube.mesh
BorgCylinder.mesh
Gazebo.mesh
walkway.mesh
cata.mesh

Re: experiment with water

Posted: Sat Jun 07, 2014 6:37 am
by applePi
i like the cube and the Gazebo , i guess the texture of the cube is electronic components like that in the motherboard , what do you do to edit these meshes, or is it saved in other formats such as obj, 3ds,..., and then converted to *.mesh with OgreAssimpConverter which do an excellent job. i have buyed recently deepmesh but it can't import most *.mesh files even it is good for other types and can export to Ogre xml which can be converted to *.mesh files with OgreXMLConverter .

Re: experiment with water

Posted: Mon Jun 09, 2014 12:31 am
by DK_PETER
Hey again..

Requires: PB 5.30!!!!

I've been working some more on the island.
It's work in progress and requires a lot of finetuning: especially 3D.
Right now it looks like something like minecraft :-)
So the next few days will go exclusively to 3D modeling..

project removed...

Again: have fun and dive :-)