mapbox / mapbox-unity-sdk Goto Github PK
View Code? Open in Web Editor NEWMapbox Unity SDK - https://www.mapbox.com/unity/
License: Other
Mapbox Unity SDK - https://www.mapbox.com/unity/
License: Other
polyline
is the only available option right now.
No terrain is generated:
ArgumentOutOfRangeException: Argument is out of range.
Parameter name: index
System.Collections.Generic.List`1[UnityEngine.Vector3].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
Mapbox.Unity.MeshGeneration.Factories.TerrainFactory.GenerateTerrainMesh (Mapbox.Unity.MeshGeneration.Data.UnityTile tile, Single heightMultiplier) (at Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs:184)
Mapbox.Unity.MeshGeneration.Factories.TerrainFactory+<CreateTerrainHeight>c__AnonStorey9.<>m__F () (at Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs:125)
Mapbox.Map.Tile.HandleTileResponse (Response response) (at Assets/Mapbox/Core/mapbox-sdk-cs/Map/Tile.cs:174)
Mapbox.Unity.Utilities.HTTPRequest+<DoRequest>c__Iterator2.MoveNext () (at Assets/Mapbox/Core/Unity/Utilities/HTTPRequest.cs:56)
Mapbox.Unity.Utilities.Runnable+Routine.MoveNext () (at Assets/Mapbox/Core/Unity/Utilities/Runnable.cs:130)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
So, I're preparing a demo project which is centered heavily around Mapbox for which I'm currently using the 0.5.1 release.
Looking at the repository, a lot has changed since then, and i'm not sure if I should be using the release or the development version... As mine is a demo project (which might go into production some day) 100% stability isn't required yet, so I'm inclined to use the development version of Mapbox.
My reasoning is that I'll have less work porting the current version of our project to the new API then a seasoned project later on.
So my question is (and I know we all hate these questions), when is the next release estimated to be published? Are we looking at days, weeks, or months?
And a followup, should I use the development branch here, or the 0.5.1 release (and wait for an official release), to minimize my overall effort of porting the project?
Thanks!
Hello,
I've been using the beta version since 0.4.0. Today I updated to 0.5.1, updated my code to match the new API, and I wanted to setup my codebase properly so I can (in practice) do a git pull
, check out develop
or a version number, and have Unity import that version. I'm familiar with the technology layer in isolation, but I'm new to working with Unity and a third-party module.
What's your development setup like? This is what I imagine on how to set up a development fork:
develop
branchfeature-xxx
sdkproject/Assets
into a Unity ProjectAnother question is that I'm using MacOS primary to work, but the UnityPackager.exe
is a Windows-only binary. Do I need to run that and import to Unity as I develop with it? Ideally, I'd like to be able to work with the source code directly, modify it, and submit pull requests.
Hi there,
After following the simple Getting Started steps, I got the 'Location provider' testscene up and running, tried to make an Android build and run it from my device. It only just got to load in the player, then crashed after 1-2 seconds.
Any idea what I'm doing wrong? Tried on 2 phones, both of them crashing.
Cheers
Stig
I'm trying to put a custom material on my terrain, but it's not working.
My visualization only has a TerrainFactory and a MeshFactory on it. If I use a custom material under TerrainFactory -> Material, the material doesn't get applied to the terrain mesh.
Looking at the generated mesh, the material that gets applied is the "Default-Material".
I've tried to hack it with a _mapController.Execute call from Slippy.cs : Update() and it partially worked but there were a lot of
MissingReferenceException: The object of type 'UnityTile' has been destroyed but you are still trying to access it.
here and there. I can band-aid it with != null check but I'm afraid it will only mask the actual problem.
If implementing zoom for slippy map is not on the near future roadmap, can you please advise on the right approach to it?
Thank you!
I started this after #23 ticket and implemented it in cuttingHoles branch at the moment.
Had to chance structure a bit to implement this and did two major changes; (1) we're passing features to stacks (instead of geometries) now, which means stacks have full knowledge about the outline&holes of a building. (2) polygon and line mesh modifiers used to work on MeshData class which has a single vertex list and actually corresponds to Mesh class of Unity3D. Now with holes, we need more than one vertex list so I changed them to work on original data. Their outcome is a single vertex list which we now use to initialize MeshData.
So in short, before this all modifiers used MeshData, now some of them use feature and some others use mesh data. It's not intuitive which one uses what for now though.
As a developer, I should know when a tile is finished loading (from the web), as well as any post-processing that happens after the tile is fetched (texture generated, meshes built, etc.). This will help to create animations, avoid temporal coupling, and allow for loading screens, etc.
I have a TerrainFactory with a 2x2 resolution (for a low-poly look) and the terrain snapping for roads doesn't work well in this case:
As the snapping modifier uses the height data of the terrain for snapping it works fine in cases with a high resolution terrain, but fails with low resolution.
Not sure what the fix for this would be... Worst case raycasting, best case, using the terrain resolution and some black magic to figure out the actual height of the terrain mesh?
My "workaround" for this was to use a map image factory with a custom style (that only includes roads) and retina resolution turned on, to get some feeling of roads, but I'd like to have them as meshes in the long term.
Using the latest develop: 61d740b
https://bitbucket.org/Unity-Technologies/unitytesttools/wiki/Home
This will help us test things that cannot be described with simple unit tests and ensure we don't break existing features as we refactor or add new features. As a bonus, we can test Unity-specific features.
One example: Test that tile load progress is reported accurately as additional tiles are requested.
eg DirectionsExample
expects JSON to be >5,000
characters:
DirectionsFactory.cs expects that there is at least one route with legs:
void HandleDirectionsResponse(DirectionsResponse response)
{
var meshData = new MeshData();
var dat = new List<Vector3>();
foreach (var leg in response.Routes[0].Legs)
^^^^^^
{
foreach (var point in response.Routes[0].Geometry)
{
dat.Add(Conversions.GeoToWorldPosition(point.x, point.y, _map.CenterMercator, _map.WorldRelativeScale).ToVector3xz());
}
}
Unity has a built-in editor test runner, but we can also add NUnit packages to our solutions to run tests there (just make sure tests are nested in an Editor
folder).
We will also need to ensure our tests work with .NET 3.5.
@david-rhodes I just saw the logo on https://mapbox.github.io/mapbox-unity-sdk/ and it's looking clipped with a slightly transparent white.
This should be adjusted to match out new brand guidelines
https://122e4e-mapbox.global.ssl.fastly.net/about/press/brand-guidelines/ Concretely:
To streamline our built-in examples and help facilitate testing, we should bring in the main scene and scene build editor scripts.
Warn user if a TerrainFactory
is missing, as this is needed to render the raster results.
Import a shp file based Dataset into Mapbox Studio.
Made a Tileset out of it.
Added the Tileset vector layer to a new Style
Published the Style
Added Style URL to
Updated access token in Unity project
In TerrainDemoMeshFactory inspector:
Added style MapId uri to TerrainDemoMeshFactory
Added key for my data to DriveBuildingVisualizer
Debugged this Unity project
VectorTileReader.cs:52 throws exceception "Unknown tile tag: 15"
I just want to see if I can get the data over. Then I will build my own visualizer. It reads something, but apparently this isn't a Layer
In Unity is Height Data, but it gets the elevation data is right?
height = -10000 + ((R * 256 * 256 + G * 256 + B) * 0.1)
https://docs.unity3d.com/Manual/StreamingAssets.html
On Android, the files are contained within a compressed .jar file (which is essentially the same format as standard zip-compressed files). This means that if you do not use Unity’s WWW class to retrieve the file, you need to use additional software to see inside the .jar archive and obtain the file.
Currently ValidateMapboxAccessFile()
does not use WWW
to check if the token file exists
if (!Directory.Exists(Application.streamingAssetsPath) || !File.Exists(_accessPath)) {
throw new InvalidTokenException("Please configure your access token in the menu!");
}
and fails, even if it is there, and LoadAccessToken()
never gets called.
LoadMapboxAccess()
is "async" and by the time the token has been retrieved all tile requests (18 in my test app, based on example MeshGenerationStyles
) have already been fired (without a token) and fail.
WebGL builds of our examples aren't working in latest develop.
@MateoV - do you have bandwidth to investigate this?
Subticket for #23.
Initially I was thinking about breaking this into bunch of smaller modifiers. Actually I'll probably still do that without removing this one but for now, I started with fixing what we already have.
There were bunch of issues with min_height usage, flat building tops, road side walls etc
They seem like fixed now on cuttingHoles
branch but there are lots of possible modifier/settings combinations so I might be missing some stuff.
In this latest structure, SnapTerrain
modifier does the terrain snapping, which was done in VectorLayerViusalizer
before. Then height modifier calculates the base height and structure height, pushes the vertices up by base height + structure height (to create the roof) and finally creates side walls from that point down to base height.
The current destruction of the only MapboxConvenience instance was happening after I built for a standalone exe. I've addressed this with the following changes:
public override void Awake()
{
/*
if (s_instance != null)
{
Destroy(gameObject);
return;
}
*/
base.Awake();
if (s_instance != this)
{
Destroy(gameObject);
return;
}
if (string.IsNullOrEmpty(_token))
{
throw new InvalidTokenException("Please get a token from mapbox.com");
}
if (_fileSource == null)
{
_fileSource = new FileSource(this);
_fileSource.AccessToken = _token;
}
}
Unity v5.5.2 (64-bit Windows editor)
Mapbox Unity SDK v0.4 beta
I'm able to run example scenes in a project with just mapbox in it so I'm thinking there's a collision with something somewhere, but can't find it. I had ICSharpCode.SharpZipLib
in the project and removed my existing one in favor of the one that cam with mapbox. I'm also using NewtonSoft's json, I tried removing that and no difference.
When running MapController no valid vector tile data is returned from the request. All I get are ParseErrors (with no further helpful information). After some digging I was able to glean the following:
Native file browser:
TextMesh pro:
Mapbox:
Other:
I'm using 0.5.1 beta, the issue is that Conversions.GeoToWorldPosition returns non-zero values for the same lat/long the map is centered on.
I.e. MapController is configured to have 37.808596, -122.412537 as Lat Lng. Slippy.Start() has a new line at the end,
Vector2d worldPos = Conversions.GeoToWorldPosition(37.808596, -122.412537, MapController.ReferenceTileRect.Center, MapController.WorldScaleFactor);
For some reason worldPos 40.50900, 41.08352. Am I wrong expecting 0, 0 there?
For example, in a Vector2d
, latitude is the x component and longitude is the y component.
Checking GeoToWorldPosition
and MetersToLatLon
, the components are being swapped at some point. This breaks the usage of Transform.GetGeoPosition()
, for example.
Hi there, I am trying to import the SDK into Unity and tried both the Unity Package and SDK example from the source repo. Unity crashed every time unfortunately. I tried the following platform:
It seems it crashed once it reached the "importing small asset" phase.
Thanks!
Best,
Zhitao
Similar to Transform.GetGeoPosition()
, but does not require a transform.
I exported the Slippy
example to Windows native x64
and panned around for a little less than 1 minute.
During that 1 minute the player used about ~19 seconds CPU time.
Seconds column is CPU time in milliseconds (values are inclusive -> line is the sum of those below it).
JobQueue::WorkLoop
(that executes UnityWebRequest
) and RunGfxDeviceWorker
for almost everything done by RyunThreadWrapper
~9.5sec
PlayerLoop
and Camera:Render
seem to be quite fast: ~2.5sec and 0.9sec
Unfortunately there's also 5sec segment for which no stack trace is available:
Memory usage peaked at ~430MB and it's pretty clear where the lion's share of tiles were loaded:
Did another profile and continuously panned for more than 2 minutes.
Memory usage stayed well below 500MB during the whole time:
On the Mapbox API Token page, the last link that says "Now that your access has been configured, check out the included examples." - the included examples link returns a 404.
https://www.mapbox.com/mapbox-unity-sdk/docs/01-mapbox-api-token.html
Currently there's no built-in way to determine when all HTTPRequests are completed.
Developers can, of course, put in their own method, but this requires modifying the internal HTTPRequest class.
Consider adding a class with a delegate that will fire when all requests have completed. I did this with a simple static Action and int where the int increments with every HTTPRequest construction then decrements in the end of the DoRequest coroutine and when the int is 0 it fires the delegate. However, there's probably a more elegant way of doing this (I was in a rush ;)).
Thanks!
When creating a texture from raw raster tile response data, we should be able to pull from a pool of available texture2ds. This should help prevent memory fragmentation and speed up texture loading times.
@MateoV once we have readme and contributing docs - tag and release a new version.
Lets look at the repo after that PR and version release and see if we're ready to open the repo.
MeshGenerationPois:
get_streamingAssetsPath is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'MapboxConfigurationWindow'.
UnityException: get_streamingAssetsPath is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'MapboxConfigurationWindow'.
How to solve?
Rather than X, Y, Z, W.
I imagine this will be part of the Mapbox->Configure
menu. We should allow developers to choose which memory and file caching strategies they use, and how big they are.
The steps we need to take to set-up Unity Cloud build to work with our submodules setup:
CloudBuild
branchCloudBuild
to our Unity cloud build@BergWerkGIS what is your bandwidth like to set this up?
I use raycasting to place some objects on the 3d map with a correct height. But atm there is no MeshCollider component on the map tiles. That's why raycasting does not work.
If I add MeshCollider in Unity editor when project is playing - everything works. Unity assign the correct mesh in runtime from editor.
But when I try to add MeshCollider from code, MeshCollider component misses the mesh reference.
This code doesn't help.
[RequireComponent(typeof(MeshRenderer), typeof(MeshFilter), typeof(MeshCollider))]
public class UnityTile : MonoBehaviour, INotifyPropertyChanged
{
<...>
void Start()
{
GetComponent<MeshCollider>().sharedMesh = MeshFilter.mesh;
}
}
In earlier SDK versions raycasting worked out of the box. Now I'm using v0.5.1-beta. How can I do it now?
Thanks.
Cheers.
Depending on zoom level and elevation, maps will have varying y
values. This lack of consistency makes it hard to plan camera position.
Alternatively, we could create a camera controller script that tries to align itself to the terrain with a smooth follow.
WIP: https://github.com/mapbox/mapbox-unity-sdk/tree/snapToOrigin
Our API supports requesting textures at 2x, but our SDK does not help with formatting the URL to do so.
We should also offer the ability to compress at runtime in Unity to save memory (at the cost of CPU time during compression), and investigate the ability to load raw data in a compressed format.
It's me again 😈 . Now I can't place objects on the map by their geo coordinates. In earlier version of SDK it worked like a charm, but now it confused me. I'm using version 0.5.1-beta.
For test I created this script:
public sealed class PlaceAtLatLng : MonoBehaviour
{
public double Latitude;
public double Longitude;
private void Update()
{
transform.MoveToGeocoordinate(Latitude, Longitude, Vector2d.zero);
}
}
For example, I set latitude = 55.7481 and longitude = 37.6196. And same values I use in MapController. By idea the object should appear in the center of the generated map. But when I press play button in Unity editor, the object has really wrong position values, smth like (4187795, 0, 7508432).
What do I wrong?
This especially happens if you load the world in low zoom levels like 1 to 5. Root world object y-axis scale goes extremely low and unless TileSize is increased proportionally (i.e. using default 100), Unity cannot render the tile texture.
It renders if world scale y-axis is set to 1 (breaks heights of features&terrain) or TileSize increased to a much bigger number (like 1000 or 100000 depending on zoom level).
Again started this with #23 and implemented the basics at cuttingHoles branch
Implemented these as mesh modifiers. Second one is named "SmoothLine" for now though and that's a horrible name. I guess I'll change that to "IncreaseDataResolution" or something. that line subdivision should be done before terrain snapping though, it's not obvious or checked/forced at the moment.
you can see the effect of subdivision below;
That would look even better as terrain resolution increases as well.
Like this https://github.com/brnkhy/MapzenGo this link is not use mapbox, but it use cache
Update
function simply reruns the factory on registered tile with current settings, generally used to change map imagery on the fly for example.
It's confusing as it's exactly same as the MonoBehviour Update signature.
Can I destory the object outside in my view?
I'll try to note everything and explain a little;
-Cutting holes in buildings
This is an important one. Current system doesn't handle that, actually even constructs holes as if they are building segments as well (not easily noticable as they are inside another mesh). That was because we're passing each geometry to stacks for visualization. I'm working on this at this branch. Main change is I'm passing features to stacks now along with the feature data (properties) and have polygon modifier to cut holes since it has all geometries (including holes) and feature properties now.
-Remove terrain snapping from vector layer visualization
I don't think that's the correct place to do that. My initial idea was to make a modifier out of it and run it first at each stack but then, I can't think of a use case that wouldn't require that either. I mean two reasonable use cases are; (1) create terrain and snap everything to it (2) use flat ground, no need to run snapping code. I think I can make it a modifier but it runs by default without a need to add it to stack. And it wouldn't run if terrain data doesn't exists anyway.
-Using filters for stack selection
Currently we're using a key(property value) and a classification key (property name) to choose stacks. i.e. if classification key
is "type" and key
of the stack is "major"; features with type==major
will be passed into that particular stack. That's quite weak and hard to use and only reason we have it is the inspector/usage problems. I'm planning to use filters for this. Filters have a basic test function that takes feature and returns true/false so they are pretty much created for this job. This will also allow users to create stacks for complex cases as well, like "a stack for commercial buildings higher than 10". I'm still learning inspector stuff so that part might be a little tedious.
-Edge subdivision
Again this is done in vector layer visualizer by default at the moment but I think it might be better if it's a modifier as well. Or maybe it might be a default mod just like snapping above. This simply cuts long edges into smaller pieces so that they won't look horrible on bumpy terrain. Imagine a long straight road (with just two end points) on a bumpy terrain. This cuts that road segment into much smaller pieces so that each vertex can be snapped individually.
~~-Height Modifier
Height modifier supposed to create building volume by pushing to base polygon to a certain height and constructing the side walls. Currently there are some problems with min_height & height calculations for example. I was thinking about breaking it into smaller modifiers for pushing polygon up, building side walls etc but now I think that might be an overkill for now. ~~
-Merging features got cut at tile edges
This is all theoretical but I'm hoping to take a shot at this. I though of something like this last week;
Might have missed some stuff but I'll add them here if I remember something.
Similar to caching tiles in memory, we should also support caching of tiles to disk.
I imagine this would be a different implementation of IAsyncRequest
.
In solving for this, we have to keep in mind the Mapbox ToS:
You may cache Map Assets on end-user devices (e.g., laptops, smartphones, or tablets) for offline use, but each device must populate its cache using direct requests to the Mapping APIs and content from a cache may only be consumed by a single end user. On mobile devices, you may only cache up to the limits set in the Mobile SDKs, and you may not circumvent or change those limits. You may not redistribute Map Assets, including from a cache, by proxying, or by using a screenshot or other static image instead of accessing Map Assets through the Mapping APIs. You may not scrape or download Map Assets in bulk for any purpose other than offline caching on a single end user’s device.
An app can download multiple regions for offline use, but the total offline download is capped at a maximum tile count “ceiling” across all downloaded regions. The tile ceiling is set to 6,000 tiles by default but can be raised for paid plans.
I've tried a few settings for these to get an idea, but they still seem to be a bit of a mystery and I cannot find a reference for them in the documentation. Is there an explanation I'm missing (maybe the API calls it something different)?
As a Unity developer I really need 2 things:
With those 2 things I can easily design my requests to get the tiles I need.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.