Import OBJ script modification (Max Smirnovs script)

Next
 From:  G (MAJOR_MORE)
10531.1 
This is a long shot...

*Background*
I love the new OBJ to Subd import option thats available out of the box in version 4.

But I also need an import option that brings in objs without automaticly subdividing them. This is because I sketch out shapes in a poly modelor and bring them into Moi as reference.

*Attempted solution**
I've been using Max Smirnovs import obj script (ImportObj.v.1.5.2015.09.10) which is great and almost does the job. It simply brings in the obj and makes them into a surface/solid which is amazing and not something i've encountered anywhere else in such a user friendly manner.

*Problem*
The problem I have is the script has a normalise funtion built in. As far as I can tell it does some clever stuff and scales up any objs that fall within certain size parameters. This means any obj no matter what its export scale was or how tiny it might translate over to Moi is always scaled up to work in Moi. Clever stuff!

But what i've found is this can lead to objs being imported and scaled inconsistently. For example in Blender I might have a mesh thats 30cm x 30cm x 40cm. On import to Moi it comes in at 30cm x 30cm x 40cm. If I modify the Obj by insetting and extruding a face so its say 30cm x 30cm x 50cm. This could lead to the normalise function bringing the obj in at different measurements.

I'd really like Moi to match Blenders scale (its almost there) and remain consistent as I bring in other Objs i've created from Blender.

*Request*
I've played with the script myself and removed the normalise funtion. Doing this i've been able to get a consistently scaled import from Blender no matter the size and shape of the mesh. Yay! But the obj consistently imports at very very tiny sizes as there is no scaling anymore. If it was 3cm in Blender it ends up at 0.003cm or thereabouts in Moi I think.

Is there anyone here clever enough to mod the script so it doesnt normalise but instead scales up by a defined factor? If this factor could be editied in script then it would have a lot of great utility and be similiar to the obj scaling on import option you get in poly modelors.

This is the funtion (theres other related code) I removed but i'm not a coder so have no idea how to replace it with consistent scaling:

function normalizeObj (norm)
{
normalize = norm;
scale = 200/(max.x-min.x+max.y-min.y+max.z-min.z)/3
var scalelog = Math.pow(10, Math.round(Math.log(scale)/Math.log(10)));
if (scalelog>1) { scalelog /=10 }
scale = Math.round(scale/scalelog)*scalelog;
if (scale == 0) scale = scalelog;
if ( !normalize && scale<1 ) scale=1;
scale *=100;
if ( !normalize ) for ( v in vertices ) vertices[v] = moi.VectorMath.createPoint(vertices[v].x*scale, vertices[v].y*scale, vertices[v].z*scale);
if ( normalize ) for ( v in vertices ) vertices[v] = moi.VectorMath.createPoint((vertices[v].x-max.x/2-min.x/2)*scale, (vertices[v].y-max.y/2-min.y/2)*scale, (vertices[v].z-min.z)*scale);
scale /=100;

*Second request*
If obj import with a scaling option could become an official feature it would be amazingly useful.

Thanks in advance!!
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  G (MAJOR_MORE)
10531.2 
Ah after some digging this script does exactly what i'm after.

With my setup and scene scale I have to export at a scale of 100.000 for the measurements between Blender and Moi to be 1:1 but the control is great.

https://github.com/TitusLVR/BMOI_Connector

If theres a way this can be added a feature to Moi officially that would be grand!

EDITED: 20 Dec 2021 by MAJOR_MORE

Image Attachments:
Size: 98.9 KB, Downloaded: 55 times, Dimensions: 723x529px
Size: 526.5 KB, Downloaded: 31 times, Dimensions: 1338x753px
Size: 102.6 KB, Downloaded: 25 times, Dimensions: 959x506px
Size: 36.5 KB, Downloaded: 31 times, Dimensions: 796x374px
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Michael Gibson
10531.3 In reply to 10531.2 
HI G, I'm glad you were able to get it resolved!

For reference for others who may be reading this in the future, it is possible to turn off the normalization in Max's ImportOBJ script by giving it a parameter value as described here:
http://moi3d.com/forum/index.php?webtag=MOI&msg=6674.453

Also another way that you can bring in a mesh as a lighter reference is the OBJ23DMWireframe converter on the resources page here:
http://moi3d.com/wiki/Resources#Obj23dmWireframe_converter

That converter will convert the edges of a poly obj file into lines, it won't have as much bloat as converting a mesh into a solid made up of a zillion little trimmed planes will.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All