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

3D Emitter Script

  • This is exactly what I have been looking for.  Did you ever get a chance to do a YouTube tutorial like you mentioned in your original post?

    Comment actions Permalink
  • Hey, happy to hear this is useful to someone. I never got around to making the video, but if you need any help getting it set up or navigating the different settings or API, I'd be happy to answer any questions you might have.

    Comment actions Permalink
  • Hey Ryan,

    I just downloaded your script - thank you for coming up with this great solution. If you don´t mind I could need some advice on setting things up and have also a feature question:

    1) is it possible to emit only one particle straight on a tap event? Right now if I dial down the birthrate, the particle doesn´t shoot out at a fixed interval-rate, but with the latency of something up  to one second I suppose (since most likely that is the birthrate per second, right?) 

    2) My setup is as follows: I have a toaster that should spit out a toast. So I took a simple Boxmesh and scaled it unevenly in allthree axes. Next I placed an empty child which is my emitter to which I attach your script. Emission and all works fine, but my toasts (made of a prefab of an unveenly scaled Boxmesh again) come out distorted;they seem to adapt the scaling of the parent of my emitter - namely the toaster. Could you give me a hint on how to deal with that issue?

    looking forward to hearing from you,

    cheers eL

    Comment actions Permalink
  • Hey eL,

    Glad you found it useful (kinda).

    1) There's no built-in way to trigger a set number of particles, but there might be a way to do it if you're down to do some custom scripting. I can walk you through it if that sounds like something you want to try.

    2) I didn't add in parent scaling compensation, so the scaling of the emitter needs to be uniform (preferably 1,1,1). I would suggest making it a sibling of the toaster object, rather than a child, assuming the toaster's parent object (and all parents above that) has/have uniform scale.

    - Ryan

    Comment actions Permalink
  • Great Ryan - thanks for the quick reply. Up to now I worked with the emitter material and set up everything just fine, but eventually it would be outstanding to have real 3D Objects emitted - so yes please if you could hint me to the custom script parameter that I need to address, that would be awesome.

     

    thanks in advance
    eL

    Comment actions Permalink
  • In the Emitter.js script, you'll find the emit function around line 138. I would add a second parameter to the function (e.g. "num"). After line 141, add a line adding this number to the "newObjects" variable. Should look something like this:

    function emit(now, num = 0) {
    // calculate how many new objects to make
    var newObjects = valueWithVariance(script.api.birthrate)*script.api.timeSinceLastUpdate;
    newObjects = Math.floor(newObjects) + ((Math.random() < (newObjects % 1)) ? 1: 0); // decimal portion becomes probability for adding an extra object
    newObjects += num;
    ...

    Note: Not sure how familiar you are with more-than-basic JS syntax, but I set "num" to have a default value of 0, so if you don't pass a second parameter to the function, the script still works as usual

    Now, for connecting the touch gesture, you can either code directly in Emitter.js (if the the user can tap anywhere on screen), or you can add it separately (if it's tied to some kind of UI element).

    If directly in Emitter.js:

    At the bottom of the script, create a TapEvent and bind a function to it that calls the emit function, like so:

    var onTap = script.createEvent('TapEvent');
    onTap.bind(function() {
    emit(Date.now(), 1);
    });

    This will emit 1 object when the user taps anywhere on the screen

    If in a separate script:

    First, in Emitter.js, add a line that exposes the emit function on the script api:

    script.api.emit = emit;

    Then, in a separate script, you'll need to create an input for the Emitter script so you can access that api:

    // @input Component.ScriptComponent emitScript

    script.emitScript.api.emit(Date.now(), 1);

    Add this script to your UI element and set it to initialize on tap and then make sure to link the Emitter.js script to the input.

     

    In either case, you'll want to set the birthrate of the Emitter.js script UI to 0 to make sure it doesn't emit any unwanted objects. And I think that should do it. I didn't test any of that though, so let me know if you run into any issues and I'll help you debug.

    Sidenote: if you're relatively comfortable with JavaScript, it might be better just to use Cannon.js to simulate physics. It's way better than my super simplified physics engine and will give you more control over the behavior of your objects, including collisions between them, which is cool. I was actually considering implementing it myself for an advanced version of the script, but never got around to it. You do however lose the nice UI interface though, so if you're not into scripting, beyond the basics I outlined above, you can ignore this.

    Comment actions Permalink
  • Hey Ryan , 

    thank you very much for jumpstarting me on that. I´m not very fluent in JS but I will try to work my way through. Thank you for your help and support. 

    Have a good week,
    cheers eL

    Comment actions Permalink
  • Hi Ryan,

    I implemented your script adjustments and it works very nicely.

    In your fountain of you lense though you added gravity to the script which I could really need to have a nice flyingcurve of my toasts. Would you tell me how you did that? Also if I ad a rotation to my toast, the 3d Object skews while rotating, do you have any idea where in your script I can fix that?

    greetings eL

    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!