Working with Spline Offset Functionality in Three.js

I am working on creating 3D text from font glyphs. While TextGeometry can be used for this purpose, I prefer to manually draw the text because I need to apply an offset on the font splines.

Currently, I have the splines with their respective points and I am able to draw the letters.

Given the points: previousPoint, currentPoint, and nextPoint, I am struggling to compute the bisector between the previous and next points. Any suggestions on how to achieve this?

Alternatively, is there a different approach to moving spline points away from their initial positions to create the desired offset?

Your insights are greatly appreciated!

EDIT:

While your responses helped me determine the correct values for most font splines, I am facing an issue specifically with the 'o' and '0'. The method used seems to be drawing a strange tangent at the bottom of these letters. Here is the unexpected result: image link

If anyone has any ideas on how to troubleshoot this, please share!

EDIT 2:

I am excited to announce that I have completed my project. The final product includes an .stl exporter feature. Check out the finalized offset here: final offset image

Thank you all for your valuable contributions!

Answer №1

These are the calculations:

x = (prev_x + next_x) / 2 and y = (prev_y + next_y) / 2
incorrect outcome

desired result

This is the code snippet where let points represents all the points in the path:

    getPathPoints(path) {
    let points = path.getPoints();
    console.log(points)
    for (let i = 0; i < points.length; i++) {
        let A = points.extended(i - 1); // previousPoint => where extends is a custom array prototype
        let B = points.extended(i); // currentPoint
        let C = points.extended(i + 1); // nextPoint

        let x = (A.x + C.x) / 2;
        let y = (A.y + C.y) / 2;
        let bisector = new THREE.Vector2(x,y);
        console.log(bisector);
    }
}

Answer №2

Can you explain the splines that define your glyphs?

I understand that TTF fonts utilize quadratic Bezier curves. In a Bezier curve, the direction vector at the starting and ending points point towards the control point. This means that the difference

S = ControlPoint[1] - ControlPoint[0]

represents the direction at the starting point, while the difference

E = ControlPoint[1] - ControlPoint[2]

represents the direction at the ending point.

To find the bisector vector between two neighboring curves, normalize these vectors and add them together:

 Bisector = E(i).Normalized + S(i+1).Normalized

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Maintaining the aspect ratio of images in Bootstrap Carousel: A complete guide

Using the default carousel from Bootstrap template has been working well for me. However, I've encountered an issue where resizing the browser window distorts the image aspect ratio by squishing it horizontally. I've tried various solutions to m ...

Unable to adjust image opacity using jQuery

I am attempting to change the opacity of an image based on a boolean flag. The image should have reduced opacity when the var pauseDisabled = true, and return to full opacity when pauseDisabled = false. To demonstrate this, I have created a fiddle below. ...

Deactivate CS:GO Dedicated Server using Node.js child_process

I've been attempting to manage multiple Counter Strike: Global Offensive dedicated servers programmatically. The process is running smoothly, however, I am facing a challenge in shutting it down completely. Upon starting the server, two processes are ...

The case of ASP.NET MVC Form Triggering Duplicate Submissions

Currently, I have a straightforward form that contains a few questions. To ensure that the inputs are filled before the form is submitted, I am utilizing the validator.min.js library from here. The structure of my form is as follows: @using (Html.BeginFo ...

Unpredictable Results with JSON Data

Can anyone shed some light on why all my JSON data is showing up as Undefined? Here is the JSON snippet in question: {"273746":[{"name":"Darius's Wizards","tier":"GOLD","queue":"RANKED_SOLO_5x5","entries":[{"playerOrTeamId":"273746","playerOrTeamName ...

activating javascript function in rails when the page reloads

I have a rails4 app and I'm looking to implement some specific JavaScript events when the page loads, but only if the user is coming from a certain page. On the post#index page, all comment replies are initially hidden. When a user clicks on a specif ...

Guide on changing the background image of an active thumbnail in an autosliding carousel

My query consists of three parts. Any assistance in solving this JS problem would be highly appreciated as I am learning and understanding JS through trial and error. https://i.sstatic.net/0Liqi.jpg I have designed a visually appealing travel landing pag ...

Using JS or jQuery to organize JSON data into a multidimensional array

Dealing with frontend processing of a response from a server that provides event reviews for the season has been challenging. In this case, there can be multiple reviewers for the same event and the simplified version of the response appears as follows: [ ...

Ways to prevent the jQuery simple slider from transitioning slides while it is in an invisible state

There is a jQuery slider on my website that behaves strangely when I navigate away from the Chrome browser and return later. It seems to speed through all pending slides quickly when it was not visible. Now, I want the slider to pause when it becomes invi ...

How to target only the parent div that was clicked using jQuery, excluding any

I have attempted to solve this issue multiple times, trying everything I could find on Google and stack overflow without success. At times I am getting the span element and other times the div - what could be causing this inconsistency? $(".bind-key"). ...

Is there a way to dynamically adjust the height of a DIV block?

I have a situation where I need the height of one div to automatically adjust based on changes in the height of another div. var height = jQuery('#leftcol').height(); height += 20; jQuery('.rightcol-botbg').height(height); Unfortun ...

How can you modify a hyperlink URL before it is activated?

I'm facing an issue with a URL structure that needs updating before it is clicked. The current URL looks like this: https://url.com/a b c which is causing redirection problems because the actual link has underscores instead of spaces in its URL. Is ...

Problem encountered in NextJS/ReactJS when attempting to dynamically load a new component by clicking a button within the current component

In my NextJS project, I am working with 3 components named "Sidebar", "Woven", and "ToolsPage". Below are the respective codes for each: ToolsPage Component: "use client" import Woven from './components/weaved'; import Sidebar from &ap ...

Can anyone explain why the Splice function is removing the element at index 1 instead of index 0 as I specified?

selectedItems= [5,47] if(this.selectedItems.length > 1) { this.selectedItems= this.selectedItems.splice(0,1); } I am attempting to remove the element at index 0 which is 5 but unexpectedly it deletes the element at index ...

Error: An unexpected identifier was encountered while declaring a class attribute

class Data { title: string; fields: string[] = []; parent: string; attributes: any = {}; } Can someone help me out here? I'm encountering an issue. I am running node v14.17.0 This is the error message I'm seeing: title: string; SyntaxE ...

Tips for implementing advertisements through a content management system or JavaScript

After reviewing a discussion on how to dynamically change code on clients' websites for serving ads, I am in search of an easy-to-implement solution. The code is frequently updated as we experiment with different ad networks like Adsense. Ideally, I w ...

Updating the state of a React component through a button click using React-JS

In my React-JS project, I am using Semantic-ui to create form inputs and a submit button. These forms have a property called 'error', and the value of this property is determined by the state. The issue arises when I click on the 'Next&apos ...

Seeking specific parameter in a JSON array using JavaScript: A guide

Currently, I am working on a project that involves retrieving Facebook news feed data using the graph API. Upon receiving the JSON object, I display it on the page. The "Likes" section is presented as an array of JSON objects like this: data.likes: { ...

Sending data to a PHP page to maintain state in an Angular application

Here is my current setup: In a dynamic Angular environment, I have various states connected to PHP pages. These PHP pages rely on specific data variables, typically provided as GET parameters outside of Angular. Now, I am looking for a way to switch to a ...

Error message in vuejs: JSON parsing error detected due to an unexpected "<" symbol at the beginning

I have been trying to troubleshoot this issue, but I am having trouble understanding how to resolve it. Currently, I am using lottie-web in a project and need to set the animation parameters on an object in order to pass them as a parameter later. This i ...