Docs show wireframe renderings of 3d shapes, but there doesn't seem to be a way to create them.

Avatar
  • updated
  • Answered

Sadly this was the reason I purchased this asset but it doesn't seem possible OTB. I assumed there would at least be an example. Am I missing something? Is the only way to create 3D shape outlines by manually defining each wire as a new shape?

Thanks!

Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
Reporting a bug? please specify Render Pipeline:
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Answered

Shapes only renders primitives, and currently doesn't have support for compound shapes such as an entire mesh

the "wireframe" on the website is not really a wireframe of a mesh, but rather a set of connected lines of a dodecahedron (if I'm thinking of the same thing you are!)

That being said, you *can* still draw the wireframe of a mesh with Shapes, though you might hit performance issues if you have a very complex mesh

Something along these lines should work in an immediate mode rendering context (more info on that here under drawing contexts)

After assigning the mesh, be sure to enable/disable the component to re-cache the mesh data

using Shapes;
using UnityEngine;

[ExecuteAlways] // to make it draw in the game view even outside of play mode
public class MeshTest : MonoBehaviour {

    public Mesh mesh; // what mesh to draw
    public Transform tf; // where you want to draw the mesh

    [Range( 0f, 0.01f )]
    public float lineThickness = 0.01f;

    Vector3[] verts;
    int[] tris;

    void OnEnable() {
        verts = mesh.vertices; // cache these here to save performance!
        tris = mesh.triangles; // these are expensive to call~
    }

    void OnPostRender() { // assuming a camera is attached to this object (see drawing contexts link above)
        Draw.Matrix = tf.localToWorldMatrix; // if you want it to follow this transform
        Draw.LineThickness = lineThickness; // and whatever else you want to configure!
        for( int t = 0; t < tris.Length; t += 3 ) {
            Draw.Line( verts[tris[t]], verts[tris[t + 1]] );
            Draw.Line( verts[tris[t + 1]], verts[tris[t + 2]] );
            Draw.Line( verts[tris[t + 2]], verts[tris[t]] );
        }
    }

}

Avatar
Freya Holmér creator
  • Answer
  • Answered

Shapes only renders primitives, and currently doesn't have support for compound shapes such as an entire mesh

the "wireframe" on the website is not really a wireframe of a mesh, but rather a set of connected lines of a dodecahedron (if I'm thinking of the same thing you are!)

That being said, you *can* still draw the wireframe of a mesh with Shapes, though you might hit performance issues if you have a very complex mesh

Something along these lines should work in an immediate mode rendering context (more info on that here under drawing contexts)

After assigning the mesh, be sure to enable/disable the component to re-cache the mesh data

using Shapes;
using UnityEngine;

[ExecuteAlways] // to make it draw in the game view even outside of play mode
public class MeshTest : MonoBehaviour {

    public Mesh mesh; // what mesh to draw
    public Transform tf; // where you want to draw the mesh

    [Range( 0f, 0.01f )]
    public float lineThickness = 0.01f;

    Vector3[] verts;
    int[] tris;

    void OnEnable() {
        verts = mesh.vertices; // cache these here to save performance!
        tris = mesh.triangles; // these are expensive to call~
    }

    void OnPostRender() { // assuming a camera is attached to this object (see drawing contexts link above)
        Draw.Matrix = tf.localToWorldMatrix; // if you want it to follow this transform
        Draw.LineThickness = lineThickness; // and whatever else you want to configure!
        for( int t = 0; t < tris.Length; t += 3 ) {
            Draw.Line( verts[tris[t]], verts[tris[t + 1]] );
            Draw.Line( verts[tris[t + 1]], verts[tris[t + 2]] );
            Draw.Line( verts[tris[t + 2]], verts[tris[t]] );
        }
    }

}