Jump to content
deltamish

Use Poly Shape tool with Custom script

Recommended Posts

Hey ,

I was working on a runtime simulation tool for which I wanted to use the pb_Poly shape to allow user to create meshes of any shape dynamically 
 
So decided to appent points  in pb_poly shape manually 
Inline image 1
 
Problem is the points are not getting connected at the end. And thus no poly is drawn 
 
Could you be kind enough to let me know how to go around this 
 
thanks 
 
Regards 

Share this post


Link to post
Share on other sites

At the moment the poly shape functions are not in the public API. I've exposed them for the next update (3.0.2) and will include an API Example showing how to use it.

Edit - If you're using the Asset Store version of ProBuilder this might actually work. I haven't tested it.

 

using UnityEngine;
using ProBuilder.Core;
using ProBuilder.MeshOperations;

namespace ProBuilder.Examples
{
	public class CreatePolyShape : MonoBehaviour
	{
		public float m_RadiusMin = 1.5f;
		public float m_RadiusMax = 2f;
		public float m_Height = 1f;
		public bool m_FlipNormals = false;

		pb_Object m_Mesh;

		void Start()
		{
			// Create a new GameObject
			var go = new GameObject();

			// Add a pb_Object component (ProBuilder mesh data is stored here)
			m_Mesh = go.gameObject.AddComponent<pb_Object>();

			InvokeRepeating("Rebuild", 0f, .1f);
		}

		void Rebuild()
		{
			// Create a circle of points with randomized distance from origin.
			Vector3[] points = new Vector3[32];

			for (int i = 0, c = points.Length; i < c; i++)
			{
				float angle = Mathf.Deg2Rad * ((i / (float)c) * 360f);
				points[i] = new Vector3(Mathf.Cos(angle), 0f, Mathf.Sin(angle)) * Random.Range(m_RadiusMin, m_RadiusMax);
			}

			// CreateShapeFromPolygon is an extension method that sets the pb_Object mesh data with vertices and faces
			// generated from a polygon path.
			m_Mesh.CreateShapeFromPolygon(points, m_Height, m_FlipNormals);
		}
	}
}

 

Share this post


Link to post
Share on other sites

Hey sorry for the delayed response.

Solved the issue it was just I had missed out the following lines and had to add first point again 

pb_object.ToMesh();
pb_object.Refresh();

 

Thank you so much for the circle example will use that in my project ;) 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×