willychyr 0 Report post Posted July 24, 2014 Hi All, I'm looking into using procedural generation to make levels and objects, and wanted to know if there's a ProBuilder scripting API for this? My specific goal is to have a script spawn and place boxes of different sizes around the scene. I know how to do this with the default Unity cubes, by just using GameObject.CreatePrimitive(PrimitiveType.Cube); And then changing its position and scale. However, I'd like to do it with ProBuilder cubes, so that I can edit them by hand. Also, I'd like to not use scale, but use the extrude face function, for having cubes of different sizes. Any help would be greatly appreciated. Thank you! - Willy Share this post Link to post Share on other sites
GabrielW 60 Report post Posted July 24, 2014 Thanks for posting here Willy, Karl should have the real knowledge of this one, I'll let him answer in-depth. Looking forward to what you end up creating here... Share this post Link to post Share on other sites
karl 321 Report post Posted July 25, 2014 Here's a quick script to show how you would instantiate a ProBuilder cube and modify the size using either extrusion or translation. using UnityEngine; using System.Collections; using ProBuilder2.Common; using ProBuilder2.Math; using ProBuilder2.MeshOperations; public class SpawnCube : MonoBehaviour { pb_Object pb; public void Start() { pb = ProBuilder.CreatePrimitive(Shape.Cube); } void OnGUI() { if(GUILayout.Button("Grow")) { foreach(pb_Face face in pb.faces) { // move all faces .5 meters pb.TranslateVertices(face.distinctIndices, pb_Math.Normal(pb.GetVertices(face.distinctIndices)) * .5f); } pb.Refresh(); } if(GUILayout.Button("Extrude")) { // extrude all faces .5 meters foreach(pb_Face face in pb.faces) pb.Extrude(new pb_Face[] {face}, .5f); pb.Refresh(); } } } Share this post Link to post Share on other sites
willychyr 0 Report post Posted July 25, 2014 Hi Karl, Thanks for the response and for the example script. I tried running it, but I'm getting the error that "The name `Shape' does not exist in the current context"' for the line pb = ProBuilder.CreatePrimitive(Shape.Cube); And "`ProBuilder2.Math.pb_Math' does not contain a definition for `Normal'" for the line: pb.TranslateVertices(face.distinctIndices, pb_Math.Normal(pb.GetVertices(face.distinctIndices)) * .5f); Going through the ProBuilder folder, I found the API Projects, and tried to run the scene 'pbObjectInstantiate', but actually got the same errors. Share this post Link to post Share on other sites
willychyr 0 Report post Posted July 25, 2014 Ok, so it turns out I actually had to use this 'Probuilder.Shape', instead of just 'shape'. pb = ProBuilder.CreatePrimitive(ProBuilder.Shape.Cube); and 'PlaneNormal' instead of 'Normal' pb.TranslateVertices(face.distinctIndices, pb_Math.PlaneNormal(pb.GetVertices(face.distinctIndices)) * .5f); After this, I realized I may not have the same version, I'm using 1536 instead of r1536. Will update now. Share this post Link to post Share on other sites
karl 321 Report post Posted July 25, 2014 Sounds like you've figured out the errors on your own, but just thought I'd chime in to say the latest version is rv2321 (2.2.5f6). There have been a lot of API changes since 1536, most of which are an attempt to standardize the style of calls to ProBuilder methods. Share this post Link to post Share on other sites
GabrielW 60 Report post Posted July 26, 2014 Oh myyy. r1536 is ancient! Send me an email if you need the latest build. I'd recommend jumping into the Beta, honestly- it's rockin' good. Share this post Link to post Share on other sites
Zplintz 7 Report post Posted July 28, 2014 Oh myyy. r1536 is ancient! Send me an email if you need the latest build. I'd recommend jumping into the Beta, honestly- it's rockin' good. I second that. There aren't enough expletives to describe how good it is. 1 karl reacted to this Share this post Link to post Share on other sites
blit 2 Report post Posted September 22, 2014 Hi, I was trying to extrude some faces on my mesh using the pb.Extrude call shown in the example above but this is not a valid api call anymore. Could someone tell me what the correct way to extrude faces is now in the latest build of ProBuilder? Share this post Link to post Share on other sites
GabrielW 60 Report post Posted September 22, 2014 I would take a look through this brand-new tutorial just sent out by Karl: http://paraboxstudios.com/blog/blog_entry.html?2014-09-19=PipeDreams.html Share this post Link to post Share on other sites
blit 2 Report post Posted September 22, 2014 I would take a look through this brand-new tutorial just sent out by Karl: http://paraboxstudios.com/blog/blog_entry.html?2014-09-19=PipeDreams.html Just had a look at this tutorial but it still references pb.Extrude(). I don't seem to have that method when referencing my pb object. pb_Object pb = GetComponent<pb_Object>(); // Call the Extrude extension method by passing an array of faces to extrude, and a distance. // You may even omit the distance paramter and ProBuilder will extrude using a default value. pb.Extrude( new pb_Face[] { pb.faces[0] }, 1f); Share this post Link to post Share on other sites
blit 2 Report post Posted September 22, 2014 In case anyone is as foolish as I was - I didn't have the "using ProBuilder2.MeshOperations;" Sorry! It's working now! 2 ErikH2000 and karl reacted to this Share this post Link to post Share on other sites
GabrielW 60 Report post Posted September 25, 2014 Thanks for updating with the answer, blit! Share this post Link to post Share on other sites
Claire Hosking 0 Report post Posted August 30, 2015 Hi, I was wondering if it's possible to do the same using Prototype? I'd like to test some possibilities for proc gen before going for the whole suite Share this post Link to post Share on other sites
karl 321 Report post Posted August 30, 2015 Yup, all of the functionality in Prototype is also accessible via API. Share this post Link to post Share on other sites
Claire Hosking 0 Report post Posted August 30, 2015 Good to know! Are there any differences? What would I need to change in the code to get this to work? Share this post Link to post Share on other sites
karl 321 Report post Posted August 31, 2015 The only differences being that the ProBuilder-only functionality is not available (ex, subdivision, welding, etc). Share this post Link to post Share on other sites
Claire Hosking 0 Report post Posted September 1, 2015 Oh, excellent! I've heard that probuilder comes with an example script for basic stuff with the api, but I can't seem to find it in prototype, do you know where I would find info for this? I did try hunting around but I'm a bit new to all this, I'll admit. Share this post Link to post Share on other sites
karl 321 Report post Posted September 1, 2015 Prototype doesn't usually ship with the API examples, but here's a tutorial that I believe should work just fine with Prototype: http://parabox.co/blog/blog_entry.html?2014-09-19=PipeDreams.html Share this post Link to post Share on other sites