Set camera, and move shape by end point
-
Hi there,
I am new to sketchup development.and I am developing a concept application, so during the development I will probably have several questions in the process of developing and learning.
Question 1
I managed to set the active_view to a custom camera.
using:Sketchup;;Camera.new eye, target, up
the question is it possible to change manipulate the camera without recreating the object for each change, for example: rotate the camera, or move the eye position.
Question 2
I got A fairly simple 3D shape - pyramid.top end point /\. /|_\`. /__|_\/`. /__|__|\/.`. b /_|__|__|\/`/`. c /|__|___|__\/`/ a /__|___|___|_\/ d
this shape got 5 end points, when 1 at top of the pyramid is connected with the rest (4).
what I want to do is first detect this end point, and then move the entire shape to different position [x,y,z]so thats mean I need a way to find a shape end points listed.
and then the proper way to move a shape to a new position, using the selected endpoint as the handle.thanks for your help, hope you can help me with my issues.
-
Set a variable that points at the camera
camera=Sketchup::Camera.new(eye, target, up)
then later use
camera.something=new_something
etc...
To 'move' an object the safest to make it inside a group so it doesn't stick/clash with other geometry.
Add the group to the model's active_entities, then add you geometry to that group.entities...
group=model.active_entities.add_group() group.entities.add_face(pt1,pt2,pt3)
then move the group...
Use a transformation on the group - a translation of one corner to a new point should do it...
tr=Geom::Transformation.translation(pt1.vector_to(another_point)) group.transform!(tr)
Nowpt1
is atanother_point
?
Hope this helps... -
@tig said:
Set a variable that points at the camera
Thanks TIG for you answer.
regarding the camera, by the documentation its appear that camera.target is a getter, and can not be used to set the target.
this apply both to up and eye.
correct me if I am wrong.yeah , a group is a good idea.
a question , what is pt1 , remember that I wish to move the entire shape by a selected endpoint (I got 5 to choose from) -
@lib said:
@tig said:
Set a variable that points at the camera
Thanks TIG for you answer.
regarding the camera, by the documentation its appear that camera.target is a getter, and can not be used to set the target.
this apply both to up and eye.
correct me if I am wrong.yeah , a group is a good idea.
a question , what is pt1 , remember that I wish to move the entire shape by a selected endpoint (I got 5 to choose from)
You are right some aspects of the camera are not 'settable' ! Sorry if I confused you.
If you want to change target/eye/up you need to create a new camera to match your requirements [you can 'clone' other aspects of another camera to that later ?]. Simply change the current view's camera to this new one ?'pt1' etc was just my shorthand for a variable that's a point e.g. earlier on you would have set it and the other points used to make the shapes you want
pt1=Geom::Point3d.new(0,0,1)
or
pt1=[0,0,1]
etc.
Then later you can refer to any of these points again to use them in moving the whole object [group], e.g. if you know which of the 'corners' pt1 is you can make a vector from it to whatever new location you want that corner to move to, then make a transformation using that vector as its argumenttr=Geom::Transformation.translation(pt1.vector_to(another_point))
then finallygroup.transform!(tr)
to relocate the group to this new point anchored by corner 'pt1' - or whatever point out of the set you might decide upon.............
You can also do rotation and scaling transformations - see the API notes... -
@tig said:
If you want to change target/eye/up you need to create a new camera to match your requirements.
I timed this for my movie. Took less than 1% of the available "fuss with the scene" time at 24 fps.
@tig said:
tr=Geom::Transformation.translation(pt1.vector_to(another_point))
then finallygroup.transform!(tr)
to relocate the group to this new point anchored by corner 'pt1'Way harder than using the API I introduce in Chapter 16.
movable = MovableCI.new( instance_you_want_to_move ) movable.move( point_or_vector )
Also includes rotate and scale methods, no transformations required.
The MovableCamera API also simplifies your life. If you're not doing animations, you can stop at mid-chapter. (You'll miss the final reprise of a character who was, in fact, modeled on TIG. You can scan for the fairytale colors to catch him near the end. He tells you why you might want to go back to the old, complicated way.)
-
thank you martin and TIG for you help
Martin I will have a look at the API you offer , I think it is going to help me in my project.
-
@lib said:
Martin I will have a look at the API you offer , I think it is going to help me in my project.
Do keep us posted!
Advertisement