Save the current layout in a cookie

We are utilizing three.js to display 3D representations of stomach contents based on MRI data. The colors represent approximate concentrations, with each bubble representing a voxel in the 3D space. Use the menu on the left to load different views.

(Feel free to use this link as sample code)

The flat surface at the top (adjust the image rotation) simulates the liquid level of the meal due to gravity.

We are interested in saving the current view in a cookie so that users can return to the same perspective later on. However, I am unsure which matrix to store in the cookie.

I have reviewed https://github.com/mrdoob/three.js/issues/1188#issuecomment-3666286

but I have yet to pinpoint the specific matrix to store in the cookie. The ones I have identified do not update during rotation. Please note that while I am familiar with using cookies, this is more of a THREE.js-specific inquiry rather than a general JavaScript programming question.

Answer №1

To save only the camera coordinates, you can use the following method:

var savedData = JSON.stringify( [
    camera.position.x,
    camera.position.y,
    camera.position.z,
    camera.rotation.x,
    camera.rotation.y,
    camera.rotation.z
] );

When you want to set up the camera using the saved data, follow this code snippet:

var dataArray = JSON.parse( savedData );
camera.position.x = dataArray[ 0 ];
camera.position.y = dataArray[ 1 ];
camera.position.z = dataArray[ 2 ];
camera.rotation.x = dataArray[ 3 ];
camera.rotation.y = dataArray[ 4 ];
camera.rotation.z = dataArray[ 5 ];

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to toggle the visibility of multiple column groups in Ag-Grid community using dynamic

I am seeking to replicate a basic version of the sidebar found in Ag-Grid Enterprise. The goal is to use JavaScript to gather all column groups within a grid and then provide a checkbox for each group to toggle visibility. While I am aware that individual ...

What is the best way to transfer a JSON object from Java to JavaScript?

I've been struggling to pass data from my Spring controller to JavaScript, but I haven't had any success so far. Would using ajax be the best approach for this task? Can you provide me with some hints on how to achieve this effectively? In my co ...

Showing additional content in an alternative design

I'm currently facing an issue with the "load more" post button on my Wordpress site. I've designed a unique grid layout for the category page, with a load more button at the bottom. However, when I click the button to load more posts, they appear ...

Comparison between PHP's JSON parser and Javascript's JSON parser

Can anyone help me with this PHP serialize JSON encoding issue? json_encode(array('pattern' => '^(?:/?site/(?[\w\-]+))?(?:/?intl/(?[a-z]{2}(?:\-[a-z]{2})?)/?)?(/?(?.*))')); // output json: {"pattern":"^(?:\/?site ...

Top Method for Reloading Element-Specific JavaScript When Replacing Elements

Is there a better way to re-initialize JavaScript without needing a page refresh? I'm currently struggling with appending an MDBootstrap <select> tag, which involves more than just adding a child element. Instead, I have to remove the element an ...

Modifying the default label for each bubble on a bubble chart with chartjs-plugin-datalabels

Is there a way to add labels to each bubble in the bubble chart using chartjs-plugin-datalabels? For every bubble, I'd like to display the label property of each object within the data.dataset array, such as "Grapefruit" or "Lime". Currently, I'm ...

Having trouble accessing properties within a JavaScript object array in React.js?

I have a React.js component that fetches its initial state data from an API call in the componentDidMount(). This data comprises an array of objects. While I can see the entire array and individual elements using JSON.stringify (for debugging purposes), a ...

Repeatedly Triggered JQuery AJAX Calls

On my web page, I have implemented a feature that allows users to search for an address using a GIS server's web-service. This functionality is triggered by a button click event which calls a JQuery AJAX method. Upon successful retrieval of address da ...

Creating a TextGeometry in THREE JS that Reacts to Mouse Movements

I have created a unique source code where the text rotates based on mouse position. // Setting up the scene const scene = new THREE.Scene(); let camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 ) ...

Why is my jQuery SlideReveal not displaying on page load?

Can anyone provide some help? I am currently using the jquery.slidereveal.js plugin from ''. The plugin works well when manually clicking the trigger to open and close the menu. However, I would like it to default to its last state on page load, ...

Creating header menus with section labels in Windows 8 Metro can be easily accomplished by utilizing Javascript

Is there a way to create a navigation menu in Windows 8 Metro JavaScript that includes header menus and section labels, similar to the example shown below? ...

Using useState props in React Native navigation screens with React Navigation

I'm currently working on my first React Native app with react navigation after previously having a background in web react development. In the past, I typically used useState for managing state. For instance, rendering a list of components based on d ...

tips on launching a pre-existing react native project

Trying to run a project downloaded from someone else can be quite challenging. I encountered some issues where the project just wouldn't start, and now I'm completely stuck. Can anyone help me out? https://github.com/sunlight3d/react_native_v0.4 ...

Utilize Angular's ngFor directive to loop through HTML elements and

<div (click)="switchImg($event)" class="containerImgSmall"> <img [ngStyle]="imgs.img1.zero.style" id="1" src="{{ imgs.img1.zero.src }}" alt="" ...

Is it possible to create a TypeScript generic type that transforms a Record into a type by utilizing the `as const` keyword?

Imagine this scenario: I define const foo = { myKey: 'myValue' } as const Now, when I ask for typeof foo, I get { readonly myKey: 'myValue' } If I have a type MyType = Record<string, string>, and I want to create a modifier (let ...

Dynamically add a plugin to jQuery during execution

After installing jQuery and a jQuery-Plugin via npm, I am facing the challenge of using it within an ES6 module. The issue arises from the fact that the plugin documentation only provides instructions for a global installation through the script tag, which ...

Ways to implement the function provided in the website using javascript

Exploring the world of JavaScript functionality as a beginner, I am eager to try pasting dynamic data into HTML. I came across a helpful link providing instructions on how to achieve this using a table format. However, despite my best efforts, I am strugg ...

In React, the entire component refreshes every time the modal is opened

<ThemeProvider theme={theme}> <GlobalStyle /> {componentName !== 'questionaire' && componentName !== 'activityResult' && <CardWrapper />} <ErrorModal ...

Lazy loading images without the need to manually adjust the image structure

After experimenting with various LazyLoad options, I found that most of them required modifications to the src tag or the addition of a new tag. Is there a way to LazyLoad content without having to change the tag structure? I am extracting content fro ...

Launching various modals on marker click

I'm having an issue where I need a different modal to be displayed depending on the name in the markerSet array. Currently, the if/else statement is always returning the same modal. Take a look at the if statement in my JavaScript code below. The nam ...