Runtime API

Teddy provides an API that can be used at runtime.

TeddyUtility.CreateMesh

a utility function that returns Mesh which is a three-dimensional representation of the contour line defined by the 2D point array passed as an argument.

public static Mesh CreateMesh(List points, int nFaces, float thickness = 0.9f, bool smooth = true)

Parameters

Example

            // Create 3D Mesh from noise applied circumference.

            using System.Collections;
            using System.Collections.Generic;

            using UnityEngine;

            using Teddy;

            public class Example : MonoBehaviour {
                public float radius = 1f;
                void Start () {
                    var points = new List<Vector2>();
                    var pi2 = Mathf.PI * 2f;
                    for(float r = 0f; r < pi2; r += (pi2 / 20f)) {
                        var x = Mathf.Cos(r);
                        var y = Mathf.Sin(r);
                        points.Add((new Vector2(x, y)).normalized * (1.0f + radius * Mathf.PerlinNoise(r, 0f)));
                    }
                    var filter = gameObject.AddComponent<MeshFilter>();
                    filter.sharedMesh = TeddyUtility.CreateMesh(points, 600, 0.85f);
                }
            }