Sketchup exporter for Ogre

The place for artists, modellers, level designers et al to discuss their approaches for creating content for OGRE.
stuartf
Gnoblar
Posts: 13
Joined: Thu Aug 04, 2005 8:12 pm

Post by stuartf »

Hi

Just for info:

I've been playing with the exporter for a while and discovered (as usual through painful trial and error!) that some of Sketchup's textures have spaces in the name which Ogre mesh viewer and Blink DON'T like.

So after using the ambient tweak, check you haven't got any textures in the material file like this:
Smooth Face Concrete Block.jpg

If you have you'll need to change the texture file name itself and its reference in the material file to remove the space e.g.
texture Smooth Face Concrete Block.jpg
to texture SmoothFaceConcreteBlock.jpg

Don't know if you can address this Kojak when you get a chance :)
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Post by Kojack »

Seems like I've got the negative scaled stuff sorted out. Here's what happens:

- Each component instance can generate a standard mesh or an inverted mesh, depending on how you scale the instance in sketchup. For example, the minivan generates a minivan_half.mesh and a minivan_half_inv.mesh.
- If an instance is inverted (negative scale on 1 or 3 axes), I negate the z axis in the matrix, negate the z coords of every vertex, and change vertex order (winding).
- Orientation is calculated using an algorithm from intel (third one I tried, only one which worked).

Why negate just z? What if z wasn't the negated axis? Well, it doesn't matter which is negated. I can tell if there's an odd or even number of negated axes, and the orientation can be calculated as long as there's an even number (non inverted mesh). So it doesn't matter if z was the negated axis, I'll end up with an even number (0 or 2) regardless. It just means that meshes with negative scales may really be exported upside down then use the orientation to rotate to the right way up.

Only the required meshes are exported. So if there's only inverted (or non inverted) instances of a component, that's the only mesh file generated. If both are present, 2 meshes are saved. So to cut down on the number of meshes, try to avoid negatively scaling stuff. I may add some tools to manually correct scale, like the backface flipping tool I put in the first exporter.

Now that OSM's seem to be exporting fine, I'll start work on getting materials back in, and dotscene support.



On the texture names with spaces issue: Yep, it's caused by me taking a handy shortcut. Sketchup has a built in function to copy a collection of textures to a directory, but it means I can't remove spaces from the names. Instead, I'll have to manually copy each texture, filtering the names as I go. Shouldn't be hard.
stuartf
Gnoblar
Posts: 13
Joined: Thu Aug 04, 2005 8:12 pm

Post by stuartf »

Top man Kojack - can't wait!
ibrown
Gremlin
Posts: 164
Joined: Wed Aug 18, 2004 6:41 pm
Location: London
Contact:

Post by ibrown »

Hi kojack, great to see you making progress on this. I've only discovered sketchup recently - and I can actually use it! Given that I'm a programmer with the artistic ability of an ant this is pretty exciting :lol:

Ian
TomKT
Gnoblar
Posts: 13
Joined: Wed Oct 25, 2006 9:23 am

Post by TomKT »

Hello Kojack,
Great job. Your script is so well written. You have mentioned that you have
rewritten it - have you published it already? I've been using sketchup_ogre_export
v1_0_1 and it has a problem with inheriting colours
from the parent group\component. Please read PM.

Really great job.
Tomasz
wooohoh
Gnoblar
Posts: 20
Joined: Wed Sep 20, 2006 9:00 am

a special case

Post by wooohoh »

hi!
first, a big thanks to u for this great exporter :D

anyway, i just found out it could go wrong if you have any spaces
in your $g_ogre_path_meshes
for ex, say $g_ogre_path_meshes is = "d:\\nice ogre\\mesh"
then the ogrexmlconverter splits the path,
and its source will be "d:\\nice", while its destinations will be "ogre\\mesh"
so just a little addition of \" is needed in the line in ogre_export.rb, like this.. :P

system($g_ogre_path_xml_converter + " " + append_paths
("\""+$g_ogre_path_meshes,$g_ogre_export_name+".mesh.xml\""))
stuartf
Gnoblar
Posts: 13
Joined: Thu Aug 04, 2005 8:12 pm

Post by stuartf »

Kojack

