Jump to content

SPS questions


Recommended Posts

I'm playing a little bit with SPS, and I'm try to check which solution is better for my next project, SPS, instances, or in the worst case clone.
The scenario is simple: Have a few objects with or without animation, on click on one begin new animation on it.
So because of this I'm haveing a few questions related to SPS.

https://playground.babylonjs.com/#C48VK3#1 this is what I'm haveing till now.

1. if I can add a animation to the sps mesh? Now they are moveing there but it would be nice if i can attach an animation to them
2. Related to optimizations, I think I added all what was necesarelly. If you think I miss something.
3. The material on SPS mesh seems to be different from material on real model, you can see this on click on a mesh, when it is replaced by the original. Can I avoid this in some way?
4. If I'm adding an environment https://playground.babylonjs.com/#C48VK3#2, line 15, click function broke. I mean even if I click random in scene it say I'm clicking an object from SPS 
5. If I'm adding color to SPS meshes https://playground.babylonjs.com/#C48VK3#3, this color is added to vertex? I know that for instances, all instance need to have the same material, but I'm thinking to try this trick from SPS, modify directly color of instance.

And the last but maybe most important :) What do you think is SPS a solution for this scenario?
I'm going to create similar playground with instance :)

Thank you for your time ;)

Link to comment
Share on other sites

Hi MG!   I'm not a pro on SPS, but I try to show something interesting.


If I said... "All 4 boxes are part of ONE mesh"... would that surprise you?

The only reason this scene "appears" to have 4 mesh... is that certain "indices" were not drawn/coded into the SPS one-mesh vertexData object.

Click on some boxes and watch console.  Notice the very high values on the tan and blue boxes. 

So, each of the particles... each of the boxes... is NOT really a (individual) mesh.  Thus, it will not accept many of the "features" that a standard mesh would.  Particles... are special things... primarily made for high-performance flying. 

Each flight-STEP... is moving (transforming) the  vertices used for one "shape".  A different particle shape will be flying in some OTHER direction, and its vertices will need DIFFERENT transforms (so it can stay on ITS trajectory).  Still... only one mesh for entire SPS system, but you can create more than one SPS, as needed.

This one-mesh system... is why "depth-sorting" can be troublesome for particle systems.  It is VERY difficult (impossible) to make SOME sprayed particles display BEHIND something, and some displayed IN-FRONT-OF something.  The particle system is ONE mesh, and it must be either ahead-of, or behind... another.

See line 35, the addShape?  That is addShape, not addModel.  Line 35 "digests" (injests?) the SHAPE of the model, but not the ACTUAL model.

Then, in line 38, the MODEL is disposed.

It takes some time to comprehend these odd high-performance methods.  They are different from standard mesh operations.

SO... when you make your mesh/shapes... be particles... you give-up MANY of the features found on standard mesh, clones, or instances.  BUT, if you can "work WITH" the SPS or particle system, and if you know about their easily-user-over-rideable startPosition and update functions, you can make them DANCE for you. 

SPS and particleSystems are VERY powerful and useful, but it requires that we understand the limitations, and the good pay-offs that result from those limitations.

Try to think about this weird stuff.  Once a SPS system "digests" the SHAPE of a mesh, then you must use SPS systems/methods... to color, scale, or texture the particles.  In BJS, both solid and standard particle systems... use this one-mesh system... for high performance.  Vrooooom!  :)  

I hope I've been helpful (and not wrong).   :)  

Link to comment
Share on other sites

1 there's no animation in the SPS, you have to animate every particle, vertex by vertex with updateVertex() if you need it

2 - in your case, instances would probably be faster than the SPS because the SPS iterates over all the particle vertices and your model seems to have a big number of vertices

3 - the SPS only copies the UVs from the model. No idea if your model has UV2s, UV3s or some PBR material.

4 - I can't see what's going wrong here

5- yep, these are vertexColor for each whole particle. This already works in your case, rotate the cam, you'll see them.


Maybe instances may faster than the SPS with your high-tri model

Link to comment
Share on other sites

Yes @Wingnut, was helpfull. Thank you.
I only try to test SPS limitations, and see what is the best for my scenario.

Thank you @jerome for answer.
More clear now :) 

I tried with instances, but it seems to have some problems with glb files. With babylon file it is working but with glb didn't get it, but still trying.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...