What are the steps to create a mirror image of an object within itself?

Can an object reflect itself?

I am interested in seeing a self-reflection on a metallic object.

In essence, the two rings of the mechanism should be reflected in the lower part.

Thank you in advance!

https://i.sstatic.net/m3KUY.jpg

https://i.sstatic.net/CLYZb.jpg

<script>

   if ( ! Detector.webgl ) Detector.addGetWebGLMessage();

   var container;

   var loader;

   var camera, cameraTarget, controls, scene, renderer;

   init();
   animate();

   function init() {

     var previewDiv = document.getElementById("preview");

     camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 15 );
     camera.position.set( 3, 0.15, 3 );

     cameraTarget = new THREE.Vector3( 0, -0.25, 0 );

     controls = new THREE.OrbitControls( camera );
     controls.maxPolarAngle = Math.PI / 2.2;
     controls.minDistance = 1;
     controls.maxDistance = 8;
     controls.noPan = false;

     scene = new THREE.Scene();
     scene.fog = new THREE.Fog( 0xdae1e6, 2, 15 );


     // Ground

     var plane = new THREE.Mesh(
       new THREE.PlaneBufferGeometry( 40, 40 ),
       new THREE.MeshPhongMaterial( { color: 0x999999, specular: 0x101010 } )
     );
     plane.rotation.x = -Math.PI/2;
     plane.position.y = -0.5;
     scene.add( plane );

     plane.receiveShadow = true;


     // Fine Linen Texture

     var fineLinenTexture = THREE.ImageUtils.loadTexture( 'textures/fine-linen.jpg' );
     fineLinenTexture.anisotropy = 16;
     fineLinenTexture.wrapS = fineLinenTexture.wrapT = THREE.RepeatWrapping;
     fineLinenTexture.repeat.set( 5, 5 );
     var fineLinen = new THREE.MeshPhongMaterial( { color: 0xffffff, map: fineLinenTexture } );


     // Chrome Material

     var path = "textures/chrome/";
     var format = '.jpg';

     var urls = [
         path + 'px' + format, path + 'nx' + format,
         path + 'py' + format, path + 'ny' + format,
         path + 'pz' + format, path + 'nz' + format
     ];

     var envMap = THREE.ImageUtils.loadTextureCube( urls, THREE.CubeReflectionMapping );

     var chrome = new THREE.MeshPhongMaterial( {
         color      : 0x151515,
         specular   : 0xffffff,
         shininess  : 200,
         envMap     : envMap,
         combine    : THREE.MixOperation,
         reflectivity : 0.8
     });

     // Base

     var baseGeometry = new THREE.BoxGeometry(1.8,0.012,3);
     var base = new THREE.Mesh(baseGeometry, fineLinen);
     base.castShadow = false;
     base.receiveShadow = true;
     base.position.set( 0, -0.47, 0 );
     scene.add(base);

    // 2 Ring

     var loader = new THREE.JSONLoader();
     loader.load('/models/2ring.js', function(geo, mat){

         var mesh = new THREE.Mesh(geo, chrome);

         mesh.position.set( 0.08, - 0.477, -0.2 );
         mesh.rotation.set( 0, - Math.PI / 0.67, 0 );
         mesh.scale.set( 0.1, 0.1, 0.1 );
         mesh.castShadow = true;
         mesh.receiveShadow = true;

         loadJson(mesh );
     });

      function loadJson(mesh){
          scene.add( mesh );
      }

      // Lights

     scene.add( new THREE.AmbientLight( 0x777777 ) );

     addShadowedLight( 1, 1, 1, 0xffffff, 1.35 );
     addShadowedLight( 0.5, 1, -1, 0xffffff, 1 );

     // renderer

     renderer = new THREE.WebGLRenderer( { antialias: true } );
     renderer.setClearColor( scene.fog.color );
     renderer.setPixelRatio( window.devicePixelRatio );
     renderer.setSize( window.innerWidth, window.innerHeight );

     renderer.gammaInput = true;
     renderer.gammaOutput = true;

     renderer.shadowMapEnabled = true;
     renderer.shadowMapSoft = true;
     renderer.shadowMapCullFace = THREE.CullFaceBack;

     previewDiv.appendChild(renderer.domElement);

     // resize

     window.addEventListener( 'resize', onWindowResize, false );

   }

   function addShadowedLight( x, y, z, color, intensity ) {

     var directionalLight = new THREE.DirectionalLight( color, intensity );
     directionalLight.position.set( x, y, z )
     scene.add( directionalLight );

     directionalLight.castShadow = true;
     // directionalLight.shadowCameraVisible = true;

     var d = 1;
     directionalLight.shadowCameraLeft = -d;
     directionalLight.shadowCameraRight = d;
     directionalLight.shadowCameraTop = d;
     directionalLight.shadowCameraBottom = -d;

     directionalLight.shadowCameraNear = 1;
     directionalLight.shadowCameraFar = 4;

     directionalLight.shadowMapWidth = 2048;
     directionalLight.shadowMapHeight = 2048;

     directionalLight.shadowBias = -0.005;
     directionalLight.shadowDarkness = 0.15;

   }

   function onWindowResize() {

     camera.aspect = window.innerWidth / window.innerHeight;
     camera.updateProjectionMatrix();

     renderer.setSize(window.innerWidth, window.innerHeight);

   }

   function animate() {

     requestAnimationFrame(animate);

     render();
   }

   function render() {

     camera.lookAt(cameraTarget);
     controls.update();

     renderer.render(scene, camera);

   }

 </script>

Answer №1

If you want an object to reflect itself in a three.js renderer, consider implementing environment mapping.

