MegaShapes Loft Object


The MegaShapes loft object is a layer based system allowing you to build up complex meshes in a simple modular way. This component manages the mesh creation and the layers used to build the mesh, it also merges all the layers into one mesh if possible to keep the number of draw calls to a minimum. To add the component use the ‘Loft’ option found in the GameObject/Create Other/MegaShapes menu. This will automatically add the Loft Object component and the required MeshFilter and MeshRenderer components. When the component is added you will see the inspector for the object. The parameters are described below.

Loft Object Params

Rebuild

Check this box to rebuild the whole object, the value will automatically clear if ‘realtime’ is false, if ‘realtime’ is true the mesh will keep on building every frame.

Realtime

If this is checked then the loft object will rebuild every frame regardless of if anything has changed, most of the time this can be left off as any updates made through the editor will cause the object to rebuild, but if you are controlling the object via script and making changes every frame then setting this value will show those updates.

Up

Some of the layers in the system need a hint as to what direction Up is, usually this can be left as the default but changing this value can have some interesting results on the final mesh generated.

Tangent

This is how far the system will look ahead on a spline when it is calculating forward vectors, the smaller the value the more accurate the forward value will be, use this if you are getting crimping on tight corners, or adjust to get a different look to your lofts.

Tangents

Check this box if you require mesh tangents to be calculated, you need these for bump mapped materials etc.

Optimize

Check this box if you want the mesh optimized by Unity, this can result in slightly quicker rendering but is best used if the mesh isn’t going to be altered as it will slow down the mesh generation slightly.

Bounds

This will cause the bounding data for the mesh to be recomputed after each build. If the overall dimensions of your mesh don’t change then this can be left off but if the loft object is being updated and its size is increasing this should be on.

Collider

The loft system can also update the mesh collider for the object if one is attached, this is a slow operation on complex meshes.

Hide Wire

This will hide the wire frame rendering mode for the object while you adjust its params.

Build Lightmap

If you are going to lightmap your lofts then click this when you are happy with your loft mesh and the light mapping data will be built for the mesh.

Copy

This button will create a fresh copy of the loft object which you can then position and edit in your scene.

Limits

Most of the layers that build the final mesh use start and length values for the along the surface or shape they use and similiar values for across the surface or shape. Sometimes the default range of the sliders in the inspector wont be enough or are too much, so you can adjust the limits of the sliders for all the layers on the object here.

Start Low

Start slider lowest value, default is -1. The layers use a normalized position and length system, so 0 is the very start of the shape 1 the very end.

Start High

Start slider highest value, default is 1

Len Low

Length slider lowest value, default is 0.001. A length of 0 will result in no mesh generated.

Len High

Length slider highest value, default is 2

Cross Start Low

Cross Start slider lowest value, default is -1

Cross Start High

Cross Start slider highest value, default is 1

Cross Len Low

Cross Length slider lowest value, default is 0.001

Cross Len High

Cross Length slider highest value, default is 2

Dist Low

Changes the slider lower limit on the Dist value on the loft layers.

Dist High

Changes the slider higher limit on the Dist value on the loft layers.

CDist Low

Changes the slider lower limit on the CDist value on the loft layers.

CDist High

Changes the slider higher limit on the CDist value on the loft layers.

Stats

This will show the current vertex and tri count for the loft object. There is a limit of 65500 vertices before a mesh is full.

Add Layer

If you click this button a window will pop up allowing you to select the kind of layer you wish to add to the object.

Add Layer Window


The add layer window allows you to select the layer type to add and some basic params for that layer.

Type

This drop down menu allows you to pick the layer type you want to add, when you select a type the description will change in the window of what the layer does and the params below will change depending on the layer type. You don’t need to fill in any params before creating the layer, they are just there for convenience.

Name

Name of the layer, this is useful not only to aid editing the object but also some layers allow you to pick others as their working surfaces, the name of the layer is what will show up in the selection list.

Start

All layers have a start value they use to define where along the shape or surface they are to start.

Length

All layers have a length value that defines are far from the start value the layer extends along the shape or surface.

Param Col

The param col will tint the layer in the inspector making it easier to track down the layer you want to edit if you have a complex object.

Create

Click this button to create and add the new layer to the loft object.

Cancel

This will close the window.

Mega Shape Loft Class

public class MegaShapeLoft : MegaShapeBase
{
    public bool                 realtime        = true;
    public bool                 rebuild         = true;
    public Mesh                 mesh;
    public MegaLoftLayerBase[]  Layers;
    public Vector3              CrossScale      = Vector3.one;
    public bool                 Tangents        = false;
    public bool                 Optimize        = false;
    public bool                 DoBounds        = true;
    public bool                 DoCollider      = false;
    public Vector3              crossrot        = Vector3.zero;
    public Vector3              up              = Vector3.up;
    public float                tangent         = 0.001f;
    public int                  vertcount       = 0;
    public int                  polycount       = 0;
    public float                startLow        = -1.0f;
    public float                startHigh       = 1.0f;
    public float                lenLow          = 0.001f;
    public float                lenHigh         = 2.0f;
    public float                crossLow        = -1.0f;
    public float                crossHigh       = 1.0f;
    public float                crossLenLow     = 0.001f;
    public float                crossLenHigh    = 2.0f;

    public float                distlow         = 0.025f;
    public float                disthigh        = 1.0f;
    public float                cdistlow        = 0.025f;
    public float                cdisthigh       = 1.0f;
    static bool                 updating        = false;

    // Lightmap
    public bool                 genLightMap     = false;
    public float                angleError      = 0.08f;
    public float                areaError       = 0.15f;
    public float                hardAngle       = 88.0f;
    public float                packMargin      = 0.0039f;
}

MegaShapes test scene video

You must be logged in to post a comment.