@unknownuser said:
camera.set takes 3 arguments: the eye (Point3d), the target (Point3d) and the up direction (Vector3d).
camera.set(eye, target, up)
Thats just it.
How do I set the camera.direction?
@unknownuser said:
camera.set takes 3 arguments: the eye (Point3d), the target (Point3d) and the up direction (Vector3d).
camera.set(eye, target, up)
Thats just it.
How do I set the camera.direction?
Here is some testcode I use.
I get: <ArgumentError: Eye, Target and Up are required> when using camera.set direction
I also tried with: direction.set!(@rx, @ry, @rz); but nothing...
# Testing code
# Name; jsCameraTool
# Author; Jan Sandstrom www.pixero.com
# Description; Position and rotate the camera numericly.
require 'sketchup.rb'
def jsCameraTool
model = Sketchup.active_model
view = model.active_view
camera = view.camera
eye = camera.eye
direction = camera.direction
target = camera.target
up = camera.up
length = camera.focal_length
fov = camera.fov
### Dialog
@px = eye.x
@py = eye.y
@pz = eye.z
@rx = direction.x
@ry = direction.y
@rz = direction.z
#@tx = target.x
#@ty = target.y
#@tz = target.z
prompts = ["Position X", "Position Y", "Position Z", "Rotation X", "Rotation Y", "Rotation Z"]
values = [@px, @py, @pz, @rx, @ry, @rz]
results = inputbox(prompts, values, "JS CameraTool")
px, py, pz, rx, ry, rz = results
@px, @py, @pz, @rx, @ry, @rz = px, py, pz, rx, ry, rz
# New position
camera.eye.x = @px;
camera.eye.y = @py;
camera.eye.z = @pz;
camera.direction.x = @rx;
camera.direction.y = @ry;
camera.direction.z = @rz;
#target.x = @tx;
#target.y = @ty;
#target.z = @tz;
#up.set!(0.0, 0.0, 1.0);
#camera.set eye, target, up;
camera.set direction;
end # end of jsCameraTool
if( not file_loaded?("jsCameraTool.rb") )
UI.menu("Plugins").add_item("JS CameraTool") { jsCameraTool }
end
I tried that and also "camera.set eye, target, up" but can't get camera to rotate.
What's the right syntax? Is there a "camera.set eye, direction, up" ?
How does the look around tool work in ruby?
The rotate view rotates around a target point
but the look around tool rotates around the position of the "camera".
How is that done in ruby?
Hmmm... there seem to be a problem. Now it doesnt work the way it did when I tested it.
I'll try it more at work tomorrow.
For now you can use the other script, jsShadowControl, to turn shadow casting and shadow receiving on or off. Even for non transparent objects.
You have misunderstod its purpose.
It's for setting objects with transparency to cast shadows or not.
The only way to get SketchUp to cast shadows matching a texture with alpha channel would be to "cut it out" in the shape of the image.
I got inspired to try this and after some help I got it working.
I ended up writing two scripts:
JS Shadow Threshold
Set the threshold for when a transparent object will cast shadows.
Works on either entire model or a selection.
JS Shadow Control
Set if a selection should cast or receive shadows.
Get them at my site: http://www.pixero.com
Enjoy!
Jan
Has anyone worked with Ruby and Open GL?
Is it possible to access Open GL in SketchUp with ruby in a more advanced way than just:
GL_LINES, GL_LINE_LOOP, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, GL_POLYGON ?
I've found some links about Ruby and Open GL but would it be possible to use in SketchUp?
For example:
http://snippets.dzone.com/posts/show/1874
http://www.ruby-forum.com/topic/119704
Got it working! Thanks for the help. Read more here:
http://www.sketchucation.com/scf/viewtopic.php?f=9&t=1986
Thanks that did it!
Now if only I can get it to work with grouped objects...
Ok, progressing veeery slowly....
When I assign a material to the faces I now get this:
e.cast_shadows= false #Error; #<NoMethodError; undefined method `cast_shadows=' for #<Sketchup;;Face;0x7532bb0>>
If I remove the e in front of cast_shadows I don't get the error but nothing happens.
Sigh...
Thanks, but now another error has occured.
For the following line:
alpha = e.material.alpha #Error; #<NoMethodError; undefined method `alpha' for nil;NilClass>
Sorry if it's elementary but I can't seem to get it right.
Thanks in advance.
/Jan
I got inspired by a thread here about shadow threshold and thought I'd try it, but I get an error: #<ArgumentError: comparison of Float with Array failed>
What am I doing wrong?
# Name ; JS Shadow Threshold
# Description ; Sets cast shadow with a threshold
# Author ; Jan Sandstrom (http://www.pixero.com)
# Date ; 12 Aug 2007
require 'sketchup.rb'
def jsShadowThreshold
model = Sketchup.active_model
entities = model.active_entities
ss = model.selection
if ss.empty?
UI.messagebox("Nothing selected!")
return nil
end
# Dialog
@thresh = 0.7 if not @thresh
prompts = ["Shadow threshold; "]
values = [@thresh]
results = inputbox(prompts, values, "Shadow threshold")
thresh = results
@thresh = thresh
ss.each {|e|
next if not (e.is_a? Sketchup;;Face) #Ignore items in the selection that are not faces.
alpha = e.material.alpha
if (alpha < thresh) #Error; #<ArgumentError; comparison of Float with Array failed>
e.cast_shadows= false
else
e.cast_shadows= true
end #if
} #end of ss.each
end #jsShadowThreshold
if( not file_loaded?("jsShadowThreshold.rb") )
UI.menu("Plugins").add_separator
UI.menu("Plugins").add_item("JS Shadow Threshold") { jsShadowThreshold }
end
file_loaded("jsShadowThreshold.rb")
Again, thanks.
The only one missing is the Alt key.
YES! That worked!!!!
Thanks a lot.
As a side note. Do you have the keycodes for Mac?
On my laptop (Windows) the keycodes are:
up = 38
left = 37
right = 39
down = 40
alt = 18
shift = 16
ctrl = 17
Thanks for your help, but it still won't work for me.
Here is what I've done (a bit shorter than the real code):
def onKeyDown(key, repeat, flags, view)
if (flags == 32 && key == 38) # Alt + Up
dist = Geom;;Point3d.new [0, 0, 100];
end #if
# Now move it
tr = Geom;;Transformation.new (dist);
Sketchup.active_model.entities.transform_entities(tr, e);
end # onKeyDown
How do I use a sequence of keys in ruby?
I've tried with:
if (key == 18 && key == 38) # Alt and Up Arrow
and:
if (ALT_MODIFIER_KEY && key == 38)
and:
if (key == ALT_MODIFIER_KEY && key == 38)