Generating a 3D aircraft model integrated with a point cloud using the three.js library

After creating a pointcloud with all points in the same plane, I am looking to highlight and display it as a rectangle shape when the mouse hovers over. To achieve this, I believe the pointcloud needs to be converted into a mesh.
I've spent hours searching online and even tried reading through Three.js documentation but have not been able to find a solution. Could someone please assist me in converting this pointcloud to a mesh? Thank you so much

        <script>

        if ( WEBGL.isWebGLAvailable() === false ) {
            document.body.appendChild( WEBGL.getWebGLErrorMessage() );
        }
        var camera, scene, renderer, controls;
        init();
        animate();

        function init() {

            renderer = new THREE.WebGLRenderer( { antialias: true } );
            renderer.setPixelRatio( window.devicePixelRatio );
            renderer.setSize( window.innerWidth, window.innerHeight );
            document.body.appendChild( renderer.domElement );
            scene = new THREE.Scene();
            camera = new THREE.PerspectiveCamera( 45.0, window.innerWidth / window.innerHeight, 5, 3500 );
            camera.position.z = 2500;
            controls = new THREE.TrackballControls( camera, renderer.domElement );
            createScene();
        }

        function createScene() {
                scene = new THREE.Scene();
                scene.background = new THREE.Color( 0x000000 );
                var geometry = new THREE.BufferGeometry();
                var positions = [];

                for ( var i = 0; i < 500; i ++ ) {
                    for ( var j = 0; j < 300; j ++ ) {
                    var y = j;
                    var x = i; 
                    var z = 0;
                    positions.push( x, y, z );
                    }
                }

                geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) );

                var material = new THREE.PointsMaterial( {color: 0xFFFFFF} );
                points = new THREE.Points( geometry, material );
                scene.add( points );
        }

        function animate( time ) {

            requestAnimationFrame( animate );
            controls.update();
            renderer.render( scene, camera );

        }

        </script>

Answer №1

Here is a simple and effective tweak to your example code. It essentially generates a slim box with the same dimensions as your point cloud, which toggles its visibility when the mouse hovers over it (using a raycaster). Currently, there isn't a direct or pre-built method to convert a point cloud into a plane or mesh.

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Three.js - wall construction</title>
        <meta charset="utf-8">
        <script src="js/three.js"></script>
        <script src="js/TrackballControls.js"></script>
    </head>
    <body style="margin:0;">
        <script>

        if ( WEBGL.isWebGLAvailable() === false ) {
            document.body.appendChild( WEBGL.getWebGLErrorMessage() );
        }
        var camera, scene, renderer, controls, box, boxMaterial;
        init();
        animate();

        function init() {


          renderer = new THREE.WebGLRenderer( { antialias: true } );
          renderer.setPixelRatio( window.devicePixelRatio );
          renderer.setSize( window.innerWidth, window.innerHeight );
          document.body.appendChild( renderer.domElement );
          scene = new THREE.Scene();
          camera = new THREE.PerspectiveCamera( 45.0, window.innerWidth / window.innerHeight, 5, 3500 );
          camera.position.z = 2500;
          controls = new THREE.TrackballControls( camera, renderer.domElement );
          createScene();
          renderer.domElement.addEventListener('mousemove', onMouseMove, false); 
        }

        function createScene() {

          scene = new THREE.Scene();
          scene.background = new THREE.Color( 0x000000 );
          var geometry = new THREE.BufferGeometry();
          var positions = [];

          for ( var i = -250; i < 250; ++i) {
              for ( var j = -150; j < 150; ++j) {
                positions.push(i, j, 0);
              }
          }

          geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) );

          var material = new THREE.PointsMaterial({color: 0xFFFFFF});
          points = new THREE.Points(geometry, material);
          scene.add(points);

          //create box based on pointcloud extends  
          var geometry = new THREE.BoxGeometry(500, 300, 1 );
          boxMaterial = new THREE.MeshBasicMaterial({color: 0x0000FF});
          boxMaterial.visible = false //set invisible by default
          box = new THREE.Mesh(geometry, boxMaterial);
          scene.add(box);
        }

        function onMouseMove (e) {

          var pointer = {
            x: (e.clientX / window.innerWidth ) * 2 - 1,
            y: - ( e.clientY / window.innerHeight ) * 2 + 1
          }  

          var raycaster = new THREE.Raycaster()
          raycaster.setFromCamera(pointer, camera)

          var intersects = raycaster.intersectObjects([box])

          boxMaterial.visible = !!intersects.length
        }

        function animate(time) {
          requestAnimationFrame(animate);
          controls.update();
          renderer.render(scene, camera);
        }

        </script>
    </body>
</html>

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

What is the best way to eliminate particular elements from a nested JSON payload in JavaScript?

