How to get the camera local axis in three.js - camera

I would like to know what is the most simple/elegant way to get the normalize local axis (x, y, z) of a perspective camera in three.js.
Thanks for your time !

well i'm not that use to OOP, but if you have the enlightment to check 2 class upstairs, there is Object3D class that looks to have all the methods i need.
http://threejs.org/docs/#Reference/Core/Object3D

Related

Contour diagram for Pandas and/or Seaborn for a 3-column matrix

I have like 400 data points which are in forms of a 3-tuple. Something like this:
[[1.2, 3.4, 7.8],
[3.1, 2.6, 3.4],
...
]
Each row is a 3-tuple point, (x, y, z) which shows a point in 3D space.
What I want to do is drawing a contour diagram using these values in the form shown in https://en.wikipedia.org/wiki/Contour_line.
I want this:https://en.wikipedia.org/wiki/Contour_line#/media/File:Contour2D.svg.
I want the third dimension (z) to be the source for contours.
I have seen some other examples on the net, but they are so confusing. They are relying on a function to draw the diagram which is not in my case. I am representing the function as a matrix.
I hope I give enough information to let you know what I am looking for.
Thanks guys.
You can try conrec algorithm from Paul Bourke. It's implemented in many languages and also good explained. It uses the marching cube algorithm.

Serializing Camera State in ThreeJS

What is the best way to serialize (or save or marshal) the state of the camera in a ThreeJS scene, and then un-serialize (or load or unmarshal) the camera later?
Right now I am saving the x, y, z coordinates of the camera's position, up, and (Euler angle) rotation fields. Later I try to restore this camera with calls to position.set(), up.set(), and rotation.set(), and then follow-up with a call to updateProjectionMatrix(). I assume the default Euler angle rotation order is the same when serializing and un-serializing.
Is this correct?
I would suggest instead storing the camera's matrix. This encompasses the entire transformation on the camera, including position, rotation and scaling.
Serializing:
const cameraState = JSON.stringify(camera.matrix.toArray());
// ... store cameraState somehow ...
Deserializing:
// ... read cameraState somehow ...
camera.matrix.fromArray(JSON.parse(cameraState));
// Get back position/rotation/scale attributes
camera.matrix.decompose(camera.position, camera.quaternion, camera.scale);
The accepted answer did not work for me, instead I came up with the following solution:
To save: serialize the x, y and z properties of camera.position and camera.rotation.
To reload: deserialize the above 6 params. And reassign them, for example:
camera.position.x = saved.position.x;
call camera.updateProjectionMatrix() to re-calculate the projection matrix.

Diagonal translation using Object AnimatorAndorid

I am trying to make a diagonal translation using object animator in Android. Following code makes a translation in Y Axis.
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(button, "translationY", -value);
Any suggestions?
Thanks in advance
You can use an AnimatorSet with two ObjectAnimators, one performing the Y translation (as in the example in your question), and a very similar one doing the X translation. Make sure to use the playTogether(..) method of the AnimatorSet and you can animate both X and Y at the same time!

Adding a second x axis to a TGraph in the CERN ROOT program

