I am currently utilizing diagrams in my three.js project to create various shapes of objects. Would you happen to know the best way to go about

I am utilizing the var shape = new THREE.Shape(); function. However, while using moveTo and lineTo, the diagram is not fully filled, and closePath() does not complete the path after using lineTo. Any insights into this issue would be appreciated.

Here is my code snippet:

var square = new THREE.Shape();
square.moveTo(startX, startY, 0);
square.lineTo(endX, startY, 0);
square.lineTo(endX, endY, 0);
square.lineTo(startX, endY, 0);
square.lineTo(startX, startY, 0);

var geometry = square.makeGeometry();  
var squareShape = new THREE.Line(geometry, new THREE.LineBasicMaterial({
    color: color
}));

return squareShape;   

Answer №1

When using the makeGeometry method, I noticed that my closePath was not fully filled. After making some changes to my code by using

var geometry = new THREE.BufferGeometry().setFromPoints(display.getPoints());
, I was able to achieve the desired result of a fully filled diagram.

var square = new THREE.Shape();
square.moveTo(startX, startY, 0);
square.lineTo(endX, startY, 0);
square.lineTo(endX, endY, 0);
square.lineTo(startX, endY, 0);
square.lineTo(startX, startY, 0); // closePath

var geometry = new THREE.BufferGeometry().setFromPoints(square.getPoints());
var square = new THREE.Line(geometry, new THREE.LineBasicMaterial({
color: color
}));

return square;

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

Creating vibrant squares using HTML and CSS

My objective is to incorporate 3 input options for selecting the color, size, and amount of cubes. The image below showcases my peer's final project, but unfortunately, he refused to share the code with me. We were given a basic template to begin with ...

User currently signed in: What specific information should be transmitted to the web browser?

Experience: Currently utilizing the MEAN stack for a web application and still in the learning process. The Concern: I am facing some confusion regarding a particular aspect. For instance, if a user is logged in (using Passport.js), I can access their inf ...

Guide on automatically inserting a colon (:) after every pair of characters in Angular

I am looking to automatically insert a colon (:) after every 2 characters in my input field: HTML <input nz-input type="text" appLimitInput="textAndNumbers" name="mac" formControlName="mac" (keydown.space)=&qu ...

How can I send extra information along with my Ajax request in jQuery UI Autocomplete?

I currently have two jQuery UI Autocomplete widgets set up. The first autocomplete allows the user to enter a client's name, narrowing down options until the correct client is selected. A callback function then takes the ID of the chosen client and st ...

Is there a way to make a link open only on the second click, instead of the first?

Is it possible to have a popunder advert that opens only when the page is clicked a second time, not the first time? Here's the code for the popunder: <script type="text/javascript"> var uid = '35190'; var wid = '65325'; &l ...

What is the process for storing a list group in an SQL database?

Having a code snippet in html which populates a list with data selected from a combo box upon clicking the 'add' button. However, running into an issue where "undefined index: subjectlist" error occurs when submitting the form. Seeking advice on ...

What is the process for incorporating the JavaScript "star" feature from Google's search results page?

In the Google search results, each entry has a star that users can click to indicate if the result is good or not. This feature is likely implemented using JavaScript. I'm interested in implementing a similar function in my own web application. I wou ...

How can I locate the ID of the HTML input element with jQuery?

I am trying to create a page with a button that looks like this: <input type="button" id="btnAddBusinessUnit" value="Add Business Unit" class="clsAddBusinessUnit" alt="testBtn" /> When the button is clicked, I want to display the id 'btnAddBus ...

CKEditor's height automatically increases as the user types

I am using a ckEditor and looking for a way to make its height automatically grow as I type. https://i.stack.imgur.com/m7eyi.png <textarea name="description" id="description"> </textarea> <script> CKEDITOR.replace( 'description ...

Drop-down selection triggering horizontal auto-scroll

Within my div element, I have a table with dropdowns. The div is set up to be horizontally scrollable. To create the dropdown functionality, I utilized Harvesthq Chosen. Let me provide some context. In Image 1, you'll notice that I've scrolled ...

Mapping distinct JSON keys to button components using Javascript/React

I am dealing with the JSON data below: [ {"location":"2034","type":"Residential","price":400000,"address":"123 Fake Street","suburb":"Maroubra","historical_DAs&q ...

Utilize JavaScript on the browser to cache videos, potentially exceeding 10 minutes in length, directly

Currently, I am experimenting with WebRTC and looking to share a video stream with multiple peers. To optimize this process, I believe it would be beneficial to cache certain parts of the video. After exploring Cache Web APIs, I found them to be less effe ...

Troubleshooting issue with ng-value in Ionic framework and AngularJS not

I'm facing an issue with an ng-value assigned to an input field. I want to pass the userID to the input field so it can be submitted when the form is clicked. Below is the HTML code snippet: <div ng-repeat="chats in chat"> <form ng-su ...

Error: The property 'language' is undefined and cannot be read

Struggling to execute the App-test.js file provided by React Native in the __test__ directory: import 'react-native'; import React from 'react'; import App from '../src/app'; // Note: test renderer must be required after rea ...

Modifying an item within an array will not automatically result in an update to the corresponding HTML elements

When editing the object, it is done in JSON format, but only the previous data appears in the browser. To retrieve a list of products from local storage, I utilize these hooks: const Cart = () => { const [products, setProducts] = useState([]); c ...

Uncertainty surrounding $q and commitments

After spending several hours researching Kris Kowal's Q library and the angularjs $q variable, I am still struggling to comprehend how it all works. Currently, my service contains the following code: resetpassword: function (email, oldPassword, newP ...

Automated tasks running on Firebase Cloud Functions with cron scheduling

There are two cloud functions in use: The first cloud function is used to set or update an existing scheduled job The second one is for canceling an existing scheduled job The management of scheduling jobs is done using import * as schedule from &ap ...

The pagination in React using React Query will only trigger a re-render when the window is in

Currently, I am utilizing React-Query with React and have encountered an issue with pagination. The component only renders when the window gains focus. This behavior is demonstrated in the video link below, https://i.sstatic.net/hIkFp.gif The video showc ...

Allocating the rendering of high-resolution images to a network of multiple servers

I currently have a setup consisting of a grid of 24 monitors running as one large wall-sized display. To enhance the visualization experience, I created a project using three.js that includes over 10,000,000 data points and has a resolution of 12690 x 3840 ...

Comparison of performance between serializing an object to indexedDB and using JSON.stringify

I am curious about the efficiency differences in terms of browser/CPU/memory between using JSON.stringify for serialization versus writing an object to an object store in indexedDB. The context for this question is optimizing the process of writing an obj ...