Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

MegaShapes advanced Lofter and spline based mesh builder.

Discussion in 'Assets and Asset Store' started by SpookyCat, Jun 14, 2012.

  1. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    Just submitted a small update to the AssetStore, this just includes the demo scene for the RigidBody object being controlled from a path. Alan over at www.uistudios.com very kindly said we could include the free Toon Sports Car asset from the Asset Store so we could make the scene available. The scene and the scripts are just examples for how to use the MegaShapes API to do different controls for objects, it is meant for you to take and adapt the ideas and code to suit your own needs or game requirements. The scene also includes the Wheel Control script which rotates and turns the wheels on the car to match its speed and turning. Below is the video to remind you want the scene is.

    As I said above the Toon Sports car was kindly provided by www.uistudio.com and you can get that asset direct from the asset store as well, or visit www.uistudio.com for more fun vehicles and game objects.

    Changes in v2.09
    • Added a new demo scene to show a RBody being controlled by a spline.
     
    elbows likes this.
  2. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Hi there, i think i'm getting a parsing error regarding the OSM import interface to the tune of

    This was upon trying to import an osm map from the osm website, thankyou for any help you can offer
     
  3. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    Can you submit a support ticket with the OSM file so I can take a look, I tested it with files from the OSM website for my area and all was fine so intrigued as to what could be different in different areas.
     
  4. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    Seems the id values in OSM files with a lot of nodes can exceed the range of an int value, changed the OSM importer to use ulong instead and all is working fine on your test case. Will submit an update soon.
     
  5. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Thankyou for the swift response
     
  6. Katzelschnurr

    Katzelschnurr

    Joined:
    Mar 25, 2011
    Posts:
    28
    Hi!
    I have a shape with the "Make Mesh" option turned on and i need to have lightmap coordinates for the generated mesh.
    I did not find a way to do this within the mega shape component, can someone help me out?
     
  7. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    @Katzelschnurr - If you can submit a support ticket at the website we can help you out.
     
  8. Katzelschnurr

    Katzelschnurr

    Joined:
    Mar 25, 2011
    Posts:
    28
    Thanks!
    In managed to do a quick work around by adding a updateMesh boolean field in MegaShape.cs/MegaShapeEditor.cs and a component that builds a second uv set and immediately disables mesh regeneration afterwards. Seems to work well enough for now for my purpose.
     
  9. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    I have added support for the creation of Lightmap data for the basic meshing options of MegaShapes, it will be in the next update which will be in the store in a day or two after testing.
     
  10. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    Just submitted a small update to the store which brings the Lightmap support for basic spline meshes and a fix for the OSM importer to handle more complex files.

    Changes in v2.10
    • You can now build lightmap data for MegaShape standard meshes.
    • Changed OSM importer to use ulong for ids instead of int so can now handle complex OSM files.
     
  11. Katzelschnurr

    Katzelschnurr

    Joined:
    Mar 25, 2011
    Posts:
    28
    Thanks for adding the feature so quickly :)
     
  12. hu_manus

    hu_manus

    Joined:
    Jun 3, 2014
    Posts:
    2
    I bought mega shapes and i have problem with twist my Lofted shape.
    When I move twist knots my loft dosent react.
    Can You help me solv this?

    Thanks
     
  13. hu_manus

    hu_manus

    Joined:
    Jun 3, 2014
    Posts:
    2
    Ok i found solution. In loft options i should check use twist. :)
     
  14. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    Sorry the Unity forum notifications are not very good, glad you found the checkbox, always best to submit a support ticket for a quick response to any issues :)
     
  15. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    Small update submitted to the Asset Store, this makes MegaShapes compatible with the changes made in Unity 5.1 and 5.2 regarding newly obsolete methods etc.

    Changes in v2.11
    • Changes for Unity 5.1, removal of obsolete items etc.
    • Fixed CrossSection lines not showing for Complex layer type.
     
  16. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    Has there been any progress on the infinite runner type lofts / splines?
    The butt of one spline, and the start of the next spline would be melded together, duplicating the previous / next node data I assume.
     
  17. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,347
    Hi,
    I´d like to build a little 3D-Runtime-Nodesystem, where nodes are connected with bezier curves.
    I have MegaFiers and want to use the included MegaShapes Basic to render the 3D-curves.
    Unfortunately I don´t find any examplescript or any solution on how to create multiple non-connected splines (ribbon-meshed)
    in one Megashape. The mesh only applies to one spline and is terribly twisted:



    Any help is very welcomed, thanks!
    Carsten

    (PS:
    2nd question: Are InTangents/Outtangents in worldspace?
    In localspace to its knot a tangent like (1,0,0) would always point one unit the right, regardless of where the knot is positioned.)
     
    Last edited: Jul 21, 2015
  18. amorrow68

    amorrow68

    Joined:
    Aug 10, 2015
    Posts:
    8
    Anyone have examples using this for jumps in a racing game? Could you make an over and under bridge? Like a figure 8 race track.

    Thanks
     
  19. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    @Cascho01 The knot and tangent values are in the local space of the spline object. The API has methods to set the knot values from an array of WorldSpace Vector3 values and it will generate the handles for you based on the smoothing value. There are also methods for moving Knots and or each knots handles.

    @amorrow68 The system can do figure of 8's etc with no problem but you will likely need to join the lofts up to a bridge object if you need a proper bridge, but if you have your bridges, tunnels etc already in place it would be no problem making the track mesh go through or over the in place objects.
     
  20. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    Again just wanted to say the best way to get an answer on any problems or help with MegaShapes is to submit a support ticket at the website.
     
  21. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    Just submitted a new version to the AssetStore, this updates fixes a bug in the Lathe system where the normals were flipped, also fixes an exception that happened if you were using a loft layer that did not use a cross section spline, and another exception when trying to use a spline with no knots in it. We also added the Conform option to all the Clone Spline layer types and the scatter spline type so making it much easier to add fences, walls etc to terrains or other ground meshes.

    Changes in v2.13
    • Fixed exception in inspector if you happen to create a spline with no knots in it.
    • Added option to turn of the autosmooth when a new knot is added to the spline.
    • Also added the AutoCurve option when the Add Knot button is clicked
    • Fixed bug in the Lathe system where normals were pointing the wrong way
    • Fixed exception bug in the spline notify system that could appear when loft layers which do not use crosssections are used.
    • Added conform option to the Clone spline layer so can now easily make fences etc fit the terrain
    • Added conform option to the Clone spline Rules layer so can now easily make fences etc fit the terrain
    • Added conform option to the Clone spline Simple layer so can now easily make fences etc fit the terrain
    • Added conform option to the Scatter spline layer so can now easily make fences etc fit the terrain
     
    MikeUpchat likes this.
  22. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Hey does this have a large performance overhead? I'm looking to buy it but the performance in the demo is so poor and the way the controls work make it impossible to turn off the image effects(The f keys do things in IE). I'm working on a mobile title that requires high performance even on low end IOS and Android devices. Could you do a build of the demo with all the image effects and stuff turned off?

    Thanks :D
     
  23. Andy-StudioBuzzword

    Andy-StudioBuzzword

    Joined:
    Nov 26, 2012
    Posts:
    4
    Hi, I have an issue I'd like help with but to submit a support request I need to provide the invoice number.
    Where can I find this? I've got the license in my list of licenses (bought it about a year ago) in the unity store but it doesn't offer any other information and I can't find any emails :S
    Thanks!
     
  24. DougMcFarlane

    DougMcFarlane

    Joined:
    Apr 25, 2009
    Posts:
    197
    I just checked, and found an old email sent by Unity when I purchased this asset.
    It included a PDF invoice, which has the invoice number.

    [Edit] Since you said you can't find your email, I'd contact Unity and get one resent.
     
  25. fivebits

    fivebits

    Joined:
    Feb 4, 2015
    Posts:
    9
    Hi, wondering if I could get some guidance.

    I've bought a few rope plug-ins that have not turned out to work well for my problem. I want to give MegaShapes a try if I can get some answers.

    Basically what I want is a rope between two points. The rope will dangle, then I'm going to spin it around a central axis (not the rope's central axis, but an axis between the two points. I'm trying make a jump rope.

    Every other solution I've tried has failed so far, and I don't wanna purchase MegaShapes and find out it also won't work, but if I can get some info on if it will work for this situation, that would help me a lot.

    Thanks,
    - Ricardo
     
  26. Steel-Grin

    Steel-Grin

    Joined:
    Aug 28, 2013
    Posts:
    16
    Hi,

    I'm looking to make a 3D Platformer and am interested in seeing if MegaShapes could be used to help create the levels.. I've watched most of the videos and I've seen there's an ability to convert a spline to a mesh and fill it in. However, is it possible to do something similar with a loft?

    Essentially I want to do an Arc Shape and then fill it in, similarly to the ground in this picture from Mario:


    I don't want a path around an arc, but the full thing filled in as a path with the ability to use the clone layer for adding in a fence, etc. Would that be possible? I could not find much on the website or the videos about that.

    Would MegaShapes be worth looking into to create a 3D Platformer in a similar style to the screenshot above or is it more strictly race related?

    Thanks!
     
    Last edited: Nov 2, 2015
  27. Rod-Galvao

    Rod-Galvao

    Joined:
    Dec 12, 2008
    Posts:
    210
    Hi,

    Pre-sales question:

    Is it possible to use Megashapes to create aligned tracks with these assets bellow?

    https://www.assetstore.unity3d.com/en/#!/content/35648

    Is MegaScatter fully included with it? If not, what would be the reason to buy it separately?

    Regards,
    Rod
     
  28. vrWiz

    vrWiz

    Joined:
    Nov 5, 2014
    Posts:
    13
    I have just bought the Mega Shapes two days ago, I am struggling to realize how to make something like this cow demo.
    How can you move and object along a track and also make it move on the width of the track. like in the cow demo, the rigidity body demo is just going backwards or forward
     
  29. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    @Rod Galvao - No problem using those assets, I did a quick test with a straight piece which can be seen in the grab below. MegaScatter is a separate package for scattering a lot of objects on other objects using splines to define the areas, there is a scatter layer in MegaShapes so you can scatter objects onto lofts but if you want to generally scatter things with a lot more options then you would need MegaScatter.
    minetrack.jpg

    @TzahiGames - If you could maybe submit a support ticket at the website we can help you out.

    Also it is far better to submit a support ticket at the website if you need any help etc as we just don't get notifications from Unity for most forum posts.
     
  30. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    @Steel Grin - Sorry missed your post, that is a tricky thing to create with a lofter, the system could certainly be used to do the fencing but the main levels is really a job for a proper 3d editor, lofts are more suited to things like tracks, or long winding levels etc.
     
  31. Rod-Galvao

    Rod-Galvao

    Joined:
    Dec 12, 2008
    Posts:
    210
    Hi,

    I'm trying to adapt your DrawSpline code to build the rail track above dynamically.

    I added the following code to FinishSpline():

    Code (CSharp):
    1.         GameObject loftObj = new GameObject();
    2.         loftObj.name = name + " - Loft " + (splinecount-1);
    3.         loftObj.transform.position = transform.position;
    4.        
    5.         MegaShapeLoft loft = loftObj.AddComponent<MegaShapeLoft>();
    6.         loft.realtime = false;
    7.         loft.DoCollider = true;
    8.        
    9.         MegaLoftLayerCloneRules trackLayer = loftObj.AddComponent<MegaLoftLayerCloneRules>();
    10.         trackLayer.LayerName = "Track " + (splinecount-1);
    11.         //trackLayer.loftcols = new Color[] { new Color(109, 63, 41) };
    12.         trackLayer.surfaceLoft = loft;
    13.         trackLayer.Length = 1f;
    14.         trackLayer.layerPath = cshape;
    15.        
    16.         MegaLoftRule endrule = new MegaLoftRule();
    17.         endrule.enabled = true;
    18.         endrule.scale -= new Vector3(0.2f, 0f, 0f);
    19.         endrule.rulename = "End Cap";
    20.         endrule.obj = trackStartEndCap;
    21.         endrule.type = MegaLoftRuleType.End;
    22.         trackLayer.rules.Add(endrule);
    23.        
    24.         MegaLoftRule startrule = new MegaLoftRule();
    25.         startrule.enabled = true;
    26.         startrule.scale -= new Vector3(0.2f, 0f, 0f);
    27.         startrule.rulename = "Start Cap";
    28.         startrule.obj = trackStartEndCap;
    29.         startrule.type = MegaLoftRuleType.Start;
    30.         trackLayer.rules.Add(startrule);
    31.        
    32.         MegaLoftRule mainrule = new MegaLoftRule();
    33.         mainrule.enabled = true;
    34.         mainrule.scale -= new Vector3(0.2f, 0f, 0f);
    35.         mainrule.gapin = 2.17f;
    36.         mainrule.rulename = "Main Segment";
    37.         mainrule.obj = trackSegment;
    38.         mainrule.type = MegaLoftRuleType.Filler;
    39.         trackLayer.rules.Add(mainrule);
    40.        
    41.         loft.Layers = new MegaLoftLayerBase[] { trackLayer };
    42.         loft.rebuild = true;
    The context variables referecend on it are properly linked in the editor, but the loft's mesh won't build. Why?

    The meshfilter has zero vertices and the meshrenderer has zero materials.
     
  32. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    The Clone Rules layer needs a loft to build on, you need to set the surfaceLoft value to an existing loft which your layer will be built onto and also set the surfaceLayer to the layer index in that loft to build on, most of the time that is 0.
     
  33. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    Small update in the store now which finally fixes the train demo scene on Unity 5.x and also fixes and error the main demo scene was giving.
     
  34. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    Another quick update this time with have made MegaShapes fully compatible with the upcoming release of Unity 5.3.
     
  35. JimRoot

    JimRoot

    Joined:
    Sep 11, 2013
    Posts:
    77
    Hey! is this cow demo also included?


    i red on the youtube comments that its not. but iam not sure what exactly they mean. if they mean the cows or the whole functionality?
     
  36. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    @PeterBrown - The demo scene is not included as it contains assets that are not mine so can not be distributed with the Asset. The loft object is included, so the textures for the grass, ground, the fence objects, trees, jumps are also included. The cow, lighthouse, ufo, boats are not.
     
  37. JimRoot

    JimRoot

    Joined:
    Sep 11, 2013
    Posts:
    77
    i actually dont realy care about the assets - rather than the functionality
     
  38. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    The scripts to move the loft spline knots is pretty simple just adds a bunch of spheres to the scene for each knot and then does a raycast when the mouse is clicked and dragged to see if a sphere is hit and it then uses the mouse movement to change the position of the spline knot and then calls the BuildMesh method on the loft if something has changed, all the trees, jumps, cows etc are using the walk loft component so they automatically stay stuck the loft surface and the fences are a loft layer so again will move with any loft change. I might still have the scripts somewhere.
     
  39. Jose_KokonutDeveloper

    Jose_KokonutDeveloper

    Joined:
    Sep 29, 2015
    Posts:
    1
    Hi,

    I'm trying to build a simple track editor, basically de user sets points in a world by tapping on the screen and a track is built using the MegaShapeLine component and the MegaShapeLoft, I'm running onto an issue where if I set a point on the ground and then some points on a wall the loft gets twisted. (like in the screenshot)
    I want to know if there is a proper way of doing this without getting the mesh all twisted like that?

    Edit: I case I didn't explained myself well I have just aded two screenshots of how I wish it looked when setting points on walls(screenshot 2 and 3).

    Screen Shot 2016-04-05 at 4.43.43 p.m..png

    Screen Shot 2016-04-05 at 5.23.22 p.m..png Screen Shot 2016-04-05 at 5.22.47 p.m..png
     
    Last edited: Apr 5, 2016
  40. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
  41. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    Just submitted an update to the Asset Store, this brings a few bug fixes and some optimizations and improvements to the Lathe system, namely faster mesh generation and a new normals system which works in all cases.

    Changes since v2.13
    • Optimized the Lathe mesh builder.
    • Improved the Lathe Normal calculation system so it works correctly for all cases.
    • Fixed the mesh array size errors in the Lathe system when reducing the vertex count.
    • Fixed the Regex error in the SVG importer when building for a Windows Store App
    • Editing of splines is now disabled if an Alt key is down, stops accidental editing of splines while changing the scene view.
    • Added simple demo scene showing the RBody following a path component.
    • Fixed error with Spline Fill mesh when being used as a collider with zero thickness.
    • MegaShapes fully compatible with Unity 5.3 and 5.4Train demo scene fixed so the train works correctly in Unity 5.x
    • Fixed main demo scene where one of the lofts had its rules disabled causing an exception.
    • Fixed a problem in Unity 5.x where zero length tris would cause an error and stop the collider being built.
     
  42. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    We have had a few requests for the code used in the MegaMoo demo for changing the path spline as seen in the video below, so I have attached the two scripts as well below so you can see how it was done and maybe use the code as a starting point in your projects. The code is provided as an example only and there is no support for it.

    MoveKnot.cs
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class MoveKnot : MonoBehaviour
    5. {
    6.    public bool   mouseDown = false;
    7.    public Color mouseOverColor = Color.blue;
    8.    Color originalColor;
    9.    bool   moved = false;
    10.    public int handletype = 0;   // 0 = knot 1 = invec 2 = outvec;
    11.    public static bool movingknot = false;
    12.    public float   inveclen = 0.0f;
    13.    public float   outveclen = 0.0f;
    14.    public Vector3   rotate = Vector3.zero;
    15.    public Vector3   scale = Vector3.one;
    16.    public MegaKnot   knot;
    17.    public Vector3   invec;
    18.    public Vector3   outvec;
    19.    public MegaShape   shape;
    20.    public int       curve;
    21.    public int       knotnum;
    22.    public float     knotoffset = 0.0f;
    23.    Vector3 screenSpace;
    24.    Vector3 offset;
    25.    Vector3 offset1;
    26.    Vector3 startpos;
    27.    public Collider plane;
    28.  
    29.    public MoveSpline movespline;
    30.  
    31.    void Start()
    32.    {
    33.      originalColor = renderer.sharedMaterial.color;
    34.    }
    35.  
    36.    void OnMouseEnter()
    37.    {
    38.      renderer.material.color = mouseOverColor;
    39.    }
    40.  
    41.    void OnMouseExit()
    42.    {
    43.      if ( !mouseDown )
    44.        renderer.material.color = originalColor;
    45.    }
    46.  
    47.    void OnMouseDown()
    48.    {
    49.      renderer.material.color = mouseOverColor;
    50.      mouseDown = true;
    51.      movingknot = true;
    52.      screenSpace = Camera.main.WorldToScreenPoint(transform.position);
    53.      offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));
    54.      startpos = transform.position;
    55.  
    56.      Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    57.      RaycastHit hitInfo;
    58.  
    59.      if ( plane.Raycast(ray, out hitInfo, 100.0f) )
    60.        offset1 = hitInfo.point - startpos;
    61.    }
    62.  
    63.    void OnMouseUp()
    64.    {
    65.      mouseDown = false;
    66.      movingknot = false;
    67.      renderer.material.color = originalColor;
    68.    }
    69.  
    70.    void OnMouseDrag()
    71.    {
    72.      if ( mouseDown )
    73.      {
    74.        renderer.material.color = mouseOverColor;
    75.  
    76.        float mx = Input.GetAxis("Mouse X");
    77.        float my = Input.GetAxis("Mouse Y");
    78.  
    79.        float mdist = Mathf.Abs(mx) + Mathf.Abs(my);
    80.  
    81.        if ( Input.GetKey(KeyCode.Z) )
    82.        {
    83.          rotate = Vector3.zero;
    84.          scale.x = 1.0f;
    85.          Quaternion rot = Quaternion.Euler(rotate);
    86.          Matrix4x4 tm = Matrix4x4.TRS(Vector3.zero, rot, Vector3.one);
    87.          Vector3 p = tm.MultiplyVector(invec * scale.x);
    88.          Vector3 p1 = tm.MultiplyVector(outvec * scale.x);
    89.  
    90.          Vector3 iv = p;
    91.          Vector3 ov = p1;
    92.  
    93.          shape.SetHandles(curve, knotnum, iv, ov);
    94.          mdist = 1.0f;
    95.        }
    96.  
    97.        if ( Input.GetKey(KeyCode.S) )
    98.        {
    99.          // Scale the handles
    100.          scale.x += mx * 0.5f;
    101.  
    102.          Quaternion rot = Quaternion.Euler(rotate);
    103.          Matrix4x4 tm = Matrix4x4.TRS(Vector3.zero, rot, Vector3.one);
    104.          Vector3 p = tm.MultiplyVector(invec * scale.x);
    105.          Vector3 p1 = tm.MultiplyVector(outvec * scale.x);
    106.  
    107.          Vector3 iv = p;
    108.          Vector3 ov = p1;
    109.  
    110.          shape.SetHandles(curve, knotnum, iv, ov);
    111.        }
    112.        else
    113.        {
    114.          if ( Input.GetKey(KeyCode.R) )
    115.          {
    116.            // Rotate the handles
    117.            rotate.x += my * 2.0f;
    118.            rotate.z += my * 2.0f;
    119.            rotate.y += mx * 2.0f;
    120.            Quaternion rot = Quaternion.Euler(rotate);
    121.            Matrix4x4 tm = Matrix4x4.TRS(Vector3.zero, rot, Vector3.one);
    122.            Vector3 p = tm.MultiplyVector(invec * scale.x);
    123.            Vector3 p1 = tm.MultiplyVector(outvec * scale.x);
    124.  
    125.            Vector3 iv = p;
    126.            Vector3 ov = p1;
    127.  
    128.            shape.SetHandles(curve, knotnum, iv, ov);
    129.          }
    130.          else
    131.          {
    132.            if ( Input.GetKey(KeyCode.Y) )
    133.            {
    134.              Vector3 curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);
    135.              Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset;
    136.  
    137.              transform.position = curPosition;
    138.  
    139.              Vector3 p = transform.position;
    140.              p.y -= knotoffset;
    141.              p = shape.transform.worldToLocalMatrix.MultiplyPoint(p);
    142.  
    143.              shape.MoveKnot(curve, knotnum, p);
    144.            }
    145.            else
    146.            {
    147.              Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    148.              RaycastHit hitInfo;
    149.  
    150.              if ( plane.Raycast(ray, out hitInfo, 100.0f) )
    151.              {
    152.                Vector3 worldSpaceHitPoint = hitInfo.point - offset1;
    153.                worldSpaceHitPoint.y = startpos.y;
    154.                transform.position = worldSpaceHitPoint;   //curPosition;
    155.  
    156.                Vector3 p = transform.position;
    157.                p = shape.transform.worldToLocalMatrix.MultiplyPoint(p);
    158.                p.y -= knotoffset;
    159.  
    160.                shape.MoveKnot(curve, knotnum, p);
    161.              }
    162.            }
    163.          }
    164.        }
    165.  
    166.        if ( mdist != 0.0f )
    167.        {
    168.          movespline.rebuild = true;
    169.          moved = true;
    170.        }
    171.      }
    172.    }
    173. }
    174.  
    MoveSpline.cs
    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4.  
    5. public class MoveSpline : MonoBehaviour
    6. {
    7.    public MegaShape   shape;
    8.    public MegaShapeLoft   loft;
    9.    public int       curve;
    10.    public float     scale = 1.0f;
    11.    public GameObject   gizmo;
    12.    public GameObject   hitobj;
    13.    public Color     color = Color.red;
    14.    public GameObject[]   objs;
    15.    public Vector3[]   kpos;
    16.    public float     offset = 0.0f;
    17.    public Transform   parent;
    18.    public bool   showhandles = true;
    19.    public bool   rebuild = false;
    20.  
    21.    void Start()
    22.    {
    23.      if ( shape != null )
    24.      {
    25.        MegaSpline spline = shape.splines[curve];
    26.  
    27.        objs = new GameObject[spline.knots.Count];
    28.        kpos = new Vector3[spline.knots.Count];
    29.  
    30.        int index = 0;
    31.        for ( int i = 0; i < spline.knots.Count; i++ )
    32.        {
    33.          // knot pos
    34.          Vector3 pos = shape.transform.localToWorldMatrix.MultiplyPoint(spline.knots[i].p);
    35.  
    36.          pos.y += offset;
    37.          kpos[index] = pos;
    38.          objs[index] = (GameObject)GameObject.Instantiate(gizmo, pos, Quaternion.identity);
    39.          objs[index].transform.localScale = new Vector3(scale, scale, scale);
    40.  
    41.          MoveKnot mk = objs[index].AddComponent<MoveKnot>();
    42.          mk.mouseOverColor = color;
    43.          mk.plane = hitobj.collider;
    44.          mk.handletype = 0;
    45.          mk.knot = spline.knots[i];
    46.          mk.movespline = this;
    47.          mk.knotoffset = offset;
    48.          mk.shape = shape;
    49.          mk.knotnum = i;
    50.          mk.curve = curve;
    51.          mk.invec = spline.knots[i].invec - spline.knots[i].p;
    52.          mk.outvec = spline.knots[i].outvec - spline.knots[i].p;
    53.  
    54.          if ( parent )
    55.            objs[index].transform.parent = parent;
    56.  
    57.          index++;
    58.        }
    59.      }
    60.  
    61.      if ( parent )
    62.        parent.gameObject.SetActiveRecursively(showhandles);
    63.    }
    64.  
    65.    void Update()
    66.    {
    67.      for ( int i = 0; i < objs.Length; i += 1 )
    68.      {
    69.        Vector3 p = objs[i].transform.position;
    70.        if ( p != kpos[i] )
    71.        {
    72.          kpos[i] = p;
    73.          p.y -= offset;
    74.          p = shape.transform.worldToLocalMatrix.MultiplyPoint(p);
    75.        }
    76.      }
    77.  
    78.      if ( rebuild )
    79.      {
    80.        loft.rebuild = true;
    81.        loft.BuildMeshFromLayersNew();
    82.      }
    83.    }
    84.  
    85.    void LateUpdate()
    86.    {
    87.      if ( rebuild )
    88.      {
    89.        shape.BuildMesh();
    90.        rebuild = false;
    91.      }
    92.    }
    93. }
    94.  
     

    Attached Files:

  43. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    I got a problem, three days ago I am hang on this, let me teach you about this error hopefully you will reply promptly.
    I have multiple spline (in SPL format) which constitute a single spline. I moving my camera on it and changing spline one by one as current spline finish but I have camera orientation problem. it moving smoothly on spline but didn't focus/orient on spline direction. How do I achieve this thing that every time it look at orientation of spline. I try lookAt but this is not the right choice ude to jerk effects. I also checked MegaTrainFollow rot property but how do i set it each time
     
  44. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    @MFKJ - If you could submit a support ticket at the website and maybe include the code you are using to control your cameras, and maybe also a video showing the problem.
     
  45. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    @MFKJ - Not heard from you, is there any reason?
     
  46. AaronDevaney

    AaronDevaney

    Joined:
    Dec 12, 2012
    Posts:
    2
    I'm looking to create quite a big track with railings inside and out, created with clone layers. Keep on running into "too many vertices limit". These are pretty low poly railings so can't make any improvements there.
    To get around this and to improve performance I'd like to only display a portion of the track at a time. Megashapes is a great module and very adaptable so I though this might be achievable by setting the distance to less that one and dynamically adjusting the start position but unfortunately this changes the position of the clone and vertices on the track.

    Is there another way to achieve this where the mesh remains static but only a portion of it is drawn?
     
  47. AaronDevaney

    AaronDevaney

    Joined:
    Dec 12, 2012
    Posts:
    2
    So I take it this isn't a viable way currently to implement LOD reduction? Just mentioning as it was recommended earlier in this thread as a potential method.
     
  48. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,237
    Hi, I'm trying to set the 'snap bottom' on a 'Mega Loft Multi Material' but I can't find it. Please can you help? I submitted a support ticket but received no reply.

    Thanks
     
  49. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,689
    Submitted an update to the Asset Store and our website, this makes MegaShapes fully compatible with the upcoming release of Unity 5.5 and we have also fixed a couple of bugs namely the collision layer in the rope system, and added a new version of the Hose system that works correctly with moving and rotating end objects. Note when you update you may get an error about the Hose system, this is because in a previous update of MegaShapes the MegaHose script somehow got moved to the Editor folder, if you do get an error just delete the MegaHose script that will be in the Editor folder, it is the script that does not have 'Editor' in its name.

    Visit the Asset Store

    Changes in v2.21
    • MegaShapes fully Unity 5.5 compatible.
    • Layer field for the Rope collision field now shows all the layers correctly.
    • Fixed bug with rope collisions not using the selected layer value correctly.
    • Moved the New Hose system source file from the editor folder to the correct folder. You may need to delete the MegaHoseNew.cs file in the editor folder after an update.
    • Added new Hose Attach system that uses the new hose system.
    • Added a new version of the hose system that works correctly when end nodes are transformed or moved. Use 'Hose New' instead of 'Hose'.
     
  50. Der_Kevin

    Der_Kevin

    Joined:
    Jan 2, 2013
    Posts:
    517
    i know. but still, the code doesn't work.

    Code (CSharp):
    1. MoveKnot.cs(93,39): error CS1061: Type `MegaShape' does not contain a definition for `SetHandles' and no extension method `SetHandles' of type `MegaShape' could be found (are you missing a using directive or an assembly reference?)
    2.