does anyone know the method or code to add a second x axis to a TGraph in CERN's ROOT program? Ive been searching the root website and its documentation almost always confuses me. What i need is just one plot of data, but a second X axis on top whose values are a function of the bottom x axis' values. Its basically so lazy people dont have to convert from the numbers of the bottom x axis to the top x axis.
For a simple example (if i wasnt clear)
Say you have a sine curve which is some function of theta. On the top x axis we could have degrees whereas on the bottom we could have radians with 360deg corresponding to 2pi rad...
Any help would be appreciated!
TGaxis is the class you are looking for to draw extra axes wherever you desire. Grabbing the world coordinate for your pad you can then superimpose like so. Replace low and high with the appropriate limits.
// your graph code here...
TGraph->Draw("AP");
TGaxis *axis = new TGaxis(gPad->GetUxmin(),gPad->GetUymax(),gPad->GetUxmax(),gPad->GetUymax(),low,high,510,"+L");
axis->Draw();
Check out TGaxis documentation for more examples.
(A previous answer I had was deleted as it was just a link to the site listed as a reference below. I hope this is more in line with the community guidelines.)
I think this might do what you want.
void axis2() {
TH1F *h = new TH1F("h","test",30,-3,3);
h->FillRandom("gaus",10000);
h->Draw();
TText t;
t.SetTextSize(0.02);
t.SetTextAlign(22);
Double_t yt = - h->GetMaximum()/15.;
for (Int_t i=1;i<=30;i++) t.DrawText(h->GetBinCenter(i),yt,Form("%d",i%10));
}
It doesn't create another taxis but shows you how to draw text at the same location of the axis. The answer comes from Rene Brun himself (one of the main authors of root) so I don't think you can have two x axes.
Source:
http://root.cern.ch/phpBB3/viewtopic.php?f=3&t=7110
Here is an example showing how to proceed.
https://root.cern/doc/master/twoscales_8C.html

How Do I Switch Y and Z Axises from Blender? (So Y is Up)

I've been having a bit of a problem with making the Y axis my up axis when exporting mesh and scenes from Blender. Both Blender and my export target use right handed transformation matrices. Z is the up axis in Blender while Y is the up axis in my target. The problem exists in 2 places though. The scene's transformations can't just be shifted on the X axis to fix this, because I also need to do the Y/Z switch for the vertices in the mesh (export as vertex.x, vertex.z, vertex.y). I need to have the actual Y and Z rotations switched, so that if the Y and Z rotations are the same, no change will occur (ie. identity). Thanks for your help in advance. Feel free to ask questions if I was not thorough enough.
Blender does two things different than the rest of the known world!
1. It uses Z axis for vertical (should be Y); Y axis for horizontal (should b X); and X axis for in and out (should b Z).
Very weird! Every high school graph since the beginning of time uses X for horizontal and Y for vertical.
It uses the right mouse button for selections.
U can change the selection btn in Preferences, but not the crazy axis arrangement!
no,
you do this
y=z
z=-y
no rotation of 90 degrees can make you go from left to right hand.
I ran into a similar issue when working with cinema4d and blender. In cinema4d Y is the up axis and rotations are heading,pitch and bank.
Blender's system looks like a right handed system, but rotated by 90 degrees on x axis.
I did the same thing for coordinates(exported as vertex.x,vertex.z,vertex.y). For rotations,
I think you should add 90 degrees(math.pi * 0.5) for rotations on X axis and the rest should be fine.
HTH
Have you tried just using Select All (the 'a' key) and then r x 90 to rotate everything 90 degrees around the X axis and the pivot point? (your pivot point is choosable in the menu bar of the 3D view if you need to control that).
You could do that, export, and then undo.
Just Download Wings3D. Export from Blender as .3ds and then Import this file in Wings3D.
Now you can just export it from Wings3D, again to .3ds. But instead of clicking directly on .3ds, click on the small icon in the right of the ".3ds" menu. now you can unchecked the Box Swap y und z axis and import the .3ds in another program.
There is no way that would be possible. Coordinate system was innately selected as hard coded from the blender source and there are no explicit option has been made in blender to switch it. It would also affected many of the hard coded functionality of any function blender was used or has been made by assume that coordinate
However, in theory, it would be possible to access blender source code and rebuild the blender to have it use another coordinate we would like. Albeit we need to carefully swap everything related to coordinate system
I too wish that left handed coordinate system (as of Unity3D) would be industrial standard and blender should at least have another version that work in left handed coordinate. People should just graduated from table coordinate to screen coordinate already
In blender, you could add empty plain axes, that will correct your orientation when exporting to unity, or try exporting as fbx file and change orientation in export options