[Plugin] Import OBJ with Materials v2.1 20131118

[Plugin] Import OBJ with Materials v2.1 20131118

Postby TIG » Wed Jul 15, 2009 12:24 am

(c) TIG 2009-2013 ***in parts***

obj_importer.rb


Note: Based on Jim Foltz's 'obj_import.rb'* AND with Whaat's UVW texture mapping ideas... Many thanks!

BUT it's now with added materials with opacity/texture, also units
setting and YZ axes swap dialogs.

On running it a dialog asks you to select units [pick from list] the
file uses any 'units' in the .obj's header as the default value,
if not then default=Inches.

The vt info in the .obj file is used for UVW texture mapping.
There's a warning in the console if .obj's .mtl or any texture files
are missing.
If the .mtl is missing or incomplete the #default material# is used.
If a texture file is missing the material's colour/opacity is used.

The zoom goes to extents at the end.

A closing dialog asks if you want to swap the YZ axes - Yes/No reply -
some .obj files are created flipped like that... so if the import
appears flipped over Yes will right it...
The 'swap YZ axes' has a one step undo.
The imported materials and geometry in the OBJ groups is only undoable
in multi-steps - instead simply erase the OBJ imported groups
and delete any new materials...

*** IT CAN TAKE A _L_O_N_G_ TIME TO LOAD A BIG OBJ FILE
WITH PERHAPS MANY THOUSANDS OF FACES ***
[perhaps >> 1 minute per Mb ?]

Sometimes very complex OBJ shapes don't receive their textures at all.
Some OBJ files have tiny numbers: then faces might not be created:
if so, retry with larger 'units', you can scale group(s) down afterwards.
Some OBJ files have tiny face planar discrepancies: then some faces
might get triangulated to compensate: if so, retry with smaller 'units'
and scale group(s) up afterwards.
Some complex files might need a bit of manual healing: they can also
have erroneous vertices - so it's recommended you use 'Fix Problems'
accessed from the 'Model Info > Statistics' dialog -
especially if the result takes a long time to process or
have divided faces forced to form geometry or if it feels jittery
when orbiting around the model etc...
Some complex files with excessive smoothing etc might fail to import.

View textured results in 'Monochrome' to see any reversed faces...

Use:
1. Menu > Plugins > OBJ Importer > Import OBJ [with Textures]
2. > Import OBJ [no Materials]
3. > Import OBJ [as Mesh]

Option 1. Imports faces with mapped textures.
Option 2. Imports faces without materials [but materials added to model].
Option 3. Imports a mesh without materials [but materials added to model].

Open the Ruby Console before running to see additional reporting...

Version:
1.0 20090714 First release.
1.1 20090715 Existing Materials re-used/make variant option added.
Swap Y & Z axes ? Yes/No, option added.
1.2 20090723 Name changed to 'obj_importer.rb' / 'Import OBJ'
Proper UV texture mapping added.
Added dialog geometry & texture mapping Units.
1.3 20090728 Submenu added with '..no Materials' and '...as Mesh'
options. Material/usemtl duplicated entries trapped.
Failure to import geometry - warning message added.
Scaling errors corrected.
Model.start_action()...commit_action removed as it was
causing errors on complex files.
1.4 20100406 Different format obj file text now accepted.
1.5 20100816 Missing group in obj trapped [with "g OBJ"].
1.6 20100825 Negative face indices allowed.
1.7 20100825 Fill from mesh changes.
1.8 20100825 Trapped for spaces in image-names/paths.
1.9 20110223 Errors with occasional reversed faces resolved.
2.0 20130321 Blender-quads now import as two tri-facets.
The OBJ file must contain header-text "# Blender" or similar.
2.1 20131118 Import of OBJ files using a -ve counter for f vertices within
sub-groups fixed. View now refreshes with each group completion.
###

Download


Download from the SketchUcation Plugin Store or AutoInstall using the toolset within SketchUp itself
http://sketchucation.com/resources/plug ... e-download
2
Last edited by TIG on Tue Jul 28, 2009 10:01 am, edited 4 times in total.
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Import OBJ with Textures - New

Postby Khai » Wed Jul 15, 2009 12:31 am

hmm a suggestion for a future release would be the option to swap the Z and Y axis on import.
0

Khai 
 

Re: [Plugin] Import OBJ with Textures - New

Postby Chris Fullmer » Wed Jul 15, 2009 12:35 am

And thanks!
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Plugin] Import OBJ with Textures - New

Postby CadFather » Wed Jul 15, 2009 12:58 am

another very useful gem TIG - ThankYou.....
0
Quarr-IT - SketchUp Training from the Master.. http://quarr-it.com/
User avatar
CadFather 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Import OBJ with Textures - New

Postby EarthMover » Wed Jul 15, 2009 2:34 am

Thanks TIG, this will come in very handy! Thanks to Jim as well for his initial contribution.
0
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: [Plugin] Import OBJ with Textures - New

Postby MALAISE » Wed Jul 15, 2009 8:58 am

Thanks TIG, to enhance Jim's plugin

Quite useful when having OBJ library.

MALAISE :thumb: :thumb:
0
La Connaissance n'a de valeur que partagée
User avatar
MALAISE 
 

Re: [Plugin] Import OBJ with Textures - New

Postby richcat » Wed Jul 15, 2009 10:55 am

Thanks TIG :thumb: & Jim :thumb:
0

richcat 
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby TIG » Wed Jul 15, 2009 10:57 am

Here's v1.1
viewtopic.php?p=172790#p172790

Existing Materials re-used/make variant option added.
Swap Y & Z axes ? Yes/No, option added.
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby bagatelo » Wed Jul 15, 2009 4:23 pm

The inverse option, for export obj files from SU is possible?
Thanks anyway....
0
Last edited by bagatelo on Tue Mar 04, 2014 6:27 pm, edited 1 time in total.
While the cat's away, the mice will play
User avatar
bagatelo 
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby Chris Fullmer » Wed Jul 15, 2009 4:31 pm

I'm confused Bagatelo. What are you asking? This is a plugin that will import .obj into SU. The inverse would be an .obj exporter.

Chris
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby Khai » Wed Jul 15, 2009 4:49 pm

TIG wrote:Here's v1.1
viewtopic.php?p=172790#p172790

Existing Materials re-used/make variant option added.
Swap Y & Z axes ? Yes/No, option added.


thank you!!!!!!!!
0

Khai 
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby Khai » Wed Jul 15, 2009 6:18 pm

okies the Swap Z/Y is working perfectly :)