I seem to be getting some 'unrecognised command' feedback from Blink3d in the material file sometimes - seems to be e.g. around glass materials - here's an example below. Blink gives an unrecognised error for the line which has:
6.0, 6.04
in it.

Not sure what should be at the beginning of this line - if anything!

Any ideas welcome - if something needs adding in in these line that's straightforward I'll add it to my temporary converter page

Thanks in hope!


material Safety_Glass
{
technique
{
pass
{
scene_blend alpha_blend
depth_check on
depth_write off
6.0, 6.04
ambient 1 1 1 0.5
diffuse 1 1 1 0.5
texture_unit
{
texture Glass-Saftey.jpg
}
}
}
}
greetzyl
Gnoblar
Posts: 6
Joined: Tue Jul 10, 2007 3:01 pm

Re: Sketchup exporter for Ogre

Post by greetzyl »

hi:
Now days I working with Sketchup exporter for Ogre but find there is a problem in it! sometimes some textures have space in name!so the model display in ogre is wrong,I use the faction remove_spaces the name of texture in material,bat when the texture copy to the file textures,the neme have space in it! So i want remove_spaces when copy,what can i do?
like this:
$g_ogre_texturewriter.write_all $g_ogre_path_textures,false
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Post by Kojack »

Surprisingly enough, I haven't completely abandoned this thing. :)

After hitting yet another major roadblock, I gave up for a while, waiting for a new version of Sketchup which would hopefully expose itself to the ruby api better.

But I had an idea the other day, so with a complete rewrite of the entire material system (and 99% of everything else) today I've been able to actually get texturing working properly.

It's not ready for a release yet, it's still fairly untested. Unfortunately this isn't the version with OSM scene export, getting the new material system to work with component instancing and scene stuff could take a bit of work.

I'll try to get a texture filename fixer added before releasing it.

Some examples:
Sketchup:
ImageImage
Ogre:
ImageImage

Those 2 models were very troublesome until now, most of their textures came out wrong.

The problem was that sketchup has a habit of doing secret texture stuff in the background without letting you directly know. If a face is uv mapped in a certain way, sketchup actually creates a new texture which is distorted to fit the face. So 2 faces can both reference the same material, and the material lists only 1 texture, but internally there's really 2 textures with different names. Asking sketchup to save it's textures will save the distorted ones too, but there's no direct way of finding out which face uses a distorted texture and which uses the original texture.

To get around it, I've had to create temp geometry with simple uv mapping, add each possible material to it, add the face to a texture writer and store the handles returned from the texture writer. After that, any face which generates a different handle must be distorted, since the first face added for each material is definitely not distorted. Tracking the order the faces are added lets me guess what the distorted textures' names should be.

Argh. My head hurts now.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

WooHoo! I like that! Great stuff! :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
PolyVox
OGRE Contributor
OGRE Contributor
Posts: 1316
Joined: Tue Nov 21, 2006 11:28 am
Location: Groningen, The Netherlands
x 18
Contact:

Post by PolyVox »

Great work! And the best thing is that those models look better in Ogre than the do in SketchUp :D
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Post by Kojack »

It's also renewed my desire to learn ruby better. Before I just implemented the exporter using only the most obvious methods, now I'm looking deeper in the docs to find better ways. Damn nice language.
For example, I originally did:

Code: Select all

def remove_spaces(s)
	for i in (0..s.length)
		if s[i,1] == " " 
			s[i] = "_" 
		end 
	end
	s
end

def extract_name(p)
	s = -1
	for i in (0..p.length)
		if p[i,1] == "\\" or p[i,1] == "/" or p[i,1] == ":"
			s=i
		end
	end
	p[s+1,p.length-(s+1)]
end
but now I do:

Code: Select all

def remove_spaces(s)
  s.tr(' ', '_')
end

def extract_name(s)
  i = s.rindex(/[:\/\\]/)
  if i
    s.slice(i+1..-1)
  else
    s
  end  
end
Probably still enough to make a ruby expert throw up, but I'm learning (I hope). :)

Unfortunately it's currently the teachers equivalent of crunch time (end of trimester marking), so I can't touch it much for the next 4 days. Damn, just as I start making progress again.
TomKT
Gnoblar
Posts: 13
Joined: Wed Oct 25, 2006 9:23 am

Post by TomKT »

Hi Kojack,
Ruby is really very nice in creating those short single line methods.
I have updated today SU2KTexporter. You can have a look how I have
fixed photo-matched textures. Still don't know how to export them correctly
from groups.
One thing - first texture can be distorted as well!
Good luck
Tomasz
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Post by Kojack »

If you mean the first instance of a texture from the texture writer can be distorted, I'm pretty sure my method avoids that. I create temporary geometry which is guaranteed to have simple non distorting uv mapping and feed that to the texture writer. Although I haven't tested it much, so maybe there's still a problem I haven't seen yet.
TomKT
Gnoblar
Posts: 13
Joined: Wed Oct 25, 2006 9:23 am

Post by TomKT »

Sorry, I haven't understood your description precisely. You are fine then.
I am creating just an empty group, assigning the material and do the rest same way as you do. I am not guessing texture names but I assign them
(create new names). I had an awful headache with guessing so I had given up first approach although it was kind of working. SU sometimes was writing incremented texture number without reason.

Tomasz
Serrux
Gnoblar
Posts: 8
Joined: Fri Jun 01, 2007 5:22 pm

Post by Serrux »

I don't know if anyone else has had this problem:
I was applying some different textures to the same face in Sketchup, and whenever I tried to view the final object in Ogre, it failed to load some of the textures (the ones that were "In Model" but not actually visible on a face). This was due to a discrepancy between output to the .material file, and the texture files getting written.

I added this in to fix my problem:

under:
def ogre_export_materials(out, mats)

I added a check for:
if $g_ogre_materials[m] (I had to change the work flow around a bit)

This way, it filters out unnecessary textures (i.e. the ones not in the texture writer).

Serrux
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

To make sure things like this don't get lost in the general chaos of the forum, please can you submit a patch for them.
User avatar
tdev
Silver Sponsor
Silver Sponsor
Posts: 244
Joined: Thu Apr 12, 2007 9:21 pm
Location: Germany
x 14

Post by tdev »

what about the rewrite of the material export function?
i seem to experience some problems with it :-\
Serrux
Gnoblar
Posts: 8
Joined: Fri Jun 01, 2007 5:22 pm

Post by Serrux »

tdev wrote:what about the rewrite of the material export function?
i seem to experience some problems with it :-\
What specific problems are you having? I'll be sending an application for some of my changes to patch the current exporter, but in the meantime I'd be glad to offer some help (if I know how to fix your problem that is :wink: )
Serrux
Gnoblar
Posts: 8
Joined: Fri Jun 01, 2007 5:22 pm

Post by Serrux »

stuartf wrote:...
If you have you'll need to change the texture file name itself and its reference in the material file to remove the space e.g.
texture Smooth Face Concrete Block.jpg
to texture SmoothFaceConcreteBlock.jpg

