# Why does TransformNode constructor have \`scene\` and \`isPure\` parameters?

**URL:** <https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767>\
**Category:** Questions\
**Created:** [July 28, 2023, 4:58am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767 "2023-07-28T04:58:26Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![trusktr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trusktr/32/840_2.png) [@trusktr](https://forum.babylonjs.com/u/trusktr)\
**Post date:** [July 28, 2023, 4:58am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/1 "2023-07-28T04:58:26Z")

</div>

The docs don’t seem to say, except that they’re optional:

> **[TransformNode | Babylon.js Documentation](https://doc.babylonjs.com/typedoc/classes/BABYLON.TransformNode#constructor)**
>
> A TransformNode is an object that is not rendered but can be used as a center of transformation. This can decrease memory usage and increase rendering

Is it not going to work if I don’t pass a scene in? If I load assets, which create scenes, is this going to unexpectedly add my nodes to some random scene if I don’t pass a scene in?

---

<div class="post-metadata">

**Author:** ![11128](https://avatars.discourse-cdn.com/v4/letter/1/d07c76/32.png) [@11128](https://forum.babylonjs.com/u/11128)\
**Post date:** [July 28, 2023, 5:06am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/2 "2023-07-28T05:06:23Z")

</div>

Here’s what it does  
[https://playground.babylonjs.com/#NCL89C](https://playground.babylonjs.com/#NCL89C)

If isPure is false, it will not push to the root transformNodes of the scene.

---

<div class="post-metadata">

**Author:** ![trusktr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trusktr/32/840_2.png) [@trusktr](https://forum.babylonjs.com/u/trusktr)\
**Post date:** [July 28, 2023, 5:15am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/3 "2023-07-28T05:15:42Z")

</div>

I’m guessing this means it will not render anything (none of its child content will render)?

What happens if we load a scene, and then make a transform node without specifying a scene? Will the new transform node be placed into the loaded scene instead of the main scene?

If we make a hierarchy of nodes, do we need to always provide the same scene to every node?

---

<div class="post-metadata">

**Author:** ![11128](https://avatars.discourse-cdn.com/v4/letter/1/d07c76/32.png) [@11128](https://forum.babylonjs.com/u/11128)\
**Post date:** [July 28, 2023, 5:31am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/4 "2023-07-28T05:31:30Z")

</div>

node’s scene is `scene || EngineStore.LastCreatedScene`  
and transform’s scene is` super(node's scene) === Nullable<Scene>`  
That is, if the transform parameter has a scene, it will be attributed to that scene.

1. maybe you not create scene it will be attributed to that null.
2. If you create a scene but the parameter doesn’t have a scene, it will still be attributed to the last applicable scene.

If you have a hierarchy of nodes that you only want to know about in the same scene, you should put the scene accordingly and isPure should also be true.  
If you don’t want to see it in the hierarchy, you can set isPure to false.

---

<div class="post-metadata">

**Author:** ![11128](https://avatars.discourse-cdn.com/v4/letter/1/d07c76/32.png) [@11128](https://forum.babylonjs.com/u/11128)\
**Post date:** [July 28, 2023, 5:34am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/5 "2023-07-28T05:34:49Z")

</div>

Also, it looks like it doesn’t render, but the worked  
[https://playground.babylonjs.com/#NCL89C#2](https://playground.babylonjs.com/#NCL89C#2)

---

<div class="post-metadata">

**Author:** ![trusktr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trusktr/32/840_2.png) [@trusktr](https://forum.babylonjs.com/u/trusktr)\
**Post date:** [July 28, 2023, 5:54am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/6 "2023-07-28T05:54:08Z")

</div>

So confusing. I don’t get why this even works.

> **[Babylon.js Playground](https://playground.babylonjs.com/#NCL89C%234)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Or why this works:

> **[Babylon.js Playground](https://playground.babylonjs.com/#NCL89C%235)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

It seems to all work the same. What is the difference? Why do all objects in Babylon need a scene? And why do they need a scene if they seem to work regardless?

In Three.js it is really simple:

```auto
const mesh = new Mesh(geometry, material)
const node = new Object3D()
node.add(mesh)
// that's all.

```

with no need to have special parameters and pass scenes everywhere.

In Babylon we need to pass scenes everywhere (or else it default to the “last scene”), yet the above examples all work with or without passing a scene, or even creating a new scene so that we have a new “last scene”.

So confused. 🥴

---

<div class="post-metadata">

**Author:** ![11128](https://avatars.discourse-cdn.com/v4/letter/1/d07c76/32.png) [@11128](https://forum.babylonjs.com/u/11128)\
**Post date:** [July 28, 2023, 6:35am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/7 "2023-07-28T06:35:52Z")

</div>

We don’t fully understand the logic of three js, so we don’t know the full relationship to its code, but we know that the

> const scene = new THREE.Scene()  
> …  
> const mesh = new Mesh(geometry, material)  
> scene.add(mesh)  
> …  
> function render() {  
> …  
> renderer.render(scene, camera);  
> …  
> }

check this basic structure, maybe expect node to copy the mesh’s scene.

[https://threejs.org/docs/#api/en/core/Object3D.parent](https://threejs.org/docs/#api/en/core/Object3D.parent)

As for why you need a scene in that structure, I can’t answer that.  
This becomes a question about the overall structure of the engine as to why we made it this way, which is too difficult for me to answer (the shields next to the names are direct development staff).

_The only helpful thing I can say is_  
engine contains the scene and scene contains other things  
I can only assume that these rules are in place because it’s reasonable to assume that creation and destruction are largely managed in such a structure.  
**in babylon**

I also had a hard time transitioning from unity to the world of babylon. 😭

---

<div class="post-metadata">

**Author:** ![trusktr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trusktr/32/840_2.png) [@trusktr](https://forum.babylonjs.com/u/trusktr)\
**Post date:** [July 28, 2023, 7:14am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/8 "2023-07-28T07:14:33Z")

</div>

Try Three.js or [PlayCanvas](https://playcanvas.com/). You’ll find they are both way simpler to develop with. The feature comparison may be different, but the _development experience_ in the other two is way simpler.

---

<div class="post-metadata">

**Author:** ![11128](https://avatars.discourse-cdn.com/v4/letter/1/d07c76/32.png) [@11128](https://forum.babylonjs.com/u/11128)\
**Post date:** [July 28, 2023, 8:09am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/9 "2023-07-28T08:09:02Z")

</div>

Yes, I know what you mean, and in general, in terms of ease of use, three and playcanvas are definitely simpler. I also realize that there is a relative lack of developers and interested users because of that.

but.

As a result, I have to make the implementation I want myself (which means I can make it with any engine for now, even if it is prohibitively expensive) and  
I’m sure that once I get good at it, the simplicity of the concept won’t make a difference.  
There are obviously advantages and disadvantages, but I don’t think the simplicity you’re talking about is a problem for developers at a certain level.

I apologize in advance if this sounds like an attack on you. It’s just an opinion based on what I’ve experienced.

the difficulty is less between Babylon the three OR play canvases than it is between Unity and Unreal Engine. so you should be able to narrow it down pretty quickly.

---

<div class="post-metadata">

**Author:** ![Joe\_Kerr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/joe_kerr/32/39017_2.png) [@Joe\_Kerr](https://forum.babylonjs.com/u/Joe_Kerr)\
**Post date:** [July 28, 2023, 11:31am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/10 "2023-07-28T11:31:26Z")

</div>

re “optional”: [Default parameters - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters)

re “isPure”: [https://github.com/BabylonJS/Babylon.js/blob/e94100614e23affdd641bad1f4604b6589e777ab/packages/dev/core/src/Meshes/transformNode.ts#L188](https://github.com/BabylonJS/Babylon.js/blob/e94100614e23affdd641bad1f4604b6589e777ab/packages/dev/core/src/Meshes/transformNode.ts#L188)

re “scene”: [https://github.com/BabylonJS/Babylon.js/blob/e94100614e23affdd641bad1f4604b6589e777ab/packages/dev/core/src/node.ts#L351](https://github.com/BabylonJS/Babylon.js/blob/e94100614e23affdd641bad1f4604b6589e777ab/packages/dev/core/src/node.ts#L351) | where Node is parent class of TransformNode (see previous link)

re [https://playground.babylonjs.com/#NCL89C#4](https://playground.babylonjs.com/#NCL89C#4) / [https://playground.babylonjs.com/#NCL89C#5:](https://playground.babylonjs.com/#NCL89C#5:) Why is it important to you whether your TF nodes are in “scene.transformNodes”?

re “Why do all objects in Babylon need a scene?” This is a wrong statement. The objects in question give the **option** to provide a scene.

re 3js: Just posting this for comparison purposes.

```auto
// https://threejs.org/docs/#manual/en/introduction/Creating-a-scene

import * as THREE from 'three';

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );

const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

const geometry = new THREE.BoxGeometry( 1, 1, 1 );
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );

camera.position.z = 5;

function animate() {
	requestAnimationFrame( animate );

	cube.rotation.x += 0.01;
	cube.rotation.y += 0.01;

	renderer.render( scene, camera );
}

animate();

```

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [July 28, 2023, 11:43am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/11 "2023-07-28T11:43:36Z")

</div>

> [@trusktr](#):
>
> You’ll find they are both way simpler to develop with. The feature comparison may be different, but the _development experience_ in the other two is way simpler

That’s from a pure dev’s perspective, is it? Because all I can say here is that ‘I’ - as a simple designer and PM - would never have made it as far doing things myself with code in a real-time 3D engine if it wasn’t for BJS. Simple enough, I have been piloting 3D projects for 20+ years - with Unity, Unreal, Cry, three.js… and I never went to the point where I would have even thought of starting to code (rather complex) interactions myself. This until I discovered BJS. So ‘Yes’, the approach is different but things like the doc, the pg, the community make the learning just so much more accessible and enjoyable (my opinion only). And where the ‘versatility’ of the engine may add a level of complexity in steps that true dev (like I believe Yourself) consider as ‘a base’, an immutable base… at later stages, taking new approaches, trying new methods, overall making new ‘attempts’ (as I call’em), BJS starts to really stand out towards what you can (potentially) do and what you will never be able to do. Now I’m not gonna lie: The level of additional ‘efforts’ of course needs to be related towards your resources and the importance of reaching your goal using what some could call an ‘un-conventional’ approach/method.  
And finally, honestly, ‘Yes’ there are still gaps and a lack of ‘normalization’ in BJS. But everyone here does his best to catch-up and things are moving fast. Very fast considering the resources available. Three.js is how many employees?…

---

<div class="post-metadata">

**Author:** ![trusktr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trusktr/32/840_2.png) [@trusktr](https://forum.babylonjs.com/u/trusktr)\
**Post date:** [July 28, 2023, 7:56pm UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/12 "2023-07-28T19:56:37Z")

</div>

> [@Joe\_Kerr](#):
>
> re “optional”: [Default parameters - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters)

I know JavaScript well, but it isn’t obvious why the parameters are optional (the API docs don’t really say). Why give a node a scene? And why not give a node a scene?

> [@Joe\_Kerr](#):
>
> re “Why do all objects in Babylon need a scene?” This is a wrong statement. The objects in question give the **option** to provide a scene.

They seem to be required: if you don’t provide it yourself, then Babylon goes and gets the `LastCreatedScene`, so no matter what, every node is apparently required to have a scene (just not always provided by the constructor).

But even so, I tried previous examples (above), including creating a new scene before making new TransformNodes without specifying scenes for them, which supposedly means they should get the `LastCreatedScene` that I made, yet the examples work the same, so I don’t get what the difference is. Either that, or there’s really a difference and it has caused some sort of weird memory leak where nodes are used in one scene but state is stored for them in the second scene. Its confusing, and means I’d have to really dig deep into the code to understand if I’m shooting myself in the foot or not.

> [@mawa](#):
>
> That’s from a pure dev’s perspective, is it?

Yes indeed, I’m writing code with Babylon, and was referring to the software developer experience.

PlayCanvas has a UI out of the box, just log in and jump right in to the full editor (more like Unity/Unreal than Babylon it seems to me), and f.e. see the docs on the [visual node-based material editor](https://developer.playcanvas.com/zh/shader-editor/introduction/). Besides having this, PlayCanvas code is clean.

As an example, in Three.js and PlayCanvas it has turned out to be way easier than in Babylon to [load an asset into a particular node in a scene graph](https://forum.babylonjs.com/t/loading-babylon-scene-as-a-child-of-a-specific-scene-graph-node/42328/12). I’m surprised at how difficult it is to do some simple things in Babylon. I find the code to be a bit disorganized compared even to JS libs in general, while Three.js is very well organized compared to JS libs of any kind (not just 3D libs).

These are just my opinions and thoughts. No offense intended to anyone. I hope contributors might see this and have a desire to simplify Babylon, as competition benefits everyone (even the non-Babylon users).

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [July 29, 2023, 5:42am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/13 "2023-07-29T05:42:08Z")

</div>

> [@trusktr](#):
>
> software developer experience

I understand. As I said, not a dev, but I can still hear you on that.

> [@trusktr](#):
>
> how difficult it is to do some simple things in Babylon. I find the code to be a bit disorganized

That’s likely (at least partly) correct. I believe it must be partly due to the way BJS is building-up, for a larger part than others, through the Community and also for one of its goal which is to keep with backwards compatibility (eventually at the cost of added complexity/disorganization, as you say).

> [@trusktr](#):
>
> These are just my opinions and thoughts. No offense intended to anyone.

Sure. I always give just my opinion. It’s the only opinion I can give 😉…and things can evolve only when sharing and confronting ideas and opinions, isn’t it so? No offense taken at all. At least, not by me.

> [@trusktr](#):
>
> I hope contributors might see this and have a desire to simplify Babylon,

Absolutely. And as @bghgary said in your other post, your skills would certainly be warmly welcomed if you wanted to help us with your contribution towards ‘simplification’. I can already assure you that ‘simplicity’ is definetely part of the philosophy and something we (I believe the Team and Community) are willing to build on.  
Of course, as I said, my opinion only 😉 and meanwhile, have a great day 🕶

---

<div class="post-metadata">

**Author:** ![trusktr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trusktr/32/840_2.png) [@trusktr](https://forum.babylonjs.com/u/trusktr)\
**Post date:** [October 8, 2023, 6:09am UTC](https://forum.babylonjs.com/t/why-does-transformnode-constructor-have-scene-and-ispure-parameters/42767/14 "2023-10-08T06:09:06Z")

</div>

Babylon’s community is known for its high levels of friendliness and welcomeness. That’s definitely worth a lot. 🙂
