Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotate and Scale #354

Closed
AgustinJB opened this issue Jul 24, 2014 · 74 comments
Closed

Rotate and Scale #354

AgustinJB opened this issue Jul 24, 2014 · 74 comments

Comments

@AgustinJB
Copy link
Collaborator

Hi guys!

I know that matrix is a very powerful tool, but sometimes it's kind of difficult to use and understand. Thinking in that, I've made two nodes for general rotation and scaling in space. Both based on a center point, and rotation also in an arbitrary direction.

I've made a new branch so you can test it and tell me what you think.
nodes
rotate

@AgustinJB AgustinJB added the beta label Jul 24, 2014
@nortikin
Copy link
Owner

nice. usefull, i think

@nortikin
Copy link
Owner

add mirroring!

@AgustinJB
Copy link
Collaborator Author

Yeah! That is the next in what I was thinking!

@nortikin
Copy link
Owner

in modifiers deform
but first put to beta nodes

@nortikin
Copy link
Owner

do we need Vector2f Vector3f Vector4f? And what the hell is Vector4f?
specially i don't think we need that, but one man asked

@AgustinJB
Copy link
Collaborator Author

What is the meaning of vector2f or vector3f??

@zeffii
Copy link
Collaborator

zeffii commented Jul 24, 2014

3 component float

@zeffii
Copy link
Collaborator

zeffii commented Jul 24, 2014

it's openGL notation, if i'm not mistaken. in openGL you could also have Vector3i which is 3 integers (for RGB) or 4 for RGBA . etc

@AgustinJB
Copy link
Collaborator Author

Oh, I understand now. GH has nodes to do that, define colours in RGBA or HSV.

@nortikin
Copy link
Owner

we not need to define colors with alpha for now.. not see why we need in future. And 4D vector as quaternion i not see now usage. it is for rotation, but why we need it? i don't think we need quaternion. what you think?

@nortikin
Copy link
Owner

this is scale. And i have question. what is better - to vectorize scale as multyextrusion or vectorize that way: every Factor value affects on every vertex? and what if for every vertex exists own center? for now i see case of multiextrude

scale

scale1

@nortikin
Copy link
Owner

for multicenter is crazy and not understandable
scale2

i've got it!
scale3

@nortikin
Copy link
Owner

Rotation is funny, indeed!
rotate5
rotate4
rotate3
rotate2
rotate1

@nortikin
Copy link
Owner

but regime with corresponding rotation will be good - i.e. i writed first - when one center fits one vertex and one factor to one vertex, so we may have two regimes - two buttons as in UVconnection node!!!
i love simple and powerfull tools

@ly29
Copy link
Collaborator

ly29 commented Jul 25, 2014

I think it a useful feature, also I wish we had per vertices matrix operations and per object so one could multiply many objects in the same list. Oh well.

The rotation model you are using is called Axis, Angle in blender, I think it is good idea to use the same naming scheme.

And has ready made matrix constructor in mathutils, Matrix.Rotation why not just use that?
You code becomes something like.

    def rotation(self, vertex, center, axis, angle):
        mat = Matrix.Rotation(radians(angle), 4,  axis)
        c = Vector(center)
        pt = Vector(vertex)
        return c + mat ( pt - c)

Instead of 51 lines (with comments and white space also.) On the other hand it is nifty to make it all into one matrix.

http://www.blender.org/documentation/blender_python_api_2_70a_release/mathutils.html?highlight=matrix.r#mathutils.Matrix.Rotation

For new code I think we should all follow pep8 naming conventions.

@ly29
Copy link
Collaborator

ly29 commented Jul 25, 2014

The whole vertex2,3,4f thing. All our vectors/points are implicitly vertex4f when it comes to matrix multiplication. Sometimes it would be nice with 2d vectors I find myself thinking but not for so long.

Also a Euler input mode and for completeness a Quarternion input would be nice I guess, to support the other rotations modes of blender. (We should also allow the creation of rotation matrices based on euler and quarternions)

For me axis angle makes the most sense but for others Euler seems to be the way they think.

@AgustinJB
Copy link
Collaborator Author

@ly29 I just don't know yet blender inside that well, but I do know maths and geometry, so I did in that way. And doing it was so funny!! :)
But yes, you are right, in terms of coding, using Matrix.Rotation has a lot of more sense. I'll look into it and change it.
I will also study pep8 conventions!

@mifth
Copy link
Collaborator

mifth commented Jul 25, 2014

Hi guys.

Is it possible to add a simple Rotation Node? For example i want to rotate an object to:
x = 20 degrees
y = 30 degrees
z = 15 degrees

As a common rotation in blender for all objects.
I did the rotation setup. But it has about 15 nodes. It would be cool to have only one Node to set rotation axeses XYZ.

