SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 31/05/2014, 11:00 PM   #1
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,943
Reputation: 1471
Default Bitmapping Object Placement

Bitmap Object Placement
A while ago I was asking around for a bitmap loader. I eventually stumbled across this plugin: http://forum.sa-mp.com/showthread.php?t=254710 which was exactly what I wanted!

I decided to speed up object placement a bit for the Scavenge and Survive project as the map is still pretty bare for the intended desolate representation of what once was San Andreas. I'm pretty lazy and spending hours placing trees and bushes is not in my best interests so I wrote the bitmap object placement tool to solve that problem!

How does it work?
First, a virtual canvas is created across the map. This makes getting a position from a resolution easier. That library is somewhere on Gist/GitHub.

Next, the EasyBMP plugin reads a bitmap file and runs some code for each pixel read.

Depending on the colour of the pixel, a different model will have a chance of spawning there. Each pixel colour has a list of possible objects for instance, dark green is mostly trees and light green is brushes and shrubbery. Blue water pixels just spawn buoys at the moment.

The loader supports any size bitmap since the virtual canvas abstraction means any resolution will translate to a world position.

Here are some example bitmaps I used while developing this idea:

Example #1

My first attempt. Green pixels are bushes, black pixels are trash piles. Mainly to test the virtual canvas layer. A canvas was created over bayside 900m square. The resolution of the canvas matches the image size (which is 450px) so each pixel represents 2 square metres and the virtual canvas library matches that up perfectly.

Example #2

This is a map of just the black pixels which is mostly roads. However, I'd rather use node data for getting road coordinates for vehicle/loot spawns as it will be more accurate.

Example #3

This is just the foliage pixels. Different shades of green spawn different types of tree/shrub which match the region (Red County and some of Flint County have darker pixels. The lighter green pixels are the small shrub areas by roads, tree lines and the edges of fields)

Example #4


I created that map using the default SA map. This one is 1000 pixels square so there isn't a pixel for each square metre in the game. The image was posterised which effectively truncates the amount of colours in the image, merging sets of pixels of similar colours to an interpolated sum of each. This gives me a flat colour to easily extract the pixel data from without needing to write the approximation code into the parser.

Example #5

This version is a slightly larger posterised 6000 square image used for more precise placement. The problem with this image (The famous high resolution map from Ian Albert) is that it's shaded with a lightmap so there are light and dark areas of the same surface material. The best solution is to use the low resolution map but manually paint over it (painting is still quicker than manually placing trees!)

Results
The results are quite beautiful. A lush abundance of foliage reclaiming the urban areas of San Fierro and trees sprouting through crops and engulfing Flint Range Farm. It makes the ground a much darker and scarier place with trees shrouding the sky from view.

Invading San Fierro


You could ambush someone from those trees!


This area needs some more trees


Different pixel colours at work, farmland grows mostly bushes rather than trees.


Makes dirt tracks much more mysterious...


