Exploring the possibilities of Obj file manipulation with threejs- Selection, updating, and transforming

I'm currently working on an application for 3D Visualization and Interactivity using threejs.
Here are the main functionalities I aim to include in this project:

In this app, users should be able to:

  • Rotate and Scale the Object - completed
  • Manipulate specific parts of the Object, such as changing its color or replacing a part with another - pending

I have been referring to the extensive threejs documentation and the list of helpful examples provided, which has greatly assisted me in making progress.

I also found a useful Chrome extension called ThreeJS Inspector.

This ThreeJS Inspector Chrome Extension seems to fulfill all my requirements; however, I am struggling to comprehend how it functions and allows selection and manipulation of the parts within an Object file.

Currently, I am utilizing the following block of code with threejs to solely display, rotate, and scale the Object file.

Updated Code:

 //The code block goes here 

If anyone can offer assistance with this, it would be greatly appreciated. Thank you in advance, and please provide feedback if there is anything I may have overlooked.

Update

Next Challenges

  • While I can change the color of a specific node (part of the object), it requires clicking on the canvas/object again to view the changes instantly.
  • Although I can hide/show a particular node (part of the object), I aspire to replace that specific node (part of the object) with another one.
  • I intend to save the final object file as an image after implementing all modifications. In the future, I aim to save it as a GIF or video to enable users to visualize a 360-degree view of the end product.

PS

TheJim01 has been instrumental in helping me understand the fundamental but crucial concept of traversing the object file and its components. This insight has brought me closer to achieving my desired outcome.

Answer №1

The three.js inspector tool simply analyzes the scene and presents the properties of the objects in an interactive user interface.

Imagine you have an OBJ file structured like this:

car
  body
  wheels
    frontLeft
    frontRight
    rearLeft
    rearRight
  windows
    front
    back

By using OBJLoader, a scene hierarchy is created as follows:

car // THREE.Group
  body // THREE.Mesh
  wheels // THREE.Group
    frontLeft // THREE.Mesh
    frontRight // THREE.Mesh
    rearLeft // THREE.Mesh
    rearRight // THREE.Mesh
  windows // THREE.Group
    front // THREE.Mesh
    back // THREE.Mesh
 

The three.js inspector visually represents this hierarchy by object names. Clicking on an object in the tree links to the corresponding object in the scene, displaying its properties such as position, rotation, visible status, etc. Changes made in the three.js inspector UI are directly reflected on the actual scene object.

Creating a map of object name to scene object for quick referencing can be executed with code similar to this:

var nameToObject = {};
scene.traverse(function(node){
    nameToObject[node.name] = node;
});

This approach allows for easy access and modification of object properties based on their assigned names.

For instance, adjusting the size of an object named "frontLeftWheel" can be achieved through:

nameToObject["frontLeftWheel"].scale.addScalar(0.1);

You can also manipulate material properties of objects, like changing the color of the "body" to red:

nameToObject["body"].material.color.setRGB(1.0, 0.0, 0.0);

Replacing objects within the scene, such as swapping out the "rearLeftWheel" with a new mesh called "newRearLeftWheel", can be accomplished with code like this:

var wheels = nameToObject["wheels"]; // parent of rearLeftWheel
wheels.remove(nameToObject["rearLeftWheel"]);
wheels.add(newRearLeftWheel);

These examples serve as a starting point for working with object properties in three.js. If you encounter any issues while accessing your data, feel free to ask for clarification.

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

Tips for passing a page as an argument in the function parameter of the page.evaluate() method?

I keep running into this issue when I pass the page as an argument: TypeError: Converting circular structure to JSON --> commencing at object with constructor 'BrowserContext' | property '_browser' -> object with const ...

Using "Datedropper" in Javascript to automatically populate values in additional input forms

I recently downloaded a "Jquery datedropper" and wanted to incorporate it into my form. Unfortunately, the javascript code does not specify a form field by an "id" or "name." Here is a picture of the problem. As a result, the datedropper is implemented in ...

Iterating over images and displaying them in Laravel's blade templating engine, updating outdated Angular code

Currently, I am in the process of transitioning an Angular repeat function used for displaying images on our website (built with Laravel). The goal is to eliminate Angular completely and handle everything using Laravel loops in the blade template. I have ...

Tips for personalizing the tooltip on a line chart in Vue.js using Chart.js