Environment mapping relies on the assumption that the reflected environment is located at an infinite distance.

Even if you utilize a CubeCamera for your environment map, like in this specific example, you may encounter the same issue.

To tackle this problem in three.js, it's recommended to employ a form of raytracing. Although three.js offers a RaytracingRenderer and a basic demonstration, please note that this renderer is currently not fully supported and does not operate at real-time frame rates.

Version: three.js r.71

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

JavaScript: set values to elements in an array

Below is the code snippet I am working with: function gotData(data){ result = data.val() const urls_kws = Object.keys(result) .filter(key => result[key].last_res > 10) var keywords = urls_kws; c ...

Is there a way to dynamically apply styles to individual cells in a React Table based on their generated values?

I'm having trouble customizing the style of a table using react table, specifically changing the background color of each cell based on its value. I attempted to use the getProps function in the column array as suggested by the react table API documen ...

Upon calling the createModalAddPost() function, a single window is triggered to open

Hey there, I'm having a JavaScript question. So, I have a panel that opens a window, and it works fine. But the issue arises when I close the window and try to open it again - it doesn't work. I have to reload the page every time in order to open ...

How to position items at specific coordinates in a dropdown using JavaScript

I have five images in my code and I would like to arrange them in a circular pattern when they are dropped into the designated area. For example, instead of lining up the five images in a straight line, I want them to form a circle shape once dropped. Ho ...

Diminish, then lead to a fresh page

I have encountered an issue with my code. The wrapper performs a fade out effect before redirecting the user to a URL. However, it only fades out once and I suspect this is due to the browser caching or loading the page quickly. Is there a way to ensure t ...

A tool that enhances the visibility and readability of web languages such as HTML, PHP, and CSS

Looking to organize my own code examples, I need a way to display my code with syntax highlighting. Similar to how Symfony framework showcases it on their website: http://prntscr.com/bqrmzk. I'm wondering if there is a JavaScript framework that can a ...

organizing the div based on the given data

I'm working on developing a web application using HTML and AngularJS. There are two main div elements: Div 1 <div class="box1" style="margin-top:20px;"> <span ng-repeat="i in data" style="font-size:14px; font-weight:normal">{{i.div ...

Combining Summernote images with Node.js using Express.js

While there are numerous solutions available for handling the Summernote file-upload in PHP, I have struggled to find a satisfactory solution for Node.js. Here is My JavaScript: $(document).ready(function() { // $('#summernote').summernote( ...

Discovering the technique to interact with obscured objects through a haze of PointsMaterial in three.js

Is there a property that allows objects behind a fog of multiple points to be clickable? I want to be able to click on objects even when they are obscured by the fog. Below is the code I am using to create and animate the fog: const loadFogEffect = () =&g ...

I encountered an unexpected obstacle while reloading my Next.js application with animejs. The error message reads: "SyntaxError: Unexpected token 'export'." This unwelcome occurrence took place during the

Encountering an error with animejs when reloading my Next.js app: An unexpected token 'export' is causing a SyntaxError. This issue occurred during the page generation process. The error originates from file:///Users/.../node_modules/animejs/lib ...

What is the best way to share image data between pages in Next.js?

I'm currently developing a project that mimics Instagram (simply because I want to explore Next.js further) and I'm looking for a way to handle image uploads. My goal is to allow users to upload their images and then redirect them to the "create ...

What is the process to subscribe and obtain data from a server-to-user channel using pusher-js?

I am currently hosting my application using next.js on Vercel. I want to integrate Pusher to provide real-time messages to users in a private and secure manner. Despite successful log entries, I am facing challenges in subscribing to the channel and retrie ...

Managing two simultaneous web service calls in Angular 2

Dealing with two parallel web service calls can be tricky. Sometimes the first call goes through first, and other times it's the second one. The problem arises when the function in my second service requires data from the first service call. I attemp ...

Encountering an undefined variable in the .env file

Once the .env file was created in the main React folder REACT_APP_API_KEY=gzomlK5CKLiaIWS.... I also installed the .env NPM library Despite this, I continued to receive undefined in the API file. What could be causing this issue? import React, { useState ...

Update the inputs following the filtering or searching of issues in VueJS

As a newcomer to VueJS, I find myself struggling with a particular function and lack the experience to fully grasp it. To address my confusion, I have formulated a question (which may be similar to others). For instance, I utilized the computed propert ...

A guide to incorporating a textview into a React application using the Google Maps API

Wondering how to incorporate a textview within a react-google-maps component? Successfully setting up a Google map page in React using the react-google-maps API, I've managed to insert markers and link them with polylines. import React from "react"; ...

The "model" feature appears to be inactive

I discovered a fiddle with a simple radio button functionality that I forked and made some modifications to. The changes worked perfectly, you can check it out in this fiddle: Vue.component('radio-button', { props: ['id', 'v ...

Tips for seamlessly incorporating advertisements into a mixed application

I am having trouble adding banner ads to my hybrid application developed with Telerik. Despite my extensive research, I have been unable to find a suitable solution. Is there any html5 or javascript banner advertising service/API that is compatible with ...

Adding local JavaScript to a Vue component is a great way to enhance its functionality

I am currently working on integrating a homepage concept (Home.vue) into my project. The design is based on a template that I purchased, which includes CSS, HTML files, and custom JavaScript. While most of the CSS has been successfully imported, I am havin ...

Having issues with socket.io connectivity on my Node server

I am setting up my node server to update all connected clients with real-time information. However, when I run the code provided below, the io.sockets.on('connection') callback keeps firing constantly, flooding the console with the message Client ...