Can someone help me with the cga code to convert a line into a tunnel in CityEngine?
Here's a simple one I made. You could use some recursion to make smooth arcs, but I try to keep the poly count low. Only works on straight lines, unfortunately. Change the nodes to crossings.
version <SPAN class="string token">"2016.0"</SPAN> attr shapeType <SPAN class="operator token">=</SPAN><SPAN class="string token">""</SPAN> attr streetWidth <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> attr sidewalkWidthLeft <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> attr sidewalkWidthRight <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="keyword token">import</SPAN> EsriStreets<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"/ESRI.lib/rules/Streets/Street_Modern_Standard.cga"</SPAN> @StartRule Lot <SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> case shapeType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"Street"</SPAN><SPAN class="punctuation token">:</SPAN> MakeTunnel EsriStreets<SPAN class="punctuation token">.</SPAN>Street case shapeType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"Sidewalk"</SPAN><SPAN class="punctuation token">:</SPAN> EsriStreets<SPAN class="punctuation token">.</SPAN>Sidewalk <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>NIL MakeTunnel <SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> extrude<SPAN class="punctuation token">(</SPAN>streetWidth<SPAN class="operator token">/</SPAN><SPAN class="number token">1.2</SPAN><SPAN class="punctuation token">)</SPAN> alignScopeToGeometry<SPAN class="punctuation token">(</SPAN>zUp<SPAN class="punctuation token">,</SPAN> any<SPAN class="punctuation token">,</SPAN> world<SPAN class="punctuation token">.</SPAN>lowest<SPAN class="punctuation token">)</SPAN> s<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'1,streetWidth+sidewalkWidthLeft+sidewalkWidthRight+2,'</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN> t<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="operator token">*</SPAN><SPAN class="punctuation token">(</SPAN>sidewalkWidthLeft<SPAN class="operator token">/</SPAN><SPAN class="number token">2</SPAN><SPAN class="operator token">+</SPAN>sidewalkWidthRight<SPAN class="operator token">/</SPAN><SPAN class="number token">2</SPAN><SPAN class="operator token">+</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> color<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> rotateScope<SPAN class="punctuation token">(</SPAN><SPAN class="number token">45</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> split<SPAN class="punctuation token">(</SPAN>y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> NIL <SPAN class="operator token">|</SPAN> <SPAN class="operator token">~</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> OuterSplit1 <SPAN class="punctuation token">}</SPAN> OuterSplit1 <SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> rotateScope<SPAN class="punctuation token">(</SPAN><SPAN class="number token">90</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> split<SPAN class="punctuation token">(</SPAN>y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> NIL <SPAN class="operator token">|</SPAN> <SPAN class="operator token">~</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> InnerSplit1<SPAN class="punctuation token">}</SPAN> InnerSplit1 <SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> color<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> rotateScope<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">45</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> split<SPAN class="punctuation token">(</SPAN>y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> Wall <SPAN class="operator token">|</SPAN> <SPAN class="operator token">~</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> InnerSplit2<SPAN class="punctuation token">}</SPAN> InnerSplit2 <SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> color<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> rotateScope<SPAN class="punctuation token">(</SPAN><SPAN class="number token">90</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> split<SPAN class="punctuation token">(</SPAN>y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> Wall <SPAN class="operator token">|</SPAN> <SPAN class="operator token">~</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> InnerSplit3 <SPAN class="operator token">|</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> Wall<SPAN class="punctuation token">}</SPAN> InnerSplit3 <SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> rotateScope<SPAN class="punctuation token">(</SPAN><SPAN class="number token">225</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> split<SPAN class="punctuation token">(</SPAN>y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> Wall <SPAN class="operator token">|</SPAN> <SPAN class="operator token">~</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> InnerSplit4 <SPAN class="punctuation token">}</SPAN> InnerSplit4 <SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> rotateScope<SPAN class="punctuation token">(</SPAN><SPAN class="number token">90</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> split<SPAN class="punctuation token">(</SPAN>y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> Wall <SPAN class="operator token">|</SPAN> <SPAN class="operator token">~</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> NIL <SPAN class="punctuation token">}</SPAN> Wall <SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> color<SPAN class="punctuation token">(</SPAN>"<SPAN class="comment token">#BBBBBB")</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
LR, much appreciated. Apologies! Did not make myself clear enough. I was looking for a railway tunnel - cylindrical in nature.
Here's a basic approach for a hollow cylinder - I insert a disc, move/extrude it and then delete the center. Again, straight lines only.
version <SPAN class="string token">"2016.0"</SPAN> attr shapeType <SPAN class="operator token">=</SPAN><SPAN class="string token">""</SPAN> attr TunnelLength <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> @StartRule Lot <SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> case shapeType <SPAN class="operator token">==</SPAN> <SPAN class="string token">"Street"</SPAN><SPAN class="punctuation token">:</SPAN> MakeTunnel <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>NIL MakeTunnel <SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> set<SPAN class="punctuation token">(</SPAN>TunnelLength<SPAN class="punctuation token">,</SPAN> scope<SPAN class="punctuation token">.</SPAN>sx<SPAN class="punctuation token">)</SPAN> alignScopeToGeometry<SPAN class="punctuation token">(</SPAN>zUp<SPAN class="punctuation token">,</SPAN> any<SPAN class="punctuation token">,</SPAN> world<SPAN class="punctuation token">.</SPAN>lowest<SPAN class="punctuation token">)</SPAN> primitiveDisk<SPAN class="punctuation token">(</SPAN><SPAN class="number token">20</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">5</SPAN><SPAN class="punctuation token">)</SPAN> center<SPAN class="punctuation token">(</SPAN>xyz<SPAN class="punctuation token">)</SPAN> r<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">90</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN> t<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">-</SPAN>scope<SPAN class="punctuation token">.</SPAN>sx<SPAN class="operator token">/</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN>TunnelLength<SPAN class="operator token">/</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN> extrude<SPAN class="punctuation token">(</SPAN>TunnelLength<SPAN class="punctuation token">)</SPAN> setback<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN>all<SPAN class="punctuation token">:</SPAN> TunnelColor <SPAN class="operator token">|</SPAN> remainder<SPAN class="punctuation token">:</SPAN> NIL<SPAN class="punctuation token">}</SPAN> TunnelColor <SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> color<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Thanks Ivan,
Where have you been?
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.