Urgent - Is there a script to reset/zero all transformation?
-
Please do write it.
-
I've alsmost got something ready for you to test. Does anyone know (I know you do!) what classes get listed in the
model.definitions
? I am planning on iterating through all definitions and then instances to straighten out their transformation. But I need to know what to weed out. I am guessing I would only include groups and components, is there anything else whose transformation might need to be reset?Chris
-
The
model.definitions
returns a list of 'component_definitions' which includes all components, groups and images... you can test for the last two with.group?
and.image?
http://code.google.com/apis/sketchup/docs/ourdoc/componentdefinition.html -
Well, I don't know if this is perfect. It should reset the scaling of all groups and components. Just enter this all as a single line of code into the ruby console.
ins = [];Sketchup.active_model.definitions.each { |e| e.instances.to_a.each { |x| ins << x } };ins.each do |e| if (e.class == Sketchup;;ComponentInstance) || (e.class == Sketchup;;Group);old_t = e.transformation.to_a;old_t[15] = 1.0;ngsm = (1)/(e.transformation.to_a[15]);e.transformation = Geom;;Transformation.new(old_t);e.transform! Geom;;Transformation.scaling(ngsm,ngsm,ngsm);end;end
Then try to re-export. I'll be interested to see if this changes anything. Thanks!
Chris
-
ok thanks TIG! I couldn't remember if it was more than just those 3 classes. In the end, I just filtered out anything that was not a group or componentinstance. I think that works out safely.
And the theory behind what my code is fixing is simple. SU uses a cheap trick to sometimes adjust the global scale of objects. It just changes the 16 element of the transformation matrix from "1.0" to a global multiplier (0.5 if the component is scale 2x larger, for example). And then it multiplies the rest of the transformation object by that 16th element. BUT, the 16th element of the transformation array is ignored by most other apps. So when exporting to renderers, they often do not take into account that a component might have a global scale modifier applied to it, hiding in that 16th element. Thus they ignore the global scale entirely, causing problems.
So this snippet will go through and determine what the global multiplier is, and apply it to the transformation matrix and reset the 16th element to 1.0. Thus the components should export correctly because all their scale data should be contained in the regular location inside the transformation matrix.
We'll see if it really helps though.
Chris
PS. This snippet WILL fix face me components that rotate all crazy in SU 7.1, as that is also a side effect of SU's own cheap global scaling trick, if anyone is having problems with that.
-
Did you get a chance to test this Jan?
-
@chris fullmer said:
Did you get a chance to test this Jan?
Sorry for not getting back.
I managed to export the scene in smaller chunks and am currently finishing it up in time for my deadline.
I will try it when things calm down later this week.
Thank you very much, I'm sure I will use this in the future. -
@unknownuser said:
The best way to tackle this issue is to explode EVERYTHING. It takes a while, especially with larger models, but it's nearly full-proof. Same thing happens when exporting to certain other formats. The Group/Comps structure of SketchUp isn't translated properly. Exploding the model puts everything in one context.
You might want to have a look a TBD's Bomb script. It explodes everything without having to do it manually. It takes the same amount of time, but you can 'set-it-and-forget-it' and wait till it's done. Might be hours though.
HTH
The thing is I don't want to explode everything, since that removes any control over how lightmapping is applied on certain objects.
Anyway you can watch the result here:
http://forums.sketchucation.com/viewtopic.php?f=81&t=28907 -
Please oh pretty please try my code snippet? Just to see if it helps, or if it even just doesn't crash. I'd love to see if that little bit of code could fix it all.
Chris
-
Oh and maybe I didn't explain it well enough. It does not change anything visually in the model. It will all look exactly the same. Nothing gets exploded. So just run it, then re-export and see if it helps sort out the issues. Thanks!
Chris
-
@chris fullmer said:
Please oh pretty please try my code snippet? Just to see if it helps, or if it even just doesn't crash. I'd love to see if that little bit of code could fix it all.
Chris
I will I will. Next week I'll have to make some modifications so I'll have to re export at least parts of the scen. I will try it then if not before.
-
Chris, I tried the script but it didnt work. Same mess as before.
Will try again later. -
Bummer, I was very hopeful. Any chance you could forward me a copy of your model to test a few things on?
-
I'll do that tomorrow.
Advertisement