How can you obtain the ilplotcube rotatation information at runtime? - ilnumerics

Suppose I plot a surface and at runtime I use the mouse to rotate the surface. Once the right rotation of the surface is achieved, how I can get its state?

Each driver creates a clone of the global scene which is constantly synched and updated with changes in its source. The rotation is done on the clone. I have not tested it, but I think, you can query objects (e.g. the plot cube) in the clone by
panel.GetCurrentScene().First<ILPlotCube>(/*your filter if needed*/)
This instance will reflect all changes done by the user.

The method pointed out in user492238s answer does work. However, GetCurrentScene() assembles a new scene as composition of the global and the local (to the current driver) scene. This can get costly if called frequently. If only individual objects / properties are needed, panel.SceneSyncRoot can be used instead.
Also, the rotation of a plot cube is exposed by the plotcube.Rotation property. So, in order to get the current rotation of a plot cube (including the rotation due to user input):
panel.SceneSyncRoot.First<ILPlotCube>().Rotation

Related

Unity: Create AnimationClip With World Scale AnimationCurves

I've been looking for a solution to this for quite a while now (meaning several days) and I haven't found anything yet. Maybe I'm thinking about it wrong and there isn't a way, but let's try!
I'm recording hand-data on a Hololens (the Unity Hololens Input Simulation for now). This essentially gives me one float AnimationCurve for each hand joint for each transform.position.x to z and rotation.x to w. Now my goal is to put these curves into an AnimationClip and add it to an AnimatorController (via an AnimatorOverrideController) that animates a hand rig and replay the recordings. Everything so far works!
However, the recorded hand-data from the Hololens is in world scale, not in local scale. (which makes sense, since you usually want absolute coordinates when you want to know where the hand is.) But to animate the hand, it seems I'm only able to set local coordinates, which I don't have.
Example:
clip.SetCurve("", typeof(Transform), "localPosition.x", curve.PositionX);
Here, the clip takes the the x-coordinates from some hand joint and puts it to the localPosition.x of the corresponding hand rig joint. The problem: curve.PositionX is world-scale (absolute coordinates), but localPosition.x takes local-scale (coordinates relative to its parent).
I can't simply change "localPosition.x" to "position.x", like so:
clip.SetCurve("", typeof(Transform), "position.x", curve.PositionX);
even though the Transform class has both properties and position is the object's world scale position. I'm not sure why this doesn't work, but it gives me the following error:
Cannot bind generic curve on Transform component, only position, rotation and scale curve are supported.
I'm aware that it doesn't make much sense to use absolute coordinates for an animation, but I simply don't have anything else.
Does anyone have an approach how I can deal with this in a sensible, not-too-cumbersome way? It seems I have all the important parts, I just can't figure out how to put them together. Thanks so much already! :)
From my basic understanding, it seems like you are using the Input animation recording service provided by MRTK. Unfortunately, MRTK does not provide the localPosition version of Curves data. However, you can modify the data from the recordingBuffer after the InputRecordingService stops recording.
So, this is a method worth trying for you: in the handJointCurves dictionary property of recordingBuffer field, a set of pose curves is stored for each joint. And then, base on this table:Joint pose curves, subtract the position value of the key None from the position value of each other joint in every key frame so that the localPosition based on the key None is obtained.

Hololens Spatial Mapping Collision - Mixed Reality Toolkit

I want to put a hologram-poster in AR, on the Hololens 1, on a wall using the Mixed Reality Toolkit. But everytime I try to put a hologram onto the spatial mapping it slides right through it and vanishes behind the spatial mapping.
What did I miss?
My understanding is you are implementing tap-to-place that enables users to move objects and place them on real-world surfaces. And your issue is that when you placing the object, it did not place on the surface as expected.
Usually, in MRTKv2, the Solver would be a good direction to implement tap-to-place.
The SurfaceMagnetism Solver can cast rays to surfaces in the world, and align the object to that surface.
So, you can add SurfaceMagnetism Component to the object and create a script that has two methods, one that turns on the solver when the object is selected and one that turns off the solver while the object is deselected. When you close the solver, the object will stay in the last position.

Importing an exported .FBX from Blender to Unity object transform issue

Alrighty,
I have a dumpster model I have exported from Blender as an FBX. The transform, rotation and scales have all been applied in Blender. when importing into Unity and then adding to the scene, the model is elevated and rotated at an odd angle to the transform as per the image.
The model has an armature for animating the lids an I have applied the location, rotation and scale on it as well.
Any one else come across this or know of a fix?Thanks
Blender image
Incorrect dumpster transform and location image
The problem is that Blender uses the right-handed coordinate system which means the Z-axis is pointing upwards.
Unity uses the left-handed coordinate system which means the Y-axis is pointing upwards.
To fix this, set the X-axis rotation of the model to be -90. Press Ctrl+A and apply rotation. The X-axis rotation will look like it is now 0 after that. Set it to 90 again and export it to Unity.
This 3 minutes video should also help you do this if you are still confused.
If you still have problems, check your animation. Don't apply it to your model and see if it's the problem.
Also as a side note, you can use blender files (.blend) directly with unity. So every time you modify them inside your project folder they change in unity as well.
The simplest way to solve this would be as follows:
Create a dummy game object (D)
Transform/offset the position of D to make sure your object's position align with the dummy parent
Put your game object as the child of the dummy game object D
You can then apply transform on D, rather than your own game object directly.

Set absolute 3D rotation is Matlab

I'm trying to show a 3D model of a box that should rotate according to some accelerometer values that are read in real time (down is where gravity is at).
I have the box, I can use rotate, but when new values come in I can only rotate relative to the current position of the box with rotate. Is there a way to either reset rotation to default values (0, 0, 0) or to set new absolute rotation values in Matlab?
Here's what I've got right now:
I tried to use the delta between old and new values, but the error gets too big too quickly.
rotate changes the actual data of your object, not just a view on it. Therefore, the only way to 'reset' would be to save the original data used to generate the object, and then re-set those data using calls like
set(oh, 'Xdata', origXData)
set(oh, 'Ydata', origYData)
set(oh, 'Zdata', origZData)
where oh is the handle of the object.
An alternative would be not to use rotate but view, which does not modify the object but only the viewpoint. However, a call to view does not change the viewpoint relative to the current one, but only absolutely. Therefore you'd need to keep track of the current viewpoint in a variable, modify it based on your accelerometer readings, and set the new value.

Unity3d Transform issues when trying to re-parent a Gameobject with sub-Gameobjects

I am trying to grab a Gameobject that's placed in the correct spot and re-parent it to different Gameobject transforms using code. I manage to do this by using ..transform.parent = parent.transform but the rotation and position get messed up. How can I keep it's rotation and position when re-parenting?
Thanks!
Always use gameObject.transform.SetParent(anotherGameObject), or you risk exactly the sort of phenomena you've described. See SetParent docs; there is a second parameter to consider.
The form mentioned in the question still works in many cases, but has been deprecated for a while.
Place all game object that you want to parent, to empty game object(example:"EMPTY\PARENT\EMPTY\CHILD") with scale 1:1:1(in editor)or re-scale your parent game object to 1:1:1