PolygonMesh behavior
-
but this is about points "particular index in the mesh."
Or it is for each face? In this case I have to calculate each angle between vertexes of adjacent faces?
Anyway the vector that I get is 0,0,0, but the faces have smooting in SU.
http://sketchup.google.com/support/bin/answer.py?hl=it&answer=114941
the procedure is explained in the yellow window.. -
I think "particular index in the mesh." refer to the index of polygons.
@soldatino said:
Anyway the vector that I get is 0,0,0, but the faces have smooting in SU.
Normals in SketchUp does not relate the smoothing. Normals are always perpendicular to the face/polygon.
To find out of the mesh has smooth edges use
PolygonMesh.polygon_at
http://code.google.com/intl/it/apis/sketchup/docs/ourdoc/polygonmesh.html#polygon_at orPolygonMesh.polygons
http://code.google.com/intl/it/apis/sketchup/docs/ourdoc/polygonmesh.html#polygons -
yes, thanks, pointing at the face I get the float values of the vector.
Now if it is a offset valid for all the points of each face, I have to find the common points of adjacent faces, and interpolate their offsets to get the vector for the points. A lot of work... do yo think it is right? -
Think so - SU doesn't provide vertex normals.
When I wrote Vertex Tools I have to work them out manually from the connected faces. -
Look at a vertex.
Get its faces.
Get the normals of the faces [lets say there are 3 of them].
Combine the faces' normals [vectors] using v = v1 + v2 + v3
Now 'v' should be the combined-vector at that vertex [the vertex-normal?]...
Test it usingentities.add_line(vertex.position,v.to_a)
which should draw a line at the vertex along the direction of the combined-vector 'v'... -
thomthom, TIG, thanks. I will attempt to write this in Ruby, even if I dont know much of this language, to do it with a post editor would be very easy, storing the array of all the normals of every face as comments within the ouput of the points ...
note: Vertex.used_by? in a loop of all connected faces ? waiting for the eternity...
-
@soldatino said:
note: Vertex.used_by? in a loop of all connected faces ? waiting for the eternity...
-
@thomthom said:
@soldatino said:
note: Vertex.used_by? in a loop of all connected faces ? waiting for the eternity...
I am worried because I think that with large model the time required will be huge.
Addictionally I would not repeat the calculation for the same point when the loop scans the already involved faces, but if I do not want to repeat I have to save an array for all the entities, containing normals already calculated, and to scan it also, which could be worse... -
What are you doing? An exporter?
-
<span class="syntaxdefault"><br /> </span><span class="syntaxkeyword">for </span><span class="syntaxdefault">eachvrtx in 0.</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">numvrtx </span><span class="syntaxkeyword">do<br /> </span><span class="syntaxdefault">x </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">mesh</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">point_at</span><span class="syntaxkeyword">((</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">eachvrtx</span><span class="syntaxkeyword">]).</span><span class="syntaxdefault">abs</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">x</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">RatioPov<br /> y </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">mesh</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">point_at</span><span class="syntaxkeyword">((</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">eachvrtx</span><span class="syntaxkeyword">]).</span><span class="syntaxdefault">abs</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">y</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">RatioPov<br /> z </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">mesh</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">point_at</span><span class="syntaxkeyword">((</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">eachvrtx</span><span class="syntaxkeyword">]).</span><span class="syntaxdefault">abs</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">z</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">RatioPov<br /></span>
Change into this
<span class="syntaxdefault"><br /> </span><span class="syntaxkeyword">for </span><span class="syntaxdefault">eachvrtx in 0.</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">numvrtx </span><span class="syntaxkeyword">do<br /> </span><span class="syntaxdefault">pt </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">mesh</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">point_at</span><span class="syntaxkeyword">((</span><span class="syntaxdefault">vertices</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">eachvrtx</span><span class="syntaxkeyword">]).</span><span class="syntaxdefault">abs</span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault">x </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">x</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">RatioPov<br /> y </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">y</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">RatioPov<br /> z </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">pt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">z</span><span class="syntaxkeyword">*</span><span class="syntaxdefault">RatioPov<br /></span>
Should be a little bit faster.
-
This is a part of my exporter to POV-Ray. Yes, now I apply your suggestion !
-
17/11/2010 10:03:00
//Ending at 17/11/2010 10:03:1817/11/2010 10:09:00
//Ending at 17/11/2010 10:09:1828935 faces
Later I will check on largest files... -
@thomthom said:
Think so - SU doesn't provide vertex normals.
You are wrong Thomas!
Check this :
polygonmesh.normal_at(vertex_index)
Soldatino, your exporter will work faster now
I think that is what you have been looking for, unless you want to do vertex welding. -
@unknownuser said:
@thomthom said:
Think so - SU doesn't provide vertex normals.
You are wrong Thomas!
Check this :
polygonmesh.normal_at(vertex_index)
?
From the docs I see nothing that indicate vertex index. http://code.google.com/apis/sketchup/docs/ourdoc/polygonmesh.html#normal_at
Saying that - it doesn't even say if it's polygon index.Tomaz: you got a working example?
-
@thomthom said:
Toma**s**z: you got a working example?
Yep. SU2TH
You have to extract a triangle indexes using
tri_indexes=polygonmesh.polygon_at(mesh_index)
and then
normal0=tri.normal_at(tri_indexes[0]) normal1=tri.normal_at(tri_indexes[1]) normal2=tri.normal_at(tri_indexes[2])
The docs are .... terribly bad, you know that you can't rely on them
Now you know how to use it and speed-up your plugins.
EDITED. I was terribly wrong It is correct now.
-
I can't get it working...
-
Do not count_points, count_polygons instead.
1 .. mesh.count_polygons
then{ tri_indexes=mesh.polygon_at(i) (0..2).each{|q| p mesh.normal_at(tri_indexes[q])} }
EDIT.
usemesh 7
to ensure you get also normals. Doc doesn't say what is a default flag. -
But when you do
1 .. mesh.count_polygons
you iterate over the polygons. Andmesh.polygon_at(i)
returns an array of point (vertex) indexes - which are the same indexes you get when you iterate mesh.count_points...??
-
@unknownuser said:
EDIT.
usemesh 7
to ensure you get also normals. Doc doesn't say what is a default flag.Ah! Yes - of course. Now I get normals.
-
Correct. They are same indexes, but now they define a triangle. In exporter you usually export triangles not a cloud of points...
Have you used mesh(7)? Maybe this is why it returns Vector3d(0,0,0) instead of Vector3d(0,-1,0)?
Advertisement