What steps should I take in Three.js to make the "terrain" look three-dimensional?

Currently, I am in the process of developing a 3D terrain using Three.js along with ImprovedNoise.js. Utilizing the examples provided on the Three.js website, I have successfully created what appears to be terrain. However, my issue lies in the fact that it remains confined to two dimensions and does not expand into the z-axis.

During the creation of this scene, I encountered some errors within the example code. In order to rectify these issues, I made slight adjustments such as:

geometry.rotateX(-Math.PI)

I modified it to read:

geometry.rotateX = -Math.PI

One specific error that I struggled with was related to THREE.CanvasTexture not functioning as expected. Despite being present in numerous three.js examples, I discovered no mention or documentation regarding changes to this feature on the official site. Thus, I presume it might have been deprecated or underwent modifications.

My current dilemma revolves around the fact that despite my efforts, I still haven't resolved the initial issue. To gain a better understanding of the code, I attempted to copy and paste the example code verbatim for reverse engineering purposes. Nevertheless, the outcome consistently results in a 2D representation when executed on my machine.

Below, you will find the adjusted example code (excluding previously mentioned problematic sections):

If anyone could confirm whether this works correctly for them or provide insights into what may be missing, I would greatly appreciate it.

Thank you

The libraries I'm utilizing are:

    <script src="js/three.min.js"></script>
    <script src="js/PointerLockControls.js"></script>
    <script src="js/OrbitControls.js"></script>
    <script src="js/ImprovedNoise.js"></script>
    <script src="js/FirstPersonControls.js"></script>
    <script src="js/Detector.js"></script>

And here is the js: (The only alteration made was excluding the stats library, thus the corresponding code has been commented out below)

        var container, stats;
        var camera, controls, scene, renderer;
        var mesh, texture;
        var worldWidth = 256, worldDepth = 256,
        worldHalfWidth = worldWidth / 2, worldHalfDepth = worldDepth / 2;
        var clock = new THREE.Clock();
        var helper;
        var raycaster = new THREE.Raycaster();
        var mouse = new THREE.Vector2();
    
        // Rest of the JavaScript code continues...

Answer №1

Your array containing height information (data) seems to only have y-axis values instead of including x-axis and z-axis values that match the height data.

Can you clarify the purpose of the for loop in generateHeight()? It appears that the data array is being overwritten multiple times within the loop.

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

Applying background-image in ngStyle results in an undefined value

I have been attempting to incorporate images (retrieved through an API) as the background-image of an element. However, I keep encountering the error message Cannot read property 'url' of undefined, even though the URL is actually being rendered. ...

Comparing Optimistic Updates and Tag Invalidation in RTK Query

I found a basic code example from the RTK query documentation: updatePost: build.mutation<void, Pick<Post, 'id'> & Partial<Post>>({ query: ({ id, ...patch }) => ({ url: `posts/${id}`, method: 'PUT', ...

Provide the aggregated content within d3's text() or html() function

Below is my d3 code snippet: grouping.append('foreignObject').html(function (d) { var string = '<p>hello, {{ "there" }} <some-directive></some-directive></p>'; string = $compile(string)(scope); return stri ...

Ways to retrieve a variable from outside of a function

I am in need of sending the following batch data to the database, but I am facing difficulties in including the course_id along with the batchData. Currently, I am retrieving the course_id from another service that fetches data from a course table. I am ...

Having issues with Facebook's login API for JavaScript?

Apologies for the improper formatting. I am encountering errors in my JavaScript compiler while working with the Facebook Login API... Error: Invalid App Id - Must be a number or numeric string representing the application id." all.js:53 "FB.getL ...

Issue with submitting input fields that were dynamically added using jquery

I created a table where clicking on a td converts it into an input field with both name and value. The input fields are successfully generated, but they do not get submitted along with the form. In my HTML/PHP : <tr> <f ...

Clarity in Collada File

How can I adjust the transparency of a Collada (DAE) file using Three.js and dat.gui library? Here is my current code snippet: $gui = new DAT.GUI(); gui.add(opacity_pele, 'pele').onChange(function(){ if ( opacity_pele.pele ) { mater ...

Leveraging ES6 in Vue.js

I have been considering picking up Vue.js as my next skillset. A friend mentioned that it's important to have a good understanding of ES6 before diving into Vue.js. I've asked around for advice, but I would love to hear more opinions on this matt ...

Issue with Jquery .ajax function returning an object even after it has already moved on to the next line of code

I'm currently working with JQUERY and AJAX, and it seems like the function is somewhat functional but there's a glitch that occurs after the next line of code runs. This issue causes the script to add a null value when trying to insert the object ...

Switch between adding elements to various div containers

Can we implement a functionality where clicking an anchor tag moves the .item from .region1 to .region2, and then moving it back to .region1 when clicked again? Essentially creating a toggle behavior? <a href="#" class="btn">Click</div> &l ...

Divs expanding below content in IE on a particular server

Currently, I am facing an issue with a JavaScript div that expands correctly over other content in most situations but goes under the content in one specific scenario. I am unsure about where to begin debugging this problem. To provide some context, the d ...

Simultaneous asynchronous access to a single object

I have been working with JS/TS for quite some time now, but the concept of race conditions still perplexes me. I am currently attempting to execute the following logic: class Deployer { protected txDataList: Array<TXData>; constructor() { this ...

Executing numerous HTTP requests in a single Node.js HTTP request

I am attempting to make a single URL call that will fetch multiple URLs and store their JSON responses in an array, which will then be sent as the response to the end user. Here is what my code looks like: var express = require('express'); var ...

Unable to display image in jqGrid binary format

In our system, we use a standard function to retrieve images stored as binaries in the database, and this function works seamlessly throughout the entire system. However, when implementing jqGrid, I encountered difficulties using the existing structure as ...

Is it possible to adjust the pivot point for rotation on TrackballControls without changing the camera's lookAt position?

Despite numerous attempts, I have been unable to change the rotation pivot on THREE.TrackballControls without affecting the camera's lookAt. Can you provide guidance on how to solve this issue? My goal is to achieve mouse controls similar to Revit. ...

I'm currently working on developing a chat system, but I'm facing an issue where I am unable to send multiple messages consecutively. It seems like there is a problem with the form

My chat application is not allowing me to post multiple messages. Here is the code snippet responsible for sending messages: window.typing = false; var posted = 0; var canPost = 1; var donotrefresh = 0; document.forms['send'].addEventListener(& ...

The error message "TypeError Cannot read properties of undefined (reading 'backdrop') - bootstrap v5.2.1 modal" is indicating that there is an

While working with the bootstrap modal, an error has been encountered ( TypeError Cannot read properties of undefined (reading 'backdrop') ), which has been logged in our bug tracker. However, attempts to replicate this error have been unsuccessf ...

How to toggle a boolean variable in AngularJS when transitioning between states

Just getting started with AngularJS and trying to figure out how to tackle this issue. I have set up the following route: name: "Tracker", url: "/tracker/:period", and I have 3 distinct states for which I've created 3 separate functions to facilit ...

Enlarging the modal overlay

My Angular/Bootstrap app features a small text area within a modal window that often contains lengthy content exceeding the size of the textarea and modal itself. I am looking to incorporate a button within the modal window that, when clicked, opens a lar ...

Troubleshooting the issue: Incompatibility between jQuery .focus() and dynamically generated list items from ng-repeat in AngularJS

I am currently working on enhancing the keyboard accessibility of a website, specifically focusing on making a dropdown menu accessible via keyboard. I am attempting to establish focus on the element with the id= list-0. Below is the HTML code snippet: & ...