A guide on extracting vertices from an imported obj file using Three.js

Currently, I'm in the process of uploading a range of .obj and .mtl files for a volume rendering tool that was created using WebGL and Three.js. Within a section of my code, I am utilizing OBJMTLLoader to handle the file uploads:

 scapula = new THREE.OBJMTLLoader();
 scapula.load( 'obj/scapulaTWO.obj', 'obj/scapulaTWO.mtl', 
    function ( object ) {
                object.name = "scapula";
                object.scale.set (4,4,4);
                vertices = object.geometry.vertices;
                scene.add(object);
    });

Despite my efforts, I've encountered an issue where I'm unable to access the vertices. The debugger indicates that object.geometry is undefined. I also attempted:

    vertices = new THREE.Mesh(object);

without success. Any assistance with this matter would be greatly appreciated.

Thank you in advance.

Answer №1

The organization of nodes in the three.js imported 3d model is determined by the structure of the OBJ file and the grouping elements such as o or g. You can explore how three.js constructs your model using a browser debugger. In my scenario, with multiple objects declared in the OBJ file, the node structure appears like this:

model (THREE.Group) > children (Array) > child [i] (THREE.Object3D) > children (Array) > child [j] (THREE.Mesh) > geometry (THREE.Geometry) > vertices (Array)

To access vertex k of Mesh j in object3d i, you can use the following code snippet:

var vertexK = object.children[i].children[j].geometry.vertices[k];

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

Exploring methods to detect when a PHP page has been printed using the 'ctrl+p' shortcut and then subsequently updating

Hey there! I'm currently managing a php website that functions as an accounting system. Within this system, there are receipts, invoices, and other forms of documentation in use. However, I've encountered a problem with the main table in my myS ...

Seeking assistance with transmitting data to the server and retrieving it for use. I am looking to achieve this goal utilizing JavaScript with Node.js

I've been experiencing challenges with the interactions between front-end and back-end. I am confident that I am sending the data, but unfortunately, I am unable to access it afterwards. Recently, I utilized this code template (sourced from Mozilla&ap ...

How can I determine the quantity of pairs in an array using JavaScript?

My current approach is not providing me with the desired result. I am facing an issue where pairs of 1 are being counted multiple times, which is incorrect. What I actually need is to count only the "perfect" pairs, such as the pair between 5 and 2 in this ...

Identify when a click occurs outside specific elements

I've been searching for solutions to address this issue, but so far nothing has worked. Here is the JavaScript code I am using: var specifiedElement = document.getElementById('a'); document.addEventListener('click', function(eve ...

Tips for modifying javascript code to have popups appear as bPopup instead of in a separate popup window

Is there a way to modify the following code so that popup windows open as dpopups instead of just in a new popup window ()? $(document).ready(function() { var table = $('#taulu').DataTable( { "ajax": "taulu.php", "columnDefs" ...

Creating an HTML element for every ajax response

I am currently working on a simple ajax call that updates a div with HTML formatting. However, I need to trigger the ajax call every 3 seconds to bring in updated responses. Should I restructure each time or is there a way to combine the HTML for each resp ...

What is stopping me from adjusting the brightness on my canvas?

When using canvas to adjust the luminosity of an image, everything works fine if the luminosity is only set once. However, when trying to reset the luminosity back to 0, the default image does not appear as expected. Here is the code that calls the effect ...

Obtaining the date for the previous month using JavaScript or jQuery

I need to retrieve a specific date in JavaScript. My goal is to obtain the current date based on a variable named frequency, which can have values of Daily, Weekly, or Monthly. if(frequency=="daily") { date='current_date -2 days'; } e ...

Spherical outline in the void (threejs) (3D)

Is there a way to remove the line in this image and only keep the contour? Click here to view the figure. const intersection = (a, b, c, heightC) => { return (u, v) => { const height = heightC || c; const size = 5; u = u ...

observable arrays in knockoutjs

To simplify the problem I'm facing, let's consider this example: var ViewModel = function() { this.self = this; self.test = ko.observableArray([]); self.test2 = ko.observableArray([]); self.test2.push('1'); self.test.push({ 'f ...

Submitting a form using AJAX without specifying the form ID when there is a change

I have a unique setup on my page where a table is created with each cell acting as a form. The goal is for these forms to submit when the input value changes (onchange) without refreshing the entire page. An example scenario would be allowing users to ent ...

Encountered a snag while executing Powershell with Selenium: Error message - unable to interact with

Looking to update a textarea with a value? The script below triggers an error stating "element not interactable". This occurs because the textarea is set to "display:none". However, manually removing the "NONE" word allows the script to successfully set th ...

Using PHP to fill input field with text output

I've been searching for an answer to this question, but so far I haven't found one. In my database, I input two pieces of data and receive a success or failure outcome. What I want is to have a "Submit" button that triggers my PHP query (which ...

Discovering the state of a checkbox element in Java and Selenium can be a challenge, especially when the element is not identified as a checkbox even with the

I'm currently creating test scenarios for the aviasales.com website and I am attempting to confirm the status of a checkbox. Locating and clicking on the checkbox was simple using the following code: WebElement checkboxValue = driver.findElement(By ...

Determine the position of a relative element using jQuery and CSS, then adjust the position of the tooltip

I designed a map that displays different locations, and when you hover over each location, a tooltip appears next to the cursor with information about that specific spot. The map is used as a background image for the main ul element with an id of "map". E ...

What are the steps for implementing pytesseract on a node.js server?

While working on my node.js server, I encountered an issue when using child-process to send an image to a python script. Although I can successfully read the image in the python script, I encounter an error when attempting to convert it to text using pytes ...

Integrating additional JavaScript into an Ionic 2 project

Imagine we have a foo.js file containing a variable, function, and class that are not yet part of the project. Now suppose we want to access these elements in our home.ts method or make them globally available for use within a home.ts method. How can this ...

Getting the value of a JavaScript variable and storing it in a Python variable within a Python-CGI script

Is there a way to capture the value of a JavaScript variable and store it in a Python variable? I have a Python-CGI script that generates a selection box where the user can choose an option from a list. I want to then take this selected value and save it ...

Is there a way to transition an element from a fixed layout position to an absolute layout position through animation?

I am looking to create a dynamic animation effect for a button within a form. The goal is for the button to move to the center of the form, while simultaneously undergoing a horizontal flip using a scale transform. During the midpoint of this animation, I ...

What methods can be used to verify that window.print() has not been overridden?

Is there a way to verify if the window.print() method is overridden using JavaScript and/or FirefoxDriver? You can prevent all print buttons on a page from functioning like this: window.print = function() { alert("Bazinga") } When this is implemented, a ...