Jump to content

BABYLON.SceneLoader - positioning and scaling issues - the saga continues


Zimbofly
 Share

Recommended Posts

Hi all - I've done as much searching as possible and tried so many different things - STILL, I'm struggling to position or resize any files from Blender exporter.

THis is driving me nuts!!!! 

The model will display, but refuses to change position and size.

 

here are a few codes I've tried.....

var LoadChairs = function () {BABYLON.SceneLoader.ImportMesh("", "GalleryAssets/", "office_chair2.babylon", scene, function (newMeshes, particleSystems) {            var benchCenter1 = newMeshes;            benchCenter1.scaling = new BABYLON.Vector3(0.4, 0.3, 0.4);            benchCenter1.rotation.y = Math.PI / 1;            benchCenter1.position = new BABYLON.Vector3(8, 0.1, 0);            shadowGenerator.getShadowMap().renderList.push(benchCenter1);        });}

This brings the chair in - BUT no scaling/position response

post-9224-0-65518700-1406391660.png

var LoadChairs = function () {BABYLON.SceneLoader.ImportMesh("", "GalleryAssets/", "office_chair2.babylon", scene, function (newMeshes, particleSystems) {            var benchCenter1 = newMeshes[0];            benchCenter1.scaling = new BABYLON.Vector3(0.4, 0.3, 0.4);            benchCenter1.rotation.y = Math.PI / 1;            benchCenter1.position = new BABYLON.Vector3(8, 0.1, 0);            shadowGenerator.getShadowMap().renderList.push(benchCenter1);        });}

This brings the chair in and the first mesh - here the first mesh responds to position and resizing - you can see it to the right in the image below.

post-9224-0-96981400-1406391927.png

BABYLON.SceneLoader.ImportMesh("", "GalleryAssets/", "office_chair2.babylon", scene, function (newMeshes, particleSystems) {            newMeshes[0].position = new Babylon.vector3(10, 1, 10);            newMeshes[0].scaling = new Babylon.vector3(0.5, 0.5, 0.5);        });

chair comes in - no scaling/position response

 

 

a)  is this something I'm doing wrong in calling my routine, or I've left out

B) lack of understanding of meshes

c) problem with the way I'm exporting these files from Blender - I have tried quite a few and all giving the same issue. - I've attached a zip of office_chair2.babylon file

Is there something I should be doing in blender b4 exporting????

 

another related problem is that if  try load more than one mesh, then the second one gives console error - Cannot set property 'y' of undefined.....

 

Can anyone help please :(

this has and has been going on for days -

I realize it's most likely my lack of understanding of meshes etc -but it's driving me nuts!!!!!

 

office_chair2.zip

Link to comment
Share on other sites

Forgive me, I did not watch the first instalment (hopefully this is not a trilogy :) ).  These properties you are changing are copied and cached.  Presumably the cached versions exist for a reason.  After changing the objects, you could call a method which re-copies to the cached versions:

 

newMeshes[0].computeWorldMatrix(true);

 

There is a _isSynchronized(), which detects if something has been changed, but maybe it has already been called & found no changes, then you changed it.  Actively, forcing a copy to cache, would at least rule that out.
 

Link to comment
Share on other sites

Hi dad72 - welding objects to a single mesh sounds exactly what i need - must it be done in blender b4 export or Babylon?

 

Good comment JCPalmer - hope it's not a trilogy either  :)   -   I will play with the cache idea - thanks

 

any other ideas out there?

Link to comment
Share on other sites

Well, what you could do in Blender is, parent all of the meshes to a single parent.  If you then explicitly import that mesh,  FileLoader will also import child meshes.  Once in the callback, find the mesh object, & do your thing:

BABYLON.SceneLoader.ImportMesh("bigDaddy", "GalleryAssets/", "office_chair2.babylon", scene, function (newMeshes, particleSystems) {            var bigDaddy = scene.getMeshByID("bigDaddy");            bigDaddy.position = new Babylon.vector3(10, 1, 10);            bigDaddy.scaling = new Babylon.vector3(0.5, 0.5, 0.5);        });

That is not to say that there may be performance improvements to making a single mesh.  I would do it on the Babylon side, to keep your editing options cleaner in Blender.  This doc talks about it in Step 5: http://blogs.msdn.com/b/davrous/archive/2014/02/19/coding4fun-tutorial-creating-a-3d-webgl-procedural-qrcode-maze-with-babylon-js.aspx

 

Finally, you might want to do both.  It might be easier in Blender to work with the meshes if they were parented.  For Blender info on parenting see: http://wiki.blender.org/index.php/Doc:2.6/Manual/Modeling/Objects/Groups_and_Parenting

Link to comment
Share on other sites

THANKYOU JC - finaly got it all working - I owe you a beer!  :)

 

since making the all the meshes to a single parent, and using this code from temechon - http://www.html5gamedevs.com/topic/1896-problem-with-babylonsceneloaderimportmesh/ (I think very similar to yours)

BABYLON.SceneLoader.ImportMesh("", "GalleryAssets/room/", "furniture.babylon", scene, function (newMeshes) {            setup(newMeshes[0]);                        function setup(mesh) {                mesh.position.x = 0;                mesh.position.z = 24;                mesh.scaling = new BABYLON.Vector3(50, 40, 40);                   mesh.material.emissiveColor = new BABYLON.Color3(0.4, 0, 0);                mesh.material.diffuse = new BABYLON.Color3(0.1, 0.1, 0.1);                shadowGenerator.getShadowMap().renderList.push(mesh);                //mesh.receiveShadows = true;            }

working good - (except I'm getting some strange results when parenting all in blender - so I need to learn a bit more about blender :D )

 

thanks!!!

Link to comment
Share on other sites

  • 2 months later...

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