- Home /
City Engine - Unity: Terrain mismatch
Hi,
I'm importing a terrain from City Engine along with an entire set of FBX models (which compose an entire city). These two assets: heightmap and models are exported in two independent steps although all the necessary data is preserved to make it possible to merge them seamlessly in Unity. However, I'm having difficulties to achieve a correct match between them (houses are "inside" the terrain) as you can see in the image below. Do you have any idea about what can be causing this? City Engine exports the heightmap as a png file and then I convert it to raw using ImageMagick.
EDIT: Trying to debug this process, I have already confirmed that the problem is caused by something related with the heightmap pipeline: CE terrain png export - conversion to raw - Unity terrian import, because if I export the terrain as a mesh in City Engine, its import to Unity matches the other models as expected. I have also tried to do the conversion to raw in Photoshop, to ensure that ImageMagick's command:
convert -flop -depth 16 -endian LSB terrain.png gray:rawTerrain.raw
was not causing the problem, and I confirm that the problem persists with Photoshop conversion.
This also made me notice that the "-normalize" argument in convert was, for some reason, changing the values in the terrain image. I've created a script to check if the image coming from CE was already normalized and it effectively is, so the process of normalizing an already normalized image should not change anything... but it does:
Raw image:
Normalized:
EDIT 2: The reason for this is that -normalize modifier performs a different action than I was expecting (making sure that the color bounds are present in the image).
ImageMagick's normalize documentation
The intensity values are stretched to cover the entire range of possible values. While doing so, black-out at most 2% of the pixels and white-out at most 1% of the pixels.
The command that seems to do what I want is "-contrast-stretch 0" ImageMagick's contrast-stretch documentation
@andresp - it doesn't seem like this question was ever answered. i'm encountering the exact circumstances with terrain heightmaps exported from City Engine. in CE everything lines up nicely and Align to Terrain matches all of the buildings perfectly to the terrain. but when i import the RAW heightmap into Unity, it's all off - even when i place the buildings in the same exact location as they were in C$$anonymous$$ did anyone find a solution to this? THX for the clues ...
Answer by proceduralien · Nov 08, 2011 at 12:52 PM
Hi there,
It seems your issue is that you forgot to align the terrain to the Shapes. Those changes should then be reflected in the exported new terrain png file.
Since there were changes in the terrain, the min/max range may also have changed. Find the new range as follows :
CityEngine 2010.3 : Select the lowest and highest (dynamic) shapes, convert them to static shapes. select the highest vertex of the highes shape and lowest vertex of the lowest shape and in the Inspector, you will find the y-values in the 'vertices' tab. Those two values represent your new min/max range.
CityEngine >= 2011.1 : way 1 : View the metadata of the exported terrain png file, where the new range is stored. Find the data e.g. with this link : http://www.fileformat.info/convert/image/metadata.htm
way 2 : Just drag and drop the terrain into a scene as if you wanted to import a new terrain. Like this, the new range is also extracted and shown in the import window.
hi, first of all thanks for your answer.
Although, this happens despite we'd already aligned the shapes to the terrain and then the terrain to the shapes.
I don't have the 2011 version yet (we are waiting for the license update :)), but your approach for the 2010.3 doesn't seem to work. Your procedure would only give me the lowest and highest altitude of my shapes, not the lowest and highest point of the terrain. I think I would have to add a shape to the lowest and another one to highest point of the terrain (if I happen to know what those points are) and only then perform your instructions to get the terrain height range.
However, in this case, I think the terrain height range shouldn't have been changed as the shapes which alter the terrain are all far from the height interval bounds.
Answer by proceduralien · Nov 08, 2011 at 03:12 PM
Yes, this is of course only the case if all of your terrain is filled with shapes, sorry for missing detail. :)
We dot not know how Unity deals with heightMaps (bitmaps) and how they define terrains in Unity. Though if you're using directly the exported 3D mesh of the terrain, are the polygons aligned correctly ?
nice suggestion, I will try that right away and let you know.
However, I'm not sure if I'll be able to import the terrain mesh because of Unity's 65k vertices limitation. I'll try... :)
after some "fighting" with Blender (terrible UI xD) to cut only a piece of the big terrain, we were finally able to test the terrain mesh, and, as expected, it correctly matches the other models' positioning / height. This implies that the problem resides in the heightmap pipeline: CE export - Image$$anonymous$$agick conversion - Unity import. However, I'm out of ideas to "debug" this procedure. I've tried testing the same use case using a heightmap in Blender but I don't know how to do it there :s
I've tested the same situation by using Photoshop to convert the png heightmap to raw, and I still have the same issues. I've also noticed a strange peculiarity related with the image normalization process. I've edited the main question to reflect these new tests.
Answer by proceduralien · Nov 09, 2011 at 12:31 PM
we have noticed as well that Photoshop sometimes generates faulty image conversions.
is it essential in unity to use the raw format for heightmaps?
give the image conversion another try with a program called imageJ
yes, RAW images are the only way to import a terrain into Unity
I'll try that conversion program.
Additionally I can tell you more about the import in Unity. It asks for the terrain's width (X) and length (Z). I need also to introduce the height delta (Y). These parameters I get from the ones I use inside City Engine. Additionally I also have to tell Unity the raw image dimensions, bit depth and byte order. After this import I move the terrain to its correct place as inside City Engine the terrain is centered in the origin, but inside Unity the terrain is placed with one of its corners in the origin. I translate it by -X/2 and -Z/2 to center it and then move it up to the $$anonymous$$imum height value. I think this is the correct process and should place the terrain in its exact position.
the raw image created by imageJ produces the same results as Photoshop and Image$$anonymous$$agick's images.
Answer by proceduralien · Nov 09, 2011 at 01:24 PM
thanks for explaining the heightmap import into Unity.
When you exported the terrain did you refresh the project?
After the export the folders do not get updated! So it could be that when you use the file in question that it actually isn't the updated version.
hmm it must have been something like that. the person who is responsible for the city engine work (I'm more on the Unity side) just went on holidays yesterday so we had to open the project ourselves and perform the shapes and terrain alignment. The export just worked as expected, i.e., what we see in City Engine is what we get in Unity. The only problem is now related with the way City Engine aligns the terrain. In this case I think a picture is really worth a thousand words so I took a screenshot of the issue: http://i.imgur.com/2jNs8.jpg
As you can see the problem occurs even inside City Engine. Do you know why this happens? Is there any way to fix it?
P.S.: I understand that this is now a problem only related with City Engine, for which we have a Gold Subscription, but as the discussion started here, I'm answering it here (if you want I can fill a support ticket with this question).
P.S.2: Obviously, I'm considering you work at Procedural.
Answer by proceduralien · Nov 10, 2011 at 02:42 PM
Hi,
Just thinking, if you are under a GOLD subscription you are eligble to update to CityEngine 2011. In the new version a lot of the terrain stuff is now a lot easier: http://www.procedural.com:9099/help/topic/com.procedural.cityengine.help/html/manual/al/terrain/terrain.html
Is it an option for you to update and try exporting your model again?
How can we update to the newest version? I can't find that option in the user area