Thanks for all the help. I found the problem. Apparently if you add some geometry to the scene using ruby and then try to export a mesh of non-component geometry, the normals become unsmoothed. An odd quirk.
Posts
-
RE: Vertex Normals Not Smoothing on Plain Geometry
-
RE: Vertex Normals Not Smoothing on Plain Geometry
@chris fullmer said:
What software and filetype are you exporting to and what settings are you using?
Hi Chris,
I'm just exporting the faces as a mesh using the Sketchup API (e.g.face.mesh) into a simple .obj format. The problem is that the vertex normals returned are not smoothed unless the Sketchup surface is part of a component. If the surface is free standing, ungrouped, or un-componentized geometry, then SU returns un-smoothed vertex normals even though they are displayed in SU as smooth. So I'm thinking that this is a bug in the SU API.
-
Vertex Normals Not Smoothing on Plain Geometry
Is this a bug?
Two simple cylinders. One is plain geometry (circle extruded with push/pull tool) the other is plain geometry and then convereted to a component.
When I export the faces, the vertex normals are different even though smoothing is turned on for both. The plain geometry object on returns non-smoothed vertex normals, whereas the component object returns smoothed normals. What I want is smoothed normals for both cases - as it is displayed in SU.
Any ideas on why this happening or should I report this as a bug.
-
RE: Compute Rotation and Scale from Transform Object
Okay, I got it working to return nice clean Euler angles from a transform object. Here's the code (note - it returns right-handed angles in degrees):
def euler 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.radians, -ry.radians, -rz.radians end
-
RE: Compute Rotation and Scale from Transform Object
I think I found a more foolproof way of doing this by using transform object axis vectors. It turns out, that the 4 x 4 matrix needs to be normalized first (e.g. sans any non-uniform scaling) before computing the rotation angles. So the way to do this is to use the already normalized axis vectors (x-axis, yaxis, etc.). So here's the revised code which returns the rotation angles in degrees:
def rotX Math.atan2(self.yaxis.z,self.yaxis.y).radians end def rotY Math.atan2(self.xaxis.z,self.xaxis.x).radians end def rotZ Math.atan2(self.xaxis.y,self.xaxis.x).radians end
Update: Sorry I jumped the gun here a bit - this isn't correct. The scaling issues now work but the multi rotation problem is still here
-
RE: Compute Rotation and Scale from Transform Object
@tig said:
I think the bits of code that're commented out [starts with a #] are perhaps the right code ?
Swap the two around - this was a work-in-progress that stalled...
Try> def rotX > Math.atan2(self.to_a[9],self.to_a[10]) > ###Math.acos(self.to_a[5]).radians > end
??????
Let me know how it works...
Hi TIG,
Yes, when switching to the commented code versus the original lines it works better (doesn't bomb) - but it give incorrect results when two or more rotations are involved - e.g. roation around the X followed by rotation around Z. I'm going to try to see if I can return better results by working with 2 vectors intead of the whole matrix.
-
RE: Compute Rotation and Scale from Transform Object
@martinrinehart said:
@dburdick said:
Is there a simple Sketchup Ruby method which returns the x,y and z rotation in degrees ...
What's the application for this? (Scaling modifies the xform's [0,0], [1,1], [2,2] entries. Rotations modify all entries from [0,0] through [2,2]. It's not immediately obvious that you can find original operations in any non-trivial case.)
Hi Martin,
Thanks for jumping in on this. I read your wonderful web-page description of the 4 x 4 matrix - truly excellent - and serves as the inspiration behind what I'm trying to do.
Basically, I need to get the exact rotation and scaling values of any component in world space in order to export an instance of that component. I already have figured out how to create the transformation by multiplying the stacked transformations of the component hierarchy, but I need to express the output rotational transformation in degrees - eg rotX, rotY, rotZ - and it needs to work even if the user decides to scale the component non-uniformly (e.g. skewing, shearing). In Sketchup, a user could for example scale a door component in only the Y direction. The current transform extension lib from TIG does not handle this correctly as the lib assumes all scaling is done uniformly to the component. So I need to understand how to adjust TIG's ruby code to accomodate this. Here's his code for example on returing the rotX value from a transform object:
def rotX #(Math.atan2(self.to_a[9],self.to_a[10])) Math.acos(self.to_a[5]).radians end
This works fine when the component is uniformly scaled, but fails when for example the x dimension is scaled to a value different than Y and Z. This is because the array value[5] contains a number greater than 1.0 when non-uniform scaling is introduced. So it will return an error and bomb. I;m not sure what the commented out code is above the equation.
-
RE: Compute Rotation and Scale from Transform Object
Hi Tig,
I tried your transformation extension routines and everything works fine if the component is scaled uniformly. However, when you scale the component non-uniformly, (e.g. scale out in only the X direction), the rotation values return incoreectly and/or the program bombs because the acos function you use is out of range. Is there someway to appy a scaling to your extension rotation values beofre computing the acos.
-
RE: Compute Rotation and Scale from Transform Object
Wow, thanks TIG. That looks like a tremendously useful set of extensions you've cooked up there. I'll put them to good use.
-
Compute Rotation and Scale from Transform Object
Is there a simple Sketchup Ruby method which returns the x,y and z rotation in degrees about the world axis and the x,z, and z scale given a component transform object? I can't seem to find anything in the API for this and I would prefer to not have to dust off my old trig book.
-
RE: Material Attributes
@al hart said:
That will work in some cases, and is a clever solution.
One of the things we are trying to do is save multiple images with a material - e.g. a bump map and specular map - in addition to the diffuse map. First we have to convert the binary to ASCII because SketchUp does not handle binary attributes properly, then we run into the problem that SketchUp can only handle about one megabyte (I don't remember the exact limit) per attribute, so we split large images up into several attributes.
Al, are you implying that you've found a way for Sketchup materials to load with multiple attributes attached? If so, can you share the magic of this invention.
-
RE: Material Attributes
The problem/bug of saving multiple material attributes with a material is still there but I found a workaround. It seems that the saved .skm material file when loaded will only retain a single attribute parameter. So I packed all the material params into a single string using a single parameter and then saved the material. If I need to do anything with the material attributes, I unpack them into Sketchup attributes at run-time. Kind of a kludge, but it works.
-
RE: Material Window Context Menu
That's too bad. Thanks for the repsonse.
-
Material Window Context Menu
Can a Ruby context menu be attached to the Material Window?? It seems the only menu contexts that can be added are to selected entities in the scene. Someone prove me wrong.
-
RE: Reset All Face UV's in a selection
TT to the rescue again. Many thanks. I tried it the first way as well but found the send_action call didn't work either. Your second method works like a champ. You're a star.
-
Reset All Face UV's in a selection
Like the title says... is this possible? I don't see anything in the Ruby api that will reset UV's although there is the send_command 21516 Reset original texture position. But I don't see a select method that would allow me to select a face by cycling through a selection list. Hard to beleive that the standard Sketchup does not allow a Texture Reset Position from a section of faces instead of just a single face. Any ideas?
-
RE: Backface UVs - How?
@thomthom said:
what flags did you use when you obtained the PolygonMesh?
Face.mesh
http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/face.html#mesh@unknownuser said:
Add these numbers together to combine flags. A value of 5 will include all flags, for example.
This is wrong. 7 is the value if you want to include them all. It's a bitwise combination of the optional values.
Thanks for that. Indeed, I was using 5 instread of 7 as the mesh flag.
Thanks again
-
Backface UVs - How?
I see that there are some bugs in the api docs on mesh.uv_at. Can someone enlighten me on how to get the UV's of the back face? I know I can get the fronts with mesh.uv_at(3,1).x The first index is the point, the second index (1) should be the flag for front or back, yes? I've tried using true/false but no luck.
-
RE: Find the global position of a Vertex in a Group/Component
Interesting thread. I'm trying to do figure out how to apply transformations to SU mesh objects for exporting. The object.transform! method seems to only perform rotation and scaling but not translation (e.g. the delta movement along the x, y, and z axis). I see that the transform matrix does indeed contain the translation values in the last row (row 4) of the matrix. Why doesn't the transform! method also perform the translation? Is this a bug or a feature?
-
RE: [Bug]Win32api.so and Sketchup7
I found the problem.
getKeyState should start with a caps GetKeyState