Flint Range Farm is now surrounded by trees! (Yes that's a glitchy bush on the roof)


The only downside to this is the object limit / stream range



Maps in 3D
This idea came from using bitmaps in Autodesk 3ds Max. For those of you who don't know, that's a 3D meshing, animation and rendering tool (and many other things). Bitmaps are generally used to add colouring ("textures") to 3D models but Max lets you use maps for a huge range of things.

You can displace geometry (give it shape) with a bitmap. You can make light react differently in different parts of a surface. You can create shadows and highlights without even modifying the geometry of the model (bump/normal maps)!

One map type will use monochrome pixel data to distribute a mesh or list of meshes across a surface. Darker pixels mean more chance of a mesh appearing at that position on the model which is determined by translating from pixel XY to mesh UV to world XY.


Development
I'd love to hear some ideas or discussion to push this idea further! I have already integrated MapAndreas for the height obviously but I must write a height check so huge height differences cancels object placement in case a pixel slightly overlaps a building.

Texture mapping can be used for loads of things other than just object placement. Smaller in scope too, we've already seen textdraws but I always thought that was a bit gimmicky due to the textdraw limit. I'm sure this plugin has far more practical uses than just textdraws. The Virtual Canvas means you don't have to apply this to just the entire map, you can make a bitmap for a custom map or a specific area in San Andreas (like the bayside example).

If you want the original bitmaps (don't bother downloading the above images, quality will be lost due to compression) let me know and I'll post a zip archive.

Code is here on GitHub: https://gist.github.com/Southclaw/16c972c8504fbc347f48
Unfinished due to lack of time and my server dying. I'll probably make a proper library out of it at some point. (Blog article)
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Old 01/06/2014, 07:22 AM   #2
AroseKhanNiazi
High-roller
 
AroseKhanNiazi's Avatar
 
Join Date: Jan 2014
Location: Pakistan
Posts: 1,374
Reputation: 78
Default Re: Bitmapping Object Placement

Awesome
AroseKhanNiazi is offline   Reply With Quote
Old 01/06/2014, 07:52 AM   #3
AIped
Gangsta
 
AIped's Avatar
 
Join Date: Feb 2011
Location: Netherlands
Posts: 781
Reputation: 46
Default Re: Bitmapping Object Placement

just...OMG YES! I love projects like these..thinking out of the box.
AIped is offline   Reply With Quote
Old 01/06/2014, 08:05 AM   #4
AndreT
Gangsta
 
AndreT's Avatar
 
Join Date: Jul 2011
Posts: 977
Reputation: 410
Default Re: Bitmapping Object Placement

A very nice project, mate!
AndreT is offline   Reply With Quote
Old 01/06/2014, 09:05 AM   #5
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,287
Reputation: 311
Default Re: Bitmapping Object Placement

This is pretty nice. I'd seen that plugin too, but never realized this implementation! The code you've written can be improved though! It should be much more calculatingly decided if to place a water body or a foliage body there instead of a random() [IF that is what it does, given I haven't misunderstood it's purpose]

An online map, where people can simply paint over the map, where the script can convert them into sparsely spaced (offsets of +- 10 units in each direction) objects, would be good. (otherwise leading to a massive overload of the same objects) Another idea is to create a similar map where you can draw lines over the map, the script making long, continuous roads out of them. Again, a text-draw maker - as already suggested in the original plugin thread.

Good one!
RajatPawar is offline   Reply With Quote
Old 01/06/2014, 01:01 PM   #6
Tamer
High-roller
 
Tamer's Avatar
 
Join Date: Nov 2011
Location: Turkey
Posts: 1,190
Reputation: 169
Default Re: Bitmapping Object Placement

Masterpiece.
__________________
The three stages of truth:

- Ridicule.
- Violent opposition.
- Acceptance.


Quote:
The greatest hypnotist on the planet Earth is an oblong box in the corner of the room. It is constantly telling us what to believe is real. If you can persuade people that what they see with their eyes is what there is to see you've got them. you know because they'll laugh in your face of an explanation that portrays the biggest picture of what's happening... and they have.
Tamer is offline   Reply With Quote
Old 11/06/2014, 07:34 PM   #7
legodude
High-roller
 
legodude's Avatar
 
Join Date: Sep 2009
Location: 127.0.0.1 duhh
Posts: 1,146
Reputation: 783
Default Re: Bitmapping Object Placement

wow, this has a lot of potential!

good job!
__________________
legodude is offline   Reply With Quote
Old 11/06/2014, 09:03 PM   #8
davve95
High-roller
 
davve95's Avatar
 
Join Date: Nov 2009
Location: Sweden
Posts: 3,854
Reputation: 234
Default Re: Bitmapping Object Placement

Awesome!.

All of your released things is pretty awesome.
davve95 is offline   Reply With Quote
Old 06/10/2014, 01:27 PM   #9
bogdyutzu
Big Clucker
 
Join Date: Nov 2011
Location: Romania, Pitesti
Posts: 138
Reputation: 5
Default Re: Bitmapping Object Placement

Can you post a zip with the images?
bogdyutzu is offline   Reply With Quote
Old 06/10/2014, 03:20 PM   #10
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,943
Reputation: 1471
Default Re: Bitmapping Object Placement

I don't have any of the original project files sorry.
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Useful object streamer that streams objects realistically (the bigger the object, the farther it gets streamed from) RajatPawar Includes 28 13/10/2016 11:28 AM
Custom Graffiti System (Custom Creation & Placement) EiresJason Screenshots and Videos 13 19/10/2013 06:58 PM
Mapping Placement kvsolga General 7 05/08/2011 11:12 AM
Instant placement on ground/Detecting if falling AlExAlExAlEx Help Archive 2 12/06/2011 10:13 PM


All times are GMT. The time now is 06:39 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.