Having difficulty rendering the Three.js OBJ model

Greetings everyone, I recently attempted to load a 3D OBJ file using a Loader in my project. The console indicates that the 3D model and texture have been successfully loaded, but unfortunately, nothing appears on the screen. I extracted the 3D model and texture from the three.js files, but it seems like something is not working as expected. If anyone could provide some insight into what might be causing this issue, I would greatly appreciate it. Here is the link to download the zip file if it helps:

var container;

var camera, scene, renderer;

var mouseX = 0, mouseY = 0;

var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;

init();
animate();

function init(){

    container = document.createElement('div');
    document.body.appendChild(container);

    camera = new THREE.PerspectiveCamera(45, window.innerWidth /   window.innerHeight, 1, 2000);
camera.position.z = 100;

//Scene
scene = new THREE.Scene();

//Light
var ambient = new THREE.AmbientLight(0x101030);
scene.add(ambient);

var directionalLight = new THREE.DirectionalLight(0xffeedd);
directionalLight.position.set(0,0,1);
scene.add(directionalLight);

//Texture
var manager = new THREE.LoadingManager();
manager.onProgress = function(item, loaded, total){
    console.log(item, loaded, total);
};

var texture = new THREE.Texture();

var onProgress = function(xhr){
    if(xhr.lengthComputable){
        var percentComplete = xhr.loaded / xhr.total * 100;
        console.log(Math.round(percentComplete, 2) + '% downloaded');
    }
};

var onError = function(xhr){};

var loader = new THREE.ImageLoader(manager);
loader.load('textures/brick_diffuse.jpg', function(image){
    texture.image = image;
    texture.needUpdate = true;
});

//Model
var loader = new THREE.OBJLoader(manager);
loader.load('models/tree.obj', function(object){
    object.traverse(function(child){
        if(child instanceof THREE.Mesh){
            child.material.map = texture;
        }
    });

    object.position.y = -80;
    object.scale.set(5,5,5);
    scene.add(object);
}, onProgress, onError);

//Model
var anotherLoader = new THREE.OBJLoader(manager);
anotherLoader.load('models/tree.obj', function(object){
    object.traverse(function(child){
        if(child instanceof THREE.Mesh){
            child.material.map = texture;
        }
    });

    object.scale.set(5,5,5);
    scene.add(object);
}, onProgress, onError);

renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild(renderer.domElement);

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

}