Here is my setup: https://dl.dropboxusercontent.com/u/26887202/blender/Sverchok/test_rotation.blend
Here is the video how to use: http://youtu.be/-bpo9CrkZdA

And here how this Rotation Node should be: http://i.imgur.com/RepF8FI.png

@ly29
Copy link
Collaborator

ly29 commented Jul 25, 2014

Euler rotations, yes

@mifth
Copy link
Collaborator

mifth commented Jul 25, 2014

If someone will add it as a one node. It would be super cool. Yes, Euler rotations. :)

@ly29
Copy link
Collaborator

ly29 commented Jul 25, 2014

The rotate node as you suggest shouldn't be like that I think, that would be the matrix multiplication node (also todo), before that the should be a node creating a Euler Matrix, in any order of [‘XYZ’, ‘XZY’, ‘YXZ’, ‘YZX’, ‘ZXY’, ‘ZYX’] , either from vector input or as separate x,y,z.
Also normalizing the rotation axis isn't needed, furthermore in you example file they are already normalized.

@mifth
Copy link
Collaborator

mifth commented Jul 25, 2014

Yes matrix multiplication is ok too. I hope you guys will be able to add such a node. As at present it's a big pain to rotate objects.
Also, we need to add Vector4 object. To make manipulations with quaternons. I think.

@zeffii
Copy link
Collaborator

zeffii commented Jul 25, 2014

Vector4f is also used for Inlfuence / Weight of spline knots and controls

@AgustinJB
Copy link
Collaborator Author

I've simplified both. I can now look into euler rotation in nobady else is alredy doing it.

@nortikin
Copy link
Owner

couple of things to remind concerning to rotations. in polygons centers there is problem with defining rotation. if @mifth can look at this node and code - some Y polygons are wrong rotated there.

and second is defining matrix from three points (not existing yet node), it is the same task as centers of polygons, but with some difference in code... what you say, could you handle this, @mifth ?

@ly29
Copy link
Collaborator

ly29 commented Jul 25, 2014

@nortikin
For centers polygon we have to apply an additional criteria to assign the rotation.
The matrix from 3 points, is that as if they where a triangle defining a plane with the normal up as up? If not please explain.

@AgustinJB
Go for the eulers!

@nortikin
Copy link
Owner

@ly29 yes, triangle

@AgustinJB
Copy link
Collaborator Author

Ok, I think we have an euler rotation node ready! :)
I've been trying and it seems to work properly. You'll tell me if it's fine.

PS: what a wonderfull world is Blender Documentation!

@AgustinJB
Copy link
Collaborator Author

@mifth can you test it now??

The problem wasn't about the code. The different results were about the gimbal order, so I've added a enum to select that order.

I think now is pretty done. Maybe some simplification in inputs/outputs could be done, but I think that's all.

Enjoy! :)

@ly29
Copy link
Collaborator

ly29 commented Jul 26, 2014

screenshot from 2014-07-26 10 15 37
Some what inconsistent and Quaternion is a variant of Euler implemented using Quaternions, not true quaternion input. Also it uses matrix instead of vertices?
Compare to the n-panel in 3d view panel.
quat

Also I noted that 3-d view doesn't reorder the inputs like my node does, opinions on that?

@AgustinJB
Copy link
Collaborator Author

Ohh......I've kind of misunderstood about quaternation...let me see that again to see if I can fix it

@nortikin
Copy link
Owner

i think, quaternion convinient for operating rotation inside code, not in user interface. am i right?

@mifth
Copy link
Collaborator

mifth commented Jul 26, 2014

It‘s good that it uses matrix. I mean second node on the screenshot. It can
make additive rotation to matrix.
26.07.2014 12:21 пользователь "ly29" notifications@github.com написал:

[image: screenshot from 2014-07-26 10 15 37]
https://cloud.githubusercontent.com/assets/6241382/3710621/11cfd6f6-149d-11e4-8d3c-8eb4a2661ff8.png
Some what inconsistent and Quaternion is a variant of Euler implemented
using Quaternions, not true quaternion input. Also it uses matrix instead
of vertices?
Compare to the n-panel in 3d view panel.
[image: quat]
https://cloud.githubusercontent.com/assets/6241382/3710625/b1d7d11c-149d-11e4-942e-bf349f811238.png

Also I noted that 3-d view doesn't reorder the inputs like my node does,
opinions on that?


Reply to this email directly or view it on GitHub
#354 (comment).

@AgustinJB
Copy link
Collaborator Author

Ok, now I think it works just like in 3d view:
quat

It's kind of tricky to understand quaternions...

@ly29 I don't understand what you mean about the reorder of the inputs.

@mifth
Copy link
Collaborator

mifth commented Jul 26, 2014

