I found this in the ogre Wiki,
is there a chance to do this from PB, and if so, how exactly would i do that ?
Thanks & regards
Can I load raw height maps without using an image?
A. Yes
Terrain::ImportData imp;
imp.terrainSize = 513;
imp.worldSize = 12000;
imp.inputScale = 1.0;
imp.inputFloat = pRawFloats;
terrain->prepare(imp);
Basically, the new terrain doesn't need to use Image to load the height data, that's just a convenience. It far prefers it if you just give it a list of unscaled floats!
If your floats are just in a flat file, it's easy:
MemoryDataStream rawFloats(ResourceGroupManager::getSingleton().openResource(filename, groupName));
imp.inputFloat = (float*)rawFloats.getPtr();
Be aware though of endian issues when you're using raw files like this. This file will only work if saved / loaded on machines of the same endianness (this applies to Myrddin too).
Basically we don't do this via a filename because it's far more flexible just to accept packaged data like this, the float data can come from anywhere. Also, you can load / construct / modify it in a background thread and even call prepare() in a background thread so the entire terrain can be bootstrapped without blocking. Again, I would expect you only to do it this way at import time, the prepare(stream)/save/load functionality of Terrain is what you'd use after that.
How to get raw heightmaps into ogre from PB ?
-
Captn. Jinguji
- User

- Posts: 94
- Joined: Sun Oct 24, 2004 9:25 am
How to get raw heightmaps into ogre from PB ?
Is this an artifact or should it be disposed of ?
Re: How to get raw heightmaps into ogre from PB ?
As far as I know you can't if you are using PB's terrain commands.
If you really want to avoid height maps then I'd recommend creating the terrain mesh manually. Then you can use grey maps, color maps, or even raw data to create the terrain.
I wrote a basic terrain generator a while back which might give you something to work off of.
http://www.purebasic.fr/english/viewtop ... 36&t=59954
If you really want to avoid height maps then I'd recommend creating the terrain mesh manually. Then you can use grey maps, color maps, or even raw data to create the terrain.
I wrote a basic terrain generator a while back which might give you something to work off of.
http://www.purebasic.fr/english/viewtop ... 36&t=59954
Re: How to get raw heightmaps into ogre from PB ?
Look at TerrainHeight.pb example, line 78 , you can remove HeightMap
and use SetTerrainTileHeightAtPoint() to create your terrain.
Code: Select all
Imported = DefineTerrainTile(0, tx, ty, "", ty % 2, tx % 2) Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
-
Captn. Jinguji
- User

- Posts: 94
- Joined: Sun Oct 24, 2004 9:25 am
Re: How to get raw heightmaps into ogre from PB ?
Thanks, Samuel.
The thing is I just would like to use the 3D Engine from PB to display landscapes based on the raw heightmaps of another game engine - which happen to be in the same format digestible by OGRE ("a list of unscaled floats")-, or rather the manipulations I effect to them with my program written in PB.
In short, I'm simply seeking for a PureBasic way to issue the following calls:
MemoryDataStream rawFloats(ResourceGroupManager::getSingleton().openResource(filename, groupName));
imp.inputFloat = (float*)rawFloats.getPtr();
Oh, btw., I already saw your Editor (or rather the thread about it). Looks great and I certainly will give it a try, but not for the current case, since I don't want to duplicate the other engine's Editor now, just provide missing functionality.
The thing is I just would like to use the 3D Engine from PB to display landscapes based on the raw heightmaps of another game engine - which happen to be in the same format digestible by OGRE ("a list of unscaled floats")-, or rather the manipulations I effect to them with my program written in PB.
In short, I'm simply seeking for a PureBasic way to issue the following calls:
MemoryDataStream rawFloats(ResourceGroupManager::getSingleton().openResource(filename, groupName));
imp.inputFloat = (float*)rawFloats.getPtr();
Oh, btw., I already saw your Editor (or rather the thread about it). Looks great and I certainly will give it a try, but not for the current case, since I don't want to duplicate the other engine's Editor now, just provide missing functionality.
Is this an artifact or should it be disposed of ?
Re: How to get raw heightmaps into ogre from PB ?
Captn. Jinguji, Samuel terrain generator are very good, also the Comtois suggestion; i have posted before example to use SetTerrainTileHeightAtPoint, as Comtois said you can define points heights. in the following quick example the heights just to make something like a slope, you can prepare more complex patterns:
i choose DefineTerrainTile(0, 0, 0, "flaretrail.png", 0, 0) , you can use DefineTerrainTile(0, 0, 0, "White.jpg", 0, 0) because you don't want the picture to affect the terrain. i can't get rid from it even it is useless here.
needs PB 5.40 LTS
ref:
terrain experiments:
http://purebasic.fr/english/viewtopic.php?f=36&t=60685
http://purebasic.fr/english/viewtopic.php?f=36&t=60719
Code: Select all
height.f=35
For y=20 To 60
height+1.5
For x=20 To 50
SetTerrainTileHeightAtPoint(0, 0, 0, x, y, height)
Next
Nextneeds PB 5.40 LTS
Code: Select all
Enumeration
#TEXTURE = 200
#MATERIAL
#ENTITY
#Camera
EndEnumeration
#CameraSpeed = 1
Global power = 1
Define.f KeyX, KeyY, MouseX, MouseY
InitEngine3D()
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/nvidia" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
ExamineDesktops()
DesktopW = DesktopWidth(0)
DesktopH = DesktopHeight(0)
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0, 0, 0, DesktopW, DesktopH, "use mouse and keys to move camera")
OpenWindowedScreen(WindowID(0), 0, 0, DesktopW, DesktopH, 0, 0, 0)
GetScriptMaterial(2, "Color/Red")
CreateMaterial(6, LoadTexture(2, "soil_wall.jpg"))
CreateMaterial(3, LoadTexture(3, "terrain_detail.jpg"))
CreateCamera(#Camera, 0, 0, 100, 100)
MoveCamera(#Camera,70,100,140, #PB_Absolute)
CameraLookAt(#Camera,0,40,0)
CreateLight(0, $FFFFFF, 1500, 800, 500)
AmbientColor(RGB(0,200,0))
SkyBox("desert07.jpg")
CreateCube(1, 1)
SetupTerrains(LightID(0), 3000, #PB_Terrain_NormalMapping)
; initialize terrain
;Result = CreateTerrain(#Terrain, Size, WorldSize, Scale, NbLayers, Filename$, Extension$)
CreateTerrain(0, 129, 100, 40, 3, "TerrainHeight", "dat")
; set all texture will be use when terrrain will be constructed
AddTerrainTexture(0, 0, 100, "Geebee2.bmp", "dirt_grayrocky_normalheight.jpg")
AddTerrainTexture(0, 1, 30, "grass_green-01_diffusespecular.jpg", "grass_green-01_normalheight.jpg")
AddTerrainTexture(0, 2, 200, "growth_weirdfungus-03_diffusespecular.jpg", "growth_weirdfungus-03_normalheight.jpg")
;- define terrains
DefineTerrainTile(0, 0, 0, "White.jpg", 0, 0)
;DefineTerrainTile(0, 0, 0, "flaretrail.png", 0, 0)
BuildTerrain(0)
CreateTerrainBody(0, 0.5, 1)
UpdateTerrain(0)
; SkyBox
SkyBox("desert07.jpg")
EnableWorldPhysics(1)
EnableWorldCollisions(1)
;Result = TerrainTileSize(0, 0, 0)
height.f=35
For y=20 To 60
height+1.5
For x=20 To 50
SetTerrainTileHeightAtPoint(0, 0, 0, x, y, height)
Next
Next
UpdateTerrain(0)
CreateTerrainBody(0, 0.5, 1) ; new
CreateSphere(2,2.5)
CreateEntity(2,MeshID(2), #PB_Material_None ,-20,110,15)
CreateEntityBody(2, #PB_Entity_SphereBody,1, 1, 1)
EnableWorldPhysics(1)
EnableWorldCollisions(1)
;Debug Result
Repeat
event = WindowEvent()
If ExamineMouse()
MouseX = -MouseDeltaX()/20
MouseY = -MouseDeltaY()/20
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
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
EndIf
RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
MoveCamera(#Camera, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)terrain experiments:
http://purebasic.fr/english/viewtopic.php?f=36&t=60685
http://purebasic.fr/english/viewtopic.php?f=36&t=60719
-
Captn. Jinguji
- User

- Posts: 94
- Joined: Sun Oct 24, 2004 9:25 am
Re: How to get raw heightmaps into ogre from PB ?
thank you, Comtois and applePi, I will try as you told me.
Is this an artifact or should it be disposed of ?
Re: How to get raw heightmaps into ogre from PB ?
i have found an interesting continuous formula for terrain to give several hills:
height.f = Sin(2*x)*Cos(2*y)/2
the x and y is going from 0 to 9 (approx 3*#Pi)
and since the terrain size = 129 (from 0 to 128) we project the smaller scene to the big terrain
with x/9*129 and y/9*129. and we amplify the height by a number such as 15
SetTerrainTileHeightAtPoint(0, 0, 0, (x/9)*129, (y/9)*129, height*15)
uncomment also line 124: height.f = Sin(x) to have a sine wave terrain
also we can fill x,y by data from DataSection lines or from data from a file ...
one annoyance is that the falling sphere float over the holes bottom at a small distance, sometimes #PB_Entity_ConvexHullBody are better than #PB_Entity_SphereBody
height.f = Sin(2*x)*Cos(2*y)/2
the x and y is going from 0 to 9 (approx 3*#Pi)
and since the terrain size = 129 (from 0 to 128) we project the smaller scene to the big terrain
with x/9*129 and y/9*129. and we amplify the height by a number such as 15
SetTerrainTileHeightAtPoint(0, 0, 0, (x/9)*129, (y/9)*129, height*15)
uncomment also line 124: height.f = Sin(x) to have a sine wave terrain
also we can fill x,y by data from DataSection lines or from data from a file ...
one annoyance is that the falling sphere float over the holes bottom at a small distance, sometimes #PB_Entity_ConvexHullBody are better than #PB_Entity_SphereBody
Code: Select all
Declare DrawTerrain()
#Camera = 0
#CameraSpeed = 1
Define.f KeyX, KeyY, MouseX, MouseY
InitEngine3D()
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/nvidia" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
ExamineDesktops()
DesktopW = DesktopWidth(0)
DesktopH = DesktopHeight(0)
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0, 0, 0, DesktopW, DesktopH, "use mouse and keys to move camera")
OpenWindowedScreen(WindowID(0), 0, 0, DesktopW, DesktopH, 0, 0, 0)
CreateMaterial(6, LoadTexture(2, "soil_wall.jpg"))
CreateMaterial(3, LoadTexture(3, "terrain_detail.jpg"))
CreateCamera(#Camera, 0, 0, 100, 100)
MoveCamera(#Camera,0,90,240, #PB_Absolute)
CameraLookAt(#Camera,0,0,0)
CreateLight(0, $FFFFFF, 1500, 800, 500)
AmbientColor(RGB(200,200,200))
SkyBox("desert07.jpg")
SetupTerrains(LightID(0), 3000, #PB_Terrain_NormalMapping)
; initialize terrain
;Result = CreateTerrain(#Terrain, Size, WorldSize, Scale, NbLayers, Filename$, Extension$)
CreateTerrain(0, 129, 200, 1, 3, "TerrainHeight", "dat")
; set all texture will be use when terrrain will be constructed
AddTerrainTexture(0, 0, 100, "dirt_grayrocky_diffusespecular.jpg", "dirt_grayrocky_normalheight.jpg")
AddTerrainTexture(0, 1, 30, "grass_green-01_diffusespecular.jpg", "grass_green-01_normalheight.jpg")
AddTerrainTexture(0, 2, 200, "growth_weirdfungus-03_diffusespecular.jpg", "growth_weirdfungus-03_normalheight.jpg")
;- define terrains
;DefineTerrainTile(0, 0, 0, "terrain.png", 0, 0)
DefineTerrainTile(0, 0, 0, "White.jpg", 0, 0)
BuildTerrain(0)
CreateTerrainBody(0, 0.5, 1)
UpdateTerrain(0)
; SkyBox
SkyBox("desert07.jpg")
EnableWorldPhysics(1)
EnableWorldCollisions(1)
;Result = TerrainTileSize(0, 0, 0)
CreateTerrainBody(0, 2, 1)
UpdateTerrain(0)
CreateSphere(2,3)
CreateEntity(2,MeshID(2), #PB_Material_None ,20,20,0)
CreateEntityBody(2, #PB_Entity_SphereBody,1, 0.3, 1)
EnableWorldPhysics(1)
EnableWorldCollisions(1)
DrawTerrain()
Repeat
event = WindowEvent()
If ExamineMouse()
MouseX = -MouseDeltaX()/20
MouseY = -MouseDeltaY()/20
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
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
EndIf
RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
MoveCamera(#Camera, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
Procedure DrawTerrain()
x.f= 0 : y.f= 0
Repeat
Repeat
x + 0.005
height.f = Sin(2*x)*Cos(2*y)/2
;height.f = Sin(x)
;If IsNAN(height): height=0:EndIf
;SetTerrainTileHeightAtPoint(#Terrain, TileX, TileY, x, y, Height)
SetTerrainTileHeightAtPoint(0, 0, 0, (x/9)*129, (y/9)*129, height*15)
Until x > 9
y + 0.005 : x=0
Until y > 9
UpdateTerrain(0)
CreateTerrainBody(0, 2, 1)
EndProcedure-
Captn. Jinguji
- User

- Posts: 94
- Joined: Sun Oct 24, 2004 9:25 am
Re: How to get raw heightmaps into ogre from PB ?
Hi, ApplePi.
Although your formula for creating landscapes from sinus formulas really does look interesting,
currently, things like you described in your second link (such as: "Is this point inside or outside of a defined ellipse")
is much more the kind of thing I'm working on for my other project.
If I remain with ogre as a display tool for that project, maybe, we can exchange thoughts on certain things of that kind after I'm finished over there.
E.g., my mere coincidence, I "developed" a feature to create "rippled" landscapes, like the bottoms of dried-off oceans or heavily eroded hills.
Seems to fit in with all that talk of real water on Mars of lately.
Best regards
CJ
Although your formula for creating landscapes from sinus formulas really does look interesting,
currently, things like you described in your second link (such as: "Is this point inside or outside of a defined ellipse")
is much more the kind of thing I'm working on for my other project.
If I remain with ogre as a display tool for that project, maybe, we can exchange thoughts on certain things of that kind after I'm finished over there.
E.g., my mere coincidence, I "developed" a feature to create "rippled" landscapes, like the bottoms of dried-off oceans or heavily eroded hills.
Seems to fit in with all that talk of real water on Mars of lately.
Best regards
CJ
Is this an artifact or should it be disposed of ?

