# Scaling a gltf model

**URL:** <https://forum.babylonjs.com/t/scaling-a-gltf-model/23850>\
**Category:** Questions\
**Tags:** gltf\
**Created:** [September 15, 2021, 10:51am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850 "2021-09-15T10:51:13Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![user1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/user1/32/18274_2.png) [@user1](https://forum.babylonjs.com/u/user1)\
**Post date:** [September 15, 2021, 10:51am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/1 "2021-09-15T10:51:13Z")

</div>

I want to scale a gltf model I have . Here is the code I have :

```auto
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>

	<script src="https://cdn.babylonjs.com/babylon.js"></script>
	<script src="https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>
	<script src="https://code.jquery.com/pep/0.4.3/pep.js"></script>
	<script src="https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>

	<style>
	#renderCanvas {
		width: 100%;
		height: 100%;
		touch-action: none;
	}
</style>
</head>
<body>
	<canvas id="renderCanvas" touch-action="none"></canvas>

	<script type="text/javascript">

		const canvas = document.getElementById("renderCanvas"); /*Get the canvas element*/ 
		const engine = new BABYLON.Engine(canvas, true); /*Generate the BABYLON 3D engine*/ 
		let render = true

		const createScene = function () {

			const scene = new BABYLON.Scene(engine);  

			const camera = new BABYLON.ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 2.5, 15, new BABYLON.Vector3(0, 0, 0));
			camera.attachControl(canvas, true);

			BABYLON.MeshBuilder.CreateBox("box",{})

			const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(1, 1, 0));

			BABYLON.SceneLoader.Append("./city_scene_tokyo/", "scene.gltf", scene);

			return scene;
		};
		
		const scene = createScene(); /*Call the createScene function*/

		/* Register a render loop to repeatedly render the scene*/
		engine.runRenderLoop(function () {
			if (render) {
				scene.render();
			}
		});

		/*Watch for browser/canvas resize events*/
		window.addEventListener("resize", function () {
			engine.resize();
		});

	</script>
</body>
</html>

```

Here’s what I tried:

```auto
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>

	<script src="https://cdn.babylonjs.com/babylon.js"></script>
	<script src="https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>
	<script src="https://code.jquery.com/pep/0.4.3/pep.js"></script>
	<script src="https://cdn.babylonjs.com/loaders/babylonjs.loaders.min.js"></script>

	<style>
	#renderCanvas {
		width: 100%;
		height: 100%;
		touch-action: none;
	}
</style>
</head>
<body>
	<canvas id="renderCanvas" touch-action="none"></canvas>

	<script type="text/javascript">

		const canvas = document.getElementById("renderCanvas"); /*Get the canvas element*/ 
		const engine = new BABYLON.Engine(canvas, true); /*Generate the BABYLON 3D engine*/ 
		let render = true

		/*Add your code here matching the playground format*/ 
		const createScene = function () {

			const scene = new BABYLON.Scene(engine);  

			const camera = new BABYLON.ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 2.5, 15, new BABYLON.Vector3(0, 0, 0));
			camera.attachControl(canvas, true);

			BABYLON.MeshBuilder.CreateBox("box",{})

			const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(1, 1, 0));

			let city = BABYLON.SceneLoader.Append("./city_scene_tokyo/", "scene.gltf", scene);
                        city.scaling = new BABYLON.Vector3(0.1,0.1,0.1)

			return scene;
		};
		
		const scene = createScene(); /*Call the createScene function*/

		/* Register a render loop to repeatedly render the scene*/
		engine.runRenderLoop(function () {
			if (render) {
				scene.render();
			}
		});

		/*Watch for browser/canvas resize events*/
		window.addEventListener("resize", function () {
			engine.resize();
		});

	</script>
</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![ynnek](https://avatars.discourse-cdn.com/v4/letter/y/c68b51/32.png) [@ynnek](https://forum.babylonjs.com/u/ynnek)\
**Post date:** [September 15, 2021, 11:17am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/2 "2021-09-15T11:17:39Z")

</div>

Hi!  
I think you can scale down the model by scaling down meshes.  
You can do this in the callback function of the `SceneLoader.Append` method like below.

```javascript
BABYLON.SceneLoader.Append("./city_scene_tokyo/", "scene.gltf", scene, (meshes, _, skeletons) => {
  meshes.forEach((mesh) => {
    mesh.scaling = new BABYLON.Vector3(0.5, 0.5, 0.5)
  })
});
```

---

<div class="post-metadata">

**Author:** ![user1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/user1/32/18274_2.png) [@user1](https://forum.babylonjs.com/u/user1)\
**Post date:** [September 15, 2021, 11:19am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/4 "2021-09-15T11:19:55Z")

</div>

Thanks!  
But what is \_, skeletons?

---

<div class="post-metadata">

**Author:** ![ynnek](https://avatars.discourse-cdn.com/v4/letter/y/c68b51/32.png) [@ynnek](https://forum.babylonjs.com/u/ynnek)\
**Post date:** [September 15, 2021, 11:23am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/5 "2021-09-15T11:23:58Z")

</div>

The callback function has some parameters like meshes, particleSystems, skeletons and so on.  
You can check these in the console like the code below.

```javascript
BABYLON.SceneLoader.Append("./city_scene_tokyo/", "scene.gltf", scene, (...params) => {
  console.log(params)
});
```

---

<div class="post-metadata">

**Author:** ![user1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/user1/32/18274_2.png) [@user1](https://forum.babylonjs.com/u/user1)\
**Post date:** [September 15, 2021, 11:24am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/6 "2021-09-15T11:24:38Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [September 15, 2021, 2:47pm UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/7 "2021-09-15T14:47:35Z")

</div>

@ynnek please consider creating your repro in the babylon playground next time 🙂 [https://playground.babylonjs.com/](https://playground.babylonjs.com/)

---

<div class="post-metadata">

**Author:** ![user1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/user1/32/18274_2.png) [@user1](https://forum.babylonjs.com/u/user1)\
**Post date:** [September 16, 2021, 2:48am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/8 "2021-09-16T02:48:16Z")

</div>

It’s not working . I tried it like you said ,

```auto
BABYLON.SceneLoader.Append("./city_scene_tokyo/", "scene.gltf", scene, (meshes, skeletons) => {
				meshes.forEach((mesh) => {
					mesh.scaling = new BABYLON.Vector3(0.1, 0.1, 0.1)
				})
		});

```

---

<div class="post-metadata">

**Author:** ![ynnek](https://avatars.discourse-cdn.com/v4/letter/y/c68b51/32.png) [@ynnek](https://forum.babylonjs.com/u/ynnek)\
**Post date:** [September 16, 2021, 3:55am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/9 "2021-09-16T03:55:32Z")

</div>

@user1 I don’t know your model’s data… So I can’t figure out the problem…  
Check out the PG below where the scaling process works well!

[https://playground.babylonjs.com/#92Y727#159](https://playground.babylonjs.com/#92Y727#159)

---

<div class="post-metadata">

**Author:** ![user1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/user1/32/18274_2.png) [@user1](https://forum.babylonjs.com/u/user1)\
**Post date:** [September 16, 2021, 5:16am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/10 "2021-09-16T05:16:20Z")

</div>

My model : [City Scene Tokyo - Download Free 3D model by Sooi Cherchye (@sooi) [b25d23f] - Sketchfab](https://sketchfab.com/3d-models/city-scene-tokyo-b25d23ff186949dca3df669c14447db5)

---

<div class="post-metadata">

**Author:** ![ynnek](https://avatars.discourse-cdn.com/v4/letter/y/c68b51/32.png) [@ynnek](https://forum.babylonjs.com/u/ynnek)\
**Post date:** [September 16, 2021, 7:34am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/11 "2021-09-16T07:34:19Z")

</div>

@user1 I don’t know if it is because of my working environment, but I can’t even load the file…  
I double-checked with blender and also failed…

---

<div class="post-metadata">

**Author:** ![user1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/user1/32/18274_2.png) [@user1](https://forum.babylonjs.com/u/user1)\
**Post date:** [September 16, 2021, 11:53am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/12 "2021-09-16T11:53:52Z")

</div>

Ok , thanks for trying . I’ll see what I can do.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [September 16, 2021, 1:31pm UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/13 "2021-09-16T13:31:31Z")

</div>

@user1 please please create a repro in the playground

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [September 16, 2021, 3:53pm UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/14 "2021-09-16T15:53:17Z")

</div>

Please provide a playground, but if you want to scale the model, you don’t want to loop through all the meshes. That will scale multiple times (at least twice) since there is a root mesh that is the parent of everything. You should be able to scale the model by scaling just the root mesh, which is always `mesh[0]` returned by the loader.

---

<div class="post-metadata">

**Author:** ![user1](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/user1/32/18274_2.png) [@user1](https://forum.babylonjs.com/u/user1)\
**Post date:** [September 17, 2021, 2:38am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/15 "2021-09-17T02:38:55Z")

</div>

But how do I load my own model in the playground?

---

<div class="post-metadata">

**Author:** ![ynnek](https://avatars.discourse-cdn.com/v4/letter/y/c68b51/32.png) [@ynnek](https://forum.babylonjs.com/u/ynnek)\
**Post date:** [September 17, 2021, 3:14am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/16 "2021-09-17T03:14:26Z")

</div>

@bghgary Thanks for correcting my mistake!

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [September 17, 2021, 9:22am UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/17 "2021-09-17T09:22:39Z")

</div>

> [@user1](#):
>
> But how do I load my own model in the playground?

This doc should help:

> **[Using External Assets In the Playground | Babylon.js Documentation](https://doc.babylonjs.com/toolsAndResources/thePlayground/externalPGAssets)**
>
> Learn how to use external assets in the playground in Babylon.js.

---

<div class="post-metadata">

**Author:** ![dirkk0](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dirkk0/32/26524_2.png) [@dirkk0](https://forum.babylonjs.com/u/dirkk0)\
**Post date:** [August 24, 2022, 3:24pm UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/18 "2022-08-24T15:24:47Z")

</div>

I just tested the glTF loader and mesh[0] is not root.  
There seems to be a mesh named ‘ **root** ’ and scale should be applied to this node.

I prepared a demo here:

> **[Glitch Code Editor ･ﾟ✧](https://glitch.com/edit/#!/dk-babylon-bloom?path=index.html%3A93%3A36)**
>
> Simple, powerful, free tools to create and use millions of apps.

Not sure if the specs changed or if this is a bug.

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [August 24, 2022, 3:54pm UTC](https://forum.babylonjs.com/t/scaling-a-gltf-model/23850/19 "2022-08-24T15:54:24Z")

</div>

[SceneLoader.Append](https://doc.babylonjs.com/typedoc/classes/BABYLON.SceneLoader#Append) returns a scene. If you want to get the loaded meshes, you need to call [SceneLoader.ImportMesh](https://doc.babylonjs.com/typedoc/classes/BABYLON.SceneLoader#ImportMesh).
