Jump to content

[SOLVED] - Physics imposter change needed


MackeyK24
 Share

Recommended Posts

I really need to be able to hook into physics collision detection... There used to be a mesh.onPhysicsCollide that would have worked perfectly for my collision detection system (I basically don't require the imposter filter part for collision detection... I will filter based off mesh.metadata tags).  Now using the registerOnPyhsicsCollide DOES NOT WORK without some kind of imposter (even with the otherImposter.length === 0). The problem is the unregister DOES NOT find if you pass null imposter or empty imposter array... you gotta pass an actual imposter to filter or you WONT be able to unregister.... and you will leak.

I need basic collision detection support... I will handle (filter) what should be imposter collision event should get dispatched.

I suggest the SMALL change to the babylon.physicsImpostor class:

        /**
         * Legacy collision detection event support
         */
        public onCollideEvent: (collider:BABYLON.PhysicsImpostor, collidedWith:BABYLON.PhysicsImpostor) => void = null;

        //event and body object due to cannon's event-based architecture.
        public onCollide = (e: { body: any }) => {
            var otherImpostor = this._physicsEngine.getImpostorWithPhysicsBody(e.body);
            if (otherImpostor) {
                // Legacy collision detection event support
                if (this.onCollideEvent) {
                    this.onCollideEvent(this, otherImpostor);
                }
                if (!this._onPhysicsCollideCallbacks.length) return;
                this._onPhysicsCollideCallbacks.filter((obj) => {
                    return obj.otherImpostors.indexOf(otherImpostor) !== -1
                }).forEach((obj) => {
                    obj.callback(this, otherImpostor);
                })
            }
        }

 

What do you think @Deltakosh @Sebavan @RaananW ...

OR 

Should i just fork my own BabylonJS Toolkit Version of the framework... And i will just use my own build for the toolkit: /Assets/Babylon/Library/babyblon.bjs

(Which might not be a BAD idea... At least i would have better control of the main babylonjs library and the API that is necessary for me to make the KOOL toolkit features i have been working on)

I dunno ... Please folks... Weigh in your thoughts before i do anything drastic with the toolkit libraries :(

 

Link to comment
Share on other sites

9 hours ago, Deltakosh said:

Forking is the worst idea ever as you will have to maintain it alone. We won't be able to keep your tool in the repo as we cannot promote and support many version of the engine.

 

I'm pretty sure you can discuss with @RaananW to find the best way to fit your needs

OK... WONT ever create a separate forked version (except for testing features and submitting PR's of course) :)

Will wait for @RaananW to make a decision :)

 

Link to comment
Share on other sites

I actually have a working solution... waiting for @RaananW to approve it. This is the modified 'onCollide' from the babylon.physicsImposter.ts:

        /**
         * Legacy collision detection event support
         */
        public onCollideEvent: (collider:BABYLON.PhysicsImpostor, collidedWith:BABYLON.PhysicsImpostor) => void = null;

        //event and body object due to cannon's event-based architecture.
        public onCollide = (e: { body: any }) => {
            var otherImpostor = this._physicsEngine.getImpostorWithPhysicsBody(e.body);
            if (otherImpostor) {
                // Legacy collision detection event support
                if (this.onCollideEvent) {
                    this.onCollideEvent(this, otherImpostor);
                }
                if (!this._onPhysicsCollideCallbacks.length) return;
                this._onPhysicsCollideCallbacks.filter((obj) => {
                    return obj.otherImpostors.indexOf(otherImpostor) !== -1
                }).forEach((obj) => {
                    obj.callback(this, otherImpostor);
                })
            }
        }

Works perfect... and NO UNREGISTER LEAKS :)

Link to comment
Share on other sites

SHIT.... @RaananW @Deltakosh @adam ... I AM A TOTAL DUMB ASS (AGAIN)... I AM SOOOOOO SORRY... BEING SOOOO THICK HEADED... I DIDNT REALLY CATCH WHAT YOU WERE SAYING....

Basically you just wanted my dumb ass to check before the 'getImposterWithPhysicsBody' if there are NO CALLBACK AND NO onCollideEvent handler... DONE MOVE DOWN AS I DID... JUST FIX UP TO INCLUDE the !onCollideEvent check...

I feel so stupid.... sorry for all the HU-HAH !!!

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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