Automating the creation of box UVW maps through programming

I'm looking for a way to automatically create box UVW maps in 3D models, similar to the functionality of UVW Map -> Box in programs like 3ds Max.

Here's an example with the default UV mapping

And here is an example with the desired box UV mapping that I want to achieve

I've experimented with javascript-based solutions, like the ones found here and here, but the results vary depending on factors like merged meshes, existing UV maps, or different directional orientations.

When applying a box UV map in Blender or 3ds Max manually, it always produces accurate results.

Ideally, I would like a command line tool similar to gltf-pipeline that can be used as follows:

generate-box-map -i model.gltf -type box -size 50

I have come across tools such as PyMeshLab and Meshmatic, as well as attempts to achieve this via Python in Blender, but haven't found a satisfactory solution yet. Is there a simpler way to accomplish this?

Answer №1

I successfully solved this issue using Blender within a Docker container with the help of this image: https://github.com/linuxserver/docker-blender.

Here is an overview of the project structure:

app.js

The app.js file receives a request through express. The body of the request contains a link to a GLTF model hosted on "https://some-storage.com/model.gltf". It then initiates a Blender process using

child_process.exec(`blender -b --addons magic_uv -P /app/src/main.py --log-level -1 -- ${pathToDownloadedGLTFFile}`)

main.py

...

    argv = sys.argv
    argv = argv[argv.index("--") + 1:]  # get all args after "--"

    param_input_file = argv[0]

    bpy.ops.import_scene.gltf(filepath=param_input_file)
    for obj in bpy.data.objects:
        if obj.type == 'MESH':
            obj.select_set(True) 
            bpy.context.view_layer.objects.active = obj 
            bpy.ops.object.mode_set(mode='EDIT')

    bpy.ops.uv.muv_uvw_box_map(size=instructions['size'], rotation=(instructions['rotationX'], instructions['rotationY'], instructions['rotationZ']))

...

# export back to GLTF and write to /some/dir/model.gltf

In addressing the issue of varying UV directions, adjusting the value of rotation.x to 270 has proven to resolve it.

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

Establishing a link between numerous web browsers solely through client-side technology

After creating a compact AJAX-powered chat application, I wonder if it is feasible to handle all the communication client-side. Can individual pages recognize each other and share real-time updates without involving the server? Is there a way to achieve th ...

The XML content fails to display after initiating an AJAX request

Attempting to create an ajax call and accessing a field from the table on the server yields the following: <PushProperty><Status ID = "1"> Success </Status><ResponseID> b3633c9eeb13498f </ResponseID><ID> 9098 & ...

Tips for converting numbers in JavaScript and troubleshooting issues when trying to filter out non-numeric characters using Tel input commands

After finding this answer on how to convert digits in JavaScript, I attempted to apply the method to convert numbers in a phone number field with tel input type. function toEnglishDigits(str) { const persianNumbers = ["۱", "۲", &quo ...

Is it possible to combine multiple filter examples together?

Could you please provide some examples or references related to the next task: var planets = [{ residents: [{ name: 'Mars' }, { name: 'Jupiter' }, ...

Having trouble unselecting the previous item when selecting a new item in Reactjs

I have a list of items and I want to change the background color of the currently selected item only. The previously selected item should deselect. However, at the moment, all items are changing when I click on each one. Can anyone help me solve this issue ...

What are some strategies for efficiently displaying a large amount of data on a screen using Javascript and HTML without sacrificing performance?

Imagine having a hefty 520 page book with over 6,200 lines of text ranging from 5 to 300 characters each. The challenge lies in efficiently displaying this content on the screen for users to read without causing lag or performance issues. Attempting to re ...

Locate the intersection point of an arc using three.js

I am working with a unique type of geometry called TorusGeometry. To achieve what I need, I must translate this geometry to a specific point labeled as C, which is the intersection point of perpendicular lines drawn from the center points of both ends labe ...

Should I return X in async functions, or should I return "Promise.Resolve(X)"?

I've always found this to be a tricky concept to fully grasp. Let's delve into async functions in Typescript. Which implementation is accurate? async function asyncFunctionOne(string1: string, string2: string, string3: string) { var returnOb ...

AngularJS nested menu functionality not functioning properly

I am currently working on a nested menu item feature in AngularJS. I have a specific menu structure that I want to achieve: menu 1 -submenu1 -submenu2 menu 2 -submenu1 -submenu2 angular.module('myapp', ['ui.bootstrap']) .cont ...

Efficient Loading and Smooth Scrolling with Angular2 (version 7)

I'm struggling to display a component upon the initial page load using lazy loading, where the content is only loaded when it's in view. For instance: - With 10 components on the page, I aim to show/scroll to component number 7 when the page lo ...

passing arguments during deferred resolve() and when() operations

I am currently working on a flash card website and I need to determine the status of preloaded images once they have finished loading or if there was an error. After obtaining the status of each image, I will proceed with further actions. My code is inspi ...

Why am I getting the error in react-dom.development.js related to my index.js file?

Upon checking the console, the following message is displayed: react-dom.development.js:86 Warning: ReactDOM.render is no longer supported in React 18. Please use createRoot instead. Until you transition to the new API, your application will behave as if i ...

Adjust the size of the embedded iframe to match the dimensions of the containing div

Is there a method to resize the iframe embed code for a vine so that it fits within the boundaries of the enclosing div? The supplied embed code already includes sizing information as shown below: <iframe src="https://vine.co/v/iMJzrThFhDL/embed/simp ...

What is the best method for performing cross-domain queries utilizing ajax and jsonp?

When attempting to send an ajax request to a specific URL, I encountered an error. Below is the code I used: $.ajax({ url: "http://webrates.truefx.com/rates/connect.html?q=ozrates&c=EUR/USD&f=csv&s=n", dataType : 'jsonp', ...

What are the methods used in TypeScript to implement features that are not available in JavaScript, despite TypeScript ultimately being compiled to JavaScript?

After transitioning from JavaScript to TypeScript, I discovered that TypeScript offers many features not found in JS, such as types. However, TypeScript is ultimately compiled down to JavaScript. How is it possible for a language like TypeScript to achie ...

performing a request to Axios API with the inclusion of ${item} within the URL

I am having trouble with calling axios in Vuetify due to backticks and ${} within the URL. I believe I need to convert it into JSON format, but my attempts have been unsuccessful. Could you please provide an explanation? Here is the code snippet. Whenever ...

The error message "TypeError: res.response is undefined" is indicating

Currently, I am implementing user authentication using JWT auth within a Vue/Laravel single-page application. The problem arises in the register module as it fails to respond upon clicking the button. Upon inspecting the Firefox developer edition's co ...

Guide to making a reusable AJAX function in JavaScript

Currently, I'm working on developing a function that utilizes AJAX to call data from another server and then processes the returned data using a callback. My goal is to be able to make multiple calls to different URLs and use the distinct responses in ...

Generate div elements dynamically for each object being populated in JSON using JavaScript

I have a main container that displays a list of JSON objects. Each object should be displayed as a separate DIV element with specific details, one after the other. Additionally, I have a comments section on a webpage where the details are stored in JSON f ...

Creating a Component and Programmatically Returning a Value in Vue.js: A Step-by-Step Guide

Could you assist me in solving my issue? I am looking to develop a customized plugin for my project so that my team and I can easily implement an alert component without having to design the dialog box repeatedly on every page and vuejs file. My objective ...