Exporting a SkinnedMesh with position using Three.js

I am attempting to export a model from a Three.js scene using the OBJExporter.js found at https://github.com/mrdoob/three.js/blob/master/examples/jsm/exporters/OBJExporter.js

Within the scene, I have both base meshes and SkinnedMeshes. To account for this, I made an adjustment to line 250 of the code snippet:

if ( child instanceof Mesh ) {

to

if ( child instanceof Mesh || child instanceof SkinnedMesh ) {

While I am successful in exporting all meshes, the SkinnedMeshes are not correctly positioned or oriented in the exported file. How can I modify the exporter to ensure the SkinnedMeshes are exported correctly, and what could be the cause of this issue?

EDIT: I also attempted to use the STL exporter as suggested by others, but it still fails to export the correct pose due to the specific properties it checks for:

if(typeof object.obj.geometry.attributes.skinIndex !== 'undefined' && typeof object.obj.geometry.attributes.skinWeight !== 'undefined' && typeof object.obj.skeleton !== 'undefined')

These properties are all undefined except for "object.obj.skeleton". The SkinnedMesh objects instead have properties such as "instanceIndex", "normal", "position", and "uv".

EDIT 2:

Apologies for the confusion earlier. Upon re-evaluating the output log, I realized that some meshes do have the properties "skinWeight0" and "skinIndex0" instead of the previously mentioned ones. I updated the code to reflect these changes and successfully accessed those arrays, but the exported model appears distorted:

https://i.sstatic.net/bF2A5.png

Answer №1

Due to the complexity of skinned meshes, their transformation is not solely determined by Object3D.position, Object3D.rotation, Object3D.scale, and their position in the object hierarchy. The skeleton structure also plays a crucial role.

The changes you've made so far may not fully consider the skeleton information. To ensure that the exported data accurately represents the skinned mesh's transformation and shape, a code similar to the one in this PR is required:

https://github.com/mrdoob/three.js/pull/16942

The key concept is to include bone transformations when calculating the final vertex positions (which will be specified in the OBJ file).

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

How can I extract data from an XML file and include it in a JSON file using GulpJS?

Being relatively inexperienced with Gulp/Node programming, I am facing some difficulties while trying to accomplish a simple task :) Within my XML file, there exists a node like the following: <widget version="1.1"></widget> My goal is to ext ...

Ensuring radio button validation prior to redirecting to contact form

I created a survey form using HTML and CSS. I am looking to add validation to the questions before redirecting to the Contact form page. Currently, when a user clicks on the submit button in the Survey form, the page redirects to the contact form. Howeve ...

Choose the list item by identifying the corresponding unordered list

Is there a way to target the second li element within an ul list like this: HTML <ul> <li></li> <ul> <li>This one is what I need to select</li> </ul> </ul> ...

Utilizing an argument in the mapStateToProps function

This component features a counter along with two buttons for incrementing and decrementing the count. class App extends Component { render() { return ( <div className="App"> <h1>{this.props.counter}</h1> <b ...

Setting values to an array based on the index of a specific name in JavaScript - a guide

How can I set values to an array if it has an index in the name field? Here is the sample data: [ { "column": "created_at[0]", "name": "created_at[0]", "type": "range", ...

Unusual AngularJS error encountered while performing calculations on object properties

After running a specific calculation in my code, I encountered an unexpected issue. if (typeof $scope.memoryTable[name][category]['total'] !== 'undefined') { $scope.memoryTable[name][category]['total'] = $scope.memoryTabl ...

Using PrimeNG checkboxes to bind objects in a datatable

PrimeFaces Checkbox In the code snippet below, my goal is to add objects to an array named selectedComponents in a model-driven form when checkboxes are checked. The object type of item1 is CampaignProductModel, which belongs to an array called selectedC ...

Showing a loading animation inside an HTML element

I have a main webpage that contains several buttons. Each button, when clicked, loads a specific target page as an object within a div on the main page. The "target" refers to the page that will be displayed within the object. <script> .... chec ...

Can the `XMLHttpRequest` object stay active when the user switches to a different page?

I am currently facing an issue on my website where users can submit a form using AJAX. The response is displayed in an alert indicating whether the submission was successful or if there were any issues. However, due to the asynchronous nature of this proce ...

Can diverse array elements be divided into separate arrays based on their object type in JavaScript?

Looking to create new arrays based on objects with similar attributes from an existing array? Here's how: Starting with this [ {name: "test", place: "country"}, {name: "walkAndEat", Long: 100, Lat: 15, Location: "place name"}, {name: "te ...

What is the best way to divide a single-item object array into three separate objects?

Here is the data structure for the response data: const res = { data: [{ name: 'c2', ipaddr: '192.168.1.5', port: 4435, sshuser: "abc", sshpass: "xyz", sshport: 22, license: 'licens ...

Modify the JavaScript window.navigator

I am attempting to modify window.navigator, but am facing difficulties in doing so: -- [10:40:28.802] window.navigator['buildID']; [10:40:28.811] "20121129162756" -- [10:40:47.225] window.navigator['appCodeName'] = "I want to change it ...

Template7 produces a bizarre outcome referred to as "each this" whenever JSON is utilized

Currently, I am experimenting with dynamically loading content on Framework7/Template7 pages. Everything works perfectly fine when using static "context" in JSON format. However, when attempting to test it with real-world data from an API, I encounter a st ...

The Discord.js .cleanContent attribute does not show up when using Object.keys() and cannot be logged

My Discord.js Message object should contain a property called .cleanContent, according to the documentation, and it should be a string. console.log(message.cleanContent) works correctly, but console.log(message) does not display the cleanContent propert ...

What is the best way to increase the quantity of items in an array while simultaneously reducing the values of one or more specified keys for each object?

I have the following array: const disabledDays = [ { year: selectedDay.year, month: selectedDay.month, day: selectedDay.day -1 } ]; and I intend to pass it as a prop to a component: <DatePicker v ...

What is the recommended value for the auto-incremented ID field when using the POST method in Node.js?

Currently, I am utilizing the mysql package for NodeJs in order to Post Data to a MySqlDB. Below is an example of my code: app.post('/countries', (req, res) => { const country = req.body.country; const city = req.body.city; const t ...

Troubleshooting my HTML5 local storage issues for optimal functionality

I've been working on using HTML5's localstorage to save two variables and load them upon page refresh, but I seem to be encountering some issues when trying to load the saved items: Variables in question: var cookies = 0; var cursors = 0; Savi ...

Mediawiki functionality experiencing issues within iframe display

Currently, I am working with MediaWiki built in PHP. Due to certain reasons, I have to embed this application within an iframe. All functionalities are running smoothly except for the Edit link for pages. The issue arises when I try to access the second li ...

Using indented, multi-line logging in a NodeJS environment can help to

I'm looking for a way to display objects that have been printed with JSON.stringify() in the console, specifically within the context of a Mocha test suite output. While my tests are running, I want the object log lines to be indented further to the ...

Changing the color of a selected list element using an Angular directive

I'm currently facing an issue with my directive that is supposed to turn a list element red when clicked. It works fine, but I also want it to revert back to black when another list item is selected, so only one item stays in red color. Here is how I ...