Anyone has any suggestions?
Latest posts made by Djarlo
-
RE: Compute Rotation and Scale from Transform Object
Thanks to both
heh must have missed that type too time and again i looked it all over to see whats wrong -
RE: Validate points for planar faces.
@gaieus said:
Hi Djarlo and welcome!
There are already some nice examples of skeleton animation, see this post for example:
http://forums.sketchucation.com/viewtopic.php?f=323&t=34530Also, we have a Developers' Forum - your ruby topic would rather belong there. If you wish, I can move it and there, with the other scripters, you could improve your importer easier I believe.
Hi, thanks for your reply, thats an interesting thread, very different as what i'm working on though.
And yes if you could move my thread to the correct forum that would be great.) -
RE: A Welcome Message to New SketchUcation Members
@foxlogan said:
http://www.youtube.com/watch?v=4Y6Rn3CusRc&feature=youtube_gdata for those who use sketchup for imvu i made a tutorial at the end of last year which shows you from start to finish and even importing it to imvu. the video is under 6 minute but very easy to follow, if you would like to know anything else dont be afraid to contact me
Its nice, but it has a way to high poly-count for what you are trying to use it. when using the curve tool reduce the ammount of segments, by changing the number bottom/right of the window.
-
Validate points for planar faces.
Hey all, im pretty fresh to this forum, so i'll start with introducing myself
So yah, Im Djarlo, currently living in the Netherlands.
Cause i have a light form of autism Some coding languages are extremely easy for me to learn and others really difficult. with Ruby being one that is rather difficult.I have several SketchUp related Application projects.
- An application for making Skeleton hierarchies and animating them. (Alpha)
- An Application to weight parts of the mesh to different Skeleton bones. (Beta)
And im working on an Importer currently.
All of the apps contain very little Ruby, and are handled by an external process.
I have an issue with the importer im working on, it works dine with xmf files exported with 3DS-Max and Blender, but not too well with files exported with SketchUp. unfortunately the creator of that exporter suddenly dissapeared years ago without ever finishing it and its a rbs, so theres nothing to be done there.
The problem is it wrongly exports certain lines as faces, ofc. those are not planar faces.
My plugin does this:
exe = Sketchup.find_support_file "xmftorb.exe", "Plugins/" plugins_menu = UI.menu("Plugins") menu = plugins_menu.add_submenu('XMF Importer') xmfReload = menu.add_item('Import xmf') { File.delete(ENV["TMP"] + '\mesh.rb') if File.exists?(ENV["TMP"] + '\mesh.rb') UI.openURL exe until File.exists?(ENV["TMP"] + '\mesh.rb') sleep 10 end load ENV["TMP"] + '\mesh.rb' File.delete(ENV["TMP"] + '\mesh.rb') if File.exists?(ENV["TMP"] + '\mesh.rb') }
The program lets you open a file and and creates a ruby script with the info from that file, the script looks like this:
i = Sketchup.active_model.entities.add_group i.name = "Car[0]" i.entities.add_face [-349.200000.mm, -658.578644.mm, 135.616973.mm], [349.200000.mm, -658.578644.mm, 58.578644.mm], [-349.200000.mm, -658.578644.mm, 58.578644.mm] i.entities.add_face [349.200000.mm, -658.578644.mm, 58.578644.mm], [-349.200000.mm, -658.578644.mm, 135.616973.mm], [349.200000.mm, -658.578644.mm, 135.616973.mm] i.entities.add_face [349.200000.mm, -658.578644.mm, 58.578644.mm], [349.200000.mm, -941.421356.mm, 185.453688.mm], [349.200000.mm, -941.421356.mm, 58.578644.mm] i.entities.add_face [349.200000.mm, -941.421356.mm, 185.453688.mm], [349.200000.mm, -658.578644.mm, 58.578644.mm], [349.200000.mm, -658.578644.mm, 185.453688.mm] i.entities.add_face [-349.200000.mm, 800.000000.mm, 341.421356.mm], [-349.200000.mm, 658.578644.mm, 185.453688.mm], [-349.200000.mm, 658.578644.mm, 341.421356.mm] i.entities.add_face [-349.200000.mm, 658.578644.mm, 185.453688.mm], [-349.200000.mm, 800.000000.mm, 341.421356.mm], [-349.200000.mm, 658.578644.mm, 135.616973.mm]
Witch gets loaded and deleted again.
Obviously it error's out on non-planar faces.
I tried to ignore non-planar faces by adding an error handler in the exe.
if all Y is the same AND all X is the same = Ignore
if all Y is the same AND all Z is the same = Ignore
if all X is the same AND all Z is the same = IgnoreBut that just takes care of the straight lines and not the diagonal ones
Is there any way of error handling available in Ruby?
or maybe theres some calculation on the points that can verify whether or not those points make a valid planar face.
Or perhaps some command in SketchUp that can check/verify the points?thanks.
-
RE: Compute Rotation and Scale from Transform Object
@tig said:
Thanks for the input...
Here's my revised code using you ideas - it's still in radians and I have tried not to clash with your method naming etc - it now finds x/y/z rotations and [x,y,z] rotation as an array and has extra methods to set rotations from a 3 item array, referring either to the model axes or object's axes...### transformation.extensions.rb (c) TIG 2009 > ### From original ideas by TBD and others ? ### TIG 20091010 > ### The euler rotation ideas from Dave Burdick 20100324 > ### It extends the methods for Geom;;Transformation... > ### The built-in method "object.transformation.origin" return a point3d > ### that is the object's origin/insertion; the new method > ### object.transformation.getX etc returns the X location of the > ### object [or Y or Z]. > ### The setX(x) resets the X value of the object [or Y or Z]; it > ### returns a new transformation that can then be used to reset the > ### original transformation; thus; > ### object.transformation=object.transformation.setX(another_object.transformation.getX) > ### - here it makes the object's X = another_object's X ; > ### it also could be given a float, e.g. 12.345 or a 'variable'... > ### The object.transformation.scaleX etc returns the scale on that axis. > ### The object.transformation.rotX etc returns the rotation on that axis > ### in radians; use ... .rotX.radians to get it in degrees... > ### It uses different names to TBD's, e.g. 'rotZ' instead of 'zrot' etc. > ### Note the capitalization... this is because some 'compiled scripts' > ### use 'rotz' already etc - [and they return the rotation in degrees!] > ### object.transformation.rotXYZ > ### returns a 3 item array giving the rotations in x/y/z > ### object.transformation.rot_a > ### returns an 11 item array of the transformation's rotation/scaling > ### - it can be used to extract some data more easily or as below... > ### object.transformation=object.transformation.rotation_from_rot_a(another_object.transformation.rot_a) > ### this applies another_object's 'rot_a' to change the object. > ### object.transformation=object.transformation.rotation_from(another_object.transformation) > ### this applies another_object's rotation/scaling to the object. > ### it returns a new transformation that can then be used to reset the original... > ### object.transformation=object.transformation.origin_from(another_object.transformation) > ### this applies another_object's origin/location to the object. > ### it returns a new transformation that can then be used to reset the original... > ### object.transformation=object.transformation.rotation_from_xyz([xrot,yrot,zrot]) > ### this applies a 3 item array of x/y/z rotations about the model's x/y/z-axes, > ### this could also be the array returned by rotXYZ. > ### it returns a new transformation that can then be used to reset the original... > ### object.transformation=object.transformation.rotation_from_xyz_locally([xrot,yrot,zrot]) > ### this applies a 3 item array of x/y/z rotations about the objects's x/y/z-axes, > ### this could also be the array returned by rotXYZ. > ### it returns a new transformation that can then be used to reset the original... > ### > class Geom;;Transformation > def euler_angle(xyx=[]) > m = self.xaxis.to_a + self.yaxis.to_a + self.zaxis.to_a > if m[6] != 1 and m[6]!= 1 > ry = -Math.asin(m[6]) > rx = Math.atan2(m[7]/Math.cos(ry),m[8]/Math.cos(ry)) > rz = Math.atan2(m[3]/Math.cos(ry),m[0]/Math.cos(ry)) > else > rz = 0 > phi = Math.atan2(m[1],m[2]) > if m[6] == -1 > ry = Math;;PI/2 > rx = rz + phi > else > ry = -Math;;PI/2 > rx = -rz + phi > end > end > return -rx if xyz==0 > return -ry if xyz==1 > return -rz if xyz==2 > return [-rx,-ry,-rz] if xyz==[] > end > def getX > self.to_a[12] > end > def getY > self.to_a[13] > end > def getZ > self.to_a[14] > end > def setX(x) > if not x.class==Float and not x.class==Integer > puts "Transformation;;setX( ) expects a Float or Integer." > return nil > end#if > x=x.to_f > t=self.to_a > t[12]=x > return self.set!(t) > end > def setY(y) > if not y.class==Float and not y.class==Integer > puts "Transformation;;setY( ) expects a Float or Integer." > return nil > end#if > y=y.to_f > t=self.to_a > t[13]=y > return self.set!(t) > end > def setZ(z) > if not z.class==Float and not z.class==Integer > puts "Transformation;;setZ( ) expects a Float or Integer." > return nil > end#if > z=z.to_f > t=self.to_a > t[14]=z > return self.set!(t) > end > def scaleX > Math.sqrt(self.to_a[0]**2+self.to_a[1]**2+self.to_a[2]**2) > end > def scaleY > Math.sqrt(self.to_a[4]**2+self.to_a[5]**2+self.to_a[6]**2) > end > def scaleZ > Math.sqrt(self.to_a[8]**2+self.to_a[9]**2+self.to_a[10]**2) > end > def rotX > #(Math.atan2(self.to_a[9],self.to_a[10])) > #Math.acos(self.to_a[5]) > euler_angle(0) > end > def rotY > #(Math.arcsin(self.to_a[8])) > #Math.acos(self.to_a[0]) > euler_angle(1) > end > def rotZ > #(-Math.atan2(self.to_a[4],self.to_a[0])) > #Math.asin(self.to_a[4]) > euler_angle(2) > end > def rotXYZ > euler_angle > end > def rot_a ### rotation matrix 4x3 3 and 7 are nil > t=self.to_a > r=[] > [0,1,2,3,4,5,6,7,8,9,10].each{|i|r[i]=t[i]} > r[3]=nil > r[7]=nil > return r > end > def rotation_from_xyz(xyz) > if not xyz.class==Array and not xyz[2] and not xyz[0].class==Float and not xyz[1].class==Float and not xyz[2].class==Float > puts "Transformation;;rotation_from_xyz( ) expects a 3 Item Array of Angles [as Floats]." > return nil > end#if > tx=Geom;;Transformation.rotation(self.origin,X_AXIS,xyz[0]) > ty=Geom;;Transformation.rotation(self.origin,Y_AXIS,xyz[1]) > tz=Geom;;Transformation.rotation(self.origin,Z_AXIS,xyz[2]) > t=(tx*ty*tz) > return self.set!(t) > end > def rotation_from_xyz_locally(xyz) > if not xyz.class==Array and not xyz[2] and not xyz[0].class==Float and not xyz[1].class==Float and not xyz[2].class==Float > puts "Transformation;;rotation_from_xyz_locally( ) expects a 3 Item Array of Angles [as Floats]." > return nil > end#if > tx=Geom;;Transformation.rotation(self.origin,self.xaxis,xyz[0]) > ty=Geom;;Transformation.rotation(self.origin,self.yaxis,xyz[1]) > tz=Geom;;Transformation.rotation(self.origin,self.zaxis,xyz[2]) > t=(tx*ty*tz) > return self.set!(t) > end > def rotation_from_rot_a(rot_a) > if not rot_a.class==Array and not rot_a[10] > puts "Transformation;;rotation_from_rot_a( ) expects an 11 Item Array." > return nil > end#if > t=self.to_a > [0,1,2,4,5,6,8,9,10].each{|i|t[i]=rot_a[i].to_f} > return self.set!(t) > end > def rotation_from(trans) > if not trans.class==Geom;;Transformation > puts "Transformation;;rotation_from( ) expects a Sketchup;;Transformation." > return nil > end#if > t=self.to_a > tt=trans.to_a > [0,1,2,4,5,6,8,9,10].each{|i|t[i]=tt[i].to_f} > return self.set!(t) > end > def origin_from(trans) > if not trans.class==Geom;;Transformation > puts "Transformation;;origin_from( ) expects a Sketchup;;Transformation." > return nil > end#if > t=self.to_a > tt=trans.to_a > [12,13,14].each{|i|t[i]=tt[i].to_f} > return self.set!(t) > end > end#class > ### >
Hey Tig, thanks for the great code, i might be doing something wrong here but this:
Selection = Sketchup.active_model.selection[0] Rotation = Selection.transformation.rotXYZ
Gives an error,
Error; #<NameError; undefined local variable or method `xyz' for #<Geom;;Transformation;0xa747534>> D;/PROGRA~1/Google/GOOGLE~1/Plugins/test.rb;128;in `euler_angle' D;/PROGRA~1/Google/GOOGLE~1/Plugins/test.rb;197;in `rotXYZ' D;/PROGRA~1/Google/GOOGLE~1/Plugins/test.rb;64
Any suggestions what could be going wrong?