In the world of three js, objects vanish from view as the camera shifts

I am attempting to display a d3 force graph in three.js using standard Line and BoxGeometry with a photo texture applied. When the force graph is updated, I call the draw function which is triggered by:

controls.addEventListener('change', () => {this.redraw()});

However, when I move the camera, some of the lines disappear, especially when viewed up close. It appears that there is no specific pattern to the disappearing lines, even when zoomed in on the graph.

Here are some examples:

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

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

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

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

I attempted scaling down units

And setting frustum to false

Full code:

(Code here - too lengthy to include in response)

Answer №1

I found the exact answer I needed in the above comment by WestLangley.

It seems that when you make changes to the vertices of a geometry, you should remember to call geometry.computeBoundingSphere(). The renderer automatically does this on the first render, but subsequent modifications to the vertices will require you to update the bounding sphere manually. Another option is to set mesh.frustumCulled = false;

Answer №2

When trying to make it work with the Line object, I faced some difficulties. However, by utilizing the LineSegments and pushing all vertex pairs into one Geometry, everything started functioning smoothly.

Therefore, within the buildScene function, I replaced:

this.lineMaterial = new LineBasicMaterial({ color: 0xccff00, linewidth: 3});

with these lines:

this.linesGeometry = new Geometry();
this.scene.add(new LineSegments(this.linesGeometry, new LineBasicMaterial({ color: 0xccff00, linewidth: 3})));

Then, the content of the buildEdge is as follows:

this.linesGeometry.vertices.push(
    vectorIndex.get(link.source.index).copy(vectorIndex.get(link.source.index).setZ(0)),
    vectorIndex.get(link.target.index).copy(vectorIndex.get(link.target.index).setZ(0))
);

In the redraw function, I simply execute:

this.linesGeometry.verticesNeedUpdate = true;

instead of iterating through individual lines in this manner:

this.lines.forEach((line:Geometry) => {
    line.verticesNeedUpdate = true;
});

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

Creating a perfectly rounded 2D sprite with a plane geometry shader that stays oriented towards the camera in Three.js WebGL coordinate system

Is there a way to create a rectangular texture with rounded corners for a 2D sprite, similar to this design: _____ / \ | | \_____/ I thought about using a mask texture and shader to create a circular mask, but I'm having t ...

JS for accessing Meteor templates through the DOM

This is a meteor template I created: {{#each p}} <div class="cpl"> <div class="chat-post"> <li class="post"> <div class="nm" id={{_id}}> <a>{{username}}</a> </div> < ...

"Setting up a schema in TypeORM when connecting to an Oracle database: A step-by-step guide

As a newcomer to TypeORM, I'm using Oracle DB with Node.js in the backend. Successfully connecting the database with TypeORM using createConnection(), but struggling to specify the schema during connection creation. One workaround is adding the schem ...

Designing webpages by superimposing text onto images with customizable positioning

My current project involves developing an HTML document with a floor plan image as the main layer. On top of this image, I need to display employee names extracted from a database and positioned on the map based on a location variable within the database ...

Issue with TypeScript Decorator Not Properly Overriding Get/Set Functions for Instance Properties

I'm struggling with creating a TypeScript decorator that modifies the get method for a property within a class. The issue I'm facing is getting it to affect instances of the class. Below is an example scenario: function CustomDecorator() { r ...

Enhancing WooCommerce by including additional text following the price for specific shipping methods

I need assistance with including a short message like "(incl. VAT)", following the shipping-price display on the checkout page. The challenge lies in ensuring that this message only appears for a specific shipping method within Zone 1 (zone_id=1), but I&a ...

Exploring the world of jQuery: Toggling radio buttons with variables on click

On the right side, there is a table of data that initially contains certain values, but can be modified using radio buttons and a slider on the left. If you select the first radio button for the "pay in full" option, it will increase the estimated discoun ...

The JavaScript function Date().timeIntervalSince1970 allows you to retrieve the time

For my React Native app, I currently set the date like this: new Date().getTime() For my Swift App, I use: Date().timeIntervalSince1970 Is there a JavaScript equivalent to Date().timeIntervalSince1970, or vice versa (as the data is stored in Firebase clo ...

Angular Material: Enable Window Dragging Across Multiple Monitors

Exploring the usage of Angular Material Dialog or any other Popup Window Component. The functionality is mostly working as expected, with the exception of the last point. a) The original screen should not have a grey overlay, b) Users should be able to i ...

Assign a unique variable to each div simultaneously

I am looking to implement a countdown feature for each DIV with the class (.topitembox) by incorporating specific JSON variables. $('#countdown_items .topitembox').each(function () { itmID = $(this).attr('class').replace(/[^0-9]/g, ...

Using a jQuery UI accordion with a numbered list

As part of my company's user documentation, I am trying to integrate jQuery UI components into our HTML output. Despite my limited experience with JavaScript, I was able to get the accordion feature working for table rows. However, I am now facing dif ...

Unexpected outcome when returning a map

Encountered a puzzling issue that requires immediate clarification. When I input the following code into my project: this.metadata = json.metadata.map((x) => {return new Metadatum(x);}); console.log(this.metadata[0].value); The output consistently sho ...

Hiding the Previous or Next Button on the First and Last Item in a Twitter Bootstrap Carousel

Is there a way to hide the previous button on the first item and hide the right button when the carousel reaches the last item? I've tried different solutions but couldn't get it to work. Any help in understanding how to implement this for a Boot ...

developing a monorepo without utilizing a package registry and installing through Bitbucket

My organization is working on creating a monorepo for react components to be used across multiple sites. Currently, we have a repository called react-components on bitbucket and we are looking to convert it into a monorepo using lerna.js, with a structure ...

Converting an array of objects into a dictionary using TypeScript

I'm attempting to convert an array of objects into a dictionary using TypeScript. Below is the code I have written: let data = [ {id: 1, country: 'Germany', population: 83623528}, {id: 2, country: 'Austria', population: 897555 ...

Press a button to generate an image inside a specified div element

I've been struggling with this particular issue and have attempted various solutions, but there seems to be an error in my implementation as it's not functioning correctly. My goal is simple: I want to be able to click a button and have an image ...

Import gltf model from internal data, not a web address

Currently in the process of downloading a gltf file from Google Drive using the Google Drive API. Although I am able to print the gltf file as text in the console, I am facing difficulties in parsing it and visualizing it in three.js. I have attempted to u ...

Utilizing Audio Record Feature with a pair of buttons - one for initiating recording and the other for concluding recording

I'm new to Vue.js and trying to create a simple audio recorder that starts recording on click of a button and stops when another button is clicked. The goal is to display the audio file in the template and save it locally as a blob. Here is the templ ...

Get the QR code canvas image with a customized background by downloading it

I am having trouble with downloading a QR code canvas image with a background. The download works fine, but my device is unable to scan the code properly due to an incomplete border. I need to add a white background behind it to make it larger. Current im ...

Hiding components in Angular 4/5 through routing decisions

Just getting started with routing in Angular 4/5, I am currently following the tutorial provided on the official Angular website. I have an Angular application and I want to create two separate pages. Currently, the main page is located at localhost:8870/d ...