RealityKit fit model entity within field of view - realitykit

Using RealityKit I’m trying to position a PerspectiveCamera to fit an ModelEntity within its field of view. Specifically I want the entity to fill the frame as much as possible. Does anyone have a function to do this? I've seen an example in a different environment but am not successful in translating it to RealityKit. I need the function to take all three axis into account when determining the camera distance.
Thanks,
Spiff

Related

Add an event listener to a particular part of a 3D Object in Three.js

I am having a human body object and what I want is that my code should open a popup whenever I click on any of the specified body parts such as eyes, nose, arms, etc. The object is a single compiled .obj file and I'm unable to figure out as to how should I attach an event listener to the multiple body parts. Any kind of help is much appreciated!
PS: - I am also using orbit controls to handle the zoom and rotation of object.
Thanks in advance..
To solve this issue, it's necessary to design your model in a way such that individual components like arms, eyes etc. are independent 3D objects grouped together to build a more complex asset. This is something you have to ensure during the design phase with a tool like Blender.
In the next step export to glTF instead of OBJ, load the model with THREE.GLTFLoader into your app and then perform a recursive raycasting with the entire asset via:
raycaster.intersectObject( gltf.scene, true, intersects );
By executing this code in a pointermove or pointerdown event listener you can find out whether the user interacts with the model or not.
Notice that three.js has no system to directly assign event listeners to 3D objects. You have to use a different solution like raycasting for this.

Aframe a-sky change rotation upon scene change

Hi I am trying to navigate between scenes. And when i navigate between scenes, i am not able to set/update rotation of the changed scene. i am storing rotation of scenes and then navigate between. Please help struggling from many days
Link to my code on Glitch https://glitch.com/~thin-newsstand
Working explained.
1. Save camera button saves the rotation into select along with the scene and
custom data attribute name data-r
2. If you inspect select dropdown options, you will notice.
3. When select option is changed, it will change sky image from select option and also change rotation.
4. I have used aframe-viewable-component.js to restrict top/bottom movement of skybox.
It sounds like you want to save and restore camera rotation, when a new panorama is loaded.
Since you are using the look-controls component on the camera, you will need to do this using that component. It might be best to modify that component, and create your own custom variation. You can download the original here:
https://github.com/aframevr/aframe/blob/master/src/components/look-controls.js
The component does have a built in function for saving and restoring position and rotation
saveCameraPose: function ()
restoreCameraPose: function ()
as it is written, the component can only save one entry
this.savedPose.position.copy(el.object3D.position);
this.savedPose.rotation.copy(el.object3D.rotation);
Depending on what you want, you may have to save the position/rotation to new variable that are associated with each pano, so that when a new pano is selected, that same entry for camera pos/rot is also loaded and camera restored. It would probably be best to do this with an array. Psuedo code looks something like:
Make an array (containing objects: {camPos, camRot}). named savedCamPR.
When new pano is selected get the index of current pano. named curPanoID
Save the look-controls pos/rot to savedCamPR[curPanoID], ie the array using the index of current pano.
Get the index of the new pao.
if there is a saved entry in the in savedCamPR, use that to restore the camera.
If you have trouble figuring it out, let us know, and I can probably make an online example that saves and restored camera positions for multiple panos.

SceneKit transform/rotate object

I want to create an app using SceneKit with a solid 3D object, whose shape I can change using a given user input. Is it better to do this with predefined animations or to make lots of smaller objects (as nodes) and change their arrangements to mimic a single object changing shape? Many thanks!
Depending on what you mean by 'change shape' you have following options:
If your object is simple (ex: SCNBox, SCNCone, SCNCylinder and alike) and you can change its shape the way you want using its animatable properties (ex: chamfer radius of SCNBox), then animations is simpliest way to go.
If your object is SCNNode with contents loaded from external source and by change its shape you mean scale/rotate/translate, you can also use animations.
If you can create complex object using graph of simple objects with acceptable performance and you can achieve desired shape change with animatable properties then you can also use animations.
If your object is complex (for example, based on some mathematical model) and/or performance is main prioprity for you, then the only way to go with SceneKit is constructing custom SCNGeometries (by filling SCNGeometrySource/SCGeometryElement) from your model.
Since question have tag blender and title mentions rotate, then perhaps (2) is best for you.

Unity Mecanim Scripting Dynamic Animation

I have a scene with one fully-rigged model of human body
and I would like to users could make their own animations by transforming the model.
I am talking about an app with time-line and possibility of rotating certain muscles.
Could you please recommend me some way how to do that?
I can imagine storing some information about model state in certain times.. but I do not know how to save it as an animation.
You can't edit animations at runtime. You can create an animation from scratch and use AnimationClip.SetCurve to build up your animation, but you can't access the curves directly at runtime.
However in an editor script you can use the AnimationUtilitys to modify an Animationclip, but of course only in the editor since this is an editor class.
Answer picked from this thread.
I think best possible solution for you is to create many different animations for every body part by your own and let user to choose different combinations of animations (if you are using Animator or Animations). Or you can split model by body parts and let user change transform parameters with iTweens (move from A to B and change angle from C to D). Then u can easily save object's "from" transform and object's "to" transform and use it as animation.

How can I display an array of rectangles of which sizes are based on user input?

I have read the cocoa drawing guide, read numerous blogs, etc. I feel like I'm missing something.
Here is what I'm trying to accomplish and if you have any direction to books, blogs, tutorials, it's much appreciated!
I'm trying to draw a group of rectangles in a custom view, where the user can change the width and height of each rectangle. When the user presses a button, the rectangle appears in the view. They can also move the rectangles around in the custom view. Eventually I want the user to choose the color of each, but for now, I just want to get the rectangles to draw.
What I don't understand is if I need a controller class for the array, or if the array code goes in my view controller class. I would like to be able to have my own rectangle class to use as a model.
Thanks in advance for your help!
I would have a single controller both controlling the view (feeding it the rectangles) and owning the array of rectangles.
As for the actual drawing, here's Apple's Cocoa Drawing Guide. There are also some handy functions for simple drawing (no gradients).

Resources