[Plugin] Import OBJ with Materials v2.1 20131118
-
from 3ds max, how do you export the files properly to have all the textures? in max it is properly textured but when you import to sketchup there is no texture. is it possible?
-
Thanks TIG. Your generous plugins and help on this forum have been invaluable to me. Much appreciated.
-
Don't laugh but I'm getting 'Error: 666' in the Ruby console? Some files import but most don't? They're fine in Modo and 3DS Max?
-
Those must be some evil files, Rich. Pray to St Patrick today
-
@unknownuser said:
Don't laugh but I'm getting 'Error: 666' in the Ruby console? Some files import but most don't? They're fine in Modo and 3DS Max?
The '666' is my joke error value - it means I don't know what the bleep is causing this but I'll struggle on regardless !
It is quite possible to get some 666 error messages but to end up with what appears to be a perfect result anyway. Some OBJ files seem to have a few faces coded in an awkward way that won't get made - usually too small to handle or perhaps with three effectively co-linear points - I can trap for these but NOT 'fix' them - so it just puts '666' when it is presented with one that fails... Do you say that some files fail completely? Can you post or PM me one so I can test with perhaps so more helpful error messages temporarily allowed on my own setup... Have you tried just doing the import as a 'mesh' - this can overcome some issues with this type of problem... -
TIG, thanks for this importer. I am playing with the "3D Modeling with Silhouettes" application, and using your plugin to bring its models into sketchup.
-
Hei TIG, sorry to bother...
I can run your script easily, but at the end of the transformation progress SU exits giving a BUGsplat message... How can I fix this? -
@pibuz said:
Hei TIG, sorry to bother...
I can run your script easily, but at the end of the transformation progress SU exits giving a BUGsplat message... How can I fix this?Not sure - without loads more details about version, OS the OBJ itself etc...
Have you tried the OBJimporter by Fluidimporter http://forums.sketchucation.com/viewtopic.php?p=316470#p316470 that is quicker and less prone to error than my old thing... -
No I didn't! I'll try that thanks!
-
Hi TIG, I've got a few more patches for you, on your importer this time. I've been running into " - Material already exists..." errors a lot, which cause the associated group to be imported untextured.
I changed the following code to reuse the existing material, but it might be nice to have an option to automatically mangle the material name if it really is a different texture.
when "newmtl" mat_name=values[0] matnames=[];materials.each{|mat|matnames << mat.display_name} if matnames.include?(mat_name) puts mat_name+" - Material already exists..." ### traps for usemtl called x2 in obj or pre-existing materials current_mat=nil ## NEW; make sure pre-existing materials are re-used if nil==new_mats.find{|mat|mat.name==mat_name} new_mats << materials[mat_name] end
I also noticed that the vast majority of import time is spent updating the progress bar. A quick fix that shortens a minute-long import to a few seconds:
change Sketchup.set_status_text("Processing line #{line_cnt} of #{lines.length}") to if line_cnt % 73 == 0 # could be any number, 73 just makes the digits spin nicely Sketchup.set_status_text("Processing line #{line_cnt} of #{lines.length}") end
Finally, one of my test models suffered from the "some faces get reversed" bug mentioned above - but I noticed that when I then imported the same object again, without my material reuse code so it ended up untextured, the problem disappeared. When I tested by commenting out the "position_material" line in the following code the problem also went away, but obviously so did the texture.
if new_face and @current_mat!= nil if @current_mat.texture != nil pt_array=[] pt_array=[verts[0],face_uvs[0],verts[1],face_uvs[1],verts[2],face_uvs[2]]if verts_length==3 and face_uvs pt_array=[verts[0],face_uvs[0],verts[1],face_uvs[1],verts[2],face_uvs[2],verts[3],face_uvs[3]]if verts_length>3 and face_uvs # new_face.position_material(@current_mat,pt_array,true) else ...
I'll keep poking at it, but I'm having to figure out both Ruby and Sketchup's API as I go, so you might have more luck.
Here's the globe model I noticed the problem on for referencetextured globe that suffers from some face-inversions when imported
-
Immer
I'd be more than happy for you to take over 'my' OBJimporter - 'Fluid' has recently made an equivalent compiled version [currently PC only].
BUT if you want to redo aspects of my stuff then please do so and publish them - I only want credit/blame for my bits [note that several others also made earlier contributions to this 'collaboration' !].
You can start a new thread [then I'll edit mine to direct new browsers to yours...]
I have too much on right now to do many changes to tools that I feel are now 'spent'...
BUT if you can improve it please do so -
Thanks, but I've got enough projects on my plate already, I was just lopping a few warts off a new tool in my box. I've seen Fluid, but my main dabbling machine is an old Mac so it's not convenient to use.
I can completely relate to not wanting to make frequent updates to old projects though, so here's my faster version for anyone interested.much faster version that also reuses existing materials instead of leaving objects untextured
-
@immer said:
Thanks, but I've got enough projects on my plate already, I was just lopping a few warts off a new tool in my box. I've seen Fluid, but my main dabbling machine is an old Mac so it's not convenient to use.
I can completely relate to not wanting to make frequent updates to old projects though, so here's my faster version for anyone interested.[attachment=0:1hpltocr]<!-- ia0 -->obj_importer.rb<!-- ia0 -->[/attachment:1hpltocr]
Cool will give it a spin shortly.
Cheers
-
TY ...
-
This plugin is the missing link between SketchUp and "Bryce 7 PLE" (also free) that I use as a renderengine.
It is a perfect team and this obj-exporter is the hard to find plugin.
Many thanks!
Daniel -
Great plugin, thanks.
However, I have a problem with many OBJ files I try to import to SketchUp... Textures are missing.
From previous posts i realized that this is not actually a "bug" in OBJ importer. The reason is that many OBJ files are originally exported with "hard coded" texture paths (instead of relative pathing). So OBJ importer is trying to find textures from folder that doesn't exist in my computer...
But hey, maybe it could be possible to do something for this?
Maybe you could add a setting for "default textures folder", so that OBJ importer would always look for textures from that user-defined folder (and it's subfolders) when OBJ file is imported? Or maybe textures that are in the same folder with OBJ file (or in /Textures folder) could be automatically imported with OBJ file?
I know that this can be done by editing manually MTL file that comes with OBJ file, but that's too much "hacking" for me... Especially if I have to do this with every sigle OBJ file that I import to SketchUp...
-
The MTL file almost always goes in the same folder as the OBJ file - if you open the OBJ file in a text editor like Notepad it shows the MTL 'relative' path in the first few lines...
If you open the MTL file in a text editor like Notepad it shows the path expected to each of the image-files used for the textures. Simply place the image-files [if you have them] in the same relationship - either in the same folder as the MTL or a subfolder suitably named... -
Yeah that can be done of course - it's just not always very handy.
For exaple, a guy who originally created the 3d object might have stored his textures into folder like this:
C:\Documents and Settings\Leonardo\projects\maya\sci-fi\spaceships\enterprise\textures
Before I could place my textures in similar location, I would first have to create folder "Leonardo", then subfolder "projects", then subfolder "maya" etc. As I said, not very handy...
Programs like "Accutrans" and "Deep Exploration" have this "default textures folder" function. Or, if they can't find textures either in folder that is defined in MTL file or in "default textures folder" they ask the user "do you want to locate textures manually?".
I just thought that OBJ Importer could have some similar function... But maybe it's too much to ask all the features that are in commercial applications from a free plugin...
(Don't get me wrong, OBJ Importer is really really great plugin already just the way it is.)
-
No!
A GOOD OBJ exporter typically makes copies all of the linked image-files either in the same folder as the OBJ, OR better in a subfolder called Images or XXX_Images or XXX_Textures, where XXX is the name of the OBJ file - OR it just fails to export them like 'tree3d.exe'.
The OBJ file says which MTL file it's using in the first few lines of code - typically it's just a name and the MTL is a file in the same folder as the OBJ, with a matching name but the .mtl suffix.
Then for each collection of faces defined in the OBJ it sets the material 'by name' that it'll be used for those faces, and there's a list of materials 'by name' defined within the MTL file - each with its own color, transparency, texture etc.
The MTL file sets the path to an image-file, if any, because an MTL can just be a 'color'.
That path as I said is typically to a file in a subfolder, kept with the OBJ/MTL, that holds jpg/png files, named exactly as specified in the MTL file...An OBJ importer looks for the MTL file... and if it exists then it applies the materials in it to the appropriate face-sets... it looks for the specified image-file [if any] for each material and if it's found it then uses that too...
If you have the image-files it's a simple matter of putting them in the path specified in the MTL - in my experience I have never seen anything other than a list of file names [i.e. the image-files are in the same folder as the MTL file OR more commonly the image-files are in a subfolder kept with the MTL file
IF the MTL file is 'messed up' then manually edit it to repath each of the image-files defined in the lines starting 'map_Kd ' thus:
map_Kd Images/image1.png
and where 'image1.png' id the name of the file you have that should be used...
and where you have made a new folder called 'Images' kept with the MTL file and you have put all of the image-files in there! -
"A GOOD OBJ exporter typically makes copies all of the linked image-files either in the same folder as the OBJ, OR better in a subfolder called Images or XXX_Images or XXX_Textures, where XXX is the name of the OBJ file"
I couldn't agree more that that's the way is SHOULD be done. However, many programs, for example popular 3ds Max, don't do it that way by default. (Why not, I have no idea.)
When you save an object from 3ds Max in OBJ format (using default settings), linked image-files are NOT copied to the folder where OBJ and MTL files are saved. MTL file only contains links to original texture folder.
And when people try to open these files (in other computers) they can't see textures... And they keep filling forums with questions like "missing textures when opening OBJ file" (as seen in this thread also).
But hey, who cares, let's forget the whole thing!
Advertisement