ProBuilder API - using ProBuilder from script

I am thinking of using ProBuilder for procedural level generation. But it seems there is no API documentation available anywhere. The documentation does not contain any information about the API and FAQ just says “The ProBuilder API is currently considered to be in beta. It will change before the final release.”

There is this ProBuilder API example repository, but it just contains a couple of examples which are not really documented/explained.

So is it really true that there is no any kind of documentation for the ProBuilder API available yet? If so, is there a roadmap for the ProBuilder that would indicate when the API would be officially released and supported?

It’s true that currently there is not any official documentation for the API. However, preparing the code and documentation for public use is what I’ve been doing for the last few months. The 4.0.0 update introduces a public API along with a scripting reference.

There is not a set release date yet, but I anticipate it within the next few weeks.

2 Likes

Thanks for the answer, @kaarrrllll . I have been toying with the API examples and it seems it is quite straight forward in terms of creating geometry. But will the API support all the geometry editing methods as well? In other words, will everything that is possible from the ProBuilder editor GUI be also possible via scripting? What I am especially interested are the boolean operations (which are now marked as experimental).

Yes, everything you can do from the editor is accessible in script (except generating lightmap uvs).

If you’re looking for just the CSG, here’s the library that ProBuilder is using under the hood: GitHub - karl-/pb_CSG: A C# port of CSG.js by Evan W (http://evanw.github.io/csg.js/).

I’ve been playing with CSG and while it does work, it creates a real dogs-breakfast of the mesh after a couple of operations. The tris count skyrockets to the point where it would be unusable on mobile and eventually the mesh breaks catastrophically. It might be fine if we had a solid and efficient way of optimizing/simplifying the mesh between operations, but for my purposes right now it seems unworkable.

Other issues include:

  • Not working with complicated or merged pb_objects, or pb_objects where extrude was used.
  • Losing nice quad face selection ability and can only select triangles.

https://vimeo.com/279211290

    public static pb_Object ExtractIntersection(GameObject source, GameObject stamp)
    {
        var sourcePb = source.GetComponent<pb_Object>();
        var sourceMeshFilter = source.GetComponent<MeshFilter>();
        var originalCenter = sourceMeshFilter.sharedMesh.bounds.center;

        // Create a mesh comprising only parts of the original mesh that overlap with the stamp.
        var intersectionMesh = CSG.Intersect(source, stamp);

        // Create a game object and pb_object from mesh
        var intersectionPb = ProBuilderize(intersectionMesh);

        // Cut out the intersection from the original, so that the original object remains the same visually but is now split into two objects.
        var newMesh = CSG.Subtract(source, intersectionPb.gameObject);

        sourceMeshFilter.sharedMesh = newMesh;

        //// Update the pb_object to reflect changes to the underlying mesh.
        ResetPbObjectWithMeshFilter(sourcePb, true);

        // The modified mesh coming out of CSG probably needs to be repositioned relative to previous pivot.
        var newCenter = sourceMeshFilter.sharedMesh.bounds.center;
        var offset = originalCenter - newCenter;
        var indices = sourceMeshFilter.sharedMesh.GetIndices(0);

        sourcePb.TranslateVertices(indices, offset);
        CenterPivot(sourcePb, indices);

        sourcePb.ToMesh();
        sourcePb.Refresh();

        //pb_Smoothing.ApplySmoothingGroups(sourcePb, sourcePb.faces, 1, pb_Vertex.GetVertices(newMesh).Select(x => x.normal).ToArray());
        //CollapseCoincidentVertices(sourcePb, sourcePb.faces);

        return intersectionPb;
    }

I think we need two things, a mesh simplification function and an easy way to clean a mesh, for example, if i create a rectangle box platform and a circular platform to place on the end of it, drag them over each other, then click a button and it strips all the overlapping parts.

Currently unless i’m missing something, if i use ‘merge objects’ it keeps them intact and if i want to properly merge them i have to go in and edit out all the internal parts manually.

Another related and frustrating thing is that it doesn’t sub-divide faces ‘properly’ when the faces next to them have already been sub-divided and extruded. This is pretty limiting for progressive modifications, we’ll end up having to know in advance and sub-divide everything up front.

In the video there, it knows already that it is a single big square face so it could re-do its layout to 2x2/2 tri

I see. I take that currently ProBuilder API does not expose CSG in any way, but it will be in the future. So right now my only option is to use CSG “in parallel” with ProBuilder?

Yes, that’s correct.

Hi @kaarrrllll , still looking forward to 4.0.0 and the docs!. In particular I’d like to clear smoothing groups and triangulate objects from the API, but I can’t seem to find it. Is this already available in 3.X or do I need to wait for 4.0?

@kaarrrllll Any update on the Probuilder API 4.0?

1 Like

Well…it has been more than 5 months since you posted this, @kaarrrllll =)

Could you maybe post an update on when the next version of ProBuilder with the API is out?

2 Likes

Hi! Well, we’ve learned not to promise dates :slight_smile: Moving along well and getting very close- meanwhile, you can try out the preview packages!

1 Like

Hey hey, is there any news about this? The CSG tools is still experimental and therefore not accessible via the PB API?

Would also love access to the CSG API. Will that be available soon?

2 Likes

I would also like access to booleans like subtract, and also if it does not destroy the mesh like in the example mentioned above…

I can’t see API model export capability via script but if someone knew how to work around it , would much appreciate a share please, cheers!

@Tarrag I don’t think the model export is publicly exposed at the moment, but I will see about making it public in the next update.

The best way to access CSG operations is still via the repository I linked above.

Thanks, that’ll be rad @kaarrrllll ! :slight_smile:

1 Like

Any 2020 news on the API docs?

Thanks

Here is a link to the latest release API docs | ProBuilder | 4.2.4-preview.0

1 Like