When the page is refreshed, reorienting axes in three.js encounters difficulties

I am currently working on a project that involves using the three.js editor source code available for download on the three.js website. As part of this project, I am required to adjust the orientation of the axes to align with standard airplane coordinate axes (x-axis out the nose, y-axis out the left wing, z-axis down). You can view the specific orientation I am aiming for by clicking on the following link: design axis orientation

To achieve this, I made modifications to the index.html (located in the editor folder), three.js (found in the build folder), and Editor.js (in the editor/js folder) files. Despite successfully rotating the axes as desired initially, upon refreshing or reloading the page, the orientation reverts back and no longer maintains the correct positioning. However, when I select File > New, it resets back to the intended orientation. Could someone enlighten me on why the code fails to retain the adjustments after a reload?

Below are the changes I implemented within the code:

index.html (line 12):

<script src="../build/three.js"></script>

replaced from

<script src="../build/three.min.js"></script>

This modification allows the use of the full three.js file instead of the minified version.

three.js (lines 40581 and 40582):

vertices.push( - size, k, 0, size, k, 0 );
vertices.push( k, - size, 0, k, size, 0 );

changed from

vertices.push( - size, 0, k, size, 0, k );
vertices.push( k, 0, - size, k, 0, size );

This alteration results in a 90-degree rotation of the grid orientation, transitioning it from horizontal to vertical.

Editor.js (line 9):

this.DEFAULT_CAMERA.position.set( -20, 20, -20 );

revised from

this.DEFAULT_CAMERA.position.set( 20, 10, 20 );

I also included the line

this.DEFAULT_CAMERA.up.set( 0, 0, -1 );

directly below the camera position.set function.

All these adjustments are aimed at realigning the grid and axes to mirror the image displayed in the provided link.

Answer №1

When working with three.js, many objects clone the THREE.Object3D.DefaultUp to determine their orientation (the up vector) during construction.
This default up value is used for various elements such as lights, objects, cameras, and possibly more.

In three.js, this vector is initially set to (0, 1, 0) by default, as seen here in the THREE.Object3D class, indicating that the y-axis points upwards.

Object3D.DefaultUp = new Vector3( 0, 1, 0 );

If you prefer the z-axis to be facing upwards by default, you can update this default up value to (0, 0, 1) (or if you want it pointing downwards as mentioned in your query, use (0, 0, -1)).

If you make this adjustment early on in your code – before creating any objects – all subsequent objects will automatically have the correct up property from the start, potentially eliminating the need for additional customization. You can modify the default up with this line of code:

THREE.Object3D.DefaultUp.set( 0, 0, 1 );

Give this a try; it simplifies changing the default orientation of your three.js scene and may also address the issue you encountered when refreshing the page.

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 advantage of not importing related modules?

As a newcomer to React, please excuse any novice questions I may have. I am currently utilizing npx create-react-app to develop a React app, but I'm unsure of the inner workings: Q1-If I were to throw an error in a component like so: import React, { ...

What is the best way to maintain the previous input value on page refresh in Vuejs?

In my development project, I am utilizing the Laravel and Vue.js technologies. I am facing an issue where I need to set the input value to its previous old value when either refreshing the page or navigating back to it in a Vue dynamic component. Here is ...

Meta tag information from Next.js not displaying properly on social media posts

After implementing meta tags using Next.js's built-in Head component, I encountered an issue where the meta tag details were not showing when sharing my link on Facebook. Below is the code snippet I used: I included the following meta tags in my inde ...

If the FedEx function does not receive a payment, it will need to return a value of Payment Required

I am struggling with understanding functions, parameters, and arguments in JavaScript as I am new to it. My goal is to have a function that returns different values based on the payment amount. If no payment is passed, it should return "Payment Required", ...

Connecting Vue component data to external state sources

I am facing a challenge with integrating a Vue component into a large legacy system that is not based on Vue. This component retrieves data through AJAX requests and displays information based on an array of database record IDs, typically passed at page lo ...

