Navigating Three.js coordinate systems

While working with vectors in three.js, I noticed that the axes seem to be mixed up. It's confusing because Y is the vertical axis, but X and Z appear "mirrored" causing objects to only look right when viewed upside-down. How can this issue be resolved? Rotating the camera representation/objects might not suffice - I require a complete change in the World X Y Z representation.

The program is built using:

<script src="jquery-2.1.4.js"></script>
<script src="jquery.blockUI.js"></script>
<script src="getparam.js"></script>    
<script src="dat.gui.js"></script>
<script src="three.js"></script>
<script src="OrbitControls.js"></script>
<script src="Stats.js"></script>
<script src="Program.js"></script>

I am unsure about which part of the code needs modification.

This represents the incorrect JS orientation: https://i.sstatic.net/yCmTo.png This is how it should ideally look: https://i.sstatic.net/S11Vb.png

Answer №1

It seems like you're looking for a specific behavior, perhaps try adjusting the up vector for the camera to achieve the desired effect. For example:

camera.up(0, 0, 1);

In this code snippet, we assume that camera refers to the camera being used for rendering, and that you want the Z-axis to be considered as "up". To observe how this change impacts the scene, check out this simple JSFiddle example here:

// JavaScript code demonstrating camera adjustments
var scene, camera, cube, light;

initialize();
animate();

function initialize() {
  var height = 500;
  var width = 500;
  var background = '#000000';

  scene = new THREE.Scene();

  var axisHelper = new THREE.AxisHelper(50);
  scene.add(axisHelper);

  // Setting up the camera
  camera = new THREE.PerspectiveCamera(50, height / width, 1, 10000);
  camera.position.set(20, 20, 20);
  // Uncomment next line if specifying up vector directly
  // camera.up = new THREE.Vector3(0, 0, 1);
  camera.lookAt(axisHelper.position);
  scene.add(camera);

  renderer = new THREE.WebGLRenderer({ antialias: true });
  renderer.setClearColor(background);
  renderer.setSize(width, height);

  var container = document.createElement('div');
  document.body.appendChild(container);
  container.appendChild(renderer.domElement);
  var canvas = document.getElementsByTagName('canvas')[0];
  canvas.style.width = width + 'px';
  canvas.style.height = height + 'px'
}

function animate() {
  requestAnimationFrame(animate);
  render();
}

function render() {
  renderer.render(scene, camera);
}

This script displays an AxisHelper representing orientation (red for x-axis, green for y-axis, blue for z-axis). Try uncommenting the line that sets the camera's up vector and re-run the code to observe the differences visually.

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

Cannot chain promises using 'then'

Having trouble understanding why the 'describeDir' promise chain is not working properly. Can anyone help me figure out what I did wrong here? Everything in the code seems to run, but functions like then or finally from the promise API never get ...

Preventing the addition of duplicate items to an array

My current challenge involves pushing containers into an array in my JavaScript code. However, once a container has been pushed, I want to prevent that same one from being pushed again. If you'd like to take a look at the JSfiddle where I'm work ...

Maintain selected dropdown option after page reload

I attempted to preserve the selected item after triggering a reload with an onchange event, however, I encountered this error in the console: "TypeError: o.nodeName is undefined[Learn More]" Here is my select element : <select onchange="showMov(this. ...

Leveraging the power of JavaScript to reveal concealed div elements

I've got a collection of divs (five in total) with a hidden class applied to them in my CSS stylesheet. Each div also has its own unique ID. My goal is to use JavaScript to reveal these divs one by one. Here's an example of what I'm looking ...

Refreshing Rails Views by Periodically Polling the Database

We are currently developing a statusboard to monitor all our external servers. Our database contains information about OS, software versions, and other details that are subject to frequent updates. To ensure real-time visibility of these changes on the web ...

Using SetTimeout with the TextInput component in a React-Native application

