Adding an outline to a child mesh in three.js is a simple process

I am interested in adding an outline to meshes. To achieve this, I followed an example that involved creating a new mesh with the same geometry and scaling it. You can find the example here.


        var outlineMaterial = new THREE.MeshBasicMaterial({color: 0x00ffff, side: THREE.BackSide});
        this.outlineMesh = new THREE.Mesh(target.geometry, outlineMaterial);
        this.outlineMesh.quaternion = target.quaternion;
        this.outlineMesh.position = target.position;
        this.outlineMesh.scale.copy(target.scale);
        this.outlineMesh.scale.multiplyScalar(1.05);
        this.scene.add(this.outlineMesh);
    

Initially, everything worked well as the position of the outlineMesh matched the target mesh's position. However, when I made the target mesh a child of another mesh, the position of the outlineMesh no longer aligned with the target mesh. I suspected this discrepancy was due to the target mesh's position being relative to its parent's coordinates while the outlineMesh remained in world coordinate.

Does anyone have any suggestions on how to ensure the outline works correctly for child meshes? Any guidance would be greatly appreciated! Thank you!

Answer №1

To incorporate the outlineMesh into the main structure, simply treat it as a child element of the desired mesh:

let outlineMaterial = new THREE.MeshBasicMaterial( { color: 0x00ffff, side: THREE.BackSide } );
outlineMesh = new THREE.Mesh( geometry, outlineMaterial );
outlineMesh.scale.multiplyScalar( 1.05 );
mesh.add( outlineMesh );

This code snippet is compatible with three.js version r.67.

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

Guide on transforming a JSON string into an array of custom objects using the json2typescript NPM module within a TypeScript environment

I am looking to utilize the json2typescript NPM module to convert a JSON string into an array of custom objects. Below is the code I have written. export class CustomObject { constructor(private property1: string, private property2: string, private p ...

Rendering JSON Data in JavaScript using Table Pagination

Currently, I am working on rendering JSON data from a URL onto a table. My challenge is to display only 10 rows per page and I'm seeking guidance on how to achieve this. Below is the code snippet that I am using for rendering the data: const url = " ...

Tips for increasing the number of pixels in the current position of an element?

I need to shift an image to the right by adding pixels to its current left position. The challenge arises when the image, positioned absolutely, goes back to its nearest relative parent (the container) and creates a strange visual effect. Within my flex c ...

The initial render in a Kanban board seems to be causing issues with the functionality of react-beautiful-dnd

I recently integrated a Kanban board into my Next.js and TypeScript project. While everything seemed to be working fine, I encountered a minor glitch during the initial rendering. Interestingly, when I refreshed the page, the drag and drop functionality st ...

Is it necessary to have a strong understanding of JavaScript in order to effectively utilize jQuery?

While I currently do not have knowledge of JavaScript, I am intending to acquire it soon. My query is whether a strong grasp of JavaScript is necessary to utilize jQuery effectively. I am already familiar with ActionScript and PHP, which share certain si ...

Manipulating data in a deeply nested field of an embedded document using Mongoose, MongoDB, and Express

I have been pondering whether it is feasible to input data into the comments field of my "TopicSchema": var mongoose = require('mongoose'); var TopicSchema = new mongoose.Schema({ username: String, topic: String, des ...

I am having trouble getting the bootstrap link and css files to work on a specific URL. Can you please help me troubleshoot this issue and let me know if there are any additional files needed to

When attempting to apply the bootstrap link and css files to the URL "/list/:customListName", they are not working. However, changing the URL to "/:customListName" somehow makes it work. What is the reason behind this behavior and how can I properly style ...

Converting input dates in nest.js using TypeScript formatting

Is it possible to set a custom date format for input in nest.js API request body? For example, like this: 12.12.2022 @ApiProperty({ example: 'ADMIN', description: 'Role name', }) readonly value: string; @ApiProperty({ ...

Using JSON.stringify to format data and making an asynchronous $http request

I am working with a JavaScript string that looks like this: user_fav = "21,16"; I need to process this string through a function so that it becomes a JSON array with an id key, like this: {"id":21},{"id":16} This JSON array is then used in an $http req ...

The handleSumbit feature seems to be malfunctioning in a React Native application that utilizes React-Hook-Form in combination with yup

Greetings, I am currently utilizing React-hook-form and yup for validation in my React Native project. However, I have run into an issue with the handleSubmit function not functioning properly in my ResetPasswordScreen component. Strangely enough, a simila ...

Sometimes the function setFromObject(mesh) returns inaccurate values

THREE.Box3.setFromObject(*object*) is returning inaccurate values. I will demonstrate my process in understanding this issue: I am creating 2 meshes using vertices. The first one using the triangle() function, and the other using trapezoidForm(). var tri ...

In which part of my code should I implement the string to numerical function for my OrderBy function?

I successfully implemented a sortable header for my table with no errors, everything is functioning as expected. However, there is a small issue that I anticipated beforehand. The data in my JSON is string-based with numerical values that include symbols l ...

Tips on leveraging LocalStorage to update state in ReactJS

In my code, an array fetches API data each time componentDidMount() is called. Within this array, each element contains an object with a default boolean value of true. An onClick function toggles the boolean value of a specific element to false when clicke ...

What is the best way to determine which option is most suitable: types, classes, or function types in TypeScript for

Currently, I am developing a small todo command line utility with a straightforward program structure. The main file is responsible for parsing the command line arguments and executing actions such as adding or deleting tasks based on the input provided. E ...

What is causing the malfunction with this JQuery/AJAX request?

Currently in the process of setting up an autocomplete feature. Following the guidance from php academy at the moment. My goal is to display "suggestions go here" below the input field whenever something is typed in. I have two files for this task: home.ph ...

Robmongo - combine unique values based on different columns

As a newcomer to robmongo, I've been tasked with writing queries for a collection that includes keys like "userId" and "deviceModel." My goal is to create a query that shows the number of users for each device model. Here is the query I have so far: ...

What steps do I need to follow to run a three.js demo in my project directory?

Is it possible to run a three.js example in my project directory? The specific example I am looking to run can be found at this link: . Once I have installed three.js using npm, I copied the source code from the example: https://github.com/mrdoob/three. ...

Having no choice but to resort to using the 'any' data type in a Typescript/Vue3 project

My function is composed to return an array of objects, while another function takes a string as input and does not return anything. The code below functions without any errors: import { ref } from "vue"; import { useRoute } from "vue-router ...

How can I write a JavaScript function that eliminates all white spaces within a string?

Exploring ways to create a custom function that trims white spaces from the beginning and end of a string (including \n, \t) without relying on built-in methods like trim(), replace(), split(), or join() Here’s an example code snippet showcasi ...

Display a popup on a button click or icon click in ASP.NET

On Facebook, you may notice that you have 4 friend requests or notifications in the small mail icon on the right side. When you click on it, a pop-up appears with an accept button, and once you accept, it disappears and the remaining three requests are sho ...