building 3d terrain editor Your Ideas welcome

Blitz3D Forums/Blitz3D Programming/building 3d terrain editor Your Ideas welcome

I have been programming in blitz3d for serveral months now yet projects are hard to complete when you have little model or texture resources available so i wish to help on one part of this subject

Landscape editor
Map editor

please post any features you think it should include and ideas of how to improve code as it developes

ideas to implement

1. Binary Maps
2. Binary Map tileable
3. 3d map editor scaleable
4. 3d tileset Generator
5. Textureset Designer
6. texturemap Designer
7. methods of export .dat .b3d

binary Editor with lod tiles

Graphics3D 1024,768,32,1

ClearWorld(1,1,1)

Global Player=CreateSphere(32)
PositionEntity player,4,4,4
Global MAPRANGE=50;CHANGES THE NUMBER OF TERRAINS IN VIEW
Global brush,cam
Global Maxheight=20;change max height

cam=CreateCamera()
lgt=CreateLight(2)
LightRange lgt,200
PositionEntity cam,10,5,10
RotateEntity cam,0,45,0
CameraRange cam,1,1000
brush=LoadBrush("grass1.png");PLACE ANY TEXTURE HERE
;BrushFX brush,1
Dim Vertx#(11,11)
Dim Verty#(11,11)
Dim Vertz#(11,11)
Dim Maparray.Map_area(100)

Type Map_tile
    Field Maptile
	Field Active
	Field tile_id[100]
	Field Brush_id[100]
	Field tilex
	Field tiley
	Field tilez
End Type

Type Map_Segm
	Field Active
	Field Maptile.Map_tile[10000]
End Type

Type Map_sect
	Field Active
	Field Mapsegm.Map_segm[100]
End Type

Type Map_area
    Field Active
	Field Mapsect.Map_sect[100]
End Type

For times4=1 To 10
maparray(times4)=New Map_area
For times3=1 To 10
maparray(times4)\mapsect[times3]=New map_sect
For times2=1 To 10
maparray(times4)\mapsect[times3]\mapsegm[times2]=New Map_Segm
For times=1 To 100
maparray(times4)\mapsect[times3]\mapsegm[times2]\maptile[times]=New Map_tile
maparray(times4)\mapsect[times3]\mapsegm[times2]\maptile[times]\active=1
Next
Next
Next
Next


For tiles=1 To 100
read_Maptile(tiles)
log_maptile(tiles)
create_maptile(tiles)
Next
tiles=0


For x=1 To 10
For z=1 To 10
tiles=tiles+1
PositionEntity maparray(1)\mapsect[1]\mapsegm[1]\maptile[tiles]\maptile,x*10,0,z*10
Next
Next

;create_skybox()
Print maparray(1)\mapsect[1]\mapsegm[1]\maptile[1]\tile_id[32]

While Not KeyHit(1)
If KeyDown(200) Then MoveEntity cam,0,0,.02
If KeyDown(208) Then MoveEntity cam,0,0,-.02
If KeyDown(203) Then TurnEntity cam,0,.05,0
If KeyDown(205) Then TurnEntity cam,0,-.05,0
EntityParent lgt,cam 
Hide_it
UpdateWorld
RenderWorld


Flip 0
Wend
End



.Sector1
Data 3,3,2,1,1,1,1,2,3,3
Data 3,3,2,1,1,1,1,2,3,3
Data 2,2,2,1,1,1,1,2,2,2
Data 1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1
Data 1,1,1,1,1,1,1,1,1,1
Data 2,2,2,1,1,1,1,2,2,2
Data 3,3,2,1,1,1,1,2,3,3
Data 3,3,2,1,1,1,1,2,3,3


Function Read_Maptile(tiles)
Restore Sector1
For times=1 To 100
Read maparray(1)\mapsect[1]\mapsegm[1]\maptile[tiles]\tile_id[times]
maparray(1)\mapsect[1]\mapsegm[1]\maptile[tiles]\tile_id[times]=maparray(1)\mapsect[1]\mapsegm[1]\maptile[tiles]\tile_id[times]
Next
End Function

Function log_maptile(tiles)
For high=1 To Maxheight
times=0
For x=1 To 10
For z=1 To 10
times=times+1
If maparray(1)\mapsect[1]\mapsegm[1]\maptile[tiles]\tile_id[times]=high Then 
vertx#(x,z)=-6+x
verty#(x,z)=high/2-1
vertz#(x,z)=-6+z
vertx#(x,z+1)=-6+x
verty#(x,z+1)=high/2-1
vertz#(x,z+1)=-6+z+1
vertx#(x+1,z+1)=-6+x+1
verty#(x+1,z+1)=high/2-1
vertz#(x+1,z+1)=-6+z+1
vertx#(x+1,z)=-6+x+1
verty#(x+1,z)=high/2-1
vertz#(x+1,z)=-6+z
EndIf
Next
Next
Next
End Function

