January 26, 2021, 06:18:02 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Miscellaneous
»
[bb] Mesh surface Packer Example by Pakz [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Mesh surface Packer Example by Pakz [ 1+ years ago ] (Read 521 times)
BlitzBot
Jr. Member
Posts: 1
[bb] Mesh surface Packer Example by Pakz [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:40 AM »
Title :
Mesh surface Packer Example
Author :
Pakz
Posted :
1+ years ago
Description :
Here a video with more maps and time taken (debugger on on 250 dollar laptop) : <a href="
" target="_blank">
[/url]
This is a example of how I am trying to optimize a random 3d map with blocks like minecraft and create bigger surfaces where possible.
In this example a small 2d map is generated and a routine goes from fitting big to small blocks into the map. If it fits then the space is added into a rects list and the map space is flagged occupied in a other array.
You end up with a list of coordinates and width and height for placing and resizing the meshes. I want to try and use this with a randomly created minecraft like map.
In this example it does not use 2*2 blocks. I still need to figure out how to do that. Edit - I added 2 4x4 block to.
Code :
Code: BlitzBasic
; Big Surfaces Maker
Graphics
800
,
600
,
32
,
2
SetBuffer
BackBuffer
(
)
SeedRnd
1
AppTitle
"Press escape to end."
Global
mapw =
50
Global
maph =
50
Dim
map
(
mapw,maph
)
Type
r
Field
x,y,w,h
End Type
Dim
cmap
(
mapw,maph
)
initmap
(
)
ms =
MilliSecs
(
)
initsurfaces
(
)
ms =
MilliSecs
(
)
- ms
timer =
CreateTimer
(
60
)
While
KeyDown
(
1
)
=
False
WaitTimer
timer
Cls
drawmap
(
)
drawrects
(
)
;
If
cnt >
60
*
3
initmap
(
)
ms =
MilliSecs
(
)
initsurfaces
(
)
ms =
MilliSecs
(
)
- ms
cnt=
0
End If
cnt=cnt+
1
Text
GraphicsWidth
(
)
-
196
,
10
,
"Took:"
+ms+
" ms"
Flip
Wend
End
Function
initsurfaces
(
)
Delete
Each
r
For
y=
0
To
maph
For
x=
0
To
mapw
cmap
(
x,y
)
=
0
Next
Next
;
; Pass 1 - Fit increasingly smaller blocks into the space and add to list
;
cnt=
0
exitloop =
False
rad = mapw
x1 =
0
y1 =
0
While
exitloop =
False
fits =
True
x2 = -rad
y2 = -rad
If
map
(
x1,y1
)
=
1
For
y2=-rad
To
rad
For
x2=-rad
To
rad
x3 = x1+x2
y3 = y1+y2
If
RectsOverlap
(
x3,y3,
1
,
1
,
0
,
0
,mapw+
1
,maph+
1
)
=
True
If
map
(
x3,y3
)
=
0
Then
fits =
False
:
Exit
If
cmap
(
x3,y3
)
=
1
Then
fits =
False
:
Exit
Else
fits =
False
:
Exit
EndIf
Next
Next
If
fits =
True
Then
For
y2 = -rad
To
rad
For
x2 = -rad
To
rad
x3 = x1 + x2
y3 = y1 + y2
cmap
(
x3,y3
)
=
1
Next
Next
r1.r =
New
r
r1x = x1-rad
r1y = y1-rad
r1w = rad*
2
r1h = rad*
2
End If
End If
x1 = x1 +
1
If
x1 > mapw
y1 = y1 +
1
x1 =
0
End If
If
x1 => mapw
And
y1=>maph
Then
x1 =
0
y1 =
0
rad = rad -
1
End If
If
rad <
0
Then
exitloop =
True
Wend
;
; Pass 2 - check the list for 4x4 rectangles to create one off
;
For
y=
0
To
maph
For
x=
0
To
mapw
If
map
(
x,y
)
=
1
For
this.r =
Each
r
If
thisx = x
And
thisy = y
And
thisw =
0
aset =
False
For
a.r =
Each
r
If
ax = thisx+
1
And
ay = thisy
And
aw =
0
Then
aset =
True
Next
bset =
False
For
b.r =
Each
r
If
bx = thisx
And
by = thisy+
1
And
bw =
0
Then
bset =
True
Next
cset =
False
For
c.r =
Each
r
If
cx = thisx+
1
And
cy = thisy+
1
And
cw =
0
Then
cset =
True
Next
If
aset =
True
And
bset =
True
And
cset =
True
that.r =
New
r
thatx = thisx
thaty = thisy
thatw =
1
thath =
1
For
a.r =
Each
r
del =
False
If
ax = thisx+
1
And
ay = thisy
And
aw =
0
Then
Del =
True
If
ax = thisx
And
ay = thisy+
1
And
aw =
0
Then
del =
True
If
ax = thisx+
1
And
ay = thisy+
1
And
aw =
0
Then
del =
True
If
del =
True
Then
Delete
a
Next
Delete
this
End If
End If
Next
End If
Next
Next
End Function
Function
drawrects
(
)
Color
255
,
255
,
255
For
this.r =
Each
r
Rect
thisx*
10
,thisy*
10
,
(
thisw+
1
)
*
10
,
(
thish+
1
)
*
10
,
False
Next
End Function
Function
drawmap
(
)
For
y=
0
To
maph
For
x=
0
To
mapw
Select
map
(
x,y
)
Case
0
:
Color
0
,
0
,
0
Case
1
:
Color
100
,
100
,
100
End Select
Rect
x*
10
,y*
10
,
10
,
10
,
True
Next
Next
End Function
Function
initmap
(
)
For
y=
0
To
maph
For
x=
0
To
mapw
map
(
x,y
)
=
0
Next
Next
exitloop =
False
While
exitloop =
False
x1 =
Rand
(
mapw
)
y1 =
Rand
(
maph
)
rad =
Rand
(
3
,
6
)
For
y2 = -rad
To
rad
For
x2 = -rad
To
rad
x3 = x1+x2
y3 = y1+y2
If
x3 =>
0
And
y3 >=
0
And
x3 =< mapw
And
y3 <= maph
map
(
x3,y3
)
= map
(
x3,y3
)
+
1
If
map
(
x3,y3
)
>
10
Then
exitloop =
True
End If
Next
Next
Wend
For
y =
0
To
maph
For
x =
0
To
mapw
If
map
(
x,y
)
<
5
Then
map
(
x,y
)
=
0
If
map
(
x,y
)
>
4
Then
map
(
x,y
)
=
1
Next
Next
End Function
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Miscellaneous
»
[bb] Mesh surface Packer Example by Pakz [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal