Creating Our Own Generative Design Extension in Forma

Creating Our Own Generative Design Extension in Forma

billy_awTVHNJ
Contributor Contributor
1,358 Views
6 Replies
Message 1 of 7

Creating Our Own Generative Design Extension in Forma

billy_awTVHNJ
Contributor
Contributor

Hi Autodesk Forma Team,

Our team was exploring the use of the forma api and we were wondering if we could get some help on some of the following steps and understand what is possible and what is not possible, as well as what other packages we could use to help us (beyond geometry extrude)

 

We want to do the following:

1. Define a polygon region on a specific region in our site
2. Generate multiple buildings in the region without the use of the Data Provider API

3. Buildings should be editable by the user afterwards
4. Generate UI to suggest multiple proposals (similar to the explore tool)

 

For now, we have managed to identify how to define our own specific region and generate a mesh (attached is the screenshot).

The mesh right now is generated however it is classified under generic, "auotmation".

Now we would like to know if its possible to define other objects other than polygon, polylines like buildings.

 

We are happy to speak to a member if that is better! Thank you. 

Accepted solutions (2)
1,359 Views
6 Replies
Replies (6)
Message 2 of 7

trygve_aaberge
Autodesk
Autodesk
Accepted solution

Hi. We don't support all of what you want yet unfortunately, but I'll try to answer what's possible today. It looks like you're using a script generator to generate this, so I'll answer with that context.

 

> as well as what other packages we could use to help us (beyond geometry extrude)

 

I'm not sure if you're asking what packages you can technically use, or what packages we think could be useful for you. There's no limitation on which packages you can use, so you can use any JavaScript package. But I don't think I have any suggestions for which packages could be useful to you.

 

>  1. Define a polygon region on a specific region in our site

 

You managed to do this, if I understood you correctly?

 

> 2. Generate multiple buildings in the region without the use of the Data Provider API

 

For a script generator, it's not currently possible to create multiple elements from one generator, so you'd have to merge all of them into a single mesh.

 

> 3. Buildings should be editable by the user afterwards

 

We don't support this yet unfortunately. The elements created by a generator can only be edited by that generator (except for moving the element itself, which is still possible).


> 4. Generate UI to suggest multiple proposals (similar to the explore tool)

 

It would be interesting to know what kind of UI you want to create. For the generators, you're currently restricted to the input schema described here, which might not support what you want to do. We do have a concept of custom embedded views, but they are not currently tied to the generators.

 

> The mesh right now is generated however it is classified under generic, "auotmation".

 

I see our documentation is lacking here, but the way to classify elements is to set a category in properties (as very briefly mentioned here). So in the return statement in your screenshot, add e.g. `properties: { category: "building" }` alongside `mesh`. We don't have documentation of which categories you can use yet either, but these are the ones that currently exist:

constraints, vegetation, site_limit, zone, building, tree_area, tree_line, road, rails, property_boundary, generic25D, generic2D, generic2DLine

 

Now we would like to know if its possible to define other objects other than polygon, polylines like buildings.

 

I'm not sure if you're asking for the input to or the output from the generator here. To you want to select existing buildings as parameters to your generator, or do you want to create buildings from your generator?

 


Trygve Aaberge
Software Engineer
0 Likes
Message 3 of 7

billy_awTVHNJ
Contributor
Contributor

Hi Trygve,

Really appreciate your speedy reply and detailed feedback to address every single point.

I have applied your feedback to include e.g. `properties: { category: "building" }` alongside `mesh`.
This has worked and resulted to change the 'generic' to ' building'. 

Other than using using return to create a mesh visible, is there any other way to render an object/objects? I would like to control the color of the mesh/object or other properties? 

 

Also, because I am relatively new, I am unsure if I am testing and debugging this right in the right manner: I am testing things out in the generator.js script before bundling it and then hosting it on a local sever, finally testing in Forma. Is there a more efficient or a better way to do this? (according to the sample code).

For your last question, I am actually trying to create buildings from my generator. Since you mentioned that point 3: "

> 3. Buildings should be editable by the user afterwards. We don't support this yet unfortunately. The elements created by a generator can only be edited by that generator (except for moving the element itself, which is still possible)." is not possible"

we will try and work around that. Thanks. 

0 Likes
Message 4 of 7

trygve_aaberge
Autodesk
Autodesk
Other than using using return to create a mesh visible, is there any other way to render an object/objects? I would like to control the color of the mesh/object or other properties?  

You can set a `color` property to set the color. Or you can set a `functionId` property as described here. Though, there is unfortunately no way of getting the custom functions created on a proposal from the generator, so you can realistically only use the default ones. And since you can only create one element, you can't set different colors/functions on different buildings. I also see that the color/function isn't visible in the preview, only when the generator finishes.

 

You can also specify gross floor area polygons alongside the mesh to get your buildings included in the area metric. This is described here.

 

You can also return geojson from the generator instead of a mesh, to create 2D objects on the terrain surface. But it sounds like this isn't relevant to you.

 

 


Also, because I am relatively new, I am unsure if I am testing and debugging this right in the right manner: I am testing things out in the generator.js script before bundling it and then hosting it on a local sever, finally testing in Forma. Is there a more efficient or a better way to do this? (according to the sample code).


If you use a bundler and server which watches the code and rebuilds/reloads on code changes, you can just change the code and then use the generator.

 

For this you can use e.g. esbuild like this:

 

npx esbuild --serve=8080 --bundle --format=esm --outfile=index.js index.ts

 

 

Note that if you edit an existing generated element, the code is only loaded when you select the element. So to use the updated code, you need to deselect the element and select it again to reload the code.


Trygve Aaberge
Software Engineer
0 Likes
Message 5 of 7

billy_awTVHNJ
Contributor
Contributor

Hi Trygve,

 

I have returned a geojson but however I seem to be running into an error because it says

"Failed to store data for generated model. Change some parameters to retry."

 

Also, is it possible to return two objects at one go like a geojson and also a mesh?

 

With regards to the GFApolygons, I am not quite sure how to do that in a script generator. 

I tried to use the https generator but was not successful.... somehow my getBody function had problems runnning. 

0 Likes
Message 6 of 7

trygve_aaberge
Autodesk
Autodesk
Accepted solution

I have returned a geojson but however I seem to be running into an error because it says

"Failed to store data for generated model. Change some parameters to retry."

Take a look in the network tab of the browser developer tools. It should have a request with the response code 400 (which is the request for storing the result to the backend). The response body of this request should give you an error message explaining what the problem is.

 


Also, is it possible to return two objects at one go like a geojson and also a mesh?


No, unfortunately, since it only creates one element you can't return both mesh and geojson, only one of them at the time.

 


With regards to the GFApolygons, I am not quite sure how to do that in a script generator. 

I tried to use the https generator but was not successful.... somehow my getBody function had problems runnning. 


Here is an example of including GFA polygons in a script generator:

import { extrudePolygon } from "geometry-extrude";

export async function runGenerator(input) {
  const { indices, position } = extrudePolygon(
    [[input.values.polygon.points]],
    {
      depth: input.values.height,
    }
  );

  return {
    mesh: {
      verts: position,
      faces: indices,
    },
    properties: {
      areaStatsReps: {
        grossFloorPolygonsV2: [
          {
            grossFloorPolygon: [input.values.polygon.points],
            elevation: 0,
          },
        ],
      },
    },
  };
}

 


Trygve Aaberge
Software Engineer
0 Likes
Message 7 of 7

billy_awTVHNJ
Contributor
Contributor

Thank you!

0 Likes