I'm having some unexpected reflections with the threejs cube camera

I'm currently experimenting with creating an object that reflects on all sides. Although I've made progress, I seem to be encountering some issues. At certain angles, I can only see partial reflections and the scale of the reflection is much larger than the actual object (an elephant in this case). Here's the code snippet:

<script>
    /*
    written by dstarr 
    */

    var controls, camera, scene, renderer, animmesh, mirrorCube, mirrorCubeCamera;
    var clock = new THREE.Clock();

    function init() { 
        // arguments for constructor are field of view, aspect ratio, near plane, far plane
        camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, .1, 10000);
        camera.position.set(-568, 694,48);
        camera.up.set(-1,0 ,1);
        controls = new THREE.OrbitControls(camera);
        scene = new THREE.Scene();
        scene.add(camera);

        // FLOOR
        var floorTexture = new THREE.ImageUtils.loadTexture('../../assets/checkerboard.jpg');
        floorTexture.wrapS = floorTexture.wrapT = THREE.RepeatWrapping; 
        floorTexture.repeat.set(10, 10);
        var floorMaterial = new THREE.MeshBasicMaterial({map: floorTexture, side:THREE.BackSide });
        var floorGeometry = new THREE.PlaneGeometry(1000, 1000, 10, 10);
        var floor = new THREE.Mesh(floorGeometry, floorMaterial);
        floor.position.z = 20; 
        floor.rotation.x = Math.PI; // 180 degrees
        scene.add(floor);

        // mirror code
        var boxGeom = new THREE.BoxGeometry(300, 10, 300, 1, 1, 1);
        mirrorCubeCamera = new THREE.CubeCamera(0.1, 10000, 500);
        scene.add(mirrorCubeCamera);

        var mirrorCubeMaterial = new THREE.MeshBasicMaterial({envMap: mirrorCubeCamera.renderTarget});
        mirrorCube = new THREE.Mesh(boxGeom, mirrorCubeMaterial);
        mirrorCube.position.set(100,-450,200);
        //mirrorCube.rotation.z = Math.PI / 2;
        mirrorCubeCamera.position = mirrorCube.position;
        scene.add(mirrorCube);

        renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth * .9, window.innerHeight * .9);
        document.body.appendChild(renderer.domElement);

        var loader = new THREE.JSONLoader();

        loader.load("../../assets/model-threejs.json", function (model, material) {
            console.log('hiiii model: ');
            console.log(model);
            console.log('hiiii loaded material: ');
            console.log(material);

            createScene(model, material);
        });
    }

    function createScene(model, material) {
        var tgaLoader = new THREE.TGALoader();
        console.log('hii tgaLoader' + tgaLoader);

        tgaLoader.load("../../assets/ELEPHANT_DIFF_SPEC.tga", function(texture) {
            var hexColor = "#848081";
            animmesh = new THREE.SkinnedMesh(model, new THREE.MeshBasicMaterial({color: hexColor, skinning: true, map: texture}));
            animmesh.position.set(0,610,0);
            scene.add(animmesh);
            var animation = new THREE.Animation(animmesh, model.animation);
            animation.play();
        });
    }

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

    function render() {

        mirrorCube.visible = false;
        mirrorCubeCamera.updateCubeMap(renderer, scene);
        mirrorCube.visible = true;

        var delta = 10 * clock.getDelta();

        if (animmesh) {
            THREE.AnimationHandler.update(delta);
        }

        renderer.render(scene, camera);

        camera.lookAt(new THREE.Vector3(0,-80,100));
    }

    init();
    animate();

</script>

For reference, here's a screenshot of what I'm observing:

Your assistance would be greatly valued. Thank you.

Answer №1

After encountering the same issue myself today, I wanted to share a possible solution with you in case you haven't found one yet.

The Problem

In utilizing the cube camera for creating an envMap, there is an issue where the floor, positioned at Y coordinate 0, is not captured due to its placement.

A Potential Solution

To address this, consider taking a cube snapshot from the center of the object or slightly above the floor using reflection methods.

var cubeCamera = new THREE.CubeCamera(1, 20000, 1024);
cubeCamera.position.set(0, 130, 0); /* This adjustment may resolve the issue */
scene.add(cubeCamera);

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

Conceal a button using an AJAX POST request

