Implementing UV unwrap algorithm by my own

Hi, all.

I’ve a need to implement UV unwrap algorithm in JS myself. Anybody knows what algorithm Blender uses for Unwrap and Smart UV Project options of “UV Mapping” menu? As far as I know Bleder is not an open source, so I don’t think I can find the source of Blender’s current implementation. If anybody knows any place with existing JS implementation, I’d be very grateful to have a link to that one, just names of algorithms would be very useful as well, so I can read up and implement myself.

Thanks,
Denis.

It kind of is open source.

I must be drunk.

Thanks.

After a short digging into the source of Blender implementation of lscm unwrap, I’ve decided a lifetime is not enough to understand it and implement it on my own in javascript, so I’m stuck with ugly import/export back and forth between Blender and my world editor tool.

I’m a sad panda.

However you can still use Blender from command line.
https://www.blender.org/manual/advanced/command_line.html?highlight=command%20line

I remember somewhere I read that some dudes used Blender to create renders for their 3D models, in a Website… That means that they uploaded the program into the webserver and hit it server side with command line arguments.

Really you can make a Frankenstein multi-tiered application that way. :wink:

So, let’s say I have a mesh in THREE.JS, I then need to AJAX it over to the server, run blender in command line, which will import the mesh, uv unwrap, export it to a file, which will be returned as AJAX response back to client?

Sounds… just about awesome :smiley: I can basically just use everything I’ve done so far in python for my web app! Use a WebGL frontend with Blender for backend mesh operations is just about… genious, if that’s possible!

Yes, let’s say you run a PHP script, you will have to see how to run terminal/command line commands
http://php.net/manual/en/function.exec.php

– import the mesh
you will have to know the filepath of the model (which filename it is)

– uv unwrap
perhaps you might do the simple unwrap, you will see what fits best

– export it to a file
you might try the obj file format since is the most simple one

– which will be returned as AJAX response back to client
This means that you will parse the .obj line by line and send it as a response (JSON?)

However there might arise some technical errors but you will figure out them as they arise. Now they won’t make sense and you can ignore them just to setup the thing, however just to have a prediction, keep reading.

  1. The most obvious one is to set a configuration allow maximum execution time for this script. There is an Apache configuration to allow maximum script execution time and this will prevent the server killing your script too early. This is because depending on the model size, the server load, the requests per minute, etc, this process won’t be really fast as in your local machine.

  2. You might try to write a PHP script as CRON job, let it run once a day to delete old .obj exports. You won’t like your folders get large with old files.

  3. You might try to create a script that will manage the execution of the batches into schedule. You won’t like your server handle 100 requests on demand because probably it will crash the machine. You most likely handle 5 or 10 requests simultaneously and put the others into the list.

I’m friends with PHP, did some nice server side excel file generations, so yeah this one should be possible. I’m not planning to do something that will run with hundreds users, rather few users, so should be ok.

Just tested with some silly script that imports some object, unwraps and then exports it via a simple python script from command line, and it works like magic.

Which means I can basically build a 3d canvas rendered web app with WebGL/THREE.JS as front end visual layer, while having the power of blender python script execution to manupilate the mesh as I wish, as backend. Now I can get rid of heavy javascript mesh manipulation I had to implement myself!

Thanks, const, this is pure awesomeness :smiley:

Glad to hear that it works. :slight_smile: