The orthographic camera slices the rendered scene down the middle

My current project utilizes an Orthographic camera and MapControls, rendering the scene correctly.

However, I'm facing an issue where the camera cuts the render scene in half:

https://i.sstatic.net/Fz208.png

The initialization of my orthographic camera is as follows:

export class OrthoCamera extends THREE.OrthographicCamera {

  constructor(
    renderingContext: HTMLCanvasElement,

  ) {
    super(
      renderingContext.offsetWidth / -2,
      renderingContext.offsetWidth / 2,

      renderingContext.offsetHeight /2,
      renderingContext.offsetHeight / - 2,

      0.1,
    );
    this.move(2, 2, 2);

  }

In addition, I've created Map controls like this:


export class Controls extends MapControls {
  constructor(camera: OrthoCamera, renderingContext: HTMLCanvasElement) {
    super(camera, renderingContext);
    this.enablePan = true;
    this.enableRotate = true;
    this.target.set(40.0, 3.0, 40.0);
    this.update(0.1);
    this.maxDistance = 240;
    this.maxPolarAngle = Math.PI / 3.2;
    this.minPolarAngle = Math.PI / 3.2;
  }
}

Combining everything together looks like this:

this.camera = new OrthoCamera(renderingContext);    
this.controls = new Controls(this.camera, renderingContext);

Answer №1

If you're looking for a better approach to set up the orthographic camera, consider this alternative method:

export class CustomOrthoCamera extends THREE.OrthographicCamera {

  constructor( renderContext: HTMLCanvasElement ) {
  
    const aspectRatio =  renderContext.offsetWidth / renderContext.offsetHeight;
    const customFrustumSize = 25;
  
    super( customFrustumSize * aspectRatio / - 2, customFrustumSize * aspectRatio / 2, customFrustumSize / 2, customFrustumSize / - 2, 0.1, 1000 );

  }

}

If you want more flexibility in adjusting the frustum size, consider using a separate variable or parameter for it. The frustumSize value should be based on your scene's dimensions.

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

Generate a random string and return it as a value

I am looking to incorporate JavaScript code into my Angular application. I attempted the following approach: export class MerchantNewComponent extends FormBaseComponent { constructor(private merchantService: MerchantService, private route ...

Guide to specifying the indexer type of a function argument as T[K] being of type X in order for t[k]=x to be a permissible expression

Currently, I am attempting to create a function that can alter a boolean property within an object based on the provided object and property name. While I have found some helpful information here, the function body is still producing errors. Is there a way ...

Combine shapes together while utilizing only one texture

New to exploring Three.js and 3D libraries in general. I combined a quarter cylinder and a plane into one geometry using the following code: var planeGeo = new THREE.PlaneGeometry(planeW, planeD / 2, 199, 399); var planeMesh = new THREE.Mesh(planeGeo); ...

Transforming Sphere into Flat Surface

How can I convert the SphereGeometry() object into a flat plane on the screen? I want it to function in the same way as demonstrated on this website, where the view changes when clicking on the bottom right buttons. Below is the code for creating the sph ...

Types of navigation items based on conditions

I want to create an interface where a navigationItem can have optional childs for a dropdown menu. If the childs property is provided, I want to require the icon property in the navigationItem object. If no childs are given, the icon property should not be ...

Typescript fails to detect class constructor mismatches

Why is TypeScript unable to detect that the MadeFromString class is missing a second boolean argument in its constructor, making it incompatible with the StringConstructable interface in this code snippet: interface ComesFromString { name: string; } cla ...

TS2304 error: 'Promise' is nowhere to be found

Hey everyone, I've exhausted all the solutions available on stackoverflow with no luck. So here's my question. tsconfig.json { "version":"2.13.0", "compilerOptions": { "target": "es5", "module": "commonjs", "sourceMap": true, ...

I encountered an error with Firebase when attempting to run functions on my local machine

Encountering a Firebase error when running the function locally using emulator in CLI $ firebase emulators:start --only functions Initiating emulators: ["functions"] functions: Using node@8 from host. functions: Emulator started at http://localhost:50 ...

When working with Angular 12, the target environment lacks support for dynamic import() syntax. Therefore, utilizing external type 'module' within a script is not feasible

My current issue involves using dynamic import code to bring in a js library during runtime: export class AuthService { constructor() { import('https://apis.google.com/js/platform.js').then(result => { console.log(resul ...

Differences between FirebaseFirestore.Timestamp and firebase.firestore.Timestamp in a React Native client and Admin Node server context

Currently facing an issue that seems straightforward but is proving difficult to resolve. Despite thorough documentation review and a lack of similar inquiries, I am encountering difficulties. My project involves building an app using React Native, where ...

Reattempting a Promise in Typescript when encountering an error

I am currently working on a nodeJS application that utilizes the mssql driver to communicate with my SQL database. My goal is to have a unified function for retrieving a value from the database. However, in the scenario where the table does not exist upon ...

Creating Overlapping Textures in Three.JS: A Step-by-Step Guide

Short version: How can I create larger textures on faces with a fading effect, allowing them to overlap each other? - Currently learning three.js by attempting to replicate the game Warzone 2100. :) I'm loading a default ground texture using this c ...

Describe a category of alternating couples

After coming across the query on How to define array with alternating types in TypeScript?, I discovered that it is indeed possible to specify a type of array where the elements must follow a specific order. For instance, the following sequences are consid ...

Exploring Angular Component Communication: Deciphering between @Input, @Output, and SharedService. How to Choose?

https://i.stack.imgur.com/9b3zf.pngScenario: When a node on the tree is clicked, the data contained in that node is displayed on the right. In my situation, the node represents a folder and the data consists of the devices within that folder. The node com ...

Is there a way for me to obtain the full error message after a failed fetch request?

I'm trying to capture all errors from the fetch function, including the specific red highlighted details as a string: https://i.sstatic.net/GtHxv.png But when I catch an error in my code, all I get is "Failed to fetch." Here's what my code looks ...

The file located at node_modules/@types/chrome/index.d.ts does not qualify as a module

I am currently working on a monorepo with a React TypeScript app. The issue I am facing is that when I try to use 'chrome' in any of my .ts files, VSCode displays an error message saying 'Cannot find name 'chrome'.' To resolv ...

Ways to resolve the issue with the Argument of type 'Date[]' not matching the parameter type '(prevState: undefined) in React

I've encountered an issue while trying to construct my project. The error message reads as follows: Argument of type 'Date[]' is not assignable to parameter of type '(prevState: undefined) Here's the excerpt of the code in questio ...

Pulling information from a JSON file using Angular 2

Is there a way to extract data from a JSON file in an Angular 2 project? I attempted the following code snippet, but it seems to be ineffective. Perhaps I missed some important details... any guidance would be greatly appreciated. Additionally, I aim to s ...

Creating and incorporating a generator function within an interface and class: A step-by-step guide

In vanilla JavaScript, the code would look something like this: class Powers { *[Symbol.iterator]() { for(let i = 0; i < 10; i++) yield { i, pow: Math.pow(i, i) } return null; } } This can then be utilized in the following manner: co ...

The HTML table is displaying with an offset, which is probably caused by the *ngFor directive

I'm having trouble aligning the HTML table properly, as it seems to be misaligned. The issue I am facing is related to the inner loop (modification) which is a list inside of Revision (basically, Revision 'has a' modification list). Althoug ...