# Personalized Name Puzzle Customizer Developing WIP (text-mesh.js)

**URL:** <https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765>\
**Category:** Work in progress\
**Created:** [November 9, 2023, 10:12am UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765 "2023-11-09T10:12:24Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Serjozha](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/serjozha/32/28950_2.png) [@Serjozha](https://forum.playcanvas.com/u/Serjozha)\
**Post date:** [November 9, 2023, 10:12am UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/1 "2023-11-09T10:12:24Z")

</div>

Hello everybody, I would like to ask some support and will be very happy for your suggestions, help and advices!

I want to create customizer for name puzzle for kids.  
The logic next:

1. client enter the name, script generates 3d text.
2. client select color scheme, script should change color(material) of each letter according to script scenario.
3. client select if he want additional engraving on the back of the plate.
4. client can add pegs for the letters.
5. client approve product and image is being generated send via api with all selected values to our shop.

I started to work on it and learned many tutorials here and on the forum, but however I hope there can be some things community can help to understand if this possible and how can I implement it.

**step 1.**  
Based on [text-mesh.js](https://github.com/playcanvas/engine/tree/main/scripts/textmesh) script generates text that entered to html input field and when ENTER pressed script regenerates 3d text in viewport (this is step 1.)

```javascript
//this code takes value from html input, put it into TextMesh.text attribute and recreates 3d text
TextMesh.prototype.update = function(dt) {
      if (pc.app.keyboard.isPressed(pc.KEY_ENTER)) {
        this.text = document.getElementById("name").value;
        this.createText();
      }
};

```

**step 2.**  
I can change color of the whole name, but unfortunately I don’t understand, how can I apply different materials randomly to child elements (each letter).  
I tried to set it with those commands:

```javascript
this.material="1"; //this one change whole TextMesh material, this is good
this.entity._children[0].material="2"; // this one apply attribute that undefined previously, but it don't change the material of the selected child element

```

> **question 1** How to apply different material each letter separately?

**step 3**.  
I guess I need to create plate at first and make it size dynamically changing based on the width of the 3d text generated.  
I hope to find in [Documentation](https://api.playcanvas.com/engine/classes/Entity.html) something like, Dimension or Length instead of Position (LocalScale):

```javascript
this.entity.getPosition();
this.entity.getLocalScale();

```

> **question 2** How can I get the width(one axis length) of selected object?

Link to the editor project:  
[https://playcanvas.com/editor/project/1157431](https://playcanvas.com/editor/project/1157431)

Link to the Launch(result) project:  
[https://launch.playcanvas.com/1890395?debug=true](https://launch.playcanvas.com/1890395?debug=true)

I will be very happy to have help, advices, suggestions and will update this post during development and probably will have more questions soon…

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [November 9, 2023, 10:32am UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/2 "2023-11-09T10:32:49Z")

</div>

Hi @Serjozha and welcome!

> [@Serjozha](#):
>
> **question 1** How to apply different material each letter separately?

Maybe the example project below can help you with this.

[https://developer.playcanvas.com/en/tutorials/switching-materials-at-runtime/](https://developer.playcanvas.com/en/tutorials/switching-materials-at-runtime/)

---

<div class="post-metadata">

**Author:** ![Serjozha](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/serjozha/32/28950_2.png) [@Serjozha](https://forum.playcanvas.com/u/Serjozha)\
**Post date:** [November 9, 2023, 11:21am UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/3 "2023-11-09T11:21:52Z")

</div>

Hi @Albertos Thank you for reply, I’ve tried this method already but got an error in console that It’s not possible to read properties of undefined (reading ‘length’)…

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [November 9, 2023, 11:34am UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/4 "2023-11-09T11:34:37Z")

</div>

What is exactly undefined? Can you share the complete error?

---

<div class="post-metadata">

**Author:** ![Serjozha](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/serjozha/32/28950_2.png) [@Serjozha](https://forum.playcanvas.com/u/Serjozha)\
**Post date:** [November 9, 2023, 11:57am UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/5 "2023-11-09T11:57:58Z")

</div>

i’ve added code from ‘switching-materials-at-runtime’ and got the error as on the screenshot below:

 ![2023-11-09 13_36_51-First Project _ Launch](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/e/c/ec9d57e84d5fa41a93431b48fd4bcbaeca054fc4.jpeg)

when I tried to debug, I used command on initializing:

```javascript
TextMesh.prototype.initialize = function () {
....//some code
console.log(this.materials.length);
....//some code
}

```

and also see the same error that it cannot read properties of undefined, I guess it’s materials

at the moment trying to set value with

```javascript
this.material.resource

```

but I don’t understand if this can set or only get values, seems changing values in code, but not in the viewport…

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [November 9, 2023, 12:16pm UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/6 "2023-11-09T12:16:25Z")

</div>

You are probably missing the attribute `materials` that is used in the example project to add the two example materials.

You cannot copy/paste code from an example project directly into your own project. You need to study the example project to be able to know what the code does and how you can use it in your own project.

---

<div class="post-metadata">

**Author:** ![Serjozha](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/serjozha/32/28950_2.png) [@Serjozha](https://forum.playcanvas.com/u/Serjozha)\
**Post date:** [November 9, 2023, 12:24pm UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/7 "2023-11-09T12:24:02Z")

</div>

Ok, thank you @Albertos !  
I will study example more detailed to be able to implement it in my project!  
Hopefully return soon with results!

---

<div class="post-metadata">

**Author:** ![Serjozha](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/serjozha/32/28950_2.png) [@Serjozha](https://forum.playcanvas.com/u/Serjozha)\
**Post date:** [November 9, 2023, 1:33pm UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/8 "2023-11-09T13:33:37Z")

</div>

Hi again, @Albertos , thanks for advice again!  
Managed to change color based on the [“switching-materials-at-runtime”](https://developer.playcanvas.com/en/tutorials/switching-materials-at-runtime/)

But still don’t have luck to change materials for every letter, don’t understand how to select this children elements and set material to each letter separately

![PlayCanvas_Changing Material](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/c/2/c292aec300b168e5e8b73978ced4a42b98952483.gif)

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [November 9, 2023, 9:24pm UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/9 "2023-11-09T21:24:43Z")

</div>

> [@Serjozha](#):
>
> Hi again, @Albertos , thanks for advice again!  
> Managed to change color based on the [“switching-materials-at-runtime”](https://developer.playcanvas.com/en/tutorials/switching-materials-at-runtime/)

Well done! 👌

> [@Serjozha](#):
>
> But still don’t have luck to change materials for every letter, don’t understand how to select this children elements and set material to each letter separately

It’s a bit complicated, because I don’t know how `text-mesh.js` exactly works.

If the text mesh is a parent entity and each letter is a child entity, then you might be able to change the line below a bit, but that’s just a guess.

```javascript
// all letters
var renders = this.entity.findComponents('render');

```

```javascript
// only first letter
var renders = this.entity.children[0].findComponents('render');

```

---

<div class="post-metadata">

**Author:** ![Serjozha](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/serjozha/32/28950_2.png) [@Serjozha](https://forum.playcanvas.com/u/Serjozha)\
**Post date:** [November 12, 2023, 10:37pm UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/10 "2023-11-12T22:37:00Z")

</div>

Hi everyone, once again!  
Dear @Albertos Thank You very much for the advice to the right path to develop!  
I’ve managed to select each letter and run function to change every letter according to chosen color combination by user.

Also as you can see from .gif I’ve developed engraving and pegs for each letter adding and combining text-mesh.js for this.

Also managed to create a screenshots.  
Mostly code for manipulation as a basis I took here from free tutorials and example.  
The hardest part were to understand the workflow of the PlayCanvas, to be honest I fell in love with it and the result!

Some minor changes, probably will be made in the future…

Now I’m pretty happy with the results,

![PUZZL CUSTOMIZER](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/1/6/16f1224f5d111cc951d28a1b09deedd891a62358.gif)

but unfortunately I can’t run it outside of PlayCanvas hosting, that make this work useless…  
I’ve downloaded the .zip file and when running from my server I see black screen in the viewport and in the console I see :

1. Error loading binary resource: ARLRDBD.ttf.bin [403] (playcanvas-stable.min.js:6 Error loading binary resource: )
2. Error while loading scene JSON 1890395.json: First argument to DataView constructor must be an ArrayBuffer  
TypeError: First argument to DataView constructor must be an ArrayBuffer ( **start**.js:213 )
3. **loading**.js:33 Uncaught TypeError: Cannot read properties of null (reading ‘parentElement’)

error screenshot:

 ![2023-11-13 00_26_46-PUZZL](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/8/f/8f46f65b0d0c2c41ae024e8cea7f56a343bfe85f.jpeg)  
browser screenshot:  
 ![2023-11-13 00_21_42-PUZZL](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/9/7/97b9e1ad84939b35143676d91fbbc689d0db2a01.jpeg)

I see that there is problem to .ttf.bin font, that should be loaded to the PlayCanvas as suggested by text-mesh.js developer Will, but I have no idea how to solve it and in which direction to think with it.

Thank you for your help and advices again!!

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [November 13, 2023, 11:51am UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/11 "2023-11-13T11:51:06Z")

</div>

Wow! That looks very good! 🤩

I assume it will be some kind of coat rack? 😇

_Users that are be able to help with the self-hosting problem can reply in the topic below._  
[https://forum.playcanvas.com/t/cant-run-project-on-my-server/](https://forum.playcanvas.com/t/cant-run-project-on-my-server/)

---

<div class="post-metadata">

**Author:** ![Albertos](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/albertos/32/19749_2.png) [@Albertos](https://forum.playcanvas.com/u/Albertos)\
**Post date:** [November 13, 2023, 12:09pm UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/12 "2023-11-13T12:09:43Z")

</div>

> [@Albertos](#):
>
> I assume it will be some kind of coat rack?

Oh wait, it will be a puzzle ofcourse! 🙃

---

<div class="post-metadata">

**Author:** ![Serjozha](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/serjozha/32/28950_2.png) [@Serjozha](https://forum.playcanvas.com/u/Serjozha)\
**Post date:** [November 13, 2023, 6:09pm UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/13 "2023-11-13T18:09:48Z")

</div>

Thank you!! Dear @Albertos feeling some feedback helped me to believe that I can do it, because I really was close to refuse this task in some points ^:))

When kid will grow up and move to his own place maybe he/she can use it as a coat rack as well )))

---

<div class="post-metadata">

**Author:** ![Serjozha](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/serjozha/32/28950_2.png) [@Serjozha](https://forum.playcanvas.com/u/Serjozha)\
**Post date:** [November 14, 2023, 8:36am UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/14 "2023-11-14T08:36:21Z")

</div>

OK, the problem with self-hosing for this projected was that default NGINX server configuration deny access to .bin files. (error 403)  
Using text-mesh requires uploading fonts with “cheat”, renaming .ttf extending it with .ttf.bin and than renaming in PlayCanvas back to .ttf, but when deploying project font still saved in assets files as a .ttf.bin, that by default not allowed to use by server.

So when allowing .bin in server configuration (NGINX or APACHE) to project location will give ability to run the PlayCanvas project, HURRAY!

---

<div class="post-metadata">

**Author:** ![Serjozha](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/serjozha/32/28950_2.png) [@Serjozha](https://forum.playcanvas.com/u/Serjozha)\
**Post date:** [November 17, 2023, 2:23pm UTC](https://forum.playcanvas.com/t/personalized-name-puzzle-customizer-developing-wip-text-mesh-js/33765/15 "2023-11-17T14:23:45Z")

</div>

Also sharing code below I used for nginx site configuration (/etc/nginx/sites-available/domain.com):  
inside

server {  
#your code goes here…  
}

```javascript
location /PUZZL/{
    root /var/www/domain.com/htdocs/;

    location ~*^.+\.(bin) {
        access_log off;
        log_not_found off;
      }
    }

```

this will give access only for the folder [DOMAIN.COM/PUZZL/](http://DOMAIN.COM/PUZZL/) path for all the .bin extensions  
for user browser
