Thanks for the response, but I guess I am not using it as you would regularly. 😉Okay so I understood the insert rules for streets having studied the modern streets examples they were helpful, and tally with your post.I needed to create broken streets, I am not using the city engine street geometry as output. This is almost the solution, I need to work on the spacing of the instances I am placing as they are currently butted to each other.I would like to space them out a little more, so adding some random variance to one of the splits should do it.The importance here is the random selection of a new instance at each recursion whilst filling the street.This is also interesting as it shows how cityEngines Rules generate nodes and get added to the execution stack and how different it is to normal code execution.
/**
* File: streetTest.cga
* Created: 20 Aug 2012 18:28:49 GMT
* Author: rhexter
*/
version "2011.2"
//attribute and function to randomly select a street section for insertion
//- lengths are unitized to 25m sections
//- x4 represents the number of lanes, could be a varible
attr streetAsset = "asset"
setStreetAsset = "assets/road_details/Street_"+listRandom("Short;Medium;Long")+"_x4" + ".obj"
// attribute to kick off our knowledge of streetsectionlength
@Hidden
attr streetModelUDim=0
PlaceInstance(asset) -->
/*
Inserts the selected model asset
*/
//Provide some Feedback
print ("PlaceInstance: In")
print ("Placing \"asset\": \n\t" + asset)
print ("InstanceLength: \n\t" + assetInfo(asset, sz))
alignScopeToGeometry(yUp, 0, 0)
s(0,0,0)
center(xz)
r(scopeCenter, 0, 89, 0) // skew'd for easy visual reading of section placements
i(asset)
print ("PlaceInstance: Out")
PlaceStreetPiece(streetModel, streetModelLen, remainingStreetUDim) -->
/*
This leaf is recursive:
In one side of the split it:
- inserts a preselected model,
(because we know the udimension of it and it fits the street)
- in the other:
- it chooses a new random model
- checks if it fits the remaining street udimension
- passes it to its-self to place
rinse/repeat
*/
print ("*-----------------------------------------*")// iterator section feedback break
print ("PlaceStreetPiece: In")
split(u,unitSpace,0)
{
streetModelLen:
//Place the streetModel previously choosen here, cos we know it fits
PlaceInstance(streetModel)
print ("RemainingStreetLength: \n\t" + remainingStreetUDim)
|// split
remainingStreetUDim :
//Work out our next model to place that will fit within our remaining streetUDimension
print ("-----------------------------------------")// iterator section feedback break
print ("-----Try to pick a new Random \"Model\"----")
set(streetAsset, setStreetAsset) // randomly pick a new model for next iteration placement
print ("Chosen streetModel: " + streetModel)
[
case assetInfo(streetAsset, sz) < remainingStreetUDim:
// if our chosen model fits, place it
PlaceStreetPiece(
streetAsset, //the next chosen streetModel
assetInfo(streetAsset, sz), // streetModelLength
(remainingStreetUDim-assetInfo(streetAsset, sz)) // the remaining StreetUDimension
)
else:
print ("-----------------------------------------")// iterator section feedback break
print ("StreetModel Did not fit " + streetAsset)
print ("-----------------------------------------")// iterator section feedback break
NIL
]
}
print ("PlaceStreetPiece: Out")
print ("*-----------------------------------------*")// iterator section feedback break
attr dim = 1.0
attr markerDim=2.0
Street -->
/*
Begin to fill the streets with streetAssets
Set an initialModel here:
- we need know its length
-- we need this information to setup and pass in
the recursive leaf's values
*/
set(streetAsset, setStreetAsset)
set(streetModelUDim, assetInfo(streetAsset, sz))
//Feedback
print ("Start streetAsset: " + streetAsset)
print ("Start streetModelUDim: " + streetModelUDim)
split(v,unitSpace,0)
{
~dim: NIL
|
markerDim:
// PlaceStreetPiece(streetAsset, streetModelUDim, remainingStreetUDim)
PlaceStreetPiece(streetAsset, streetModelUDim, geometry.du(0,unitSpace)- assetInfo(streetAsset, sz))
|
~dim: NIL
}