Attempting to embed a secondary window within the primary window using three.js

I am currently working on incorporating a zoomed view of a sphere into a main window that represents the sphere.

At this point, I have succeeded in displaying a subwindow at the bottom right corner that contains three axes of the main scene. These axes rotate in synchrony with the sphere when manipulated using the mouse.

Now, my goal is to show a zoomed view of the sphere in this subwindow instead of the 3D axes.

Based on input from Can multiple WebGLRenderers render the same scene?, it is not possible to utilize a second instance of THREE.WebGLRenderer() for the subwindow.

Regarding suggestions from How to render the same scene with different cameras in three.js?, one solution involves using the setViewport function, but I am unsure if it can be used to display the zoomed sphere in the subwindow.

In attempting to achieve this, I have made modifications within the render() function:

function render() {
    controls.update();
    requestAnimationFrame(render);

    zoomCamera.position.copy(camera.position);
    zoomCamera.position.sub(controls.target);
    zoomCamera.position.setLength(500);
    zoomCamera.lookAt(zoomScene.position );

    // Add Viewport for zoomScene
    renderer.setViewport(0, 0, width, height);
    renderer.render(scene, camera);

    zoomRenderer.setViewport(0, 0, 200 , 200);
    zoomRenderer.render(zoomScene, zoomCamera);

  }

Given your expertise, do you think it is technically feasible to simultaneously have two objects displayed (one in the main window and the other in the right-bottom subwindow)?

Could the use of setViewport help resolve my issue?

If anyone could provide documentation or guidance on utilizing setViewport, it would be greatly appreciated.

Thank you in advance.

UPDATE :

@WestLangley, thank you for your suggestions. After implementing your modifications by using a single scene, I encountered an issue where the content of the inset does not appear.

I suspect that the problem lies in my inability to establish a connection between "the container of the inset" and the rendering of this "inset".

As an example, referring back to the aforementioned link, I attempted the following:

...
 // Add sphere to main scene
  scene.add(sphere);

  camera.position.z = 10;

  var controls = new THREE.TrackballControls(camera);

  // If I include these two lines below, nothing appears 
  // zoomContainer = document.getElementById('zoomContainer');
  // zoomContainer.appendChild(renderer.domElement);

  // Zoom camera
  zoomCamera = new THREE.PerspectiveCamera(50, zoomWidth, zoomHeight, 1, 1000);
  zoomCamera.position.z = 20;
  zoomCamera.up = camera.up; // important!

  // Call rendering function
  render();

  function render() {

  controls.update();
  requestAnimationFrame(render);

  zoomCamera.position.copy(camera.position);
  zoomCamera.position.sub(controls.target); 
  zoomCamera.position.setLength(camDistance);
  zoomCamera.lookAt(scene.position);

  // Add zoomCamera to main scene
  scene.add(zoomCamera);

  // render scene
  renderer.clear();
  renderer.setViewport(0, 0, width, height);
  renderer.render(scene, camera);

  // render inset
  renderer.clearDepth(); // important!
  renderer.setViewport(10, height - zoomHeight - 10, zoomWidth, zoomHeight);
  renderer.render(scene, zoomCamera);

}

With only one renderer available, I am uncertain how to assign the "inset" container to the Viewport renderer correctly.

Do you have any suggestions or workarounds to address this challenge?

Answer №1

If you want to display a different perspective of your scene in a smaller window, follow these steps:

Begin by creating a single scene and two separate cameras.

When initializing the renderer, be sure to set autoClear to false.

renderer.autoClear = false;

Next, within your rendering loop, implement this approach:

// Render the main scene
renderer.clear();
renderer.setViewport( 0, 0, window.innerWidth, window.innerHeight );
renderer.render( scene, camera );

// Render the inset view
renderer.clearDepth(); // This step is crucial!
renderer.setViewport( 10, window.innerHeight - insetHeight - 10, insetWidth, insetHeight );
renderer.render( scene, camera2 );

This technique applies to three.js version r.75

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

Checking for Three.js WebGL compatibility and then switching to traditional canvas if necessary

Is there a way to check for WebGL support in three.js and switch to a standard Canvas render if not available? I'd appreciate any insights from those who have experience with this library. ...

Send a substantial item for display using Express Layout

