Building an aircraft using the points of a polyline with threejs

My goal is to achieve a design similar to this:

https://i.sstatic.net/EvyLO.png

I have a Polyline with its points, and now I am looking to create a sheet as displayed in the image. The polyline is shown above and below is a sheet generated from those polyline points.

I attempted to implement the solution mentioned in this post Extruding a line in three.js, but unfortunately, it doesn't render anything when I try it.

Below is the code snippet that I experimented with:

let containerThreeJs = document.getElementById('threed-view-container');
let w = containerThreeJs.offsetWidth;
let h = containerThreeJs.offsetHeight;

let renderer = new THREE.WebGLRenderer({
  antialias: true
});
renderer.setSize(w, h);
containerThreeJs.appendChild(renderer.domElement);

let scene = new THREE.Scene();

let camera = new THREE.PerspectiveCamera(5, 1, 1, 1000);
camera.position.setScalar(300);

let threeDpoints = [
  [88.5, 370],
  [229.5, 268],
  [300.5, 333],
  [373.5, 290],
  [426.5, 392]
];

let geometry = extrudePath(threeDpoints, 100);

var material = new THREE.MeshBasicMaterial({
  color: 0x00ff00,
  side: THREE.DoubleSide
});
var mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);

var controls = new THREE.OrbitControls(camera, renderer.domElement);

render();

function resize(renderer) {
  const canvas = renderer.domElement;
  const width = canvas.clientWidth;
  const height = canvas.clientHeight;
  const needResize = canvas.width !== width || canvas.height !== height;
  if (needResize) {
    renderer.setSize(width, height, false);
  }
  return needResize;
}

function render() {
  if (resize(renderer)) {
    camera.aspect = canvas.clientWidth / canvas.clientHeight;
    camera.updateProjectionMatrix();
  }
  renderer.render(scene, camera);
  requestAnimationFrame(render);
}

function extrudePath(points, depth) {
  var geometry = new THREE.PlaneGeometry(10, 10, points.length - 1, 1);
  var vertices = geometry.vertices;
  // if I comment this loop then the plane is visible
  for (var i = 0, l = points.length, p; i < l; i++) {
    p = points[i];

    vertices[i].x = vertices[i + l].x = p[0];
    vertices[i].y = vertices[i + l].y = p[1];

    vertices[i].z = p[2];
    vertices[i + l].z = p[2] + depth;
  }

  geometry.computeFaceNormals();

  return geometry;
}
<script src="http://mrdoob.github.io/three.js/build/three.min.js"></script>
<script src=http://mrdoob.github.io/three.js/examples/js/controls/OrbitControls.js></script>
<div id="threed-view-container" style="width: 100%; height: 500px"></div>

If I remove the for-loop from extrudePath, then the simple plane is visible. However, keeping it results in nothing being rendered.

Answer №1

It appears that there is a mismatch between the number of parts in the points array threeDpoints and what the extrudePath function is expecting. The points in threeDpoints have 2 parts, while the function is looking for 3 parts (p[0], p[1], p[2]).

`let threeDpoints = [
    [88.5, 370],
    [229.5, 268],
    [300.5, 333],
    [373.5, 290],
    [426.5, 392]
];
`

`p = points[i];
vertices[i].x = vertices[i + l].x = p[0];
vertices[i].y = vertices[i + l].y = p[1];
vertices[i].z = p[2];
vertices[i + l].z = p[2] + depth;`

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

Unusual blue outline spotted on Firefox

Could you please review the following code snippet: http://www.jsfiddle.net/tt13/5CxPr/21 In Firefox, there is a strange blue border that appears when selecting multiple rows by pressing the ctrl button. However, this issue does not occur in Chrome. Thi ...

What is the process for broadcasting an object with socket.io?

I am encountering an issue with sending responses in my code. socket.on('findUserMessages', (userName) => { io.sockets.connected[socket.id].emit('Checking-message', { type: 'ss', text: bot, use ...

The communication between Node.js Express and the front end is experiencing synchronization issues

I'm facing an issue where a property is mysteriously disappearing when I try to send an object from my nodejs server to the front end. server router.post('/cart/retrieve', (req, res) => { let cart = req.session.cart; let prodId ...

Combining JWT authentication with access control lists: a comprehensive guide

I have successfully integrated passport with a JWT strategy, and it is functioning well. My jwt-protected routes are structured like this... app.get('/thingThatRequiresLogin/:id', passport.authenticate('jwt', { session: false }), thing ...

The implementation of a custom event for jQuery rows is not functioning as expected

I need assistance with jQuery code to add click events only to columns in a row that have text in the first column. Specifically, I want to hide rows containing "1/" in the first column when clicked on for the first row. <table class="results"> < ...

Discover how ReactJS can dynamically display or hide div elements based on specific conditions being met within JSON data

How do I show or hide a div based on a condition in React, using data from a JSON array? I have implemented the code below, but changing the value of isPassed={resultPass.pass} to isPassed={resultPass.failed} still displays the result as pass. I came acro ...

Restricting the input field in jQuery to only accept the maximum value based on the

There are two input fields: discountType and discountAmount. My goal is to set restrictions based on the value of discountType: if it's percentage, the discountAmount input should only accept numbers between 0 and 100; if it's absolute, any numbe ...

Guide to making a Typescript interface by combining elements from two separate interfaces without utilizing inheritance

Programming Language: Typescript I am looking to combine the properties of two interfaces as the value of an indexable-type within a third interface. Interface 1: export interface Employee { id: string name: string } Interface 2: export interfa ...

Utilizing the nuxt $store in a Dynamic Component

I'm currently working on a Promise-based modal component that allows for specifying a component as the body of the modal itself. My approach to achieving this was by using a dynamic component inside the modal template. However, when working within a N ...

Error encountered: Unable to access the 'showBarChart' property of an undefined variable within a React application

I am working on a function that customizes the tooltip for a scatter plot in nvd3. To update the state within this function, I am calling another function that utilizes setState: chart.tooltip.contentGenerator(function (d) { var html = "<div>" ...

The Ajax request appears to be triggered twice, yet all other associated JavaScript functions are executed only once

Using ajax, I have a code that retrieves the contents of a PHP page every X seconds until completed=="yes". Each time it fetches the content, it displays an alert with <script>alert("checked");</script>. Within the PHP page, there is another al ...

Gathering all components prior to the comment

I am in the process of scraping information from a webpage. The data I require is contained within separate divs that have a specific class assigned to them. For instance: <div class="temp">text </div> The challenge arises when the number of ...

Tips for ensuring all data is properly set before saving in mongoose

Struggling to update undefined or defined values in Mongoose due to the need to await their assignment. It seems like the code is not saving the data because USER.save() is executed before the values are set. How can I ensure that the data is updated/set ...

Using Angular to assign an object as the input value

I have an input field and I would like to assign a formControl to it that is an object in this format: { id:'123', name: 'Name' } However, I want the input field to display the "name" property of the object ...

What causes .obj files to not respond to directional light in three.js?

Can anyone explain why the .obj file is not displaying directional light similar to the box? Both have identical materials. You can find the code on GitHub: https://github.com/triple-verge/triple-verge-website/blob/master/src/js/modules/logo-3d.js#L52 H ...

When using the map function, I am receiving an empty item instead of the intended item based on a condition

Need assistance with my Reducer in ngRx. I am trying to create a single item from an item matching an if condition, but only getting an empty item. Can someone please help me out? This is the code for the Reducer: on(rawSignalsActions.changeRangeSchema, ...

Can you explain the concept of an anonymous block in JavaScript ES6 to me?

Recently, I came across an article on pragmatists which discussed some interesting ES6 features. However, one concept that caught my attention was the use of an anonymous block within a function. function f() { var x = 1 let y = 2 const z = 3 { ...

IE is causing issues with parseInt, returning NaN, while Chrome is working properly with it

When attempting to convert a date in a string to a Unix timestamp integer, I encountered an issue. While using parseInt successfully changed the string to an integer in Chrome, Internet Explorer and Edge returned NaN. If you'd like to see the code sn ...

Perform a task only once during several scroll events and disable additional scrolling

I want to add scrolling functionality similar to the Google Inbox landing page: On that page, no matter how fast or how many times you scroll the wheel, it only counts as one scroll and moves to the next step. This sounds simple, but it's actually qu ...

Error: Attempting to access the 'name' property of an undefined variable is resulting in a TypeError in Material UI

When attempting to display the retrieved data on MUI Autocomplete, I encountered an error that I cannot seem to figure out. The data is fetched from MongoDB, and I simply want to showcase the category names as selectable options. https://i.sstatic.net/cxT ...