BabylonJS Editor - Scaling Mismatch

Hello!

TLDR: There is a discrepancy between the scaling factor of a mesh within the BabylonJS Editor and within a running instance of a BabylonJS game. I export a mesh’s position and scaling values from the Editor and try to instantiate meshes with those values in my game, but the scaling of the instantiated meshes don’t match in terms of appearance with the meshes from the Editor. As a workaround, I multiply the scaling values by 5 to get them to look as expected. Can anyone help me figure out if there’s something I’m doing wrong so I can avoid having to hack a way around it?


I have been working on a simple export function on and off. After getting lots of help from this forum previously I was able to complete the function and export my scene data from the BabylonJS Desktop Editor into JSON format. At that point I thought I was done with the function and continued to work on the logic within the actual game. Last night I reached a point in development where I was able to finally make use of the exported data and attempt to iterate through the JSON and instantiate the meshes I had exported. I was able to complete that without much ado, however, all of the meshes ended up in sizes that I did not expect and looked unrecognizable from what they appeared within the BabylonJS editor. After some analysis I think the issue is that the scaling of the mesh objects are inconsistent between the BabylonJS Editor “world” and when they get brought into my game .html file.

How is this possible? Like I stated in my other post, I am a newbie to BabylonJS and to game dev in general, so I may be missing some very simple concepts and blowing things way out of proportion. Please see below screenshots to illustrate what I mean (playground):


As you can see, within the Editor, the squares are stacked nicely on top of each other. However, if I take the same position/scaling values of the meshes from the Editor and dump them into a game/playground, they are spread out by 3 or 4 units. If I adjust the scaling of the meshes to 5 times the exported value, then I see a result that more closely aligns with what I’m expecting to see. Please see below (playground):

I would like to avoid doing this workaround for my code, if possible. Could anyone help me understand why it is happening and if it’s avoidable?

Thank you!
Frank

I think it will be easier to look at the problem if you can provide the file you generated from the editor.

Pinging @julien-moreau

Hi Evgeni,

Please see below for a sample:

{
"objects": [{
	"SkyBox": []
}, {
	"test-prefab": [{
		"name": "cube_1",
		"material": "blue",
		"position": "0, 0.5, 0",
		"scaling": "1, 1, 1"
	}, {
		"name": "cube_2",
		"material": "blue",
		"position": "5, 0.5, 0",
		"scaling": "1, 1, 1"
	}]
}]

}

Thanks,
Frank

Thanks, but do you have the .babylon file that you exported from the editor?

It’s the file you can feed Babylon with to display your scene.

I couldn’t upload it with a comment, so I uploaded it externally.

Is this what you are looking for?

That’s it, but your file doesn’t display any cube:

https://www.babylonjs-playground.com/#WGZLGJ#838

To test the scene created in the editor, you should export it as a .babylon file and load it with the appropriate method (see PG above). You should normally see the same thing in the PG than in the editor (at least I think so, I never used the editor).

Hi Evgeni,

Unfortunately, while it is interesting and useful that you can feed a .babylon file into the game instance, that’s not exactly what my use case for the BabylonJS Editor is. I’m only looking to export a few pieces of information about each mesh from the Editor into a JSON object–that’s it. I’m not looking to export the entire editor scene and loading it into a game. This is more of a utility function than anything.

NOTE: There isn’t anything wrong with the export function–the values that it exports matches exactly with the values in the editor transform panel. My issue is that instantiating meshes with those values from the editor creates meshes that are smaller by a factor of 5.

Thanks,
Frank

As said I don’t know the editor at all, but what if there are some global parameters in the babylon file that impact the global rendering? By extracting only a part of the file you would miss those parameters and then could end up with a different rendering.

That’s a wild guess, I think someone more knowledgeable than me should have a look at this.

Hey @frank_lin thanks for that feedback!
Indeed, the editor creates cubes with an arbitrary default size of 5 (Editor/scene-factory.ts at master · BabylonJS/Editor · GitHub). I can change to 1 as it is not a breaking change.
Would you like to have a cube of size 1 instead? This would look better :slight_smile:

1 Like

Bless you! Yes, please :slight_smile:

Noob question: How would I get the update?

Automatically when deployed :slight_smile:
Deploying ASAP. I just have to finish a documentation about photoshop and then I release the 3.2.0 !

1 Like

Awesome! Thank you! And thanks to everyone who commented as well.

2 Likes