nortikin / sverchok

Sverchok
http://nortikin.github.io/sverchok/
GNU General Public License v3.0
2.21k stars 234 forks source link

Rotate and Scale #354

Closed AgustinJB closed 9 years ago

AgustinJB commented 9 years ago

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

nortikin commented 9 years ago

nice. usefull, i think

nortikin commented 9 years ago

add mirroring!

AgustinJB commented 9 years ago

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

nortikin commented 9 years ago

in modifiers deform but first put to beta nodes

nortikin commented 9 years ago

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 commented 9 years ago

What is the meaning of vector2f or vector3f??

zeffii commented 9 years ago

3 component float

zeffii commented 9 years ago

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 commented 9 years ago

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

nortikin commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

for multicenter is crazy and not understandable scale2

i've got it! scale3

nortikin commented 9 years ago

Rotation is funny, indeed! rotate5 rotate4 rotate3 rotate2 rotate1

nortikin commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

@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 commented 9 years ago

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 commented 9 years ago

Euler rotations, yes

mifth commented 9 years ago

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

ly29 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

AgustinJB commented 9 years ago

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

nortikin commented 9 years ago

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 commented 9 years ago

@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 commented 9 years ago

@ly29 yes, triangle

AgustinJB commented 9 years ago

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!

mifth commented 9 years ago

@AgustinJB where i can test new euler Node?

AgustinJB commented 9 years ago

There is a branch named "Rotate&Scale": https://github.com/nortikin/sverchok/tree/Rotate%26Scale

There you have this 3 new nodes.

mifth commented 9 years ago

Ok, i tested. It rotates perfectly! But i have another issue: You did rotation of vertices. But what if i need to rotate Object? So that i could remove rotation or add another rotation? We need to rotate Matrix also. As in my example i rotate the Matrix: https://dl.dropboxusercontent.com/u/26887202/blender/Sverchok/test_rotation.blend

Is it possible to add Rotation of an Object Matrix too?

Here is my explanation of the issue: http://i.imgur.com/mcPC47Y.png

Thanks.

mifth commented 9 years ago

Possibly it should be another new RotateMatrix Node?

ly29 commented 9 years ago

I think a rotation node would be nice, with 3 different rotation input methods. I think we could add quarternion input and call it rotation modifier where you all different inputs are possible in one node. Also the same as a matrix creation node would be nice.

mifth commented 9 years ago

Yeah like this feature http://i.imgur.com/RepF8FI.png

AgustinJB commented 9 years ago

@ly29 you mean the three methods described here, right? http://wiki.blender.org/index.php/User:Pepribal/Ref/Appendices/Rotation

Now we have Euler and Axis Angle, and left the third. Combine them in one node with an EnumProperty to select?

ly29 commented 9 years ago

Exactly. For some hints to make the code simpler look at float range node. This will be a little bit messier than that but not much. If quarternions give you trouble do the first two and then we add the third mode. https://github.com/nortikin/sverchok/blob/master/nodes/number/range_float.py

AgustinJB commented 9 years ago

I'll give it a try and let's see how it goes!

mifth commented 9 years ago

Hello guys again.

I modified MatrixDeform Node and i did Rotate Matrix Node. Could you check it?

Video: http://youtu.be/kR_DMlUIaXQ The Node: https://dl.dropboxusercontent.com/u/26887202/blender/Sverchok/rotateMatrix.py

Just copy the script to "scripts/addons_contrib/sverchok-master/nodes/matrix/" folder and register it in init.py

Can i make pull request to add this node?

mifth commented 9 years ago

@AgustinJB I found some issues with your and my Rotate Nodes.

Your node: http://i.imgur.com/QnXwO4u.png - i tried to rotate 45 45 0 models have difference

And my matrix node has different angles too. But this is in DeformMatrixNode bug which i'll report soon.

ly29 commented 9 years ago

@mifth There some issues with your code. To create the matrix it would be better/simpler with the mathutils Euler.

>>> angles=(22,45,0)
>>> a_r = [radians(x) for x in angles]
>>> eul = Euler(a_r, 'XYZ')
>>> eul.to_matrix().to_4x4()
Matrix(((0.7071067690849304, 0.26488685607910156, 0.6556180119514465, 0.0),
        (0.0, 0.9271838665008545, -0.37460657954216003, 0.0),
        (-0.7071067690849304, 0.26488685607910156, 0.6556179523468018, 0.0),
        (0.0, 0.0, 0.0, 1.0)))

I made quick variant of my own euler

https://github.com/nortikin/sverchok/blob/Rotate%26Scale/nodes/matrix/euler.py

nortikin commented 9 years ago

@mifth make fork!!! i told you. it is not so hard

nortikin commented 9 years ago

@mifth and investigate how we making nodes. there needed vectorization.

AgustinJB commented 9 years ago

Ok guys, I've just commited the new node with three differents rotations. It need some cleaning and fixing, but I think it works properly.

Now I think euler and matrix rotation gives the same results.

AgustinJB commented 9 years ago

Ok, no, some problems persists. Some combination of axis rotation give little different results. I'll investigate it.

mifth commented 9 years ago

@ly29 your Euler Node is great! It fixes all issues! Must be put in Sverchok! :) Thank you. You vector math is great.

@AgustinJB let me know if you need some new testing.

@nortikin Thanks. I'll make new for when will do something new.

Guys I love you. These nodes are really great!

AgustinJB commented 9 years ago

@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 commented 9 years ago

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 commented 9 years ago

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

nortikin commented 9 years ago

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

mifth commented 9 years ago

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 https://github.com/nortikin/sverchok/issues/354#issuecomment-50227220.