Attempting to create a line graph using chart js and vue, but new to both technologies. In the chart below, I am trying to change the tooltip to display "10 Answers July 19, 2023". I have attempted to use the beforeLabel and afterLabel options without succ ...

Encountering issues with verifying login credentials in Angular 2

Greetings! I have designed a login page where the user will be logged in if the response is successful, otherwise an error message will be displayed. Below is the JSON data with email and password fields: { Email": "<a href="/cdn-cgi/l/email-protect ...

"Transferring a Ruby hash containing objects as keys to JavaScript on the front end as a Map object: a step-by-step

While Javascript does not natively support objects as object keys, the Map object offers a solution. My query is, how can an object like this be transmitted easily from the backend to the frontend? def test_controller object = {"a"=>1," ...

Unable to forward with POST request in Node.js

I have a button on the front end that allows users to update their profile photo using the Cloudinary API. When the button is clicked, a Node.js POST request is sent with the user's data to query the database and update the profile photo URL. The func ...

Step-by-step guide on replicating a website along with its CSS styles and scripts

I've been exploring the idea of cloning a webpage, such as Instagram's login page, along with its CSS elements and JavaScript, to use locally. Basically, I want to duplicate the login page and host it on my test server in a way that allows it to ...

What is the best way to reindex dynamically added rows in jQuery?

I've been searching everywhere, but I can't seem to find the solution to my problem. I have a table where rows are dynamically added based on an index. So, when I click on a link in row 5, I want to add a new row at index 6. The issue arises when ...

Issue with React app: IconMenu does not expand when clicked

Seeking assistance with a react app and IconMenu from material-ui. I've been researching similar issues extensively but haven't found a solution yet :( In the code below, I am looking to manually trigger the expansion of a menu - this is essenti ...

How to rename a class of an image tag using jQuery

I need to update the class name in my image tag <img src="img/nex2.jpeg" class="name"> When hovering over with jquery, I want to add a new class to it. After hovering, the tag should appear as follows: <img src="img/nex2.jpeg" class="name seco ...

Unable to insert an array within a function

I've searched for the answer but couldn't find it - my array is not pushing to datahasil. How can I push the array hasil into datahasil...?? const data1 = await JadwalBooking.aggregate([{ $project: { "keterangan": "$keterangan", ...

Having trouble connecting retrieved database information with AngularJS for display in the view

I am currently working on extracting data from a database and displaying it in a view using AngularJS. I have created a WEM method for this purpose: [WebMethod] public static string fetchNames() { SqlHelper sql = new SqlHelper(); DataTable dt = sql.Ex ...

Is it possible to alter objects through the use of jQuery.map?

I'm working with a key-value pair that looks like this: var classes = { red: 'Red', green: 'Green' }; Is there a way to add a specific value before each key in the pair? Can jQuery.map help with this task? The desired end result ...

Ways to apply autofocus to one element once another element already has it?

I have encountered an issue while attempting to give a textarea autofocus using the autofocus attribute. Upon doing so, I receive an error message in the console that says: Autofocus processing was blocked because a document already has a focused element. ...

Styling does not affect an Angular component that is injected into an iframe

I am facing an issue with styling in an iframe when trying to append my own angular component. Despite various attempts, I have been unsuccessful in getting the styling to apply to the component within the iframe. Upon loading the iframe, I use JavaScript ...

Eliminate repeat entries in MongoDB database

Within our MongoDB collection, we have identified duplicate revisions pertaining to the same transaction. Our goal is to clean up this collection by retaining only the most recent revision for each transaction. I have devised a script that successfully re ...

Utilizing unique layouts for specific views in sails.js and angular.js

I am currently working on a Sails.js + Angular.js project with a single layout. However, I have come across different HTML files that have a completely different layout compared to the one I am using. The layout file I am currently using is the default la ...

What is the best way to set a background image that covers the entire screen while eliminating any borders on the sides using React and Material UI?

Working with Material-UI in React, I am attempting to set a background image behind a Paper component on the login page. Despite setting the image's backgroundSize to cover, there is still a white edge on the left and right sides of the screen. Below ...

Having trouble retrieving the selected date from the Material-Ui datepicker after the first selection

I am facing an issue with the material-ui dateandtimepicker where I am unable to retrieve the date value on the first select. The value only shows up after the second click, and it's always the previous one. Is there a way to convert the date to a for ...