Tips for resizing an object in a single direction using THREE.JS

I have encountered an issue while adding a cube to my scene using THREE.JS. When I try to change the height of the cube by increasing its y coordinate, it also seems to expand in the negative y direction as well.

    var cubeGeometry2 = new THREE.BoxGeometry(10, 25, 5);
    
    var cubeMaterial2 = new THREE.MeshBasicMaterial({
        
        color: '#5A5A5A',
        wireframe: false
    });
    var cube3 = new THREE.Mesh(cubeGeometry2, cubeMaterial2);
    console.log(cubeGeometry2)
    cube3.position.set(25, 5.5, -12);
    scene.add(cube3);

To adjust the scale of the cube, I have been increasing the y coordinate in the box geometry constructor

Solution Edit

Despite taking an unconventional approach, here is how I managed to solve it:

//First look into the vertices by

console.log(cubeGeometry2)
//Changed all the occurrences of Y vertices to positive values by looping through the vertices list
for(let i = 0;i < cube3.geometry.vertices.length;i++){
        
        
        if(cube3.geometry.vertices[i].y < 0){
            cube3.geometry.vertices[i].y = cube3.geometry.vertices[i].y * 0
        } 
    }

Answer №1

To achieve the desired effect, it is important to note that specifying a particular height parameter in the constructor of BoxGeometry will not yield the intended outcome.

Adjusting the scale property of the mesh also does not provide the solution needed. Altering the scale along the y-axis will result in scaling both positively and negatively along this axis.

A workaround involves displacing the vertices within the geometry. This process entails identifying the corner vertices of the relevant cube side and subsequently updating the data in the buffer attribute for a resolution.

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 a single header that can be used across multiple pages in HTML

Hello there, I've been on the hunt for a JavaScript code that will allow me to create one header for multiple HTML pages. Unfortunately, my search has come up empty-handed. Can anyone offer some advice on how to achieve this? Thank you! ...

Having trouble with the Post Request feature as an error message pops up saying "unable to post /addstudent/add"

I'm encountering an issue with the post request I'm trying to send. I've attempted to work on it both in Postman and with forms, but I keep getting an error that says "cannot POST /addstudent/add". Below you'll find the code snippets fo ...

Exploring JSON data with JQuery: A comprehensive guide to looping through with each

I am currently facing an issue with looping through cached JSON data obtained from an Ajax call. Specifically, I keep receiving the error message 'Cannot read property 'title' of undefined'. Can someone provide assistance? $.each(cach ...

Phonegap - Retaining text data in a checklist app beyond app shutdown

This is my first time developing an app with Phonegap. I am looking to create a checklist feature where users can input items into an input field. However, I am struggling with figuring out how to save these items so that they remain in the checklist even ...

Is there a method to achieve greater accuracy when dividing a large number?

My requirement involves operating on Big Numbers, and I need the results to maintain precision, as demonstrated below: const BN = require('bn.js'); var a = 11060622312717714974 var b = 1570481433500000000000; console.log(a/b); //0.00704282271460 ...

Encountering a NoSuchElementException when transitioning from frame[0] to window[1] in Firefox GeckoDriver using Selenium with Python

Encountered an issue with the Firefox GeckoDriver browser where I receive an error stating `element not found`. The problem arises when I navigate from window[1] to frame[0], back to window[1], and then attempt to click the close frame button. I prefer u ...

A guide on passing ObjectID using Ajax to the backend in Node.js

I am trying to create a delete button using font-end code (HTML, Javascript) but I am facing an issue with sending ObjectID via ajax var retName = $(this).data("row-id"); $.ajax({ type: "POST", url: "/delete", data: ...

Trouble with modifying style in Google Chrome and Internet Explorer prior to AJAX request

When utilizing AJAX, I have a common practice of setting up a loading indicator before each request to inform the user about the short wait. Usually, this is achieved by adding an animated loading gif. Interestingly, when performing this action in Firefox, ...

JavaScript is unable to make changes to the page once it has finished loading

I have implemented a JavaScript code that allows me to send messages in a chat interface: function sendMessageToChat(conversation, message) { $("#content").html(conversation + message); $(".current-msg").hide(); $(".current-msg").delay(500).fadeIn ...

When I click, I expect to retrieve the tr element, but instead, I am receiving the td element

When I have a table and click on a tr element, the function returns a td element instead. Can someone explain why this is happening? let func = function () { $("tr").on("click", (event) => { event.preventDefault(); event.stopPropaga ...

What is the proper method for utilizing the .done or .complete functions in conjunction with .toggle in jQuery?

I am struggling to understand the proper usage of .complete or .done after .toggle in jQuery. My goal is to have the button's text change after the toggle animation finishes, but I'm not sure if I'm chaining them correctly. The jQuery docume ...

Remove a batch of images from Amazon Web Services

Currently, this is the code snippet I am utilizing to delete multiple images from AWS: AWS.config.update({ accessKeyId: process.env.ACCESS_KEY, secretAccessKey: process.env.SECRET_ACCESS_KEY }) const s3 = new AWS.S3({ params: { Bucket: process. ...

What is the best way to manage HTML code that is delivered through JSON data?

I am dealing with data from a JSON that is in HTML code format. I need to print it as HTML, but currently it is only printing as a string: "content": "More tests\u003cbr /\u003e\n\u003cbr /\u003e\n\u003cdiv class=&bso ...

Browsersync and Babel Express are set up to work together, with the Express server ready and waiting

Currently, I have set up a basic static server using Express in a separate server file. In my Gulpfile configuration, I am utilizing nodemon to run the server file and then passing its address to browsersync for proxying. Upon navigating to the webpage in ...

Using Angular: A guide to setting individual values for select dropdowns with form controls

I am working on a project that involves organizing food items into categories. Each item has a corresponding table entry, with a field indicating which category it belongs to. The category is represented by a Guid but displayed in a user-friendly format. C ...

Tips for launching a web application using Nuxt with Firebase

After successfully installing the Nuxt Firebase plugin into my web app, everything works flawlessly when I run the generated folder (dist) locally. However, once I deploy it to the server, my web app fails to recognize any Nuxt Firebase commands and throws ...

Guide to implementing the Office 365 Javascript API in your application

Looking to integrate an Office 365 Excel sheet with the necessary toolbars into my web-based application, similar to this setup (including the Excel Online toolbar above). Link Here Unsure of the process - is there a way to implement tables and toolbars ...

Firefox 3 fails to utilize cache when an ajax request is made while the page is loading

Upon loading the page DOM, I utilize jQuery to fetch JSON data via ajax like so: $(document).ready(function(){ getData(); }); ...where the function getData() executes a basic jQuery ajax call similar to this: function getData(){ $.ajax({cache: t ...

What happens when 'grid' property is undefined in modal?

I encountered an issue with my modal where I wanted to display pre-selected rows, but kept getting a 'cannot read 'grid' of undefined' error. The UI Grids are defined within the modal, and I have declared two Grid APIs with different na ...

Using AngularJS to modify a record

I am currently developing a web application using C# with angularjs. Within my app, I have multiple records that I need to update. I have set up the necessary web service and included the required JS files for updating these records. My main concern is fig ...