Website powered by

Procedurally generating a row of books in Unreal Engine using PCG is fairly straightforward, but handling gaps and calculating lean angles was a fun challenge.

Books 3D Model:
https://www.cgtrader.com/free-3d-models/interior/house-interior/books-collect

I used Shape Grammar because I wanted to stack rows with random books of different thicknesses. To achieve this, I needed to generate the grammar rule procedurally based on the books added in the graph's "Books" parameter.

I used Shape Grammar because I wanted to stack rows with random books of different thicknesses. To achieve this, I needed to generate the grammar rule procedurally based on the books added in the graph's "Books" parameter.

PCG_Bookshelf_CalcLean Graph
This graph loops through all points and calculates the lean angle for each based on its gap distance.

PCG_Bookshelf_CalcLean Graph
This graph loops through all points and calculates the lean angle for each based on its gap distance.

To find the lean angle, I first needed the collision point of the leaning book against the previous one. I used the GetRaySphereIntersection function to determine this point.

To find the lean angle, I first needed the collision point of the leaning book against the previous one. I used the GetRaySphereIntersection function to determine this point.

In RaySphereIntersection, the book’s height is used as the sphere radius by default. However, if the previous book has a steep lean angle, this produces incorrect results because the bottom of the previous book may intersect first.

In RaySphereIntersection, the book’s height is used as the sphere radius by default. However, if the previous book has a steep lean angle, this produces incorrect results because the bottom of the previous book may intersect first.

To fix this, I added another step to check for bottom contact.