Function create_maptile(tiles)
maparray(1)\mapsect[1]\mapsegm[1]\maptile[tiles]\maptile=CreateMesh()
surf=CreateSurface(maparray(1)\mapsect[1]\mapsegm[1]\maptile[tiles]\maptile,brush)
For x=1 To 10
For z=1 To 10
v1=AddVertex (surf,vertx#(x,z),verty#(x,z),vertz#(x,z),0,0)
v2=AddVertex (surf,vertx#(x,z+1),verty#(x,z+1),vertz#(x,z+1),0,1)
v3=AddVertex (surf,vertx#(x+1,z+1),verty#(x+1,z+1),vertz#(x+1,z+1),1,1)
v4=AddVertex (surf,vertx#(x+1,z),verty#(x+1,z),vertz#(x+1,z),1,0)
t1=AddTriangle(surf,v1,v2,v3)
t2=AddTriangle(surf,v3,v4,v1)
Next
Next
UpdateNormals maparray(1)\mapsect[1]\mapsegm[1]\maptile[tiles]\maptile
End Function

Function Hide_it()
For times=1 To 100
If EntityDistance(maparray(1)\mapsect[1]\mapsegm[1]\maptile[times]\maptile,cam)>maprange Then 
HideEntity maparray(1)\mapsect[1]\mapsegm[1]\maptile[times]\maptile
EndIf
If EntityDistance(maparray(1)\mapsect[1]\mapsegm[1]\maptile[times]\maptile,cam)<maprange Then 
ShowEntity maparray(1)\mapsect[1]\mapsegm[1]\maptile[times]\maptile
EndIf
Next
End Function

Function create_skybox()
    mesh = CreateMesh()

    ;front face
    brush = LoadBrush("front.jpg",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,-1,0,0
    AddVertex surface,+1,+1,-1,1,0
    AddVertex surface,+1,-1,-1,1,1
    AddVertex surface,-1,-1,-1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush

    ;right face
    brush = LoadBrush("right.jpg",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,+1,+1,-1,0,0
    AddVertex surface,+1,+1,+1,1,0
    AddVertex surface,+1,-1,+1,1,1
    AddVertex surface,+1,-1,-1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush

    ;back face
    brush = LoadBrush("back.jpg",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,+1,+1,+1,0,0
    AddVertex surface,-1,+1,+1,1,0
    AddVertex surface,-1,-1,+1,1,1
    AddVertex surface,+1,-1,+1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
 
    ;left face
    brush = LoadBrush("left.jpg",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,+1,0,0
    AddVertex surface,-1,+1,-1,1,0
    AddVertex surface,-1,-1,-1,1,1
    AddVertex surface,-1,-1,+1,0,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush

    ;top face
    brush = LoadBrush("top.jpg",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,+1,+1,0,1
    AddVertex surface,+1,+1,+1,0,0
    AddVertex surface,+1,+1,-1,1,0
    AddVertex surface,-1,+1,-1,1,1
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
   
    ;bottom face 
    brush = LoadBrush("bottom.jpg",49)
    surface = CreateSurface(mesh,brush)
    AddVertex surface,-1,-1,-1,1,0
    AddVertex surface,+1,-1,-1,1,1
    AddVertex surface,+1,-1,+1,0,1
    AddVertex surface,-1,-1,+1,0,0
    AddTriangle surface,0,1,2
    AddTriangle surface,0,2,3
    FreeBrush brush
    
    ScaleMesh mesh,200,200,200
    FlipMesh mesh
    EntityFX mesh,1 ; make fullbright
    Return mesh
    UpdateNormals mesh
End Function



arrow keys move camera

editing the binary data within sector1 changes the map detail by raising quads

;3d terrain editor in progress
;duckstab

;left mouse select triangle
;hold q vert up
;hold a vert down
;arrow keys rotate map
;page up and down zoom
;create a texture with a black background and a white circle outline for target.png (30 by 30)
;create a texture with a green background with a 1 pixle border for vertile.png (30 by 30) 


Graphics3D 1024,768,32,1
ClearWorld(1,1,1)
Global cam1=CreateCamera()
Global lgt1=CreateLight()
Global mesh

Global picked#,tri,surface
Global v1x#,v1y#,v1z#,v1
Global v2x#,v2y#,v2z#,v2
Global v3x#,v3y#,v3z#,v3,uvmap1#,uvmap2#

Dim Vert#(21,21)
PositionEntity cam1,0,2,-40
tex=LoadTexture("vertile.png")
target=LoadImage("target.png")

mesh_create
EntityTexture mesh,tex
ScaleTexture tex,.05,.05
;EntityColor mesh,255,126,46
RotateEntity mesh,90,0,0
While Not KeyHit(1)

If KeyDown(200) Then TurnEntity mesh,.1,0,0
If KeyDown(203) Then TurnEntity mesh,0,-.1,0
If KeyDown(208) Then TurnEntity mesh,-.1,0,0
If KeyDown(205) Then TurnEntity mesh,0,.1,0
If KeyDown(201) Then MoveEntity cam1,0,0,.1
If KeyDown(209) Then MoveEntity cam1,0,0,-.1
If KeyDown(16) And picked>0 Then movevert1
If KeyDown(30) And picked>0 Then movevert2
If MouseDown(1) Then getpicked
UpdateWorld
RenderWorld
Text 100,100,"picked="+picked
Text 100,115,"Tri="+tri
Text 100,130,"vert1 x="+v1x+"  y="+v1y+"  z="+v1z
Text 100,145,"uv1="+uvmap1
Text 100,160,"uv2="+uvmap2
DrawImage target,MouseX(),MouseY()
Flip 0
Wend
End

Function Mesh_create()
mesh=CreateMesh()
surf=CreateSurface(mesh)
	For x=1 To 21
		For z=1 To 21
		vert(x,z)=AddVertex(surf,x-9,0,z-9,(x*.05)-.05,((z*.05)-.05))
		Next
	Next
	For x=1 To 20
		For z=1 To 20
			AddTriangle surf,vert(x,z),vert(x+1,z),vert(x,z+1)
			AddTriangle surf,vert(x,z+1),vert(x+1,z),vert(x+1,z+1)
		Next
	Next
UpdateNormals Mesh
EntityPickMode mesh,2	
End Function

		

Function Getpicked()
picked=CameraPick(cam1,MouseX()+15,MouseY()+15)
If picked>0 Then getvert
End Function


Function Getvert()
tri=PickedTriangle()
surface=GetSurface(mesh,1)
v1=TriangleVertex(surface,tri,0)
v2=TriangleVertex(surface,tri,1)
v3=TriangleVertex(surface,tri,2)
v1x=VertexX(surface,v1)
v1y=VertexY(surface,v1)
V1z=VertexZ(surface,v1)
v2x=VertexX(surface,v2)
v2y=VertexY(surface,v2)
V2z=VertexZ(surface,v2)
v3x=VertexX(surface,v3)
v3y=VertexY(surface,v3)
V3z=VertexZ(surface,v3)
uvmap1=VertexV# ( surface,v1,0 )
uvmap2=VertexU# ( surface,v1,1)
End Function

Function movevert1()

v1y=v1y+.003
v2y=v2y+.003
v3y=v3y+.003

VertexCoords (surface,v1,v1x,v1y,v1z)
VertexCoords (surface,v2,v2x,v2y,v2z)
VertexCoords (surface,v3,v3x,v3y,v3z)

UpdateNormals mesh
End Function

Function movevert2()

v1y=v1y-.003
v2y=v2y-.003
v3y=v3y-.003

VertexCoords (surface,v1,v1x,v1y,v1z)
VertexCoords (surface,v2,v2x,v2y,v2z)
VertexCoords (surface,v3,v3x,v3y,v3z)

UpdateNormals mesh
End Function



updated code slimline added testing for vertical move of tris

I see a black screen when I run it.

sorry just changed the entity position try again

What's the difference between the first & the second? Why are there two?

Ok, got it to work.

I like the terrain editor. It is one I can work with - I can't wait until you start making textures for the thing!

And I also have one suggestion: make it so you can click on the terrain and hold down the button to make the terrain go up/down.

The first is a binary editor the higher the value the higher the quad appears on the map

each sector is a 3d tile map predefined
combining these to create your level which works on entity distance to show,hide,delete

so you could have create a map 100,100 each unit is a 3d tile map
using entitydistance it can create,show,hide,delete relevant tile to allow huge levels stored in data variable
giving minamal collision coding and manual 3d creation

The Second is to work with both

The concept

Create Large Map Single,Multi Surface terrains Multi might be needed for tile set to allow proper uv coords without conflicts

Create Large Multi Segment maps to be used in a similar format as the binary lod

Create Template Map To be used in TileSet Generator which is a third concept in the early stages
ie creates four corners 4,8,or 12 side panels and numerus central tiles

As for your request hope to add today thankyou Man of Many Names :) for your Responce