I am in need of creating a function that can scan through a nested JSON structure to locate specific elements and delete all occurrences of those elements, even if they are within an array. Consider this JSON example: { "userId": "John991", "grou ...

What could be causing the data in my JavaScript array to be replaced when I use myarr.push(mydic)?

Currently, I am working on a function that converts a 3D array into an array of key/value pairs. Below is the code I have written. function arrToDictArray(array) { var myarr = []; var mydic = {}; var x = 0; for (var i in array) { console.log("i ...

The Art of Mass Updating Embedded Documents in MongoDB

Struggling with updating an embedded document in MongoDB using Bulk updates on version 3.0. Any assistance would be greatly appreciated. ...

Protected knockout observable

Incorporating the protected observable into my code has been a goal of mine, so I stumbled upon this helpful tutorial: HERE While experimenting with the demo on the website, I encountered an interesting scenario: Initially, click the edit button for a ...

Ways to dynamically assign value to a checkbox using jquery

var sites = sites_str.split(","); $.each(sites,function(i,j) { $('.check').append("<input type=checkbox name=site_name value=sites[i]>"+sites[i] +"</br>" }) I am facing an issue when trying to retrieve the values of selected check ...

Utilizing the <webview> functions within Electron: A comprehensive guide

After checking out the documentation for the Electron <webview>, I attempted to use some of the listed methods with no success. In inspecting the properties of the <webview> element, I found that its prototype is labeled as webview (__proto__ : ...

SimpleLightBox refuses to function

Having trouble getting SimpleLightBox to work properly? It seems like when you click on an image, it opens as a regular image on a blank page. I've added the JS and CSS files correctly (I double-checked in the source code) and included the HTML and JS ...

Tips for displaying all documents within a MongoDB collection using the sharedb-cli command line tool

My client-demo is not working as expected. I am trying to retrieve all documents from the "file" collection, but I am getting null results. https://i.sstatic.net/Pw6sA.png When testing with the mongo shell, I can see that the document data actually exist ...

Incomplete JSON response being received

We set up an express server to call an API and successfully requested the JSON object in our server. However, we are facing an issue where the JSON data is getting cut off when being displayed as a complete object on the client side. We tried using parse i ...

What is the method for displaying a file using a binary string as input?

Is there a way to display a PDF file from a binary string on a web browser? I know that for image files, we can use atob() and then <img src="data:image/png;base64,... But what about PDF files? Is there an equivalent method or syntax like ReadItAs("cont ...

Guide on extracting the text from the <script> tag using python

I'm attempting to extract the script element content from a generic website using Selenium. <script>...</script> . url = 'https://unminify.com/' browser.get(url) elements = browser.find_elements_by_xpath('/html/body/script[ ...

AngularJS: accessing remote systems - a guide

I am looking to explain my objective clearly I need guidance on how to establish a remote desktop connection from my Angular.js application to a windows application running system. The server I am using is Google App Engine. My current ideas: The Windo ...

Passing information from Vue to a modal

I'm working with 3 components: TaskList, TaskItem, and TaskForm. Within the TaskList component, there is a loop that renders all the data in TaskItem. Each TaskItem has an edit button meant to open a TaskForm modal (using bootstrap) displaying the sp ...

Is there an equivalent of numpy.random.choice in JavaScript?

The Numpy.random.choice function is a handy tool that allows you to select a sample of integers based on a specific probability distribution: >>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0]) array([3, 3, 0]) Is there a similar feature in Java ...

Node -- error encountered: options parameter must be of type object

Encountering a frustrating issue with the error message TypeError: options must be an object. Currently delving into the State example in Chapter 4 of Node.js Design Patterns. Initially assumed it was a mistake on my end, but even after testing the file w ...

Issue: [next-auth]: `useSession` function should be enclosed within a <SessionProvider /> tag in order to work properly

Encountering an error loading my ProfilePage where the page loads fine in the browser but an error appears in the terminal. Error: [next-auth]: `useSession` must be wrapped in a <SessionProvider /> All child components are properly wrapped using Se ...

convert the datatype of JSON values in JavaScript

I am facing an issue with my JSON object which contains timestamp values in string format. Here is a snippet of the data: var json = [{ "Time": "2017-08-17 16:35:28.000", "Value": "3.85" }, { "Time": ...

Discover data using JavaScript recursively through paths

Here is the data structure I am working with: [ { name: 'root', children: [ { name: 'page', children: [ // and so on ] } ] } ] I am in need of a function that can retrieve ...

Guide on correctly importing a node module, ensuring all functions are exported

I am facing an issue with my file stats.js. Upon inspecting its contents, I found the following code: (function () { func1 = function () { } func2 = function () { } module.exports = this; }).call(this); According to what I have r ...

Bootstrap 4 tabs function perfectly in pairs, but encounter issues when there are three of them

Having trouble with bootstrap4 tabs not working properly? They function well with 2 tabs using the code below: <div class="row"> <div class="col-12"> <ul class="nav nav-tabs" id="registration-picker-acc-select" role="tablist"> ...