@AgustinJB sorry for late responce. I tested. It seems Rotation Node works ok now.

@AgustinJB
Copy link
Collaborator Author

I'm glad to hear @mifth. I'll test it some more before pushing to master.

In the meanwhile I'm trying with mirror node:
mirror
Does someone know if I can use enumproperty and select various options at the same time? Or I have to use boolproperty for doing that?

@zeffii
Copy link
Collaborator

zeffii commented Jul 26, 2014

@AgustinJB have a look at index visualizer (viewer_indices.py)

@AgustinJB
Copy link
Collaborator Author

Thank you for the tip @zeffii!!

I've added mirror node:
mirror

It's in early stages, but it works pretty well. Maybe I should add edge and poly inputs/outputs, and maybe study clipping and merging options.

I've been looking at the source code of mirror modifier, but right now it's hard to understand to me, so I'm not sure if it could be usefull to the rest of the options.

@nortikin
Copy link
Owner

@AgustinJB will there be mirror from plane/point? because there are three type of mirror:

  1. around point - center_of_mirroring-delta(vector1, center_of_mirroring)
  2. around axis - this is kind of rotation, but like this http://www.mathsisfun.com/geometry/reflection.html only in 3d
  3. around plane, this means what you have done, but plane - is matrix or if you'd like, in matrix socket could be inserted center and vector from center... so you can define plane

@mifth
Copy link
Collaborator

mifth commented Jul 27, 2014

Also, if set scaleX = -1.0 to Matrix.... possibly it will be like a mirror?

@nortikin
Copy link
Owner

@mifth it is if you scale around local zero, but if you need define some other center point?

@mifth
Copy link
Collaborator

mifth commented Jul 27, 2014

then i dunno know :(

@AgustinJB
Copy link
Collaborator Author

@nortikin I'll look into that mirrors modes tomorrow. I also want to get clipping working.

@AgustinJB
Copy link
Collaborator Author

I've added clipping option. It need some fixing for multiple center inputs, but it works pretty well I think.

Do you think edge/polys inputs/outputs should be added?? Right now it's needed just a list repeater.

@nortikin
Copy link
Owner

no need to add edges and polygons, but only for flipping normal (reverse plygons indexes)

@AgustinJB
Copy link
Collaborator Author

@nortikin I've been looking into those others symmetry methods. Are they the ones described in this web: http://www.mathsisfun.com/geometry/symmetry.html

Because I think the last two can be made with rotation Axis/Angle, which is in rotation node.
captura de pantalla de 2014-07-30 11 10 50

Maybe I can add the option to input a matrix to define an arbitrary plane of mirroring?

@nortikin
Copy link
Owner

@AgustinJB
you have to understand that 2d is not 3d
https://drive.google.com/file/d/0B6KMvjWAjGiyb1k2NHVXMnJPajg/edit?usp=sharing
here is explanation. as i can drew.

@nortikin
Copy link
Owner

sorry, just
mirroring blend
uploaded new file the same link. mirror over point fixed

@AgustinJB
Copy link
Collaborator Author

Uhmm, right, I see. Yep, I'll do that!

@nortikin
Copy link
Owner

1,2,3 points. depending on how many points it builds mirror. Or if matrix inserted in the same socket, it should consider it as plane, as three points. it is my proposal, but you make as you see

@nortikin
Copy link
Owner

total - two sockets - one for vertices, one for point/line/plane/matrix
or three - for polygons to make them reverse slice polygon[::-1]

@AgustinJB
Copy link
Collaborator Author

Ok, I got the three methods now:

mirror_vertex
mirror_axis
mirror_plane

It needs some testing, but my first tests were ok. I'm not sure if clipping has sense now.

@nortikin
Copy link
Owner

WOW!!!!!! will test

@nortikin
Copy link
Owner

Traceback (most recent call last):
  File "/home/nikitron/.config/blender/2.71/scripts/addons/sverchok-master/nodes/basic_view/viewer.py", line 217, in update
    cache_viewer_baker[n_id+'m'] = dataCorrect(propm)
  File "/home/nikitron/.config/blender/2.71/scripts/addons/sverchok-master/data_structure.py", line 288, in dataCorrect
    if dept < 2:
TypeError: unorderable types: NoneType() < int()

when matrix not connected
Everything works well

@AgustinJB
Copy link
Collaborator Author

Oh, right, I forgot to add a default matrix. I'll add it later.

@AgustinJB
Copy link
Collaborator Author

I've been testing all the new nodes again and they seem to work properly. If you are ok, I will merge this branch with master, leaving new nodes in beta tab.

@nortikin
Copy link
Owner

nortikin commented Aug 1, 2014

yes

@zeffii zeffii closed this as completed Aug 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants