Skip to content
Advertisement

Setting the position of a text geometry?

I have looked through stack overflow and google and I have found how to CENTER a text geometry but that is not what I want to do.

I have a scene that just has a block of text that says “Buy Here!”. Using the documentation in the three.js website and examples here I was able to do that after some struggling. I had some trouble finding out how to refer to that mesh since I had created the geometry inside a function, and it took hours for me to know about setting a name for it as a string so it can be accessible from different parent/child levels.

What I am NOT able to do now is to offset the text by some arbitrary number of units. I tried shifting it down by 5 units. No matter how I try to do it it isn’t working. I either manage to make the text geometry disappear OR my whole scene is black.

Here is my code…

I have the basic scene setup working properly and I’ll include it here but feel free to skip since I’m pretty sure this has nothing to do with the issue…

JavaScript

and here is my code for the text object….

JavaScript

Here’s what I have tried…..

under “var geometry ({…});” I typed….

JavaScript

but the text object disappears completely so I tried

JavaScript

but there was no difference so i tried taking out

JavaScript

but it had the same results.

So then I tried using

JavaScript

with AND without

JavaScript

but again, they all just make my text object disappear.

So now I tried to set the position from outside the function by typing the following code OUTSIDE of everything that is contained in

loaderF.load (‘https…..’, function (font){var geometry = …..})

using the reference I learned….

JavaScript

but this makes my entire scene go blank (black). So I tried variations of like

JavaScript

and again trying each of those with AND without

JavaScript

but they all made my scene go black.

I just wanna move it down a couple of units. Sheesh.

Could anyone be kind enough to tell me WHERE in my code I can set the position of the text geometry? Thank you please.

Advertisement

Answer

I just wanna move it down a couple of units.

In this case use mesh.position.y = - 5;. Changing the x coordinate will move the mesh to the left or right. Here is a complete live example based on your code:

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement