In a 3D Scene, I have a table asset on which sits a game board asset, displaying a map with countries. My map is quite large- 7776 × 3456 pixels. The Main Camera looks down at an angle, can be moved via WASD controls, and be zoomed in/out by moving along its local Y axis (relative to the "look down" angle). This is all working well.
Next, I want to identify, and highlight, the "region" on the map (country, ocean, etc.) under the mouse cursor. Region borders are irregular (like a world map). The region count will be under 255, so I could use a single byte index to identify each region. I have a strategy that I believe should work:
- Create another copy of my map image, painting each region in a different color (call this the "country mask"). If I can save this as a "palletized" image, or a single-channel greyscale image, I can just use the pixel value (0-255) as the index of the map region. Load this into memory without displaying it.
- Trace a ray from the camera, through the mouse, onto the game board map, getting the coordinates on the map (texture) where the ray hits.
- Use those coordinates to get the color of the same location on the Country mask, and read the pixel value to get the map region index. This solves the Identification requirement.
- To solve the highlighting requirement, use the country mask in some fashion to highlight the hovered country. For example, if map region 29 is selected, I should be able to identify all pixels in the country mask with pixel value 29, then use that as a mask to apply some sort of effect on the actual map for just those pixels.
This leads me to the following questions:
- What's the most efficient way to load the country mask as a 2D array of index values? Ideally, 1 byte per pixel as opposed to 3 or 4 color channels.
- Is there a particular image format that I should use for the mask texture asset to facilitate this (e.g., storing only 1 byte per pixel).
- What's the right way to implement step 4? I'm sure that iterating all the pixels in both images via x/y loops would be very slow.
OnMouseOver()
andOnMouseExit()
. \$\endgroup\$