Getting started with three.js by initializing an object in close proximity to the camera

Within my three.js project, I have set up my scene and camera as follows:

        var container = document.getElementById('container');

        renderer = new THREE.WebGLRenderer({ antialias: true });
        renderer.setPixelRatio(window.devicePixelRatio);
        renderer.setSize(window.innerWidth, window.innerHeight);
        renderer.setAnimationLoop(render);
        renderer.outputEncoding = THREE.sRGBEncoding;
        renderer.toneMapping = THREE.ACESFilmicToneMapping;
        renderer.toneMappingExposure = 1.25;
        container.appendChild(renderer.domElement);

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

        stats = new Stats();
        container.appendChild(stats.dom);

        //

        camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 0.1, 100);
        camera.position.set(3.5, 2, - 2.5);


        controls = new OrbitControls(camera, container);
        controls.target.set(0, 0.5, 0);
        controls.update();

        scene = new THREE.Scene();
        scene.background = new THREE.Color(0xeeeeee);
        scene.environment = new RoomEnvironment(renderer);
        scene.fog = new THREE.Fog(0xeeeeee, 10, 50);
        ...

Initially, my scene looks like this:

https://i.sstatic.net/2TvuR.png

I want to start with my object doubled in size, like shown here:

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

I attempted the following:

camera.zoom.set(2);

but nothing happened. So I then tried defining a vector3 (2,2,2) and scaling my object:

myobj.scale.set(myVector3);

Still, no change occurred.

Could someone provide guidance on how to start my scene with a larger object size?

Thank you in advance for any assistance.

Answer №1

When adjusting the camera zoom factor to 2, it is crucial to also update the project matrix accordingly:

camera.updateProjectionMatrix();

Another important point to note is that the Vector3.set() method requires three individual scalar values as arguments, not a single Vector3 object. To address this, you can set the scale of an object like so:

myobj.scale.set(myVector3.x, myVector3.y, myVector3.z);

An even more efficient approach would be:

myobj.scale.copy(myVector3);

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

The onMessage listener in Chrome consistently returns an 'undefined' response

My latest project involves creating a simple chrome extension that utilizes message passing. The goal of the extension is to listen for messages from a specific website (in this case, localhost:8080/*) and respond with a simple "Bye". To test this function ...

Pytest is not able to locate any elements on the webpage, yet the same elements can be easily found using the console

When using CSS or XPath in the console (F12), I am able to locate the element on the page. $$("span.menu-item[data-vars-category-name='Most Popular']") However, when trying to find the same elements with Selenium (pytest) using: driver.find_el ...

Navigate the user directly to the page where the event date aligns with today's date for easier access to relevant events

I have a function that retrieves posts, but I want users to be directed to a page where posts have a date of "today" that is not the event's publish date but the date when the event is happening. For example, if I have events with a man_date field of ...

Having trouble sending POST requests in Express?

I developed an API and all the routes were working perfectly until now. However, when I attempted to send a POST request to the "/scammer" route, I encountered the following error message: Error: write EPROTO 1979668328:error:100000f7:SSL routines:OPENSSL_ ...

Handling redirection on a single-page website without javascript functionality turned on

Currently, I am in the process of creating a single-page website using html, css, javascript, and php. My aim is to use jQuery for navigating through the website - allowing the content to fade out when a user clicks on a link in the navigation menu and hav ...

AngularJS is failing to properly register custom directives

Looking to enhance the SEO caching capabilities of my AngularJS website, I've embarked on implementing a couple of directives for custom page titles and descriptions. Incorporated within my app config (angular.module('website', [...'we ...

Add an input element to a form fieldset by employing vue

In my form, I have a staged approach with 3 fieldsets that only appear when the "Next" button is clicked. Now, in the third fieldset, I need to add input elements based on keys extracted from an external json object. Data: data: () => ({ c ...

Using Javascript's Speech Recognition to activate a button

I am new to using JavaScript Speech Recognition and decided to work with the Annyang library. My goal is to automatically trigger the "show date" button when the user says 'hello', without actually clicking the button. However, I've been fac ...

Embedding Array into Mongodb is an efficient way to store and

Whenever I attempt to store array data within MongoDB using the query below, it always shows a success message without actually storing any data in an empty array inside MongoDB. My goal is to successfully store array data inside MongoDB as shown in the f ...

What is the best method to pass a JavaScript file array to a Node.js server?

Is it possible to transfer data from a Javascript file linked to an HTML page to a Node.js file on a post route without displaying it on the HTML page? If so, what is the best way to accomplish this? ...

Guide on how to modify the color of a single row within a table with just a click

My table structure is as follows: <table> <tr> <td>A1</td> <td>A2</td> <td>A3</td> <td>A4</td> </tr> <tr> ...

Splitting a JSON array into two separate arrays of values using jQuery: a step-by-step guide

My AJAX script is pulling a JSON array from a PHP file. Here's the script: // jsonData fetched from inc/wip-data.php var jsonData = $.ajax({ url: 'inc/wip-data.php', dataType: 'json', }); The JSON array looks like this: [ { ...

The componentDidMount event of the child component is throwing an error due to the parent state being

I'm experiencing an issue where the value passed from the parent component to the child component via props is showing as undefined when logging it in the componentDidMount event of the child component. I need this value to be properly updated and acc ...

"Troubleshooting tip: encountering a SyntaxError message stating 'import declarations may only appear at top level of a module'? Here's

After downloading fetch-jsonp by running npm i fetch-jsonp and adding its dependency to my package.json, I attempted to import it using the following code at the top of my main.js: import fetchJsonp from 'fetch-jsonp'; However, I kept encounter ...

Developing with Phonegap Build: A Guided Process

With all the conflicting information available, I am seeking clarity on this topic. Objective: To create and enhance a Phonegap app using Phonegap Build. 1) My preference is to utilize Phonegap Build without needing to install Android and iOS SDKs. 2) I ...

Tips for Deactivating a Multi-Select Dropdown Upon Page Load and Reactivating it According to Another Dropdown's Value

There are two MultiSelect dropdowns on this page. The functionality I am looking for is as follows: Upon loading the page, I want the multiselect02 field to be disabled. Only when I choose the option "Item2" from multiselect01, do I want the multiselect ...

The ultimate guide to removing a targeted form input using jquery

My HTML form contains two text inputs: <form id="insert_amount",onsubmit="submitAmount();return false;"> **input(type="text",placeholder="Your message",name="message")** **input(type="text",placeholder="Your amount",name="amount") ...

Placing elements from an array into a customized output

Currently, I am dealing with a unique output: dAmn_Raw('send chat:Sandbox\n\nmsg main\n\nthismessage'); In my code, there exists a variable: myvariable that stores a random value selected from an array I formulated. The cha ...

What is the best way to set a checkbox's default state in a react table using a value from Firestore?

Is there a way to initialize the checkboxes in React Table based on values from Firestore? I've tried reading the official documentation and looking at some examples, but I'm still confused about how to achieve this. My goal is to retrieve a val ...

Create data according to jQuery's AJAX data method

When editing in place using jQuery, if the code snippet seems too complicated, please refer to a simpler one. 'column2' => "RAJANgsfdgf" 'column3' => "SRARDHAMgsdfgdf" 'column4' => "40043433" 'column7' =&g ...