The Three.js camera imported from Collada is unable to properly focus on an object within the scene

Having some trouble grasping the concept of Collada Animation in Three.js! I have an animation with a moving camera in 3Dsmax, and exported the scene into Collada.

loader.load( ColladaName, function ( collada ) {

    model = collada.scene;
    model.updateMatrix();
    animations = collada.animations;
    kfAnimationsLength = animations.length;
    model.scale.x = model.scale.y = model.scale.z = 0.001; // 1/8 scale, modeled in cm
    document.getElementById('preload').style.opacity = '0';

    callback()

} );

I extracted the camera object from the collada:

 model.traverse(function(child) {

    if (child instanceof THREE.PerspectiveCamera) {

        camera = child;
        camera.near = 1;
        camera.fov = 30;
        camera.castShadow = true;
    }

    if (child instanceof THREE.SpotLight) {

        child.castShadow = true;

        child.shadowBias = 0.02;

        child.shadowCameraNear = 1;
        child.shadowCameraFov = 60;
        child.intensity = 1.2;

        child.shadowMapWidth = 1024; // default is 1024
        child.shadowMapHeight = 1024; // default is 1024
        child.shadowDarkness = 0.06; // default is 512

    }

});

 camera.aspect = window.innerWidth / window.innerHeight;

 camera.updateProjectionMatrix();

Next, I rendered it in my scene: camera.lookAt(scene.position) renderer.render(scene, camera);

Everything appears on the screen, I can see my model with the imported camera, but unfortunately my camera does not focus on the scene and doesn't replicate the x-rotation as in my 3Dsm zoom in and out! Whenever I log the camera position, it always shows: 0,0,0. Furthermore, if I log the model.children[0] position, which corresponds to the perspective camera imported from the collada, it also shows 0,0,0.

What could be causing this issue?

EDIT 1:

I attempted to update my camera matrix using the imported camera from the Collada file:

camera.matrixNeedsUpdate = true;
model.children[0].matrixNeedsUpdate = true;
model.children[0].lookAt(model.position)

camera.matrix.elements = model.children[0].matrix.elements

Unfortunately, I didn't see any noticeable results.

Answer №1

It seems like the issue could be related to using camera.lookAt() with a position in "local space".

You may want to attempt the following solution:

var coords = new THREE.Vector3();
coords.setFromMatrixPosition( targetObject.matrixWorld );

camera.lookAt( coords );

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

A more efficient method for refreshing Discord Message Embeds using a MessageComponentInteraction collector to streamline updates

Currently, I am working on developing a horse race command for my discord bot using TypeScript. The code is functioning properly; however, there is an issue with updating an embed that displays the race and the participants. To ensure the update works co ...

Sharing data from a Provider to a function in React can be done through various methods

After developing an NPM library that contains various utility functions, including one for calling endpoints, I encountered a roadblock when trying to set the Axios.create instance globally. Initially, my idea was to create a Provider and establish a cont ...

Three.js seamlessly transitions between three different backgrounds without interruption

I'm currently delving into my first project using three.js and it has been quite a learning experience. However, I've reached a roadblock and I am in need of a general outline on what steps to take next. My project involves three images that I w ...

What could be the reason for the malfunction of Bootstrap Js in my template?

This question focuses on understanding how something works rather than just fixing it. I really enjoy learning about this. Currently, I am involved in a project that combines VueJS and Symfony. One of the things I would like to achieve is using Bootstrap ...

Contrast between Q.defer() and the Promise() function

I am puzzled by the differing behavior of the following code when using Q.defer() as opposed to Promise() Scenario 1 : When Q.defer() is used getDocument(id) .then(function (response) { console.log('in first then') return 'from tw ...

Reposition the Column, Filter popover within the MUI Data Grid Pro

I am working with the MUI Data Grid Pro to showcase my data. By default, the Data Grid Pro exhibits the toolbar on the left side. Although I managed to shift the toolbar to the right side, the popovers and menus retained their position on the left. My inte ...

The width of the Bootstrap row decreases with each subsequent row

I'm having trouble understanding this issue, as it seems like every time I try to align my rows in bootstrap, they keep getting smaller. Can anyone point out what mistake I might be making? ...

Every time I try to call the event in jQuery for the second time, it fails to work

I am currently working on a website that features an image gallery powered by the jquery wookmark plugin with filtering capabilities. Recently, I integrated the colorbox plugin (which was provided as an example by wookmark) to enhance the user experience. ...

Exploring the power of the JavaScript this keyword

Can you explain the purpose of the line this.tasks = tasks; in relation to the constructor method? class TaskCollection { constructor(tasks =[]) { this.tasks = tasks; } } ...

Node unable to interpret accented characters from CSV file input

Currently, I am utilizing npm fast-csv as my CSV reader/writer tool. It offers a simple and straightforward way to handle CSV files. My goal is to use this tool along with iconv to deal with "accented" characters and non-ASCII characters by converting them ...

Accessing data outside of the scope when looping through items in Angular forEach

I am currently working on retrieving the Game ID generated by the APIService.postData method for the game. The goal is to utilize this Game ID within the Angular foreach loops to maintain foreign key constraints on the RESTful side. Any advice on extracti ...

Convert the user input into a div by clicking a button

Here is the code snippet I am currently using: $(document).on('click', '#editDetailBtn', function () { var input = $('<input id="#detailprimaryDescription" type="text" />'); input.val($('#detailprimaryDes ...

Tips for integrating JQuery into a JavaScript file seamlessly without causing conflicts

Similar Question: Dynamically Including jQuery using JavaScript if it's not already present I am currently working on a project that requires users to embed a piece of javascript code on their websites, similar to Google Analytics. My main concer ...

Unable to prevent ordered lists from overlapping with other content I attempt to place beneath them in HTML

function filterImages() { let input = document.getElementById('searchbar').value; input = input.toLowerCase(); let images = document.getElementsByClassName('gallery'); for (let i = 0; i < images.length; i++) { ...

Exploring the ancestors of an element

JS <script> $('.btn').click(function(e){ target = e.target; parent = target.parentNode.parentNode; console.log(parent); }); </script> HTML <div class="card" sty ...

The functionality for tabbed content seems to be malfunctioning on Chrome and Firefox, however it works perfectly

In my index.js file, I have various functions set up like so: // a and b is placed at index.jsp $("#a").click(function (){ //this works on index.jsp and display.jsp(where the servlets forwards it). $("#b").load('servletA.html?action=dis ...

Custom Tooltips arrow is not receiving the CSS styling

I have implemented ReactTooltip from the ReactTooltip library You can view an example here Component Setup <ReactTooltip className={styles.customTheme} id={id} place={placement} effect="solid"> {children} </ReactTooltip> Stylin ...

javascriptchange the format from <string, string[]> to <string, string>

In my code, I came across a JavaScript object that consists of key/value pairs. Each value in this object is an array of strings: var errors = { "Message": ["Error #1", "Error #2"], "Email": ["Error #3", "Error #4"] }; My goal is to transform thi ...

What is the best approach to display data in React fetched from an API request? If this is not the right method, what changes should be made to the JSX rendering to convert

As I begin my journey with React, I find myself questioning the best practices for displaying data. Should I always break down components into smaller ones rather than having one large component render everything? It seems like a good practice, but I' ...

A guide to categorizing and tallying JSON data based on multiple keys within the past 30 days using JavaScript/jQuery

I am facing an issue while trying to display a chart and extract specific data from an array. My goal is to generate a chart based on three columns in a JSON array: Source, Campaign, and Date. The process involves grouping the data, counting it, and then ...