Wingnut Posted July 1, 2015 Share Posted July 1, 2015 You love it, and you know it. It's like a crossword puzzle with three words yet unanswered. It keeps you coming back, and often obsessively, right? The sign of a great project. Billlboard mode. hmmm. I think you should say goodbye to it. Maybe it's time to use statics. BABYLON.SolidParticleSystem.ROTATIONMODE_X et al. _x _y _z _xy _xz _yz _all _none _random Then, for particle rotation speed... allow value or random as well... and allow zero... which would be the same as ROATATIONMODE_NONE, right? In fact, it would be nice if ALL of BJS... allowed Math.Random() to be abbreviated IN THE CODE... with ? ...a question mark. Hey ECMA. Good luck on your bug find, ParticleMan! Don't try to find it too quick... or you'll need to think-up yet another feature. Oh crap, I didn't cover BILLBOARD in my list of particle rotation constants. Yep, we still got trouble. Rotation modes aside, there's still three axes that could be told to face the camera. hmm. *scratch scratch* And the many billboard modes could "fight" against the particle rotation modes. Crap! User has sps rotationMode set to all, but billboardmode_x set... and is in the forum, asking why their particles won't rotate on the x axis. Trouble. Okay, ignore me and this post. Quote Link to comment Share on other sites More sharing options...
jerome Posted July 1, 2015 Author Share Posted July 1, 2015 but I have another just-backed nice feature : the per particle texture ! from a single BJS classic texture something you can set either in initParticles() either in setParticles() ... yes, live texturing in the render loop if you want ! It already worksBut I want to fix this f$*%§@#king billboard mode for plane particles. My afternoon on it and ... nothing, pffffI give up for today. Quote Link to comment Share on other sites More sharing options...
jerome Posted July 2, 2015 Author Share Posted July 2, 2015 Hi guys ! What is the worst bug you ever had to fix ? the bug that doesn't exist !I wasted my afternoon yesterday trying to fix the billboard mode... that wasn't broken.Let's forget this... So at last, today, here is the new feature I wanted to introduce you yesterday : http://www.babylonjs-playground.com/#2KSQ1R#32Here are some textured and colored quad particles slowly rotating in billboard mode. You should recognize the wise old man and his famous tongue in the picture.As you can see at the line 24, it's a very classical BJS Texture what is then then applied to the SPS mesh material (line 34). Let's now use a new particle property that I called uvs for now (may a better name would be needed). This uvs property is just an array with 4 numeric elements [u0, v0, u1, v1].u0, v0 are the "coordinates" of the upper left point from where you want to crop the particle image in the loaded textureu1, v1 are the "coordinates" of the lower right point down to where you want to crop the particle image in the loaded texture u0, v0, u1, v1 are just expressed in percentages of the original texture, it is to say with values between 0 and 1. Dont talk, show !Line 50, in the initParticles function, I set random values to uvs for each particles : http://www.babylonjs-playground.com/#2KSQ1R#33 Of course, it would be better to have a real image with many different patterns (like a texture atlas) and to set them to each particle. But I don't have such a file here, sorry. Does this work only in initParticles() ?No, sir, it can work at run time ! Line 56, in the updateParticle() method. Beware if you are epilectic : http://www.babylonjs-playground.com/#2KSQ1R#34 Note : API changed and billboard is now a SPS property that can be changed at any time.There are also other new available methods to optimize the SPS setParticles() method if you know you don't need (even temporarily) some features :SPS.enableParticleRotation() // prevent from computing particle.rotationSPS.disableParticleRotation() // re-activate particle.rotation computingSPS.enableParticleTexture() // prevent from computing particle.uvsSPS.disableParticleTexture() // re-activate particle.uvs computingSPS.enableParticleColor() // prevent from computing particle.colorSPS.disableParticleColor() // re-activate particle.color computingEverything is unfrozen by default. doc updated : https://github.com/BabylonJSX/SolidParticleSystem [EDIT] all freezeXXX() method names changed into enableXXX() because they don't keep the last values hypothetically used. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 2, 2015 Share Posted July 2, 2015 Huge! Quote Link to comment Share on other sites More sharing options...
jerome Posted July 2, 2015 Author Share Posted July 2, 2015 a few my nephew ! Quote Link to comment Share on other sites More sharing options...
jerome Posted July 2, 2015 Author Share Posted July 2, 2015 and since it is a mesh, we can texture it as a mesh... with bump for instance : http://www.babylonjs-playground.com/#2KSQ1R#35 only one mesh and one texture here, please take a look at the debug button [edit] can't stop playing : http://www.babylonjs-playground.com/#2KSQ1R#36 Quote Link to comment Share on other sites More sharing options...
jerome Posted July 3, 2015 Author Share Posted July 3, 2015 I stole a sprite atlas somewhere on the Web just to show you how a single texture can make different particle images : http://www.babylonjs-playground.com/#2KSQ1R#37 As you can see, the original image contains 6 x 4 sprites : http://jerome.bousquie.fr/BJS/images/spriteAtlas.pngSo in the initParticles() function, I simply set random sprites to each particle (line 46) var hSpriteNb = 6; // 6 sprites per raw var vSpriteNb = 4; // 4 sprite raws var u = Math.floor(Math.random() * hSpriteNb) / hSpriteNb; var v = Math.floor(Math.random() * vSpriteNb) / vSpriteNb; this.particles[p].uvs = [u, v, u + 1 / hSpriteNb, v + 1 /vSpriteNb];easy, isn't it ? adam 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted July 3, 2015 Author Share Posted July 3, 2015 Did I say the per particle texturing worked also for solid particles also ?I didn't ... but it does : http://www.babylonjs-playground.com/#2KSQ1R#38 Temechon, Wingnut and adam 3 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 3, 2015 Share Posted July 3, 2015 This is just COOOOOL.Could you add it as an official extension? I added you as admin on this repo:) Quote Link to comment Share on other sites More sharing options...
jerome Posted July 3, 2015 Author Share Posted July 3, 2015 thanks It's not finished yet (almost)then I'll do it are extensions in TS only ? I won't have time to port it Quote Link to comment Share on other sites More sharing options...
Temechon Posted July 3, 2015 Share Posted July 3, 2015 It's not TS only. bGUI is fully in JS for example. Quote Link to comment Share on other sites More sharing options...
iiceman Posted July 3, 2015 Share Posted July 3, 2015 I keep checking the thread now and then.. when it's done I might try to create a really cool space scene with god ray sun, partcle paralax stars in the background, some planets orbiting the sun and a cool spaceship in an asteroid filed. Can your Mesh Particle System do that? I mean a really cool asteroid field? and derbies from the spaceship that got hit by the asteroids? I assume it can. This will be AWESOME! Quote Link to comment Share on other sites More sharing options...
jerome Posted July 3, 2015 Author Share Posted July 3, 2015 The SPS can do :asteroid fieldsscraps blown for an explosionliquid drops flowingimmobile buildings in the distancemusic 3D vu-meterluck in gamesprofessional successlove regaincoffee Well, it's just one single mesh with many accessible parts.Just see SPS as an API to program these parts. jahow, Wingnut and iiceman 3 Quote Link to comment Share on other sites More sharing options...
jerome Posted July 3, 2015 Author Share Posted July 3, 2015 It's almost done anyway I would love to add :- the ability to dispose the SPS- the ability for the end user to dynamically morph each particle - (maybe) the ability to sort particles according to the particle-camera distance in order to solve the exotic case of vertices with alpha wrongly z-sorted... not sure it's worth it because of the performance cost. BTW, in the current SPS I re-implemented some BJS internal methods (like Matrix.RotationYawPitchRoll or Quaternion.toMatrix) with no temporary local variables.I did it because I noticed the GC can deal pretty well with temp variable allocations if we call these methods, say, dozen times per frame.But since in SPS we do CPU side things that usually happens GPU side (like to compute each position and rotation of each vertex of each particle...and we may have 10K particles !), we need to call rotationYawPitchRoll dozen of thousands times each frame... and it quickly reaches an amount of temp memory allocation that has a significative effect on the GC.That's why many SPS private properties are set just for storing temporary values and to never allocate/free the related memory. The re-implemented functions then use these private properties. Quote Link to comment Share on other sites More sharing options...
adam Posted July 4, 2015 Share Posted July 4, 2015 This is looking great. Your demos run surprisingly well on my 3 year old Nokia 822 windows phone. How hard would it be to get skeletons/animations working with this? I wonder if that would just kill the performance gains you have achieved. Quote Link to comment Share on other sites More sharing options...
jerome Posted July 4, 2015 Author Share Posted July 4, 2015 No ideaI don't know anything about skeletons :-( Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 6, 2015 Share Posted July 6, 2015 Extensions can be on javascript:) Quote Link to comment Share on other sites More sharing options...
jerome Posted July 6, 2015 Author Share Posted July 6, 2015 coolstep after step (and my steps are shorter with such a hot weather here) :first finish itthen push it to official extension repothen maybe... port it to TS if you want it in BJS.... but this may keep optional Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 6, 2015 Share Posted July 6, 2015 I WOULD LOVE IT in bjs Quote Link to comment Share on other sites More sharing options...
jerome Posted July 6, 2015 Author Share Posted July 6, 2015 added to my monstrous backlog I will have to re-think many things because the current SPS re-implement some dedicated local GC-optimized legacy BJS functions Quote Link to comment Share on other sites More sharing options...
jerome Posted July 7, 2015 Author Share Posted July 7, 2015 just some news : this topic is not dead ...Things go on under hood very slowly because it's very hot here and I have another real job to do Well, added :SPS.dispose() to free the memory if you don't need the SPS anylongerand internal refactoring to get rid off parameter variables in re-implemented legacy BJS rotation functions... a serious hunt to every case where the GC could wake up adam 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 7, 2015 Share Posted July 7, 2015 Is SPS still considered a particle system as far as LOD levels are concerned? RenderGroups working for it? (like I know what ANY of these things are) Quote Link to comment Share on other sites More sharing options...
jerome Posted July 7, 2015 Author Share Posted July 7, 2015 Quote Link to comment Share on other sites More sharing options...
jerome Posted July 8, 2015 Author Share Posted July 8, 2015 Hi guys, "a feature a day keeps the DK away" Let's go today for the particle rotation quaternion :http://www.babylonjs-playground.com/#2KSQ1R#39 Here, I just set a classic SPS. Just note I don't call for now the setParticles() method in the render loop (line 78), so it doesn't call the updateParticle() method each frame.Take a look at initParticles() (line 49) and updateParticle() (from line 65).As you can see, I don't use any longer the particle rotation property (which still exists, don't worry) but a new property called quaternion in order to set each particle rotation quaternion (amazing, isn't it ?). Why a quaternion and not just a rotation ?Because it could be easier sometimes to define a rotation around an axis than from euler angles only.If you look at the updateParticle() code, you will see that I give each particle a rotation (zero for now) around the axis origin-particle position. So each particle will then rotate around the axis what starts at the origin and what holds the particle. Let's uncomment the line 78 : http://www.babylonjs-playground.com/#2KSQ1R#40 It's not that easy to check, but each particle now rotates around a radius (O-particle)... maybe slower (sorry DK for this one-more-PG ) : http://www.babylonjs-playground.com/#2KSQ1R#41 [EDIT] : added radius lines so it is easier to understand : http://www.babylonjs-playground.com/#2KSQ1R#42 As for standard BJS meshes, if you define a particle quaternion, its rotation property is ignored. updated doc : https://github.com/BabylonJSX/SolidParticleSystem Quote Link to comment Share on other sites More sharing options...
jerome Posted July 8, 2015 Author Share Posted July 8, 2015 Hi people, As usual, here is the second feature of the day Well, as this one is really powerful and complex (imHo), it is not enabled by default.Let's go : http://www.babylonjs-playground.com/#2KSQ1R#43 You can see a usual SPS with 100 cubes and 50 spheres orbiting.Line 71 :PS.enableParticleVertex();This will make the user custom updateParticleVertex(particle, vertex, i) to be called on each vertex of each particle !particle is the current particlevertex the current vertexi the index of the current (i-th) vertex What is this for ?Well you can now morph your particles dynamically !line 64 , let's define a custom function : PS.updateParticleVertex = function(particle, vertex, i) { if (particle.shapeId == 1) { vertex.x += 1.2 * Math.cos( ang * i / 1000 ); } };Here, I set a new x value to each vertex of particles with shapeId equal to 1 (my spheres). Since I can access the vertex index, I use this value to multiply it by an increasing angle :http://www.babylonjs-playground.com/#2KSQ1R#44 Well, the example may be not be that pertinent because the morph function is really simple here, but you can see that only spheres are morphed. Does it still work with other properties like rotation ?Yes, sir : http://www.babylonjs-playground.com/#2KSQ1R#45line 59 Have fun ! I think this will be the last feature of the SPS as I it is quite versatile now, being able to redo almost a BJS like particle system if you use only quads with no normals and other optimizations (with disableXXX() methods) to some complex slower and parametrable 3D shape system with all mesh properties. Vousk-prod. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.