Blank white screen issue in Three JS while loading JSON object

I have recently downloaded threejs and am attempting to create a 3D environment where users can freely move around in an "ego perspective". To start, I used the pointlock-control example as a reference and now I'm trying to add my own elements, beginning with a car model created in Blender and exported as JSON. However, every time I try to load the car model, all I see is a blank white screen. I'm hoping someone here can assist me with this issue.

Code:

<style>
        html, body {
            width: 100%;
            height: 100%;
        }

        body {
            background-color: #ffffff;
            margin: 0;
            overflow: hidden;
            font-family: arial;
        }

        #blocker {
            position: absolute;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
        }

        #instructions {
            width: 100%;
            height: 100%;
            display: -webkit-box;
            display: -moz-box;
            display: box;
            -webkit-box-orient: horizontal;
            -moz-box-orient: horizontal;
            box-orient: horizontal;
            -webkit-box-pack: center;
            -moz-box-pack: center;
            box-pack: center;
            -webkit-box-align: center;
            -moz-box-align: center;
            box-align: center;
            color: #ffffff;
            text-align: center;
            cursor: pointer;
        }

    </style>
</head>
<body>
    <script src="../build/three.min.js"></script>
    <script src="js/controls/PointerLockControls.js"></script>
    <div id="blocker">
        <div id="instructions">
            <span style="font-size:40px">Click to move</span>
            <br />
            (WASD or Arrow Keys = Move, SPACE = Jump, MOUSE = Look around)
        </div>
    </div>
    <script>
        // Your JavaScript code goes here...
    </script>
</body>

Answer №1

const hits = raycaster.intersectObjects( targets );
Make sure you have included your mesh in the 'targets' array.

Answer №2

The camera lacks both position and target information.

Answer №3

The background color of the body and the text "color" in the instructions are currently set to #ffffff in the style.

To avoid confusion, please change one of them and then test it out :)

While it may be generating output, you might not be able to see it clearly,

Update:

In the section where you add a scene with scene.add(mesh2);, I suggest sticking to the working code provided below and refreshing the scene using a loop or timer (every 0.05 seconds) instead of adding a new scene. Start with a simple example like moving around a round object before progressing to more complex objects, as this approach can prevent possible confusion.

Working Code:

loader = new THREE.JSONLoader();
loadModel = function (geometry) {
    mesh2 = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({
                envMap : THREE.ImageUtils.loadTexture('textures/metal.refl.jpg', new THREE.SphericalReflectionMapping()),
                overdraw : true,
                shading : THREE.SmoothShading
            }));
    mesh2.scale.set(1, 1, 1);
    mesh2.position.set(0, 0, 0); 
    //mesh.rotation.set(Math.PI/2, Mat.PI/2, Math.PI/2); 
    //mesh.matrix.setRotationFromEuler(mesh.rotation); 
    scene.add( mesh2 ); 
};

If the issue persists, feel free to leave a comment.

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

Modify background color when a column is clicked in a dynamically filled table

I'm in the process of dynamically generating an HTML table as shown below: for (var i = 0; i < rowsToAdd; i++) { var tr = table.insertRow(-1); var colsToAddLength = findColsToAddLength(); for (var j = 0; j < colsToAddLength; j++) { ...

Implementing a click event listener to target a specific div using JavaScript

In my JavaScript code, I have implemented a snowfall effect. I am looking to create a click event specifically on the 10th snowflake that falls down. Additionally, I want to add a class called "clickable" to this snowflake. The goal is to redirect the user ...

Production environment experiences issues with Angular animations

In my MEAN stack application, I started with Sails.js. Everything was working smoothly during development, especially with angular-animate. However, once I changed the Sails environment to production, I encountered issues. Grunt is set up to concatenate a ...

Looking to execute a PHP script upon form submission

I have a form that I need to submit in order for a PHP script to run using AJAX. <form method="post" action="index.php" id="entryform" name="entryform"> <input type="submit" name="submit" value="Submit" onclick="JavaScript:xmlhttpPost('/web/ ...

