Calling all Three.JS gurus! Seeking assistance with accurately mapping points and faces

I would greatly appreciate any assistance from this wonderful community. Lately, I've been grappling with the challenge of plotting a series of points and faces extracted from an XML file using Three.js. The point data appears as follows:

<P id="1">472227.25640192 2943287.51179465 200.138787</P>
<P id="2">472232.14363148 2943288.56768013 200.129142</P>
<P id="3">472237.03086105 2943289.62356560 200.119496</P>

Meanwhile, the face information is structured like this:

<F>1021 1020 1061</F>
<F>640 754 641</F>
<F>1534 1633 1535</F>

It's worth noting that there are numerous points and faces, each comprised of three numbers. I've successfully converted the XML to JSON and performed all necessary parsing tasks. However, my attempt at creating a basic line visualization in Three.js yields only a blank screen. Below is a snippet of my code. Could someone please advise if what I'm trying to achieve is feasible with Three.js or suggest a better alternative?

var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 500 );
camera.position.set( 0, 0, 100 );
camera.lookAt( 0, 0, 0 );

var scene = new THREE.Scene();

var material = new THREE.LineBasicMaterial( { color: 0x0000ff } );

var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3( 472227.25640192, 2943287.51179465, 200.138787) );
geometry.vertices.push(new THREE.Vector3( 472232.14363148, 2943288.56768013, 200.129142) );
geometry.vertices.push(new THREE.Vector3( 472237.03086105, 2943289.62356560, 200.119496) );

var line = new THREE.Line( geometry, material );
scene.add( line );
renderer.render( scene, camera );

Your help would be immensely valued. Thank you.

Answer №1

Your current vertex coordinates are causing the line to extend beyond the viewport. Try adjusting them to bring the line into view, like this:

geometry.vertices.push(new THREE.Vector3(1, 2, 0));
geometry.vertices.push(new THREE.Vector3(3, 3, 0));
geometry.vertices.push(new THREE.Vector3(5, 6, 0));

By making these changes, you should be able to see the line within the viewport.

-or-

If your coordinate values are too large like in the example, consider moving the camera far back on the z-axis or scaling down the values for better visibility.

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

AngularJS substitution with regular expressions

Looking to replace specific words in HTML content within <div> and <p> tags upon page load. Utilizing angularJS to achieve this task. This is my current function: var elementsList = e.find('p'); var regex = ('[^<>\& ...

The functionality ceases to operate properly once a new element has been added

I am encountering an issue with the "click" action on a newly created element through a jQuery function, as it is not functioning properly. To demonstrate this problem, I have set up a JSFiddle at the following link (JSFiddle), however, please note that t ...

504 error when attempting to access HTTPS with Node.js

I have encountered an issue with making an https request in my backend node.js web app. The code I am using is as follows: const express = require('express'); const https = require('https'); const app = express(); app.get("/", functio ...

The Discord message will be automatically removed once there is a reply from a new user

Wondering how to implement a feature where a user's message gets deleted once another message is sent, preventing the same person from sending two consecutive messages? Perhaps by checking the last message and the author of the message on the channel? ...

What is the best way to transfer variables between PHP and an external JavaScript file?

I need to transfer 2 variables (which store data for a chart) to an external JS file that contains the chart settings. In my PHP code, I have: <script type='text/javascript'> var final_values = '$final_values'; var final_names = ...

Converting 3D vector to 2D pixel position in THREE.js by considering the z-coordinate

After stumbling upon this Stack Overflow post, I came across a function that caught my attention. The function, which allows for the conversion of a point in 3D space to a pixel position on the screen, is provided below for easy reference. function toScre ...

javascriptif the number is a whole number and evenly divisible

I am currently developing a script that tracks the distance traveled by some dogs in meters. It is basically just a gif running in a loop. What I want to achieve now is to display an image every 50 meters for a duration of 3 seconds. Here's my attempt ...

"An unexpected 'b' character was found at the beginning of the

I encountered the error "Unexpected token b in position 0" while trying to parse JSON returned from my PHP file in JavaScript. $file = array( array( 'src' => 'http://localhost/grapesjs-dev/uploads/'.$ ...

Extract a value from a JSON array without using any predefined entities

Can someone help me figure out how to access the values for 2.2.10.60 and "bank overdrafts...." from the array linked below? https://i.sstatic.net/XF3v9.png I attempted to retrieve the values using the following code: var json=chunk.toString(); ...

JavaScript Database Operations

I have a script that reads data from a Google Sheet and returns its content. I am looking to save all of this data into a database. var request = gapi.client.sheets.spreadsheets.values.get(params); request.then(function(response) { console.log(respons ...

Creating URLs in asp.net using both name and ID parameters

test.Controls.Add(GetButton(thisReader["session_id"].ToString(), "Join Session")); I made a modification to the code above, switching it to: test.Controls.Add(GetButton(thisReader["session_name"].ToString(), "Join Session")); The reason for this change ...

Employ fixed values in select2 before conducting an ajax search

I am using the select2 4.0.2 plugin to implement a select box that performs an AJAX search. However, I would like the options to display within <option> tags initially, similar to a regular <select>, until the user starts typing. At that point, ...

In Vue, reactivity does not extend to nested child objects

I am dealing with JSON data structured like this- items: { id: 1, children: [{ id: 2, parentId: 1, children: [{ id: 3, parentId: 2 }] }] } level-1 children represent parent items that all possess a parent_id of 1 (the roo ...

active components and monitoring interactions with them

I have a webpage that displays a list of emails. echo "<div class='comms'>"; $sel = "SELECT * from emails where customerId=:custId"; $stmt = $db->prepare($sel); $stmt->bindParam(':custId',$_POST['custId']); $ ...

What steps can we take to perform queries within the context of a specific element in a Jest test?

Currently, I am in the process of writing Jest tests for a React application. Imagine that there is a webpage with multiple instances of a specific element present. For instance, let's consider a scenario where there are two buttons on the page. My ob ...

Guide to automatically triggering overscrolling

Currently working on a kiosk webpage designed for an iPad. Discovered an app that enables fullscreen mode, but requires overscrolling at the bottom. Is there a method to automatically trigger this on my webpage? Attempted to achieve this using autoscroll ...

Regular expression in JavaScript that can match two different potential combinations

To capture a specific combination of letters followed by a variable number in a string, stored in the input variable, I have set some rules. The letters must be strict while the numbers can vary. They can either be at the start of the string or immediately ...

Uploading videos to a single YouTube channel using the YouTube Data API

I have been tasked with creating a node js app for a select group of individuals who need to upload videos. However, our budget is quite limited and we are unable to afford cloud storage services. I am curious if it would be feasible to create a key syste ...

Incorporating additional information into the database

When I run the code, I see a table and a button. After entering data in the prompts as instructed, the table does not get updated. I'm unsure why this is happening. Can someone please explain? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Trans ...

Refresh Layers in Openlayers with LayerRedraw(), Rotate Features, and Manipulate Linestring Coordinates

TLDR: I am facing difficulties with my OpenLayers map. Specifically, I want to remove and add a layer called 'track', or find a way to plot a triangle based on one set of coordinates and a heading (see below). In my OpenLayers map, there is an i ...