Select to view content in your preferred language

CGA Export meshes order

728
1
Jump to solution
09-14-2023 05:03 AM
AdamChełstowski
Emerging Contributor

My current goal is to create a series of points that are next to the road segments, both from left and right side. To accomplish this I tried using special CGA rule on the road and sidewalks that creates these points, then export to the FBX in order to post-process them in Unity.

I also need to specify if the markers are on the left side of the road, or the right side (which was easily done by using different rule for both left and right markers), giving the result as follows:

AdamChestowski_1-1694691971786.png

The problem I am having, is the created meshes order. In the generated fbx file when testing in Unity, it seems it orders them sometimes ok, sometimes a bit random? (ML - Marker Left, MR - Marker Right)

AdamChestowski_2-1694692421749.png

AdamChestowski_3-1694692595739.png

Is there any way to order those markers, so that they would start from 0 at UV - U0? Or Order them in any way so they won't be suddenly 0 in the middle of the exported road?

I am attaching very simple project to replicate my issue, using CityEngine 2021.0.7316.
In order to export markers I also used the MeshGranularity option as "Do not merge any meshes"

0 Kudos
1 Solution

Accepted Solutions
AdamChełstowski
Emerging Contributor

The solution I went with was sorting them myself in Unity later by distance.

By using python in CityEngine, first I found start segment of the road and set special attribute roadStart.
I don't know if there is a better way, but to find start of the road I randomly selected a segment, got its first node by using:

 

ce.getObjectsFrom(currentCheckSegment, ce.isGraphNode)[0]

 

then from all segments I found another segment that uses that node as node [1]:

 

ce.getObjectsFrom(segment, ce.isGraphNode)[1]

 

When there were no more matches, I marked the segment as start of the road and removed all segments that were checked from next searches in case there are other roads.

 

In .cga rule on the roadStart segment I built the first node with different rule MarkerStart and rest as MarkerVertical, to have its name later in Unity post-processing:

 

case roadStart == "yes": 
			split(v,unitSpace,0){ '0.1 : NIL | 
								  0.1 : split(u, unitSpace, 0) { 2 : NIL
								  							   | ~0.1 : [MarkerStart(sidewalkSide)]
															   | ~4 : NIL
															   | {~0.1 : [MarkerVertical(sidewalkSide)] | ~4 : NIL}*
															   | ~0.1 : [MarkerVertical(sidewalkSide)]
															   | 2 : NIL }

 

After exporting from CityEngine and importing the model in Unity, I found object that was called MarkerStart, found all objects named MarkerVertical and sorted them by distance from eachother. As the road in my uses never makes more than 90 degree turn, sorting by distances is more than sufficient.

View solution in original post

0 Kudos
1 Reply
AdamChełstowski
Emerging Contributor

The solution I went with was sorting them myself in Unity later by distance.

By using python in CityEngine, first I found start segment of the road and set special attribute roadStart.
I don't know if there is a better way, but to find start of the road I randomly selected a segment, got its first node by using:

 

ce.getObjectsFrom(currentCheckSegment, ce.isGraphNode)[0]

 

then from all segments I found another segment that uses that node as node [1]:

 

ce.getObjectsFrom(segment, ce.isGraphNode)[1]

 

When there were no more matches, I marked the segment as start of the road and removed all segments that were checked from next searches in case there are other roads.

 

In .cga rule on the roadStart segment I built the first node with different rule MarkerStart and rest as MarkerVertical, to have its name later in Unity post-processing:

 

case roadStart == "yes": 
			split(v,unitSpace,0){ '0.1 : NIL | 
								  0.1 : split(u, unitSpace, 0) { 2 : NIL
								  							   | ~0.1 : [MarkerStart(sidewalkSide)]
															   | ~4 : NIL
															   | {~0.1 : [MarkerVertical(sidewalkSide)] | ~4 : NIL}*
															   | ~0.1 : [MarkerVertical(sidewalkSide)]
															   | 2 : NIL }

 

After exporting from CityEngine and importing the model in Unity, I found object that was called MarkerStart, found all objects named MarkerVertical and sorted them by distance from eachother. As the road in my uses never makes more than 90 degree turn, sorting by distances is more than sufficient.

0 Kudos