# Add 3MF support in engine

**URL:** <https://forum.grid.space/t/add-3mf-support-in-engine/2348>\
**Category:** Uncategorized\
**Created:** [January 28, 2025, 12:52pm UTC](https://forum.grid.space/t/add-3mf-support-in-engine/2348 "2025-01-28T12:52:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Atam\_Panday](https://forum.grid.space/user_avatar/forum.grid.space/atam_panday/32/2127_2.png) [@Atam\_Panday](https://forum.grid.space/u/Atam_Panday)\
**Post date:** [January 28, 2025, 12:52pm UTC](https://forum.grid.space/t/add-3mf-support-in-engine/2348/1 "2025-01-28T12:52:03Z")

</div>

Hi, when only using the engine the parse(data) and load()only seems to support STL:

```auto

parse(data) {
        return new Promise((accept, reject) => {
            try {
                let vertices = new load.STL().parse(data);
                this.listener({parsed: data, vertices});
                this.widget.loadVertices(vertices).center();
                accept(this);
            } catch (error) {
                reject(error);
            }
        });
    }

```

Why not also add support for 3mf using the existing functions?

> <https://github.com/GridSpace/grid-apps/blob/master/src/load/3mf.js>

Thank you,  
Atam Panday

---

<div class="post-metadata">

**Author:** ![stewart](https://forum.grid.space/user_avatar/forum.grid.space/stewart/32/21_2.png) [@stewart](https://forum.grid.space/u/stewart)\
**Post date:** [January 28, 2025, 1:57pm UTC](https://forum.grid.space/t/add-3mf-support-in-engine/2348/2 "2025-01-28T13:57:25Z")

</div>

certainly doable. very few people use this code and it’s never been requested. I would welcome a PR to make this change. 3MF was added long after the engine code existed

---

<div class="post-metadata">

**Author:** ![Atam\_Panday](https://forum.grid.space/user_avatar/forum.grid.space/atam_panday/32/2127_2.png) [@Atam\_Panday](https://forum.grid.space/u/Atam_Panday)\
**Post date:** [January 28, 2025, 4:00pm UTC](https://forum.grid.space/t/add-3mf-support-in-engine/2348/3 "2025-01-28T16:00:34Z")

</div>

haha I don’t know npm stuff, like e.g. how to build a new engine.js?

But maybe I can help with this?

replace dep: load.stl with load.file?

```auto
load(url) {
        return new Promise((accept, reject) => {
            try {
                fetch(url)
                    .then(response => {
                        if (!response.ok) {
                            throw new Error(`Failed to fetch URL: ${response.statusText}`);
                        }
                        return response.arrayBuffer();
                    })
                    .then(buffer => {
                        const fileName = url.split('/').pop();
                        load.File.load_data(buffer, fileName)
                            .then(fileDataArray => {
                                fileDataArray.forEach(fileData => {
                                    const { mesh } = fileData;
                                    this.listener({ loaded: url, vertices: mesh });
                                    this.widget.loadVertices(mesh).center();
                                });
                                accept(this);
                            })
                            .catch(reject);
                    })
                    .catch(reject);
            } catch (error) {
                reject(error);
            }
        });
    }

parse(data, file) {
        return new Promise((accept, reject) => {
            try {
                load.File.load_data(data, file)
                    .then(fileDataArray => {
                        fileDataArray.forEach(fileData => {
                            const { mesh } = fileData;
                            this.listener({ parsed: data, vertices: mesh });
                            this.widget.loadVertices(mesh).center();
                        });
                        accept(this);
                    })
                    .catch(reject);
            } catch (error) {
                reject(error);
            }
        });
    }

```

I used AI for this, I’m not a front-end developer so probably full of bugs 🙂

---

<div class="post-metadata">

**Author:** ![stewart](https://forum.grid.space/user_avatar/forum.grid.space/stewart/32/21_2.png) [@stewart](https://forum.grid.space/u/stewart)\
**Post date:** [January 28, 2025, 9:47pm UTC](https://forum.grid.space/t/add-3mf-support-in-engine/2348/4 "2025-01-28T21:47:36Z")

</div>

AI code gen is just going to produce trash. let’s not further pollute the internet archive with bad data for it to feed on.

---

<div class="post-metadata">

**Author:** ![Atam\_Panday](https://forum.grid.space/user_avatar/forum.grid.space/atam_panday/32/2127_2.png) [@Atam\_Panday](https://forum.grid.space/u/Atam_Panday)\
**Post date:** [January 29, 2025, 8:22am UTC](https://forum.grid.space/t/add-3mf-support-in-engine/2348/5 "2025-01-29T08:22:03Z")

</div>

Can you give some tips how i can generate a new code/engine.js to test locally if I change the code?

---

<div class="post-metadata">

**Author:** ![stewart](https://forum.grid.space/user_avatar/forum.grid.space/stewart/32/21_2.png) [@stewart](https://forum.grid.space/u/stewart)\
**Post date:** [January 30, 2025, 11:45pm UTC](https://forum.grid.space/t/add-3mf-support-in-engine/2348/6 "2025-01-30T23:45:49Z")

</div>

have you followed the readme to run everything locally? it’s quite simple

---

<div class="post-metadata">

**Author:** ![Atam\_Panday](https://forum.grid.space/user_avatar/forum.grid.space/atam_panday/32/2127_2.png) [@Atam\_Panday](https://forum.grid.space/u/Atam_Panday)\
**Post date:** [February 2, 2025, 5:06pm UTC](https://forum.grid.space/t/add-3mf-support-in-engine/2348/7 "2025-02-02T17:06:55Z")

</div>

Hi Stewart,

I don’t control my backend.  
I can only include the [code/engine.js](https://grid.space/code/engine.js) in the frontend. This means, I cannot launch the whole framework using npm/nodejs.

I also miss notes in the Readme how to generate/export a new code/engine.js if I change the code and need to test it. Without testing I cannot work on a PR.  
With npm build I can create new:  
KiriMoto-linux-x64.zip  
KiriMoto-linux-x86\_64.AppImage

But not a new engine.js like at [https://grid.space/code/engine.js](https://grid.space/code/engine.js)  
How do I do that?

Thanks, Atam

---

<div class="post-metadata">

**Author:** ![stewart](https://forum.grid.space/user_avatar/forum.grid.space/stewart/32/21_2.png) [@stewart](https://forum.grid.space/u/stewart)\
**Post date:** [February 2, 2025, 7:57pm UTC](https://forum.grid.space/t/add-3mf-support-in-engine/2348/8 "2025-02-02T19:57:32Z")

</div>

the `code/engine.js` file is not present in the file-system because it is a composite of multiple code fragments in the system. it is generated by the back-end server at startup and served from a memory cache.

---

<div class="post-metadata">

**Author:** ![Atam\_Panday](https://forum.grid.space/user_avatar/forum.grid.space/atam_panday/32/2127_2.png) [@Atam\_Panday](https://forum.grid.space/u/Atam_Panday)\
**Post date:** [February 3, 2025, 1:20pm UTC](https://forum.grid.space/t/add-3mf-support-in-engine/2348/9 "2025-02-03T13:20:21Z")

</div>

haha that explains, I will try it out

---

<div class="post-metadata">

**Author:** ![Atam\_Panday](https://forum.grid.space/user_avatar/forum.grid.space/atam_panday/32/2127_2.png) [@Atam\_Panday](https://forum.grid.space/u/Atam_Panday)\
**Post date:** [February 8, 2025, 9:01pm UTC](https://forum.grid.space/t/add-3mf-support-in-engine/2348/10 "2025-02-08T21:01:02Z")

</div>

Hi Stewart, I need some help here.

The original engine.js ([https://grid.space/code/engine.js](https://grid.space/code/engine.js)) is 942 KiB  
When I run locally e.g.

```auto
npm i
sudo npm install -g @gridspace/app-server
gs-app-server

```

or on newest branches:

```auto
npm run setup
npm run start

```

I can download it from either  
[http://localhost:8080/code/engine.js](http://localhost:8080/code/engine.js)  
or  
[http://localhost:5309/code/engine.js](http://localhost:5309/code/engine.js)

I tried master, rel-4.1 and rel-4.0 branches.  
All produce a engine.js of 1.4 to 1.5 MiB which is different.

Also, in my test the original engine works:  
this.engine = kiri.newEngine();  
this.engine.parse(data);

However, all the custom builds, **with no code change** give some error

> parse [https://kubify.nl/code/engine.js:600](https://kubify.nl/code/engine.js:600) TypeError: r is undefined

So how can I generate the same engine.js locally as the live one?  
Which branch is used live?

Once I can reproduce that, I can try and make the change and test it.  
But I need the baseline.
