First of all, you should not change Core Ruby classes or API classes as this will cause havoc for other extensions.
In Ruby there are refinements that allow a single file or class to change Ruby classes so only the file using the refinement can see the changes. File: refinements.rdoc [Ruby 2.7.1]
But Ruby is actually implemented in C. And there are ways to call Ruby methods from C/C++.
But I’m not quite sure how Ruby refinements would be done from C.
You should probably read this …
It is a bit old and predates Ruby refinements, but will allow you to understand how to use Ruby from the C side.
As Dan says the Ruby API methods are implented using the Ruby C API, and are closed source. You can’t read these methods and base your own on their code.
What you can do is to check if the changes you want to InputPoint#pick is logged in our Ruby API Issue Tracker, or otherwise add it.
Refinement seems to be the way. But can it be inherited to others? That is I refine InputPoint, but all the other plugins or even native SU tool will also respond to my refinement?
NO. That is the purpose of a Ruby refinement. A Ruby class (or file) must specifically use the refinement.
The whole point is that it will not be “used” by the SketchUp core C code (native tools) or by other Ruby extensions.
And again, native SketchUp tools can not be modified by the APIs. But some of these tools can be “watched” by observers and respond to their actions.
Usually extension authors must result in coding their own Ruby tools if they need custom behaviors.
Well, Trimble itself can create “secret hooks” because they have access to the C++ core of SketchUp’s code. We “lowly” API developers do not have access to these “secrets”.
Also, I had asked in that topic if you could post a model with a small point cloud created using that extension. Then I could look at the cloud objects. (I do have the Scan extension nor a laser scanner myself.)
I don’t know what use you could make of OpenGL objects rather than their SketchUp source entities. But nonetheless, the SketchUp API does not provide any way to access OpenGL data directly. You can generate OpenGL objects within a Tool’s draw method, but it is one-way; you don’t get a reference to them and there is method to request one. I’d be leery of hacking around this because there is a risk you could completely disrupt SketchUp’s heavy entanglement with OpenGL.
I would challenge “many”. But regardless of that, what makes you believe either of those extensions directly reads OpenGL data? Don’t they add geometry to a SketchUp model’s contents, which is then displayed in the view? I don’t see the point of “importing” point cloud data if all that results is a visual, not geometry, since there would be no resulting model in SketchUp.
I have upload a video to demonstrate this from my development. InputPoint can not do this, but only my own Tool can. However, Trimble Scan Essentials does not do this way. It affect all tools using InputPoint.
Maybe I misunderstood the task, but at least just for fun, I did a test … how do I imagine snapping on opengl points: (I have no idea influencing the performance…)
class Tool_test_snapto_gl_points
###dirty!!###
def initialize
p_cloud = spiral_sphere( 1000 )
@segments = p_cloud.map{|p| p.transform!( Geom::Transformation.scaling(10) ) }
end
def onMouseMove(flags, x, y, view)
ph = view.pick_helper
ph.init(x, y, 10)
@picked = ph.pick_segment(@segments)
if( @picked && @picked >= 0 )
@point_to_draw = @segments[@picked]
end
view.invalidate
end
def draw(view)
view.tooltip = @picked.to_s if( @picked && @picked >= 0 )
view.draw_points( @segments, 5, 2, "peru" ) if @segments
view.line_width = 2
view.draw_points( @point_to_draw, 15, 4, "green" ) if @point_to_draw
end
#-----------------------------------------------------------------------------
# Borrowed from:
# Thomas Thomassen
# thomas[at]thomthom[dot]net
# TT_Lib2
def spiral_sphere( number_of_points, origin=ORIGIN )
t = Geom::Transformation.new( origin )
n = number_of_points
node = Array.new( n )
dlong = Math::PI * (3-Math.sqrt(5))
dz = 2.0/n
long = 0
z = 1 - dz/2
(0...n).each { |k|
r = Math.sqrt( 1-z*z )
pt = Geom::Point3d.new( Math.cos(long)*r, Math.sin(long)*r, z )
node[k] = pt.transform( t )
z = z - dz
long = long + dlong
}
node
end
# Thanks
#-----------------------------------------------------------------------------
end
Sketchup.active_model.select_tool(Tool_test_snapto_gl_points.new)
Your example is interesting, but it does not actually snap to OpenGL objects.
Your code just happens to draw OpenGL “peru” colored squares at the same locations as the Geom::Point3d points in a “virtual” curve vertex array, which is what PickHelper is snapping to. (Ie, virtual in that an actual curve object does not exist. This is what I find most interesting about the example.)
The point of this topic and the related topic is that the OP (is saying) he does not have access to “read” the point positions of the “special” point clouds created by the Trimble Scan Essentials extension. In that topic, Christina said …