Currently, I am working on creating a SearchBar component for my new Android application using React-Native. As a newcomer to React-Native, I created a function called _changeInput() to handle passing text to a local function. Initially, the text pass wor ...

Issue with displaying Images on Datatables using Javascript

I have been scouring the depths of the Internet. Everything was running smoothly, I was handling image uploads and retrievals with NodeJs to MongoDB using the schema below: image: { data: fs.readFileSync(path.join(__dirname, '/public/uploads/&apos ...

What is the reason that TypeScript does not automatically infer void & {} as the never type?

When TypeScript's void type is used in combination with other types through intersection, the outcomes vary. type A = void & {} // A becomes void & {} type B = void & '1' // B becomes never type C = void & 1 // C becomes never type D = void ...

Is there a way to transform a JSON object into a custom JavaScript file format that I can define myself?

I have a JSON object structured as follows: { APP_NAME: "Test App", APP_TITLE: "Hello World" } My goal is to transform this JSON object into a JavaScript file for download. The desired format of the file should resemble the follo ...

Calculating the sum of values in a GridView using ASP.NET

I have an ASP.NET Web Application where I am utilizing a BulkEditGridView to create an order form. This GridView allows users to edit all rows simultaneously. Within the grid, there is a column that calculates the total cost for each item (cost x quantit ...

Utilizing jQuery for seamless communication between parent and child iFrame windows

On my webpage, there is an iFrame containing a table where I want to add a click event to the rows. The challenge is retrieving the selected row within the iFrame from the parent window. The goal is to define a class for a clicked table row like this: $( ...

Struggling to implement .indexOf() in conjunction with .filter()

Hello, I'm new to JavaScript and ES6. Currently, I am working on a react-native app that utilizes Firebase and Redux. One of my action creators acts as a search bar function to fetch data from Firebase. Here's the code I have so far: export cons ...

Utilizing webpack to import both d3 and d3-cloud libraries

I've been attempting to integrate d3 and d3-cloud (for word cloud) into my AngularJs(v - 1.4) app by using: import d3 from 'd3' import d3Cloud from 'd3-cloud'. However, when trying to use d3-cloud with d3.layout.cloud(), ...

A skeleton framework lacking a data storage backend

I am currently developing an offline javascript application that must be compatible with IE7, ruling out the use of localStorage. The app does not require any information persistence, as a refresh clears everything. My query is regarding setting up Backbo ...

Issue with webcomponents-lite.js file

Encountering this particular error message in the console while attempting to run the application: webcomponents-lite.js:64Uncaught TypeError: Cannot read property 'getAttribute' of null at webcomponents-lite.js:64 at Object.549 (webcomp ...

Find the index of the element that was clicked by utilizing pure JavaScript

I am struggling to find the index of the element that was clicked. Can anyone help me with this? for (i = 0; i < document.getElementById('my_div').children.length; i++) { document.getElementById('my_div').children[i].onclick = f ...

What are the steps for accessing a server-side WebControl from the client side?

Issue Overview: I am facing a problem with managing different types of input values in my dialog box. Depending on the selection from a dropdown list, the required input could be simple text, a date, or specific data from a database. I have successfully i ...

CreatePortalLink directs users to a payment URL instead of a dashboard

I am currently working on a project that utilizes the Stripe payments extension in conjunction with Firebase. The application is built using Next JS. After a user subscribes, I want to provide them with a tab where they can manage their subscription. The ...

Point the API endpoint to a different file

Is there a method to proxy a specific binary file, such as redirecting a PDF file to another PDF file using something like app.use('/proxy', proxy('/desiredPath'))? I have tried this approach, but it does not seem to work for the parti ...

When the "x" close icon is clicked, the arrow should toggle back to 0 degrees

I've been tackling the challenge of creating an accordion and I'm almost there. However, I'm facing an issue where the arrow doesn't return to its original position after clicking the close "x" icon. The toggle works fine but the arrow ...