grire974 Posted September 22, 2015 Share Posted September 22, 2015 This is probably quite a simple problem to solve; but I'm pretty new to BabylonJS. I would like users of my code to be able to arbitrarily scale a 3D model loaded from a .babylon file using code like this: BABYLON.SceneLoader.Load("", "model.babylon", engine, function (newScene) {newScene.executeWhenReady(function () {... After the scene has been rendered using, engine.runRenderLoop(function() {newScene.render();}); I'm then trying to apply the user defined scaling value like this (for example 200% scaling): for (i = 0; i < newScene.meshes.length; i++){ newScene.meshes[i].scaling = new BABYLON.Vector3(2, 2, 2); } As you can see from the attached images of normal vs scaled; the 200 percent scaled version isn't scaled proportionately; e.g. the wheels out grow the chassis of the vehicle. Is this the correct way to scale a scene of multiple meshes? Should I instead be adding all my meshes to a parent node and then scaling that? (if so how). Appreciate the help; thanks! Quote Link to comment Share on other sites More sharing options...
ChrisR Posted September 22, 2015 Share Posted September 22, 2015 This could be because the scale of the mesh before you set it isn't 1,1,1 (which is sometimes the case when importing meshes). You could try,for (i = 0; i < newScene.meshes.length; i++){ newScene.meshes[i].scaling.multiply(new BABYLON.Vector3(2, 2, 2)); } What happens to the mesh if you set it to (1,1,1) does the mesh change size? Quote Link to comment Share on other sites More sharing options...
grire974 Posted September 23, 2015 Author Share Posted September 23, 2015 Good question - I think I'd already tried that; Tried it again just to be sure... All 6 meshes are showing initial scaling of {x: 1, y: 1, z: 1}.. also noticed that you added the .multiply member of the Vector3 class into your code; so I tried some variations of that - however as you have it; I don't think it will have any effect as its a statement rather than an assignment, I did try something like this though:newScene.meshes[i].scaling = newScene.meshes[i].scaling.multiply(new BABYLON.Vector3(2, 2, 2));However this still gave me the out of proportion scaling shown in my 200 percent attachment. Any other thoughts? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 23, 2015 Share Posted September 23, 2015 a good idea would be to have an object which will be the parent of all others objects and just set parent.scaling = new BABYLON.Vector3(2, 2, 2); Quote Link to comment Share on other sites More sharing options...
grire974 Posted September 23, 2015 Author Share Posted September 23, 2015 Yeh I figured it would be something like that.. Using cocos3d I used something similar; attaching the model (including its meshes) to a node; & then performing scaling / positioning/ rotation operations on that parent node.. Looking at the API documentation for Babylon though; I'm not too sure how that might look; the Node class doesn't have the scaling member; and Scene doesn't seem to extend any other classes (nor does it have the scaling property either). Any hints? p.s thanks for the quick reply! Quote Link to comment Share on other sites More sharing options...
grire974 Posted September 23, 2015 Author Share Posted September 23, 2015 more specifically I mean; what type of parent class should I be adding my imported .babylon file to? & what does the code for that look like? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 23, 2015 Share Posted September 23, 2015 just create a box, make it like box.isVisible = false and then set myObject.parent = box Quote Link to comment Share on other sites More sharing options...
grire974 Posted September 23, 2015 Author Share Posted September 23, 2015 Thanks for that tip.. I tried something like this: var m = BABYLON.Mesh.CreateBox('pmesh',15000, newScene);m.isVisible = false; for (i = 0; i < newScene.meshes.length; i++){ newScene.meshes[i].parent = m;} m.scaling = new BABYLON.Vector3(2, 2, 2); However, unfortunately it doesn't work; I get a javascript error with babylon.js: Uncaught RangeError: Maximum call stack size exceeded. Its citing line 6; however the file is minified so I'm not so sure. Before the error is thrown, there are numerous console logs: t.isEnabled @ babylon.js:6 Any thoughts? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 23, 2015 Share Posted September 23, 2015 I think that this is because you try to set m.parent = m you have to check if newScene.meshes[i] !== m in your loop Quote Link to comment Share on other sites More sharing options...
grire974 Posted September 24, 2015 Author Share Posted September 24, 2015 aha! Of course.. Thanks for that. For those of you reading the thread this was my code that solved it for me: var m = BABYLON.Mesh.CreateBox('pmesh',15000, newScene);m.isVisible = false; for (i = 0; i < newScene.meshes.length; i++){ if(newScene.meshes[i].id == 'ground1'){continue}//substitute 'ground1' for the id of any mesh you don't want to scale if(newScene.meshes[i].id == 'pmesh'){continue} newScene.meshes[i].parent = m;} m.scaling = new BABYLON.Vector3(2, 2, 2);//e.g. for 200% scaling Quote Link to comment Share on other sites More sharing options...
grire974 Posted September 24, 2015 Author Share Posted September 24, 2015 p.s. deltakosh - on a side note while I've got you here; not sure if you're interested but I made a fix to the FBX exporter visual c++ solution a couple of weeks back.. However couldn't get my pull request to be accepted; are there any permissions that I need to be aware of for the github repo? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 24, 2015 Share Posted September 24, 2015 Hello! No there is no permission: jsut fork it, make your fix, commit and create a pull request Quote Link to comment Share on other sites More sharing options...
oschakravarthi Posted January 6, 2019 Share Posted January 6, 2019 Hi @Deltakosh Can you please help with same problem explained in a different thread ? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Guest Posted January 7, 2019 Share Posted January 7, 2019 Hey we moved to a new forum: forum.babylonjs.com Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.