the sizing is not atm :( (tried importing OBJ's from trueSpace, UVmapper and Hexagon) it's almost there tho...

Edit

Thanks to the notes inside the Ruby I was able to reset my units to Metres and now things are coming in the right size :)
0

Khai 
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby Whaat » Thu Jul 16, 2009 2:50 am

Hi TIG,

I can't quite tell from your description if your script imports UVs correctly. If you are looking to add this feature, I was working on an OBJ importer awhile ago that imported materials and UVs. If you would like the code, let me know and you can have it. I don't think I'll ever get around to releasing it officially.

Thanks for another great script!
0

Whaat 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby TIG » Thu Jul 16, 2009 9:04 am

Whaat wrote:Hi TIG,

I can't quite tell from your description if your script imports UVs correctly. If you are looking to add this feature, I was working on an OBJ importer a while ago that imported materials and UVs. If you would like the code, let me know and you can have it. I don't think I'll ever get around to releasing it officially.

Thanks for another great script!


My tool imports materials and textures. It doesn't deal with UVs as most of the example OBJs I have didn't have that info in their MTLs. Thus any imported material has it's colour and opacity set correctly, AND also has the correct texture added BUT without any UVs scaling etc - it uses the default 10" square version... However if you already have a pre-existing material with a matching name that has UVs set etc it asks if you want to use it or make a new variant - if you answer Yes it uses the existing material...

Am I right in understanding you, that some OBJ/MTLs have UV mapping info ? SUp exported OBJ/MTLs don't seem to ? Please PM me your half-baked UV code and I'll look at incorporating it [with credit to you, as appropriate]... Thanks for the offer.
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby Khai » Thu Jul 16, 2009 12:05 pm

yup UV information is a core part of the OBJ Format.. makes it very useful for transfering between programs, such as Maya to trueSpace to Max....
0

Khai 
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby TIG » Thu Jul 16, 2009 1:43 pm

Khai wrote:yup UV information is a core part of the OBJ Format.. makes it very useful for transfering between programs, such as Maya to trueSpace to Max....

Where is it stored in the files ?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby Khai » Thu Jul 16, 2009 1:56 pm

I think it's stored as the VT entries.

ah yes here we go

http://local.wasp.uwa.edu.au/~pbourke/dataformats/obj/ - Full OBJ Format Spec

vt u v w

Vertex statement for both polygonal and free-form geometry.

Specifies a texture vertex and its coordinates. A 1D texture
requires only u texture coordinates, a 2D texture requires both u
and v texture coordinates, and a 3D texture requires all three
coordinates.

u is the value for the horizontal direction of the texture.

v is an optional argument.

v is the value for the vertical direction of the texture. The
default is 0.

w is an optional argument.

w is a value for the depth of the texture. The default is 0.

0

Khai 
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby bagatelo » Thu Jul 16, 2009 5:06 pm

Chris Fullmer wrote:I'm confused Bagatelo. What are you asking? This is a plugin that will import .obj into SU. The inverse would be an .obj exporter.

Chris



Yes, I mistake. I have think about EXPORT model with obj file types. But .3ds is very good.

I try to import this model ( http://www.evermotion.org/modelshop/sho ... /1806/0/0/ ) into sketchup and the plugin don't work properly. Export with 3ds Files from MAX result crash in Sketchup.

FBX files maybe can be de very best option.
0
While the cat's away, the mice will play
User avatar
bagatelo 
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby TIG » Thu Jul 16, 2009 5:40 pm

Khai wrote:I think it's stored as the VT entries.

ah yes here we go

http://local.wasp.uwa.edu.au/~pbourke/dataformats/obj/ - Full OBJ Format Spec

vt u v w

Vertex statement for both polygonal and free-form geometry.

Specifies a texture vertex and its coordinates. A 1D texture
requires only u texture coordinates, a 2D texture requires both u
and v texture coordinates, and a 3D texture requires all three
coordinates.

u is the value for the horizontal direction of the texture.

v is an optional argument.

v is the value for the vertical direction of the texture. The
default is 0.

w is an optional argument.

w is a value for the depth of the texture. The default is 0.


Thanks - I see it now... wait for update...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby TIG » Thu Jul 16, 2009 8:37 pm

bagatelo wrote:
Chris Fullmer wrote:I'm confused Bagatelo. What are you asking? This is a plugin that will import .obj into SU. The inverse would be an .obj exporter.

Chris



Yes, I mistake. I have think about EXPORT model with obj file types. But .3ds is very good.

I try to import this model ( http://www.evermotion.org/modelshop/sho ... /1806/0/0/ ) into sketchup and the plugin don't work properly. Export with 3ds Files from MAX result crash in Sketchup.

FBX files maybe can be de very best option.

Since I'm not going to pay $35 for a model of a small statue I can't see how the actual file is structured - looks like it might be very complex though !!! The current OBJ Importers are quite limited...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby avariant » Fri Jul 17, 2009 7:47 pm

Cool, thanks TIG. I've been using Jim's importer for a long time.

One thing I've encountered with materials. You are assuming that the 'd' tag comes after the Kd tag, but it doesn't necessarily. It can show up anywhere in the list. The obj format doesn't require a specific order. So, if 'd' comes first, the plugin is crashing.
0

avariant 
PluginStore Author
PluginStore Author
 

Re: [Plugin] Import OBJ with Materials- v1.1

Postby TIG » Fri Jul 17, 2009 7:57 pm

Thanks for the info... I'm looking at uv mapping to so a fix might be soon...
I also need to trap mtl's with a texture but no colour [using texture.average_color if no Kd ?]... I am looking at various fixes and other improvements... Please check out the Ruby Forum over the coming days...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Import OBJ with Materials- v1.2

Postby TIG » Thu Jul 23, 2009 6:15 pm

I have at last got working - texture mapping, units dialog, YZ-flip, crash avoidance etc etc...

Here's v1.2 viewtopic.php?p=172790#p172790

Note that the file has been renamed and you need to delete any earlier ones...

It's still not perfect, takes ages with large files and large/complex/smoothed objs come out slow/messy/in_need_of_fixing...

Feedback please.
0
Last edited by TIG on Fri Jul 24, 2009 1:33 am, edited 1 time in total.
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Import OBJ with Materials- v1.2

Postby Khai » Thu Jul 23, 2009 6:27 pm

ok for some reason I'm not getting anything at all.
it's asking for the measurements, I see it reading lines at the bottom, it asks me if I want to flip Axis...then nothing appears on screen.

edit : testing an idea. I think it's do to with the choice of measurements. hold on...
0

Khai 
 

Re: [Plugin] Import OBJ with Materials- v1.2

Postby Khai » Thu Jul 23, 2009 6:41 pm

yup it's metres and kilometres.... looks like it's coming in so tiny you can't see it. (Inches, Feet, yards, Miles, Millimetres, Centimetres are working ok)
0

Khai 
 

Re: [Plugin] Import OBJ with Materials- v1.2

Postby Khai » Thu Jul 23, 2009 6:44 pm

and I'm happy to report the UVmapping is now spot on :)
0

Khai 
 

Re: [Plugin] Import OBJ with Materials- v1.2

Postby EarthMover » Thu Jul 23, 2009 6:56 pm

Tested also and it's working Great!!! Thanks TIG. I tried to import a few Lounge Chairs that I had for Vue in .obj format that crashed SU with the previous importer and the new version handled them flawlessly.
0
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: [Plugin] Import OBJ with Materials- v1.2

Postby Khai » Fri Jul 24, 2009 8:07 pm

ok I'm getting strange results here. some OBJ's just won't import for some reason. Trying to figure it out atm.. the affected OBJ's will load into other app's ok tho, so I'm not sure what the issue could be.

Update.

the affected OBJ's import with Jim's Ruby ok (apart from flipped Axis and no UVmapping), so it looks like a bug somewhere..

want me to send you a copy of one of the affected OBJ's to test with?
0

Khai 
 

Re: [Plugin] Import OBJ with Materials- v1.2

Postby TIG » Fri Jul 24, 2009 10:05 pm

Khai wrote:ok I'm getting strange results here. some OBJ's just won't import for some reason. Trying to figure it out atm.. the affected OBJ's will load into other app's ok tho, so I'm not sure what the issue could be.

Update.

the affected OBJ's import with Jim's Ruby ok (apart from flipped Axis and no UVmapping), so it looks like a bug somewhere..

want me to send you a copy of one of the affected OBJ's to test with?


Please send... Waht errors do you get in the console etc ?

Jim's code for the faces is effectively the same in both versions ??? :?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] Import OBJ with Materials- v1.2

Postby Khai » Fri Jul 24, 2009 10:23 pm

thats the problem.. I'm not getting any errors (unless I'm doing something wrong the console window is remaining blank).... I'm just not getting the object...

the steps I'm getting :

select Ruby
Select OBJ
asked what unit's. (choose at random here)
Status bar shows the lines being read

here on a file that works I see the OBJ loaded. on a file thats not working, the view jumps, nothing is shown.

asked if I want to flip axis. (y/n)

no change in scene from start. - this also happens if I choose Metres or kilometers with an OBJ that does work ok. (obj will load as Feet...) the affected OBJ's will load with Jim's original script tho *shrug*

ok.. where do you want me to send the files to? I can't seem to attach them here...
0

Khai 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 

Next


 

Return to Plugins

Who is online

Users browsing this forum: No registered users and 2 guests

Visit our sponsors: