The scene is filled with meshes, but all that can be seen is the renderer's clear color

I am currently experimenting with Three.js and jQuery to develop a small visual application. My main objective is to display all the meshes I have on the screen.

The Issue: Unfortunately, none of the meshes are visible on the screen at all.

Observations: Despite the meshes not appearing, the renderer's clear color (0x00bfff) is visible, and upon checking console.log(scene), it confirms that all the meshes exist within the scene.

Efforts to Rectify: I have tried various solutions including using THREE.Projector, THREE.Raycaster, adjusting camera positioning, and several other attempts.

Being new to Three.js and programming in general, I welcome any feedback or criticism regarding my work. Any help would be greatly appreciated! Thank you!

WORLD.JS

$(document).ready(function() {
    initialize();
    animate();
});

var initialize = function() {
    clock = new THREE.Clock();

    scene = new THREE.Scene();

    camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, .1, 10000);
    camera.position.set(25, 25, 125);
    camera.lookAt(scene.position);

    setupEnvironment();

    setupAI();

    renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.setClearColor(0x00bfff, 1);
    document.body.appendChild(renderer.domElement);
};

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

var render = function() {
    var delta = clock.getDelta();

    renderer.render(scene, camera);
}

var setupEnvironment = function() {
    // Environment setup code here
};

var setupAI = function() {
    // AI setup code here
};

function BoxMesh(width, height, depth, hexColor, amount) {   
    // BoxMesh constructor definition
}

var positionThenAdd = function(varMesh, posArrXByZ) { 
    // Positioning function definition
};

HTML FILE

<!DOCTYPE html>
<html>
<head>
    <title>Custom World Title</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            border: 0;
        }
    </style>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="mrdoob-three.js-d6384d2/build/Three.js"></script>
    <script src="mrdoob-three.js-d6384d2/examples/js/renderers/Projector.js"></script>
    <script src="world.js"></script>
</head>
<body></body>
</html>

Answer №1

There are a couple of issues with your code:

  • Within your positionThenAdd function, at the line position.set(...), you mistakenly used ground.height. Instead, you should use

    varMesh[mesh].geometry.parameters.height
    as ground is an array.

  • Your console may display an error stating that positionThenAdd is not a function. This is because while you defined previous functions using the syntax function myFunction(){....}, you defined this one differently as

    var positionThenAdd = function () { ... };
    . To fix this, change its declaration to function positionThenAdd(){...}. For more information, refer to this resource.

Access your scene here: http://jsfiddle.net/ba8vvkyg/1/

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 there a way to make my red div switch its background color from red to green when I press the swap button?

How can I make the red div change its background color to toggle between red and green when I click on the swap button in the following code? $(document).ready(onReady); var numberOfClicks = 0; function onReady() { console.log('inside on ready ...

Struggling to make antd compatible with my create-react-app project

Exploring ant.design with create-react-app piqued my interest, so I decided to follow the steps outlined in the antd documentation. https://ant.design/docs/react/use-with-create-react-app npx create-react-app antd-demo npm add antd Within the app.js fil ...

A React child error has occurred in Next.js due to invalid objects being used

Within my project, I have integrated the latest version of next.js and encountered an issue where objects are not valid as a React.js child. https://i.stack.imgur.com/MCO7z.png The problem arises after importing the Head component from Next.js and implem ...

Controlling data tables with knockout.js

I have successfully integrated an API in knockout.js, but I am facing an issue with displaying the amount based on accounting principles. My table definition includes columns for id, name, debit, credit, and amount. Since not all amounts fall under debit o ...

Trouble with Setting Up the Email Address for the 'File a Complaint' Form in WordPress

I am currently in the process of integrating a 'Complaint Registration Form' on my WordPress site. This form enables users to input their name, email address, order ID, and reason for filing a complaint. Once submitted, the details are forwarded ...

Guide on transforming the popup hover state into the active state in vue.js through a click event

My code currently includes a popup menu that shows up when I hover over the icon. However, I need to adjust it so that the popup changes its state from hover to active. Intended behavior: When I click the icon, the popup should appear and then disappear w ...

Quick inquiry about referencing state variables in the render method in React Native

Initially, I assumed it was just a simple syntax error, but now I'm beginning to think that it might be related to a bigger concept concerning hierarchy and inheritance. I am currently working on an app in react native (expo) where I aim to display a ...

Mapping Service by Google - Navigate from your current location to desired destination

I have a script that currently displays a route for either car or transit depending on the user's selection. I am looking to adapt this script to set the origin as the user's current location and route from there to a set latitudes and longitudes ...

Expandable Buttons - Bootstrap version 3.3.4

I'm currently working with a bootstrap collapsible button group and I'm facing an issue where only one group box should be visible at any given time. I tried creating a JavaScript function to remove the "in" class and update the aria-expanded att ...

Processing MongoDB elements in NodeJS by retrieving them and appending them to a list or array for further processing

Currently, I am involved in a full stack project that requires fetching stock data from mongodb and performing algorithms on specific information. Here is an illustration of the JSON object stored in mongodb: [{ _id: 5e11d67abf05f3d00d56b801, LUNA: { ...

Is it possible to deploy Vue.js from a content delivery network (CDN) for production

My decision to use Vue.js for a new project was influenced by its ability to run natively in the browser, unlike React which requires compilation/transpilation via Node. I'm considering linking directly to a CDN like this in my production code: <s ...

Storing translations in localStorage on my website to avoid repeatedly loading them each time I revisit the page

Recently, I created a function that loads translations for my website using an ajax request. However, I am now considering optimizing my code so that these translations are saved in localStorage and loaded from there instead of making a request every time. ...

Revamping a design using Mustache js

I've successfully implemented mustache js to render a template using data from an API, but now I face a challenge in updating the same template at a later time. Within my template, there is a list structured like this: template.html <div id="temp ...

Buefy's Loading Feature in Action with b-table

I am currently working on enhancing the animation of the Buefy loader to display text while loading data into my b-table. Is there a way for me to customize the default loader? It would be great if I could personalize the vue spinner to include text in th ...

Working with Vue.js to call component methods when the page loads

My payment implementation utilizes vue-js and stripe. I found that the only way to incorporate Stripe with vue-js was through the use of script.onload. Now, I am trying to access some of my methods within the onload function. Specifically, I want to call ...

Excluding form items that are disabled from a request in ReactJS

In my code, I am dealing with a Form section that contains multiple Collapse.Panel sub-sections. Interestingly, the Form.Item elements within collapsed panels are not included in the form values upon submission. However, I have noticed that certain InputNu ...

Issue with Three JS: Troubleshooting texture offset and repeat for accurately positioning elements from a spritesheet

I am currently working with a sprite sheet that I exported using Texture Packer. I am utilizing the offset and repeat properties of a texture to display elements from my sprite sheet. However, I am encountering an issue where the elements are being croppe ...

Creating a dynamic map in AngularJS by parsing and utilizing data from a JSON file

Looking to create a map from JSON data returned by a RESTFUL WEB Service using AngularJS. Here is an example of the JSON format: myJSON = [{ id: 8, color: "red", value: "#f00" }, { id: 37, color: "green", value: "#0f0" }, { id ...

The cube mesh is failing to render inside the designated div

I created a Torus and Cube Mesh in my scene, but I want the cube to be positioned at the bottom right corner of the screen. Here's what I tried: <div style="position: absolute; bottom: 0px; right:0px; width: 100px; text-align: center; "> & ...

How to Monitor Store Changes within a Vue File Using Vue.js

I am working with 2 vue files, header.vue and sidebar.vue. Both components are imported into layout.vue. Here are the steps I am following: 1. Initially, when the page loads, I update the store in header.vue with some values inside the created hook. 2. ...