Sign in to follow this  
ian

ToB exporter and collision/impostors problems

Recommended Posts

I attach model. And test project (look below). 

You don't need any server to test it. Just export project zip file and run html in browser!

Original exported ToB file is in directory. (I change this file by hand (some lines in code) and seve it in ProjectTest/js/ToB/1/ModelFInish.js.

What I would like to achive is to add BoxImpostors on each box/cube/mesh which is named as BoxCollider* 
Note: There are boxes which have instances !!!


When I change code by hand and save in ProjectTest/js/ToB/1/ModelFInish.js. I setup scene in file indexToB.html
I add code (for both physics, you can test/try/run any of this but you should comment one of each.

scene.enablePhysics( new BABYLON.Vector3(0, -10, 0), new BABYLON.CannonJSPlugin() );
//scene.enablePhysics( new BABYLON.Vector3(0,-10,0), new BABYLON.OimoJSPlugin() );


MAIN PROBLEM HERE IS WHY COLLISION BETWEEN "Ball" AND "BoxCollider.135" DOES NOT WORK!
AM I MISSING ANYTHING? WHAT IS THE PROBLEM? 
CAN ANYBODY TAKE A LOOK AND HELP ME SOLVE THE PROBLEM?
IT WILL BE VERY GOOD TO TAKE A LOOK AN TEST IT ALSO INSTANCES AND PHYSICS IMPOSTORS! 
IF YOU CAN FIND A PROBLEM WHY COLLISION NOT WORKS AND THAN IF YOU CAN CHANGE/FIX CODE OF ToB EXPORTER SO THAT COLLISION DEFINED IN BLENDER FILE AND/OR CHECKCOLLISION
CAN BE PROPERLY GENERATED WHEN WE EXPORT FROM .BLENDER TO ToB .JS THAN THIS COULD BE VERY GOOD EXPORTER WITH COLLISIONS FOR BABYLONJS !!!

PLEASE LET ME KNOW IF ANYBODY FIND A ERROR IN CODE AND IF AUTOR OF ToB EXPORTER CAN FIX/ADD/REPAIR EXPORTER SO THAT COLLISION/IMPOSTORS CODE IN JS WILL BE SO THAT COLLISION WILL WORKS
IN BABYLONJS WHEN WE IMPORT "ModelFInish.initScene(scene);" ToB .js file.


What I have change in code by hand!
 ProjectTest/js/ToB/1/ModelFInish.js

Ball:
-----

 //this.setPhysicsState({ impostor: 1, mass: 1, friction: .5, restitution: 0});
    this.physicsImpostor = new BABYLON.PhysicsImpostor( this, BABYLON.PhysicsImpostor.SphereImpostor, { mass : 0.2, friction : 0.5, restitution : 0 }, scene);


And Box collider under Ball and its instances
BoxCollider.134 or BoxCollider_134 is main box mesh and it have its instances. I also add checkCollisions = true;!
I change (this boxes/cubes should be colliders/BoxImpostors with mass 0 (I also add 

//this.setPhysicsState({ impostor: 2, mass: 0, friction: .5, restitution: 0});
this.checkCollisions = true;
this.physicsImpostor = new BABYLON.PhysicsImpostor( this, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0, friction : 0.5, restitution : 0.5 }, scene);            

and..

// add below two lines
instance.checkCollisions = true;
instance.physicsImpostor = new BABYLON.PhysicsImpostor( instance, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0.0, friction : 1, restitution : 0 },

---------------------------------------------
 

    var BoxCollider_134 = (function (_super) {
        __extends(BoxCollider_134, _super);
        function BoxCollider_134(name, scene, materialsRootDir, source) {
            _super.call(this, name, scene, null, source, true);

            if (!materialsRootDir) { materialsRootDir = "./"; }
            defineMaterials(scene, materialsRootDir); //embedded version check
            var cloning = source && source !== null;
            var load = _B.Tools.Now;
            var geo = 0;
            var shape = 0;
            this.position.x  = 0;
            this.position.y  = 0;
            this.position.z  = 0;
            this.rotation.x  = 0;
            this.rotation.y  = 0;
            this.rotation.z  = 0;
            this.scaling.x   = 1;
            this.scaling.y   = 1;
            this.scaling.z   = 1;

            this.id = this.name;
            this.billboardMode  = 0;
            this.isVisible  = false; //always false; evaluated again at bottom
            this.setEnabled(true);
            // add below line
            this.checkCollisions = true;
            this.receiveShadows  = false;
            this.castShadows  = false;
            if (!scene.isPhysicsEnabled()) {
                scene.enablePhysics();
            }
            //this.setPhysicsState({ impostor: 2, mass: 0, friction: .5, restitution: 0});
            this.checkCollisions = true;
            this.physicsImpostor = new BABYLON.PhysicsImpostor( this, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0, friction : 0.5, restitution : 0.5 }, scene);            
            if (!cloning){
                geo = _B.Tools.Now;
                this.setVerticesData(_B.VertexBuffer.PositionKind, new Float32Array([
                    -5,.5,-5,-5,-.5,5,-5,-.5,-5,-5,.5,5,5,-.5,5,-5,-.5,5,5,.5,5,5,-.5,-5,5,-.5,5,5,.5,-5,-5,-.5,-5,5,-.5,-5,5,-.5,5,-5,-.5,-5,-5,-.5,5,-5,.5,5,5,.5,-5
                    ,5,.5,5,-5,.5,-5,-5,.5,5,-5,-.5,5,-5,.5,5,5,.5,5,5,-.5,5,5,.5,5,5,.5,-5,5,-.5,-5,5,.5,-5,-5,.5,-5,-5,-.5,-5,5,-.5,5,5,-.5,-5,-5,-.5,-5,-5,.5,5
                    ,-5,.5,-5,5,.5,-5
                ]),
                false);

                var _i;//indices & affected indices for shapekeys
                _i = new Uint32Array(36);
                CONTIG(_i, 0, 0, 35);
                this.setIndices(_i);

                this.setVerticesData(_B.VertexBuffer.NormalKind, new Float32Array([
                    -1,0,0,-1,0,0,-1,0,0,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,0,0,-1,0,0,-1,0,0,-1,0,-1,0,0,-1,0,0,-1,0,0,1,0,0,1,0
                    ,0,1,0,-1,0,0,-1,0,0,-1,0,0,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,0,0,-1,0,0,-1,0,0,-1,0,-1,0,0,-1,0,0,-1,0,0,1,0
                    ,0,1,0,0,1,0
                ]),
                false);

                geo = (_B.Tools.Now - geo) / 1000;
                this.subMeshes = [];
                new _B.SubMesh(0, 0, 36, 0, 36, this);
                if (scene._selectionOctree) {
                    scene.createOrUpdateSelectionOctree();
                }
            }
            if (this.postConstruction) this.postConstruction();
            load = (_B.Tools.Now - load) / 1000;
            _B.Tools.Log("defined mesh: " + this.name + (cloning ? " (cloned)" : "") + " completed:  " + load.toFixed(2) + ", geometry:  " + geo.toFixed(2) + ", skey:  " + shape.toFixed(2) + " secs");
            if (matLoaded && !_sceneTransitionName){
                if (typeof this.grandEntrance == "function") this.grandEntrance();
                else makeVisible(this);

            } else waitingMeshes.push(this);
        }

        BoxCollider_134.prototype.dispose = function (doNotRecurse) {
            _super.prototype.dispose.call(this, doNotRecurse);
            if (this.skeleton) this.skeleton.dispose();
        };

        BoxCollider_134.prototype.makeInstances = function (positionOffset) {
            var instance;
            instance =  this.createInstance("BoxCollider.129");
            instance.position.x  = 0;
            instance.position.y  = 0;
            instance.position.z  = -10;
            instance.rotation.x  = 0;
            instance.rotation.y  = 0;
            instance.rotation.z  = 0;
            instance.scaling.x   = 1;
            instance.scaling.y   = 1;
            instance.scaling.z   = 1;
            // add below two lines
            instance.checkCollisions = true;
            instance.physicsImpostor = new BABYLON.PhysicsImpostor( instance, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0.0, friction : 1, restitution : 0 }, scene);                        
            if (positionOffset) instance.position.addInPlace(positionOffset);
            instance.checkCollisions = false;
            instance =  this.createInstance("BoxCollider.100");
            instance.position.x  = 29.5438;
            instance.position.y  = -2.3742;
            instance.position.z  = 0;
            instance.rotation.x  = 0;
            instance.rotation.y  = 0;
            instance.rotation.z  = 0;
            instance.scaling.x   = 1;
            instance.scaling.y   = 1;
            instance.scaling.z   = 1;
            // add below two lines
            instance.checkCollisions = true;
            instance.physicsImpostor = new BABYLON.PhysicsImpostor( instance, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0.0, friction : 1, restitution : 0 }, scene);
            if (positionOffset) instance.position.addInPlace(positionOffset);
            instance.checkCollisions = false;
            instance =  this.createInstance("BoxCollider.095");
            instance.position.x  = 29.4404;
            instance.position.y  = 2.5005;
            instance.position.z  = -10.0006;
            instance.rotation.x  = 0;
            instance.rotation.y  = 0;
            instance.rotation.z  = 0;
            instance.scaling.x   = 1;
            instance.scaling.y   = 1;
            instance.scaling.z   = 1;
            // add below two lines
            instance.checkCollisions = true;
            instance.physicsImpostor = new BABYLON.PhysicsImpostor( instance, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0.0, friction : 1, restitution : 0 }, scene);
            if (positionOffset) instance.position.addInPlace(positionOffset);
            instance.checkCollisions = false;
            instance =  this.createInstance("BoxCollider.078");
            instance.position.x  = -39.0553;
            instance.position.y  = 5.1819;
            instance.position.z  = 0;
            instance.rotation.x  = 0;
            instance.rotation.y  = 0;
            instance.rotation.z  = 0;
            instance.scaling.x   = 1;
            instance.scaling.y   = 1;
            instance.scaling.z   = 1;
            // add below two lines
            instance.checkCollisions = true;
            instance.physicsImpostor = new BABYLON.PhysicsImpostor( instance, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0.0, friction : 1, restitution : 0 }, scene);
            if (positionOffset) instance.position.addInPlace(positionOffset);
            instance.checkCollisions = false;
            instance =  this.createInstance("BoxCollider.073");
            instance.position.x  = -39.1818;
            instance.position.y  = -4.9811;
            instance.position.z  = -9.9322;
            instance.rotation.x  = 0;
            instance.rotation.y  = 0;
            instance.rotation.z  = 0;
            instance.scaling.x   = 1;
            instance.scaling.y   = 1;
            instance.scaling.z   = 1;
            // add below two lines
            instance.checkCollisions = true;
            instance.physicsImpostor = new BABYLON.PhysicsImpostor( instance, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0.0, friction : 1, restitution : 0 }, scene);
            if (positionOffset) instance.position.addInPlace(positionOffset);
            //instance.checkCollisions = false;
            instance.checkCollisions = true;
        };
        return BoxCollider_134;
    })(BABYLON.Mesh);
    ModelFInish.BoxCollider_134 = BoxCollider_134;

@JCPalmer

@gryff

@Deltakosh

@RaananW

ProjectTest.zip

Model.zip

Share this post


Link to post
Share on other sites

I wrote ToB.  For anything related to physics, in 2014, I just took what the JSON exporter wrote & what file loader did with it on the other side.  Since I do not know anything about it I never tested it.

I am already writing a set to checkCollisions, not for instances though.  BTW, you are checking the 'Check Collisions' check box , right?

As far as instancing a new BABYLON.PhysicsImposter, you might be right.  I cannot find the method 'setPhysicsState' in either Mesh or AbstractMesh.  This might be old.

Have not issue making change, but since I do not know much about it nor have a lot of time, what I would like are 2 files, not just code within a topic:

  • The un-modified file
  • The changes you made.

I can then just diff the 2 files (using Netbeans).  Before that, it looks like you have a problem even with the changes you made.  Get that worked out without me.

Share this post


Link to post
Share on other sites

JCPalmer I will prepare you blender file and now ToB js and how new ToB js should be (tomorrow or some day after tomorow...)

 

I would like to know opinion of problem from someone (maybe @RaananW ) why Ball in this example fall through box impostor/collider. 

In this example Ball should not fall through box collider/impostorji below Ball. I don't know why physics here not work (Cannon or Oimo). I don't know if problem is in my (by hand repaired js ToB file OR IS THERE ANY PROBLEM IN babylon.js file around physics ?

Can @RaananW or @Deltakosh chach or debug my example and babylon.js ? Can anybody help me finder bug/fix?

If we find and fix problem that Ball not fall through box under Ball than I can prepare js file which ToB generate now and another(by hand fix js) so that I can send this two JPAlmer that he can make diff and update/fix ToB exported .

Share this post


Link to post
Share on other sites

Deltakosh exporter ToB .js file is made from .blender file (I attach those files). It is a little bit complicated for PG!

If you download Project.zip and run indexToB.html in browser.  You will see that Ball fall through BoxCollider.134 (this box is under Ball...If you can enable inspector you will see it is BoxCollider.134....) 

"(scene.debugLayer.show(); is in code but as I see now it have problem with babylon.inspector.bundle.js F12 I don't know why ...(on server it works for me...)"

 

whatever.

THE MAIN PROBLEM IS THAT PHYSICS OF Ball and BoxCollider.134 is setup and "Turn on" !! You can see this in code !

I don't know why physics doesn't work as it should work !!

If we can fix that (maybe is .babylon bug or cannon.js or cannon plugin for babylon ..) (my is bug in ToB .js file ( ModelFInish.js ).

 

So if we fix that, than I would like to help JCPalmer to prepare him 2 files onn ToB .js as it is now (old one) and by hand fixed new ToB .js (new one) with correct settings for physics.

I would like to hel JCPalmer to give him "old one" and "new on" ToB .js files. He could make diff on those files and try to make fix for ToB EXPORTER FOR BLENDER.

I would like that ToB exporter will get new MUCH BETTER FEATURE which will allow it to export colliders setting from BLENDER to "ToB .js file".

Greetings
Ian

 

 

 


This playground should work for you and any other who is interesting to see this playground.
I don't see a reason to custom this with PG.
I don't know how to include ToB .js file with PG???

 

 

Share this post


Link to post
Share on other sites

This fix for ToB exporter. If ToB could correctly export colliders from blender, this could be BIG DEAL.
BELEVE ME.

But It is hard form me for now to debug colliders of physics,physics-plugin,cannon or oimo or exported ToB js file. Somewhere must be some bug..
Maybe @RaananW could help us/me to find bug and help us/me to repair/add/fix ToB .js file and than repair/fix ToB Exporter.

Greetings

Ian

Share this post


Link to post
Share on other sites

I just updated exporter to handle those QI & TOWER_OF_BABEL checks.  BTW, having any non-inline textures, is another reason you are actually going need the TOWER_OF_BABEL runtime module.  This is inside of the QI module .

Cleaned up the .blend for a better scene using an arcrotate camera, and an automatic camera light.  Plus flat shading.

 

Share this post


Link to post
Share on other sites

Yes, if you get the exporter I updated today, and you have no textures.  This should be good enough for working your issue.

I will make a playground example which dynamically brings in a QI, but not today.  Something for my documentation.

Share this post


Link to post
Share on other sites

+just some info what I would like to achive.

I am building components visual model and add box colliders around this model. Then I group this together in group in blender. Then I build final model from this components/groups and save them in FinalGroup.
Than in new blender file i append FinalGroup and do ctrl+shift+A. Then I remove all groups. So I get meshes and instances. model+colliders.

Now export this with TOWER_OF_BABEL to get js file (which have all "model meshes+all colliders").

So if we fix ToB. we can get qul exporter which can export model+coliders (FROM BLENDER -> .js).


I will post tomorow (how far I come now).
 

greetings

Ian

 

(My Curiosity. Do babylon have any alternative exporter/importer which can export model+model's colliders ? )

 

Share this post


Link to post
Share on other sites

@JCPalmer

Hi,

Definitely what you can/should change in ToB Exporter is.

 

everywhere do from

this.setPhysicsState({ impostor: 2, mass: .6, friction: .5, restitution: 0});  

to  

this.physicsImpostor = new BABYLON.PhysicsImpostor( this, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0.6, friction : 0.5, restitution : 0 }, scene); 

(value of : type of impostor, mass, friction, restitution should be as they are defined in blender under physics settings...)

-----------------------

I might even ask someone for physics @RaananW if green line up is OK or is there any better recommended way/syntax  alternative.

BUT THIS GREEN LINE UP WORKS OK IF I CHANGE IT EVERYWHERE IN ToB file.

 

Share this post


Link to post
Share on other sites

close enough.  I see physicsImposter is at the AbstractMesh level, therefore will attempt to write info InstancedMesh object  (not for JSON exporter right now).  If it does not work, do not assign a rigid body to them in Blender.

I am seeing that imposter types (see collision shape) no longer line up.  In the old code CONVEX_HULL matched to CONVEX_HULL_IMPOSTER.  I am going to assume this has just been renamed to ParticleImposter.  If not, then it just will not be right.

There is no need to bother Rannan.  Just look at the source code, there is no other way to do it.

Share this post


Link to post
Share on other sites

Ok.  Done.  I see your test blend generated too much code to allow save in playground.  I did not fine any instancedMeshes with rigid body.  Out of time if that does not work.

I did not want to post this .js file & dynamically, since it did not actually work.  The ball falls right thru the maze.  But what is the max size of a playground, @Deltakosh ?

Now that this Bug is closed as far as I am concerned, @satguru, have you tried the Netbeans' Typescript Plugin?  I am using Eclipse for most things.  I like the Python editor better there, unless the Netbeans one has improved.  The Typescript for eclipse looks like it is not being maintained.  I use Gulp for everything now.  Gulp is really great from Eclipse:

gulp.jpg.64746bc0d066e5f1a627c2f271a186cf.jpg

Share this post


Link to post
Share on other sites

@JCPalmer

I mostly use  NetBeans, both at work (Java) and at home (TypeScript). Use  NetBeans typescript plugin a lot. Has worked pretty well for me. Use Visual Code too from time to time.  Light weight and fast. Not a big fan of Eclipse. Haven't used Python a lot, would like to though, if nothing else then just to do more Blender programming. Good support for npm and gulp in NetBeans too. Prefer npm over gulp for my builds. Keeps things simple :) How to Use npm as a Build Tool

Share this post


Link to post
Share on other sites

In following day I will post more details what are still problems. I will send original blender ToB js and hand fixed ToB file so we could do diff between those ToB js files.

But my latest post definitely ToB shuld be fixed.

I found some progress That ball and boxes with mass not fall through colliders. 

 

Greetings 

Ian

Share this post


Link to post
Share on other sites

ToB now generates valid code.  It might not do what you wish, but I no-longer not see it as a bug.  If you have issues with making your scene, you should post to questions & answers as it may or may not be more with how you are building your model.  More people might comment that know more about using Blender in this way there, then in a Bug folder.

Share this post


Link to post
Share on other sites

did you or anybody fix this ? Who is autor of python ToB exporter for blender?

this.setPhysicsState({ impostor: 2, mass: .6, friction: .5, restitution: 0});   (does not work js error take chrome console error !! )

ToB export should generate green and not 

this.physicsImpostor = new BABYLON.PhysicsImpostor( this, BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0.6, friction : 0.5, restitution : 0 }, scene);  (this fix  those problems and objects/meshes have OK setup "Rigid Boxy" physics colliders/impostors) (every object in blender can has collider (box/sphere/capsule/cylinder/cone/convex hull/mesh convex hull is exception is not supporter with cannon or oimo)

YOUR OPINION TESTS?

greetings

Ian

Share this post


Link to post
Share on other sites

OK, Hi again

This is code (attached ToB_BabylonJS_PlayGround.js) which you have to copy/paste in Playground. Why? Because I can not save this code in playground (too much code)

Here is included QueuedInterpolation.1.1.js, ModelFInish.js(fix) Exported from Tower Of Bable, PhysicsColliderDebuger.js (my custom debuger to show where are colliders - pink wireframe)
and BEGIN MAIN .... END MAIN section which set physics and load ToB model.

I export final scene from ModelFInish.blend. Final scene is builded from components(groups in blender). Scene is build from components(groups) and add
in SceneFinslGroup. (I use ctrl+shift+A) and remove groups so I get final scene. Object have more then one "data block". ToB export those object as instance.

After export final scene from blender I get ModelFInish.js(original) file.
I add BABYLON.PhysicsImpostor to all box(gray) without mass and colliders and box(gray) instances.
Collider also have Big/Gray Ball, Yellow Ball, Blue Box and Yellow Box with mass.

FIRST problem: some colliders have wrong rotation. This is because blender add rotation meshes/instances/box(gray) colliders.
Or babylon physics can't handle with colliders which have rotation(x,y,z) or maybe also scale(x,y,z).

SECOND problem: Ball and boxes partly through box colliders. I don't know what is here problem. (Maybe some bug in physics or ToB file ???)

I attach files Model.blender and ModelFInish.js, ModelFInish.js(original) file ModelFInish_fix.js(fix) hand changed by me.
You can make diff between (original) and (fix). This diff could be interesting for who develop ToB exporter to fix those problems.

PLEASE CODE code from ToB_BabylonJS_PlayGround.js and paste in https://www.babylonjs-playground.com/ and run code. 

@Deltakosh

@JCPalmer

@RaananW

@Wingnut

@gryff
greetings
Ian
 

files.zip

Share this post


Link to post
Share on other sites

Hi again. I don't want to be annoying. 

This post means a lot for me and for better (to debug and fix problems with Babylon colliders/collision and especially to fix Tower of Babel exporter) 

I spend some days to find spots in ToB file and fix code manually to fix collision.

I appeal author of ToB to fix(to make better exporter which can export also physics collision information from blender. And I appeal those authors for physic collider to help find an fix final 3.step file which doesn't works as it should.

Guys I know you are busy and It is Holliday time.

Please save this post for latter free time. Please take this post very serious!  (info where I found problems how should fix ToB to become more powerful exporter which can deal with model and colliders instances.) And babylonJS will gain with every powerful exporter ToB if we fix/add capability to properly export colliders from blender to js!

 

greetings

Ian

Share this post


Link to post
Share on other sites

Deltakosh. I add zip file because code is too big for PR and I have PR save problem !
If you download file.zip, and (ToB_BabylonJS_PlayGround.js) copy/paste in PR and run it must work I test it.

I zip contain ModelFInish.js(this is not orignial ToB js file, I fix it) which can use for diff code with one you Tob exported from 

ModelFInish.blend ----you export with latest ToB  exporter from blender-> ModelFinish_Original.js.


So If you do ModelFinish_Origninal diff ModelFinis.js(in file.zip). you can see what to fix in ToB exporter!

(file.zip contain also Model.blender (with groups), ModelFinis.blender(final scene builded from groups), ModelFinish.js(fixed by me by hand original ToB exported file), 
ToB_BabylonJS_PlayGround.js (this is PlayGround code you just copy and paste in Playground and run, you can debug/inspector colliders because Ball(s) Box(es) have some problem with collider)

Greetings,
Ian

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.