Don't know if you can address this Kojak when you get a chance :)
Hi stuartf, I've fixed this exporting problem in my exporter version, I'll be applying for a patch to the exporter after I polish it up a bit (I have some of my own preferences built in that I'll need to take out :wink: )
r40ul
Gnoblar
Posts: 1
Joined: Wed Jan 16, 2008 5:27 pm

missing shadows light

Post by r40ul »

Hi,
I've imported a Google Sketchup map with your plugin, but I've got a problem : my lights have no effects on it.
Actually, it projects shadow on other entities, but not on itself.
Look at this screen for more.
http://img183.imageshack.us/img183/8960/problemsb5.jpg
You can see that the robots and the bullets receive the red light, but do not cast shadow on the map. Moreover, the map is not red. When a robot is near a wall, it's no longer enlighted.
We try to erase the map.material, in order to see whether the problem came for here, but it has no effect.
I tried to replace the map by an other existing mesh, and lights are good on this mesh.

Can you help me please.
dracflamloc
Gnoblar
Posts: 1
Joined: Sat Feb 23, 2008 3:14 am

Post by dracflamloc »

Any progress on the new updates?
ethankennerly
Gnoblar
Posts: 20
Joined: Tue May 29, 2007 8:45 pm
Location: Los Angeles, USA

dotScene

Post by ethankennerly »

My project has its storyboards in SketchUp. I have been exporting them to OBJ and then to Maya. From there exporting to dotScene, which my application parses. It is a round-about way to Ogre.

In the first post from 2006, Kojack had Sketchup to dotScene export on a wishlist. I know the project maintainer changed in version 1.2.

Has anyone attempted dotScene exported from SketchUp? I've done a little scripting in SketchUp. I would like to augment an existing dotScene (or XML) exporter.
ethankennerly
Gnoblar
Posts: 20
Joined: Tue May 29, 2007 8:45 pm
Location: Los Angeles, USA

SketchUp DotScene exporter, version 0.0.-1

Post by ethankennerly »

I began a dotScene exporter for SketchUp. Components and cameras pass my test cases for translation and rotation. But when a component is scaled and rotated, the values are not preserved.

I've combed a lot of matrix algebra and 3D graphics links, and revisited my linear algebra and 3D programming textbooks, but this puzzle is stumping me for the last couple of days.

As far as I can tell SketchUp uses left-handed coordinate system in row-major matrix with Z pointing up. OGRE uses right-handed coordinate system in column major matrix with Y pointing up. Advice on converting from one to the other varies. Such as:

Negate row 2 and column 2.
"Coordinate Systems... left versus right."
http://www.ogre3d.org/phpBB2/viewtopic. ... 6f4e2718c6

Invert z-axis and swap vector order.
"Change right hand system to left hand system"
http://www.ogre3d.org/phpBB2/viewtopic. ... 6f4e2718c6

Inspect the rotation matrix by hand.
http://social.msdn.microsoft.com/Forums ... 19a28516cc

SketchUp Pro exports cameras to COLLADA matrix (right-handed coordinate system, column-major, Y pointing up). I've matched half a dozen test case matrices by negating the third row of the SketchUp transform.

Although this works for cameras and translations and rotations, (scale + rotation + translation) seems to vary the output data from what I would expect, and the models appeared warped when rotating.

My conversion algorithm is essentially (leaving out rotation for Y-up until this part works):

Code: Select all

    left_handed_array = left_handed_transformation.to_a
    left_handed_array = to_meter(left_handed_array)
    right_handed_array = negate_row_2(left_handed_array)
    column_major_array = transpose(right_handed_array)
I've been at it for days and am stumped. If you could have a look at those functions in this SketchUp script and advise? I'd appreciate it; and we'd all have a SketchUp dotScene exporter.
http://motorola.usc.edu/svn/runesinger/tool/dotscene.rb

Automated test cases are in the Python-Ogre dotScene loader "test_cube_sphere":
http://motorola.usc.edu/svn/runesinger/ ... otscene.py

Test case data:
http://motorola.usc.edu/svn/runesinger/ ... sphere.skp
http://motorola.usc.edu/svn/runesinger/ ... sphere.dae
http://motorola.usc.edu/svn/runesinger/ ... here.scene
http://motorola.usc.edu/svn/runesinger/ ... e.ma.scene

-- Ethan

Here are a few of the coordinate system links I found especially helpful:
http://www.f-lohmueller.de/pov_tut/a_geo/a_geo85e.htm
http://msdn.microsoft.com/en-us/library ... S.85).aspx
http://www.evl.uic.edu/ralph/508S98/coordinates.html
http://blip.tv/file/1308721
User avatar
Fish
Greenskin
Posts: 131
Joined: Fri Aug 22, 2008 6:12 pm

Post by Fish »

It's my understanding that the .mesh file format can hold the names of a submesh using the "M_SUBMESH_NAME_TABLE". Would it make sense to have an option to export SU layers as submeshes along with the layer name in the M_SUBMESH_NAME_TABLE?

The reason I'm asking is because I'm using the Portal Controlled Zone Scene Manager and I'd like the artists to be able to flag the exterior walls of a house as 'outside' using a layer called 'outside'. Likewise, I'd like the artists to be able to flag interior walls as 'inside' using a layer called 'inside'. Once the .mesh is created and imported into Ogre it would then be trivial to determine which parts of the house belong to which PCZSM zone.

I could ask the artists to create two separate models, one for interior and one for exterior but it's more elegant to have the entire model in one file. Or perhaps someone has a better suggestion?
Post Reply