The forum on this site is closed for new comments and posts. Continue the conversation in our Snap AR Discord server.

Creating a Procedural Mesh Using Mesh Builder

Featured
  • Great stuff. I'll definitely try this out. Thank you, Jonathan!

    Comment actions Permalink
  • Can you post a sample project for this? I'm having some issues with the object setup and figure if I can see the actual project it would be easier to get working.

    Comment actions Permalink
  • Hi Ralph,  Here is a sample project for this. Let me know if you are still having issues, and I would be happy to help!

     

    You're welcome Dpid! Show us what you end up making :)

    Comment actions Permalink
  • Does meshbuilder fetch and put to a file and then load the graphics processor?  Is there a way to stream polys directly to the processor in the API.  My file is too large, but procedural.  I don't need to store them after they are produced.  It would be faster for all procedural files too!

     

    Comment actions Permalink
  • Hi Alyn, MeshBuilder does not fetch or put to a file anything. It is streaming polys directly to the renderer.

    Can you explain a bit more what you're experiencing? Which file is too large? Thanks!

    Comment actions Permalink
  • Great, good to know.  Here is the model. 

    https://sketchfab.com/models/b7acfad9aa744a7a802c439b502994c4

    It was made with SuperD  (bouldergraphcis.io).   It creates lots of polys, but it is a SubD-like modeler (without subdivision) so the control cage is small.  The polys generated from the cage are fast, so it is much better to stream.   I assume that meshbuilder.update streams them?  I am looking for a way to do VR/AR using the small control cage to stream high quality, complex models.

    Comment actions Permalink
  • Typo

    bouldergraphics.io

    Comment actions Permalink
  • Hi Alyn, MeshBuilder is not intended to be used as a way to SubD polys. MeshBuilder does its job on the CPU. It would be better to import an FBX or OBJ with already generated polys.

    We recommend a limit of 10,000 triangles for all 3D objects in the scene (under Lens Content here: https://lensstudio.snapchat.com/support/)and using materials and textures to add additional fidelity to your models (https://lensstudio.snapchat.com/guides/3d/materials/).

    Comment actions Permalink
  • Hi Jonathan,  I understand it is not Meshbuilder's design to recursively subdivide poly's.  I have developed a separate procedural method to generate polys rapdily and with continuity.  From a small, control mesh I stream polys to the GPU. (see boudlergraphics.io/learning).  I would now like to apply this method to Sketchfab VR/AR.  It would greatly enhance the quality and speed of model display there.  What I need is a command in the API that lets me do this.  In Objective C I do this with an OpenGL call (including texture coords for preloaded materials).  Is there a way to access OpenGL commands in meshbuilder? or otherwise?  This could be a blow away improvement!  Thanks..

     

    Comment actions Permalink
  • For something like this is it possible to reduce the randomness and create smooth flowing lines instead of jagged streams of geometry? I was testing different topology such as lines and triangle fans which were interesting, but not they weren't smooth enough. How might you create smooth lines with this idea?

    Comment actions Permalink
  • Hi Alyn, 

    Currently lens studio does not support this feature; We'll add the desire to have additional control over MeshBuilder to our feature request list. Thanks for the input!

     

    Hi Tom,

    Yep definitely! We can remove the randomness from our new vertex position and get our phone exact location.

    builder.appendVerticesInterleaved([
    loc.x, loc.y, loc.z, Math.random(),Math.random(),Math.random(),Math.random(),
    ]);

    Additionally, If you have a list of points that you are drawing, you can consider using a mathematical function to smooth out the lines between your points (e.g.: cardinal, Bézier, etc.).

    For example, you can use https://github.com/epistemex/cardinal-spline-js ’s curve_calc.js and change the function so that it’s accessible globally and set to "Initialized" in the Inspector panel.

    global.getCurvePoints = function (points, tension, numOfSeg, close) {…}

    As you mentioned, you can use

    builder.topology = MeshTopology.TriangleStrip

    so that the points we add are automatically connected to each other.

    Then in the script above, instead of drawing on an update loop, you can just do it once on "Lens Turned On" (aka just remove the UpdateEvent since the script is on "Lens Turned On"), and process your points via the spline function before drawing it.

    // The cardinal-spline-js library accepts a list 
    // of points interleaved ([x1, y1, x2, y2, ..., xn, yn])
    var points = [-40,20, 0,100, 30,0, 20,70]

    // We’re giving it a tension of 3 (so it’s very curvy),
    // adding 20 additional points between each points above, and connecting the ends.
    // See the library for more information
    var interpolatedPoints = global.getCurvePoints(points, 3, 20, true);

    for (var i = 0; i < interpolatedPoints.length; i = i+2) {

    // Since we want some thickness in our lines we add two points and spaced 2 units apart.
    // We draw the mesh 20 units away so we can see it.
    // Then instead of random colors, we just give it a solid red.
    builder.appendVerticesInterleaved([
    interpolatedPoints[i]-1, interpolatedPoints[i+1]-1, -20, 1,0,0,1,
    interpolatedPoints[i]+1, interpolatedPoints[i+1]+1, -20, 1,0,0,1,
    ]);

    // Then we add the two vertices to our list.
    var lastVertexIndex = builder.getVerticesCount()-1;
    builder.appendIndices([
    lastVertexIndex - 1, lastVertexIndex,
    ]);
    }

    // Finally, we tell the Mesh Builder to render the mesh as we did earlier
    builder.updateMesh();

    You should see something like:

    Let me know what you end up creating!

    Cheers,

    Jonathan

    Comment actions Permalink
  • How can i do the same but with cubes? 

    i found how to build cube here 

    https://lensstudio.snapchat.com/api/classes/MeshBuilder/

    but i cant spawn it

    Comment actions Permalink

We're here to help! We just need a little bit of information...

What system are you using?

Have you downloaded the latest version of Lens Studio?

Please download the latest version of Lens Studio. If you still run into this issue, please come back and report it!

Is this issue causing Lens Studio to crash?

What system do you run Lens Studio on?

Version

Graphics

Follow the next steps to help us solve your issue:

  • Copy and paste this text into your TerminalCommand Window
    open ~/Library/Preferences/Snap/Lens\ Studio/ %LOCALAPPDATA%\Snap\Lens Studio Copy Text
  • Press ReturnEnter to run the command. The Lens Studio folder will automatically open
  • Prepare to upload your files: zip the "Log" Folder by right-clicking and choosing "compress."
    Locate the Log.txt file right above it.

    Attach a screenshot of the issue:

Name:

Email:

What is this most relevant to?

Please enter a brief description of your issue:

Thanks for submitting this issue.

Unfortunately, it's likely due to the operating system or hardware you're using – since they don't meet the system requirements for Lens Studio.

Still, we hear you loud and clear, and are logging the issue in case there's ever a workaround we can provide!

Minimum Requirements

Operating System: Windows 10 (64 bit); MacOS 10.11+

Hardware: Minimum of Intel Core i3 2.5Ghz or AMD Phenom II 2.6Ghz with 4 GB RAM; Intel HD Graphics 4000 / Nvidia GeForce 710 / AMD Radeon HD 6450 or better; screen resolution of 1280x768 or higher

We'll try to resolve this issue as soon as possible. Thanks for letting us know about it!

Keep an eye out for a followup email from us. We may have a couple more questions for you, or we might already have a solution to offer.

Happy creating!