What is the method for retrieving the output of a command?

I am working on a project where I am developing a WebApp that is capable of sending commands to Linux servers. To achieve this functionality, I am utilizing Javascript/jQuery on the client side and Node.js on the server side. Below is an excerpt of my code ...

Can someone explain the purpose of $event in Angular Material and whether it is necessary when using UI Router?

As I explore this unanswered question, I can't help but ponder if discovering the answer is truly important. My search for information on $event has led me through Angular Material and material docs, yet no mention of it exists. The only reference I f ...

When I use .fadeToggle, my div transitions smoothly between visible and hidden states

Looking to create a sleek navigation menu that showcases a colored square when hovered over? I'm currently experiencing an issue where the squares are not aligning correctly with the items being hovered. Switching the position to absolute would likely ...

Sending an array of objects over socket io: A step-by-step guide

Recently, I've been struggling with an issue when trying to send an array of objects through socket io. This is my server-side code: var addEntity = function(ent) { entityBag.push(ent); }; var entityBag = []; addEntity(new Circle({ ...

Can someone help me with retrieving items from local storage and displaying them in my list view?

I am currently working on creating a Todo list that includes two values: "Title" and "Detail". I have successfully managed to store items in my local storage. However, I am facing challenges in retrieving the stored items from the local storage and display ...

Utilizing $resource within a promise sequence to correct the deferred anti-pattern

One challenge I encountered was that when making multiple nearly simultaneous calls to a service method that retrieves a list of project types using $resource, each call generated a new request instead of utilizing the same response/promise/data. After doi ...

Only when the canvas Div becomes visible, WebGL Three.js will start loading

In my HTML5 application, I am utilizing three canvases. Two of these canvases hold a WebGL 3D scene that is rendered using Three.js. These canvases are contained within a custom slider that displays only one canvas at a time in full window size. The issue ...

Vue Component, switching state

Feeling like I'm losing it, this should be really simple but it's not working... The idea is that when the link is clicked, the display property toggles between true and false. However, it's not working as expected. Vue.component('d ...

Using express.js to send multiple post requests to the same url

My website features a login form where users input their information. Upon submission, a post request is made to check the validity of the provided information. If successful, users are redirected back to the login form where they must enter the code sent ...

Embed a React component within another component

Recently, I've started learning React and I'm utilizing material-ui for my project. My goal is to create a customized autocomplete feature in React where selected data from the dropdown will appear as chips inside the text input field. I am curre ...

Determine if a SQL column exists following a SELECT statement

I have a query that I need help with: let selectQuery = "select * from mainTable where username = '"+ username + "'"; In my code, I am trying to make sure that childtable2id exists in the table. Here is what I have so far: for (let i = 0; i & ...

Updating an array element in Mongoose, the MongoDB ORM

I am currently in the process of making changes to a MongoDb collection that contains an array of documents called items. To achieve this, I am utilizing the express and mongoose frameworks. This is how my schema is structured: const mongoose = require(" ...

Can you include conditional logic within a switch statement?

I've been using if, else if, and else statements in my code but recently switched to switch statements which have made things much simpler. Now I'm wondering if it's possible to add multiple conditions inside a switch statement, similar to i ...

Choose the span element within every other td that is not enclosed by an anchor tag

The table structure I am working with is as follows: <tr> <td> <a> <span> some content </span> </a> </td> <!-- td having straight span --> <td> <span> ...

What are some ways to avoid the use of underline and slash symbols in material-ui/pickers?

Is there a way to remove the underline and slash characters that separate day, month, and year in the material ui pickers for version mui version 4? <KeyboardDatePicker margin="normal" id="date-picker-dialog" label="Dat ...

Implementing the sorting feature in Angular JS to properly align sub sections with their correct parent sections

I'm facing an issue with the functionality of my sample code. Users can add sections and subsections within those sections, which are sortable using ui-sortable. However, after sorting the items, if I try to add a new sub-section to Section 2, it wron ...