When we have a mirror in a scene, we are very annoyed each time the camera is moved (or if we move the plan of the mirror itself) because point by which the texture is calculated must be rebuilt too. And this texture can't be used in an animation.
It is not especially difficult if we use a plan parallel with a plan of the trihedron, that becomes unpleasing when this plan was rotated on three various angles (see the method suggested in these pages .)
It would not be marvellous that Blender automatically readjusts this texture according to the modifications of positionnemement and orientations of empty which controls the texture? Alas that is not yet possible, but we can write a script python which will do it in its place.
The objective of
this tutoriel is to have script and how to make use
of it Then to detail different the elements necessary to the realization
and the correct operation from this script, i.e.:
The explanations which follow take the version 1.80a in example because it is the surest version and that which holds less surprises when with the nondesired results. Indeed the verison 2.12 functions but adds additional nodes in the mesh Plan. Experiment to try to include/understand the problem: edition of the plan touches, selection of all the nodes with the key has and their displacement with the key G What has the long one can be génant even dangeureux for the stability of the software.
Script is autonomous and functions without any additional importation, even not the module math If one wishes to adapt it to a personal realization it is enough to control the three principal objects which are:
The ' Mirror' is simply the plan on which
all must be reflected.
It is the point which
is contrary to the plan on an axis perpendicular to this plan and at a
distance identical to that which separates the plan from the camera. In
script, it is defined by the EmptyObCibleName variable The variable
which indicates the name of the mirror plan is PlaneObName The camera
is quite simply CameraName These variables must be documented with
the names of the objects corresponding in the scene under development.
If one of them is not correctly identified then script does not function
and returns an error in the console.
In the script which is proposed in accompaniment these results were transformed into a very short function:
and U, v, W and H were replaced by nx, ny, nz and K
plan, ny, nz would
correspond to the normal vector of the plan, knowing that, it would be
enough to substitute any point of the plan to obtain K In fact the
API Python of blender makes it possible to recover the normal vector associated
with any node. But that would not be used for nothing because the vector
in question would be calculated in the local reference mark of the plan
itself and not the reference mark of the total space of blender where the
camera is located.
On the other hand
if one multiplies the position of the node by the matrix of the object
one obtains a result much more convincing. However, under Windows **
direct use of this matrix in the API python of Blender 1.80a plant irremediably
software. But operation is correct, once again has my great surprise, if
one recovers each list of 4 cells to recompose a new matrix then.
| X |
the matrix of transformation is form:
| M11 M21 M31 M41 |
| X | | M11 M21 M31 M41 |
to carry out a multiplication of matrix, each column of the first matrix is associated the each line of the second in the following way:
x1 = x*M11 + y * M21 + z*M31+1 * M41
Donc here it has only one column there what returns the things much simpler to write, it is not necessary to fulfill a function of general processing of the matrices. On the other hand the classification of the cells starts to 0 it is thus necessary to adapt a little so that that functions in python. The following presentation is obtained:
x1 = (X * M[0 ]) + (y * M[0 ])
+ (Z * M[0 ]) + M[0 ]
For this project, the last line is not useful.
Example of use:
To return from there to the coefficients of the plan one can write the following function:
So that script is éxecuté with each modification made to the objects which interessent us, it should be bound to these objects. For that one starts by inserting the button of connection of script quite simply named Script Short props In the image below, it is that which is on the left. Normally that should reveal a window divided into two parts. In that of right-hand side is two new buttons: [ 0Scr:0 ] and [ New ] But these buttons, in this case, are not of any utility. In fact they manage the connection with the whole scene. It is necessary to reveal those which are in the left part. For that one inserts the button Display Object Script Link. In the image below, it is that which is marked by the three black arrows.
Then one selectionne the object with the usual method: clicsouris-right one presses on the button [ New ].
That will reveal two new buttons: a selector knob which will allow choisr between FrameChanged and Redraw, the first is rather interessant for animation, the second for an interactive installation since script will be carried out each time the windows of display are repainted, and a button of text where it will be necessary to register very exactly exactly the name of the script associated python which is in the window of script.
It any more but does not remain to find a camera angle interessant so that the reflection is visible in your scene. I hope that this script will render service to you. Hold me with the current of your tests or problems of use either while passing by the forum of which the address fig at the foot of the page or while writing to me personally: firstname.lastname@example.org.
cette page peuvent être posées sur :
Les questions concernant cette page
peuvent être posées sur :