# Babylon Editor Set Mesh Programmatically

**URL:** <https://forum.babylonjs.com/t/babylon-editor-set-mesh-programmatically/34610>\
**Category:** Questions\
**Created:** [October 8, 2022, 6:09pm UTC](https://forum.babylonjs.com/t/babylon-editor-set-mesh-programmatically/34610 "2022-10-08T18:09:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![colfrog](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/colfrog/32/27363_2.png) [@colfrog](https://forum.babylonjs.com/u/colfrog)\
**Post date:** [October 8, 2022, 6:09pm UTC](https://forum.babylonjs.com/t/babylon-editor-set-mesh-programmatically/34610/1 "2022-10-08T18:09:42Z")

</div>

Hello! I’m currently learning to use the babylon editor. In the editor, you can add a mesh to the scene and then attach a script to it. This script can then alter the position/rotation/etc of that mesh by referencing `this.position`, `this.rotation`, etc.  
However, I would like to set the mesh programmatically and can’t find how that would be done. I could add my own variable to my class such as `this.myMesh = MeshBuilder()` and reference that for all my translations but I would miss out on a lot of the nifty tools built into the editor classes. Does anyone know the best way to do this? Thanks!

Edit: After doing some more research, it seems my question is more along the lines of: How can I set an instance of the Mesh class to use a box or sphere?

Edit: This seems to work. It’s added as a child which I’m good with. Is this the best way then? There still seems to be some quirks doing it this way

```auto
export default class MyScript extends Mesh {

  public onStart(): void {
    const box = MeshBuilder.CreateBox('testbox');
    this.addChild(box);
  }

```

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [October 10, 2022, 12:05pm UTC](https://forum.babylonjs.com/t/babylon-editor-set-mesh-programmatically/34610/2 "2022-10-10T12:05:04Z")

</div>

cc @julien-moreau

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [November 7, 2022, 12:56pm UTC](https://forum.babylonjs.com/t/babylon-editor-set-mesh-programmatically/34610/3 "2022-11-07T12:56:58Z")

</div>

bump @julien-moreau

---

<div class="post-metadata">

**Author:** ![flex](https://avatars.discourse-cdn.com/v4/letter/f/8baadc/32.png) [@flex](https://forum.babylonjs.com/u/flex)\
**Post date:** [November 7, 2022, 1:47pm UTC](https://forum.babylonjs.com/t/babylon-editor-set-mesh-programmatically/34610/4 "2022-11-07T13:47:49Z")

</div>

Here’s a way to do it:

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

Just copy the positions and indices to an empty mesh from the constructor and recalculate the normals.

I’d be curious to hear from the council what the ‘gotchas’ are on this approach. It works great for simple meshes.