Utilizing Express layouts to render my webpage upon accessing a specific route: The current project I am developing is an admin panel designed for editing a substantial table of data (imagine a website dedicated to managing thousands of product entries, fo ...

What could be the reason behind the occurrence of an error after deleting certain lines of code

The code below is functioning correctly. obj = { go: function() { alert(this) } } obj.go(); // object (obj.go)(); // object (a = obj.go)(); // window (0 || obj.go)(); // window However, an error arises when I comment out the first two lines. obj ...

Encountering a 500 error in Angular while utilizing forkJoin for calling API services

In my Angular 7 project, I have implemented a call in the ngOnInit method to two different API routes to fetch some data using forkJoin. Here is how I have set it up: ngOnInit() { debugger this.route.params.pipe( switchMap(params => for ...

"Modifying the form-control-lg class in Bootstrap and AngularJS affects input size exclusively, leaving the label unaffected

Currently, I am focusing on enhancing an AngularJS custom text input component: <div class="form-group has-feedback" ng-class="[$ctrl.sizeClass, {'has-error': $ctrl.isNotValid(), 'has-success': $ctrl.isValid()}]" > ...

Steps to take to save an HTML element as a PNG

Unique content: I am looking to convert a standard HTML element into an image on an HTML canvas for my website project. I am currently working on creating a website that involves displaying various elements on the screen. One of the key requirements is b ...

What is the best way to resize a div located below a dynamic div in order to occupy the available space?

My website has a dynamic div1 and a scrollable table inside div2. I need the div2 to take up the remaining height of the window, while ensuring all divs remain responsive. I've tried using JavaScript to calculate and adjust the heights on window loa ...

Increase the padding at the top and bottom of the div border

I am facing a problem with CSS shrinkwrapping. Here is the simple code snippet... <!doctype html> <html lang="en-US"> <head> <title>Device Activation</title> <meta charset="utf-8"> <style ...

troubles with dividing string

Recently delving into JavaScript/Angular development and encountering a little roadblock. I am attempting to break up a string of a textarea into an array at the \n character within a controller by utilizing $scope.mytext.split("\n"), however, I ...

Is the jQuery ajax .done() function being triggered prematurely?

Struggling with a problem here. I'm dealing with this code (simplified): var initializeZasilkovna = function () { // Initialize object window.packetery.initialize(); }; // Check if the object doesn't exist if (!window.packetery) { // It ...

Fulfill all of the promises within Bluebird, as well as decline any that do

I am in search of a method to retrieve both successful resolutions and rejections from a promise array. I am relying on the Bluebird implementation, so any ES6 compatible solution would be preferable. One option that comes to mind is utilizing Bluebird&ap ...

Extracting the id of an element using jQuery

The desired outcome is for the code to print the id of the selected div, but it's not working as expected. I've reviewed it multiple times but couldn't pinpoint the error. Any assistance would be greatly appreciated. Here is the HTML: < ...

What could be causing the strange output from my filtered Object.values() function?

In my Vue3 component, I created a feature to showcase data using chips. The input is an Object with keys as indexes and values containing the element to be displayed. Here is the complete code documentation: <template> <div class="row" ...

Error in canvas-sketch: "THREE.ParametricGeometry has been relocated to /examples/jsm/geometries/ParametricGeometry.js"

I recently started using canvas-sketch to create some exciting Three.js content. For my Three.js template, I utilized the following command: canvas-sketch --new --template=three --open The version that got installed is 1.11.14 canvas-sketch -v When atte ...

The Angular directive is failing to refresh the data on the Google Map

I created a directive called "myMap" to incorporate a Google map into my application. However, I am facing an issue when attempting to update the longitude and latitude values for a different location using a controller function. The directive does not ref ...

Ways to eliminate the gap between the currency symbol and the numerical value in HTML

Is there a way to eliminate the gap between the Currency Symbol and Amount? I've been attempting to get rid of the space between the currency symbol and the amount in my HTML code. However, even when I input decimals, there remains a gap between the ...

ajax fails to send the variables, instead sending undefined values

In my HTML code, I have inputs and checkboxes. The JavaScript code collects the data from the inputs, and through AJAX, it should send the information to PHP where it is received and stored in the session. However, when sending the array to the PHP file v ...

The pop-up window created programmatically refuses to close

I am struggling with an issue where I am opening a pop-up from the code behind as a waiting image while processing some background activities. However, the pop-up does not close after the activity is done. Can someone please help me figure out what I am ...

How can we choose the best set of samples to accurately represent a curve with a fixed number of samples?

Background Exploring my passion project involves analyzing an RC aircraft control input device. In the realm of this hobby, there is a common feature known as "stick expo" where control sticks vary in sensitivity based on their position. As I delve into t ...

Is it possible to concurrently hot module reload both the server (.NET Core) and client (Angular)?

Using the command 'dotnet watch run' to monitor changes in server code and 'ng build --watch' for Angular code updates has been successful. It rebuilds the code correctly into directories "bin/" and "wwwroot/" respectively. myapp.cspro ...