I'm encountering an issue with my Ajax post where I am trying to disable the button used to submit data. I've reviewed my code and it seems accurate, but the button is not getting disabled. I attempted using $("#refreshButton").attr("disabled", t ...

What is the method of adding a child to the outerHTML of the parent element instead of within it?

Is there a way to use the outerHTML method on a parent element to append a child element so that the icons appear outside of the targeted element rather than inside it? The current code snippet shows the icons inside the box, but I want them to be placed o ...

The JSON retrocycle function selectively converts certain references only

I have an array of objects with some cyclic references. To handle this, I used JSON.decycle when sending the object via JSON and JSON.retrocycle on the receiving end. For example: var refactor_data = JSON.retrocycle(JSON.parse(event.data)); The issue is ...

Utilizing pixel values for Material-UI breakpoints rather than using the default sm, md, lg, xl options

Below is the code snippet that I am using: [theme.breakpoints.only('lg')]: {} The above code works perfectly and shifts at the desired breakpoint. However, when I implement the following: [theme.breakpoints.between('1200', '1021&a ...

jQuery: Implementing a function for all elements, including those dynamically loaded through Ajax later on

I have implemented a jQuery function to resize text areas, but I need it to work on all text areas. The function works well for existing text areas: $(document.ready(function(){$("text_area").resizer('250px')}); However, it fails to resize tex ...

Issues with message display validation in jQuery

Validation has been applied to the form, and there are div elements within the input fields with corresponding IDs. The goal is to display error messages within those divs. Specifically, if an input field is missing, the errorMessage should be set in the ...

Instead of using a checkmark, consider using step numbers with Mui Stepper's Completed StepIcon

I'm currently utilizing Mui Stepper from [email protected] within a React project. Despite my efforts to search on platforms like Stackoverflow and Github, I have been unable to find a solution for displaying the step number upon completion inst ...

The bootpag event seems to trigger multiple times upon execution following an Ajax function call

I have integrated the bootpag jQuery pagination plugin from bootpag into my .NET/jQuery project. Within my project, there is a filtering menu that triggers an Ajax call to update the page with filtered or paginated data when a user selects a filtering opti ...

Alert: VirtualizedList warns of slow updates for a large list despite optimized components

Struggling with avoiding the warning message "VirtualizedList: You have a large list that is slow to update" while utilizing the <FlatList> component in React-Native. Despite thorough research and attempts at finding a solution, including referencin ...

Using React in ES5 to create a button that triggers two separate functions with a

I have encountered an issue with two React classes that both contain a render function returning forms with buttons. In class A, I had to import class B in order to use the form from class B. The problem: Whenever I click the inner button, the outer butto ...

When utilizing JavaScript syntax and performing API testing with Postman

Hello, I need some assistance from experts in connecting to Postman using the JavaScript code provided below. When running nodemon, the connection appears to be normal with no errors. Also, the GET request sent to Postman works fine. However, I am encounte ...

Easy Steps to Simplify Your Code for Variable Management

I currently have 6 tabs, each with their own object. Data is being received from the server and filtered based on the tab name. var a = {} // First Tab Object var b = {} // Second Tab Object var c = {} // Third Tab Object var d = {}// Fou ...

Is the array State not setting properly in React Native?

I apologize for the strange request, but I need help with a validation method for form inputs within a modal. Currently, I am checking each this.state.variable and pushing them to an aux array, which is then supposed to be set to the original fieldErrors ...

Attempting to showcase information in React

Having recently delved into React, I am attempting to display data (within a bootstrap modal) from MongoDB to React using an axios ajax request. Postman indicates everything is correct. However, React throws an error stating "TypeError: this.state.reviews. ...

Exploring the functionality of the instanceof operator in Javascript

I'm currently developing a Node.js application and the project structure is as follows: [Project Folder] | |---[plc] | |--- plc.js | |--- scheduler.js | |---[source] | |--- source.js | |---[test] |--- test.js Th ...

Are 'const' and 'let' interchangeable in Typescript?

Exploring AngularJS 2 and Typescript led me to create something using these technologies as a way to grasp the basics of Typescript. Through various sources, I delved into modules, Typescript concepts, with one particularly interesting topic discussing the ...

Ways to transfer ID to a different HTML page

I have some Javascript code in a file named nextPage.js. When this code is executed by clicking on something, it should transfer the value of category_id to another page called reportlist.html. Can you please provide assistance with this? var base_url = " ...

Vue.js: Optimize Webpack bundle by excluding core-js

Below is the content of my vue.config.js file: module.exports = { configureWebpack: { externals: { "vue": "Vue", "core-js": "core-js", }, }, }; By using this configuration, I have successfully excluded the vue.js (Vue) library and ...

Error: Unable to find the specified "location.ejs" view in the views directory

I am encountering the following error - Error: Failed to find view "location.ejs" in views folder "e:\NodeJs_Project\geolocationProject\views" at Function.render Your help in resolving this issue would be greatly appreciated. server.js ...

$injector encountered a problem resolving the required dependency

Currently, I am attempting to adopt the LIFT protocol (Locate, Identify, Flat, Try(Dry)) for organizing my Angular projects. However, I am encountering difficulties in handling dependencies from other files. Here is the factory I have: (function () { ...