Three.js - Adjusting Camera Placement

I'm struggling to figure out how to load an object that covers almost the entire width and height of the canvas.

 <script>

        var scene               = new THREE.Scene();
        var camera              = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
        var renderer            = new THREE.WebGLRenderer();
        var loader              = new THREE.STLLoader();
        var mesh;

        renderer.setClearColor(0xFFFFFF, 1);

        renderer.setSize( window.innerWidth, window.innerHeight );
        document.body.appendChild( renderer.domElement );

        loader.addEventListener( 'load', function ( event ) {
            var geometry = event.content;
            var redPhongMaterial = new THREE.MeshPhongMaterial({ color: 0xFFEA32, side: THREE.DoubleSide, ambient:0x000000});
            mesh         = new THREE.Mesh( geometry, redPhongMaterial )
            mesh.castShadow = true;
            mesh.receiveShadow = true;
            geometry.computeBoundingBox();
            var boundingBox = mesh.geometry.boundingBox.clone();
            drawBoundingBox(boundingBox, mesh.scale.x, mesh.scale.y, mesh.scale.z);
            mesh.translateX (0);
            mesh.translateY (0);
            mesh.translateZ (0);
            scene.add( mesh );

        } );
        loader.addEventListener( 'progress', function ( event ) {
            document.getElementById('progress').innerHTML = 'Progress: '+event.loaded+'%';
        });
        loader.addEventListener( 'error', function ( event ) {
            alert( event.message );
        });
        loader.load( 'pet.stl' );

        camera.position.set( 15, -10, 120 );

        render();

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

    </script>

I believe adjusting the camera's position along the x, y, and z axes may help, but I'm unsure.

Any suggestions on how to achieve this?

Answer №1

Updating the camera position based on the maximum value among x*3, ys*3, and z*3.

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

Please send the element that is specifically activated by the onClick function

This is the HTML code I am working with: <li class="custom-bottom-list"> <a onClick="upvote(this)"><i class="fa fa-thumbs-o-up"></i><span>upvote</span></a> </li> Here is my JavaScript function for Upvot ...

Using multiple module.exports in mongoose

Hey everyone, I'm facing an issue that I could use some help with. I have 2 collections on mlab, but they are essentially the same database. The problem arises when my code is only saving data to one collection. Any ideas on what might be causing this ...

Using Javascript to pass the value of a selected checkbox

I am having an issue with passing a row value to a different function when a user clicks on a checkbox in the last column of a table. The code I have written doesn't seem to be firing as expected. Can anyone help me figure out what might be missing in ...

Using JsGrid to efficiently load nested object data into a table

Currently, I am in the process of developing a web project using Django and implementing jsGrid. However, I have encountered an issue for which I cannot seem to find a solution. The problem lies with my nested JSON data that is generated by merging record ...

It is necessary for the listener to be a function when handling a socket.io event

I decided to revamp my socket.io server to avoid the notorious "callback hell". Currently, I am exploring the option of listening for an event and passing a function exported by a module as the callback instead of using an anonymous function. My goal is t ...

Is there anyone who can clarify the operations happening within this Three.js StereoEffect code?

Is there anyone knowledgeable in stereo rendering who can provide an explanation of how these functions work together to achieve the VR stereo effect? Information on functions like StereoCamera(), setScissor(), setViewPort() in the three.js library seems s ...

Ways to verify whether a callback function supplied as a parameter in Javascript has any arguments

My task involves implementing the following: doSomething .then(success) .catch(failure); The success and failure functions are callbacks that will receive their value at runtime (I am developing a module). Therefore, I need to ensure that the fa ...

The ability to submit a conversation chat is currently

I encountered an issue when attempting to submit a chat, and I received the error message 'handlebar is not define'. I followed the code tutorial provided in this link: https://codepen.io/drehimself/pen/KdXwxR This is the screenshot of the error ...

Angular Error: Issue: Unable to locate the specified column ID within the TS file

Within my application, I have a table containing multiple columns. I am attempting to populate it with the appropriate data, but upon opening the page, I encounter the error Could not find column with id "PublishedParty", despite it being present ...

Instructions for setting up a session where the user can input data at a later time

Is there a method to save user input so that they can return to continue filling out a form from where they left off? I am in need of assistance as I am unsure of the optimal way to achieve this. Thank you in advance for any help. ...

Personalized Navigation Bar Toggle (transitioning from dropdown to sliding from the left)

On larger screens, I would like the navigation/navbar to be positioned at the top. However, on mobile view or when collapsed, I want the toggle button to reveal the navigation menu by sliding from the left side, similar to this example: (source by David B ...

Unable to modify an element within an array using findIndex

Struggling with updating a value within an array, my research has not yielded a working solution. I have encountered multiple issues. Array = [{ val1: "1", val2: "2", nameval: "name", val4: "3" },{ val1: "4", val2: "5", nameval: "name", val4: ...

The table in React does not update after sorting the elements in the state, causing the list to not re-render

I'm encountering a problem with React where the data is not rendering properly after sorting the table. Even though I am updating the state variable using setState, the new updated data does not appear on the screen. Here's the snippet of my code ...

Encountering errors when importing a JS file into a Vue project

I recently attempted to utilize the plugin https://www.npmjs.com/package/mobius1-selectr After running npm install mobius1-selectr I proceeded to import it into my main.js import 'mobius1-selectr/dist/selectr.min.css'; import 'mobius1-sel ...

javascript has a funny way of saying "this is not equal to this" (well,

Sample 1 var Animal = function () { var animal = this; this.makeSound = function() { alert(animal.sound); } } var dog = new Animal(); dog.sound = 'woof'; dog.makeSound(); Sample 2 var Animal = function () { this.makeSound = ...

jquery click event triggers changes on several elements sharing a common class

I am looking to incorporate auto play functionality for a YouTube video on my video style page, which can be found at . Currently, I am able to trigger the video to auto play by clicking on an image thumbnail using the code below. However, I am encounterin ...

Methods for setting the value of a scope variable within a controller's function

I have a goal of presenting a page that calculates a balance in the background and displays it. To achieve this, I decided to separate the balance into its own directive. Here is the directive I have created: app.directive('smBalanceInfo', fun ...

The maxBodySize feature is ineffective in restify

I am currently running a node app on version v0.10.33 with the Restify module ^2.8.3 installed. var app = restify.createServer(); app.use(restify.queryParser()); app.use(restify.bodyParser({ maxBodySize: 1, //Issue: The limit is not being enforced at th ...

Refresh an iframe smoothly and without any visual distraction (using JavaScript)

Does anyone have a clever solution to dynamically refresh an iframe without the annoying flickering or flashing that usually occurs when the page reloads? Is it possible to incorporate a smooth blur-out and blur-in animation instead of the unappealing flic ...

Tips for locating a specific HTML element within a string

Trying to convert a website into a phonegap app is proving to be challenging for me. When I send a request to the server, it responds with the HTML content as text. My goal is to extract certain HTML elements from this text and then append them to a div in ...