"Creating a 3D effect with inset shadow using three.js

I am looking to add inset shadow to my object using three.js, creating a unique effect similar to this image:

https://i.sstatic.net/L8Ori.png

Imagine something like a ring with engraved text.

Answer №1

To simplify the process, consider utilizing a normal-map for engraving instead of creating dynamic text. You can easily export a normal-map from Blender as outlined here. If dynamic text is required, generating a normal-map dynamically on a canvas might be more efficient than constructing geometry for the engraving.

Alternatively, you could create a 3D geometry with the engraving embedded. Explore the ThreeCSG library, which allows manipulation of geometries using boolean operations. By incorporating this method, you can form a 3D-text mesh, adapt it to fit the ring's curvature, and then subtract it from the ring mesh to achieve the desired engraved effect.

In my experimentation, I simulated a similar process by combining ThreeCSG to remove text geometry from a cylinder shape. The potential of this approach is showcased here: (view source here).

const textBSP = new ThreeBSP(textGeometry);
const cylinderBSP = new ThreeBSP(cylinderGeometry);      
const resultGeometry = cylinderBSP.subtract(textBSP).toGeometry();

scene.add(new THREE.Mesh(resultGeometry, new THREE.MeshStandardMaterial());

While this method proved effective, there were some challenges encountered, particularly with the slow tessellation caused by threeCSG. Further refinement is needed to address issues with computed normals.

A third option involves utilizing both displacement and normal-maps for quicker processing. This technique requires adding numerous vertices to facilitate displacement effects. Refer to a helpful code snippet by mrdoob for assistance in creating a normal-map based on displacement:

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

Using JavaScript, create a function that accepts an HTML element as a parameter

I have a script with two functions. One function generates a lengthy HTML string, and the other function processes this string as a parameter. function myFirstFunction() { // Generate HTML content return myHTML; } var myHTML = myFirstFunction(); ...

Combining the power of Node.js and Node-MySQL with Express 4 and the versatile Mustache

Currently, I am delving into the world of Node.js and encountering a bit of a roadblock. My focus is on passing a query to Mustache. Index.js // Incorporate Express Framework var express = require('express'); // Integrate Mustache Template En ...

What is the reason for needing to multiply all the numbers by ten in order to solve this floating point addition problem?

When dealing with floating point arithmetic in Javascript, it's common to see results like 0.2 + 0.1 = 0.30000000000000004, which can be confusing. However, a simple workaround is to multiply the numbers by 10, perform the operation, and then divide b ...

How can I pass a value from a jQuery variable to a PHP variable?

Utilizing jQuery to create a table based on the output of JSON. The JSON values are retrieved from a SoapClient, which is functioning correctly and producing the desired output. https://i.sstatic.net/vJbfW.png Now, the goal is to assign the value of the ...

What methods can be used in ThreeJS to avoid the camera orientation from flipping after a specified threshold is crossed?

In my current project, I have a scenario where I've imported a model of a spaceship that moves solely in the z-direction. Using the 'WASD' keys, I can control its movements within the scene. The camera is positioned directly behind the space ...

change visibility:hidden to visible in a css class using JavaScript

I've put together a list of Game of Thrones characters who might meet their demise (no spoilers included). However, I'm struggling with removing a CSS class as part of my task. Simply deleting the CSS is not the solution I am looking for. I' ...

Guide to looping through an array within an object in React JS

Let's imagine we have an array of objects like this: const chefs = [ { key: 1, images: ['http://lorempixel.com/400/400/sports/', 'http://lorempixel.com/400/400/abstract/', 'http://lorempixel.com/400/400/animals/&apo ...

How to create shapes with smooth edges in ThreeJS

I am attempting to create a shape using threeJS that consists of both straight and curved edges. Here is what I currently have: https://i.sstatic.net/9pK3g.jpg My goal is to connect the two top corners with a semicircle in order to achieve a square shape ...

Is it possible to add a click handler function to a dynamically generated link in Vue?

When working with Vue components, I receive dynamic messages from the server: module.exports = { data() { return: { windowText: '' } }, methods: { showCancelEntrieWindow(){ this.$http.post('/page', {'number& ...

Display popup depending on the post's identification number

Currently, I'm in the process of integrating Sanity into my blog. Using the json object returned from a query with useState, I managed to display my posts successfully. However, I am now faced with the challenge of populating a React-Modal with the ap ...

What is the best way to assign src and alt attributes to an image tag using JavaScript?

As I continue to learn JavaScript, please bear with me as I navigate through my current level of understanding. I am working on a gallery that opens a modal when an image is clicked. I have successfully gathered all the image sources into an array and used ...

When using Mongoose with Ejs, I am unable to view the comment I made when I navigate back to the post using GET. The comment only becomes visible after I have submitted it

After creating a comment, I can only see it when rendering the same page again. However, if I navigate to posts or myposts page and then return to the post where I created the comment, it disappears. Can someone please help me understand why this is happen ...

Obtain the texture from a user upload and apply it to a geometry in three.js

As a beginner in three.js and JavaScript, I am excited about the possibilities and have been creating small Three.js scenes to improve my skills. My ultimate goal is to build a 3D website, but I am currently stuck on how to allow users to upload an image f ...

Loading views and controllers on-the-fly in AngularJS

A new configuration tool is under development using Angular.JS. The user interface consists of two main sections: a left panel with a tree view listing all the configuration items and a right panel displaying screens for editing these items. There are appr ...

How to attach keypress event to an input with type 'number' using Jquery and attribute value

I'm trying to figure out how to validate an input field only when it is of type number and has the validate attribute set to checkit. I'm not sure what to use in place of the asterisks to bind this to the keypress event $('*** input[type=num ...

The Vue component is only functioning partially and is not visible in the Vue inspector

I have a straightforward Vue component that is causing me some trouble. <template> <div class="field has-addons"> <div class="control is-expanded"> <div class="select is-fullwidth"> <select v-mode ...

How can the parameters -i -u "clientId:" be interpreted when translating a curl command into Ajax?

As I work on integrating a 3rd party API into my website, I am currently in the testing phase using Postman (the Chrome Extension) before proceeding to write my AngularJS Service with $http. However, there is one aspect of the process that has me puzzled. ...

Avoiding setting state before useEffect is important to ensure that the component's initial

I have a React/Next component that retrieves data from firebase storage based on the route. For example, if the route is http://localhost:3000/training/javascript, the component will fetch data from the /training/javascript route in firebase storage. // Re ...

Navigation bar disappears when the page is scrolled to the top

Having an issue with the navbar functionality on my website. It is working properly in Firefox, but not in Chrome and Safari. When scrolling back up to the very top of the page, the navbar hides due to a minor bounce effect which triggers the hide action. ...

What is the process for creating unit tests for a method that utilizes the @Transaction() decorator?

I am currently using NestJS 6 and TypeORM to interact with a MySQL database. While attempting to write unit tests for a method that utilizes the @Transaction() and @TransactionManager() decorators, I encountered the following error message: ConnectionNotF ...