Two problems with an 'Export to Vue' ruby script
-
I've been working on a ruby script to take a SketchUP camera into 'Vue'. It's heavily based on Grant Marshall's 'camera2modo' ruby, and it's ALMOST working.
However, I've come across a couple of issues I'm trying to solve, and my head is just about fried. The information may well be around, but if it is, it's not in a form I'm currently capable of understanding - so your time / patience is appreciated!
Problem #1:
camscript.puts("cam.SetPosition(" + vx.to_s + ", " + vy.to_s + ", " + vz.to_s + ")")
outputs something that looks like this:
cam.SetPosition( 5.44m, -7.92m, 9.85m)
I would like it to output this, WITHOUT the units:
cam.SetPosition( 5.44, -7.92, 9.85)
I thought that 'to_f' would be the correct command, but that doesn't seem to work... Any ideas on how I could do this?
Problem #2:
I need to calculate the 'roll' (i.e. z-axis rotation) of the camera.
I've found a tutorial on highend3d on how to do this:
http://www.highend3d.com/boards/index.php?showtopic=57543&mode=threaded&pid=57740
And I'm pretty sure that in Ruby, (rather than MEL) it should look like this:
# Calculate Y-rotation of camera (roll) globaly = [0, 1, 0] normal = zaxis.cross globaly projection = normal.cross zaxis cosine_roll = up.dot projection ry = Math.acos(cosine_roll).radians if (upy < 0) ry = -ry end
But this doesn't return the correct result. Does anyone know what I'm doing wrong?
Many thanks for your time.
AJ
-
Alex I cannot help with the coding as I'm useless at such things but I would like to add my support and urge any of our code wizards to look into this as being a dedicated Vue user, such a facillity would be most welcome and very needed.
I'm very happy someone (you) is doing an effort in making this feature possible. -
#1 try this:
camscript.puts("cam.SetPosition(" + vx..to_f.to_s + ", " + vy.to_f.to_s + ", " + vz.to_f.to_s + ")")
You were right thinking you wanted .to_f, but it still has to end up being a string. So keep the .to_s on the end also.
I'll have to think about #2. Maybe someone else will come up with the answer faster,
Chris
-
Thanks Chris...
It's currently working perfectly for SketchUP scenes in which the camera isn't rotated in the z-axis (i.e. rolled / dutch tilted), and is above ground level.
You also have to enter the camera 'field of view' by hand once you're in Vue.
That's why I haven't posted it up yet - super user-unfriendly!
If I can solve these two problems with Ruby, and the 'FoV' issue with Python, SketchUP and Vue are ready to go.
AJ
EDIT: I've just got problem#1 to work, using .to_f.to_m.to_s - your script still produced a value in inches. Thanks for the pointer, though...
-
Oh good! I never get unit stuff right on the first try. Glad you figured it out.
I'll keep thinking about the other issue.
Chris
-
@alex jenyon said:
EDIT: I've just got problem#1 to work, using .to_f.to_m.to_s - your script still produced a value in inches. Thanks for the pointer, though...
SU always works in inches internally. Use
.to_mm
to turn the SU units to mm. Look at the Numeric class for other conversions: http://code.google.com/apis/sketchup/docs/ourdoc/numeric.html -
I've solved both problems now - please see my other thread for the finished plugin
Advertisement