[Request] Transformation rotation for animation help
-
Here is a clip of a web dialog being used as a kind of ruby console but for Javascript.
[flash=480,295:1n391k8g]http://www.youtube.com/v/sa9trxXhIdU[/flash:1n391k8g]
The report comes from this ruby callback:@dlg.add_action_callback("modelArrayGenerate") {|d, p| a = 0 model = Sketchup.active_model model.options["UnitsOptions"]["SuppressUnitsDisplay"]= true entities = model.active_entities selection = model.selection[0] entities.each do |entity| if entity.class == Sketchup;;Group || entity.class == Sketchup;;ComponentInstance if entity == selection t = selection.transformation to = t.origin array = [] array[0] = ["Index",a] array[1] = ["x",to[0]] array[2] = ["y",to[1]] array[3] = ["z",to[2]] array[4] = ["axisX",t.xaxis] array[5] = ["axisY",t.yaxis] array[6] = ["axisZ",t.zaxis] array = array.join(";") cmd = "receiveArray('#{array}');" @dlg.execute_script (cmd) end #selection if end #entity if a+=1 end # loop }
I want to save each of the transformation reports to record various positions and orientations for a component manipulation in the SU display. These are to be used to animate the component directly from the web dialog scripts. As you can work SU tools while web dialog animation is running, I want to test whether it is possible to have components flying around while regular scene-based animation is in progress.
If anyone would like to help with that that would be great, but my first ambition is to get to grips with or solve the rotation business - I am currently really confused. Can anyone help me to translate the x-, y- and zaxis results to degrees for each axis?
Many thanks
Chris
-
@chrisglasier said:
Can anyone help me to translate the x-, y- and zaxis results to degrees for each axis?
Have you tried .degrees method? Is it something more complicated?
Tomasz
-
@unknownuser said:
Have you tried .degrees method? Is it something more complicated?
I have used the degrees method when there is an Integer to attach it to, but here there are three numbers for each axis. For me it is more complicated because I don't really know what's what!
Chris
-
I have done a search, because I have remembered it has been discussed already.
The Transformation Matrix thread.There is enough information there with examples of angles readouts.
Good luck
Tomasz -
@unknownuser said:
There is enough information there with examples of angles readouts.
Thanks very much Tomasz for that. I don't know how I missed it; I am always looking out for such topics.
I decided to understand a bit more and am currently studying Vector lessons.
So between the two I should get to where I want - the ability to interpret any skp model as a javascript array. My idea is to kind of sneak up on namesets from the rear, as opposed to previous full frontal assault!
Cheers
Chris
-
@chrisglasier said:
My idea is to kind of sneak up on namesets from the rear, as opposed to previous full frontal assault!
-
@chrisglasier said:
Can anyone help me to translate the x-, y- and zaxis results to degrees for each axis?
Vector3d.angle_between will get you part of the way there.
angle = t.zaxis.angle_between(Z_AXIS).degrees
However, angle_between always gives a result between 0 and 180 (or more accurately between zero and ฯ).
-
@jim said:
> angle = t.zaxis.angle_between(Z_AXIS).degrees >
However, angle_between always gives a result between 0 and 180 (or more accurately between zero and ฯ).
What..?! All you need to do to convert radians to degrees is appending
.degrees
? doh! -
-
@jim said:
@thomthom said:
What..?! All you need to do to convert radians to degrees is appending .degrees? doh!
Heh, see the Numeric documentation for the SketchUp-specific additions.
Meh,... I've seen that page, taking note of the unit conversion, but completely missed the ones relating to radians and degrees. goes of to clean up some scripts...
-
@jim said:
> angle = t.zaxis.angle_between(Z_AXIS).degrees >
However, angle_between always gives a result between 0 and 180 (or more accurately between zero and ฯ).
A quick pre-dinner try I get this with 90 deg rotation around X :
Now off to eat!
Chris
-
@chrisglasier said:
@jim said:
> > angle = t.zaxis.angle_between(Z_AXIS).degrees > >
However, angle_between always gives a result between 0 and 180 (or more accurately between zero and ฯ).
A quick pre-dinner try ...
... failed because I made
t = selection.transformation
, when it should be something related to vector3D ??
Also I don't understand the difference/relationship/source ofzaxis
and(Z_AXIS)
.Perhaps I have made it too confusing both here and also in this previous topic.
All I want to do is iterate through model entities to make each component and group a javascript array element, each with its own array of name/value couplets at least for xPos, yPos, zPos, xRot, yRot, zRot. The xyz business seems OK, where in an animation, for example, I can compare one entity's position with a new position to determine the translation. I want to do the same with rotations around each of the axes.
Sorry if I'm being rather painful, but I am sure a good result will help the mantra below.
Chris
-
Chris,
Z_AXIS, X_AXIS, and Y_AXIS are constants that are the vectors of SketchUp's global axes.
Here's a screenshot of a cube rotated 45 deg around the Z axis.
And I just noticed I said to use
.degrees
in an earlier post, sorry; it's.radians
.
-
@jim said:
Chris,
Z_AXIS, X_AXIS, and Y_AXIS are constants that are the vectors of SketchUp's global axes.
Here's a screenshot of a cube rotated 45 deg around the Z axis.
And I just noticed I said to use
.degrees
in an earlier post, sorry; it's.radians
.Jim I think the fog maybe clearing ... many thanks ... chris
-
I made a skp, rb, html set to test what I understand so far about transformations on a 3x4x5 metre group. If you want to try it out temporarily unzip the files to your plugin directory.
Here is a clip of it showing a group rotating around each of the axes in turn:
[flash=425,344:32q3oq38]http://www.youtube.com/v/aXxkHu7gSv4[/flash:32q3oq38]
The rotations are made with:
tr = Geom::Transformation.rotation(Geom::Point3d.new(ent.bounds.center), rv, theDegrees)
, where rv is the axis,and the angle_between values with:
(t.xaxis.angle_between X_AXIS).radians
- same for y and z.
From this, I gather if the angle_between values returned are 0-180-180, the group has been turned by 180 deg on the X_AXIS; and if 0_90_90, the group could have been turned 90 or 270 (-90) degs on the X_AXIS; and the same for the angle_between values for the other axis rotations.
The second clip shows the application of different series of rotations:
[flash=425,344:32q3oq38]http://www.youtube.com/v/TFAnDrHXaIg[/flash:32q3oq38]
Screenshots of rotations providing angle_between values of 90-90-90 shows there is either something fundamental missing or perhaps that an entirely different method is appropriate.
Any suggestions about this most welcome...
Chris
Advertisement