I planned writing new method in C and calling it via Win32api... but I never find time and enough determination to do it. I wish somebody else did it instead , someone who knows C, unlike me.
Posts
-
RE: [Info] Ambient Occlusion -> Simple Rays
-
RE: [Question] Is it possible to set the face.normal?
One-click windows installer has it. Here: http://rubyinstaller.org/
-
RE: [Question] Is it possible to set the face.normal?
I suppose so, try it on Mac.
Below is not however, only Windows. This seems to freeze SketchUp OpenGL.
FindWindow = Win32API.new("user32.dll", "FindWindow", ['P','P'], 'N') GetDC = Win32API.new("user32.dll", "GetDC", ['N'], 'N') GetCurrentContext = Win32API.new("opengl32.dll", "wglGetCurrentContext", ['V'], 'N') CreateContext = Win32API.new("opengl32.dll", "wglCreateContext", ['N'], 'N') MakeCurrent = Win32API.new("opengl32.dll", "wglMakeCurrent", ['N','N'], 'V') DeleteContext = Win32API.new("opengl32.dll", "wglDeleteContext", ['N'], 'V') hwnd = FindWindow.call(0, "Untitled - SketchUp") hdc = GetDC.call(hwnd) hglrc = GetCurrentContext.call() DeleteContext.call(hglrc)
I wonder if this is good direction?
-
RE: [Question] Is it possible to set the face.normal?
@pixero said:
SU keep asking for glut32.dll. It's not in the zip you provided?
It didn't ask me. Maybe because I have it in my Ruby installation.
-
RE: [Plugin] Finite Element Analysis (FEA) - Spring-mass model
I wonder. Maybe instead of going math intensive subdivide a model into an array of virtual springs. Transforming them should be faster than the actual model. What do you think?
-
RE: [Question] Is it possible to set the face.normal?
Yes you can!
I've just found the first thing that changed the view of the model.
I typed in the Ruby consoleglDisable(GL_DEPTH_TEST)
.
To see result try turning the model around.
Bear in mind that I'm just starting to learn OpenGL .ps. You need to run SU with the files from the zip above in Plugins, except the example.
-
RE: [Question] Is it possible to set the face.normal?
These are the libraries included in Ruby Windows installer:
http://ruby-opengl.rubyforge.org/. -
RE: [Info] Ambient Occlusion -> Simple Rays
Yeah, but how would the method know if the first hit is the closest?
It could be for example some distant face that got hit first, because it was first in the collection. -
[Plugin] Finite Element Analysis (FEA) - Spring-mass model
Since I'm an architect I've been looking for an easy way to incorporate FEA into SU. This would add a completely new dimension to design in SU.
After browsing through some books I found the math a bit to hard so I decided to start off with a simple spring-mass model (to be exact it's not 100% real, instead of a=F/m, s~F/m)
simple_springs.rb
Here is a video example:
[flash=425,344:13mjw25i]http://www.youtube.com/v/ojtHu1yZSUQ&hl=pl_PL&fs=1&rel=0[/flash:13mjw25i]I hope someone with strong mathematical background would take this on or help me to go on.
What about SketchyPhysics? I tried it couple of times but I'm not sure it's suitable for this purpose.Kuba
-
RE: [Question] Is it possible to set the face.normal?
So far I managed to run the example above. Give me some time
-
RE: [Info] Ambient Occlusion -> Simple Rays
But then how would it find out the closest intersection?
ps. I write all this out of my head, I'm not familiar with 3d algorithms.
-
RE: [Info] Ambient Occlusion -> Simple Rays
@thomthom said:
You can use
face.plane
insteadSomehow I didn't notice that one in the API
@thomthom said:
hmm... If you only iterate the entities collection once then it won't help to pre-process to filter out only faces. Infact, that would mean more iterations. But if you need to iterate the face multiple times, then you will save time on pre-filtering.
I meant to sort the collection before proceeding to the next testing point. The faces that got hit before might as well be the first to get hit by rays cast from adjacent point.
@thomthom said:
@qpik said:
I thought exactly the same, as it returns "the first thing that the ray hits". I suppose it means "the closest thing". For my purpose it's enough to get first-on-the-list hit end exit.
Isn't that the same thing?
I suppose
model.raytest
doesn't break after first positive ray hit, but returns the closest one from an array of all.@thomthom said:
@qpik said:
I quickly wrote this, but it worked MUCH slower than original method.
You're writing a ruby method to be faster than a C method - that C method must be doing a lot of extra processing in order to be able to out-perform it in Ruby.
That is certainly true. That is why I managed to connect with a DLL using
Win32api.call
(BTW thanks to TBD for his SUDLL example).
Now I'm on my way to moving everything to C. I hope this will finally give a speed boost.I'm looking into Ruby-OpenGL as well for another approach.
Here is an example - http://forums.sketchucation.com/viewtopic.php?f=180&t=20893&p=209966#p209966 -
RE: [Question] Is it possible to set the face.normal?
During my research for improving raytesting plugin for SU
(http://forums.sketchucation.com/viewtopic.php?f=323&t=21077&st=0&sk=t&sd=a)
I've found out that Ruby supports OpenGL.I mixed an example and library from Ruby installation.
You can run this example in SU (unzip 4 files to Plugins folder).
-
RE: [Info] Ambient Occlusion -> Simple Rays
I quickly wrote this, but it worked MUCH slower than original method.
def raytest2 ray hit = false entities = self.entities entities.each { |face| if face.kind_of?(Sketchup;;Face) and face.classify_point(ray[0]) > 4 plane = [face.vertices[0].position, face.normal] intersection = Geom.intersect_line_plane(ray, plane) if intersection and face.classify_point(intersection) < 8 hit = true break end end } return hit end
This could be optimized by passing pre-sorted face array (based on results from previous tests) instead of browsing entities array, but I doubt it would speed it up much.
What do you think? -
RE: [Info] Ambient Occlusion -> Simple Rays
@wacov said:
I guess I don't know what I'm talking about, but doesn't SU's raytest method extract more information than you need for your plugin? Maybe that's why it's so (comparatively) slow.
I thought exactly the same, as it returns "the first thing that the ray hits". I suppose it means "the closest thing". For my purpose it's enough to get first-on-the-list hit end exit.
That might do the trick. -
RE: [Info] Ambient Occlusion -> Simple Rays
But I would have to export geometry for that one external routine.
Is there other way?@thomthom said:
What I meant was that the
.raytest
is probably written in C already.I've got that, I just wonder what makes it slow then and how to write a faster one.
I guess I have to prepare myself for switching to C. Even for my simple use, which is lately sunlight exposure analysis, it's simply too slow, when run on part of the city centre model.
Kuba
ps. Many thanks for all the help so far.
-
RE: [Info] Ambient Occlusion -> Simple Rays
Does that mean that
model.raytest
algorithm is inherently slow?
So I would need to write my own in C. -
RE: [Info] Ambient Occlusion -> Simple Rays
Does anyone know if there is a way of creating a faster replacement for
model.raytest
method?
I've found a Ruby PNG library. That's a step towards layering textures in Sketchup (using PNG alpha).
Kuba
ps. Would anybody like to cooperate on this plugin?
-
RE: [Info] Ambient Occlusion -> Simple Rays
Hello there.
Since I need to calculate sun exposure time in my current project I've added this functionality to the plugin. Here you can see an example. Yellow corresponds to 10h exposure, blue is no exposure.
It is based on peculiar polish building code (which requires an apartment to have at least 3 hours of direct sunlight on vernal equinox between 7am and 5pm) making this version useful in Poland. It can be easily adjusted though to fit any location and sun position.ps. My previous question is still actual - Would doing the raytest in Javascript via Webdialog be faster than Ruby?
-
RE: [Info] Ambient Occlusion -> Simple Rays
How about doing the raytest in Javascript via Webdialog?
Would that be faster than Ruby?Kuba