function onWindowResize(){
    windowHalfX = window.innerWidth / 2;
    windowHalfY = window.innerHeight / 2;

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

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

function onDocumentMouseMove(event){
    mouseX = (event.clientX - windowHalfX) / 2;
    mouseY = (event.clientY - windowHalfY) / 2;
}

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

function render(){
    camera.position.x += (mouseX - camera.position.x) * .05;
    camera.position.y += (- mouseY - camera.position.y) * .05;

    camera.lookAt(scene.position);

    renderer.render(scene, camera);
}

Answer №1

Before exporting a .obj file from Cinema 4D, remember to check that your scale is set to 1. If you need a bigger object, consider scaling it either in Cinema 4D or in three.js. Additionally, I recommend converting your units from centimeters to feet for better accuracy.

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

Is it possible for Masonry to incorporate RTL (Right-To-Left) direction?

Before, Masonry worked perfectly with the Left-To-Right text direction. Now, I need to adjust it for use with Right-To-Left (RTL) languages like Hebrew and Arabic. When I try running Masonry with RTL text direction, the plugin still lays out the grid in a ...

Is there a way to inform TypeScript that the process is defined rather than undefined?

When I execute the code line below: internalWhiteList = process.env.INTERNAL_IP_WHITELIST.split( ',' ) An error pops up indicating, Object is possibly undefined. The env variables are injected into process.env through the utilization of the mod ...

Differences Between Object.keys().map() and Array.map()

I'm seeking a rationale for why Approach A is considered superior to Approach B. Approach A: const transformCompanyOptions = (companies: Array<{id: string, name: string}>, selectedId: string) => { return companies.map(key => { retu ...

guide on creating a simple line highchart using JSON data

Here is the JSON data I have: {"09/02/2014 15:36:25":[33.82,33.42,40.83],"08/11/2014 16:25:15":[36.6,33.42,40.45],"07/30/2014 08:43:57":[0.0,0.0,0.0],"08/12/2014 22:00:52":[77.99,74.1,80.12],"08/12/2014 21:19:48":[56.91,63.23,52.42],"07/23/2014 13:37:46": ...

Utilizing Draft JS to dynamically insert text in the form of span

I'm utilizing Draft.js with its mentions plugin. Occasionally, I'd like users to input a mention not by choosing from a dropdown menu, but by typing something like, for example, "@item" or "@item". In the function below, you can observe that if ...

Is there a way to streamline the form completion process on my website by utilizing voice commands through the user's microphone?

My webpage features a web form using Flask where users manually input their information that is then added to a table upon submitting. The current setup involves an autoplay video prompting users with questions, which they answer manually and then submit t ...

Sending dynamic internationalization resources from Node.js to Jade templates

Looking for a way to show a custom error page to the user in case of an error, but it needs to be internationalized (i18n-ed). Solution: My idea is to validate in node -> if not accepted -> res.render('error', {message: errorMessageNameToo ...

What could be causing the inability to move down on this page?

Trying to scroll down a page using Selenium with Python and the execute_script command, but encountering issues. Despite executing the code provided below, I am unable to reach the bottom of the page: def create_browser(first_page=None): print "Starti ...

Validate with JavaScript, then display and submit

I've created a submit function to verify form inputs, and then, if desired (via checkbox), print as part of the submission process. The issue is that when printing, the form submission never finishes. However, without printing, the form submits corre ...

How can the communication be improved between a JSP page and a Java object?

In the midst of a project involving a java back-end and web page UI, my goal is to integrate the two seamlessly. The java system functions on the server, storing rules created within the web page's interface. To achieve this, I am seeking a way for te ...

Encountered a module build failure due to the inability to resolve the 'bootstrap-sass' module, a required installation when configuring bootstrap version v3

Encountered an error while building an angular project: ERROR in ./~/bootstrap-loader/lib/bootstrap.loader.js!./~/bootstrap-loader/no-op.js Module build failed: Error: Could not resolve module 'bootstrap-sass' which must be installed when bootstr ...

What is the process of embedding a Vue.js application into an already existing webpage using script tags?

My goal is to integrate a Vue.js application into an existing webpage using script tags. Upon running `npm run build` in my Vue application, I end up with 7 compiled files: app.js app.js.map manifest.js manifest.js.map vendor.js vendor.js.map app.css In ...

Tips for correctly importing modules into a threejs project

I've been trying to include modules in order to utilize the bloom effect, however, I keep encountering this error message. The .js files were copied from three/examples/js/, so they are current. index.html: <script src="../module/three.js&quo ...

Creating dynamic grids in React.js by utilizing HTML

Currently, I am tackling one of the projects on FCC which is the Game of Life. Prior to diving in, my focus is on figuring out how to render a grid on the page. I aim to modify the table dimensions while ensuring it fits neatly within its container. The ...

Which is better for creating a curved plane surface: CSS3 or Three.js?

Is it possible to achieve a curved plane surface resembling the one shown in the image using CSS3 or Three.js? ...

Is there a way to guide users to their designated page on Node.js?

My goal is to seamlessly redirect users to their designated pages based on their role. If the user is a regular user, they should be redirected to the user menu. On the other hand, if it's an employee, they should be directed to the employee menu. E ...

"Using JavaScript to trigger a button click event, and then

I have a question that I think may sound silly, but here it is. I have this code snippet: <script type="text/javascript"> $(document).ready(function(){ var email_value = prompt('Please enter your email address'); if(email_value !== null){ ...

Struggling to understand the implementation of webpack's require.context() method

I'm currently working on an AngularJS project with webpack, and I'm looking for a way to import all the .js files in my project into webpack without manually adding each file path. Upon reviewing the webpack documentation, I came across the requi ...

Instruct Smarty to display the block exactly as it is

Struggling to inline some JavaScript code into the Smarty template files due to the {ldelim} {rdelim} markers. Is there a way to instruct Smarty to disregard the markup and just output it as is? Any similar approach like CDATA blocks in XML? Just demonstr ...

Displaying JSON data using Vue.js

fetching JSON data save movieData: {} ...... retrieveMovieData (context, parameter) { axios.get(API.movieData + parameter.id) .then(response => { context.commit('MOVIE_DATA', response.data) }) .catch(error => ...