How should one go about editing the vertices of a box geometry?

I have been customizing the vertices of various box geometries to create unique shapes or adjust their heights. Everything looks great in my scenes (check out this example https://i.sstatic.net/w7Z3G.jpg).

However, I encountered an issue when using the ObjectExporter and attempting to load the scene into . None of the vertex modifications were appearing. Additionally, loading the scene.json file into Blender resulted in an error mentioning KeyError:'vertices'

The process involves editing geometry vertices via a UI, saving these changes into a matrix, then verifying the matrix upon scene load. The relevant function snippet is shown below:

setBaseTileVertices:function()
{
    var scope = this;

    scope.baseTiles.children.forEach(function(tile , t)
    {
        tile.geometry.vertices.forEach(function(vertex , v)
        {
            vertex.x = (tile.userData.vertices[v].x) ? tile.userData.vertices[v].x : vertex.x;
            vertex.y = (tile.userData.vertices[v].y) ? tile.userData.vertices[v].y : vertex.y;
            vertex.z = (tile.userData.vertices[v].z) ? tile.userData.vertices[v].z : vertex.z;
        });
    });
}

Is there a more accurate method for editing vertices so that the changes reflect in the editor and/or Blender? Have I selected the appropriate exporter? I attempted to use the THREE.SceneExporter, but faced errors indicated here

Edit

Upon further investigation, I noticed that all modified box geometries shared a similar matrix value in the JSON output, while a square pyramid I created had the correct matrix. It seems I need to update the matrix of each geometry after modification. Although uncertain about the exact approach, I am making progress towards a solution.

Edit 2

Upon confirming that the matrices for each geometry are being updated, I am perplexed by why only the pyramid renders correctly, whereas the box geometries appear flat without any vertex changes reflected. An illustrative screenshot from the editor can be seen here: https://i.sstatic.net/mtU0J.jpg, note how the bounding box helper recognizes the height of baseTiles, indicating edited vertices are considered.

Edit 3

Conducting a test, I modified lines 65 - 74 of ObjectExporter.js as follows:

} else if ( geometry instanceof THREE.BoxGeometry ) {

    data.type = 'Geometry';
    data.data = geometryExporter.parse( geometry );

    delete data.data.metadata;

    //handleParameters( [ 'width', 'height', 'depth', 'widthSegments', 'heightSegments', 'depthSegments' ] );}

This alteration resulted in the shape of my level looking correct on the editor (https://i.sstatic.net/E4sdU.jpg), yet the colors or materials were not transferring over. Every element appeared black in contrast to the intended green color on the +Y faces.

Here is an example of exporting with the unedited ObjectExporter for comparison:

{
    "metadata": {
        "version": 4.3,
        "type": "Object",
        "generator": "ObjectExporter"
    },
    ...
}

And here is a sample of edited JSON resulting from parsing box geometries as geometry instead of the entire scene, leading to this outcome: https://i.sstatic.net/E4sdU.jpg

Any insights or suggestions?

Answer №1

Based on extensive research, it has been discovered that the current recommended method for achieving this task is to convert your BoxGeometry instances into either BufferGeometry or traditional Geometry objects. This conversion can be done after modifying their vertices.

Here is an example:


var box = new THREE.BoxGeometry(64, 32, 64);

box.verticesNeedUpdate = true;
box.vertices[0].y = 128;
box.vertices[1].y = 128;

var geometry = new THREE.BufferGeometry().fromGeometry(box);

// Alternatively

var geometry = new THREE.Geometry();
geometry.merge(box);

Upon exporting the object using the ObjectExporter, it should load correctly in the .

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

Deleting a character creates an error

I am conducting a small experiment with a simple goal: to filter and search for users whose names match the current value typed into an input text field. To implement this functionality, I am using RegExp(). Everything works well except when I delete a cha ...

Storing Byte Array in a File using JavaScript

I am working on a Java REST webservice that returns documents as byte array. I am trying to write JavaScript code that will retrieve the response from the webservice and save it to a file for downloading as a PDF. However, when testing my sample code, the ...

Switch the visibility of a div tag using Next.js

Script export default function Navigation(){ let displayMenu = false; function toggleMenu() { displayMenu = !displayMenu; } return ( <> <button onClick={toggleMenu}>Toggle Navigation</button> {/*This code sh ...

Having trouble getting jQuery .click to trigger on a dynamically loaded button?

I'm having some trouble with my code. I have a list that loads dynamically with a button inside, and although I have set up jQuery to handle the click event, nothing is happening. Here's a snippet of the code: HTML: <ul id="cart"> ...

Real-time text updates with JavaScript

How can I update text in real-time using Javascript? Here is a snippet of my HTML code: <p class="fun-fact">This text will fade out</p> <p class="fun-fact-2">and then this text will fade in</p> I have 10 different texts that I wo ...

Is it possible to create a hyperlink on the second page that directs to the first page and triggers a specific JavaScript function on the first page?

Working with a former colleague's code in C#, asp.net MVC, Telerik/Kendo controls. I am trying to navigate to a specific section on a page from another page that uses tabs/sections with links at the top of the page to toggle visibility based on the se ...

Tips on revealing concealed information when creating a printable format of an HTML document

I need to find a way to transform an HTML table into a PDF using JavaScript or jQuery. The challenge I'm facing is that the table contains hidden rows in the HTML, and I want these hidden rows to also appear in the generated PDF. Currently, when I co ...

Using setTimeout in Node.js

I've been struggling to find a solution for slowing down the timeout in my code. The issue is that it runs too quickly, and I can't seem to figure out how to adjust it using Request. Everything else in the code works perfectly. var Scraper = fun ...

Is it not possible to generate HTML tags using jQuery and JavaScript in JSF?

I'm currently working with jsf 2.0 and richfaces 4.0 to develop my application. Occasionally, I incorporate jQuery and JavaScript functions for displaying and hiding elements. However, I've encountered an issue when trying to generate tags within ...

What is the best way to connect socket.io to multiple instances of HTTPServer?

My Express server is set up to listen on both HTTP and HTTPS: Above, you can see the code snippet where I create the server instances for both HTTP and HTTPS protocols using Express. Currently, I am facing an issue with socket.io as it only listens to on ...

Differences between importing {fn1} from 'lib' and importing fn1 from 'lib'

When it comes to importing functions from lodash, I have been advised by my coworker that it is more efficient to import each function individually rather than as a group. The current method of importing: import {fn1, fn2, fn3} from 'lodash'; ...

The getelementbyid function can only target and retrieve the information from the first ID within a PHP

I am facing an issue with a form embedded in a PHP while loop and processed by JavaScript using getelementbyid. When I submit the form, it only submits the first item on the loop. Below is my PHP code: $qsel = "SELECT * FROM sellbusiness ORDER BY sn DESC ...

Tips for extracting the text either before or after a certain character within a string

Consider the following two strings: var str = "Extract Me @ Leave Me"; var str2 = "Not This @ Yes, This"; Imagine a function named extractString() that can work like this: extractString("frontOf", "@", str); // => Extract Me extractString("behi ...

How to pass GetServerSideProps into Page component props in Next.js with custom _app.js

Having issues integrating GetServerSideProps into my Next.js app. Despite the network call successfully fetching data and generating the pageName.json, the response data is not being injected into the page props as expected. Below is a snippet of my page ...

Combining an attribute selector with a variable results in a syntax error

Although this code is functioning properly and the class is successfully added, an error message is being displayed. console.log(key); //first_date $('*[name='+key+']').addClass('error'); ERROR: Uncaught Error: Syntax er ...

Notify users with a prompt when a modal or popup is closed on Google Chrome extensions

I have developed a Google Chrome extension for setting timers and receiving alerts. Currently, the alert only goes off when the extension is open, but I want it to fire even when the extension is closed. This extension currently requires the window to be ...

Direct all paths to the base path "/" using Express

Is there a way to redirect all URLs containing "/something" in Express to the base path "/:=", while still maintaining additional paths to their respective pages? For instance, I would like to implement the following redirects: "/something" redirects to ...

Exploring the process of implementing functions on buttons in Three.js

I have a written program in Three JS that I want to enhance by adding an animated function triggered by a button click event. Additionally, I need help with setting buttons in an inner window and calling all animations on button click events. Any assistanc ...

Tips for creating a filter in React JS using checkboxes

In my current situation, I have a constant that will eventually be replaced with an API. For now, it resembles the future API in the following way: const foo = { {'id':1, 'price':200, 'type':1,}, {'id':2, &apo ...

Unable to save cookies using AngularJs

Currently, I am immersed in a small project utilizing AngularJs. The main objective of this project is to save a user's username and password within browser cookies. Here is my snippet from app.js where you can observe ngCookies being injected as a d ...