Tips on transforming a JSON array object into a JSON array

**Background:** I have been utilizing lodash to eliminate the empty key from my JSON data. However, upon removal of the keys, it transforms my array into an object. For instance: { "projection": "Miller", "series": [ { "mapPolygons": { ...

Sequential execution of multiple useState updates when an update triggers a re-render

Can you explain why the function setPeople is being executed after setFirstName, setEmail, and after the event handler has been exited? const [firstName, setFirstName] = useState(''); const [email, setEmail] = useState(''); const [peopl ...

Sending information to a PHP script using Ajax

I am working on a project that involves input fields sending data to a PHP page for processing, and then displaying the results without reloading the page. However, I have encountered an issue where no data seems to be passed through. Below is my current s ...

Add up the duplicate elements in two arrays

I have dynamically created two arrays with the same number of cells (where array.length is the same, representing a key and value association). Below are the arrays: barData.labels["Food", "Food", "Food", "Food", "Food", "Food", "Food", "Food", "Food", "F ...

Utilize an array value as a parameter for getStaticProps within Next.js

Currently, I am fetching my Youtube playlist using a fetch request and utilizing getStaticProps(). However, I am encountering an issue where my playlist is dependent on the result of an array of objects. export async function getStaticProps(){ const MY_P ...

Using the Sequelize query string prefix to find data that starts with a specific value

I'm currently working on an autofill feature that takes a string input and provides a list of string suggestions. While using Sequelize's iLike:query, it retrieves all strings in which the queried string is present. However, my goal is to priori ...

Size three canvas, woven with triple strands of fiber

I am currently facing an issue with the dimensions of a three-fiber canvas. I require specific fixed width and height for the canvas, but I cannot figure out how to adjust these parameters. Although I've tried changing the sizes using style={{width: 1 ...

Create a Vue application that is built on modules which could potentially be absent

I am currently developing a Vue+Vite app with module-based architecture. I have several Vue components and some parts of the app are functioning correctly. However, I want to ensure that the missing components are not imported or used in the application. H ...

Refresh the browser tab's content

How can I reload the specific content of a browser tab? I am looking for a solution that does not rely solely on jQuery (although I prefer it if there are more options available). Here is what I need: I have a page with many links to other pages (the fo ...

The condition is not functioning properly when the array's length is greater than 1

Within the primary controller, there is an if-else statement: var entity = shareDataService.getModalEntity(); if (entity = "NULL" || entity.length === 1) { myDataPromise = getDataService.getDataFromREST(security); console.log("HERE") } else { ...

Successfully updating a document with Mongoose findByIdAndUpdate results in an error being returned

findByIdAndUpdate() function in my code successfully updates a document, but unexpectedly returns an error that I am having trouble understanding. Below is the schema that I am working with: const userSchema = mongoose.Schema({ phone: String, pas ...

Datatables ajax response not loading data into table

I don't have much experience with JavaScript, so I believe there may be a misconfiguration or something that I'm overlooking. My current setup involves using Datatables v1.10.7. I have a table with the required parts - a thead, tfoot, and a tbod ...

Angular 7 error: No provider found for PagerService causing NullInjectorError

I have been struggling to get pagination working properly in my project. Below is the code I have written: pager.service.ts: import * as _ from 'underscore'; @Injectable({ providedIn: 'root', }) export class PagerService { ...

Extracting information from a string with JSON in Javascript

Can you assist me? I have developed a web service that provides a clean string after clicking on the URL: { "PersonID": 125, "Title": "Security Officer", "Company": "TSA", "CellNum": "423-915-3224", "EmergencyPhone": "", "Email": " ...

Issue with Component: Data is not being injected into controller from ui-router resolve, resulting in undefined data

Encountering an issue with resolve when using a component and ui-router: the data returned after resolving the promise is displaying as "undefined" in the controller. Service: class userService { constructor ($http, ConfigService, authService) { th ...