vujadin / BabylonHx

Port of Babylon.js 3D engine to Haxe.
http:/paradoxplay.com/babylonhx
Apache License 2.0
189 stars 43 forks source link

Particle2 sample - does not work off mainline/master branch #107

Closed duderinone closed 8 years ago

duderinone commented 8 years ago

I was trying to run Particle2.hx using the cutting edge master branch. (running on windows7, lime, html5 target)

It does not seem to work because of the change in the signature of the function passed into registerBeforeRender. So i patched it in my sand box "function (s:Scene, ?es:EventState)".

Still did not work, its failing here:

Scene.hx:1893


        var beforeParticlesDate = Tools.Now();
        if (this.particlesEnabled) {
            for (particleIndex in 0...this.particleSystems.length) {
                var particleSystem = this.particleSystems[particleIndex];
                if (!particleSystem.isStarted()) {
                    continue;
                }
                if (particleSystem.emitter.position == null || (particleSystem.emitter != null && particleSystem.emitter.isEnabled())) {
                                        // ******fails here******
                    this._activeParticleSystems.push(particleSystem);
                                        // *******fails here******
                    particleSystem.animate();
                }
            }

What seems to be happening here is _activeParticleSystems is of type SmartArray, but when we "push" SmartArray::push our particleSystem into _activeParticleSystems, it fails in SmartArray::push

https://github.com/vujadin/BabylonHx/blob/master/com/babylonhx/tools/SmartArray.hx#L33 So perhaps this line should really say: thissmartArrayFlags[this._id] = this._duplicateId; Perhaps we just initialize smartArrayFlags in the constructor of ParticleSystem ?

So i changed that in my sandbox and still not working :-( Its failing here https://github.com/vujadin/BabylonHx/blob/master/com/babylonhx/particles/ParticleSystem.hx#L385

_effect never gets defined when you setup a customEffect. So what i did is change https://github.com/vujadin/BabylonHx/blob/master/com/babylonhx/particles/ParticleSystem.hx#L194 to this._effect = this._getEffect();

The particles2 demo then worked and its pretty nice.

I am actually a C++ programmer - and have never done haxe (yes hax noob!). So i dont know if the master branch has these bugs or if i am just doing something fundamentally wrong ?

I tried the android targets and they are simply stunning. Amazing performance and the fact that it just worked on several android devices is something that i never expected ! This port of babylonjs to haxe by vujadin is simply fantastic!!.

vujadin commented 8 years ago

Hi, I'm glad you like BHx :) You're right about all you said, __smartArrayFlags wasn't initialized and this._effect was null. I've fixed this in now with 27b96a3c73d32dd7132f022abbae4985af04a921 and updated all 4 particles samples in 5cd9ec8. Thank you for your help :+1: