Jump to content

Does SceneLoader.ImportMesh import lights and cameras ?


Vousk-prod.
 Share

Recommended Posts

Hi beautiful people,

 

I'm in the process of converting all my SceneLoader.Load to SceneLoader.ImportMesh for a better management with multi scenes, and multi objects files by scene.

 

But I have a little annoying problem: all my scenes are now totally dark... :ph34r: 

It seems that SceneLoader.ImportMesh. doesn't import lights... (maybe it takes care only of meshes, particles system and skeletons, as its name claims - and onsuccess callback args tends to confirm- :P).

 

And since we can now benefit from camera and lights animations with JCPalmer TOB (thanks man !!),  does SceneLoader.ImportMesh import those nicely animated cameras ?

 

Of course we can manually add BJS lights with some piece of code at scene init, but this is not what I need, my Blender lamps are precisely positionned, oriented, powered... and the same for the cameras.

 

I checked in the BJS project source code but there is no SceneLoader.ImportLights or ImportCameras...

 

Any idea, advice ?

 

 

Link to comment
Share on other sites

  • 4 weeks later...

When I copy my meshes from the new scene created with SceneLoader.Load into my already existing scene, I don't have the copied meshes in my scene...

 

I copy meshes, skeletons, materials, textures, multiMaterials, lights, cameras like this :

for (var i = 0; i < scene.meshes.length; i++) {    myExistingScene.meshes.push(scene.meshes[i]);}for (var i = 0; i < scene.skeletons.length; i++) {    myExistingScene.skeletons.push(scene.skeletons[i]);}for (var i = 0; i < scene.materials.length; i++) {    myExistingScene.materials.push(scene.materials[i]);}for (var i = 0; i < scene.multiMaterials.length; i++) {    myExistingScene.multiMaterials.push(scene.multiMaterials[i]);}for (var i = 0; i < scene.textures.length; i++) {   myExistingScene.textures.push(scene.textures[i]);}for (var i = 0; i < scene.cameras.length; i++) {   myExistingScene.cameras.push(scene.cameras[i]);}for (var i = 0; i < scene.lights.length; i++) {    myExistingScene.lights.push(scene.lights[i]);}

But at the end myExistingScene does not contain the loaded meshes. lights and cameras are here, but not the meshes (and getTotalVertices() confirms that)...

Any idea ?

Link to comment
Share on other sites

My guess of your problem is due to the fact that the BABYLON.Node (parent of mesh) is passed scene in constructor.  It copies scene to this._scene.  I think this is going to make a mess for copying meshes across scenes.

 

Option 1:  Inline JS (if you do not have mesh instances)

TOB generated code is passed a scene, so things are very incremental / additive.  Also everything is done synchronously.  I seem to remember someone having race conditions with multiple .importMesh(es) and textures files.  This multi-import was the original reason for TOB.

 

Just add a <script> tag for each .js file in the <header>.  If you want to add everything from a given .js there is a convenience method initScene(scene, materialsRootDir).  If you wish to pick and choose, just grab the parts of initScene() of interest, & copy to your .html.  Here is the camera animation sample code:

var camera_anim = (function(){    var internal = {};    internal.initScene = function(scene, materialsRootDir = "./"){        if (typeof(BABYLON.Engine.Version) === "undefined" || Number(BABYLON.Engine.Version.substr(0, 4)) < 1.14) throw "Babylon version too old";        scene.autoClear = true;        scene.clearColor    = new BABYLON.Color3(0,0,0);        scene.ambientColor  = new BABYLON.Color3(0,0,0);        scene.gravity = new BABYLON.Vector3(0,-9.81,0);        // define materials & skeletons before meshes        internal.defineMaterials(scene, materialsRootDir);        internal.defineSkeletons(scene);        // instance all root meshes        new internal.Cylinder_003_4("4Cylinder.003", scene);        new internal.Cylinder_002_4("4Cylinder.002", scene);        new internal.Cylinder_001_4("4Cylinder.001", scene);        new internal.Cylinder_4("4Cylinder", scene);        new internal.Cylinder_purple_001_2("2Cylinder.purple.001", scene);        new internal.Cube_tex_001_3("3Cube_tex.001", scene);        new internal.Cube_tex_3("3Cube_tex", scene);        new internal.Ground_5("5Ground", scene);        new internal.Cube_blue_1("1Cube.blue", scene);        new internal.Cube_teal_1("1Cube.teal", scene);        new internal.Cylinder_purple_2("2Cylinder.purple", scene);        // define cameras after meshes, incase LockedTarget is in use        internal.defineCameras  (scene);        // cannot call Shadow Gen prior to all lights & meshes being instanced        internal.defineLights   (scene);        internal.defineShadowGen(scene);    };

The entire contents is inserted with: camera_anim.initScene(scene);

Just one root level mesh could also be grabbed with:  var cube = new camera_anim.Cube_teal_1("my name", scene);  No need to run defineMaterials() or defineSkeletons(), since they are run inside each mesh constructor (but only loaded once).

 

Option 2: (Fix SceneLoader to have the option of passing a pre existing scene)

Everything then could be additive.  Not sure how.  I am in the process of editing babylonFileLoader.ts so Automatons can come in from a .babylon, and I think it has to be higher than that.  Not saying you might get the existing code base to work, but better to improve the code base, than have spaghetti code.

Link to comment
Share on other sites

On the fix the code base front, option 2, I have a one line change to BABYLON.SceneLoader.Load().  It is done without changing arguments, since multiple optional args at the end are tricky / ugly.

 

Basically, the engine has a .scenes[ ].  When it has length 1, the stuff is dumped into the existing scene.

 

It built successfully, but I did not test this.  I also have no intention of doing a pull request.  If Deltatosh thinks it is the way to go, it is only one line to retype.

post-8492-0-98432400-1409593963_thumb.pn

Link to comment
Share on other sites

As soon as I posted that, I knew of a side effect / behaviour change free way of doing it in 4 lines.  This time, rename the Load method to Append / changing the engine argument to scene, then delete the create of a new scene.

 

Add a 2 line Load method, that wrappers Append.

 

I tested that Load still worked.  Will submit pull request on request.

 

 

post-8492-0-84829900-1409596593_thumb.pn

Link to comment
Share on other sites

  • 2 weeks later...

No, sorry.  I need DK to say he will grant it.  If I commit it & push it up to my GitHub fork, & he does not want to do it, then it becomes a problem.  You cannot just put in a pull request for some things, only all changes.

 

I had committed something by accident, and ended up re-creating my Github fork once already.  If he does not want to do it, you will have to put it in your fork, & start "Gulping".

 

Thanks for reminding me.

Link to comment
Share on other sites

You can create a branch before commiting on your github repository and sending the pull request, that could prevent some mess and it's then easier to cancel changes if needed. One of the best advantage of git compared to other versionning system is its so well structured branching system, concieved for coding every little piece of code in parallel branches easily without hasardous problem.

Link to comment
Share on other sites

Well I made the commit / push / pull request for SceneLoader.Append using the master.  Starting to use branches.

 

- First, pulled out TOB addin / blender-test dir / Automaton files, and set aside.

- did: git checkout tower_of_babel.py (to revert back working directory)

- fetched & merged from main repository

- Created branch TOB, moved back everything but Automaton stuff

- did a local commit.

 

Now I think I am supposed to a push the TOB branch to my Github fork, right?  Am using mostly Eclipse UI for git, but also have command-line git installed.  See attached Eclipse picture for UI for "Push Branch to Remote".

 

Can u describe how things are to flow (repository, merge, branch wise), please?

 

Jeff

post-8492-0-72114100-1410472858.png

Link to comment
Share on other sites

Yes, you have now to push your branch to your git repository.

I'm not the good one to guide you on this because I'm mostly using git locally, I barely use pulling stuff.

But regarding branches I now understand pretty well this powerfull tool and I'm not scared anymore, thanks to an excellent online book. I strongly encourage you to read the branch related chapter :

http://git-scm.com/book/en/Git-Branching

You will for instance understand difference beetween merge and rebase.

Enjoy !

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